Skip to content

Commit

Permalink
fix(js): do not infer typecheck target for root tsconfig.json (#27950)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
leosvelperez authored Sep 17, 2024
1 parent 81d3529 commit 67ecff1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 73 deletions.
74 changes: 1 addition & 73 deletions packages/js/src/plugins/typescript/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,85 +34,13 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
process.env.NX_CACHE_PROJECT_GRAPH = originalCacheProjectGraph;
});

it('should create nodes for root tsconfig.json files', async () => {
it('should not create nodes for root tsconfig.json files', async () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'package.json': `{}`,
'project.json': `{}`,
'tsconfig.json': `{}`,
'src/index.ts': `console.log('Hello World!');`,
});
expect(await invokeCreateNodesOnMatchingFiles(context, {}))
.toMatchInlineSnapshot(`
{
"projects": {
".": {
"projectType": "library",
"targets": {
"typecheck": {
"cache": true,
"command": "tsc --build --emitDeclarationOnly --pretty --verbose",
"dependsOn": [
"^typecheck",
],
"inputs": [
"production",
"^production",
{
"externalDependencies": [
"typescript",
],
},
],
"metadata": {
"description": "Runs type-checking for the project.",
"help": {
"command": "npx tsc --build --help",
"example": {
"args": [
"--force",
],
},
},
"technologies": [
"typescript",
],
},
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/**/*.js",
"{projectRoot}/**/*.cjs",
"{projectRoot}/**/*.mjs",
"{projectRoot}/**/*.jsx",
"{projectRoot}/**/*.js.map",
"{projectRoot}/**/*.jsx.map",
"{projectRoot}/**/*.d.ts",
"{projectRoot}/**/*.d.cts",
"{projectRoot}/**/*.d.mts",
"{projectRoot}/**/*.d.ts.map",
"{projectRoot}/**/*.d.cts.map",
"{projectRoot}/**/*.d.mts.map",
"{projectRoot}/tsconfig.tsbuildinfo",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
},
},
},
},
}
`);
});

it('should not create nodes when it is not a tsconfig.json file and there is no sibling tsconfig.json file', async () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'package.json': `{}`,
'project.json': `{}`,
'tsconfig.base.json': `{}`,
'src/index.ts': `console.log('Hello World!');`,
});
expect(await invokeCreateNodesOnMatchingFiles(context, {}))
.toMatchInlineSnapshot(`
{
Expand Down
5 changes: 5 additions & 0 deletions packages/js/src/plugins/typescript/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ async function createNodesInternal(
configFilePath
);

// Do not create a project for the workspace root tsconfig files.
if (projectRoot === '.') {
return {};
}

// Do not create a project if package.json and project.json isn't there.
const siblingFiles = readdirSync(join(context.workspaceRoot, projectRoot));
if (
Expand Down

0 comments on commit 67ecff1

Please sign in to comment.