Skip to content

Commit

Permalink
fix: recompute dependencies on every run
Browse files Browse the repository at this point in the history
Currently, we recompute dependencies only if fileNames for the main
configuration changes. It doesn't handle the case when we have project
references.
  • Loading branch information
piotr-oles committed Aug 8, 2021
1 parent dcd1a6f commit 7afc037
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
11 changes: 5 additions & 6 deletions src/typescript-reporter/reporter/TypeScriptReporter.ts
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
32 changes: 18 additions & 14 deletions test/e2e/TypeScriptSolutionBuilderApi.spec.ts
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
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
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

0 comments on commit 7afc037

Please sign in to comment.