New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@nx/workspace

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx/workspace - npm Package Compare versions

Comparing version

to
0.0.0-pr-29860-d639246

{
"name": "@nx/workspace",
"version": "0.0.0-pr-29860-74361a9",
"version": "0.0.0-pr-29860-d639246",
"private": false,

@@ -41,8 +41,10 @@ "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.",

"dependencies": {
"@nx/devkit": "0.0.0-pr-29860-74361a9",
"@nx/devkit": "0.0.0-pr-29860-d639246",
"@zkochan/js-yaml": "0.0.7",
"chalk": "^4.1.0",
"enquirer": "~2.3.6",
"picomatch": "4.0.2",
"tslib": "^2.3.0",
"yargs-parser": "21.1.1",
"nx": "0.0.0-pr-29860-74361a9"
"nx": "0.0.0-pr-29860-d639246"
},

@@ -49,0 +51,0 @@ "publishConfig": {

@@ -8,2 +8,3 @@ "use strict";

const nx_cloud_utils_1 = require("nx/src/utils/nx-cloud-utils");
const ts_solution_setup_1 = require("../../utilities/typescript/ts-solution-setup");
async function ciWorkflowGenerator(tree, schema) {

@@ -39,2 +40,3 @@ const ci = schema.ci;

const hasE2E = hasCypress || hasPlaywright;
const hasTypecheck = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
const connectedToCloud = (0, nx_cloud_utils_1.isNxCloudUsed)((0, devkit_1.readJson)(tree, 'nx.json'));

@@ -52,2 +54,3 @@ return {

hasPlaywright,
hasTypecheck,
nxCloudHost,

@@ -54,0 +57,0 @@ tmpl: '',

@@ -51,4 +51,10 @@ "use strict";

}
// Create a new project with the root replaced
(0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
if (schema.isNxConfiguredInPackageJson) {
// Update the existing project configuration in the package.json
(0, devkit_1.updateProjectConfiguration)(tree, schema.newProjectName, newProject);
}
else {
// Create a new project with the root replaced
(0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeSchema = normalizeSchema;
const devkit_1 = require("@nx/devkit");
const get_import_path_1 = require("../../../utilities/get-import-path");

@@ -9,2 +10,3 @@ const utils_1 = require("./utils");

const { destination, newProjectName, importPath } = await determineProjectNameAndRootOptions(tree, schema, projectConfiguration);
const isNxConfiguredInPackageJson = !tree.exists((0, devkit_1.joinPathFragments)(projectConfiguration.root, 'project.json'));
return {

@@ -16,2 +18,3 @@ ...schema,

relativeToRootDestination: destination,
isNxConfiguredInPackageJson,
};

@@ -21,4 +24,31 @@ }

validateName(tree, options.newProjectName, projectConfiguration);
const projectNameAndRootOptions = getProjectNameAndRootOptions(tree, options, projectConfiguration);
return projectNameAndRootOptions;
let destination = (0, utils_1.normalizePathSlashes)(options.destination);
if (options.newProjectName &&
options.newProjectName.includes('/') &&
!options.newProjectName.startsWith('@')) {
throw new Error(`You can't specify a new project name with a directory path (${options.newProjectName}). ` +
`Please provide a valid name without path segments and the full destination with the "--destination" option.`);
}
const newProjectName = options.newProjectName ?? options.projectName;
if (projectConfiguration.projectType !== 'library') {
return { destination, newProjectName };
}
let importPath = options.importPath;
if (importPath) {
return { destination, newProjectName, importPath };
}
if (options.newProjectName?.startsWith('@')) {
// keep the existing import path if the name didn't change
importPath =
options.newProjectName && options.projectName !== options.newProjectName
? newProjectName
: undefined;
}
else if (options.newProjectName) {
const npmScope = (0, get_import_path_1.getNpmScope)(tree);
importPath = npmScope
? `${npmScope === '@' ? '' : '@'}${npmScope}/${newProjectName}`
: newProjectName;
}
return { destination, newProjectName, importPath };
}

@@ -55,37 +85,1 @@ function validateName(tree, name, projectConfiguration) {

}
function getProjectNameAndRootOptions(tree, options, projectConfiguration) {
let destination = (0, utils_1.normalizePathSlashes)(options.destination);
if (options.newProjectName &&
options.newProjectName.includes('/') &&
!options.newProjectName.startsWith('@')) {
throw new Error(`You can't specify a new project name with a directory path (${options.newProjectName}). ` +
`Please provide a valid name without path segments and the full destination with the "--destination" option.`);
}
const asProvidedOptions = getAsProvidedOptions(tree, { ...options, destination }, projectConfiguration);
return asProvidedOptions;
}
function getAsProvidedOptions(tree, options, projectConfiguration) {
const newProjectName = options.newProjectName ?? options.projectName;
const destination = options.destination;
if (projectConfiguration.projectType !== 'library') {
return { destination, newProjectName };
}
let importPath = options.importPath;
if (importPath) {
return { destination, newProjectName, importPath };
}
if (options.newProjectName?.startsWith('@')) {
// keep the existing import path if the name didn't change
importPath =
options.newProjectName && options.projectName !== options.newProjectName
? newProjectName
: undefined;
}
else if (options.newProjectName) {
const npmScope = (0, get_import_path_1.getNpmScope)(tree);
importPath = npmScope
? `${npmScope === '@' ? '' : '@'}${npmScope}/${newProjectName}`
: newProjectName;
}
return { destination, newProjectName, importPath };
}

@@ -1,4 +0,4 @@

import { Tree } from '@nx/devkit';
import { type GeneratorCallback, type Tree } from '@nx/devkit';
import { Schema } from './schema';
export declare function moveGenerator(tree: Tree, rawSchema: Schema): Promise<void>;
export declare function moveGenerator(tree: Tree, rawSchema: Schema): Promise<GeneratorCallback>;
export default moveGenerator;

@@ -5,4 +5,7 @@ "use strict";

const devkit_1 = require("@nx/devkit");
const package_manager_workspaces_1 = require("../../utilities/package-manager-workspaces");
const ts_solution_setup_1 = require("../../utilities/typescript/ts-solution-setup");
const check_destination_1 = require("./lib/check-destination");
const create_project_configuration_in_new_destination_1 = require("./lib/create-project-configuration-in-new-destination");
const extract_base_configs_1 = require("./lib/extract-base-configs");
const move_project_files_1 = require("./lib/move-project-files");

@@ -22,5 +25,5 @@ const normalize_schema_1 = require("./lib/normalize-schema");

const update_storybook_config_1 = require("./lib/update-storybook-config");
const extract_base_configs_1 = require("./lib/extract-base-configs");
async function moveGenerator(tree, rawSchema) {
let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, rawSchema.projectName);
const wasIncludedInWorkspaces = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, projectConfig.root);
const schema = await (0, normalize_schema_1.normalizeSchema)(tree, rawSchema, projectConfig);

@@ -53,6 +56,21 @@ (0, check_destination_1.checkDestination)(tree, schema, rawSchema.destination);

await (0, run_angular_plugin_1.runAngularPlugin)(tree, schema);
let task;
if (wasIncludedInWorkspaces) {
// check if the new destination is included in the package manager workspaces
const isIncludedInWorkspaces = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, schema.destination);
if (!isIncludedInWorkspaces) {
// the new destination is not included in the package manager workspaces
// so we need to add it and run a package install to ensure the symlink
// is created
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, schema.destination);
task = () => (0, devkit_1.installPackagesTask)(tree, true);
}
}
if (!schema.skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
if (task) {
return task;
}
}
exports.default = moveGenerator;

@@ -12,2 +12,3 @@ export interface Schema {

relativeToRootDestination: string;
isNxConfiguredInPackageJson?: boolean;
}

@@ -7,6 +7,5 @@ "use strict";

const path_1 = require("path");
const get_import_path_1 = require("../../utilities/get-import-path");
async function normalizeOptions(tree, options) {
await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
const { projectName, projectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
const { projectName, projectRoot, importPath } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
name: options.name,

@@ -20,2 +19,3 @@ projectType: 'library',

projectRoot,
importPath,
};

@@ -26,3 +26,3 @@ }

(0, devkit_1.writeJson)(tree, packageJsonPath, {
name: (0, get_import_path_1.getImportPath)(tree, options.name),
name: options.importPath,
version: '0.0.0',

@@ -29,0 +29,0 @@ scripts: {

@@ -76,2 +76,3 @@ "use strict";

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -110,2 +111,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -142,2 +144,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -174,2 +177,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -207,2 +211,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -253,2 +258,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -267,2 +273,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -284,2 +291,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -299,2 +307,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -358,2 +367,3 @@ }

formatter: options.formatter,
useProjectJson: !options.workspaces,
});

@@ -360,0 +370,0 @@ }

import { type Tree } from '@nx/devkit';
export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): Promise<void>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
const devkit_1 = require("@nx/devkit");
const posix_1 = require("node:path/posix");
const tree_1 = require("nx/src/generators/tree");
const package_manager_workspaces_1 = require("../package-manager-workspaces");
function isUsingPackageManagerWorkspaces(tree) {

@@ -58,1 +61,46 @@ return isWorkspacesEnabled(tree);

}
async function addProjectToTsSolutionWorkspace(tree, projectDir) {
const isIncluded = (0, package_manager_workspaces_1.isProjectIncludedInPackageManagerWorkspaces)(tree, projectDir);
if (isIncluded) {
return;
}
// If dir is "libs/foo", we try to use "libs/*" but we only do it if it's
// safe to do so. So, we first check if adding that pattern doesn't result
// in extra projects being matched. If extra projects are matched, or the
// dir is just "foo" then we add it as is.
const baseDir = (0, posix_1.dirname)(projectDir);
let pattern = projectDir;
if (baseDir !== '.') {
const patterns = (0, package_manager_workspaces_1.getPackageManagerWorkspacesPatterns)(tree);
const projectsBefore = await (0, devkit_1.globAsync)(tree, patterns);
patterns.push(`${baseDir}/*/package.json`);
const projectsAfter = await (0, devkit_1.globAsync)(tree, patterns);
if (projectsBefore.length + 1 === projectsAfter.length) {
// Adding the pattern to the parent directory only results in one extra
// project being matched, which is the project we're adding. It's safe
// to add the pattern to the parent directory.
pattern = `${baseDir}/*`;
}
}
if (tree.exists('pnpm-workspace.yaml')) {
const { load, dump } = require('@zkochan/js-yaml');
const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
const yamlData = load(workspaceFile) ?? {};
yamlData.packages ??= [];
if (!yamlData.packages.includes(pattern)) {
yamlData.packages.push(pattern);
tree.write('pnpm-workspace.yaml', dump(yamlData, { indent: 2, quotingType: '"', forceQuotes: true }));
}
}
else {
// Update package.json
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
if (!packageJson.workspaces) {
packageJson.workspaces = [];
}
if (!packageJson.workspaces.includes(pattern)) {
packageJson.workspaces.push(pattern);
tree.write('package.json', JSON.stringify(packageJson, null, 2));
}
}
}
export declare const nxVersion: any;
export declare const typescriptVersion = "~5.7.2";
export declare const angularCliVersion = "~19.1.0";
export declare const angularCliVersion = "~19.2.0";

@@ -8,2 +8,2 @@ "use strict";

// deps are not installed from workspace
exports.angularCliVersion = '~19.1.0';
exports.angularCliVersion = '~19.2.0';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet