Skip to content

Commit dc41bfe

Browse files
ndcunninghamFrozenPandaz
authored andcommitted
fix(js): Update typescript plugin check for buildable projects (#29431)
<!-- 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 --> Currently, we use `rootDir` to check if the project is buildable. This might not be correct in the case where the transpiled files are inside source. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> It should work the for projects as long as the main / exports files are not source files. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit a77e3ef)
1 parent a24e16f commit dc41bfe

File tree

2 files changed

+101
-98
lines changed

2 files changed

+101
-98
lines changed

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

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
18191819
// Sibling package.json
18201820
await applyFilesToTempFsAndContext(tempFs, context, {
18211821
'libs/my-lib/tsconfig.json': `{}`,
1822-
'libs/my-lib/tsconfig.lib.json': `{}`,
1822+
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
18231823
'libs/my-lib/tsconfig.build.json': `{}`,
18241824
'libs/my-lib/package.json': `{}`,
18251825
});
@@ -1867,7 +1867,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
18671867
// Sibling package.json
18681868
await applyFilesToTempFsAndContext(tempFs, context, {
18691869
'libs/my-lib/tsconfig.json': `{}`,
1870-
'libs/my-lib/tsconfig.lib.json': `{}`,
1870+
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
18711871
'libs/my-lib/tsconfig.build.json': `{}`,
18721872
'libs/my-lib/package.json': `{}`,
18731873
});
@@ -1917,7 +1917,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
19171917
// Sibling package.json
19181918
await applyFilesToTempFsAndContext(tempFs, context, {
19191919
'libs/my-lib/tsconfig.json': `{}`,
1920-
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
1920+
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
19211921
'libs/my-lib/tsconfig.build.json': `{}`,
19221922
'libs/my-lib/package.json': `{"main": "dist/index.js"}`,
19231923
});
@@ -1965,7 +1965,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
19651965
"options": {
19661966
"cwd": "libs/my-lib",
19671967
},
1968-
"outputs": [],
1968+
"outputs": [
1969+
"{projectRoot}/dist",
1970+
],
19691971
"syncGenerators": [
19701972
"@nx/js:typescript-sync",
19711973
],
@@ -1978,8 +1980,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
19781980

19791981
// Sibling project.json
19801982
await applyFilesToTempFsAndContext(tempFs, context, {
1981-
'libs/my-lib/tsconfig.json': `{"compilerOptions": {"rootDir": "src"}}`,
1982-
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
1983+
'libs/my-lib/tsconfig.json': `{}`,
1984+
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
19831985
'libs/my-lib/tsconfig.build.json': `{}`,
19841986
'libs/my-lib/project.json': `{}`,
19851987
});
@@ -2027,7 +2029,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
20272029
"options": {
20282030
"cwd": "libs/my-lib",
20292031
},
2030-
"outputs": [],
2032+
"outputs": [
2033+
"{projectRoot}/dist",
2034+
],
20312035
"syncGenerators": [
20322036
"@nx/js:typescript-sync",
20332037
],
@@ -2043,7 +2047,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
20432047
// Sibling package.json
20442048
await applyFilesToTempFsAndContext(tempFs, context, {
20452049
'libs/my-lib/tsconfig.json': `{}`,
2046-
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
2050+
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
20472051
'libs/my-lib/tsconfig.build.json': `{}`,
20482052
'libs/my-lib/package.json': `{ "main": "dist/index.js" }`,
20492053
});
@@ -2093,7 +2097,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
20932097
"options": {
20942098
"cwd": "libs/my-lib",
20952099
},
2096-
"outputs": [],
2100+
"outputs": [
2101+
"{projectRoot}/dist",
2102+
],
20972103
"syncGenerators": [
20982104
"@nx/js:typescript-sync",
20992105
],
@@ -2110,7 +2116,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
21102116
await applyFilesToTempFsAndContext(tempFs, context, {
21112117
'libs/my-lib/tsconfig.json': `{}`,
21122118
'libs/my-lib/tsconfig.lib.json': `{}`,
2113-
'libs/my-lib/tsconfig.build.json': `{"compilerOptions": {"rootDir": "src"}}`,
2119+
'libs/my-lib/tsconfig.build.json': `{"compilerOptions": {"outDir": "dist"}}`,
21142120
'libs/my-lib/project.json': `{}`,
21152121
});
21162122
expect(
@@ -2159,7 +2165,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
21592165
"options": {
21602166
"cwd": "libs/my-lib",
21612167
},
2162-
"outputs": [],
2168+
"outputs": [
2169+
"{projectRoot}/dist",
2170+
],
21632171
"syncGenerators": [
21642172
"@nx/js:typescript-sync",
21652173
],
@@ -2193,7 +2201,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
21932201
await applyFilesToTempFsAndContext(tempFs, context, {
21942202
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
21952203
compilerOptions: {
2196-
rootDir: 'src',
2204+
outDir: 'dist',
21972205
},
21982206
include: ['src/**/*.ts'],
21992207
exclude: ['src/**/*.spec.ts'],
@@ -2247,7 +2255,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
22472255
"options": {
22482256
"cwd": "libs/my-lib",
22492257
},
2250-
"outputs": [],
2258+
"outputs": [
2259+
"{projectRoot}/dist",
2260+
],
22512261
"syncGenerators": [
22522262
"@nx/js:typescript-sync",
22532263
],
@@ -2272,7 +2282,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
22722282
extends: '../../tsconfig.foo.json',
22732283
include: ['src/**/*.ts'],
22742284
compilerOptions: {
2275-
rootDir: 'src',
2285+
outDir: 'dist',
22762286
},
22772287
}),
22782288
'libs/my-lib/package.json': `{"main": "dist/index.js"}`,
@@ -2326,7 +2336,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
23262336
"options": {
23272337
"cwd": "libs/my-lib",
23282338
},
2329-
"outputs": [],
2339+
"outputs": [
2340+
"{projectRoot}/dist",
2341+
],
23302342
"syncGenerators": [
23312343
"@nx/js:typescript-sync",
23322344
],
@@ -2351,7 +2363,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
23512363
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
23522364
extends: '../../tsconfig.foo.json',
23532365
compilerOptions: {
2354-
rootDir: 'src',
2366+
outDir: 'dist',
23552367
},
23562368
include: ['src/**/*.ts'],
23572369
}),
@@ -2412,7 +2424,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
24122424
"options": {
24132425
"cwd": "libs/my-lib",
24142426
},
2415-
"outputs": [],
2427+
"outputs": [
2428+
"{projectRoot}/dist",
2429+
],
24162430
"syncGenerators": [
24172431
"@nx/js:typescript-sync",
24182432
],
@@ -2428,7 +2442,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
24282442
await applyFilesToTempFsAndContext(tempFs, context, {
24292443
'libs/my-lib/tsconfig.json': '{}',
24302444
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2431-
compilerOptions: { rootDir: 'src' },
2445+
compilerOptions: { outDir: 'dist' },
24322446
include: ['src/**/*.ts'],
24332447
exclude: ['src/**/foo.ts'], // should be ignored because a referenced internal project includes this same pattern
24342448
references: [
@@ -2494,7 +2508,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
24942508
"options": {
24952509
"cwd": "libs/my-lib",
24962510
},
2497-
"outputs": [],
2511+
"outputs": [
2512+
"{projectRoot}/dist",
2513+
],
24982514
"syncGenerators": [
24992515
"@nx/js:typescript-sync",
25002516
],
@@ -2511,7 +2527,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
25112527
await applyFilesToTempFsAndContext(tempFs, context, {
25122528
'libs/my-lib/tsconfig.json': '{}',
25132529
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2514-
compilerOptions: { rootDir: 'src' }, // rootDir is required to determine if the project is buildable
2530+
compilerOptions: { outDir: 'dist' }, // outDir is required to determine if the project is buildable
25152531
include: ['src/**/*.ts'],
25162532
exclude: ['src/**/foo.ts'], // should be ignored
25172533
references: [{ path: './tsconfig.other.json' }],
@@ -2548,7 +2564,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
25482564
await applyFilesToTempFsAndContext(tempFs, context, {
25492565
'libs/my-lib/tsconfig.json': '{}',
25502566
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2551-
compilerOptions: { rootDir: 'src' },
2567+
compilerOptions: { outDir: 'dist' },
25522568
include: ['**/*.ts'],
25532569
exclude: ['**/foo.ts'], // should be ignored
25542570
references: [{ path: './tsconfig.other.json' }],
@@ -2584,7 +2600,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
25842600
await applyFilesToTempFsAndContext(tempFs, context, {
25852601
'libs/my-lib/tsconfig.json': '{}',
25862602
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2587-
compilerOptions: { rootDir: 'src' }, // rooDir is required to determine if the project is buildable
2603+
compilerOptions: { outDir: 'dist' }, // outDir is required to determine if the project is buildable
25882604
include: ['src/**/*.ts'],
25892605
exclude: ['src/**/foo.ts'], // should be ignored
25902606
references: [{ path: './tsconfig.other.json' }],
@@ -2620,7 +2636,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
26202636
await applyFilesToTempFsAndContext(tempFs, context, {
26212637
'libs/my-lib/tsconfig.json': '{}',
26222638
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2623-
compilerOptions: { rootDir: 'src' },
2639+
compilerOptions: { outDir: 'dist' },
26242640
include: ['src/**/*.ts'],
26252641
exclude: ['src/**/foo.ts'], // should be ignored
26262642
references: [{ path: './tsconfig.other.json' }],
@@ -2656,7 +2672,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
26562672
await applyFilesToTempFsAndContext(tempFs, context, {
26572673
'libs/my-lib/tsconfig.json': '{}',
26582674
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2659-
compilerOptions: { rootDir: 'src' },
2675+
compilerOptions: { outDir: 'dist' },
26602676
include: ['src/**/*.ts'],
26612677
exclude: [
26622678
'src/**/foo.ts', // should be ignored
@@ -2696,7 +2712,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
26962712
it('should fall back to named inputs when not using include', async () => {
26972713
await applyFilesToTempFsAndContext(tempFs, context, {
26982714
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2699-
compilerOptions: { rootDir: 'src' },
2715+
compilerOptions: { outDir: 'dist' },
27002716
files: ['main.ts'],
27012717
}),
27022718
'libs/my-lib/tsconfig.json': `{}`,
@@ -2746,19 +2762,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
27462762
"cwd": "libs/my-lib",
27472763
},
27482764
"outputs": [
2749-
"{projectRoot}/**/*.js",
2750-
"{projectRoot}/**/*.cjs",
2751-
"{projectRoot}/**/*.mjs",
2752-
"{projectRoot}/**/*.jsx",
2753-
"{projectRoot}/**/*.js.map",
2754-
"{projectRoot}/**/*.jsx.map",
2755-
"{projectRoot}/**/*.d.ts",
2756-
"{projectRoot}/**/*.d.cts",
2757-
"{projectRoot}/**/*.d.mts",
2758-
"{projectRoot}/**/*.d.ts.map",
2759-
"{projectRoot}/**/*.d.cts.map",
2760-
"{projectRoot}/**/*.d.mts.map",
2761-
"{projectRoot}/tsconfig.lib.tsbuildinfo",
2765+
"{projectRoot}/dist",
27622766
],
27632767
"syncGenerators": [
27642768
"@nx/js:typescript-sync",
@@ -2778,12 +2782,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
27782782
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
27792783
compilerOptions: {
27802784
outFile: '../../dist/libs/my-lib/index.js',
2781-
rootDir: 'src',
27822785
},
27832786
files: ['main.ts'],
27842787
}),
27852788
'libs/my-lib/tsconfig.json': `{}`,
2786-
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
2789+
'libs/my-lib/package.json': `{}`,
27872790
});
27882791
expect(
27892792
await invokeCreateNodesOnMatchingFiles(context, {
@@ -2851,12 +2854,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
28512854
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
28522855
compilerOptions: {
28532856
outDir: '../../dist/libs/my-lib',
2854-
rootDir: 'src',
28552857
},
28562858
files: ['main.ts'],
28572859
}),
28582860
'libs/my-lib/tsconfig.json': `{}`,
2859-
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
2861+
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/index.js"}`,
28602862
});
28612863
expect(
28622864
await invokeCreateNodesOnMatchingFiles(context, {
@@ -2919,7 +2921,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
29192921
it('should add the inline output files when `outDir` is not defined', async () => {
29202922
await applyFilesToTempFsAndContext(tempFs, context, {
29212923
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
2922-
compilerOptions: { rootDir: 'src' },
29232924
files: ['main.ts'],
29242925
}),
29252926
'libs/my-lib/tsconfig.json': `{}`,
@@ -3000,19 +3001,17 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
30003001
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
30013002
compilerOptions: {
30023003
outFile: '../../dist/libs/my-lib/lib.js',
3003-
rootDir: 'src',
30043004
},
30053005
files: ['main.ts'],
30063006
references: [{ path: './tsconfig.other.json' }],
30073007
}),
30083008
'libs/my-lib/tsconfig.other.json': JSON.stringify({
30093009
compilerOptions: {
30103010
outDir: '../../dist/libs/my-lib/other',
3011-
rootDir: 'src',
30123011
},
30133012
include: ['other/**/*.ts'],
30143013
}),
3015-
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/lib.js"}`,
3014+
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/lib.js"}`,
30163015
});
30173016
expect(
30183017
await invokeCreateNodesOnMatchingFiles(context, {
@@ -3087,12 +3086,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
30873086
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
30883087
compilerOptions: {
30893088
outFile: '../../dist/libs/my-lib/index.js',
3090-
rootDir: 'src',
30913089
tsBuildInfoFile: '../../dist/libs/my-lib/my-lib.tsbuildinfo',
30923090
},
30933091
files: ['main.ts'],
30943092
}),
3095-
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
3093+
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/index.js"}`,
30963094
});
30973095
expect(
30983096
await invokeCreateNodesOnMatchingFiles(context, {
@@ -3159,7 +3157,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
31593157
'libs/my-lib/tsconfig.json': '{}',
31603158
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
31613159
compilerOptions: {
3162-
rootDir: 'src',
31633160
tsBuildInfoFile: '../../dist/libs/my-lib/my-lib.tsbuildinfo',
31643161
},
31653162
files: ['main.ts'],
@@ -3239,7 +3236,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
32393236
await applyFilesToTempFsAndContext(tempFs, context, {
32403237
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
32413238
compilerOptions: {
3242-
rootDir: 'src',
32433239
outDir: 'dist',
32443240
tsBuildInfoFile: 'my-lib.tsbuildinfo',
32453241
},
@@ -3312,7 +3308,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
33123308
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
33133309
compilerOptions: {
33143310
outDir: 'dist',
3315-
rootDir: 'src',
33163311
tsBuildInfoFile: 'dist/my-lib.tsbuildinfo',
33173312
},
33183313
files: ['main.ts'],

0 commit comments

Comments
 (0)