Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): Update typescript plugin check for buildable projects #29431

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 46 additions & 51 deletions packages/js/src/plugins/typescript/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
// Sibling package.json
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/tsconfig.build.json': `{}`,
'libs/my-lib/package.json': `{}`,
});
Expand Down Expand Up @@ -1744,7 +1744,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
// Sibling package.json
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/tsconfig.build.json': `{}`,
'libs/my-lib/package.json': `{}`,
});
Expand Down Expand Up @@ -1794,7 +1794,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
// Sibling package.json
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/tsconfig.build.json': `{}`,
'libs/my-lib/package.json': `{"main": "dist/index.js"}`,
});
Expand Down Expand Up @@ -1842,7 +1842,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -1855,8 +1857,8 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {

// Sibling project.json
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{"compilerOptions": {"rootDir": "src"}}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/tsconfig.build.json': `{}`,
'libs/my-lib/project.json': `{}`,
});
Expand Down Expand Up @@ -1904,7 +1906,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -1920,7 +1924,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
// Sibling package.json
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"rootDir": "src"}}`,
'libs/my-lib/tsconfig.lib.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/tsconfig.build.json': `{}`,
'libs/my-lib/package.json': `{ "main": "dist/index.js" }`,
});
Expand Down Expand Up @@ -1970,7 +1974,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -1987,7 +1993,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/tsconfig.lib.json': `{}`,
'libs/my-lib/tsconfig.build.json': `{"compilerOptions": {"rootDir": "src"}}`,
'libs/my-lib/tsconfig.build.json': `{"compilerOptions": {"outDir": "dist"}}`,
'libs/my-lib/project.json': `{}`,
});
expect(
Expand Down Expand Up @@ -2036,7 +2042,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand Down Expand Up @@ -2070,7 +2078,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
rootDir: 'src',
outDir: 'dist',
},
include: ['src/**/*.ts'],
exclude: ['src/**/*.spec.ts'],
Expand Down Expand Up @@ -2123,7 +2131,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -2148,7 +2158,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
extends: '../../tsconfig.foo.json',
include: ['src/**/*.ts'],
compilerOptions: {
rootDir: 'src',
outDir: 'dist',
},
}),
'libs/my-lib/package.json': `{"main": "dist/index.js"}`,
Expand Down Expand Up @@ -2201,7 +2211,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -2226,7 +2238,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
extends: '../../tsconfig.foo.json',
compilerOptions: {
rootDir: 'src',
outDir: 'dist',
},
include: ['src/**/*.ts'],
}),
Expand Down Expand Up @@ -2286,7 +2298,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -2302,7 +2316,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
compilerOptions: { outDir: 'dist' },
include: ['src/**/*.ts'],
exclude: ['src/**/foo.ts'], // should be ignored because a referenced internal project includes this same pattern
references: [
Expand Down Expand Up @@ -2367,7 +2381,9 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"options": {
"cwd": "libs/my-lib",
},
"outputs": [],
"outputs": [
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
],
Expand All @@ -2384,7 +2400,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' }, // rootDir is required to determine if the project is buildable
compilerOptions: { outDir: 'dist' }, // outDir is required to determine if the project is buildable
include: ['src/**/*.ts'],
exclude: ['src/**/foo.ts'], // should be ignored
references: [{ path: './tsconfig.other.json' }],
Expand Down Expand Up @@ -2420,7 +2436,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
compilerOptions: { outDir: 'dist' },
include: ['**/*.ts'],
exclude: ['**/foo.ts'], // should be ignored
references: [{ path: './tsconfig.other.json' }],
Expand Down Expand Up @@ -2455,7 +2471,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' }, // rooDir is required to determine if the project is buildable
compilerOptions: { outDir: 'dist' }, // outDir is required to determine if the project is buildable
include: ['src/**/*.ts'],
exclude: ['src/**/foo.ts'], // should be ignored
references: [{ path: './tsconfig.other.json' }],
Expand Down Expand Up @@ -2490,7 +2506,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
compilerOptions: { outDir: 'dist' },
include: ['src/**/*.ts'],
exclude: ['src/**/foo.ts'], // should be ignored
references: [{ path: './tsconfig.other.json' }],
Expand Down Expand Up @@ -2525,7 +2541,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
compilerOptions: { outDir: 'dist' },
include: ['src/**/*.ts'],
exclude: [
'src/**/foo.ts', // should be ignored
Expand Down Expand Up @@ -2564,7 +2580,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
it('should fall back to named inputs when not using include', async () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
compilerOptions: { outDir: 'dist' },
files: ['main.ts'],
}),
'libs/my-lib/tsconfig.json': `{}`,
Expand Down Expand Up @@ -2614,19 +2630,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"cwd": "libs/my-lib",
},
"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.lib.tsbuildinfo",
"{projectRoot}/dist",
],
"syncGenerators": [
"@nx/js:typescript-sync",
Expand All @@ -2646,12 +2650,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
outFile: '../../dist/libs/my-lib/index.js',
rootDir: 'src',
},
files: ['main.ts'],
}),
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
'libs/my-lib/package.json': `{}`,
});
expect(
await invokeCreateNodesOnMatchingFiles(context, {
Expand Down Expand Up @@ -2719,12 +2722,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
outDir: '../../dist/libs/my-lib',
rootDir: 'src',
},
files: ['main.ts'],
}),
'libs/my-lib/tsconfig.json': `{}`,
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/index.js"}`,
});
expect(
await invokeCreateNodesOnMatchingFiles(context, {
Expand Down Expand Up @@ -2786,7 +2788,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
it('should add the inline output files when `outDir` is not defined', async () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: { rootDir: 'src' },
files: ['main.ts'],
}),
'libs/my-lib/tsconfig.json': `{}`,
Expand Down Expand Up @@ -2867,19 +2868,17 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
outFile: '../../dist/libs/my-lib/lib.js',
rootDir: 'src',
},
files: ['main.ts'],
references: [{ path: './tsconfig.other.json' }],
}),
'libs/my-lib/tsconfig.other.json': JSON.stringify({
compilerOptions: {
outDir: '../../dist/libs/my-lib/other',
rootDir: 'src',
},
include: ['other/**/*.ts'],
}),
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/lib.js"}`,
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/lib.js"}`,
});
expect(
await invokeCreateNodesOnMatchingFiles(context, {
Expand Down Expand Up @@ -2952,12 +2951,11 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
outFile: '../../dist/libs/my-lib/index.js',
rootDir: 'src',
tsBuildInfoFile: '../../dist/libs/my-lib/my-lib.tsbuildinfo',
},
files: ['main.ts'],
}),
'libs/my-lib/package.json': `{"main": "dist/libs/my-lib/index.js"}`,
'libs/my-lib/package.json': `{"main": "../../dist/libs/my-lib/index.js"}`,
});
expect(
await invokeCreateNodesOnMatchingFiles(context, {
Expand Down Expand Up @@ -3024,7 +3022,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.json': '{}',
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
rootDir: 'src',
tsBuildInfoFile: '../../dist/libs/my-lib/my-lib.tsbuildinfo',
},
files: ['main.ts'],
Expand Down Expand Up @@ -3104,7 +3101,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
await applyFilesToTempFsAndContext(tempFs, context, {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
rootDir: 'src',
outDir: 'dist',
tsBuildInfoFile: 'my-lib.tsbuildinfo',
},
Expand Down Expand Up @@ -3177,7 +3173,6 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
'libs/my-lib/tsconfig.lib.json': JSON.stringify({
compilerOptions: {
outDir: 'dist',
rootDir: 'src',
tsBuildInfoFile: 'dist/my-lib.tsbuildinfo',
},
files: ['main.ts'],
Expand Down
Loading
Loading