@nx/js 0.0.0-pr-29993-0fbf3d3 → 0.0.0-pr-29720-06f67e5
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 -5
- package/src/generators/init/init.js +2 -1
- package/src/generators/library/library.js +17 -27
- package/src/plugins/typescript/plugin.js +94 -27
- package/src/plugins/typescript/util.d.ts +0 -8
- package/src/plugins/typescript/util.js +0 -74
- package/src/utils/assets/copy-assets-handler.js +1 -7
- package/src/utils/buildable-libs-utils.js +7 -8
- package/src/utils/package-manager-workspaces.d.ts +0 -1
- package/src/utils/package-manager-workspaces.js +5 -10
- package/src/utils/typescript/plugin.d.ts +1 -1
- package/src/utils/typescript/plugin.js +16 -27
- package/src/utils/typescript/ts-solution-setup.d.ts +2 -3
- package/src/utils/typescript/ts-solution-setup.js +9 -32
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-29720-06f67e5",
|
|
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-29720-06f67e5",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-29720-06f67e5",
|
|
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",
|
|
@@ -55,11 +55,10 @@
|
|
|
55
55
|
"npm-package-arg": "11.0.1",
|
|
56
56
|
"npm-run-path": "^4.0.1",
|
|
57
57
|
"ora": "5.3.0",
|
|
58
|
-
"picocolors": "^1.1.0",
|
|
59
58
|
"picomatch": "4.0.2",
|
|
60
59
|
"semver": "^7.5.3",
|
|
61
60
|
"source-map-support": "0.5.19",
|
|
62
|
-
"tinyglobby": "^0.2.
|
|
61
|
+
"tinyglobby": "^0.2.10",
|
|
63
62
|
"ts-node": "10.9.1",
|
|
64
63
|
"tsconfig-paths": "^4.1.2",
|
|
65
64
|
"tslib": "^2.3.0"
|
|
@@ -54,7 +54,8 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
54
54
|
schema.addPlugin ??=
|
|
55
55
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
56
56
|
nxJson.useInferencePlugins !== false;
|
|
57
|
-
schema.addTsPlugin ??=
|
|
57
|
+
schema.addTsPlugin ??=
|
|
58
|
+
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';
|
|
58
59
|
if (schema.addTsPlugin) {
|
|
59
60
|
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
|
|
60
61
|
typecheck: [
|
|
@@ -22,6 +22,7 @@ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
|
22
22
|
const versions_1 = require("../../utils/versions");
|
|
23
23
|
const init_1 = require("../init/init");
|
|
24
24
|
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
25
|
+
const get_import_path_1 = require("../../utils/get-import-path");
|
|
25
26
|
const add_release_config_1 = require("./utils/add-release-config");
|
|
26
27
|
const defaultOutputDirectory = 'dist';
|
|
27
28
|
async function libraryGenerator(tree, schema) {
|
|
@@ -42,16 +43,16 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
42
43
|
formatter: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'none' : 'prettier',
|
|
43
44
|
}));
|
|
44
45
|
const options = await normalizeOptions(tree, schema);
|
|
46
|
+
// If we are using the new TS solution
|
|
47
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
48
|
+
if (options.isUsingTsSolutionConfig) {
|
|
49
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
|
|
50
|
+
}
|
|
45
51
|
createFiles(tree, options);
|
|
46
52
|
await configureProject(tree, options);
|
|
47
53
|
if (!options.skipPackageJson) {
|
|
48
54
|
tasks.push(addProjectDependencies(tree, options));
|
|
49
55
|
}
|
|
50
|
-
// If we are using the new TS solution
|
|
51
|
-
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
52
|
-
if (options.isUsingTsSolutionConfig) {
|
|
53
|
-
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
|
|
54
|
-
}
|
|
55
56
|
if (options.bundler === 'rollup') {
|
|
56
57
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
57
58
|
await configurationGenerator(tree, {
|
|
@@ -160,7 +161,7 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
160
161
|
async function configureProject(tree, options) {
|
|
161
162
|
if (options.hasPlugin) {
|
|
162
163
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
163
|
-
(0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot
|
|
164
|
+
(0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
|
|
164
165
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
165
166
|
}
|
|
166
167
|
const projectConfiguration = {
|
|
@@ -235,7 +236,9 @@ async function configureProject(tree, options) {
|
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
238
|
// empty targets are cleaned up automatically by `updateProjectConfiguration`
|
|
238
|
-
(0, devkit_1.updateProjectConfiguration)(tree, options.
|
|
239
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.isUsingTsSolutionConfig
|
|
240
|
+
? options.importPath ?? options.name
|
|
241
|
+
: options.name, projectConfiguration);
|
|
239
242
|
}
|
|
240
243
|
else if (options.config === 'workspace' || options.config === 'project') {
|
|
241
244
|
(0, devkit_1.addProjectConfiguration)(tree, options.name, projectConfiguration);
|
|
@@ -465,11 +468,6 @@ function createFiles(tree, options) {
|
|
|
465
468
|
format: ['esm'],
|
|
466
469
|
});
|
|
467
470
|
}
|
|
468
|
-
if (!options.useProjectJson && options.name !== options.importPath) {
|
|
469
|
-
packageJson.nx = {
|
|
470
|
-
name: options.name,
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
471
|
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
474
472
|
}
|
|
475
473
|
if (options.config === 'npm-scripts') {
|
|
@@ -529,7 +527,7 @@ function replaceJestConfig(tree, options) {
|
|
|
529
527
|
});
|
|
530
528
|
}
|
|
531
529
|
async function normalizeOptions(tree, options) {
|
|
532
|
-
await (0, project_name_and_root_utils_1.
|
|
530
|
+
await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
|
|
533
531
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
534
532
|
options.addPlugin ??=
|
|
535
533
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
@@ -631,7 +629,9 @@ async function normalizeOptions(tree, options) {
|
|
|
631
629
|
return {
|
|
632
630
|
...options,
|
|
633
631
|
fileName,
|
|
634
|
-
name: isUsingTsSolutionConfig
|
|
632
|
+
name: isUsingTsSolutionConfig
|
|
633
|
+
? (0, get_import_path_1.getImportPath)(tree, projectName)
|
|
634
|
+
: projectName,
|
|
635
635
|
projectNames,
|
|
636
636
|
projectRoot,
|
|
637
637
|
parsedTags,
|
|
@@ -719,7 +719,9 @@ function createProjectTsConfigs(tree, options) {
|
|
|
719
719
|
.map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`)
|
|
720
720
|
.join(',\n '),
|
|
721
721
|
tmpl: '',
|
|
722
|
-
outDir: '
|
|
722
|
+
outDir: options.bundler === 'tsc'
|
|
723
|
+
? 'dist'
|
|
724
|
+
: `out-tsc/${options.projectRoot.split('/').pop()}`,
|
|
723
725
|
emitDeclarationOnly: options.bundler === 'tsc' ? false : true,
|
|
724
726
|
});
|
|
725
727
|
// tsconfig.json
|
|
@@ -732,12 +734,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
732
734
|
json.references.push({
|
|
733
735
|
path: './tsconfig.lib.json',
|
|
734
736
|
});
|
|
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
737
|
return json;
|
|
742
738
|
});
|
|
743
739
|
}
|
|
@@ -749,12 +745,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
749
745
|
include: [],
|
|
750
746
|
references: [{ path: './tsconfig.lib.json' }],
|
|
751
747
|
};
|
|
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
748
|
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
759
749
|
// update root project tsconfig.json references with the new lib tsconfig
|
|
760
750
|
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
@@ -178,9 +178,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
178
178
|
const tsConfig = retrieveTsConfigFromCache(configFilePath, context.workspaceRoot);
|
|
179
179
|
let internalProjectReferences;
|
|
180
180
|
// Typecheck target
|
|
181
|
-
if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' &&
|
|
182
|
-
options.typecheck &&
|
|
183
|
-
tsConfig.raw?.['nx']?.addTypecheckTarget !== false) {
|
|
181
|
+
if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' && options.typecheck) {
|
|
184
182
|
internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
185
183
|
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
186
184
|
const targetName = options.typecheck.targetName;
|
|
@@ -216,7 +214,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
216
214
|
// Build target
|
|
217
215
|
if (options.build &&
|
|
218
216
|
(0, node_path_1.basename)(configFilePath) === options.build.configName &&
|
|
219
|
-
|
|
217
|
+
isValidPackageJsonBuildConfig(tsConfig, context.workspaceRoot, projectRoot)) {
|
|
220
218
|
internalProjectReferences ??= resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
221
219
|
const targetName = options.build.targetName;
|
|
222
220
|
targets[targetName] = {
|
|
@@ -371,6 +369,87 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
|
|
|
371
369
|
});
|
|
372
370
|
return Array.from(outputs);
|
|
373
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Validates the build configuration of a `package.json` file by ensuring that paths in the `exports`, `module`,
|
|
374
|
+
* and `main` fields reference valid output paths within the `outDir` defined in the TypeScript configuration.
|
|
375
|
+
* Priority is given to the `exports` field, specifically the `.` export if defined. If `exports` is not defined,
|
|
376
|
+
* the function falls back to validating `main` and `module` fields. If `outFile` is specified, it validates that the file
|
|
377
|
+
* is located within the output directory.
|
|
378
|
+
* If no `package.json` file exists, it assumes the configuration is valid.
|
|
379
|
+
*
|
|
380
|
+
* @param tsConfig The TypeScript configuration object.
|
|
381
|
+
* @param workspaceRoot The workspace root path.
|
|
382
|
+
* @param projectRoot The project root path.
|
|
383
|
+
* @returns `true` if the package has a valid build configuration; otherwise, `false`.
|
|
384
|
+
*/
|
|
385
|
+
function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
386
|
+
const packageJsonPath = (0, node_path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
387
|
+
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
388
|
+
// If the package.json file does not exist.
|
|
389
|
+
// Assume it's valid because it would be using `project.json` instead.
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
393
|
+
const outDir = tsConfig.options.outFile
|
|
394
|
+
? (0, node_path_1.dirname)(tsConfig.options.outFile)
|
|
395
|
+
: tsConfig.options.outDir;
|
|
396
|
+
const resolvedOutDir = outDir
|
|
397
|
+
? (0, node_path_1.resolve)(workspaceRoot, projectRoot, outDir)
|
|
398
|
+
: undefined;
|
|
399
|
+
const isPathSourceFile = (path) => {
|
|
400
|
+
if (resolvedOutDir) {
|
|
401
|
+
const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, projectRoot, path);
|
|
402
|
+
return !pathToCheck.startsWith(resolvedOutDir);
|
|
403
|
+
}
|
|
404
|
+
const ext = (0, node_path_1.extname)(path);
|
|
405
|
+
// Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
|
|
406
|
+
return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
|
|
407
|
+
};
|
|
408
|
+
// Checks if the value is a path within the `src` directory.
|
|
409
|
+
const containsInvalidPath = (value) => {
|
|
410
|
+
if (typeof value === 'string') {
|
|
411
|
+
return isPathSourceFile(value);
|
|
412
|
+
}
|
|
413
|
+
else if (typeof value === 'object') {
|
|
414
|
+
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
415
|
+
// Skip types field
|
|
416
|
+
if (currentKey === 'types') {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
if (typeof subValue === 'string') {
|
|
420
|
+
return isPathSourceFile(subValue);
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
};
|
|
427
|
+
const exports = packageJson?.exports;
|
|
428
|
+
// Check the `.` export if `exports` is defined.
|
|
429
|
+
if (exports) {
|
|
430
|
+
if (typeof exports === 'string') {
|
|
431
|
+
return !isPathSourceFile(exports);
|
|
432
|
+
}
|
|
433
|
+
if (typeof exports === 'object' && '.' in exports) {
|
|
434
|
+
return !containsInvalidPath(exports['.']);
|
|
435
|
+
}
|
|
436
|
+
// Check other exports if `.` is not defined or valid.
|
|
437
|
+
for (const key in exports) {
|
|
438
|
+
if (key !== '.' && containsInvalidPath(exports[key])) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
// If `exports` is not defined, fallback to `main` and `module` fields.
|
|
445
|
+
const buildPaths = ['main', 'module'];
|
|
446
|
+
for (const field of buildPaths) {
|
|
447
|
+
if (packageJson[field] && isPathSourceFile(packageJson[field])) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
374
453
|
function pathToInputOrOutput(path, workspaceRoot, projectRoot) {
|
|
375
454
|
const fullProjectRoot = (0, node_path_1.resolve)(workspaceRoot, projectRoot);
|
|
376
455
|
const fullPath = (0, node_path_1.resolve)(workspaceRoot, path);
|
|
@@ -475,7 +554,7 @@ function hasExternalProjectReferences(tsConfigPath, tsConfig, workspaceRoot, pro
|
|
|
475
554
|
return false;
|
|
476
555
|
}
|
|
477
556
|
function isExternalProjectReference(refTsConfigPath, workspaceRoot, projectRoot) {
|
|
478
|
-
const relativePath =
|
|
557
|
+
const relativePath = posix.relative(workspaceRoot, refTsConfigPath);
|
|
479
558
|
if (cache.isExternalProjectReference[relativePath] !== undefined) {
|
|
480
559
|
return cache.isExternalProjectReference[relativePath];
|
|
481
560
|
}
|
|
@@ -505,7 +584,7 @@ function getTsConfigDirName(tsConfigPath) {
|
|
|
505
584
|
: (0, node_path_1.normalize)(tsConfigPath);
|
|
506
585
|
}
|
|
507
586
|
function retrieveTsConfigFromCache(tsConfigPath, workspaceRoot) {
|
|
508
|
-
const relativePath =
|
|
587
|
+
const relativePath = posix.relative(workspaceRoot, tsConfigPath);
|
|
509
588
|
// we don't need to check the hash if it's in the cache, because we've already
|
|
510
589
|
// checked it when we initially populated the cache
|
|
511
590
|
return tsConfigCache[relativePath]
|
|
@@ -521,7 +600,7 @@ function initializeTsConfigCache(configFilePaths, workspaceRoot) {
|
|
|
521
600
|
}
|
|
522
601
|
}
|
|
523
602
|
function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
524
|
-
const relativePath =
|
|
603
|
+
const relativePath = posix.relative(workspaceRoot, tsConfigPath);
|
|
525
604
|
const hash = getFileHash(tsConfigPath, workspaceRoot);
|
|
526
605
|
let extendedFilesHash;
|
|
527
606
|
if (tsConfigCache[relativePath] &&
|
|
@@ -637,7 +716,7 @@ function resolveExtendedTsConfigPath(tsConfigPath, directory) {
|
|
|
637
716
|
}
|
|
638
717
|
}
|
|
639
718
|
function getFileHash(filePath, workspaceRoot) {
|
|
640
|
-
const relativePath =
|
|
719
|
+
const relativePath = posix.relative(workspaceRoot, filePath);
|
|
641
720
|
if (!cache.fileHashes[relativePath]) {
|
|
642
721
|
const content = readFile(filePath, workspaceRoot);
|
|
643
722
|
cache.fileHashes[relativePath] = (0, file_hasher_1.hashArray)([content]);
|
|
@@ -645,7 +724,7 @@ function getFileHash(filePath, workspaceRoot) {
|
|
|
645
724
|
return cache.fileHashes[relativePath];
|
|
646
725
|
}
|
|
647
726
|
function readFile(filePath, workspaceRoot) {
|
|
648
|
-
const relativePath =
|
|
727
|
+
const relativePath = posix.relative(workspaceRoot, filePath);
|
|
649
728
|
if (!cache.rawFiles[relativePath]) {
|
|
650
729
|
const content = (0, node_fs_1.readFileSync)(filePath, 'utf8');
|
|
651
730
|
cache.rawFiles[relativePath] = content;
|
|
@@ -658,9 +737,6 @@ function toAbsolutePaths(cache, workspaceRoot) {
|
|
|
658
737
|
updatedCache[key] = {
|
|
659
738
|
data: {
|
|
660
739
|
options: { noEmit: data.options.noEmit },
|
|
661
|
-
raw: {
|
|
662
|
-
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
663
|
-
},
|
|
664
740
|
extendedConfigFile: data.extendedConfigFile,
|
|
665
741
|
},
|
|
666
742
|
extendedFilesHash,
|
|
@@ -693,38 +769,29 @@ function toRelativePaths(cache, workspaceRoot) {
|
|
|
693
769
|
updatedCache[key] = {
|
|
694
770
|
data: {
|
|
695
771
|
options: { noEmit: data.options.noEmit },
|
|
696
|
-
raw: {
|
|
697
|
-
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
698
|
-
},
|
|
699
772
|
extendedConfigFile: data.extendedConfigFile,
|
|
700
773
|
},
|
|
701
774
|
extendedFilesHash,
|
|
702
775
|
hash,
|
|
703
776
|
};
|
|
704
777
|
if (data.options.rootDir) {
|
|
705
|
-
updatedCache[key].data.options.rootDir =
|
|
778
|
+
updatedCache[key].data.options.rootDir = posix.relative(workspaceRoot, data.options.rootDir);
|
|
706
779
|
}
|
|
707
780
|
if (data.options.outDir) {
|
|
708
|
-
updatedCache[key].data.options.outDir =
|
|
781
|
+
updatedCache[key].data.options.outDir = posix.relative(workspaceRoot, data.options.outDir);
|
|
709
782
|
}
|
|
710
783
|
if (data.options.outFile) {
|
|
711
|
-
updatedCache[key].data.options.outFile =
|
|
784
|
+
updatedCache[key].data.options.outFile = posix.relative(workspaceRoot, data.options.outFile);
|
|
712
785
|
}
|
|
713
786
|
if (data.options.tsBuildInfoFile) {
|
|
714
|
-
updatedCache[key].data.options.tsBuildInfoFile =
|
|
787
|
+
updatedCache[key].data.options.tsBuildInfoFile = posix.relative(workspaceRoot, data.options.tsBuildInfoFile);
|
|
715
788
|
}
|
|
716
789
|
if (data.extendedConfigFile?.filePath) {
|
|
717
|
-
updatedCache[key].data.extendedConfigFile.filePath =
|
|
790
|
+
updatedCache[key].data.extendedConfigFile.filePath = posix.relative(workspaceRoot, data.extendedConfigFile.filePath);
|
|
718
791
|
}
|
|
719
792
|
if (data.projectReferences) {
|
|
720
|
-
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({
|
|
721
|
-
...ref,
|
|
722
|
-
path: posixRelative(workspaceRoot, ref.path),
|
|
723
|
-
}));
|
|
793
|
+
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({ ...ref, path: posix.relative(workspaceRoot, ref.path) }));
|
|
724
794
|
}
|
|
725
795
|
}
|
|
726
796
|
return updatedCache;
|
|
727
797
|
}
|
|
728
|
-
function posixRelative(workspaceRoot, path) {
|
|
729
|
-
return posix.normalize((0, node_path_1.relative)(workspaceRoot, path));
|
|
730
|
-
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { type TargetConfiguration } from '@nx/devkit';
|
|
2
2
|
import { type PackageManagerCommands } from 'nx/src/utils/package-manager';
|
|
3
|
-
import { type ParsedCommandLine } from 'typescript';
|
|
4
|
-
export type ParsedTsconfigData = Pick<ParsedCommandLine, 'options' | 'projectReferences' | 'raw'> & {
|
|
5
|
-
extendedConfigFile: {
|
|
6
|
-
filePath: string;
|
|
7
|
-
externalPackage?: string;
|
|
8
|
-
} | null;
|
|
9
|
-
};
|
|
10
3
|
/**
|
|
11
4
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
12
5
|
*/
|
|
@@ -14,4 +7,3 @@ export declare function addBuildAndWatchDepsTargets(workspaceRoot: string, proje
|
|
|
14
7
|
buildDepsTargetName?: string;
|
|
15
8
|
watchDepsTargetName?: string;
|
|
16
9
|
}, pmc: PackageManagerCommands): void;
|
|
17
|
-
export declare function isValidPackageJsonBuildConfig(tsConfig: ParsedTsconfigData, workspaceRoot: string, projectRoot: string): boolean;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addBuildAndWatchDepsTargets = addBuildAndWatchDepsTargets;
|
|
4
|
-
exports.isValidPackageJsonBuildConfig = isValidPackageJsonBuildConfig;
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const node_fs_1 = require("node:fs");
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
6
|
const path_1 = require("path");
|
|
9
7
|
/**
|
|
10
8
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
@@ -29,80 +27,8 @@ function addBuildAndWatchDepsTargets(workspaceRoot, projectRoot, targets, option
|
|
|
29
27
|
dependsOn: ['^build'],
|
|
30
28
|
};
|
|
31
29
|
targets[options.watchDepsTargetName ?? 'watch-deps'] = {
|
|
32
|
-
continuous: true,
|
|
33
30
|
dependsOn: [buildDepsTargetName],
|
|
34
31
|
command: `${pmc.exec} nx watch --projects ${projectName} --includeDependentProjects -- ${pmc.exec} nx ${buildDepsTargetName} ${projectName}`,
|
|
35
32
|
};
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
39
|
-
const resolvedProjectPath = (0, node_path_1.isAbsolute)(projectRoot)
|
|
40
|
-
? (0, node_path_1.relative)(workspaceRoot, projectRoot)
|
|
41
|
-
: projectRoot;
|
|
42
|
-
const packageJsonPath = (0, path_1.join)(workspaceRoot, resolvedProjectPath, 'package.json');
|
|
43
|
-
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
44
|
-
// If the package.json file does not exist.
|
|
45
|
-
// Assume it's valid because it would be using `project.json` instead.
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
49
|
-
const outDir = tsConfig.options.outFile
|
|
50
|
-
? (0, node_path_1.dirname)(tsConfig.options.outFile)
|
|
51
|
-
: tsConfig.options.outDir;
|
|
52
|
-
const resolvedOutDir = outDir
|
|
53
|
-
? (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir)
|
|
54
|
-
: undefined;
|
|
55
|
-
const isPathSourceFile = (path) => {
|
|
56
|
-
if (resolvedOutDir) {
|
|
57
|
-
const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
58
|
-
return !pathToCheck.startsWith(resolvedOutDir);
|
|
59
|
-
}
|
|
60
|
-
const ext = (0, node_path_1.extname)(path);
|
|
61
|
-
// Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
|
|
62
|
-
return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
|
|
63
|
-
};
|
|
64
|
-
// Checks if the value is a path within the `src` directory.
|
|
65
|
-
const containsInvalidPath = (value) => {
|
|
66
|
-
if (typeof value === 'string') {
|
|
67
|
-
return isPathSourceFile(value);
|
|
68
|
-
}
|
|
69
|
-
else if (typeof value === 'object') {
|
|
70
|
-
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
71
|
-
// Skip types field
|
|
72
|
-
if (currentKey === 'types') {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (typeof subValue === 'string') {
|
|
76
|
-
return isPathSourceFile(subValue);
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
};
|
|
83
|
-
const exports = packageJson?.exports;
|
|
84
|
-
// Check the `.` export if `exports` is defined.
|
|
85
|
-
if (exports) {
|
|
86
|
-
if (typeof exports === 'string') {
|
|
87
|
-
return !isPathSourceFile(exports);
|
|
88
|
-
}
|
|
89
|
-
if (typeof exports === 'object' && '.' in exports) {
|
|
90
|
-
return !containsInvalidPath(exports['.']);
|
|
91
|
-
}
|
|
92
|
-
// Check other exports if `.` is not defined or valid.
|
|
93
|
-
for (const key in exports) {
|
|
94
|
-
if (key !== '.' && containsInvalidPath(exports[key])) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
// If `exports` is not defined, fallback to `main` and `module` fields.
|
|
101
|
-
const buildPaths = ['main', 'module'];
|
|
102
|
-
for (const field of buildPaths) {
|
|
103
|
-
if (packageJson[field] && isPathSourceFile(packageJson[field])) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
@@ -9,7 +9,6 @@ const ignore_1 = require("ignore");
|
|
|
9
9
|
const tinyglobby_1 = require("tinyglobby");
|
|
10
10
|
const devkit_1 = require("@nx/devkit");
|
|
11
11
|
const client_1 = require("nx/src/daemon/client/client");
|
|
12
|
-
const picocolors_1 = require("picocolors");
|
|
13
12
|
const defaultFileEventHandler = (events) => {
|
|
14
13
|
const dirs = new Set(events.map((event) => path.dirname(event.dest)));
|
|
15
14
|
dirs.forEach((d) => (0, node_fs_1.mkdirSync)(d, { recursive: true }));
|
|
@@ -25,9 +24,6 @@ const defaultFileEventHandler = (events) => {
|
|
|
25
24
|
else {
|
|
26
25
|
devkit_1.logger.error(`Unknown file event: ${event.type}`);
|
|
27
26
|
}
|
|
28
|
-
const eventDir = path.dirname(event.src);
|
|
29
|
-
const relativeDest = path.relative(eventDir, event.dest);
|
|
30
|
-
devkit_1.logger.log(`\n${(0, picocolors_1.dim)(relativeDest)}`);
|
|
31
27
|
});
|
|
32
28
|
};
|
|
33
29
|
exports.defaultFileEventHandler = defaultFileEventHandler;
|
|
@@ -119,9 +115,7 @@ class CopyAssetsHandler {
|
|
|
119
115
|
async processWatchEvents(events) {
|
|
120
116
|
const fileEvents = [];
|
|
121
117
|
for (const event of events) {
|
|
122
|
-
const pathFromRoot =
|
|
123
|
-
? path.relative(this.rootDir, event.path)
|
|
124
|
-
: event.path;
|
|
118
|
+
const pathFromRoot = path.relative(this.rootDir, event.path);
|
|
125
119
|
for (const ag of this.assetGlobs) {
|
|
126
120
|
if (picomatch(ag.pattern)(pathFromRoot) &&
|
|
127
121
|
!ag.ignore?.some((ig) => picomatch(ig)(pathFromRoot)) &&
|
|
@@ -17,7 +17,6 @@ const output_1 = require("nx/src/utils/output");
|
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const ts_config_1 = require("./typescript/ts-config");
|
|
19
19
|
const crypto_1 = require("crypto");
|
|
20
|
-
const project_graph_1 = require("nx/src/config/project-graph");
|
|
21
20
|
function isBuildable(target, node) {
|
|
22
21
|
return (node.data.targets &&
|
|
23
22
|
node.data.targets[target] &&
|
|
@@ -50,7 +49,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
50
49
|
.map(({ name: dep, isTopLevel }) => {
|
|
51
50
|
let project = null;
|
|
52
51
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
53
|
-
if (
|
|
52
|
+
if (depNode.type === 'lib') {
|
|
54
53
|
if (isBuildable(targetName, depNode)) {
|
|
55
54
|
const libPackageJsonPath = (0, path_1.join)(root, depNode.data.root, 'package.json');
|
|
56
55
|
project = {
|
|
@@ -69,7 +68,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
69
68
|
nonBuildableDependencies.push(dep);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
else if (
|
|
71
|
+
else if (depNode.type === 'npm') {
|
|
73
72
|
project = {
|
|
74
73
|
name: depNode.data.packageName,
|
|
75
74
|
outputs: [],
|
|
@@ -285,9 +284,10 @@ function findMissingBuildDependencies(root, projectName, targetName, projectDepe
|
|
|
285
284
|
function updatePaths(dependencies, paths) {
|
|
286
285
|
const pathsKeys = Object.keys(paths);
|
|
287
286
|
// For each registered dependency
|
|
288
|
-
dependencies
|
|
289
|
-
|
|
290
|
-
|
|
287
|
+
dependencies.forEach((dep) => {
|
|
288
|
+
if (dep.node.type === 'npm') {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
291
|
// If there are outputs
|
|
292
292
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
293
293
|
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
@@ -351,8 +351,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
351
351
|
!hasDependency(packageJson, 'peerDependencies', packageName)) {
|
|
352
352
|
try {
|
|
353
353
|
let depVersion;
|
|
354
|
-
if (
|
|
355
|
-
entry.node.type === 'lib') {
|
|
354
|
+
if (entry.node.type === 'lib') {
|
|
356
355
|
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
357
356
|
project: projectName,
|
|
358
357
|
target: targetName,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
2
2
|
export type ProjectPackageManagerWorkspaceState = 'included' | 'excluded' | 'no-workspaces';
|
|
3
3
|
export declare function getProjectPackageManagerWorkspaceState(tree: Tree, projectRoot: string): ProjectPackageManagerWorkspaceState;
|
|
4
|
-
export declare function getPackageManagerWorkspacesPatterns(tree: Tree): string[];
|
|
5
4
|
export declare function isUsingPackageManagerWorkspaces(tree: Tree): boolean;
|
|
6
5
|
export declare function isWorkspacesEnabled(tree: Tree): boolean;
|
|
7
6
|
export declare function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState, workspaceRoot: string): GeneratorCallback;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProjectPackageManagerWorkspaceState = getProjectPackageManagerWorkspaceState;
|
|
4
|
-
exports.getPackageManagerWorkspacesPatterns = getPackageManagerWorkspacesPatterns;
|
|
5
4
|
exports.isUsingPackageManagerWorkspaces = isUsingPackageManagerWorkspaces;
|
|
6
5
|
exports.isWorkspacesEnabled = isWorkspacesEnabled;
|
|
7
6
|
exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageManagerWorkspaceStateWarningTask;
|
|
@@ -14,21 +13,17 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
|
14
13
|
if (!isUsingPackageManagerWorkspaces(tree)) {
|
|
15
14
|
return 'no-workspaces';
|
|
16
15
|
}
|
|
17
|
-
const patterns =
|
|
16
|
+
const patterns = (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }));
|
|
18
17
|
const isIncluded = patterns.some((p) => picomatch(p)((0, posix_1.join)(projectRoot, 'package.json')));
|
|
19
18
|
return isIncluded ? 'included' : 'excluded';
|
|
20
19
|
}
|
|
21
|
-
function getPackageManagerWorkspacesPatterns(tree) {
|
|
22
|
-
return (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
|
|
23
|
-
const content = tree.read(path, 'utf-8');
|
|
24
|
-
const { load } = require('@zkochan/js-yaml');
|
|
25
|
-
return load(content, { filename: path });
|
|
26
|
-
}, (path) => tree.exists(path));
|
|
27
|
-
}
|
|
28
20
|
function isUsingPackageManagerWorkspaces(tree) {
|
|
29
21
|
return isWorkspacesEnabled(tree);
|
|
30
22
|
}
|
|
31
|
-
function isWorkspacesEnabled(tree
|
|
23
|
+
function isWorkspacesEnabled(tree
|
|
24
|
+
// packageManager: PackageManager = detectPackageManager(),
|
|
25
|
+
// root: string = workspaceRoot
|
|
26
|
+
) {
|
|
32
27
|
const packageManager = (0, devkit_1.detectPackageManager)(tree.root);
|
|
33
28
|
if (packageManager === 'pnpm') {
|
|
34
29
|
return tree.exists('pnpm-workspace.yaml');
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { NxJsonConfiguration } from '@nx/devkit';
|
|
2
|
-
export declare function ensureProjectIsIncludedInPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string, buildTargetName
|
|
2
|
+
export declare function ensureProjectIsIncludedInPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string, buildTargetName?: string): void;
|
|
3
3
|
export declare function ensureProjectIsExcludedFromPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string): void;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ensureProjectIsIncludedInPluginRegistrations = ensureProjectIsIncludedInPluginRegistrations;
|
|
4
4
|
exports.ensureProjectIsExcludedFromPluginRegistrations = ensureProjectIsExcludedFromPluginRegistrations;
|
|
5
5
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
6
|
-
function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, buildTargetName) {
|
|
6
|
+
function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, buildTargetName = 'build') {
|
|
7
7
|
nxJson.plugins ??= [];
|
|
8
8
|
let isIncluded = false;
|
|
9
9
|
let index = 0;
|
|
@@ -13,17 +13,12 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
|
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
15
|
if (typeof registration === 'string') {
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
isIncluded = true;
|
|
26
|
-
}
|
|
16
|
+
// if it's a string all projects are included but the are no user-specified options
|
|
17
|
+
// and the build task is not inferred by default, so we need to exclude it
|
|
18
|
+
nxJson.plugins[index] = {
|
|
19
|
+
plugin: '@nx/js/typescript',
|
|
20
|
+
exclude: [`${projectRoot}/*`],
|
|
21
|
+
};
|
|
27
22
|
}
|
|
28
23
|
else {
|
|
29
24
|
// check if the project would be included by the plugin registration
|
|
@@ -32,7 +27,7 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
|
|
|
32
27
|
// it's included by the plugin registration, check if the user-specified options would result
|
|
33
28
|
// in the appropriate build task being inferred, if not, we need to exclude it
|
|
34
29
|
if (registration.options?.typecheck !== false &&
|
|
35
|
-
|
|
30
|
+
matchesBuildTarget(registration.options?.build, buildTargetName)) {
|
|
36
31
|
// it has the desired options, do nothing, but continue processing
|
|
37
32
|
// other registrations to exclude as needed
|
|
38
33
|
isIncluded = true;
|
|
@@ -45,7 +40,7 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
|
|
|
45
40
|
}
|
|
46
41
|
else if (!isIncluded &&
|
|
47
42
|
registration.options?.typecheck !== false &&
|
|
48
|
-
|
|
43
|
+
matchesBuildTarget(registration.options?.build, buildTargetName)) {
|
|
49
44
|
if (!registration.exclude?.length) {
|
|
50
45
|
// negative pattern are not supported by the `exclude` option so we
|
|
51
46
|
// can't update it to not exclude the project, so we only update the
|
|
@@ -71,20 +66,17 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
|
|
|
71
66
|
if (!isIncluded) {
|
|
72
67
|
// the project is not included by any plugin registration with an inferred build task
|
|
73
68
|
// with the given name, so we create a new plugin registration for it
|
|
74
|
-
|
|
69
|
+
nxJson.plugins.push({
|
|
75
70
|
plugin: '@nx/js/typescript',
|
|
76
71
|
include: [`${projectRoot}/*`],
|
|
77
72
|
options: {
|
|
78
73
|
typecheck: { targetName: 'typecheck' },
|
|
74
|
+
build: {
|
|
75
|
+
targetName: buildTargetName,
|
|
76
|
+
configName: 'tsconfig.lib.json',
|
|
77
|
+
},
|
|
79
78
|
},
|
|
80
|
-
};
|
|
81
|
-
if (buildTargetName) {
|
|
82
|
-
registration.options.build = {
|
|
83
|
-
targetName: buildTargetName,
|
|
84
|
-
configName: 'tsconfig.lib.json',
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
nxJson.plugins.push(registration);
|
|
79
|
+
});
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
function ensureProjectIsExcludedFromPluginRegistrations(nxJson, projectRoot) {
|
|
@@ -123,11 +115,8 @@ function isTypeScriptPluginRegistration(plugin) {
|
|
|
123
115
|
return ((typeof plugin === 'string' && plugin === '@nx/js/typescript') ||
|
|
124
116
|
(typeof plugin !== 'string' && plugin.plugin === '@nx/js/typescript'));
|
|
125
117
|
}
|
|
126
|
-
function
|
|
118
|
+
function matchesBuildTarget(buildOptions, buildTargetName) {
|
|
127
119
|
if (buildOptions === undefined || buildOptions === false) {
|
|
128
|
-
return !buildTargetName;
|
|
129
|
-
}
|
|
130
|
-
if (!buildTargetName) {
|
|
131
120
|
return false;
|
|
132
121
|
}
|
|
133
122
|
if (buildOptions === true && buildTargetName === 'build') {
|
|
@@ -2,8 +2,7 @@ import { type Tree } from '@nx/devkit';
|
|
|
2
2
|
export declare function isUsingTypeScriptPlugin(tree: Tree): boolean;
|
|
3
3
|
export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
|
|
4
4
|
export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: string, generatorName: string): void;
|
|
5
|
-
export declare function findRuntimeTsConfigName(
|
|
5
|
+
export declare function findRuntimeTsConfigName(tree: Tree, projectRoot: string): string | null;
|
|
6
6
|
export declare function updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
|
|
7
|
-
export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string):
|
|
7
|
+
export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): void;
|
|
8
8
|
export declare function getProjectType(tree: Tree, projectRoot: string, projectType?: 'library' | 'application'): 'library' | 'application';
|
|
9
|
-
export declare function getProjectSourceRoot(tree: Tree, projectSourceRoot: string | undefined, projectRoot: string): string | undefined;
|
|
@@ -7,7 +7,6 @@ exports.findRuntimeTsConfigName = findRuntimeTsConfigName;
|
|
|
7
7
|
exports.updateTsconfigFiles = updateTsconfigFiles;
|
|
8
8
|
exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
|
|
9
9
|
exports.getProjectType = getProjectType;
|
|
10
|
-
exports.getProjectSourceRoot = getProjectSourceRoot;
|
|
11
10
|
const devkit_1 = require("@nx/devkit");
|
|
12
11
|
const posix_1 = require("node:path/posix");
|
|
13
12
|
const tree_1 = require("nx/src/generators/tree");
|
|
@@ -72,8 +71,7 @@ function assertNotUsingTsSolutionSetup(tree, pluginName, generatorName) {
|
|
|
72
71
|
});
|
|
73
72
|
throw new Error(`The ${artifactString} doesn't yet support the existing TypeScript setup. See the error above.`);
|
|
74
73
|
}
|
|
75
|
-
function findRuntimeTsConfigName(
|
|
76
|
-
tree ??= new tree_1.FsTree(devkit_1.workspaceRoot, false);
|
|
74
|
+
function findRuntimeTsConfigName(tree, projectRoot) {
|
|
77
75
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json')))
|
|
78
76
|
return 'tsconfig.app.json';
|
|
79
77
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.lib.json')))
|
|
@@ -92,7 +90,9 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
92
90
|
json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
|
|
93
91
|
json.compilerOptions = {
|
|
94
92
|
...json.compilerOptions,
|
|
95
|
-
|
|
93
|
+
// Make sure d.ts files from typecheck does not conflict with bundlers.
|
|
94
|
+
// Other tooling like jest write to "out-tsc/jest" to we just default to "out-tsc/<project-name>".
|
|
95
|
+
outDir: (0, devkit_1.joinPathFragments)('out-tsc', projectRoot.split('/').at(-1)),
|
|
96
96
|
rootDir,
|
|
97
97
|
...compilerOptions,
|
|
98
98
|
};
|
|
@@ -145,29 +145,12 @@ function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compile
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
// If dir is "libs/foo", we try to use "libs/*" but we only do it if it's
|
|
154
|
-
// safe to do so. So, we first check if adding that pattern doesn't result
|
|
155
|
-
// in extra projects being matched. If extra projects are matched, or the
|
|
156
|
-
// dir is just "foo" then we add it as is.
|
|
148
|
+
function addProjectToTsSolutionWorkspace(tree, projectDir) {
|
|
149
|
+
// If dir is "libs/foo" then use "libs/*" so we don't need so many entries in the workspace file.
|
|
150
|
+
// If dir is nested like "libs/shared/foo" then we add "libs/shared/*".
|
|
151
|
+
// If the dir is just "foo" then we have to add it as is.
|
|
157
152
|
const baseDir = (0, posix_1.dirname)(projectDir);
|
|
158
|
-
|
|
159
|
-
if (baseDir !== '.') {
|
|
160
|
-
const patterns = (0, package_manager_workspaces_1.getPackageManagerWorkspacesPatterns)(tree);
|
|
161
|
-
const projectsBefore = await (0, devkit_1.globAsync)(tree, patterns);
|
|
162
|
-
patterns.push(`${baseDir}/*/package.json`);
|
|
163
|
-
const projectsAfter = await (0, devkit_1.globAsync)(tree, patterns);
|
|
164
|
-
if (projectsBefore.length + 1 === projectsAfter.length) {
|
|
165
|
-
// Adding the pattern to the parent directory only results in one extra
|
|
166
|
-
// project being matched, which is the project we're adding. It's safe
|
|
167
|
-
// to add the pattern to the parent directory.
|
|
168
|
-
pattern = `${baseDir}/*`;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
153
|
+
const pattern = baseDir === '.' ? projectDir : `${baseDir}/*`;
|
|
171
154
|
if (tree.exists('pnpm-workspace.yaml')) {
|
|
172
155
|
const { load, dump } = require('@zkochan/js-yaml');
|
|
173
156
|
const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
|
|
@@ -206,9 +189,3 @@ function getProjectType(tree, projectRoot, projectType) {
|
|
|
206
189
|
return 'application';
|
|
207
190
|
return 'library';
|
|
208
191
|
}
|
|
209
|
-
function getProjectSourceRoot(tree, projectSourceRoot, projectRoot) {
|
|
210
|
-
return (projectSourceRoot ??
|
|
211
|
-
(tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'src'))
|
|
212
|
-
? (0, devkit_1.joinPathFragments)(projectRoot, 'src')
|
|
213
|
-
: projectRoot));
|
|
214
|
-
}
|