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 #
This commit is contained in:
parent
1a235d7236
commit
e4e9973db3
@ -132,16 +132,19 @@ ${content}`
|
|||||||
|
|
||||||
// check typecheck
|
// check typecheck
|
||||||
expect(runCLI(`typecheck ${esbuildParentLib}`)).toContain(
|
expect(runCLI(`typecheck ${esbuildParentLib}`)).toContain(
|
||||||
`Successfully ran target typecheck for project @proj/${esbuildParentLib} and 4 tasks it depends on`
|
`Successfully ran target typecheck for project @proj/${esbuildParentLib} and 5 tasks it depends on`
|
||||||
);
|
);
|
||||||
expect(runCLI(`typecheck ${rollupParentLib}`)).toContain(
|
expect(runCLI(`typecheck ${rollupParentLib}`)).toContain(
|
||||||
`Successfully ran target typecheck for project @proj/${rollupParentLib} and 4 tasks it depends on`
|
`Successfully ran target typecheck for project @proj/${rollupParentLib} and 5 tasks it depends on`
|
||||||
);
|
);
|
||||||
expect(runCLI(`typecheck ${swcParentLib}`)).toContain(
|
expect(runCLI(`typecheck ${swcParentLib}`)).toContain(
|
||||||
`Successfully ran target typecheck for project @proj/${swcParentLib} and 4 tasks it depends on`
|
`Successfully ran target typecheck for project @proj/${swcParentLib} and 5 tasks it depends on`
|
||||||
|
);
|
||||||
|
expect(runCLI(`typecheck ${tscParentLib}`)).toContain(
|
||||||
|
`Successfully ran target typecheck for project @proj/${tscParentLib} and 5 tasks it depends on`
|
||||||
);
|
);
|
||||||
expect(runCLI(`typecheck ${viteParentLib}`)).toContain(
|
expect(runCLI(`typecheck ${viteParentLib}`)).toContain(
|
||||||
`Successfully ran target typecheck for project @proj/${viteParentLib} and 4 tasks it depends on`
|
`Successfully ran target typecheck for project @proj/${viteParentLib} and 5 tasks it depends on`
|
||||||
);
|
);
|
||||||
|
|
||||||
// check lint
|
// check lint
|
||||||
|
|||||||
@ -106,6 +106,7 @@ describe('Node Applications', () => {
|
|||||||
expect(() => runCLI(`lint ${nodelib}`)).not.toThrow();
|
expect(() => runCLI(`lint ${nodelib}`)).not.toThrow();
|
||||||
expect(() => runCLI(`test ${nodelib}`)).not.toThrow();
|
expect(() => runCLI(`test ${nodelib}`)).not.toThrow();
|
||||||
expect(() => runCLI(`build ${nodelib}`)).not.toThrow();
|
expect(() => runCLI(`build ${nodelib}`)).not.toThrow();
|
||||||
|
expect(() => runCLI(`typecheck ${nodelib}`)).not.toThrow();
|
||||||
|
|
||||||
const p = await runCommandUntil(
|
const p = await runCommandUntil(
|
||||||
`serve ${nodeapp}`,
|
`serve ${nodeapp}`,
|
||||||
|
|||||||
@ -47,6 +47,9 @@ describe('Nx Plugin (TS solution)', () => {
|
|||||||
expect(runCLI(`lint @proj/${plugin}`)).toContain(
|
expect(runCLI(`lint @proj/${plugin}`)).toContain(
|
||||||
`Successfully ran target lint for project @proj/${plugin}`
|
`Successfully ran target lint for project @proj/${plugin}`
|
||||||
);
|
);
|
||||||
|
expect(runCLI(`typecheck @proj/${plugin}`)).toContain(
|
||||||
|
`Successfully ran target typecheck for project @proj/${plugin}`
|
||||||
|
);
|
||||||
expect(runCLI(`build @proj/${plugin}`)).toContain(
|
expect(runCLI(`build @proj/${plugin}`)).toContain(
|
||||||
`Successfully ran target build for project @proj/${plugin}`
|
`Successfully ran target build for project @proj/${plugin}`
|
||||||
);
|
);
|
||||||
|
|||||||
@ -106,7 +106,7 @@ ${content}`
|
|||||||
|
|
||||||
// check typecheck
|
// check typecheck
|
||||||
expect(runCLI(`typecheck ${reactApp}`)).toContain(
|
expect(runCLI(`typecheck ${reactApp}`)).toContain(
|
||||||
`Successfully ran target typecheck for project @proj/${reactApp} and 5 tasks it depends on`
|
`Successfully ran target typecheck for project @proj/${reactApp} and 6 tasks it depends on`
|
||||||
);
|
);
|
||||||
}, 300_000);
|
}, 300_000);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2347,24 +2347,6 @@ describe('lib', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add nx.addTypecheckTarget to tsconfig.json when using tsc to build to avoid duplicated typechecks', async () => {
|
|
||||||
await libraryGenerator(tree, {
|
|
||||||
...defaultOptions,
|
|
||||||
useProjectJson: false,
|
|
||||||
directory: 'my-ts-lib',
|
|
||||||
bundler: 'tsc',
|
|
||||||
unitTestRunner: 'none',
|
|
||||||
linter: 'none',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(readJson(tree, 'my-ts-lib/tsconfig.json').nx)
|
|
||||||
.toMatchInlineSnapshot(`
|
|
||||||
{
|
|
||||||
"addTypecheckTarget": false,
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
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 () => {
|
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 () => {
|
||||||
await libraryGenerator(tree, {
|
await libraryGenerator(tree, {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
|
|||||||
@ -1057,12 +1057,6 @@ function createProjectTsConfigs(
|
|||||||
json.references.push({
|
json.references.push({
|
||||||
path: './tsconfig.lib.json',
|
path: './tsconfig.lib.json',
|
||||||
});
|
});
|
||||||
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
||||||
// This applies to `@nx/js/typescript` plugin only.
|
|
||||||
if (options.bundler === 'tsc') {
|
|
||||||
json['nx'] ??= {};
|
|
||||||
json['nx'].addTypecheckTarget = false;
|
|
||||||
}
|
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -1073,12 +1067,6 @@ function createProjectTsConfigs(
|
|||||||
include: [],
|
include: [],
|
||||||
references: [{ path: './tsconfig.lib.json' }],
|
references: [{ path: './tsconfig.lib.json' }],
|
||||||
};
|
};
|
||||||
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
||||||
// This applies to `@nx/js/typescript` plugin only.
|
|
||||||
if (options.bundler === 'tsc') {
|
|
||||||
tsconfig['nx'] ??= {};
|
|
||||||
tsconfig['nx'].addTypecheckTarget = false;
|
|
||||||
}
|
|
||||||
writeJson(
|
writeJson(
|
||||||
tree,
|
tree,
|
||||||
joinPathFragments(options.projectRoot, 'tsconfig.json'),
|
joinPathFragments(options.projectRoot, 'tsconfig.json'),
|
||||||
|
|||||||
@ -466,9 +466,6 @@ describe('NxPlugin Plugin Generator', () => {
|
|||||||
"extends": "../tsconfig.base.json",
|
"extends": "../tsconfig.base.json",
|
||||||
"files": [],
|
"files": [],
|
||||||
"include": [],
|
"include": [],
|
||||||
"nx": {
|
|
||||||
"addTypecheckTarget": false,
|
|
||||||
},
|
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
"path": "./tsconfig.lib.json",
|
"path": "./tsconfig.lib.json",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user