Skip to content

Commit 4bf937e

Browse files
authored
fix(js): improve @nx/js/typescript plugin check for buildable libraries (#32405)
## Current Behavior The `@nx/js/typescript` plugin exhibits the following wrong behaviors when it comes to determining whether a project is buildable: - Having a custom conditional export other than `development` pointing to a source file means the project is not buildable - Having any conditional export pointing to source files means the project is not buildable - It falls back to check against included files when `outDir` is defined The above creates issues where some buildable libraries are not identified. ## Expected Behavior The `@nx/js/typescript` plugin should behave as follows (simplified) when it comes to determining whether a project is buildable: - If `outFile` is defined: - If the `.` entry point is defined and it's pointing to the `outFile` or any of its conditional exports are pointing to the `outFile`, it's buildable - If `exports` is not defined and `main` or `module` are defined and pointing to the `outFile`, it's buildable - Otherwise, it's not buildable - Otherwise, if `outDir` is defined: - If the `.` entry point is defined and it's pointing to a path contained in the `outDir` or any of its conditional exports are pointing to a path contained in the `outDir`, it's buildable - If `exports` is not defined and `main` or `module` are defined and pointing to a path contained in the `outDir`, it's buildable - Otherwise, it's not buildable - Otherwise (no `outFile` and no `outDir`): - If the `.` entry point is defined and it's pointing to a path not matched by the `files` or `include` patterns or any of its conditional exports are pointing to a path not matched by the `files` or `include` patterns, it's buildable - If `exports` is not defined and `main` or `module` are defined and pointing to a path not matched by the `files` or `include` patterns, it's buildable - Otherwise, it's not buildable The above also ensures that custom conditional exports are not a factor, given that all that is needed is that at least one conditional export is deemed non-buildable. ## Related Issue(s) Fixes #32116 Fixes #32290
1 parent 8737c07 commit 4bf937e

3 files changed

Lines changed: 878 additions & 130 deletions

File tree

packages/js/src/plugins/typescript/plugin.spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,7 +6064,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
60646064
await applyFilesToTempFsAndContext(tempFs, context, {
60656065
'libs/my-lib/tsconfig.json': '{}',
60666066
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
6067-
compilerOptions: { outDir: 'build' },
6067+
compilerOptions: {},
60686068
include: ['lib/**/*.ts'],
60696069
}),
60706070
'libs/my-lib/package.json': JSON.stringify({
@@ -6094,7 +6094,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
60946094
await applyFilesToTempFsAndContext(tempFs, context, {
60956095
'libs/my-lib/tsconfig.json': '{}',
60966096
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
6097-
compilerOptions: { outDir: 'build' },
6097+
compilerOptions: {},
60986098
include: ['lib/**/*.ts'],
60996099
}),
61006100
'libs/my-lib/package.json': JSON.stringify({
@@ -6150,7 +6150,19 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
61506150
"cwd": "libs/my-lib",
61516151
},
61526152
"outputs": [
6153-
"{projectRoot}/build",
6153+
"{projectRoot}/**/*.js",
6154+
"{projectRoot}/**/*.cjs",
6155+
"{projectRoot}/**/*.mjs",
6156+
"{projectRoot}/**/*.jsx",
6157+
"{projectRoot}/**/*.js.map",
6158+
"{projectRoot}/**/*.jsx.map",
6159+
"{projectRoot}/**/*.d.ts",
6160+
"{projectRoot}/**/*.d.cts",
6161+
"{projectRoot}/**/*.d.mts",
6162+
"{projectRoot}/**/*.d.ts.map",
6163+
"{projectRoot}/**/*.d.cts.map",
6164+
"{projectRoot}/**/*.d.mts.map",
6165+
"{projectRoot}/tsconfig.lib.tsbuildinfo",
61546166
],
61556167
"syncGenerators": [
61566168
"@nx/js:typescript-sync",

0 commit comments

Comments
 (0)