@nx/js 20.6.2 → 20.6.4
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 -5
- package/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +2 -1
- package/src/generators/library/library.js +5 -0
- package/src/generators/setup-build/generator.js +4 -0
- package/src/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/util.js +2 -2
- package/src/utils/package-json/update-package-json.d.ts +1 -0
- package/src/utils/package-json/update-package-json.js +42 -1
- package/src/utils/typescript/tsnode-register.d.ts +0 -1
- package/src/utils/typescript/tsnode-register.js +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "20.6.
|
|
3
|
+
"version": "20.6.4",
|
|
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": "20.6.
|
|
43
|
-
"@nx/workspace": "20.6.
|
|
42
|
+
"@nx/devkit": "20.6.4",
|
|
43
|
+
"@nx/workspace": "20.6.4",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -60,8 +60,6 @@
|
|
|
60
60
|
"semver": "^7.5.3",
|
|
61
61
|
"source-map-support": "0.5.19",
|
|
62
62
|
"tinyglobby": "^0.2.12",
|
|
63
|
-
"ts-node": "10.9.1",
|
|
64
|
-
"tsconfig-paths": "^4.1.2",
|
|
65
63
|
"tslib": "^2.3.0"
|
|
66
64
|
},
|
|
67
65
|
"peerDependencies": {
|
|
@@ -425,6 +425,8 @@ function createFiles(tree, options) {
|
|
|
425
425
|
};
|
|
426
426
|
if (options.isUsingTsSolutionConfig &&
|
|
427
427
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
428
|
+
// the file must exist in the TS solution setup
|
|
429
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
428
430
|
return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
|
|
429
431
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
430
432
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -433,6 +435,7 @@ function createFiles(tree, options) {
|
|
|
433
435
|
generateExportsField: true,
|
|
434
436
|
packageJsonPath,
|
|
435
437
|
format: ['esm'],
|
|
438
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
436
439
|
});
|
|
437
440
|
}
|
|
438
441
|
return updatedPackageJson;
|
|
@@ -455,6 +458,7 @@ function createFiles(tree, options) {
|
|
|
455
458
|
}
|
|
456
459
|
if (options.isUsingTsSolutionConfig &&
|
|
457
460
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
461
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
458
462
|
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
459
463
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
460
464
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -463,6 +467,7 @@ function createFiles(tree, options) {
|
|
|
463
467
|
generateExportsField: true,
|
|
464
468
|
packageJsonPath,
|
|
465
469
|
format: ['esm'],
|
|
470
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
466
471
|
});
|
|
467
472
|
}
|
|
468
473
|
if (!options.useProjectJson && options.name !== options.importPath) {
|
|
@@ -232,6 +232,9 @@ function updatePackageJson(tree, projectName, projectRoot, main, outputPath, roo
|
|
|
232
232
|
version: '0.0.1',
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
+
// the file must exist in the TS solution setup, which is the only case this
|
|
236
|
+
// function is called
|
|
237
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
235
238
|
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
236
239
|
main,
|
|
237
240
|
outputPath,
|
|
@@ -240,6 +243,7 @@ function updatePackageJson(tree, projectName, projectRoot, main, outputPath, roo
|
|
|
240
243
|
packageJsonPath,
|
|
241
244
|
rootDir,
|
|
242
245
|
format,
|
|
246
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
243
247
|
});
|
|
244
248
|
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
245
249
|
}
|
|
@@ -29,17 +29,21 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
|
|
|
29
29
|
const port = parseInt(data.toString().match(new RegExp(`${listenAddress}:(?<port>\\d+)`))
|
|
30
30
|
?.groups?.port);
|
|
31
31
|
const registry = `http://${listenAddress}:${port}`;
|
|
32
|
+
const authToken = 'secretVerdaccioToken';
|
|
32
33
|
console.log(`Local registry started on ${registry}`);
|
|
33
34
|
process.env.npm_config_registry = registry;
|
|
34
|
-
(0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "
|
|
35
|
+
(0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "${authToken}" --ws=false`, {
|
|
35
36
|
windowsHide: false,
|
|
36
37
|
});
|
|
38
|
+
// bun
|
|
39
|
+
process.env.BUN_CONFIG_REGISTRY = registry;
|
|
40
|
+
process.env.BUN_CONFIG_TOKEN = authToken;
|
|
37
41
|
// yarnv1
|
|
38
42
|
process.env.YARN_REGISTRY = registry;
|
|
39
43
|
// yarnv2
|
|
40
44
|
process.env.YARN_NPM_REGISTRY_SERVER = registry;
|
|
41
45
|
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;
|
|
42
|
-
console.log('Set npm and yarn config registry to ' + registry);
|
|
46
|
+
console.log('Set npm, bun, and yarn config registry to ' + registry);
|
|
43
47
|
resolve(() => {
|
|
44
48
|
childProcess.kill();
|
|
45
49
|
(0, child_process_1.execSync)(`npm config delete //${listenAddress}:${port}/:_authToken --ws=false`, {
|
|
@@ -67,8 +67,8 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
67
67
|
}
|
|
68
68
|
else if (typeof value === 'object') {
|
|
69
69
|
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
70
|
-
// Skip types
|
|
71
|
-
if (currentKey === 'types') {
|
|
70
|
+
// Skip types and development conditions
|
|
71
|
+
if (currentKey === 'types' || currentKey === 'development') {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
74
|
if (typeof subValue === 'string') {
|
|
@@ -19,6 +19,7 @@ export interface UpdatePackageJsonOption {
|
|
|
19
19
|
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
|
20
20
|
generateLockfile?: boolean;
|
|
21
21
|
packageJsonPath?: string;
|
|
22
|
+
skipDevelopmentExports?: boolean;
|
|
22
23
|
}
|
|
23
24
|
export declare function updatePackageJson(options: UpdatePackageJsonOption, context: ExecutorContext, target: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], fileMap?: ProjectFileMap): void;
|
|
24
25
|
interface Exports {
|
|
@@ -50,7 +50,10 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
50
50
|
options.format = ['cjs'];
|
|
51
51
|
}
|
|
52
52
|
// update package specific settings
|
|
53
|
-
packageJson = getUpdatedPackageJsonContent(packageJson,
|
|
53
|
+
packageJson = getUpdatedPackageJsonContent(packageJson, {
|
|
54
|
+
skipDevelopmentExports: true,
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
54
57
|
// save files
|
|
55
58
|
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, packageJson);
|
|
56
59
|
if (options.generateLockfile) {
|
|
@@ -146,6 +149,19 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
146
149
|
packageJson.exports ??=
|
|
147
150
|
typeof packageJson.exports === 'string' ? {} : { ...packageJson.exports };
|
|
148
151
|
packageJson.exports['./package.json'] ??= './package.json';
|
|
152
|
+
if (!options.skipDevelopmentExports && (hasCjsFormat || hasEsmFormat)) {
|
|
153
|
+
packageJson.exports['.'] ??= {};
|
|
154
|
+
const developmentExports = getDevelopmentExports(options);
|
|
155
|
+
for (const [exportEntry, filePath] of Object.entries(developmentExports)) {
|
|
156
|
+
if (!packageJson.exports[exportEntry]) {
|
|
157
|
+
packageJson.exports[exportEntry] ??= {};
|
|
158
|
+
packageJson.exports[exportEntry]['development'] ??= filePath;
|
|
159
|
+
}
|
|
160
|
+
else if (typeof packageJson.exports[exportEntry] === 'object') {
|
|
161
|
+
packageJson.exports[exportEntry].development ??= filePath;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
149
165
|
}
|
|
150
166
|
if (!options.skipTypings) {
|
|
151
167
|
const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
|
|
@@ -215,6 +231,31 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
215
231
|
}
|
|
216
232
|
return packageJson;
|
|
217
233
|
}
|
|
234
|
+
function getDevelopmentExports(options) {
|
|
235
|
+
const mainRelativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
|
|
236
|
+
const exports = {
|
|
237
|
+
'.': mainRelativeDir + (0, path_1.basename)(options.main),
|
|
238
|
+
};
|
|
239
|
+
if (options.additionalEntryPoints?.length) {
|
|
240
|
+
const jsRegex = /\.[jt]sx?$/;
|
|
241
|
+
for (const file of options.additionalEntryPoints) {
|
|
242
|
+
const { ext: fileExt, name: fileName, base: baseName } = (0, path_1.parse)(file);
|
|
243
|
+
if (!jsRegex.test(fileExt)) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const relativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(file, options.projectRoot);
|
|
247
|
+
const sourceFilePath = relativeDir + baseName;
|
|
248
|
+
const entryRelativeDir = relativeDir.replace(/^\.\/src\//, './');
|
|
249
|
+
const entryFilePath = entryRelativeDir + fileName;
|
|
250
|
+
if (fileName === 'index') {
|
|
251
|
+
const barrelEntry = entryRelativeDir.replace(/\/$/, '');
|
|
252
|
+
exports[barrelEntry] = sourceFilePath;
|
|
253
|
+
}
|
|
254
|
+
exports[entryFilePath] = sourceFilePath;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return exports;
|
|
258
|
+
}
|
|
218
259
|
function getOutputDir(options) {
|
|
219
260
|
const packageJsonDir = options.packageJsonPath
|
|
220
261
|
? (0, path_1.dirname)(options.packageJsonPath)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function tsNodeRegister(file: string, tsConfig?: string): void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsNodeRegister = tsNodeRegister;
|
|
4
|
-
function tsNodeRegister(file, tsConfig) {
|
|
5
|
-
if (!file?.endsWith('.ts'))
|
|
6
|
-
return;
|
|
7
|
-
// Register TS compiler lazily
|
|
8
|
-
require('ts-node').register({
|
|
9
|
-
project: tsConfig,
|
|
10
|
-
compilerOptions: {
|
|
11
|
-
module: 'CommonJS',
|
|
12
|
-
types: ['node'],
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
if (!tsConfig)
|
|
16
|
-
return;
|
|
17
|
-
// Register paths in tsConfig
|
|
18
|
-
const tsconfigPaths = require('tsconfig-paths');
|
|
19
|
-
const { absoluteBaseUrl: baseUrl, paths } = tsconfigPaths.loadConfig(tsConfig);
|
|
20
|
-
if (baseUrl && paths) {
|
|
21
|
-
tsconfigPaths.register({ baseUrl, paths });
|
|
22
|
-
}
|
|
23
|
-
}
|