@nx/js 19.5.3 → 19.5.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 +4 -4
- package/src/executors/swc/swc.impl.js +0 -6
- package/src/executors/tsc/schema.json +5 -0
- package/src/executors/tsc/tsc.batch-impl.js +0 -6
- package/src/executors/tsc/tsc.impl.js +0 -6
- package/src/executors/verdaccio/schema.d.ts +1 -0
- package/src/executors/verdaccio/schema.json +4 -0
- package/src/executors/verdaccio/verdaccio.impl.js +4 -1
- package/src/plugins/typescript/plugin.js +36 -26
- package/src/utils/package-json/update-package-json.js +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "19.5.
|
|
3
|
+
"version": "19.5.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": {
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"semver": "^7.5.3",
|
|
59
59
|
"source-map-support": "0.5.19",
|
|
60
60
|
"tslib": "^2.3.0",
|
|
61
|
-
"@nx/devkit": "19.5.
|
|
62
|
-
"@nx/workspace": "19.5.
|
|
63
|
-
"@nrwl/js": "19.5.
|
|
61
|
+
"@nx/devkit": "19.5.4",
|
|
62
|
+
"@nx/workspace": "19.5.4",
|
|
63
|
+
"@nrwl/js": "19.5.4"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"verdaccio": "^5.0.4"
|
|
@@ -102,9 +102,6 @@ async function* swcExecutor(_options, context) {
|
|
|
102
102
|
format: [
|
|
103
103
|
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
|
104
104
|
],
|
|
105
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
106
|
-
// TSC can match them correctly based on file names.
|
|
107
|
-
skipTypings: true,
|
|
108
105
|
}, context);
|
|
109
106
|
removeTmpSwcrc(options.swcCliOptions.swcrcPath);
|
|
110
107
|
disposeFn = () => {
|
|
@@ -122,9 +119,6 @@ async function* swcExecutor(_options, context) {
|
|
|
122
119
|
format: [
|
|
123
120
|
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
|
124
121
|
],
|
|
125
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
126
|
-
// TSC can match them correctly based on file names.
|
|
127
|
-
skipTypings: true,
|
|
128
122
|
extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
|
|
129
123
|
}, context);
|
|
130
124
|
removeTmpSwcrc(options.swcCliOptions.swcrcPath);
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"x-completion-type": "directory",
|
|
39
39
|
"x-priority": "important"
|
|
40
40
|
},
|
|
41
|
+
"outputFileName": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "The path to the main file relative to the outputPath",
|
|
44
|
+
"x-completion-type": "file"
|
|
45
|
+
},
|
|
41
46
|
"tsConfig": {
|
|
42
47
|
"type": "string",
|
|
43
48
|
"description": "The path to the Typescript configuration file.",
|
|
@@ -51,9 +51,6 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
51
51
|
...taskInfo.options,
|
|
52
52
|
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(taskInfo.options.additionalEntryPoints, context.root),
|
|
53
53
|
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
|
|
54
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
55
|
-
// TSC can match them correctly based on file names.
|
|
56
|
-
skipTypings: true,
|
|
57
54
|
}, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
|
|
58
55
|
taskInfo.endTime = Date.now();
|
|
59
56
|
}
|
|
@@ -80,9 +77,6 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
80
77
|
...t.options,
|
|
81
78
|
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(t.options.additionalEntryPoints, context.root),
|
|
82
79
|
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
|
|
83
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
84
|
-
// TSC can match them correctly based on file names.
|
|
85
|
-
skipTypings: true,
|
|
86
80
|
}, t.context, t.projectGraphNode, t.buildableProjectNodeDependencies);
|
|
87
81
|
}
|
|
88
82
|
});
|
|
@@ -67,9 +67,6 @@ async function* tscExecutor(_options, context) {
|
|
|
67
67
|
...options,
|
|
68
68
|
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
|
|
69
69
|
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
70
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
71
|
-
// TSC can match them correctly based on file names.
|
|
72
|
-
skipTypings: true,
|
|
73
70
|
}, context, target, dependencies);
|
|
74
71
|
(0, inline_1.postProcessInlinedDependencies)(tsCompilationOptions.outputPath, tsCompilationOptions.projectRoot, inlineProjectGraph);
|
|
75
72
|
});
|
|
@@ -83,9 +80,6 @@ async function* tscExecutor(_options, context) {
|
|
|
83
80
|
const disposePackageJsonChanges = await (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)({
|
|
84
81
|
...options,
|
|
85
82
|
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
|
|
86
|
-
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
87
|
-
// TSC can match them correctly based on file names.
|
|
88
|
-
skipTypings: true,
|
|
89
83
|
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
90
84
|
}, context, target, dependencies));
|
|
91
85
|
const handleTermination = async (exitCode) => {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"type": "number",
|
|
21
21
|
"description": "Port of local registry that Verdaccio should listen to"
|
|
22
22
|
},
|
|
23
|
+
"listenAddress": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Listen address that Verdaccio should listen to"
|
|
26
|
+
},
|
|
23
27
|
"config": {
|
|
24
28
|
"type": "string",
|
|
25
29
|
"description": "Path to the custom Verdaccio config file"
|
|
@@ -104,7 +104,10 @@ function createVerdaccioOptions(options, workspaceRoot) {
|
|
|
104
104
|
options.port ??= 4873; // set default port if config is not provided
|
|
105
105
|
}
|
|
106
106
|
if (options.port) {
|
|
107
|
-
|
|
107
|
+
const listenAddress = options.listenAddress
|
|
108
|
+
? `${options.listenAddress}:${options.port.toString()}`
|
|
109
|
+
: options.port.toString();
|
|
110
|
+
verdaccioArgs.push('--listen', listenAddress);
|
|
108
111
|
}
|
|
109
112
|
return verdaccioArgs;
|
|
110
113
|
}
|
|
@@ -13,7 +13,9 @@ const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
|
13
13
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
14
14
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
15
15
|
function readTargetsCache(cachePath) {
|
|
16
|
-
return
|
|
16
|
+
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, node_fs_1.existsSync)(cachePath)
|
|
17
|
+
? (0, devkit_1.readJsonFile)(cachePath)
|
|
18
|
+
: {};
|
|
17
19
|
}
|
|
18
20
|
function writeTargetsToCache(cachePath, results) {
|
|
19
21
|
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
@@ -90,7 +92,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
90
92
|
let internalProjectReferences;
|
|
91
93
|
// Typecheck target
|
|
92
94
|
if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' && options.typecheck) {
|
|
93
|
-
internalProjectReferences = resolveInternalProjectReferences(
|
|
95
|
+
internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
94
96
|
const targetName = options.typecheck.targetName;
|
|
95
97
|
if (!targets[targetName]) {
|
|
96
98
|
let command = `tsc --build --emitDeclarationOnly --pretty --verbose`;
|
|
@@ -112,7 +114,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
112
114
|
}
|
|
113
115
|
// Build target
|
|
114
116
|
if (options.build && (0, node_path_1.basename)(configFilePath) === options.build.configName) {
|
|
115
|
-
internalProjectReferences ??= resolveInternalProjectReferences(
|
|
117
|
+
internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
116
118
|
const targetName = options.build.targetName;
|
|
117
119
|
targets[targetName] = {
|
|
118
120
|
dependsOn: [`^${targetName}`],
|
|
@@ -137,9 +139,11 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
137
139
|
[configFilePath, tsConfig],
|
|
138
140
|
...Object.entries(internalProjectReferences),
|
|
139
141
|
];
|
|
142
|
+
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
140
143
|
projectTsConfigFiles.forEach(([configPath, config]) => {
|
|
141
144
|
configFiles.add(configPath);
|
|
142
|
-
(
|
|
145
|
+
const offset = (0, node_path_1.relative)(absoluteProjectRoot, (0, node_path_1.dirname)(configPath));
|
|
146
|
+
(config.raw?.include ?? []).forEach((p) => includePaths.add((0, node_path_1.join)(offset, p)));
|
|
143
147
|
if (config.raw?.exclude) {
|
|
144
148
|
/**
|
|
145
149
|
* We need to filter out the exclude paths that are already included in
|
|
@@ -173,7 +177,7 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
173
177
|
if (excludePaths.size) {
|
|
174
178
|
inputs.push(...Array.from(excludePaths).map((p) => `!${pathToInputOrOutput((0, devkit_1.joinPathFragments)(projectRoot, p), workspaceRoot, projectRoot)}`));
|
|
175
179
|
}
|
|
176
|
-
if (hasExternalProjectReferences(configFilePath, tsConfig)) {
|
|
180
|
+
if (hasExternalProjectReferences(configFilePath, tsConfig, workspaceRoot, projectRoot)) {
|
|
177
181
|
// Importing modules from a referenced project will load its output declaration files (d.ts)
|
|
178
182
|
// https://www.typescriptlang.org/docs/handbook/project-references.html#what-is-a-project-reference
|
|
179
183
|
inputs.push({ dependentTasksOutputFiles: '**/*.d.ts' });
|
|
@@ -251,18 +255,17 @@ function getExtendedConfigFiles(tsConfigPath, tsConfig) {
|
|
|
251
255
|
}
|
|
252
256
|
return Array.from(extendedConfigFiles);
|
|
253
257
|
}
|
|
254
|
-
function resolveInternalProjectReferences(
|
|
258
|
+
function resolveInternalProjectReferences(tsConfig, workspaceRoot, projectRoot, projectReferences = {}) {
|
|
255
259
|
if (!tsConfig.projectReferences?.length) {
|
|
256
260
|
return projectReferences;
|
|
257
261
|
}
|
|
258
|
-
const basePath = getTsConfigBasePath(configFilePath);
|
|
259
262
|
for (const ref of tsConfig.projectReferences) {
|
|
260
263
|
let refConfigPath = ref.path;
|
|
261
264
|
if (projectReferences[refConfigPath]) {
|
|
262
265
|
// Already resolved
|
|
263
266
|
continue;
|
|
264
267
|
}
|
|
265
|
-
if (isExternalProjectReference(refConfigPath,
|
|
268
|
+
if (isExternalProjectReference(refConfigPath, workspaceRoot, projectRoot)) {
|
|
266
269
|
continue;
|
|
267
270
|
}
|
|
268
271
|
if (!refConfigPath.endsWith('.json')) {
|
|
@@ -270,51 +273,58 @@ function resolveInternalProjectReferences(configFilePath, tsConfig, projectRefer
|
|
|
270
273
|
}
|
|
271
274
|
const refTsConfig = readCachedTsConfig(refConfigPath);
|
|
272
275
|
projectReferences[refConfigPath] = refTsConfig;
|
|
273
|
-
resolveInternalProjectReferences(
|
|
276
|
+
resolveInternalProjectReferences(refTsConfig, workspaceRoot, projectRoot, projectReferences);
|
|
274
277
|
}
|
|
275
278
|
return projectReferences;
|
|
276
279
|
}
|
|
277
|
-
function hasExternalProjectReferences(tsConfigPath, tsConfig, seen = new Set()) {
|
|
280
|
+
function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, projectRoot, seen = new Set()) {
|
|
278
281
|
if (!tsConfig.projectReferences?.length) {
|
|
279
282
|
return false;
|
|
280
283
|
}
|
|
281
284
|
seen.add(tsConfigPath);
|
|
282
|
-
const basePath = getTsConfigBasePath(tsConfigPath);
|
|
283
285
|
for (const ref of tsConfig.projectReferences) {
|
|
284
286
|
let refConfigPath = ref.path;
|
|
285
287
|
if (seen.has(refConfigPath)) {
|
|
286
288
|
// Already seen
|
|
287
289
|
continue;
|
|
288
290
|
}
|
|
289
|
-
if (isExternalProjectReference(refConfigPath,
|
|
291
|
+
if (isExternalProjectReference(refConfigPath, workspaceRoot, projectRoot)) {
|
|
290
292
|
return true;
|
|
291
293
|
}
|
|
292
294
|
if (!refConfigPath.endsWith('.json')) {
|
|
293
295
|
refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
|
|
294
296
|
}
|
|
295
297
|
const refTsConfig = readCachedTsConfig(refConfigPath);
|
|
296
|
-
const result = hasExternalProjectReferences(refConfigPath, refTsConfig);
|
|
298
|
+
const result = hasExternalProjectReferences(refConfigPath, refTsConfig, workspaceRoot, projectRoot, seen);
|
|
297
299
|
if (result) {
|
|
298
300
|
return true;
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
303
|
return false;
|
|
302
304
|
}
|
|
303
|
-
function isExternalProjectReference(refTsConfigPath,
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
305
|
+
function isExternalProjectReference(refTsConfigPath, workspaceRoot, projectRoot) {
|
|
306
|
+
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
307
|
+
let currentPath = getTsConfigDirName(refTsConfigPath);
|
|
308
|
+
if ((0, node_path_1.relative)(absoluteProjectRoot, currentPath).startsWith('..')) {
|
|
309
|
+
// it's outside of the project root, so it's an external project reference
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
while (currentPath !== absoluteProjectRoot) {
|
|
313
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(currentPath, 'package.json')) ||
|
|
314
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(currentPath, 'project.json'))) {
|
|
315
|
+
// it's inside a nested project root, so it's and external project reference
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
currentPath = (0, node_path_1.dirname)(currentPath);
|
|
319
|
+
}
|
|
320
|
+
// it's inside the project root, so it's an internal project reference
|
|
321
|
+
return false;
|
|
312
322
|
}
|
|
313
|
-
function
|
|
314
|
-
return (0, node_fs_1.statSync)(tsConfigPath).isFile()
|
|
323
|
+
function getTsConfigDirName(tsConfigPath) {
|
|
324
|
+
return (0, node_fs_1.statSync)(tsConfigPath).isFile()
|
|
325
|
+
? (0, node_path_1.dirname)(tsConfigPath)
|
|
326
|
+
: (0, node_path_1.normalize)(tsConfigPath);
|
|
315
327
|
}
|
|
316
|
-
// TODO: we could probably persist this to disk to avoid reading the same
|
|
317
|
-
// tsconfig files over multiple runs
|
|
318
328
|
const tsConfigCache = new Map();
|
|
319
329
|
function readCachedTsConfig(tsConfigPath) {
|
|
320
330
|
const cacheKey = getTsConfigCacheKey(tsConfigPath);
|
|
@@ -37,6 +37,18 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
37
37
|
? (0, devkit_1.readJsonFile)(pathToPackageJson)
|
|
38
38
|
: { name: context.projectName, version: '0.0.1' };
|
|
39
39
|
}
|
|
40
|
+
if (packageJson.type === 'module') {
|
|
41
|
+
if (options.format?.includes('cjs')) {
|
|
42
|
+
devkit_1.logger.warn(`Package type is set to "module" but "cjs" format is included. Going to use "esm" format instead. You can change the package type to "commonjs" or remove type in the package.json file.`);
|
|
43
|
+
}
|
|
44
|
+
options.format = ['esm'];
|
|
45
|
+
}
|
|
46
|
+
else if (packageJson.type === 'commonjs') {
|
|
47
|
+
if (options.format?.includes('esm')) {
|
|
48
|
+
devkit_1.logger.warn(`Package type is set to "commonjs" but "esm" format is included. Going to use "cjs" format instead. You can change the package type to "module" or remove type in the package.json file.`);
|
|
49
|
+
}
|
|
50
|
+
options.format = ['cjs'];
|
|
51
|
+
}
|
|
40
52
|
// update package specific settings
|
|
41
53
|
packageJson = getUpdatedPackageJsonContent(packageJson, options);
|
|
42
54
|
// save files
|
|
@@ -115,8 +127,13 @@ function getExports(options) {
|
|
|
115
127
|
const { ext: fileExt, name: fileName } = (0, path_1.parse)(file);
|
|
116
128
|
const relativeDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(file, options.projectRoot);
|
|
117
129
|
const sourceFilePath = relativeDir + fileName;
|
|
118
|
-
const
|
|
130
|
+
const entryRelativeDir = relativeDir.replace(/^\.\/src\//, './');
|
|
131
|
+
const entryFilepath = entryRelativeDir + fileName;
|
|
119
132
|
const isJsFile = jsRegex.test(fileExt);
|
|
133
|
+
if (isJsFile && fileName === 'index') {
|
|
134
|
+
const barrelEntry = entryRelativeDir.replace(/\/$/, '');
|
|
135
|
+
exports[barrelEntry] = sourceFilePath + options.fileExt;
|
|
136
|
+
}
|
|
120
137
|
exports[isJsFile ? entryFilepath : entryFilepath + fileExt] =
|
|
121
138
|
sourceFilePath + (isJsFile ? options.fileExt : fileExt);
|
|
122
139
|
}
|
|
@@ -139,7 +156,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
139
156
|
});
|
|
140
157
|
packageJson.module ??= esmExports['.'];
|
|
141
158
|
if (!hasCjsFormat) {
|
|
142
|
-
packageJson.type
|
|
159
|
+
packageJson.type ??= 'module';
|
|
143
160
|
packageJson.main ??= esmExports['.'];
|
|
144
161
|
}
|
|
145
162
|
if (options.generateExportsField) {
|
|
@@ -160,7 +177,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
|
|
|
160
177
|
});
|
|
161
178
|
packageJson.main ??= cjsExports['.'];
|
|
162
179
|
if (!hasEsmFormat) {
|
|
163
|
-
packageJson.type
|
|
180
|
+
packageJson.type ??= 'commonjs';
|
|
164
181
|
}
|
|
165
182
|
if (options.generateExportsField) {
|
|
166
183
|
for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
|