Socket
Socket
Sign inDemoInstall

@nrwl/devkit

Package Overview
Dependencies
Maintainers
1
Versions
1295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nrwl/devkit - npm Package Compare versions

Comparing version 11.1.5 to 11.2.0-beta.1

src/generators/to-js.d.ts

13

index.d.ts
export { Tree, FileChange } from '@nrwl/tao/src/shared/tree';
export { WorkspaceConfiguration, TargetConfiguration, ProjectConfiguration, Generator, GeneratorCallback, } from '@nrwl/tao/src/shared/workspace';
export { WorkspaceConfiguration, TargetConfiguration, ProjectConfiguration, Generator, GeneratorCallback, Executor, ExecutorContext, } from '@nrwl/tao/src/shared/workspace';
export { NxJsonConfiguration, NxJsonProjectConfiguration, } from '@nrwl/tao/src/shared/nx';
export { logger } from '@nrwl/tao/src/shared/logger';
export { TargetContext } from '@nrwl/tao/src/commands/run';
export { getPackageManagerCommand } from '@nrwl/tao/src/shared/package-manager';
export { runExecutor } from '@nrwl/tao/src/commands/run';
export { formatFiles } from './src/generators/format-files';
export { generateFiles } from './src/generators/generate-files';
export { addProjectConfiguration, readProjectConfiguration, updateProjectConfiguration, } from './src/generators/project-configuration';
export { addProjectConfiguration, readProjectConfiguration, removeProjectConfiguration, updateProjectConfiguration, readWorkspaceConfiguration, updateWorkspaceConfiguration, getProjects, } from './src/generators/project-configuration';
export { toJS } from './src/generators/to-js';
export { visitNotIgnoredFiles } from './src/generators/visit-not-ignored-files';
export { readJson, writeJson, updateJson } from './src/utils/json';

@@ -13,5 +16,7 @@ export { addDependenciesToPackageJson } from './src/utils/package-json';

export { names } from './src/utils/names';
export { getWorkspaceLayout } from './src/utils/get-workspace-layout';
export { getWorkspaceLayout, getWorkspacePath, } from './src/utils/get-workspace-layout';
export { applyChangesToString, ChangeType, StringChange, StringDeletion, StringInsertion, } from './src/utils/string-change';
export { offsetFromRoot } from './src/utils/offset-from-root';
export { convertNxGenerator } from './src/utils/invoke-nx-generator';
export { convertNxExecutor } from './src/utils/convert-nx-executor';
export { stripIndents } from './src/utils/strip-indents';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertNxGenerator = exports.offsetFromRoot = exports.ChangeType = exports.applyChangesToString = exports.getWorkspaceLayout = exports.names = exports.installPackagesTask = exports.addDependenciesToPackageJson = exports.updateJson = exports.writeJson = exports.readJson = exports.updateProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.generateFiles = exports.formatFiles = exports.logger = void 0;
exports.stripIndents = exports.convertNxExecutor = exports.convertNxGenerator = exports.offsetFromRoot = exports.ChangeType = exports.applyChangesToString = exports.getWorkspacePath = exports.getWorkspaceLayout = exports.names = exports.installPackagesTask = exports.addDependenciesToPackageJson = exports.updateJson = exports.writeJson = exports.readJson = exports.visitNotIgnoredFiles = exports.toJS = exports.getProjects = exports.updateWorkspaceConfiguration = exports.readWorkspaceConfiguration = exports.updateProjectConfiguration = exports.removeProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.generateFiles = exports.formatFiles = exports.runExecutor = exports.getPackageManagerCommand = exports.logger = void 0;
var logger_1 = require("@nrwl/tao/src/shared/logger");
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
var package_manager_1 = require("@nrwl/tao/src/shared/package-manager");
Object.defineProperty(exports, "getPackageManagerCommand", { enumerable: true, get: function () { return package_manager_1.getPackageManagerCommand; } });
var run_1 = require("@nrwl/tao/src/commands/run");
Object.defineProperty(exports, "runExecutor", { enumerable: true, get: function () { return run_1.runExecutor; } });
var format_files_1 = require("./src/generators/format-files");

@@ -13,3 +17,11 @@ Object.defineProperty(exports, "formatFiles", { enumerable: true, get: function () { return format_files_1.formatFiles; } });

Object.defineProperty(exports, "readProjectConfiguration", { enumerable: true, get: function () { return project_configuration_1.readProjectConfiguration; } });
Object.defineProperty(exports, "removeProjectConfiguration", { enumerable: true, get: function () { return project_configuration_1.removeProjectConfiguration; } });
Object.defineProperty(exports, "updateProjectConfiguration", { enumerable: true, get: function () { return project_configuration_1.updateProjectConfiguration; } });
Object.defineProperty(exports, "readWorkspaceConfiguration", { enumerable: true, get: function () { return project_configuration_1.readWorkspaceConfiguration; } });
Object.defineProperty(exports, "updateWorkspaceConfiguration", { enumerable: true, get: function () { return project_configuration_1.updateWorkspaceConfiguration; } });
Object.defineProperty(exports, "getProjects", { enumerable: true, get: function () { return project_configuration_1.getProjects; } });
var to_js_1 = require("./src/generators/to-js");
Object.defineProperty(exports, "toJS", { enumerable: true, get: function () { return to_js_1.toJS; } });
var visit_not_ignored_files_1 = require("./src/generators/visit-not-ignored-files");
Object.defineProperty(exports, "visitNotIgnoredFiles", { enumerable: true, get: function () { return visit_not_ignored_files_1.visitNotIgnoredFiles; } });
var json_1 = require("./src/utils/json");

@@ -27,2 +39,3 @@ Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return json_1.readJson; } });

Object.defineProperty(exports, "getWorkspaceLayout", { enumerable: true, get: function () { return get_workspace_layout_1.getWorkspaceLayout; } });
Object.defineProperty(exports, "getWorkspacePath", { enumerable: true, get: function () { return get_workspace_layout_1.getWorkspacePath; } });
var string_change_1 = require("./src/utils/string-change");

@@ -35,2 +48,6 @@ Object.defineProperty(exports, "applyChangesToString", { enumerable: true, get: function () { return string_change_1.applyChangesToString; } });

Object.defineProperty(exports, "convertNxGenerator", { enumerable: true, get: function () { return invoke_nx_generator_1.convertNxGenerator; } });
var convert_nx_executor_1 = require("./src/utils/convert-nx-executor");
Object.defineProperty(exports, "convertNxExecutor", { enumerable: true, get: function () { return convert_nx_executor_1.convertNxExecutor; } });
var strip_indents_1 = require("./src/utils/strip-indents");
Object.defineProperty(exports, "stripIndents", { enumerable: true, get: function () { return strip_indents_1.stripIndents; } });
//# sourceMappingURL=index.js.map
{
"name": "@nrwl/devkit",
"version": "11.1.5",
"version": "11.2.0-beta.1",
"description": "Extensible Dev Tools for Monorepos",

@@ -29,4 +29,5 @@ "repository": {

"dependencies": {
"@nrwl/tao": "11.1.5",
"@nrwl/tao": "11.2.0-beta.1",
"ejs": "^3.1.5",
"ignore": "^5.0.4",
"semver": "6.3.0",

@@ -33,0 +34,0 @@ "strip-json-comments": "2.0.1",

import { Tree } from '@nrwl/tao/src/shared/tree';
import { ProjectConfiguration } from '@nrwl/tao/src/shared/workspace';
import { ProjectConfiguration, WorkspaceConfiguration } from '@nrwl/tao/src/shared/workspace';
import { NxJsonProjectConfiguration } from '@nrwl/tao/src/shared/nx';

@@ -27,2 +27,27 @@ /**

/**
* Removes the configuration of an existing project.
*
* The project configuration is stored in workspace.json and nx.json.
* The utility will update both files.
*/
export declare function removeProjectConfiguration(host: Tree, projectName: string): void;
/**
* Get a map of all projects in a workspace.
*
* Use {@link readProjectConfiguration} if only one project is needed.
*/
export declare function getProjects(host: Tree): Map<string, ProjectConfiguration & NxJsonProjectConfiguration>;
/**
* Read general workspace configuration such as the default project or cli settings
*
* This does _not_ provide projects configuration, use {@link readProjectConfiguration} instead.
*/
export declare function readWorkspaceConfiguration(host: Tree): Omit<WorkspaceConfiguration, 'projects'>;
/**
* Update general workspace configuration such as the default project or cli settings.
*
* This does _not_ update projects configuration, use {@link updateProjectConfiguration} or {@link addProjectConfiguration} instead.
*/
export declare function updateWorkspaceConfiguration(host: Tree, workspace: Omit<WorkspaceConfiguration, 'projects'>): void;
/**
* Reads a project configuration.

@@ -29,0 +54,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readProjectConfiguration = exports.updateProjectConfiguration = exports.addProjectConfiguration = void 0;
exports.readProjectConfiguration = exports.updateWorkspaceConfiguration = exports.readWorkspaceConfiguration = exports.getProjects = exports.removeProjectConfiguration = exports.updateProjectConfiguration = exports.addProjectConfiguration = void 0;
const tslib_1 = require("tslib");

@@ -37,2 +37,50 @@ const workspace_1 = require("@nrwl/tao/src/shared/workspace");

/**
* Removes the configuration of an existing project.
*
* The project configuration is stored in workspace.json and nx.json.
* The utility will update both files.
*/
function removeProjectConfiguration(host, projectName) {
setProjectConfiguration(host, projectName, undefined, 'delete');
}
exports.removeProjectConfiguration = removeProjectConfiguration;
/**
* Get a map of all projects in a workspace.
*
* Use {@link readProjectConfiguration} if only one project is needed.
*/
function getProjects(host) {
const workspace = readWorkspace(host);
const nxJson = json_1.readJson(host, 'nx.json');
return new Map(Object.keys(workspace.projects).map((projectName) => {
return [
projectName,
getProjectConfiguration(projectName, workspace, nxJson),
];
}));
}
exports.getProjects = getProjects;
/**
* Read general workspace configuration such as the default project or cli settings
*
* This does _not_ provide projects configuration, use {@link readProjectConfiguration} instead.
*/
function readWorkspaceConfiguration(host) {
const workspace = readWorkspace(host);
delete workspace.projects;
return workspace;
}
exports.readWorkspaceConfiguration = readWorkspaceConfiguration;
/**
* Update general workspace configuration such as the default project or cli settings.
*
* This does _not_ update projects configuration, use {@link updateProjectConfiguration} or {@link addProjectConfiguration} instead.
*/
function updateWorkspaceConfiguration(host, workspace) {
json_1.updateJson(host, get_workspace_layout_1.getWorkspacePath(host), (json) => {
return Object.assign(Object.assign({}, workspace), { projects: json.projects });
});
}
exports.updateWorkspaceConfiguration = updateWorkspaceConfiguration;
/**
* Reads a project configuration.

@@ -47,15 +95,6 @@ *

function readProjectConfiguration(host, projectName) {
return Object.assign(Object.assign({}, readWorkspaceSection(host, projectName)), readNxJsonSection(host, projectName));
}
exports.readProjectConfiguration = readProjectConfiguration;
function readWorkspaceSection(host, projectName) {
const path = get_workspace_layout_1.getWorkspacePath(host);
const workspaceJson = json_1.readJson(host, path);
const newFormat = workspace_1.toNewFormat(workspaceJson);
if (!newFormat.projects[projectName]) {
throw new Error(`Cannot find configuration for '${projectName}' in ${path}.`);
const workspace = readWorkspace(host);
if (!workspace.projects[projectName]) {
throw new Error(`Cannot find configuration for '${projectName}' in ${get_workspace_layout_1.getWorkspacePath(host)}.`);
}
return newFormat.projects[projectName];
}
function readNxJsonSection(host, projectName) {
const nxJson = json_1.readJson(host, 'nx.json');

@@ -65,5 +104,23 @@ if (!nxJson.projects[projectName]) {

}
return getProjectConfiguration(projectName, workspace, nxJson);
}
exports.readProjectConfiguration = readProjectConfiguration;
function getProjectConfiguration(projectName, workspace, nxJson) {
return Object.assign(Object.assign({}, readWorkspaceSection(workspace, projectName)), readNxJsonSection(nxJson, projectName));
}
function readWorkspaceSection(workspace, projectName) {
return workspace.projects[projectName];
}
function readNxJsonSection(nxJson, projectName) {
return nxJson.projects[projectName];
}
function setProjectConfiguration(host, projectName, projectConfiguration, mode) {
if (mode === 'delete') {
addProjectToNxJson(host, projectName, undefined, mode);
addProjectToWorkspaceJson(host, projectName, undefined, mode);
return;
}
if (!projectConfiguration) {
throw new Error(`Cannot ${mode} "${projectName}" with value ${projectConfiguration}`);
}
const { tags, implicitDependencies } = projectConfiguration, workspaceConfiguration = tslib_1.__rest(projectConfiguration, ["tags", "implicitDependencies"]);

@@ -74,3 +131,3 @@ addProjectToWorkspaceJson(host, projectName, workspaceConfiguration, mode);

implicitDependencies,
});
}, mode);
}

@@ -86,12 +143,26 @@ function addProjectToWorkspaceJson(host, projectName, project, mode) {

}
if (mode == 'delete' && !workspaceJson.projects[projectName]) {
throw new Error(`Cannot update Project '${projectName}'. It does not exist.`);
}
workspaceJson.projects[projectName] = project;
host.write(path, JSON.stringify(workspaceJson));
}
function addProjectToNxJson(host, projectName, config) {
function addProjectToNxJson(host, projectName, config, mode) {
const nxJson = json_1.readJson(host, 'nx.json');
nxJson.projects[projectName] = Object.assign({
tags: [],
}, (config || {}));
if (mode === 'delete') {
delete nxJson.projects[projectName];
}
else {
nxJson.projects[projectName] = Object.assign({
tags: [],
}, (config || {}));
}
host.write('nx.json', JSON.stringify(nxJson));
}
function readWorkspace(host) {
const path = get_workspace_layout_1.getWorkspacePath(host);
const workspaceJson = json_1.readJson(host, path);
const originalVersion = workspaceJson.version;
return Object.assign(Object.assign({}, workspace_1.toNewFormat(workspaceJson)), { version: originalVersion });
}
//# sourceMappingURL=project-configuration.js.map

@@ -9,2 +9,2 @@ import { Tree } from '@nrwl/tao/src/shared/tree';

*/
export declare function installPackagesTask(host: Tree, alwaysRun?: boolean): void;
export declare function installPackagesTask(host: Tree, alwaysRun?: boolean, cwd?: string): void;

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

const package_manager_1 = require("@nrwl/tao/src/shared/package-manager");
const path_1 = require("path");
let storedPackageJsonValue;

@@ -15,10 +16,11 @@ /**

*/
function installPackagesTask(host, alwaysRun = false) {
const packageJsonValue = host.read('package.json').toString();
if (host.listChanges().find((f) => f.path === 'package.json') || alwaysRun) {
function installPackagesTask(host, alwaysRun = false, cwd = '') {
const packageJsonValue = host.read(path_1.join(cwd, 'package.json')).toString();
if (host.listChanges().find((f) => f.path === path_1.join(cwd, 'package.json')) ||
alwaysRun) {
if (storedPackageJsonValue != packageJsonValue || alwaysRun) {
storedPackageJsonValue = host.read('package.json').toString();
storedPackageJsonValue = host.read(path_1.join(cwd, 'package.json')).toString();
const pmc = package_manager_1.getPackageManagerCommand();
child_process_1.execSync(pmc.install, {
cwd: host.root,
cwd: path_1.join(host.root, cwd),
stdio: [0, 1, 2],

@@ -25,0 +27,0 @@ });

@@ -9,5 +9,5 @@ "use strict";

function createTree() {
return new tree_1.FsTree('/', false);
return new tree_1.FsTree('/virtual', false);
}
exports.createTree = createTree;
//# sourceMappingURL=create-tree.js.map

@@ -5,2 +5,2 @@ import { Generator } from '@nrwl/tao/src/shared/workspace';

*/
export declare function convertNxGenerator<T = any>(generator: Generator<T>): (options: T) => (tree: any, context: any) => any;
export declare function convertNxGenerator<T = any>(generator: Generator<T>): (options: T) => (tree: any, context: any) => Promise<any>;

@@ -40,3 +40,3 @@ "use strict";

function invokeNxGenerator(generator, options) {
return (tree, context) => {
return (tree, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (context.engine.workflow) {

@@ -46,4 +46,7 @@ const engineHost = context.engine.workflow.engineHost;

}
const adapterTree = new DevkitTreeFromAngularDevkitTree(tree);
const result = generator(adapterTree, options);
const root = context.engine.workflow
? context.engine.workflow.engineHost.paths[1]
: tree.root.path;
const adapterTree = new DevkitTreeFromAngularDevkitTree(tree, root);
const result = yield generator(adapterTree, options);
if (!result) {

@@ -57,3 +60,3 @@ return adapterTree['tree'];

}
};
});
}

@@ -66,14 +69,12 @@ const actionToFileChangeMap = {

class DevkitTreeFromAngularDevkitTree {
constructor(tree) {
constructor(tree, _root) {
this.tree = tree;
this._root = _root;
}
get root() {
return this.tree.root.path;
return this._root;
}
children(dirPath) {
const { subdirs, subfiles } = this.tree.getDir(dirPath);
return [
...subdirs.map((fragment) => path_1.join(this.root, fragment)),
...subfiles.map((fragment) => path_1.join(this.root, fragment)),
];
return [...subdirs, ...subfiles];
}

@@ -94,8 +95,8 @@ delete(filePath) {

fileChanges.push({
path: action.path,
path: this.normalize(action.to),
type: 'CREATE',
content: this.read(action.path),
content: this.read(action.to),
});
fileChanges.push({
path: action.to,
path: this.normalize(action.path),
type: 'DELETE',

@@ -107,3 +108,3 @@ content: null,

fileChanges.push({
path: action.path,
path: this.normalize(action.path),
type: actionToFileChangeMap[action.kind],

@@ -115,3 +116,3 @@ content: action.content,

fileChanges.push({
path: action.path,
path: this.normalize(action.path),
type: 'DELETE',

@@ -124,2 +125,5 @@ content: null,

}
normalize(path) {
return path_1.relative(this.root, path_1.join(this.root, path));
}
read(filePath) {

@@ -126,0 +130,0 @@ return this.tree.read(filePath);

export declare enum ChangeType {
Delete = "DELETE",
Delete = "Delete",
Insert = "Insert"

@@ -4,0 +4,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

(function (ChangeType) {
ChangeType["Delete"] = "DELETE";
ChangeType["Delete"] = "Delete";
ChangeType["Insert"] = "Insert";

@@ -43,8 +43,20 @@ })(ChangeType = exports.ChangeType || (exports.ChangeType = {}));

assertChangesValid(changes);
const sortedChanges = changes.sort((a, b) => getChangeIndex(a) - getChangeIndex(b));
const sortedChanges = changes.sort((a, b) => {
const diff = getChangeIndex(a) - getChangeIndex(b);
if (diff === 0) {
if (a.type === b.type) {
return 0;
}
else {
// When at the same place, Insert before Delete
return a.type === ChangeType.Insert ? -1 : 1;
}
}
return diff;
});
let offset = 0;
for (const change of sortedChanges) {
const index = getChangeIndex(change) + offset;
switch (change.type) {
case ChangeType.Insert: {
const index = change.index + Math.max(offset, 0);
text = text.substr(0, index) + change.text + text.substr(index);

@@ -55,5 +67,3 @@ offset += change.text.length;

case ChangeType.Delete: {
text =
text.substr(0, change.start + offset) +
text.substr(change.start + change.length + offset);
text = text.substr(0, index) + text.substr(index + change.length);
offset -= change.length;

@@ -60,0 +70,0 @@ break;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc