@nx/workspace 20.4.0-canary.20250123-7524356 → 20.4.0-canary.20250124-45847a6
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/generators/convert-to-monorepo/convert-to-monorepo.js +6 -3
- package/src/generators/move/lib/normalize-schema.js +6 -4
- package/src/generators/move/lib/utils.d.ts +0 -16
- package/src/generators/move/lib/utils.js +0 -31
- package/src/utils/ts-solution-setup.d.ts +2 -0
- package/src/utils/ts-solution-setup.js +21 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/workspace",
|
3
|
-
"version": "20.4.0-canary.
|
3
|
+
"version": "20.4.0-canary.20250124-45847a6",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
|
6
6
|
"repository": {
|
@@ -38,12 +38,12 @@
|
|
38
38
|
}
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@nx/devkit": "20.4.0-canary.
|
41
|
+
"@nx/devkit": "20.4.0-canary.20250124-45847a6",
|
42
42
|
"chalk": "^4.1.0",
|
43
43
|
"enquirer": "~2.3.6",
|
44
44
|
"tslib": "^2.3.0",
|
45
45
|
"yargs-parser": "21.1.1",
|
46
|
-
"nx": "20.4.0-canary.
|
46
|
+
"nx": "20.4.0-canary.20250124-45847a6"
|
47
47
|
},
|
48
48
|
"publishConfig": {
|
49
49
|
"access": "public"
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.monorepoGenerator = monorepoGenerator;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const move_1 = require("../move/move");
|
6
|
+
const ts_solution_setup_1 = require("../../utils/ts-solution-setup");
|
6
7
|
async function monorepoGenerator(tree, options) {
|
7
8
|
const projects = (0, devkit_1.getProjects)(tree);
|
8
9
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
@@ -22,7 +23,8 @@ async function monorepoGenerator(tree, options) {
|
|
22
23
|
// Currently, Nx only handles apps+libs or packages. You cannot mix and match them.
|
23
24
|
// If the standalone project is an app (React, Angular, etc), then use apps+libs.
|
24
25
|
// Otherwise, for TS standalone (lib), use packages.
|
25
|
-
const isRootProjectApp = rootProject.projectType ===
|
26
|
+
const isRootProjectApp = (0, ts_solution_setup_1.getProjectType)(tree, rootProject.root, rootProject.projectType) ===
|
27
|
+
'application';
|
26
28
|
const appsDir = isRootProjectApp ? 'apps' : 'packages';
|
27
29
|
const libsDir = isRootProjectApp ? 'libs' : 'packages';
|
28
30
|
if (rootProject) {
|
@@ -38,13 +40,14 @@ async function monorepoGenerator(tree, options) {
|
|
38
40
|
});
|
39
41
|
}
|
40
42
|
for (const project of projectsToMove) {
|
43
|
+
const projectType = (0, ts_solution_setup_1.getProjectType)(tree, project.root, project.projectType);
|
41
44
|
await (0, move_1.moveGenerator)(tree, {
|
42
45
|
projectName: project.name,
|
43
46
|
newProjectName: project.name,
|
44
|
-
destination:
|
47
|
+
destination: projectType === 'application'
|
45
48
|
? (0, devkit_1.joinPathFragments)(appsDir, project.root === '.' ? project.name : project.root)
|
46
49
|
: (0, devkit_1.joinPathFragments)(libsDir, project.root === '.' ? project.name : project.root),
|
47
|
-
updateImportPath:
|
50
|
+
updateImportPath: projectType === 'library',
|
48
51
|
});
|
49
52
|
}
|
50
53
|
}
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeSchema = normalizeSchema;
|
4
4
|
const get_import_path_1 = require("../../../utilities/get-import-path");
|
5
5
|
const utils_1 = require("./utils");
|
6
|
+
const ts_solution_setup_1 = require("../../../utils/ts-solution-setup");
|
6
7
|
async function normalizeSchema(tree, schema, projectConfiguration) {
|
7
8
|
const { destination, newProjectName, importPath } = await determineProjectNameAndRootOptions(tree, schema, projectConfiguration);
|
8
9
|
return {
|
@@ -14,11 +15,11 @@ async function normalizeSchema(tree, schema, projectConfiguration) {
|
|
14
15
|
};
|
15
16
|
}
|
16
17
|
async function determineProjectNameAndRootOptions(tree, options, projectConfiguration) {
|
17
|
-
validateName(options.newProjectName, projectConfiguration);
|
18
|
+
validateName(tree, options.newProjectName, projectConfiguration);
|
18
19
|
const projectNameAndRootOptions = getProjectNameAndRootOptions(tree, options, projectConfiguration);
|
19
20
|
return projectNameAndRootOptions;
|
20
21
|
}
|
21
|
-
function validateName(name, projectConfiguration) {
|
22
|
+
function validateName(tree, name, projectConfiguration) {
|
22
23
|
if (!name) {
|
23
24
|
return;
|
24
25
|
}
|
@@ -34,13 +35,14 @@ function validateName(name, projectConfiguration) {
|
|
34
35
|
*/
|
35
36
|
const libraryPattern = '(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$';
|
36
37
|
const appPattern = '^[a-zA-Z][^:]*$';
|
37
|
-
|
38
|
+
const projectType = (0, ts_solution_setup_1.getProjectType)(tree, projectConfiguration.root, projectConfiguration.projectType);
|
39
|
+
if (projectType === 'application') {
|
38
40
|
const validationRegex = new RegExp(appPattern);
|
39
41
|
if (!validationRegex.test(name)) {
|
40
42
|
throw new Error(`The new project name should match the pattern "${appPattern}". The provided value "${name}" does not match.`);
|
41
43
|
}
|
42
44
|
}
|
43
|
-
else if (projectConfiguration.projectType === 'library') {
|
45
|
+
else if ((0, ts_solution_setup_1.getProjectType)(tree, projectConfiguration.root, projectConfiguration.projectType) === 'library') {
|
44
46
|
const validationRegex = new RegExp(libraryPattern);
|
45
47
|
if (!validationRegex.test(name)) {
|
46
48
|
throw new Error(`The new project name should match the pattern "${libraryPattern}". The provided value "${name}" does not match.`);
|
@@ -1,19 +1,3 @@
|
|
1
|
-
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
2
|
-
import { Schema } from '../schema';
|
3
|
-
/**
|
4
|
-
* This helper function ensures that we don't move libs or apps
|
5
|
-
* outside of the folders they should be in.
|
6
|
-
*
|
7
|
-
* This will break if someone isn't using the default libs/apps
|
8
|
-
* folders. In that case, they're on their own :/
|
9
|
-
*/
|
10
|
-
export declare function getDestination(host: Tree, schema: Schema, project: ProjectConfiguration): string;
|
11
|
-
/**
|
12
|
-
* Joins path segments replacing slashes with dashes
|
13
|
-
*
|
14
|
-
* @param path
|
15
|
-
*/
|
16
|
-
export declare function getNewProjectName(path: string): string;
|
17
1
|
/**
|
18
2
|
* Normalizes slashes (removes duplicates)
|
19
3
|
*
|
@@ -1,38 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getDestination = getDestination;
|
4
|
-
exports.getNewProjectName = getNewProjectName;
|
5
3
|
exports.normalizePathSlashes = normalizePathSlashes;
|
6
4
|
const devkit_1 = require("@nx/devkit");
|
7
|
-
/**
|
8
|
-
* This helper function ensures that we don't move libs or apps
|
9
|
-
* outside of the folders they should be in.
|
10
|
-
*
|
11
|
-
* This will break if someone isn't using the default libs/apps
|
12
|
-
* folders. In that case, they're on their own :/
|
13
|
-
*/
|
14
|
-
function getDestination(host, schema, project) {
|
15
|
-
const projectType = project.projectType;
|
16
|
-
const workspaceLayout = (0, devkit_1.getWorkspaceLayout)(host);
|
17
|
-
let rootFolder = workspaceLayout.libsDir;
|
18
|
-
if (projectType === 'application') {
|
19
|
-
rootFolder = workspaceLayout.appsDir;
|
20
|
-
}
|
21
|
-
return (0, devkit_1.joinPathFragments)(rootFolder, schema.destination);
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* Joins path segments replacing slashes with dashes
|
25
|
-
*
|
26
|
-
* @param path
|
27
|
-
*/
|
28
|
-
function getNewProjectName(path) {
|
29
|
-
// strip leading '/' or './' or '../' and trailing '/' and replaces '/' with '-'
|
30
|
-
return (0, devkit_1.normalizePath)(path)
|
31
|
-
.replace(/(^\.{0,2}\/|\.{1,2}\/|\/$)/g, '')
|
32
|
-
.split('/')
|
33
|
-
.filter((x) => !!x)
|
34
|
-
.join('-');
|
35
|
-
}
|
36
5
|
/**
|
37
6
|
* Normalizes slashes (removes duplicates)
|
38
7
|
*
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getProjectType = getProjectType;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
// This is copied from `@nx/js` to avoid circular dependencies.
|
6
|
+
function getProjectType(tree, projectRoot, projectType) {
|
7
|
+
if (projectType)
|
8
|
+
return projectType;
|
9
|
+
if ((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.lib.json'))
|
10
|
+
return 'library';
|
11
|
+
if ((0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.app.json'))
|
12
|
+
return 'application';
|
13
|
+
// If there are no exports, assume it is an application since both buildable and non-buildable libraries have exports.
|
14
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(projectRoot, 'package.json');
|
15
|
+
const packageJson = tree.exists(packageJsonPath)
|
16
|
+
? (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))
|
17
|
+
: null;
|
18
|
+
if (!packageJson?.exports)
|
19
|
+
return 'application';
|
20
|
+
return 'library';
|
21
|
+
}
|