Skip to content

Commit e4e9973

Browse files
authored
fix(js): infer typecheck task for buildable libraries with tsc (#30505)
## Current Behavior Buildable libraries using `tsc` for `build` don't get a `typecheck` task, which results in test files not being type-checked. ## Expected Behavior The `typecheck` task should be inferred, and test files should be type-checked. ## Related Issue(s) Fixes #
1 parent 1a235d7 commit e4e9973

File tree

7 files changed

+12
-38
lines changed

7 files changed

+12
-38
lines changed

e2e/js/src/js-ts-solution.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,19 @@ ${content}`
132132

133133
// check typecheck
134134
expect(runCLI(`typecheck ${esbuildParentLib}`)).toContain(
135-
`Successfully ran target typecheck for project @proj/${esbuildParentLib} and 4 tasks it depends on`
135+
`Successfully ran target typecheck for project @proj/${esbuildParentLib} and 5 tasks it depends on`
136136
);
137137
expect(runCLI(`typecheck ${rollupParentLib}`)).toContain(
138-
`Successfully ran target typecheck for project @proj/${rollupParentLib} and 4 tasks it depends on`
138+
`Successfully ran target typecheck for project @proj/${rollupParentLib} and 5 tasks it depends on`
139139
);
140140
expect(runCLI(`typecheck ${swcParentLib}`)).toContain(
141-
`Successfully ran target typecheck for project @proj/${swcParentLib} and 4 tasks it depends on`
141+
`Successfully ran target typecheck for project @proj/${swcParentLib} and 5 tasks it depends on`
142+
);
143+
expect(runCLI(`typecheck ${tscParentLib}`)).toContain(
144+
`Successfully ran target typecheck for project @proj/${tscParentLib} and 5 tasks it depends on`
142145
);
143146
expect(runCLI(`typecheck ${viteParentLib}`)).toContain(
144-
`Successfully ran target typecheck for project @proj/${viteParentLib} and 4 tasks it depends on`
147+
`Successfully ran target typecheck for project @proj/${viteParentLib} and 5 tasks it depends on`
145148
);
146149

147150
// check lint

e2e/node/src/node-ts-solution.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('Node Applications', () => {
106106
expect(() => runCLI(`lint ${nodelib}`)).not.toThrow();
107107
expect(() => runCLI(`test ${nodelib}`)).not.toThrow();
108108
expect(() => runCLI(`build ${nodelib}`)).not.toThrow();
109+
expect(() => runCLI(`typecheck ${nodelib}`)).not.toThrow();
109110

110111
const p = await runCommandUntil(
111112
`serve ${nodeapp}`,

e2e/plugin/src/nx-plugin-ts-solution.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ describe('Nx Plugin (TS solution)', () => {
4747
expect(runCLI(`lint @proj/${plugin}`)).toContain(
4848
`Successfully ran target lint for project @proj/${plugin}`
4949
);
50+
expect(runCLI(`typecheck @proj/${plugin}`)).toContain(
51+
`Successfully ran target typecheck for project @proj/${plugin}`
52+
);
5053
expect(runCLI(`build @proj/${plugin}`)).toContain(
5154
`Successfully ran target build for project @proj/${plugin}`
5255
);

e2e/vite/src/vite-ts-solution.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ${content}`
106106

107107
// check typecheck
108108
expect(runCLI(`typecheck ${reactApp}`)).toContain(
109-
`Successfully ran target typecheck for project @proj/${reactApp} and 5 tasks it depends on`
109+
`Successfully ran target typecheck for project @proj/${reactApp} and 6 tasks it depends on`
110110
);
111111
}, 300_000);
112112
});

packages/js/src/generators/library/library.spec.ts

-18
Original file line numberDiff line numberDiff line change
@@ -2347,24 +2347,6 @@ describe('lib', () => {
23472347
]);
23482348
});
23492349

2350-
it('should add nx.addTypecheckTarget to tsconfig.json when using tsc to build to avoid duplicated typechecks', async () => {
2351-
await libraryGenerator(tree, {
2352-
...defaultOptions,
2353-
useProjectJson: false,
2354-
directory: 'my-ts-lib',
2355-
bundler: 'tsc',
2356-
unitTestRunner: 'none',
2357-
linter: 'none',
2358-
});
2359-
2360-
expect(readJson(tree, 'my-ts-lib/tsconfig.json').nx)
2361-
.toMatchInlineSnapshot(`
2362-
{
2363-
"addTypecheckTarget": false,
2364-
}
2365-
`);
2366-
});
2367-
23682350
it('should set "nx.name" in package.json when the user provides a name that is different than the package name and "useProjectJson" is "false"', async () => {
23692351
await libraryGenerator(tree, {
23702352
...defaultOptions,

packages/js/src/generators/library/library.ts

-12
Original file line numberDiff line numberDiff line change
@@ -1057,12 +1057,6 @@ function createProjectTsConfigs(
10571057
json.references.push({
10581058
path: './tsconfig.lib.json',
10591059
});
1060-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
1061-
// This applies to `@nx/js/typescript` plugin only.
1062-
if (options.bundler === 'tsc') {
1063-
json['nx'] ??= {};
1064-
json['nx'].addTypecheckTarget = false;
1065-
}
10661060
return json;
10671061
});
10681062
} else {
@@ -1073,12 +1067,6 @@ function createProjectTsConfigs(
10731067
include: [],
10741068
references: [{ path: './tsconfig.lib.json' }],
10751069
};
1076-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
1077-
// This applies to `@nx/js/typescript` plugin only.
1078-
if (options.bundler === 'tsc') {
1079-
tsconfig['nx'] ??= {};
1080-
tsconfig['nx'].addTypecheckTarget = false;
1081-
}
10821070
writeJson(
10831071
tree,
10841072
joinPathFragments(options.projectRoot, 'tsconfig.json'),

packages/plugin/src/generators/plugin/plugin.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,6 @@ describe('NxPlugin Plugin Generator', () => {
466466
"extends": "../tsconfig.base.json",
467467
"files": [],
468468
"include": [],
469-
"nx": {
470-
"addTypecheckTarget": false,
471-
},
472469
"references": [
473470
{
474471
"path": "./tsconfig.lib.json",

0 commit comments

Comments
 (0)