@nx/js 21.2.1 → 21.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/generators/library/library.js +4 -4
- package/src/generators/setup-build/generator.js +2 -2
- package/src/plugins/typescript/util.js +89 -12
- package/src/utils/assets/copy-assets-handler.js +5 -2
- package/src/utils/inline.js +2 -1
- package/src/utils/typescript/ts-solution-setup.d.ts +2 -2
- package/src/utils/typescript/ts-solution-setup.js +12 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "21.2.
|
|
3
|
+
"version": "21.2.3",
|
|
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": "21.2.
|
|
43
|
-
"@nx/workspace": "21.2.
|
|
42
|
+
"@nx/devkit": "21.2.3",
|
|
43
|
+
"@nx/workspace": "21.2.3",
|
|
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",
|
|
@@ -384,14 +384,14 @@ function createFiles(tree, options) {
|
|
|
384
384
|
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
|
-
if (options.
|
|
387
|
+
if (options.includeBabelRc) {
|
|
388
|
+
addBabelRc(tree, options);
|
|
389
|
+
}
|
|
390
|
+
else if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
388
391
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' && !options.isUsingTsSolutionConfig
|
|
389
392
|
? 'commonjs'
|
|
390
393
|
: 'es6');
|
|
391
394
|
}
|
|
392
|
-
else if (options.includeBabelRc) {
|
|
393
|
-
addBabelRc(tree, options);
|
|
394
|
-
}
|
|
395
395
|
if (options.unitTestRunner === 'none') {
|
|
396
396
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`));
|
|
397
397
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/app', `${options.fileName}.spec.ts`));
|
|
@@ -5,12 +5,12 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
6
6
|
const posix_1 = require("node:path/posix");
|
|
7
7
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
-
const plugin_1 = require("../../utils/typescript/plugin");
|
|
9
8
|
const get_import_path_1 = require("../../utils/get-import-path");
|
|
10
9
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
11
10
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
12
11
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
13
12
|
const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
|
|
13
|
+
const plugin_1 = require("../../utils/typescript/plugin");
|
|
14
14
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
15
15
|
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
16
16
|
const versions_1 = require("../../utils/versions");
|
|
@@ -29,7 +29,7 @@ async function setupBuildGenerator(tree, options) {
|
|
|
29
29
|
mainFile = options.main;
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
const root = project
|
|
32
|
+
const root = (0, ts_solution_setup_1.getProjectSourceRoot)(project, tree);
|
|
33
33
|
for (const f of [
|
|
34
34
|
(0, devkit_1.joinPathFragments)(root, 'main.ts'),
|
|
35
35
|
(0, devkit_1.joinPathFragments)(root, 'main.js'),
|
|
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const picomatch = require("picomatch");
|
|
9
10
|
/**
|
|
10
11
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
11
12
|
*/
|
|
@@ -46,22 +47,98 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
48
49
|
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
:
|
|
50
|
+
const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
|
|
51
|
+
// Handle outFile first (has precedence over outDir)
|
|
52
|
+
if (tsConfig.options.outFile) {
|
|
53
|
+
const outFile = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, tsConfig.options.outFile);
|
|
54
|
+
const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, outFile);
|
|
55
|
+
// If outFile is outside project root: buildable
|
|
56
|
+
if (relativeToProject.startsWith('..')) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
// If outFile is inside project root: check if entry points point to outFile
|
|
60
|
+
const isPathSourceFile = (path) => {
|
|
61
|
+
const normalizedPath = (0, node_path_1.isAbsolute)(path)
|
|
62
|
+
? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
|
|
63
|
+
: (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
64
|
+
// For outFile case, check if path points to the specific outFile
|
|
65
|
+
return normalizedPath === outFile;
|
|
66
|
+
};
|
|
67
|
+
// Check if any entry points match the outFile
|
|
68
|
+
const exports = packageJson?.exports;
|
|
69
|
+
if (exports) {
|
|
70
|
+
if (typeof exports === 'string') {
|
|
71
|
+
return !isPathSourceFile(exports);
|
|
72
|
+
}
|
|
73
|
+
if (typeof exports === 'object' && '.' in exports) {
|
|
74
|
+
const dotExport = exports['.'];
|
|
75
|
+
if (typeof dotExport === 'string') {
|
|
76
|
+
return !isPathSourceFile(dotExport);
|
|
77
|
+
}
|
|
78
|
+
else if (typeof dotExport === 'object') {
|
|
79
|
+
const hasMatch = Object.entries(dotExport).some(([key, value]) => {
|
|
80
|
+
if (key === 'types' || key === 'development')
|
|
81
|
+
return false;
|
|
82
|
+
return typeof value === 'string' && isPathSourceFile(value);
|
|
83
|
+
});
|
|
84
|
+
return !hasMatch;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const buildPaths = ['main', 'module'];
|
|
89
|
+
for (const field of buildPaths) {
|
|
90
|
+
if (packageJson[field] && isPathSourceFile(packageJson[field])) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
// Handle outDir
|
|
97
|
+
const outDir = tsConfig.options.outDir;
|
|
98
|
+
let resolvedOutDir;
|
|
99
|
+
if (outDir) {
|
|
100
|
+
const potentialOutDir = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir);
|
|
101
|
+
const relativePath = (0, node_path_1.relative)(projectAbsolutePath, potentialOutDir);
|
|
102
|
+
// If outDir is outside project root: buildable
|
|
103
|
+
if (relativePath.startsWith('..')) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
// If outDir is inside project root, then we should check entry points
|
|
107
|
+
if (!relativePath.startsWith('..')) {
|
|
108
|
+
resolvedOutDir = potentialOutDir;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
55
111
|
const isPathSourceFile = (path) => {
|
|
112
|
+
const normalizedPath = (0, node_path_1.isAbsolute)(path)
|
|
113
|
+
? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
|
|
114
|
+
: (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
56
115
|
if (resolvedOutDir) {
|
|
57
|
-
|
|
58
|
-
|
|
116
|
+
// If the path is within the outDir, we assume it's not a source file.
|
|
117
|
+
const relativePath = (0, node_path_1.relative)(resolvedOutDir, normalizedPath);
|
|
118
|
+
if (!relativePath.startsWith('..')) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
59
121
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
122
|
+
// If no include patterns, TypeScript includes all TS files by default
|
|
123
|
+
const include = tsConfig.raw?.include;
|
|
124
|
+
if (!include || !Array.isArray(include)) {
|
|
125
|
+
const ext = (0, node_path_1.extname)(path);
|
|
126
|
+
const tsExtensions = ['.ts', '.tsx', '.cts', '.mts'];
|
|
127
|
+
if (tsExtensions.includes(ext)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
// If include is not defined and it's not a TS file, assume it's not a source file
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
|
|
134
|
+
const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, normalizedPath);
|
|
135
|
+
for (const pattern of include) {
|
|
136
|
+
if (picomatch(pattern)(relativeToProject)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
63
141
|
};
|
|
64
|
-
// Checks if the value is a path within the `src` directory.
|
|
65
142
|
const containsInvalidPath = (value) => {
|
|
66
143
|
if (typeof value === 'string') {
|
|
67
144
|
return isPathSourceFile(value);
|
|
@@ -52,16 +52,19 @@ class CopyAssetsHandler {
|
|
|
52
52
|
let input;
|
|
53
53
|
let output;
|
|
54
54
|
let ignore = null;
|
|
55
|
+
const resolvedOutputDir = path.isAbsolute(opts.outputDir)
|
|
56
|
+
? opts.outputDir
|
|
57
|
+
: path.resolve(opts.rootDir, opts.outputDir);
|
|
55
58
|
if (typeof f === 'string') {
|
|
56
59
|
pattern = f;
|
|
57
60
|
input = path.relative(opts.rootDir, opts.projectDir);
|
|
58
|
-
output = path.relative(opts.rootDir,
|
|
61
|
+
output = path.relative(opts.rootDir, resolvedOutputDir);
|
|
59
62
|
}
|
|
60
63
|
else {
|
|
61
64
|
isGlob = true;
|
|
62
65
|
pattern = pathPosix.join(f.input, f.glob);
|
|
63
66
|
input = f.input;
|
|
64
|
-
output = pathPosix.join(path.relative(opts.rootDir,
|
|
67
|
+
output = pathPosix.join(path.relative(opts.rootDir, resolvedOutputDir), f.output);
|
|
65
68
|
if (f.ignore)
|
|
66
69
|
ignore = f.ignore.map((ig) => pathPosix.join(f.input, ig));
|
|
67
70
|
}
|
package/src/utils/inline.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
+
const ts_solution_setup_1 = require("./typescript/ts-solution-setup");
|
|
10
11
|
function isInlineGraphEmpty(inlineGraph) {
|
|
11
12
|
return Object.keys(inlineGraph.nodes).length === 0;
|
|
12
13
|
}
|
|
@@ -72,7 +73,7 @@ function projectNodeToInlineProjectNode(projectNode, pathAlias = '', buildOutput
|
|
|
72
73
|
return {
|
|
73
74
|
name: projectNode.name,
|
|
74
75
|
root: projectNode.data.root,
|
|
75
|
-
sourceRoot: projectNode.data
|
|
76
|
+
sourceRoot: (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data),
|
|
76
77
|
pathAlias,
|
|
77
78
|
buildOutputPath,
|
|
78
79
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Tree } from '@nx/devkit';
|
|
1
|
+
import { type ProjectConfiguration, 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;
|
|
@@ -6,4 +6,4 @@ export declare function findRuntimeTsConfigName(projectRoot: string, tree?: Tree
|
|
|
6
6
|
export declare function updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
|
|
7
7
|
export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): Promise<void>;
|
|
8
8
|
export declare function getProjectType(tree: Tree, projectRoot: string, projectType?: 'library' | 'application'): 'library' | 'application';
|
|
9
|
-
export declare function getProjectSourceRoot(
|
|
9
|
+
export declare function getProjectSourceRoot(project: ProjectConfiguration, tree?: Tree): string;
|
|
@@ -9,6 +9,7 @@ exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
|
|
|
9
9
|
exports.getProjectType = getProjectType;
|
|
10
10
|
exports.getProjectSourceRoot = getProjectSourceRoot;
|
|
11
11
|
const devkit_1 = require("@nx/devkit");
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
12
13
|
const posix_1 = require("node:path/posix");
|
|
13
14
|
const tree_1 = require("nx/src/generators/tree");
|
|
14
15
|
const package_manager_workspaces_1 = require("../package-manager-workspaces");
|
|
@@ -206,9 +207,15 @@ function getProjectType(tree, projectRoot, projectType) {
|
|
|
206
207
|
return 'application';
|
|
207
208
|
return 'library';
|
|
208
209
|
}
|
|
209
|
-
function getProjectSourceRoot(
|
|
210
|
-
|
|
211
|
-
(
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
function getProjectSourceRoot(project, tree) {
|
|
211
|
+
if (tree) {
|
|
212
|
+
return (project.sourceRoot ??
|
|
213
|
+
(tree.exists((0, devkit_1.joinPathFragments)(project.root, 'src'))
|
|
214
|
+
? (0, devkit_1.joinPathFragments)(project.root, 'src')
|
|
215
|
+
: project.root));
|
|
216
|
+
}
|
|
217
|
+
return (project.sourceRoot ??
|
|
218
|
+
((0, node_fs_1.existsSync)((0, posix_1.join)(devkit_1.workspaceRoot, project.root, 'src'))
|
|
219
|
+
? (0, devkit_1.joinPathFragments)(project.root, 'src')
|
|
220
|
+
: project.root));
|
|
214
221
|
}
|