@nx/js 0.0.0-pr-28808-eac89e6 → 0.0.0-pr-29114-41d0324
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/plugins/typescript/plugin.js +10 -41
- package/src/utils/package-manager-workspaces.d.ts +0 -1
- package/src/utils/package-manager-workspaces.js +1 -14
- package/src/utils/typescript/ts-solution-setup.d.ts +0 -1
- package/src/utils/typescript/ts-solution-setup.js +0 -62
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-29114-41d0324",
|
|
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-29114-41d0324",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-29114-41d0324",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^2.8.0",
|
|
@@ -72,20 +72,12 @@ async function createNodesInternal(configFilePath, options, context, lockFileNam
|
|
|
72
72
|
!siblingFiles.includes('tsconfig.json')) {
|
|
73
73
|
return {};
|
|
74
74
|
}
|
|
75
|
-
// Do not create project for Next.js projects since they are not compatible with
|
|
76
|
-
// project references and typecheck will fail.
|
|
77
|
-
if (siblingFiles.includes('next.config.js') ||
|
|
78
|
-
siblingFiles.includes('next.config.cjs') ||
|
|
79
|
-
siblingFiles.includes('next.config.mjs') ||
|
|
80
|
-
siblingFiles.includes('next.config.ts')) {
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
75
|
/**
|
|
84
76
|
* The cache key is composed by:
|
|
85
77
|
* - hashes of the content of the relevant files that can affect what's inferred by the plugin:
|
|
86
78
|
* - current config file
|
|
87
79
|
* - config files extended by the current config file (recursively up to the root config file)
|
|
88
|
-
* - referenced config files that are internal to the owning Nx project of the current config file
|
|
80
|
+
* - referenced config files that are internal to the owning Nx project of the current config file
|
|
89
81
|
* - lock file
|
|
90
82
|
* - hash of the plugin options
|
|
91
83
|
* - current config file path
|
|
@@ -93,13 +85,11 @@ async function createNodesInternal(configFilePath, options, context, lockFileNam
|
|
|
93
85
|
const tsConfig = readCachedTsConfig(fullConfigPath);
|
|
94
86
|
const extendedConfigFiles = getExtendedConfigFiles(fullConfigPath, tsConfig);
|
|
95
87
|
const internalReferencedFiles = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
96
|
-
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
97
88
|
const nodeHash = (0, file_hasher_1.hashArray)([
|
|
98
89
|
...[
|
|
99
90
|
fullConfigPath,
|
|
100
91
|
...extendedConfigFiles.files,
|
|
101
92
|
...Object.keys(internalReferencedFiles),
|
|
102
|
-
...Object.keys(externalProjectReferences),
|
|
103
93
|
(0, node_path_1.join)(context.workspaceRoot, lockFileName),
|
|
104
94
|
].map(file_hasher_1.hashFile),
|
|
105
95
|
(0, file_hasher_1.hashObject)(options),
|
|
@@ -129,15 +119,14 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
129
119
|
// Typecheck target
|
|
130
120
|
if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' && options.typecheck) {
|
|
131
121
|
internalProjectReferences = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
132
|
-
const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
|
|
133
122
|
const targetName = options.typecheck.targetName;
|
|
134
123
|
if (!targets[targetName]) {
|
|
135
124
|
let command = `tsc --build --emitDeclarationOnly --pretty --verbose`;
|
|
136
125
|
if (tsConfig.options.noEmit ||
|
|
137
|
-
Object.values(internalProjectReferences).some((ref) => ref.options.noEmit)
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
command = `
|
|
126
|
+
Object.values(internalProjectReferences).some((ref) => ref.options.noEmit)) {
|
|
127
|
+
// `--emitDeclarationOnly` and `--noEmit` are mutually exclusive, so
|
|
128
|
+
// we remove `--emitDeclarationOnly` if `--noEmit` is set.
|
|
129
|
+
command = `tsc --build --pretty --verbose`;
|
|
141
130
|
}
|
|
142
131
|
targets[targetName] = {
|
|
143
132
|
dependsOn: [`^${targetName}`],
|
|
@@ -332,27 +321,6 @@ function getExtendedConfigFiles(tsConfigPath, tsConfig) {
|
|
|
332
321
|
};
|
|
333
322
|
}
|
|
334
323
|
function resolveInternalProjectReferences(tsConfig, workspaceRoot, projectRoot, projectReferences = {}) {
|
|
335
|
-
walkProjectReferences(tsConfig, workspaceRoot, projectRoot, (configPath, config) => {
|
|
336
|
-
if (isExternalProjectReference(configPath, workspaceRoot, projectRoot)) {
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
projectReferences[configPath] = config;
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
return projectReferences;
|
|
344
|
-
}
|
|
345
|
-
function resolveShallowExternalProjectReferences(tsConfig, workspaceRoot, projectRoot, projectReferences = {}) {
|
|
346
|
-
walkProjectReferences(tsConfig, workspaceRoot, projectRoot, (configPath, config) => {
|
|
347
|
-
if (isExternalProjectReference(configPath, workspaceRoot, projectRoot)) {
|
|
348
|
-
projectReferences[configPath] = config;
|
|
349
|
-
}
|
|
350
|
-
return false;
|
|
351
|
-
});
|
|
352
|
-
return projectReferences;
|
|
353
|
-
}
|
|
354
|
-
function walkProjectReferences(tsConfig, workspaceRoot, projectRoot, visitor, // false stops recursion
|
|
355
|
-
projectReferences = {}) {
|
|
356
324
|
if (!tsConfig.projectReferences?.length) {
|
|
357
325
|
return projectReferences;
|
|
358
326
|
}
|
|
@@ -366,14 +334,15 @@ projectReferences = {}) {
|
|
|
366
334
|
// the referenced tsconfig doesn't exist, ignore it
|
|
367
335
|
continue;
|
|
368
336
|
}
|
|
337
|
+
if (isExternalProjectReference(refConfigPath, workspaceRoot, projectRoot)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
369
340
|
if (!refConfigPath.endsWith('.json')) {
|
|
370
341
|
refConfigPath = (0, node_path_1.join)(refConfigPath, 'tsconfig.json');
|
|
371
342
|
}
|
|
372
343
|
const refTsConfig = readCachedTsConfig(refConfigPath);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
walkProjectReferences(refTsConfig, workspaceRoot, projectRoot, visitor);
|
|
376
|
-
}
|
|
344
|
+
projectReferences[refConfigPath] = refTsConfig;
|
|
345
|
+
resolveInternalProjectReferences(refTsConfig, workspaceRoot, projectRoot, projectReferences);
|
|
377
346
|
}
|
|
378
347
|
return projectReferences;
|
|
379
348
|
}
|
|
@@ -2,5 +2,4 @@ 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
4
|
export declare function isUsingPackageManagerWorkspaces(tree: Tree): boolean;
|
|
5
|
-
export declare function isWorkspacesEnabled(tree: Tree): boolean;
|
|
6
5
|
export declare function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState, workspaceRoot: string): GeneratorCallback;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProjectPackageManagerWorkspaceState = getProjectPackageManagerWorkspaceState;
|
|
4
4
|
exports.isUsingPackageManagerWorkspaces = isUsingPackageManagerWorkspaces;
|
|
5
|
-
exports.isWorkspacesEnabled = isWorkspacesEnabled;
|
|
6
5
|
exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageManagerWorkspaceStateWarningTask;
|
|
7
6
|
const devkit_1 = require("@nx/devkit");
|
|
8
7
|
const minimatch_1 = require("minimatch");
|
|
@@ -18,19 +17,7 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
|
18
17
|
return isIncluded ? 'included' : 'excluded';
|
|
19
18
|
}
|
|
20
19
|
function isUsingPackageManagerWorkspaces(tree) {
|
|
21
|
-
return isWorkspacesEnabled(tree);
|
|
22
|
-
}
|
|
23
|
-
function isWorkspacesEnabled(tree
|
|
24
|
-
// packageManager: PackageManager = detectPackageManager(),
|
|
25
|
-
// root: string = workspaceRoot
|
|
26
|
-
) {
|
|
27
|
-
const packageManager = (0, devkit_1.detectPackageManager)(tree.root);
|
|
28
|
-
if (packageManager === 'pnpm') {
|
|
29
|
-
return tree.exists('pnpm-workspace.yaml');
|
|
30
|
-
}
|
|
31
|
-
// yarn and npm both use the same 'workspaces' property in package.json
|
|
32
|
-
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
33
|
-
return !!packageJson?.workspaces;
|
|
20
|
+
return (0, devkit_1.isWorkspacesEnabled)((0, devkit_1.detectPackageManager)(tree.root), tree.root);
|
|
34
21
|
}
|
|
35
22
|
function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState, workspaceRoot) {
|
|
36
23
|
return () => {
|
|
@@ -2,4 +2,3 @@ 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 updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
|
|
@@ -3,11 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isUsingTypeScriptPlugin = isUsingTypeScriptPlugin;
|
|
4
4
|
exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
|
|
5
5
|
exports.assertNotUsingTsSolutionSetup = assertNotUsingTsSolutionSetup;
|
|
6
|
-
exports.updateTsconfigFiles = updateTsconfigFiles;
|
|
7
6
|
const devkit_1 = require("@nx/devkit");
|
|
8
7
|
const tree_1 = require("nx/src/generators/tree");
|
|
9
8
|
const package_manager_workspaces_1 = require("../package-manager-workspaces");
|
|
10
|
-
const posix_1 = require("node:path/posix");
|
|
11
9
|
function isUsingTypeScriptPlugin(tree) {
|
|
12
10
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
13
11
|
return (nxJson?.plugins?.some((p) => typeof p === 'string'
|
|
@@ -67,63 +65,3 @@ function assertNotUsingTsSolutionSetup(tree, pluginName, generatorName) {
|
|
|
67
65
|
});
|
|
68
66
|
process.exit(1);
|
|
69
67
|
}
|
|
70
|
-
function updateTsconfigFiles(tree, projectRoot, runtimeTsconfigFileName, compilerOptions, exclude = [], rootDir = 'src') {
|
|
71
|
-
if (!isUsingTsSolutionSetup(tree))
|
|
72
|
-
return;
|
|
73
|
-
const offset = (0, devkit_1.offsetFromRoot)(projectRoot);
|
|
74
|
-
const tsconfig = `${projectRoot}/${runtimeTsconfigFileName}`;
|
|
75
|
-
const tsconfigSpec = `${projectRoot}/tsconfig.spec.json`;
|
|
76
|
-
const e2eRoot = `${projectRoot}-e2e`;
|
|
77
|
-
const tsconfigE2E = `${e2eRoot}/tsconfig.json`;
|
|
78
|
-
if (tree.exists(tsconfig)) {
|
|
79
|
-
(0, devkit_1.updateJson)(tree, tsconfig, (json) => {
|
|
80
|
-
json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
|
|
81
|
-
json.compilerOptions = {
|
|
82
|
-
...json.compilerOptions,
|
|
83
|
-
// Make sure d.ts files from typecheck does not conflict with bundlers.
|
|
84
|
-
// Other tooling like jest write to "out-tsc/jest" to we just default to "out-tsc/<project-name>".
|
|
85
|
-
outDir: (0, devkit_1.joinPathFragments)('out-tsc', projectRoot.split('/').at(-1)),
|
|
86
|
-
rootDir,
|
|
87
|
-
...compilerOptions,
|
|
88
|
-
};
|
|
89
|
-
const excludeSet = json.exclude
|
|
90
|
-
? new Set(['dist', ...json.exclude, ...exclude])
|
|
91
|
-
: new Set(exclude);
|
|
92
|
-
json.exclude = Array.from(excludeSet);
|
|
93
|
-
return json;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (tree.exists(tsconfigSpec)) {
|
|
97
|
-
(0, devkit_1.updateJson)(tree, tsconfigSpec, (json) => {
|
|
98
|
-
json.extends = (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json');
|
|
99
|
-
json.compilerOptions = {
|
|
100
|
-
...json.compilerOptions,
|
|
101
|
-
...compilerOptions,
|
|
102
|
-
};
|
|
103
|
-
const runtimePath = `./${runtimeTsconfigFileName}`;
|
|
104
|
-
json.references ??= [];
|
|
105
|
-
if (!json.references.some((x) => x.path === runtimePath))
|
|
106
|
-
json.references.push({ path: runtimePath });
|
|
107
|
-
return json;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (tree.exists(tsconfigE2E)) {
|
|
111
|
-
// tsconfig.json for e2e projects need to have references array
|
|
112
|
-
(0, devkit_1.updateJson)(tree, tsconfigE2E, (json) => {
|
|
113
|
-
json.references ??= [];
|
|
114
|
-
const projectPath = (0, posix_1.relative)(e2eRoot, projectRoot);
|
|
115
|
-
if (!json.references.some((x) => x.path === projectPath))
|
|
116
|
-
json.references.push({ path: projectPath });
|
|
117
|
-
return json;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
if (tree.exists('tsconfig.json')) {
|
|
121
|
-
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
122
|
-
const projectPath = './' + projectRoot;
|
|
123
|
-
json.references ??= [];
|
|
124
|
-
if (!json.references.some((x) => x.path === projectPath))
|
|
125
|
-
json.references.push({ path: projectPath });
|
|
126
|
-
return json;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|