@nx/js 0.0.0-pr-30565-ba2942e → 0.0.0-pr-29464-73fdcbb
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/migrations.json +9 -0
- 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 -12
- package/src/generators/setup-build/generator.js +4 -0
- package/src/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/plugin.js +136 -42
- package/src/plugins/typescript/util.d.ts +5 -4
- package/src/plugins/typescript/util.js +2 -3
- package/src/utils/buildable-libs-utils.d.ts +0 -2
- package/src/utils/buildable-libs-utils.js +1 -33
- 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/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/utils/typescript/tsnode-register.d.ts +0 -1
- package/src/utils/typescript/tsnode-register.js +0 -23
package/migrations.json
CHANGED
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-29464-73fdcbb",
|
|
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-29464-73fdcbb",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-29464-73fdcbb",
|
|
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) {
|
|
@@ -732,12 +737,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
732
737
|
json.references.push({
|
|
733
738
|
path: './tsconfig.lib.json',
|
|
734
739
|
});
|
|
735
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
736
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
737
|
-
if (options.bundler === 'tsc') {
|
|
738
|
-
json['nx'] ??= {};
|
|
739
|
-
json['nx'].addTypecheckTarget = false;
|
|
740
|
-
}
|
|
741
740
|
return json;
|
|
742
741
|
});
|
|
743
742
|
}
|
|
@@ -749,12 +748,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
749
748
|
include: [],
|
|
750
749
|
references: [{ path: './tsconfig.lib.json' }],
|
|
751
750
|
};
|
|
752
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
753
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
754
|
-
if (options.bundler === 'tsc') {
|
|
755
|
-
tsconfig['nx'] ??= {};
|
|
756
|
-
tsconfig['nx'].addTypecheckTarget = false;
|
|
757
|
-
}
|
|
758
751
|
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
759
752
|
// update root project tsconfig.json references with the new lib tsconfig
|
|
760
753
|
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
@@ -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`, {
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createNodes = exports.createNodesV2 = exports.PLUGIN_NAME = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
6
|
-
const picomatch = require("picomatch");
|
|
7
6
|
const node_fs_1 = require("node:fs");
|
|
8
7
|
const node_path_1 = require("node:path");
|
|
9
8
|
const posix = require("node:path/posix");
|
|
10
9
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
10
|
+
const picomatch = require("picomatch");
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
12
12
|
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 util_1 = require("./util");
|
|
15
|
+
let ts;
|
|
15
16
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
17
|
let tsConfigCache;
|
|
17
18
|
const tsConfigCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
|
|
@@ -144,6 +145,9 @@ async function getConfigFileHash(configFilePath, workspaceRoot, projectRoot, opt
|
|
|
144
145
|
lockFileHash,
|
|
145
146
|
optionsHash,
|
|
146
147
|
...(packageJson ? [(0, file_hasher_1.hashObject)(packageJson)] : []),
|
|
148
|
+
// change this to bust the cache when making changes that would yield
|
|
149
|
+
// different results for the same hash
|
|
150
|
+
(0, file_hasher_1.hashObject)({ bust: 2 }),
|
|
147
151
|
]);
|
|
148
152
|
}
|
|
149
153
|
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, context) {
|
|
@@ -192,13 +196,27 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
192
196
|
// `tsc --build` does not work with `noEmit: true`
|
|
193
197
|
command = `echo "The 'typecheck' target is disabled because one or more project references set 'noEmit: true' in their tsconfig. Remove this property to resolve this issue."`;
|
|
194
198
|
}
|
|
199
|
+
const dependsOn = [`^${targetName}`];
|
|
200
|
+
if (options.build && targets[options.build.targetName]) {
|
|
201
|
+
// we already processed and have a build target
|
|
202
|
+
dependsOn.unshift(options.build.targetName);
|
|
203
|
+
}
|
|
204
|
+
else if (options.build) {
|
|
205
|
+
// check if the project will have a build target
|
|
206
|
+
const buildConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, options.build.configName);
|
|
207
|
+
if (context.configFiles.some((f) => f === buildConfigPath) &&
|
|
208
|
+
(0, util_1.isValidPackageJsonBuildConfig)(retrieveTsConfigFromCache(buildConfigPath, context.workspaceRoot), context.workspaceRoot, projectRoot)) {
|
|
209
|
+
dependsOn.unshift(options.build.targetName);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
195
212
|
targets[targetName] = {
|
|
196
|
-
dependsOn
|
|
213
|
+
dependsOn,
|
|
197
214
|
command,
|
|
198
215
|
options: { cwd: projectRoot },
|
|
199
216
|
cache: true,
|
|
200
217
|
inputs: getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot),
|
|
201
|
-
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot
|
|
218
|
+
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot,
|
|
219
|
+
/* emitDeclarationOnly */ true),
|
|
202
220
|
syncGenerators: ['@nx/js:typescript-sync'],
|
|
203
221
|
metadata: {
|
|
204
222
|
technologies: ['typescript'],
|
|
@@ -225,7 +243,9 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
225
243
|
options: { cwd: projectRoot },
|
|
226
244
|
cache: true,
|
|
227
245
|
inputs: getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot),
|
|
228
|
-
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot
|
|
246
|
+
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot,
|
|
247
|
+
// should be false for build target, but providing it just in case is set to true
|
|
248
|
+
tsConfig.options.emitDeclarationOnly),
|
|
229
249
|
syncGenerators: ['@nx/js:typescript-sync'],
|
|
230
250
|
metadata: {
|
|
231
251
|
technologies: ['typescript'],
|
|
@@ -260,10 +280,57 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
260
280
|
...Object.entries(internalProjectReferences),
|
|
261
281
|
];
|
|
262
282
|
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
283
|
+
if (!ts) {
|
|
284
|
+
ts = require('typescript');
|
|
285
|
+
}
|
|
286
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9869
|
|
287
|
+
const supportedTSExtensions = [
|
|
288
|
+
ts.Extension.Ts,
|
|
289
|
+
ts.Extension.Tsx,
|
|
290
|
+
ts.Extension.Dts,
|
|
291
|
+
ts.Extension.Cts,
|
|
292
|
+
ts.Extension.Dcts,
|
|
293
|
+
ts.Extension.Mts,
|
|
294
|
+
ts.Extension.Dmts,
|
|
295
|
+
];
|
|
296
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9878
|
|
297
|
+
const allSupportedExtensions = [
|
|
298
|
+
ts.Extension.Ts,
|
|
299
|
+
ts.Extension.Tsx,
|
|
300
|
+
ts.Extension.Dts,
|
|
301
|
+
ts.Extension.Js,
|
|
302
|
+
ts.Extension.Jsx,
|
|
303
|
+
ts.Extension.Cts,
|
|
304
|
+
ts.Extension.Dcts,
|
|
305
|
+
ts.Extension.Cjs,
|
|
306
|
+
ts.Extension.Mts,
|
|
307
|
+
ts.Extension.Dmts,
|
|
308
|
+
ts.Extension.Mjs,
|
|
309
|
+
];
|
|
310
|
+
const normalizeInput = (input, config) => {
|
|
311
|
+
const extensions = config.options.allowJs
|
|
312
|
+
? [...allSupportedExtensions]
|
|
313
|
+
: [...supportedTSExtensions];
|
|
314
|
+
if (config.options.resolveJsonModule) {
|
|
315
|
+
extensions.push(ts.Extension.Json);
|
|
316
|
+
}
|
|
317
|
+
const segments = input.split('/');
|
|
318
|
+
// An "includes" path "foo" is implicitly a glob "foo/**/*" if its last
|
|
319
|
+
// segment has no extension, and does not contain any glob characters
|
|
320
|
+
// itself.
|
|
321
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9577-L9585
|
|
322
|
+
if (!/[.*?]/.test(segments.at(-1))) {
|
|
323
|
+
return extensions.map((ext) => `${segments.join('/')}/**/*${ext}`);
|
|
324
|
+
}
|
|
325
|
+
return [input];
|
|
326
|
+
};
|
|
263
327
|
projectTsConfigFiles.forEach(([configPath, config]) => {
|
|
264
328
|
configFiles.add(configPath);
|
|
265
329
|
const offset = (0, node_path_1.relative)(absoluteProjectRoot, (0, node_path_1.dirname)(configPath));
|
|
266
|
-
(config.raw?.include ?? []).forEach((p) =>
|
|
330
|
+
(config.raw?.include ?? []).forEach((p) => {
|
|
331
|
+
const normalized = normalizeInput((0, node_path_1.join)(offset, p), config);
|
|
332
|
+
normalized.forEach((input) => includePaths.add(input));
|
|
333
|
+
});
|
|
267
334
|
if (config.raw?.exclude) {
|
|
268
335
|
/**
|
|
269
336
|
* We need to filter out the exclude paths that are already included in
|
|
@@ -311,7 +378,7 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
311
378
|
inputs.push({ externalDependencies });
|
|
312
379
|
return inputs;
|
|
313
380
|
}
|
|
314
|
-
function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot) {
|
|
381
|
+
function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot, emitDeclarationOnly) {
|
|
315
382
|
const outputs = new Set();
|
|
316
383
|
// We could have more surgical outputs based on the tsconfig options, but the
|
|
317
384
|
// user could override them through the command line and that wouldn't be
|
|
@@ -333,9 +400,18 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
|
|
|
333
400
|
: pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
334
401
|
}
|
|
335
402
|
else if (config.options.outDir) {
|
|
336
|
-
|
|
403
|
+
if (emitDeclarationOnly) {
|
|
404
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, '**/*.d.ts'), workspaceRoot, projectRoot));
|
|
405
|
+
if (tsConfig.options.declarationMap) {
|
|
406
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, '**/*.d.ts.map'), workspaceRoot, projectRoot));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
outputs.add(pathToInputOrOutput(config.options.outDir, workspaceRoot, projectRoot));
|
|
411
|
+
}
|
|
337
412
|
if (config.options.tsBuildInfoFile) {
|
|
338
|
-
if (
|
|
413
|
+
if (emitDeclarationOnly ||
|
|
414
|
+
!(0, node_path_1.normalize)(config.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(config.options.outDir)}${node_path_1.sep}`)) {
|
|
339
415
|
// https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
|
|
340
416
|
outputs.add(pathToInputOrOutput(config.options.tsBuildInfoFile, workspaceRoot, projectRoot));
|
|
341
417
|
}
|
|
@@ -345,6 +421,11 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
|
|
|
345
421
|
const relativeRootDir = (0, node_path_1.relative)(config.options.rootDir, (0, node_path_1.join)(workspaceRoot, projectRoot));
|
|
346
422
|
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, relativeRootDir, `*.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
347
423
|
}
|
|
424
|
+
else if (emitDeclarationOnly) {
|
|
425
|
+
// https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
|
|
426
|
+
const name = (0, node_path_1.basename)(configFilePath, '.json');
|
|
427
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, `${name}.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
428
|
+
}
|
|
348
429
|
}
|
|
349
430
|
else if (config.raw?.include?.length ||
|
|
350
431
|
config.raw?.files?.length ||
|
|
@@ -380,17 +461,15 @@ function pathToInputOrOutput(path, workspaceRoot, projectRoot) {
|
|
|
380
461
|
}
|
|
381
462
|
return (0, devkit_1.joinPathFragments)('{projectRoot}', pathRelativeToProjectRoot);
|
|
382
463
|
}
|
|
383
|
-
function getExtendedConfigFiles(tsConfig, workspaceRoot) {
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
extendedConfigFiles.add(currentExtendedConfigFile.filePath);
|
|
393
|
-
currentExtendedConfigFile = retrieveTsConfigFromCache(currentExtendedConfigFile.filePath, workspaceRoot).extendedConfigFile;
|
|
464
|
+
function getExtendedConfigFiles(tsConfig, workspaceRoot, extendedConfigFiles = new Set(), extendedExternalPackages = new Set()) {
|
|
465
|
+
for (const extendedConfigFile of tsConfig.extendedConfigFiles) {
|
|
466
|
+
if (extendedConfigFile.externalPackage) {
|
|
467
|
+
extendedExternalPackages.add(extendedConfigFile.externalPackage);
|
|
468
|
+
}
|
|
469
|
+
else if (extendedConfigFile.filePath) {
|
|
470
|
+
extendedConfigFiles.add(extendedConfigFile.filePath);
|
|
471
|
+
getExtendedConfigFiles(retrieveTsConfigFromCache(extendedConfigFile.filePath, workspaceRoot), workspaceRoot, extendedConfigFiles, extendedExternalPackages);
|
|
472
|
+
}
|
|
394
473
|
}
|
|
395
474
|
return {
|
|
396
475
|
files: Array.from(extendedConfigFiles),
|
|
@@ -526,44 +605,54 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
|
526
605
|
let extendedFilesHash;
|
|
527
606
|
if (tsConfigCache[relativePath] &&
|
|
528
607
|
tsConfigCache[relativePath].hash === hash) {
|
|
529
|
-
extendedFilesHash = getExtendedFilesHash(tsConfigCache[relativePath].data.
|
|
608
|
+
extendedFilesHash = getExtendedFilesHash(tsConfigCache[relativePath].data.extendedConfigFiles, workspaceRoot);
|
|
530
609
|
if (tsConfigCache[relativePath].extendedFilesHash === extendedFilesHash) {
|
|
531
610
|
return tsConfigCache[relativePath].data;
|
|
532
611
|
}
|
|
533
612
|
}
|
|
534
613
|
const tsConfig = readTsConfig(tsConfigPath, workspaceRoot);
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
614
|
+
const extendedConfigFiles = [];
|
|
615
|
+
if (tsConfig.raw?.extends) {
|
|
616
|
+
const extendsArray = typeof tsConfig.raw.extends === 'string'
|
|
617
|
+
? [tsConfig.raw.extends]
|
|
618
|
+
: tsConfig.raw.extends;
|
|
619
|
+
for (const extendsPath of extendsArray) {
|
|
620
|
+
const extendedConfigFile = resolveExtendedTsConfigPath(extendsPath, (0, node_path_1.dirname)(tsConfigPath));
|
|
621
|
+
if (extendedConfigFile) {
|
|
622
|
+
extendedConfigFiles.push(extendedConfigFile);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
extendedFilesHash ??= getExtendedFilesHash(extendedConfigFiles, workspaceRoot);
|
|
539
627
|
tsConfigCache[relativePath] = {
|
|
540
628
|
data: {
|
|
541
629
|
options: tsConfig.options,
|
|
542
630
|
projectReferences: tsConfig.projectReferences,
|
|
543
631
|
raw: tsConfig.raw,
|
|
544
|
-
|
|
632
|
+
extendedConfigFiles,
|
|
545
633
|
},
|
|
546
634
|
hash,
|
|
547
635
|
extendedFilesHash,
|
|
548
636
|
};
|
|
549
637
|
return tsConfigCache[relativePath].data;
|
|
550
638
|
}
|
|
551
|
-
function getExtendedFilesHash(
|
|
639
|
+
function getExtendedFilesHash(extendedConfigFiles, workspaceRoot) {
|
|
552
640
|
const hashes = [];
|
|
553
|
-
if (!
|
|
641
|
+
if (!extendedConfigFiles.length) {
|
|
554
642
|
return '';
|
|
555
643
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
.extendedConfigFile, workspaceRoot)
|
|
644
|
+
for (const extendedConfigFile of extendedConfigFiles) {
|
|
645
|
+
if (extendedConfigFile.externalPackage) {
|
|
646
|
+
hashes.push(extendedConfigFile.externalPackage);
|
|
647
|
+
}
|
|
648
|
+
else if (extendedConfigFile.filePath) {
|
|
649
|
+
hashes.push(getFileHash(extendedConfigFile.filePath, workspaceRoot));
|
|
650
|
+
hashes.push(getExtendedFilesHash(readTsConfigAndCache(extendedConfigFile.filePath, workspaceRoot)
|
|
651
|
+
.extendedConfigFiles, workspaceRoot));
|
|
652
|
+
}
|
|
563
653
|
}
|
|
564
654
|
return hashes.join('|');
|
|
565
655
|
}
|
|
566
|
-
let ts;
|
|
567
656
|
function readTsConfig(tsConfigPath, workspaceRoot) {
|
|
568
657
|
if (!ts) {
|
|
569
658
|
ts = require('typescript');
|
|
@@ -623,7 +712,8 @@ function resolveExtendedTsConfigPath(tsConfigPath, directory) {
|
|
|
623
712
|
const resolvedPath = require.resolve(tsConfigPath, {
|
|
624
713
|
paths: directory ? [directory] : undefined,
|
|
625
714
|
});
|
|
626
|
-
if (tsConfigPath.startsWith('.')
|
|
715
|
+
if (tsConfigPath.startsWith('.') ||
|
|
716
|
+
!resolvedPath.includes('/node_modules/')) {
|
|
627
717
|
return { filePath: resolvedPath };
|
|
628
718
|
}
|
|
629
719
|
// parse the package from the tsconfig path
|
|
@@ -661,7 +751,7 @@ function toAbsolutePaths(cache, workspaceRoot) {
|
|
|
661
751
|
raw: {
|
|
662
752
|
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
663
753
|
},
|
|
664
|
-
|
|
754
|
+
extendedConfigFiles: data.extendedConfigFiles,
|
|
665
755
|
},
|
|
666
756
|
extendedFilesHash,
|
|
667
757
|
hash,
|
|
@@ -678,8 +768,10 @@ function toAbsolutePaths(cache, workspaceRoot) {
|
|
|
678
768
|
if (data.options.tsBuildInfoFile) {
|
|
679
769
|
updatedCache[key].data.options.tsBuildInfoFile = (0, node_path_1.join)(workspaceRoot, data.options.tsBuildInfoFile);
|
|
680
770
|
}
|
|
681
|
-
if (data.
|
|
682
|
-
updatedCache[key].data.
|
|
771
|
+
if (data.extendedConfigFiles.length) {
|
|
772
|
+
updatedCache[key].data.extendedConfigFiles.forEach((file) => {
|
|
773
|
+
file.filePath = (0, node_path_1.join)(workspaceRoot, file.filePath);
|
|
774
|
+
});
|
|
683
775
|
}
|
|
684
776
|
if (data.projectReferences) {
|
|
685
777
|
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({ ...ref, path: (0, node_path_1.join)(workspaceRoot, ref.path) }));
|
|
@@ -696,7 +788,7 @@ function toRelativePaths(cache, workspaceRoot) {
|
|
|
696
788
|
raw: {
|
|
697
789
|
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
698
790
|
},
|
|
699
|
-
|
|
791
|
+
extendedConfigFiles: data.extendedConfigFiles,
|
|
700
792
|
},
|
|
701
793
|
extendedFilesHash,
|
|
702
794
|
hash,
|
|
@@ -713,8 +805,10 @@ function toRelativePaths(cache, workspaceRoot) {
|
|
|
713
805
|
if (data.options.tsBuildInfoFile) {
|
|
714
806
|
updatedCache[key].data.options.tsBuildInfoFile = posixRelative(workspaceRoot, data.options.tsBuildInfoFile);
|
|
715
807
|
}
|
|
716
|
-
if (data.
|
|
717
|
-
updatedCache[key].data.
|
|
808
|
+
if (data.extendedConfigFiles.length) {
|
|
809
|
+
updatedCache[key].data.extendedConfigFiles.forEach((file) => {
|
|
810
|
+
file.filePath = posixRelative(workspaceRoot, file.filePath);
|
|
811
|
+
});
|
|
718
812
|
}
|
|
719
813
|
if (data.projectReferences) {
|
|
720
814
|
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type TargetConfiguration } from '@nx/devkit';
|
|
2
2
|
import { type PackageManagerCommands } from 'nx/src/utils/package-manager';
|
|
3
3
|
import { type ParsedCommandLine } from 'typescript';
|
|
4
|
+
export type ExtendedConfigFile = {
|
|
5
|
+
filePath: string;
|
|
6
|
+
externalPackage?: string;
|
|
7
|
+
};
|
|
4
8
|
export type ParsedTsconfigData = Pick<ParsedCommandLine, 'options' | 'projectReferences' | 'raw'> & {
|
|
5
|
-
|
|
6
|
-
filePath: string;
|
|
7
|
-
externalPackage?: string;
|
|
8
|
-
} | null;
|
|
9
|
+
extendedConfigFiles: ExtendedConfigFile[];
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
@@ -29,7 +29,6 @@ function addBuildAndWatchDepsTargets(workspaceRoot, projectRoot, targets, option
|
|
|
29
29
|
dependsOn: ['^build'],
|
|
30
30
|
};
|
|
31
31
|
targets[options.watchDepsTargetName ?? 'watch-deps'] = {
|
|
32
|
-
continuous: true,
|
|
33
32
|
dependsOn: [buildDepsTargetName],
|
|
34
33
|
command: `${pmc.exec} nx watch --projects ${projectName} --includeDependentProjects -- ${pmc.exec} nx ${buildDepsTargetName} ${projectName}`,
|
|
35
34
|
};
|
|
@@ -68,8 +67,8 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
68
67
|
}
|
|
69
68
|
else if (typeof value === 'object') {
|
|
70
69
|
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
71
|
-
// Skip types
|
|
72
|
-
if (currentKey === 'types') {
|
|
70
|
+
// Skip types and development conditions
|
|
71
|
+
if (currentKey === 'types' || currentKey === 'development') {
|
|
73
72
|
return false;
|
|
74
73
|
}
|
|
75
74
|
if (typeof subValue === 'string') {
|
|
@@ -33,8 +33,6 @@ export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph,
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function computeCompilerOptionsPaths(tsConfig: string | ts.ParsedCommandLine, dependencies: DependentBuildableProjectNode[]): ts.MapLike<string[]>;
|
|
35
35
|
export declare function createTmpTsConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, dependencies: DependentBuildableProjectNode[], useWorkspaceAsBaseUrl?: boolean): string;
|
|
36
|
-
export declare function checkDependentProjectsHaveBeenBuilt(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): boolean;
|
|
37
|
-
export declare function findMissingBuildDependencies(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): DependentBuildableProjectNode[];
|
|
38
36
|
export declare function updatePaths(dependencies: DependentBuildableProjectNode[], paths: Record<string, string[]>): void;
|
|
39
37
|
/**
|
|
40
38
|
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
@@ -5,8 +5,6 @@ exports.calculateProjectDependencies = calculateProjectDependencies;
|
|
|
5
5
|
exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
|
|
6
6
|
exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
|
|
7
7
|
exports.createTmpTsConfig = createTmpTsConfig;
|
|
8
|
-
exports.checkDependentProjectsHaveBeenBuilt = checkDependentProjectsHaveBeenBuilt;
|
|
9
|
-
exports.findMissingBuildDependencies = findMissingBuildDependencies;
|
|
10
8
|
exports.updatePaths = updatePaths;
|
|
11
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
12
10
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -252,36 +250,6 @@ function cleanupTmpTsConfigFile(tmpTsConfigPath) {
|
|
|
252
250
|
}
|
|
253
251
|
catch (e) { }
|
|
254
252
|
}
|
|
255
|
-
function checkDependentProjectsHaveBeenBuilt(root, projectName, targetName, projectDependencies) {
|
|
256
|
-
const missing = findMissingBuildDependencies(root, projectName, targetName, projectDependencies);
|
|
257
|
-
if (missing.length > 0) {
|
|
258
|
-
console.error((0, devkit_1.stripIndents) `
|
|
259
|
-
It looks like all of ${projectName}'s dependencies have not been built yet:
|
|
260
|
-
${missing.map((x) => ` - ${x.node.name}`).join('\n')}
|
|
261
|
-
|
|
262
|
-
You might be missing a "targetDefaults" configuration in your root nx.json (https://nx.dev/reference/project-configuration#target-defaults),
|
|
263
|
-
or "dependsOn" configured in ${projectName}'s project.json (https://nx.dev/reference/project-configuration#dependson)
|
|
264
|
-
`);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function findMissingBuildDependencies(root, projectName, targetName, projectDependencies) {
|
|
272
|
-
const depLibsToBuildFirst = [];
|
|
273
|
-
// verify whether all dependent libraries have been built
|
|
274
|
-
projectDependencies.forEach((dep) => {
|
|
275
|
-
if (dep.node.type !== 'lib') {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const paths = dep.outputs.map((p) => (0, path_1.join)(root, p));
|
|
279
|
-
if (!paths.some(fileutils_1.directoryExists)) {
|
|
280
|
-
depLibsToBuildFirst.push(dep);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return depLibsToBuildFirst;
|
|
284
|
-
}
|
|
285
253
|
function updatePaths(dependencies, paths) {
|
|
286
254
|
const pathsKeys = Object.keys(paths);
|
|
287
255
|
// For each registered dependency
|
|
@@ -291,7 +259,7 @@ function updatePaths(dependencies, paths) {
|
|
|
291
259
|
// If there are outputs
|
|
292
260
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
293
261
|
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
294
|
-
paths[dep.name] = dep.outputs;
|
|
262
|
+
paths[dep.name] = dep.outputs.map((output) => output.replace(/(\*|\/[^\/]*\*).*$/, ''));
|
|
295
263
|
// check for secondary entrypoints
|
|
296
264
|
// For each registered path
|
|
297
265
|
for (const path of pathsKeys) {
|
|
@@ -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)
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const esbuildVersion = "^0.19.2";
|
|
3
3
|
export declare const prettierVersion = "^2.6.2";
|
|
4
|
-
export declare const swcCliVersion = "~0.
|
|
4
|
+
export declare const swcCliVersion = "~0.6.0";
|
|
5
5
|
export declare const swcCoreVersion = "~1.5.7";
|
|
6
6
|
export declare const swcHelpersVersion = "~0.5.11";
|
|
7
7
|
export declare const swcNodeVersion = "~1.9.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.supportedTypescriptVersions = exports.typescriptVersion = exports.verdac
|
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.esbuildVersion = '^0.19.2';
|
|
6
6
|
exports.prettierVersion = '^2.6.2';
|
|
7
|
-
exports.swcCliVersion = '~0.
|
|
7
|
+
exports.swcCliVersion = '~0.6.0';
|
|
8
8
|
exports.swcCoreVersion = '~1.5.7';
|
|
9
9
|
exports.swcHelpersVersion = '~0.5.11';
|
|
10
10
|
exports.swcNodeVersion = '~1.9.1';
|
|
@@ -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
|
-
}
|