@nx/js 0.0.0-pr-29705-bc2a0dd → 0.0.0-pr-29408-73bb882
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/executors/node/node.impl.js +21 -2
- package/src/generators/library/files/tsconfig-lib/ts-solution/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/library.js +26 -25
- package/src/generators/library/schema.d.ts +1 -0
- package/src/utils/swc/add-swc-config.d.ts +2 -1
- package/src/utils/swc/add-swc-config.js +23 -7
- package/src/utils/typescript/ts-solution-setup.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-29408-73bb882",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "0.0.0-pr-
|
|
43
|
-
"@nx/workspace": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-29408-73bb882",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-29408-73bb882",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -16,9 +16,25 @@ const get_main_file_dir_1 = require("../../utils/get-main-file-dir");
|
|
|
16
16
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
17
17
|
function debounce(fn, wait) {
|
|
18
18
|
let timeoutId;
|
|
19
|
+
let pendingPromise = null;
|
|
19
20
|
return () => {
|
|
20
21
|
clearTimeout(timeoutId);
|
|
21
|
-
|
|
22
|
+
if (!pendingPromise) {
|
|
23
|
+
pendingPromise = new Promise((resolve, reject) => {
|
|
24
|
+
timeoutId = setTimeout(() => {
|
|
25
|
+
fn()
|
|
26
|
+
.then((result) => {
|
|
27
|
+
pendingPromise = null;
|
|
28
|
+
resolve(result);
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
pendingPromise = null;
|
|
32
|
+
reject(error);
|
|
33
|
+
});
|
|
34
|
+
}, wait);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return pendingPromise;
|
|
22
38
|
};
|
|
23
39
|
}
|
|
24
40
|
async function* nodeExecutor(options, context) {
|
|
@@ -52,7 +68,7 @@ async function* nodeExecutor(options, context) {
|
|
|
52
68
|
let additionalExitHandler = null;
|
|
53
69
|
let currentTask = null;
|
|
54
70
|
const tasks = [];
|
|
55
|
-
yield* (0, async_iterable_1.createAsyncIterable)(async ({ done, next, error }) => {
|
|
71
|
+
yield* (0, async_iterable_1.createAsyncIterable)(async ({ done, next, error, registerCleanup }) => {
|
|
56
72
|
const processQueue = async () => {
|
|
57
73
|
if (tasks.length === 0)
|
|
58
74
|
return;
|
|
@@ -163,6 +179,9 @@ async function* nodeExecutor(options, context) {
|
|
|
163
179
|
await stopAllTasks('SIGHUP');
|
|
164
180
|
process.exit(128 + 1);
|
|
165
181
|
});
|
|
182
|
+
registerCleanup(async () => {
|
|
183
|
+
await stopAllTasks('SIGTERM');
|
|
184
|
+
});
|
|
166
185
|
if (options.runBuildTargetDependencies) {
|
|
167
186
|
// If a all dependencies need to be rebuild on changes, then register with watcher
|
|
168
187
|
// and run through CLI, otherwise only the current project will rebuild.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"rootDir": "src",
|
|
6
6
|
"outDir": "dist",
|
|
7
7
|
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
8
|
-
"emitDeclarationOnly":
|
|
8
|
+
"emitDeclarationOnly": <%= emitDeclarationOnly %>,<% if (compilerOptions.length) { %>
|
|
9
9
|
<%- compilerOptions %>,<% } %>
|
|
10
10
|
"types": ["node"]
|
|
11
11
|
},
|
|
@@ -92,7 +92,8 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
92
92
|
if (options.unitTestRunner === 'jest') {
|
|
93
93
|
const jestCallback = await addJest(tree, options);
|
|
94
94
|
tasks.push(jestCallback);
|
|
95
|
-
if (options.
|
|
95
|
+
if (!options.isUsingTsSolutionConfig &&
|
|
96
|
+
(options.bundler === 'swc' || options.bundler === 'rollup')) {
|
|
96
97
|
replaceJestConfig(tree, options);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -444,10 +445,8 @@ function createFiles(tree, options) {
|
|
|
444
445
|
},
|
|
445
446
|
...determineEntryFields(options),
|
|
446
447
|
};
|
|
447
|
-
if (options.
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
else if (options.bundler !== 'vite' && options.bundler !== 'rollup') {
|
|
448
|
+
if (options.isUsingTsSolutionConfig &&
|
|
449
|
+
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
451
450
|
return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
|
|
452
451
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
453
452
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -476,21 +475,17 @@ function createFiles(tree, options) {
|
|
|
476
475
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
|
|
477
476
|
packageJson.files = ['dist', '!**/*.tsbuildinfo'];
|
|
478
477
|
}
|
|
479
|
-
if (options.isUsingTsSolutionConfig
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
packageJsonPath,
|
|
491
|
-
format: ['esm'],
|
|
492
|
-
});
|
|
493
|
-
}
|
|
478
|
+
if (options.isUsingTsSolutionConfig &&
|
|
479
|
+
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
480
|
+
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
481
|
+
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
482
|
+
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
483
|
+
projectRoot: options.projectRoot,
|
|
484
|
+
rootDir: (0, path_1.join)(options.projectRoot, 'src'),
|
|
485
|
+
generateExportsField: true,
|
|
486
|
+
packageJsonPath,
|
|
487
|
+
format: ['esm'],
|
|
488
|
+
});
|
|
494
489
|
}
|
|
495
490
|
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
496
491
|
}
|
|
@@ -521,12 +516,12 @@ async function addJest(tree, options) {
|
|
|
521
516
|
setupFile: 'none',
|
|
522
517
|
supportTsx: false,
|
|
523
518
|
skipSerializers: true,
|
|
524
|
-
testEnvironment: options.testEnvironment,
|
|
519
|
+
testEnvironment: options.testEnvironment ?? 'node',
|
|
525
520
|
skipFormat: true,
|
|
526
|
-
compiler: options.
|
|
527
|
-
?
|
|
528
|
-
: options.bundler === '
|
|
529
|
-
? '
|
|
521
|
+
compiler: options.shouldUseSwcJest
|
|
522
|
+
? 'swc'
|
|
523
|
+
: options.bundler === 'tsc'
|
|
524
|
+
? 'tsc'
|
|
530
525
|
: undefined,
|
|
531
526
|
runtimeTsconfigFileName: 'tsconfig.lib.json',
|
|
532
527
|
});
|
|
@@ -647,6 +642,9 @@ async function normalizeOptions(tree, options) {
|
|
|
647
642
|
options.minimal ??= false;
|
|
648
643
|
// We default to generate a project.json file if the new setup is not being used
|
|
649
644
|
options.useProjectJson ??= !isUsingTsSolutionConfig;
|
|
645
|
+
const shouldUseSwcJest = options.bundler === 'swc' ||
|
|
646
|
+
options.bundler === 'rollup' ||
|
|
647
|
+
isUsingTsSolutionConfig;
|
|
650
648
|
return {
|
|
651
649
|
...options,
|
|
652
650
|
fileName,
|
|
@@ -659,6 +657,7 @@ async function normalizeOptions(tree, options) {
|
|
|
659
657
|
importPath,
|
|
660
658
|
hasPlugin,
|
|
661
659
|
isUsingTsSolutionConfig,
|
|
660
|
+
shouldUseSwcJest,
|
|
662
661
|
};
|
|
663
662
|
}
|
|
664
663
|
function addProjectDependencies(tree, options) {
|
|
@@ -742,6 +741,7 @@ function createProjectTsConfigs(tree, options) {
|
|
|
742
741
|
outDir: options.bundler === 'tsc'
|
|
743
742
|
? 'dist'
|
|
744
743
|
: `out-tsc/${options.projectRoot.split('/').pop()}`,
|
|
744
|
+
emitDeclarationOnly: options.bundler === 'tsc' ? false : true,
|
|
745
745
|
});
|
|
746
746
|
// tsconfig.json
|
|
747
747
|
if (options.isUsingTsSolutionConfig) {
|
|
@@ -903,6 +903,7 @@ function determineEntryFields(options) {
|
|
|
903
903
|
case 'none': {
|
|
904
904
|
if (options.isUsingTsSolutionConfig) {
|
|
905
905
|
return {
|
|
906
|
+
type: 'module',
|
|
906
907
|
main: options.js ? './src/index.js' : './src/index.ts',
|
|
907
908
|
types: options.js ? './src/index.js' : './src/index.ts',
|
|
908
909
|
exports: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
2
|
export declare const defaultExclude: string[];
|
|
3
|
-
export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6'): void;
|
|
3
|
+
export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
|
|
4
|
+
export declare function addSwcTestConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultExclude = void 0;
|
|
4
4
|
exports.addSwcConfig = addSwcConfig;
|
|
5
|
+
exports.addSwcTestConfig = addSwcTestConfig;
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
exports.defaultExclude = [
|
|
7
8
|
'jest.config.ts',
|
|
@@ -11,17 +12,25 @@ exports.defaultExclude = [
|
|
|
11
12
|
'./**/jest-setup.ts$',
|
|
12
13
|
'.*.js$',
|
|
13
14
|
];
|
|
14
|
-
const swcOptionsString = (type = 'commonjs') => `{
|
|
15
|
+
const swcOptionsString = (type = 'commonjs', exclude, supportTsx) => `{
|
|
15
16
|
"jsc": {
|
|
16
17
|
"target": "es2017",
|
|
17
18
|
"parser": {
|
|
18
19
|
"syntax": "typescript",
|
|
19
20
|
"decorators": true,
|
|
20
|
-
"dynamicImport": true
|
|
21
|
+
"dynamicImport": true${supportTsx
|
|
22
|
+
? `,
|
|
23
|
+
"tsx": true`
|
|
24
|
+
: ''}
|
|
21
25
|
},
|
|
22
26
|
"transform": {
|
|
23
27
|
"decoratorMetadata": true,
|
|
24
|
-
"legacyDecorator": true
|
|
28
|
+
"legacyDecorator": true${supportTsx
|
|
29
|
+
? `,
|
|
30
|
+
"react": {
|
|
31
|
+
"runtime": "automatic"
|
|
32
|
+
}`
|
|
33
|
+
: ''}
|
|
25
34
|
},
|
|
26
35
|
"keepClassNames": true,
|
|
27
36
|
"externalHelpers": true,
|
|
@@ -31,11 +40,18 @@ const swcOptionsString = (type = 'commonjs') => `{
|
|
|
31
40
|
"type": "${type}"
|
|
32
41
|
},
|
|
33
42
|
"sourceMaps": true,
|
|
34
|
-
"exclude": ${JSON.stringify(
|
|
35
|
-
}
|
|
36
|
-
|
|
43
|
+
"exclude": ${JSON.stringify(exclude)}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
function addSwcConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
|
|
37
47
|
const swcrcPath = (0, path_1.join)(projectDir, '.swcrc');
|
|
38
48
|
if (tree.exists(swcrcPath))
|
|
39
49
|
return;
|
|
40
|
-
tree.write(swcrcPath, swcOptionsString(type));
|
|
50
|
+
tree.write(swcrcPath, swcOptionsString(type, exports.defaultExclude, supportTsx));
|
|
51
|
+
}
|
|
52
|
+
function addSwcTestConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
|
|
53
|
+
const swcrcPath = (0, path_1.join)(projectDir, '.spec.swcrc');
|
|
54
|
+
if (tree.exists(swcrcPath))
|
|
55
|
+
return;
|
|
56
|
+
tree.write(swcrcPath, swcOptionsString(type, [], supportTsx));
|
|
41
57
|
}
|
|
@@ -185,7 +185,7 @@ function getProjectType(tree, projectRoot, projectType) {
|
|
|
185
185
|
const packageJson = tree.exists(packageJsonPath)
|
|
186
186
|
? (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))
|
|
187
187
|
: null;
|
|
188
|
-
if (packageJson?.exports)
|
|
189
|
-
return '
|
|
190
|
-
return '
|
|
188
|
+
if (!packageJson?.exports)
|
|
189
|
+
return 'application';
|
|
190
|
+
return 'library';
|
|
191
191
|
}
|