@nx/js 16.6.0 → 16.7.0-beta.0
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 +5 -5
- package/src/executors/node/node.impl.js +1 -1
- package/src/executors/swc/schema.json +21 -3
- package/src/executors/swc/swc.impl.js +27 -2
- package/src/executors/tsc/schema.json +21 -3
- package/src/executors/tsc/tsc.batch-impl.js +9 -2
- package/src/executors/tsc/tsc.impl.d.ts +4 -0
- package/src/executors/tsc/tsc.impl.js +34 -3
- package/src/utils/get-main-file-dir.d.ts +1 -1
- package/src/utils/get-main-file-dir.js +5 -5
- package/src/utils/package-json/update-package-json.d.ts +10 -0
- package/src/utils/package-json/update-package-json.js +59 -33
- package/src/utils/schema.d.ts +2 -0
- package/src/utils/swc/compile-swc.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.7.0-beta.0",
|
|
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,9 +39,9 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.22.9",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nrwl/js": "16.
|
|
43
|
-
"@nx/devkit": "16.
|
|
44
|
-
"@nx/workspace": "16.
|
|
42
|
+
"@nrwl/js": "16.7.0-beta.0",
|
|
43
|
+
"@nx/devkit": "16.7.0-beta.0",
|
|
44
|
+
"@nx/workspace": "16.7.0-beta.0",
|
|
45
45
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"types": "./src/index.d.ts",
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "bda51652665181d38894e7ed910151e60176a9be"
|
|
75
75
|
}
|
|
@@ -265,7 +265,7 @@ function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
|
|
|
265
265
|
const fileName = `${path.parse(buildOptions.main).name}.js`;
|
|
266
266
|
if (buildTargetExecutor === '@nx/js:tsc' ||
|
|
267
267
|
buildTargetExecutor === '@nx/js:swc') {
|
|
268
|
-
outputFileName = path.join((0, get_main_file_dir_1.
|
|
268
|
+
outputFileName = path.join((0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(buildOptions.main, project.data.root), fileName);
|
|
269
269
|
}
|
|
270
270
|
else {
|
|
271
271
|
outputFileName = fileName;
|
|
@@ -11,18 +11,36 @@
|
|
|
11
11
|
"type": "string",
|
|
12
12
|
"description": "The name of the main entry-point file.",
|
|
13
13
|
"x-completion-type": "file",
|
|
14
|
-
"x-completion-glob": "main@(.js|.ts|.tsx)"
|
|
14
|
+
"x-completion-glob": "main@(.js|.ts|.tsx)",
|
|
15
|
+
"x-priority": "important"
|
|
16
|
+
},
|
|
17
|
+
"generateExportsField": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"alias": "exports",
|
|
20
|
+
"description": "Update the output package.json file's 'exports' field. This field is used by Node and bundles.",
|
|
21
|
+
"x-priority": "important",
|
|
22
|
+
"default": false
|
|
23
|
+
},
|
|
24
|
+
"additionalEntryPoints": {
|
|
25
|
+
"type": "array",
|
|
26
|
+
"description": "Additional entry-points to add to exports field in the package.json file.",
|
|
27
|
+
"items": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"x-priority": "important"
|
|
15
31
|
},
|
|
16
32
|
"outputPath": {
|
|
17
33
|
"type": "string",
|
|
18
34
|
"description": "The output path of the generated files.",
|
|
19
|
-
"x-completion-type": "directory"
|
|
35
|
+
"x-completion-type": "directory",
|
|
36
|
+
"x-priority": "important"
|
|
20
37
|
},
|
|
21
38
|
"tsConfig": {
|
|
22
39
|
"type": "string",
|
|
23
40
|
"description": "The path to the Typescript configuration file.",
|
|
24
41
|
"x-completion-type": "file",
|
|
25
|
-
"x-completion-glob": "tsconfig.*.json"
|
|
42
|
+
"x-completion-glob": "tsconfig.*.json",
|
|
43
|
+
"x-priority": "important"
|
|
26
44
|
},
|
|
27
45
|
"swcrc": {
|
|
28
46
|
"type": "string",
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.swcExecutor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const assets_1 = require("../../utils/assets/assets");
|
|
6
7
|
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const fast_glob_1 = require("fast-glob");
|
|
7
9
|
const path_1 = require("path");
|
|
8
10
|
const assets_2 = require("../../utils/assets");
|
|
9
11
|
const check_dependencies_1 = require("../../utils/check-dependencies");
|
|
@@ -69,13 +71,23 @@ function swcExecutor(_options, context) {
|
|
|
69
71
|
// - other libraries that are not dependent on the current project
|
|
70
72
|
options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath);
|
|
71
73
|
}
|
|
74
|
+
function determineModuleFormatFromSwcrc(absolutePathToSwcrc) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const swcrc = (0, devkit_1.readJsonFile)(absolutePathToSwcrc);
|
|
77
|
+
return ((_b = (_a = swcrc.module) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.startsWith('es')) ? 'esm' : 'cjs';
|
|
78
|
+
}
|
|
72
79
|
if (options.watch) {
|
|
73
80
|
let disposeFn;
|
|
74
81
|
process.on('SIGINT', () => disposeFn());
|
|
75
82
|
process.on('SIGTERM', () => disposeFn());
|
|
76
83
|
return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, compile_swc_1.compileSwcWatch)(context, options, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
84
|
const assetResult = yield (0, assets_2.copyAssets)(options, context);
|
|
78
|
-
const packageJsonResult = yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), {
|
|
85
|
+
const packageJsonResult = yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [
|
|
86
|
+
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
|
87
|
+
],
|
|
88
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
89
|
+
// TSC can match them correctly based on file names.
|
|
90
|
+
skipTypings: true }), context);
|
|
79
91
|
removeTmpSwcrc(options.swcCliOptions.swcrcPath);
|
|
80
92
|
disposeFn = () => {
|
|
81
93
|
assetResult === null || assetResult === void 0 ? void 0 : assetResult.stop();
|
|
@@ -86,7 +98,12 @@ function swcExecutor(_options, context) {
|
|
|
86
98
|
else {
|
|
87
99
|
return yield tslib_1.__await(yield yield tslib_1.__await((0, compile_swc_1.compileSwc)(context, options, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
100
|
yield (0, assets_2.copyAssets)(options, context);
|
|
89
|
-
yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), {
|
|
101
|
+
yield (0, package_json_1.copyPackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [
|
|
102
|
+
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
|
103
|
+
],
|
|
104
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
105
|
+
// TSC can match them correctly based on file names.
|
|
106
|
+
skipTypings: true, extraDependencies: swcHelperDependency ? [swcHelperDependency] : [] }), context);
|
|
90
107
|
removeTmpSwcrc(options.swcCliOptions.swcrcPath);
|
|
91
108
|
(0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
|
|
92
109
|
}))));
|
|
@@ -99,4 +116,12 @@ function removeTmpSwcrc(swcrcPath) {
|
|
|
99
116
|
(0, fs_extra_1.removeSync)((0, path_1.dirname)(swcrcPath));
|
|
100
117
|
}
|
|
101
118
|
}
|
|
119
|
+
function createEntryPoints(options, context) {
|
|
120
|
+
var _a;
|
|
121
|
+
if (!((_a = options.additionalEntryPoints) === null || _a === void 0 ? void 0 : _a.length))
|
|
122
|
+
return [];
|
|
123
|
+
return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
|
|
124
|
+
cwd: context.root,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
102
127
|
exports.default = swcExecutor;
|
|
@@ -10,7 +10,23 @@
|
|
|
10
10
|
"type": "string",
|
|
11
11
|
"description": "The name of the main entry-point file.",
|
|
12
12
|
"x-completion-type": "file",
|
|
13
|
-
"x-completion-glob": "main@(.js|.ts|.jsx|.tsx)"
|
|
13
|
+
"x-completion-glob": "main@(.js|.ts|.jsx|.tsx)",
|
|
14
|
+
"x-priority": "important"
|
|
15
|
+
},
|
|
16
|
+
"generateExportsField": {
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"alias": "exports",
|
|
19
|
+
"description": "Update the output package.json file's 'exports' field. This field is used by Node and bundles.",
|
|
20
|
+
"default": false,
|
|
21
|
+
"x-priority": "important"
|
|
22
|
+
},
|
|
23
|
+
"additionalEntryPoints": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"description": "Additional entry-points to add to exports field in the package.json file.",
|
|
26
|
+
"items": {
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
"x-priority": "important"
|
|
14
30
|
},
|
|
15
31
|
"rootDir": {
|
|
16
32
|
"type": "string",
|
|
@@ -19,13 +35,15 @@
|
|
|
19
35
|
"outputPath": {
|
|
20
36
|
"type": "string",
|
|
21
37
|
"description": "The output path of the generated files.",
|
|
22
|
-
"x-completion-type": "directory"
|
|
38
|
+
"x-completion-type": "directory",
|
|
39
|
+
"x-priority": "important"
|
|
23
40
|
},
|
|
24
41
|
"tsConfig": {
|
|
25
42
|
"type": "string",
|
|
26
43
|
"description": "The path to the Typescript configuration file.",
|
|
27
44
|
"x-completion-type": "file",
|
|
28
|
-
"x-completion-glob": "tsconfig.*.json"
|
|
45
|
+
"x-completion-glob": "tsconfig.*.json",
|
|
46
|
+
"x-priority": "important"
|
|
29
47
|
},
|
|
30
48
|
"assets": {
|
|
31
49
|
"type": "array",
|
|
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const async_iterator_1 = require("nx/src/utils/async-iterator");
|
|
8
8
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
9
|
+
const tsc_impl_1 = require("./tsc.impl");
|
|
9
10
|
const lib_1 = require("./lib");
|
|
10
11
|
const batch_1 = require("./lib/batch");
|
|
11
12
|
function tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
@@ -47,7 +48,10 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
47
48
|
if (tsConfigTaskInfoMap[tsConfig]) {
|
|
48
49
|
const taskInfo = tsConfigTaskInfoMap[tsConfig];
|
|
49
50
|
taskInfo.assetsHandler.processAllAssetsOnceSync();
|
|
50
|
-
(0, update_package_json_1.updatePackageJson)(taskInfo.options, taskInfo.context,
|
|
51
|
+
(0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, taskInfo.options), { additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(taskInfo.options, context), format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
|
|
52
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
53
|
+
// TSC can match them correctly based on file names.
|
|
54
|
+
skipTypings: true }), taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
|
|
51
55
|
taskInfo.endTime = Date.now();
|
|
52
56
|
}
|
|
53
57
|
};
|
|
@@ -64,7 +68,10 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
64
68
|
const watchAssetsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsFileChangesForAssets)(taskInfos));
|
|
65
69
|
const watchProjectsChangesDisposer = yield tslib_1.__await((0, batch_1.watchTaskProjectsPackageJsonFileChanges)(taskInfos, (changedTaskInfos) => {
|
|
66
70
|
for (const t of changedTaskInfos) {
|
|
67
|
-
(0, update_package_json_1.updatePackageJson)(t.options, t.context,
|
|
71
|
+
(0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, t.options), { additionalEntryPoints: (0, tsc_impl_1.createEntryPoints)(t.options, context), format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
|
|
72
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
73
|
+
// TSC can match them correctly based on file names.
|
|
74
|
+
skipTypings: true }), t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
|
|
68
75
|
}
|
|
69
76
|
}));
|
|
70
77
|
const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import type { TypeScriptCompilationOptions } from '@nx/workspace/src/utilities/typescript/compilation';
|
|
3
3
|
import { ExecutorOptions, NormalizedExecutorOptions } from '../../utils/schema';
|
|
4
|
+
export declare function determineModuleFormatFromTsConfig(absolutePathToTsConfig: string): 'cjs' | 'esm';
|
|
4
5
|
export declare function createTypeScriptCompilationOptions(normalizedOptions: NormalizedExecutorOptions, context: ExecutorContext): TypeScriptCompilationOptions;
|
|
5
6
|
export declare function tscExecutor(_options: ExecutorOptions, context: ExecutorContext): AsyncGenerator<import("../../utils/typescript/compile-typescript-files").TypescriptCompilationResult, any, undefined>;
|
|
7
|
+
export declare function createEntryPoints(options: {
|
|
8
|
+
additionalEntryPoints?: string[];
|
|
9
|
+
}, context: ExecutorContext): string[];
|
|
6
10
|
export default tscExecutor;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tscExecutor = exports.createTypeScriptCompilationOptions = void 0;
|
|
3
|
+
exports.createEntryPoints = exports.tscExecutor = exports.createTypeScriptCompilationOptions = exports.determineModuleFormatFromTsConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = require("typescript");
|
|
6
|
+
const fast_glob_1 = require("fast-glob");
|
|
5
7
|
const copy_assets_handler_1 = require("../../utils/assets/copy-assets-handler");
|
|
6
8
|
const check_dependencies_1 = require("../../utils/check-dependencies");
|
|
7
9
|
const compiler_helper_dependency_1 = require("../../utils/compiler-helper-dependency");
|
|
@@ -10,6 +12,20 @@ const update_package_json_1 = require("../../utils/package-json/update-package-j
|
|
|
10
12
|
const compile_typescript_files_1 = require("../../utils/typescript/compile-typescript-files");
|
|
11
13
|
const watch_for_single_file_changes_1 = require("../../utils/watch-for-single-file-changes");
|
|
12
14
|
const lib_1 = require("./lib");
|
|
15
|
+
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
16
|
+
function determineModuleFormatFromTsConfig(absolutePathToTsConfig) {
|
|
17
|
+
const tsConfig = (0, ts_config_1.readTsConfig)(absolutePathToTsConfig);
|
|
18
|
+
if (tsConfig.options.module === ts.ModuleKind.ES2015 ||
|
|
19
|
+
tsConfig.options.module === ts.ModuleKind.ES2020 ||
|
|
20
|
+
tsConfig.options.module === ts.ModuleKind.ES2022 ||
|
|
21
|
+
tsConfig.options.module === ts.ModuleKind.ESNext) {
|
|
22
|
+
return 'esm';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return 'cjs';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.determineModuleFormatFromTsConfig = determineModuleFormatFromTsConfig;
|
|
13
29
|
function createTypeScriptCompilationOptions(normalizedOptions, context) {
|
|
14
30
|
return {
|
|
15
31
|
outputPath: normalizedOptions.outputPath,
|
|
@@ -48,12 +64,18 @@ function tscExecutor(_options, context) {
|
|
|
48
64
|
}
|
|
49
65
|
const typescriptCompilation = (0, compile_typescript_files_1.compileTypeScriptFiles)(options, tsCompilationOptions, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
66
|
yield assetHandler.processAllAssetsOnce();
|
|
51
|
-
(0, update_package_json_1.updatePackageJson)(options, context,
|
|
67
|
+
(0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context), format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
68
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
69
|
+
// TSC can match them correctly based on file names.
|
|
70
|
+
skipTypings: true }), context, target, dependencies);
|
|
52
71
|
(0, inline_1.postProcessInlinedDependencies)(tsCompilationOptions.outputPath, tsCompilationOptions.projectRoot, inlineProjectGraph);
|
|
53
72
|
}));
|
|
54
73
|
if (options.watch) {
|
|
55
74
|
const disposeWatchAssetChanges = yield tslib_1.__await(assetHandler.watchAndProcessOnAssetChange());
|
|
56
|
-
const disposePackageJsonChanges = yield tslib_1.__await((0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)(options,
|
|
75
|
+
const disposePackageJsonChanges = yield tslib_1.__await((0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)(Object.assign(Object.assign({}, options), { additionalEntryPoints: createEntryPoints(options, context),
|
|
76
|
+
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
77
|
+
// TSC can match them correctly based on file names.
|
|
78
|
+
skipTypings: true, format: [determineModuleFormatFromTsConfig(options.tsConfig)] }), context, target, dependencies)));
|
|
57
79
|
const handleTermination = (exitCode) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
58
80
|
yield typescriptCompilation.close();
|
|
59
81
|
disposeWatchAssetChanges();
|
|
@@ -67,4 +89,13 @@ function tscExecutor(_options, context) {
|
|
|
67
89
|
});
|
|
68
90
|
}
|
|
69
91
|
exports.tscExecutor = tscExecutor;
|
|
92
|
+
function createEntryPoints(options, context) {
|
|
93
|
+
var _a;
|
|
94
|
+
if (!((_a = options.additionalEntryPoints) === null || _a === void 0 ? void 0 : _a.length))
|
|
95
|
+
return [];
|
|
96
|
+
return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
|
|
97
|
+
cwd: context.root,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.createEntryPoints = createEntryPoints;
|
|
70
101
|
exports.default = tscExecutor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function getRelativeDirectoryToProjectRoot(file: string, projectRoot: string): string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getRelativeDirectoryToProjectRoot = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const path_2 = require("nx/src/utils/path");
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
const relativeDir = (0, path_2.normalizePath)((0, path_1.relative)(projectRoot,
|
|
6
|
+
function getRelativeDirectoryToProjectRoot(file, projectRoot) {
|
|
7
|
+
const dir = (0, path_1.dirname)(file);
|
|
8
|
+
const relativeDir = (0, path_2.normalizePath)((0, path_1.relative)(projectRoot, dir));
|
|
9
9
|
return relativeDir === '' ? `./` : `./${relativeDir}/`;
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
11
|
+
exports.getRelativeDirectoryToProjectRoot = getRelativeDirectoryToProjectRoot;
|
|
@@ -5,10 +5,12 @@ export type SupportedFormat = 'cjs' | 'esm';
|
|
|
5
5
|
export interface UpdatePackageJsonOption {
|
|
6
6
|
projectRoot: string;
|
|
7
7
|
main: string;
|
|
8
|
+
additionalEntryPoints?: string[];
|
|
8
9
|
format?: SupportedFormat[];
|
|
9
10
|
outputPath: string;
|
|
10
11
|
outputFileName?: string;
|
|
11
12
|
outputFileExtensionForCjs?: `.${string}`;
|
|
13
|
+
outputFileExtensionForEsm?: `.${string}`;
|
|
12
14
|
skipTypings?: boolean;
|
|
13
15
|
generateExportsField?: boolean;
|
|
14
16
|
excludeLibsInPackageJson?: boolean;
|
|
@@ -17,4 +19,12 @@ export interface UpdatePackageJsonOption {
|
|
|
17
19
|
generateLockfile?: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare function updatePackageJson(options: UpdatePackageJsonOption, context: ExecutorContext, target: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], fileMap?: ProjectFileMap): void;
|
|
22
|
+
interface Exports {
|
|
23
|
+
'.': string;
|
|
24
|
+
[name: string]: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function getExports(options: Pick<UpdatePackageJsonOption, 'main' | 'projectRoot' | 'outputFileName' | 'additionalEntryPoints'> & {
|
|
27
|
+
fileExt: string;
|
|
28
|
+
}): Exports;
|
|
20
29
|
export declare function getUpdatedPackageJsonContent(packageJson: PackageJson, options: UpdatePackageJsonOption): PackageJson;
|
|
30
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUpdatedPackageJsonContent = exports.updatePackageJson = void 0;
|
|
3
|
+
exports.getUpdatedPackageJsonContent = exports.getExports = exports.updatePackageJson = void 0;
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
5
5
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
@@ -88,56 +88,82 @@ function addMissingDependencies(packageJson, { projectName, targetName, configur
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
+
function getExports(options) {
|
|
92
|
+
const mainFile = options.outputFileName
|
|
93
|
+
? options.outputFileName.replace(/\.[tj]s$/, '')
|
|
94
|
+
: (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
|
|
95
|
+
const relativeMainFileDir = options.outputFileName
|
|
96
|
+
? './'
|
|
97
|
+
: (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
|
|
98
|
+
const exports = {
|
|
99
|
+
'.': relativeMainFileDir + mainFile + options.fileExt,
|
|
100
|
+
};
|
|
101
|
+
if (options.additionalEntryPoints) {
|
|
102
|
+
const jsRegex = /\.[jt]sx?$/;
|
|
103
|
+
for (const file of options.additionalEntryPoints) {
|
|
104
|
+
const { ext: fileExt, name: fileName } = (0, path_1.parse)(file);
|
|
105
|
+
const relativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(file, options.projectRoot);
|
|
106
|
+
const sourceFilePath = relativeDir + fileName;
|
|
107
|
+
const entryFilepath = sourceFilePath.replace(/^\.\/src\//, './');
|
|
108
|
+
const isJsFile = jsRegex.test(fileExt);
|
|
109
|
+
exports[isJsFile ? entryFilepath : entryFilepath + fileExt] =
|
|
110
|
+
sourceFilePath + (isJsFile ? options.fileExt : fileExt);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return exports;
|
|
114
|
+
}
|
|
115
|
+
exports.getExports = getExports;
|
|
91
116
|
function getUpdatedPackageJsonContent(packageJson, options) {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
93
|
-
var
|
|
117
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
118
|
+
var _h;
|
|
94
119
|
// Default is CJS unless esm is explicitly passed.
|
|
95
120
|
const hasCjsFormat = !options.format || ((_a = options.format) === null || _a === void 0 ? void 0 : _a.includes('cjs'));
|
|
96
121
|
const hasEsmFormat = (_b = options.format) === null || _b === void 0 ? void 0 : _b.includes('esm');
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
: Object.assign({ '.': {} }, packageJson.exports);
|
|
103
|
-
const mainJsFile = (_c = options.outputFileName) !== null && _c !== void 0 ? _c : `${relativeMainFileDir}${mainFile}.js`;
|
|
122
|
+
if (options.generateExportsField) {
|
|
123
|
+
packageJson.exports =
|
|
124
|
+
typeof packageJson.exports === 'string' ? {} : Object.assign({}, packageJson.exports);
|
|
125
|
+
packageJson.exports['./package.json'] = './package.json';
|
|
126
|
+
}
|
|
104
127
|
if (hasEsmFormat) {
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
const esmExports = getExports(Object.assign(Object.assign({}, options), { fileExt: (_c = options.outputFileExtensionForEsm) !== null && _c !== void 0 ? _c : '.js' }));
|
|
129
|
+
packageJson.module = esmExports['.'];
|
|
107
130
|
if (!hasCjsFormat) {
|
|
108
131
|
packageJson.type = 'module';
|
|
109
|
-
(
|
|
132
|
+
(_d = packageJson.main) !== null && _d !== void 0 ? _d : (packageJson.main = esmExports['.']);
|
|
110
133
|
}
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(_g = exports['.']) !== null && _g !== void 0 ? _g : (exports['.'] = mainJsFile);
|
|
134
|
+
if (options.generateExportsField) {
|
|
135
|
+
for (const [exportEntry, filePath] of Object.entries(esmExports)) {
|
|
136
|
+
packageJson.exports[exportEntry] = hasCjsFormat
|
|
137
|
+
? { import: filePath }
|
|
138
|
+
: filePath;
|
|
117
139
|
}
|
|
118
140
|
}
|
|
119
141
|
}
|
|
120
142
|
// CJS output may have .cjs or .js file extensions.
|
|
121
143
|
// Bundlers like rollup and esbuild supports .cjs for CJS and .js for ESM.
|
|
122
|
-
// Bundlers/Compilers like webpack, tsc, swc do not have different file extensions.
|
|
144
|
+
// Bundlers/Compilers like webpack, tsc, swc do not have different file extensions (unless you use .mts or .cts in source).
|
|
123
145
|
if (hasCjsFormat) {
|
|
124
|
-
const {
|
|
125
|
-
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
146
|
+
const cjsExports = getExports(Object.assign(Object.assign({}, options), { fileExt: (_e = options.outputFileExtensionForCjs) !== null && _e !== void 0 ? _e : '.js' }));
|
|
147
|
+
packageJson.main = cjsExports['.'];
|
|
148
|
+
if (!hasEsmFormat) {
|
|
149
|
+
packageJson.type = 'commonjs';
|
|
150
|
+
}
|
|
151
|
+
if (options.generateExportsField) {
|
|
152
|
+
for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
|
|
153
|
+
if (hasEsmFormat) {
|
|
154
|
+
(_f = (_h = packageJson.exports[exportEntry])['default']) !== null && _f !== void 0 ? _f : (_h['default'] = filePath);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
packageJson.exports[exportEntry] = filePath;
|
|
158
|
+
}
|
|
133
159
|
}
|
|
134
160
|
}
|
|
135
161
|
}
|
|
136
|
-
if (options.generateExportsField) {
|
|
137
|
-
packageJson.exports = exports;
|
|
138
|
-
}
|
|
139
162
|
if (!options.skipTypings) {
|
|
140
|
-
|
|
163
|
+
const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
|
|
164
|
+
const relativeMainFileDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
|
|
165
|
+
const typingsFile = `${relativeMainFileDir}${mainFile}.d.ts`;
|
|
166
|
+
packageJson.types = (_g = packageJson.types) !== null && _g !== void 0 ? _g : typingsFile;
|
|
141
167
|
}
|
|
142
168
|
return packageJson;
|
|
143
169
|
}
|
package/src/utils/schema.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ function getSwcCmd({ swcrcPath, srcPath, destPath }, watch = false) {
|
|
|
13
13
|
let swcCmd = `${packageManager.exec} swc ${
|
|
14
14
|
// TODO(jack): clean this up when we remove inline module support
|
|
15
15
|
// Handle root project
|
|
16
|
-
srcPath === '.' ? 'src' : srcPath} -d ${destPath} --config-file=${swcrcPath}`;
|
|
16
|
+
srcPath === '.' ? 'src' : srcPath} -d ${srcPath === '.' ? `${destPath}/src` : destPath} --config-file=${swcrcPath}`;
|
|
17
17
|
return watch ? swcCmd.concat(' --watch') : swcCmd;
|
|
18
18
|
}
|
|
19
19
|
function getTypeCheckOptions(normalizedOptions) {
|