Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix project references bug #642

Merged
merged 2 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,18 @@ function createControlledTypeScriptSystem(
}

function getReadFileSystem(path: string) {
if (
!isInitialRun &&
(mode === 'readonly' || mode === 'write-tsbuildinfo') &&
isArtifact(path)
) {
if ((mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
if (isInitialRun && !memFileSystem.exists(path) && passiveFileSystem.exists(path)) {
// copy file to memory on initial run
const stats = passiveFileSystem.readStats(path);
if (stats?.isFile()) {
const content = passiveFileSystem.readFile(path);
if (content) {
memFileSystem.writeFile(path, content);
memFileSystem.updateTimes(path, stats.atime, stats.mtime);
}
}
}
return memFileSystem;
}

Expand All @@ -175,6 +182,9 @@ function createControlledTypeScriptSystem(
const controlledSystem: ControlledTypeScriptSystem = {
...typescript.sys,
useCaseSensitiveFileNames: caseSensitive,
realpath(path: string): string {
return getReadFileSystem(path).realPath(path);
},
fileExists(path: string): boolean {
const stats = getReadFileSystem(path).readStats(path);

Expand Down
11 changes: 5 additions & 6 deletions src/typescript-reporter/reporter/TypeScriptReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,15 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
diagnosticsPerProject.clear();
configurationChanged = true;
} else {
const previousParsedConfiguration = parsedConfiguration;
const previousDependencies = dependencies;
[parsedConfiguration, parseConfigurationDiagnostics] = parseConfiguration();
dependencies = getDependencies();

if (
previousParsedConfiguration &&
JSON.stringify(previousParsedConfiguration.fileNames) !==
JSON.stringify(parsedConfiguration.fileNames)
previousDependencies &&
JSON.stringify(previousDependencies) !== JSON.stringify(dependencies)
) {
// root files changed - we need to recompute dependencies and artifacts
dependencies = getDependencies();
// dependencies changed - we need to recompute artifacts
artifacts = getArtifacts();
shouldUpdateRootFiles = true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/TypeScriptGenerateTrace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('TypeScript Generate Trace', () => {

// update sandbox to generate trace
await sandbox.patch(
'tsconfig.json',
'tsconfig.base.json',
' "rootDir": "./packages"',
[' "rootDir": "./packages",', ' "generateTrace": "./traces"'].join('\n')
);
Expand Down
32 changes: 18 additions & 14 deletions test/e2e/TypeScriptSolutionBuilderApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ describe('TypeScript SolutionBuilder API', () => {
await driver.waitForNoErrors();

await sandbox.write('packages/client/src/nested/additional.ts', 'export const x = 10;');

// this compilation should be successful
await driver.waitForNoErrors();

await sandbox.patch(
'packages/client/src/index.ts',
'import { intersect, subtract } from "@project-references-fixture/shared";',
Expand All @@ -125,31 +129,31 @@ describe('TypeScript SolutionBuilder API', () => {
break;

case 'write-tsbuildinfo':
expect(await sandbox.exists('packages/shared/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/client/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib')).toEqual(false);
expect(await sandbox.exists('packages/client/lib')).toEqual(false);
expect(await sandbox.exists('packages/shared/lib/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/client/lib/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib')).toEqual(true);
expect(await sandbox.exists('packages/client/lib')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib/index.js')).toEqual(false);
expect(await sandbox.exists('packages/client/lib/index.js')).toEqual(false);

expect(await sandbox.read('packages/shared/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/client/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/shared/lib/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/client/lib/tsconfig.tsbuildinfo')).not.toEqual('');

await sandbox.remove('packages/shared/tsconfig.tsbuildinfo');
await sandbox.remove('packages/client/tsconfig.tsbuildinfo');
await sandbox.remove('packages/shared/lib');
await sandbox.remove('packages/client/lib');
break;

case 'write-references':
expect(await sandbox.exists('packages/shared/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/client/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/client/lib/tsconfig.tsbuildinfo')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib')).toEqual(true);
expect(await sandbox.exists('packages/client/lib')).toEqual(true);
expect(await sandbox.exists('packages/shared/lib/index.js')).toEqual(true);
expect(await sandbox.exists('packages/client/lib/index.js')).toEqual(true);

expect(await sandbox.read('packages/shared/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/client/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/shared/lib/tsconfig.tsbuildinfo')).not.toEqual('');
expect(await sandbox.read('packages/client/lib/tsconfig.tsbuildinfo')).not.toEqual('');

await sandbox.remove('packages/shared/tsconfig.tsbuildinfo');
await sandbox.remove('packages/client/tsconfig.tsbuildinfo');
await sandbox.remove('packages/shared/lib');
await sandbox.remove('packages/client/lib');
break;
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/fixtures/environment/typescript-monorepo.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
}

/// tsconfig.json
/// tsconfig.base.json
{
"compilerOptions": {
"target": "es5",
Expand All @@ -42,7 +42,12 @@
"declarationMap": true,
"sourceMap": true,
"rootDir": "./packages"
},
}
}

/// tsconfig.json
{
"extends": "./tsconfig.base.json",
"files": [],
"references": [
{ "path": "./packages/shared" },
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/fixtures/implementation/typescript-monorepo.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

/// packages/shared/tsconfig.json
{
"extends": "../../tsconfig",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"tsBuildInfoFile": "lib/tsconfig.tsbuildinfo",
"sourceRoot": "./src",
"baseUrl": "./src"
},
"include": ["src"],
"exclude": ["node_modules", "lib"]
"include": ["src"]
}

/// packages/shared/src/intersect.ts
Expand Down Expand Up @@ -63,16 +63,16 @@ export {

/// packages/client/tsconfig.json
{
"extends": "../../tsconfig",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"tsBuildInfoFile": "lib/tsconfig.tsbuildinfo",
"sourceRoot": "./src",
"baseUrl": "./src"
},
"references": [{ "path": "../shared" }],
"include": ["src"],
"exclude": ["node_modules", "lib"]
"include": ["src"]
}


Expand Down