@nrwl/workspace 14.8.7 → 14.9.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +1 -1
- package/LICENSE +22 -22
- package/README.md +5 -26
- package/executors.json +4 -2
- package/generators.json +7 -52
- package/index.d.ts +4 -10
- package/index.js +4 -42
- package/index.js.map +1 -1
- package/migrations.json +20 -1
- package/package.json +33 -44
- package/presets/core.json +4 -9
- package/presets/npm.json +4 -12
- package/src/executors/counter/schema.json +1 -0
- package/src/executors/run-commands/schema.json +9 -1
- package/src/executors/run-script/schema.json +1 -0
- package/src/generators/ci-workflow/ci-workflow.d.ts +1 -1
- package/src/generators/ci-workflow/ci-workflow.js +13 -0
- package/src/generators/ci-workflow/ci-workflow.js.map +1 -1
- package/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ +0 -2
- package/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ +36 -0
- package/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ +1 -4
- package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ +3 -3
- package/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ +47 -0
- package/src/generators/ci-workflow/schema.json +5 -3
- package/src/generators/convert-to-nx-project/convert-to-nx-project.d.ts +1 -2
- package/src/generators/convert-to-nx-project/convert-to-nx-project.js +62 -38
- package/src/generators/convert-to-nx-project/convert-to-nx-project.js.map +1 -1
- package/src/generators/convert-to-nx-project/schema.d.ts +2 -0
- package/src/generators/convert-to-nx-project/schema.json +11 -6
- package/src/generators/library/files/lib/__dot__babelrc__tmpl__ +1 -1
- package/src/generators/library/files/lib/tsconfig.lib.json +2 -2
- package/src/generators/library/library.d.ts +2 -1
- package/src/generators/library/library.js +44 -33
- package/src/generators/library/library.js.map +1 -1
- package/src/generators/library/schema.d.ts +1 -1
- package/src/generators/library/schema.json +9 -4
- package/src/generators/move/lib/create-project-configuration-in-new-destination.d.ts +3 -0
- package/src/generators/move/lib/{move-project-configuration.js → create-project-configuration-in-new-destination.js} +6 -9
- package/src/generators/move/lib/create-project-configuration-in-new-destination.js.map +1 -0
- package/src/generators/move/lib/{move-project.d.ts → move-project-files.d.ts} +1 -1
- package/src/generators/move/lib/{move-project.js → move-project-files.js} +4 -4
- package/src/generators/move/lib/move-project-files.js.map +1 -0
- package/src/generators/move/lib/update-cypress-config.js +8 -2
- package/src/generators/move/lib/update-cypress-config.js.map +1 -1
- package/src/generators/move/lib/update-default-project.js +4 -5
- package/src/generators/move/lib/update-default-project.js.map +1 -1
- package/src/generators/move/lib/update-implicit-dependencies.d.ts +0 -2
- package/src/generators/move/lib/update-implicit-dependencies.js +0 -2
- package/src/generators/move/lib/update-implicit-dependencies.js.map +1 -1
- package/src/generators/move/lib/update-imports.js +28 -18
- package/src/generators/move/lib/update-imports.js.map +1 -1
- package/src/generators/move/move.js +5 -4
- package/src/generators/move/move.js.map +1 -1
- package/src/generators/move/schema.json +2 -1
- package/src/generators/{workspace/files → new/files-integrated-repo}/__dot__gitignore +2 -2
- package/src/generators/{workspace/files → new/files-integrated-repo}/__dot__vscode/extensions.json__tmpl__ +1 -1
- package/src/generators/new/files-integrated-repo/package.json__tmpl__ +14 -0
- package/src/generators/new/files-package-based-repo/__dot__gitignore +39 -0
- package/src/generators/new/files-package-based-repo/__dot__vscode/extensions.json__tmpl__ +8 -0
- package/src/generators/new/files-package-based-repo/package.json__tmpl__ +13 -0
- package/src/generators/new/files-readme/README.md.template +21 -0
- package/src/generators/new/files-root-app/__dot__gitignore +39 -0
- package/src/generators/new/files-root-app/__dot__vscode/extensions.json__tmpl__ +6 -0
- package/src/generators/new/files-root-app/package.json__tmpl__ +14 -0
- package/src/generators/new/generate-preset.d.ts +4 -0
- package/src/generators/new/generate-preset.js +131 -0
- package/src/generators/new/generate-preset.js.map +1 -0
- package/src/generators/new/generate-workspace-files.d.ts +3 -0
- package/src/generators/{workspace/workspace.js → new/generate-workspace-files.js} +81 -72
- package/src/generators/new/generate-workspace-files.js.map +1 -0
- package/src/generators/new/new.d.ts +11 -6
- package/src/generators/new/new.js +41 -212
- package/src/generators/new/new.js.map +1 -1
- package/src/generators/new/schema.json +16 -7
- package/src/generators/npm-package/npm-package.js +3 -6
- package/src/generators/npm-package/npm-package.js.map +1 -1
- package/src/generators/preset/preset.d.ts +1 -2
- package/src/generators/preset/preset.js +57 -255
- package/src/generators/preset/preset.js.map +1 -1
- package/src/generators/preset/schema.d.ts +5 -1
- package/src/generators/preset/schema.json +34 -7
- package/src/generators/remove/lib/check-project-is-safe-to-remove.d.ts +3 -0
- package/src/generators/remove/lib/check-project-is-safe-to-remove.js +26 -0
- package/src/generators/remove/lib/check-project-is-safe-to-remove.js.map +1 -0
- package/src/generators/remove/lib/check-targets.d.ts +1 -1
- package/src/generators/remove/lib/check-targets.js +33 -29
- package/src/generators/remove/lib/check-targets.js.map +1 -1
- package/src/generators/remove/lib/remove-project-references-in-config.d.ts +3 -0
- package/src/generators/remove/lib/remove-project-references-in-config.js +22 -0
- package/src/generators/remove/lib/remove-project-references-in-config.js.map +1 -0
- package/src/generators/remove/lib/update-jest-config.js +10 -5
- package/src/generators/remove/lib/update-jest-config.js.map +1 -1
- package/src/generators/remove/lib/update-tsconfig.d.ts +2 -2
- package/src/generators/remove/lib/update-tsconfig.js +23 -15
- package/src/generators/remove/lib/update-tsconfig.js.map +1 -1
- package/src/generators/remove/remove.js +6 -4
- package/src/generators/remove/remove.js.map +1 -1
- package/src/generators/remove/schema.json +2 -1
- package/src/generators/run-commands/run-commands.js +3 -1
- package/src/generators/run-commands/run-commands.js.map +1 -1
- package/src/generators/run-commands/schema.json +2 -1
- package/src/generators/utils/insert-import.js +10 -5
- package/src/generators/utils/insert-import.js.map +1 -1
- package/src/generators/utils/insert-statement.js +8 -3
- package/src/generators/utils/insert-statement.js.map +1 -1
- package/src/generators/utils/presets.d.ts +6 -5
- package/src/generators/utils/presets.js +5 -4
- package/src/generators/utils/presets.js.map +1 -1
- package/src/generators/workspace-generator/schema.json +3 -2
- package/src/migrations/update-12-5-0/add-target-dependencies.js +2 -2
- package/src/migrations/update-12-5-0/add-target-dependencies.js.map +1 -1
- package/src/migrations/update-13-0-0/config-locations/config-locations.d.ts +1 -1
- package/src/migrations/update-13-0-0/config-locations/config-locations.js +19 -9
- package/src/migrations/update-13-0-0/config-locations/config-locations.js.map +1 -1
- package/src/migrations/update-13-0-0/set-default-base-if-not-set.js +2 -2
- package/src/migrations/update-13-0-0/set-default-base-if-not-set.js.map +1 -1
- package/src/migrations/update-13-10-0/update-tasks-runner.js +4 -3
- package/src/migrations/update-13-10-0/update-tasks-runner.js.map +1 -1
- package/src/migrations/update-13-2-0/set-parallel-default.js +2 -2
- package/src/migrations/update-13-2-0/set-parallel-default.js.map +1 -1
- package/src/migrations/update-13-6-0/remove-old-task-runner-options.js +3 -3
- package/src/migrations/update-13-6-0/remove-old-task-runner-options.js.map +1 -1
- package/src/migrations/update-14-0-0/change-npm-script-executor.js +1 -1
- package/src/migrations/update-14-0-0/change-npm-script-executor.js.map +1 -1
- package/src/migrations/update-14-0-0/change-nx-json-presets.js +3 -3
- package/src/migrations/update-14-0-0/change-nx-json-presets.js.map +1 -1
- package/src/migrations/update-14-2-0/enable-source-analysis.js +14 -13
- package/src/migrations/update-14-2-0/enable-source-analysis.js.map +1 -1
- package/src/migrations/update-14-8-0/change-run-commands-executor.js +1 -1
- package/src/migrations/update-14-8-0/change-run-commands-executor.js.map +1 -1
- package/src/migrations/update-15-7-0/split-configuration-into-project-json-files.d.ts +3 -0
- package/src/migrations/update-15-7-0/split-configuration-into-project-json-files.js +15 -0
- package/src/migrations/update-15-7-0/split-configuration-into-project-json-files.js.map +1 -0
- package/src/utilities/assets.d.ts +2 -2
- package/src/utilities/buildable-libs-utils.d.ts +18 -7
- package/src/utilities/buildable-libs-utils.js +28 -13
- package/src/utilities/buildable-libs-utils.js.map +1 -1
- package/src/utilities/plugins/plugin-capabilities.d.ts +1 -3
- package/src/utilities/plugins/plugin-capabilities.js +2 -75
- package/src/utilities/plugins/plugin-capabilities.js.map +1 -1
- package/src/utilities/run-tasks-in-serial.d.ts +6 -0
- package/src/utilities/run-tasks-in-serial.js +6 -0
- package/src/utilities/run-tasks-in-serial.js.map +1 -1
- package/src/utilities/set-default-collection.js +5 -5
- package/src/utilities/set-default-collection.js.map +1 -1
- package/src/utilities/ts-config.d.ts +5 -0
- package/src/utilities/ts-config.js +40 -0
- package/src/utilities/ts-config.js.map +1 -0
- package/src/utilities/typescript/compilation.d.ts +1 -1
- package/src/utilities/typescript/compilation.js +22 -12
- package/src/utilities/typescript/compilation.js.map +1 -1
- package/src/utilities/typescript/find-nodes.d.ts +5 -2
- package/src/utilities/typescript/find-nodes.js +7 -25
- package/src/utilities/typescript/find-nodes.js.map +1 -1
- package/src/utilities/typescript/get-source-nodes.d.ts +4 -1
- package/src/utilities/typescript/get-source-nodes.js +3 -0
- package/src/utilities/typescript/get-source-nodes.js.map +1 -1
- package/src/utilities/typescript.d.ts +8 -4
- package/src/utilities/typescript.js +21 -38
- package/src/utilities/typescript.js.map +1 -1
- package/src/utilities/version-utils.d.ts +3 -0
- package/src/utilities/version-utils.js +7 -12
- package/src/utilities/version-utils.js.map +1 -1
- package/src/utils/ast-utils.d.ts +0 -123
- package/src/utils/ast-utils.js +5 -546
- package/src/utils/ast-utils.js.map +1 -1
- package/src/utils/cli-config-utils.d.ts +4 -3
- package/src/utils/cli-config-utils.js +4 -45
- package/src/utils/cli-config-utils.js.map +1 -1
- package/src/utils/lint.d.ts +0 -32
- package/src/utils/lint.js +0 -262
- package/src/utils/lint.js.map +1 -1
- package/src/utils/project-type.d.ts +1 -3
- package/src/utils/project-type.js +1 -8
- package/src/utils/project-type.js.map +1 -1
- package/src/utils/rules/add-install-task.d.ts +1 -1
- package/src/utils/rules/add-install-task.js +2 -2
- package/src/utils/rules/add-install-task.js.map +1 -1
- package/src/utils/rules/deleteFile.d.ts +1 -1
- package/src/utils/rules/format-files.js +0 -19
- package/src/utils/rules/format-files.js.map +1 -1
- package/src/utils/rules/workspace.d.ts +1 -1
- package/src/utils/strings.d.ts +12 -0
- package/src/utils/strings.js +12 -0
- package/src/utils/strings.js.map +1 -1
- package/src/utils/testing-utils.d.ts +1 -1
- package/src/utils/testing-utils.js +6 -6
- package/src/utils/testing-utils.js.map +1 -1
- package/src/utils/testing.d.ts +1 -1
- package/src/utils/versions.d.ts +3 -4
- package/src/utils/versions.js +6 -5
- package/src/utils/versions.js.map +1 -1
- package/src/utils/workspace.d.ts +1 -1
- package/src/generators/convert-to-nx-project/utils/get-project-configuration-path.d.ts +0 -2
- package/src/generators/convert-to-nx-project/utils/get-project-configuration-path.js +0 -9
- package/src/generators/convert-to-nx-project/utils/get-project-configuration-path.js.map +0 -1
- package/src/generators/move/lib/move-project-configuration.d.ts +0 -3
- package/src/generators/move/lib/move-project-configuration.js.map +0 -1
- package/src/generators/move/lib/move-project.js.map +0 -1
- package/src/generators/preset/files/pnpm-workspace/pnpm-workspace.yaml +0 -2
- package/src/generators/remove/lib/remove-project-config.d.ts +0 -8
- package/src/generators/remove/lib/remove-project-config.js +0 -32
- package/src/generators/remove/lib/remove-project-config.js.map +0 -1
- package/src/generators/utils/decorate-angular-cli.js__tmpl__ +0 -69
- package/src/generators/workspace/files/README.md__tmpl__ +0 -186
- package/src/generators/workspace/files/__dot__prettierignore +0 -4
- package/src/generators/workspace/files/package.json__tmpl__ +0 -18
- package/src/generators/workspace/schema.d.ts +0 -15
- package/src/generators/workspace/schema.json +0 -77
- package/src/generators/workspace/workspace.d.ts +0 -7
- package/src/generators/workspace/workspace.js.map +0 -1
- package/src/tslint/nxEnforceModuleBoundariesRule.d.ts +0 -14
- package/src/tslint/nxEnforceModuleBoundariesRule.js +0 -177
- package/src/tslint/nxEnforceModuleBoundariesRule.js.map +0 -1
- package/src/utilities/ast-utils.d.ts +0 -22
- package/src/utilities/ast-utils.js +0 -182
- package/src/utilities/ast-utils.js.map +0 -1
- package/src/utilities/create-package-json.d.ts +0 -10
- package/src/utilities/create-package-json.js +0 -87
- package/src/utilities/create-package-json.js.map +0 -1
- package/src/utilities/executor-options-utils.d.ts +0 -13
- package/src/utilities/executor-options-utils.js +0 -36
- package/src/utilities/executor-options-utils.js.map +0 -1
- package/src/utilities/generate-globs.d.ts +0 -6
- package/src/utilities/generate-globs.js +0 -75
- package/src/utilities/generate-globs.js.map +0 -1
- package/src/utilities/prettier.d.ts +0 -6
- package/src/utilities/prettier.js +0 -38
- package/src/utilities/prettier.js.map +0 -1
- package/src/utils/app-root.d.ts +0 -1
- package/src/utils/app-root.js +0 -8
- package/src/utils/app-root.js.map +0 -1
- package/src/utils/graph-utils.d.ts +0 -5
- package/src/utils/graph-utils.js +0 -116
- package/src/utils/graph-utils.js.map +0 -1
- package/src/utils/rules/check-project-exists.d.ts +0 -10
- package/src/utils/rules/check-project-exists.js +0 -24
- package/src/utils/rules/check-project-exists.js.map +0 -1
- package/src/utils/rules/move-npm-packages.d.ts +0 -11
- package/src/utils/rules/move-npm-packages.js +0 -76
- package/src/utils/rules/move-npm-packages.js.map +0 -1
- package/src/utils/rules/rename-npm-packages.d.ts +0 -10
- package/src/utils/rules/rename-npm-packages.js +0 -81
- package/src/utils/rules/rename-npm-packages.js.map +0 -1
- package/src/utils/rules/rename-package-imports.d.ts +0 -10
- package/src/utils/rules/rename-package-imports.js +0 -58
- package/src/utils/rules/rename-package-imports.js.map +0 -1
- package/src/utils/rules/to-js.d.ts +0 -8
- package/src/utils/rules/to-js.js +0 -77
- package/src/utils/rules/to-js.js.map +0 -1
- package/src/utils/rules/update-karma-conf.d.ts +0 -8
- package/src/utils/rules/update-karma-conf.js +0 -36
- package/src/utils/rules/update-karma-conf.js.map +0 -1
- package/src/utils/runtime-lint-utils.d.ts +0 -80
- package/src/utils/runtime-lint-utils.js +0 -307
- package/src/utils/runtime-lint-utils.js.map +0 -1
- package/src/utils/update-packages-in-package-json.d.ts +0 -3
- package/src/utils/update-packages-in-package-json.js +0 -56
- package/src/utils/update-packages-in-package-json.js.map +0 -1
- package/src/utils/update-task.d.ts +0 -2
- package/src/utils/update-task.js +0 -83
- package/src/utils/update-task.js.map +0 -1
- /package/src/generators/{workspace/files → library/files/root}/tsconfig.base.json +0 -0
- /package/src/generators/{workspace/files → new/files-integrated-repo}/__dot__editorconfig +0 -0
- /package/src/generators/{workspace/files → new/files-integrated-repo}/tools/generators/.gitkeep +0 -0
- /package/src/generators/{workspace/files → new/files-integrated-repo}/tools/tsconfig.tools.json +0 -0
@@ -1,177 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Rule = void 0;
|
4
|
-
const Lint = require("tslint");
|
5
|
-
const devkit_1 = require("@nrwl/devkit");
|
6
|
-
const runtime_lint_utils_1 = require("../utils/runtime-lint-utils");
|
7
|
-
const path_1 = require("path");
|
8
|
-
const target_project_locator_1 = require("nx/src/utils/target-project-locator");
|
9
|
-
const graph_utils_1 = require("../utils/graph-utils");
|
10
|
-
const fileutils_1 = require("../utilities/fileutils");
|
11
|
-
class Rule extends Lint.Rules.AbstractRule {
|
12
|
-
constructor(options, projectPath, projectGraph, targetProjectLocator, workspaceLayout) {
|
13
|
-
super(options);
|
14
|
-
this.projectPath = projectPath;
|
15
|
-
this.projectGraph = projectGraph;
|
16
|
-
this.targetProjectLocator = targetProjectLocator;
|
17
|
-
this.workspaceLayout = workspaceLayout;
|
18
|
-
if (!projectPath) {
|
19
|
-
this.projectPath = (0, path_1.normalize)(devkit_1.workspaceRoot);
|
20
|
-
if (!global.projectGraph) {
|
21
|
-
const nxJson = (0, devkit_1.readNxJson)();
|
22
|
-
global.workspaceLayout = nxJson.workspaceLayout;
|
23
|
-
/**
|
24
|
-
* Because there are a number of ways in which the rule can be invoked (executor vs TSLint CLI vs IDE Plugin),
|
25
|
-
* the ProjectGraph may or may not exist by the time the lint rule is invoked for the first time.
|
26
|
-
*/
|
27
|
-
try {
|
28
|
-
global.projectGraph = (0, runtime_lint_utils_1.mapProjectGraphFiles)((0, devkit_1.readCachedProjectGraph)());
|
29
|
-
}
|
30
|
-
catch (_a) { }
|
31
|
-
}
|
32
|
-
this.workspaceLayout = global.workspaceLayout;
|
33
|
-
this.projectGraph = global.projectGraph;
|
34
|
-
if (!global.targetProjectLocator && this.projectGraph) {
|
35
|
-
global.targetProjectLocator = new target_project_locator_1.TargetProjectLocator(this.projectGraph.nodes, this.projectGraph.externalNodes);
|
36
|
-
}
|
37
|
-
this.targetProjectLocator = global.targetProjectLocator;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
apply(sourceFile) {
|
41
|
-
if (!this.projectGraph)
|
42
|
-
return [];
|
43
|
-
return this.applyWithWalker(new EnforceModuleBoundariesWalker(sourceFile, this.getOptions(), this.projectPath, this.projectGraph, this.targetProjectLocator, this.workspaceLayout));
|
44
|
-
}
|
45
|
-
}
|
46
|
-
exports.Rule = Rule;
|
47
|
-
class EnforceModuleBoundariesWalker extends Lint.RuleWalker {
|
48
|
-
constructor(sourceFile, options, projectPath, projectGraph, targetProjectLocator, workspaceLayout) {
|
49
|
-
super(sourceFile, options);
|
50
|
-
this.projectPath = projectPath;
|
51
|
-
this.projectGraph = projectGraph;
|
52
|
-
this.targetProjectLocator = targetProjectLocator;
|
53
|
-
this.workspaceLayout = workspaceLayout;
|
54
|
-
this.enforceBuildableLibDependency = false; // for backwards compat
|
55
|
-
this.allowCircularSelfDependency = false;
|
56
|
-
this.allow = Array.isArray(this.getOptions()[0].allow)
|
57
|
-
? this.getOptions()[0].allow.map((a) => `${a}`)
|
58
|
-
: [];
|
59
|
-
this.depConstraints = Array.isArray(this.getOptions()[0].depConstraints)
|
60
|
-
? this.getOptions()[0].depConstraints
|
61
|
-
: [];
|
62
|
-
this.enforceBuildableLibDependency =
|
63
|
-
this.getOptions()[0].enforceBuildableLibDependency === true;
|
64
|
-
this.allowCircularSelfDependency =
|
65
|
-
this.getOptions()[0].allowCircularSelfDependency === true;
|
66
|
-
}
|
67
|
-
visitImportDeclaration(node) {
|
68
|
-
const imp = node.moduleSpecifier
|
69
|
-
.getText()
|
70
|
-
.substring(1, node.moduleSpecifier.getText().length - 1);
|
71
|
-
// whitelisted import
|
72
|
-
if (this.allow.some((a) => (0, runtime_lint_utils_1.matchImportWithWildcard)(a, imp))) {
|
73
|
-
super.visitImportDeclaration(node);
|
74
|
-
return;
|
75
|
-
}
|
76
|
-
const filePath = (0, runtime_lint_utils_1.getSourceFilePath)(this.getSourceFile().fileName, this.projectPath);
|
77
|
-
const sourceProject = (0, runtime_lint_utils_1.findSourceProject)(this.projectGraph, filePath);
|
78
|
-
if (!sourceProject) {
|
79
|
-
super.visitImportDeclaration(node);
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
let targetProject = (0, runtime_lint_utils_1.getTargetProjectBasedOnRelativeImport)(imp, this.projectPath, this.projectGraph, filePath);
|
83
|
-
// check for relative and absolute imports
|
84
|
-
if ((targetProject && sourceProject !== targetProject) ||
|
85
|
-
(0, runtime_lint_utils_1.isAbsoluteImportIntoAnotherProject)(imp, this.workspaceLayout)) {
|
86
|
-
this.addFailureAt(node.getStart(), node.getWidth(), `libraries cannot be imported by a relative or absolute path, and must begin with a npm scope`);
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
targetProject =
|
90
|
-
targetProject ||
|
91
|
-
(0, runtime_lint_utils_1.findProjectUsingImport)(this.projectGraph, this.targetProjectLocator, filePath, imp);
|
92
|
-
// If source or target are not part of an nx workspace, return.
|
93
|
-
if (!targetProject || targetProject.type === 'npm') {
|
94
|
-
super.visitImportDeclaration(node);
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
// same project => allow
|
98
|
-
if (sourceProject === targetProject) {
|
99
|
-
if (!this.allowCircularSelfDependency &&
|
100
|
-
!(0, fileutils_1.isRelativePath)(imp) &&
|
101
|
-
!(0, runtime_lint_utils_1.isAngularSecondaryEntrypoint)(this.targetProjectLocator, imp)) {
|
102
|
-
const error = `Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "${imp}"`;
|
103
|
-
this.addFailureAt(node.getStart(), node.getWidth(), error);
|
104
|
-
}
|
105
|
-
else {
|
106
|
-
super.visitImportDeclaration(node);
|
107
|
-
}
|
108
|
-
return;
|
109
|
-
}
|
110
|
-
// check for circular dependency
|
111
|
-
const circularPath = (0, graph_utils_1.checkCircularPath)(this.projectGraph, sourceProject, targetProject);
|
112
|
-
if (circularPath.length !== 0) {
|
113
|
-
const path = circularPath.reduce((acc, v) => `${acc} -> ${v.name}`, sourceProject.name);
|
114
|
-
const circularFilePath = (0, graph_utils_1.findFilesInCircularPath)(circularPath);
|
115
|
-
const filePaths = circularFilePath
|
116
|
-
.map((files) => (files.length > 1 ? `[${files.join(',')}]` : files[0]))
|
117
|
-
.reduce((acc, files) => `${acc}\n- ${files}`, `- ${filePath}`);
|
118
|
-
const error = `Circular dependency between "${sourceProject.name}" and "${targetProject.name}" detected: ${path}\n\nCircular file chain:\n${filePaths}`;
|
119
|
-
this.addFailureAt(node.getStart(), node.getWidth(), error);
|
120
|
-
return;
|
121
|
-
}
|
122
|
-
// cannot import apps
|
123
|
-
if (targetProject.type === 'app') {
|
124
|
-
this.addFailureAt(node.getStart(), node.getWidth(), 'imports of apps are forbidden');
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
// cannot import e2e projects
|
128
|
-
if (targetProject.type === 'e2e') {
|
129
|
-
this.addFailureAt(node.getStart(), node.getWidth(), 'imports of e2e projects are forbidden');
|
130
|
-
return;
|
131
|
-
}
|
132
|
-
// buildable-lib is not allowed to import non-buildable-lib
|
133
|
-
if (this.enforceBuildableLibDependency === true &&
|
134
|
-
sourceProject.type === 'lib' &&
|
135
|
-
targetProject.type === 'lib') {
|
136
|
-
if ((0, runtime_lint_utils_1.hasBuildExecutor)(sourceProject) && !(0, runtime_lint_utils_1.hasBuildExecutor)(targetProject)) {
|
137
|
-
this.addFailureAt(node.getStart(), node.getWidth(), 'buildable libraries cannot import non-buildable libraries');
|
138
|
-
return;
|
139
|
-
}
|
140
|
-
}
|
141
|
-
// if we import a library using loadChildren, we should not import it using es6imports
|
142
|
-
if ((0, runtime_lint_utils_1.onlyLoadChildren)(this.projectGraph, sourceProject.name, targetProject.name, [])) {
|
143
|
-
this.addFailureAt(node.getStart(), node.getWidth(), 'imports of lazy-loaded libraries are forbidden');
|
144
|
-
return;
|
145
|
-
}
|
146
|
-
// check that dependency constraints are satisfied
|
147
|
-
if (this.depConstraints.length > 0) {
|
148
|
-
const constraints = (0, runtime_lint_utils_1.findConstraintsFor)(this.depConstraints, sourceProject);
|
149
|
-
// when no constrains found => error. Force the user to provision them.
|
150
|
-
if (constraints.length === 0) {
|
151
|
-
this.addFailureAt(node.getStart(), node.getWidth(), `A project without tags matching at least one constraint cannot depend on any libraries`);
|
152
|
-
return;
|
153
|
-
}
|
154
|
-
for (let constraint of constraints) {
|
155
|
-
if (constraint.onlyDependOnLibsWithTags &&
|
156
|
-
(0, runtime_lint_utils_1.hasNoneOfTheseTags)(targetProject, constraint.onlyDependOnLibsWithTags)) {
|
157
|
-
const error = `A project tagged with "${constraint.sourceTag}" can only depend on libs tagged with ${(0, runtime_lint_utils_1.stringifyTags)(constraint.onlyDependOnLibsWithTags)}`;
|
158
|
-
this.addFailureAt(node.getStart(), node.getWidth(), error);
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
if (constraint.notDependOnLibsWithTags &&
|
162
|
-
constraint.notDependOnLibsWithTags.length) {
|
163
|
-
const projectPaths = (0, runtime_lint_utils_1.findDependenciesWithTags)(targetProject, constraint.notDependOnLibsWithTags, this.projectGraph);
|
164
|
-
if (projectPaths.length > 0) {
|
165
|
-
const error = `A project tagged with "${constraint.sourceTag}" can not depend on libs tagged with ${(0, runtime_lint_utils_1.stringifyTags)(constraint.notDependOnLibsWithTags)}\n\nViolation detected in:\n${projectPaths
|
166
|
-
.map((projectPath) => `- ${projectPath.map((p) => p.name).join(' -> ')}`)
|
167
|
-
.join('\n')}`;
|
168
|
-
this.addFailureAt(node.getStart(), node.getWidth(), error);
|
169
|
-
return;
|
170
|
-
}
|
171
|
-
}
|
172
|
-
}
|
173
|
-
}
|
174
|
-
super.visitImportDeclaration(node);
|
175
|
-
}
|
176
|
-
}
|
177
|
-
//# sourceMappingURL=nxEnforceModuleBoundariesRule.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"nxEnforceModuleBoundariesRule.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAQ/B,yCAIsB;AACtB,oEAiBqC;AACrC,+BAAiC;AACjC,gFAA2E;AAC3E,sDAG8B;AAC9B,sDAAwD;AAExD,MAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC,YAAY;IAC/C,YACE,OAAiB,EACA,WAAoB,EACpB,YAAiC,EACjC,oBAA2C,EAC3C,eAAwD;QAEzE,KAAK,CAAC,OAAO,CAAC,CAAC;QALE,gBAAW,GAAX,WAAW,CAAS;QACpB,iBAAY,GAAZ,YAAY,CAAqB;QACjC,yBAAoB,GAApB,oBAAoB,CAAuB;QAC3C,oBAAe,GAAf,eAAe,CAAyC;QAIzE,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,CAAC,WAAW,GAAG,IAAA,gBAAS,EAAC,sBAAa,CAAC,CAAC;YAC5C,IAAI,CAAE,MAAc,CAAC,YAAY,EAAE;gBACjC,MAAM,MAAM,GAAG,IAAA,mBAAU,GAAE,CAAC;gBAC3B,MAAc,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;gBAEzD;;;mBAGG;gBACH,IAAI;oBACD,MAAc,CAAC,YAAY,GAAG,IAAA,yCAAoB,EACjD,IAAA,+BAAsB,GAAE,CACzB,CAAC;iBACH;gBAAC,WAAM,GAAE;aACX;YACD,IAAI,CAAC,eAAe,GAAI,MAAc,CAAC,eAAe,CAAC;YACvD,IAAI,CAAC,YAAY,GAAI,MAAc,CAAC,YAAkC,CAAC;YAEv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AAwB,CACpC,EAAE,CAAC;oBACJ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;oBAC3D,OAAO;iBACR;gBACD,IACE,UAAU,CAAC,uBAAuB;oBAClC,UAAU,CAAC,uBAAuB,CAAC,MAAM,EACzC;oBACA,MAAM,YAAY,GAAG,IAAA,6CAAwB,EAC3C,aAAa,EACb,UAAU,CAAC,uBAAuB,EAClC,IAAI,CAAC,YAAY,CAClB,CAAC;oBACF,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;wBAC3B,MAAM,KAAK,GAAG,0BACZ,UAAU,CAAC,SACb,wCAAwC,IAAA,kCAAa,EACnD,UAAU,CAAC,uBAAuB,CACnC,+BAA+B,YAAY;6BACzC,GAAG,CACF,CAAC,WAAW,EAAE,EAAE,CACd,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACrD;6BACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBAChB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;wBAC3D,OAAO;qBACR;iBACF;aACF;SACF;QAED,KAAK,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF"}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import type { Tree } from '@nrwl/devkit';
|
2
|
-
import * as ts from 'typescript';
|
3
|
-
export declare function insertChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, insertPosition: number, contentToInsert: string): ts.SourceFile;
|
4
|
-
export declare function replaceChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, insertPosition: number, contentToInsert: string, oldContent: string): ts.SourceFile;
|
5
|
-
export declare function removeChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, removePosition: number, contentToRemove: string): ts.SourceFile;
|
6
|
-
export declare function insertImport(host: Tree, source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): ts.SourceFile;
|
7
|
-
export declare function addGlobal(host: Tree, source: ts.SourceFile, modulePath: string, statement: string): ts.SourceFile;
|
8
|
-
export declare function getImport(source: ts.SourceFile, predicate: (a: any) => boolean): {
|
9
|
-
moduleSpec: string;
|
10
|
-
bindings: string[];
|
11
|
-
}[];
|
12
|
-
export declare function replaceNodeValue(host: Tree, sourceFile: ts.SourceFile, modulePath: string, node: ts.Node, content: string): ts.SourceFile;
|
13
|
-
export declare function addParameterToConstructor(tree: Tree, source: ts.SourceFile, modulePath: string, opts: {
|
14
|
-
className: string;
|
15
|
-
param: string;
|
16
|
-
}): ts.SourceFile;
|
17
|
-
export declare function addMethod(tree: Tree, source: ts.SourceFile, modulePath: string, opts: {
|
18
|
-
className: string;
|
19
|
-
methodHeader: string;
|
20
|
-
body?: string;
|
21
|
-
}): ts.SourceFile;
|
22
|
-
export declare function findClass(source: ts.SourceFile, className: string, silent?: boolean): ts.ClassDeclaration;
|
@@ -1,182 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.findClass = exports.addMethod = exports.addParameterToConstructor = exports.replaceNodeValue = exports.getImport = exports.addGlobal = exports.insertImport = exports.removeChange = exports.replaceChange = exports.insertChange = void 0;
|
4
|
-
const ts = require("typescript");
|
5
|
-
const typescript_1 = require("./typescript");
|
6
|
-
const find_nodes_1 = require("./typescript/find-nodes");
|
7
|
-
function nodesByPosition(first, second) {
|
8
|
-
return first.getStart() - second.getStart();
|
9
|
-
}
|
10
|
-
function updateTsSourceFile(host, sourceFile, filePath) {
|
11
|
-
const newFileContents = host.read(filePath).toString('utf-8');
|
12
|
-
return sourceFile.update(newFileContents, {
|
13
|
-
newLength: newFileContents.length,
|
14
|
-
span: {
|
15
|
-
length: sourceFile.text.length,
|
16
|
-
start: 0,
|
17
|
-
},
|
18
|
-
});
|
19
|
-
}
|
20
|
-
function insertChange(host, sourceFile, filePath, insertPosition, contentToInsert) {
|
21
|
-
const content = host.read(filePath).toString();
|
22
|
-
const prefix = content.substring(0, insertPosition);
|
23
|
-
const suffix = content.substring(insertPosition);
|
24
|
-
host.write(filePath, `${prefix}${contentToInsert}${suffix}`);
|
25
|
-
return updateTsSourceFile(host, sourceFile, filePath);
|
26
|
-
}
|
27
|
-
exports.insertChange = insertChange;
|
28
|
-
function replaceChange(host, sourceFile, filePath, insertPosition, contentToInsert, oldContent) {
|
29
|
-
const content = host.read(filePath, 'utf-8');
|
30
|
-
const prefix = content.substring(0, insertPosition);
|
31
|
-
const suffix = content.substring(insertPosition + oldContent.length);
|
32
|
-
const text = content.substring(insertPosition, insertPosition + oldContent.length);
|
33
|
-
if (text !== oldContent) {
|
34
|
-
throw new Error(`Invalid replace: "${text}" != "${oldContent}".`);
|
35
|
-
}
|
36
|
-
host.write(filePath, `${prefix}${contentToInsert}${suffix}`);
|
37
|
-
return updateTsSourceFile(host, sourceFile, filePath);
|
38
|
-
}
|
39
|
-
exports.replaceChange = replaceChange;
|
40
|
-
function removeChange(host, sourceFile, filePath, removePosition, contentToRemove) {
|
41
|
-
const content = host.read(filePath).toString();
|
42
|
-
const prefix = content.substring(0, removePosition);
|
43
|
-
const suffix = content.substring(removePosition + contentToRemove.length);
|
44
|
-
host.write(filePath, `${prefix}${suffix}`);
|
45
|
-
return updateTsSourceFile(host, sourceFile, filePath);
|
46
|
-
}
|
47
|
-
exports.removeChange = removeChange;
|
48
|
-
function insertImport(host, source, fileToEdit, symbolName, fileName, isDefault = false) {
|
49
|
-
const rootNode = source;
|
50
|
-
const allImports = (0, find_nodes_1.findNodes)(rootNode, ts.SyntaxKind.ImportDeclaration);
|
51
|
-
// get nodes that map to import statements from the file fileName
|
52
|
-
const relevantImports = allImports.filter((node) => {
|
53
|
-
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
54
|
-
const importFiles = node
|
55
|
-
.getChildren()
|
56
|
-
.filter((child) => child.kind === ts.SyntaxKind.StringLiteral)
|
57
|
-
.map((n) => n.text);
|
58
|
-
return importFiles.filter((file) => file === fileName).length === 1;
|
59
|
-
});
|
60
|
-
if (relevantImports.length > 0) {
|
61
|
-
let importsAsterisk = false;
|
62
|
-
// imports from import file
|
63
|
-
const imports = [];
|
64
|
-
relevantImports.forEach((n) => {
|
65
|
-
Array.prototype.push.apply(imports, (0, find_nodes_1.findNodes)(n, ts.SyntaxKind.Identifier));
|
66
|
-
if ((0, find_nodes_1.findNodes)(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
67
|
-
importsAsterisk = true;
|
68
|
-
}
|
69
|
-
});
|
70
|
-
// if imports * from fileName, don't add symbolName
|
71
|
-
if (importsAsterisk) {
|
72
|
-
return source;
|
73
|
-
}
|
74
|
-
const importTextNodes = imports.filter((n) => n.text === symbolName);
|
75
|
-
// insert import if it's not there
|
76
|
-
if (importTextNodes.length === 0) {
|
77
|
-
const fallbackPos = (0, find_nodes_1.findNodes)(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
78
|
-
(0, find_nodes_1.findNodes)(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
79
|
-
return insertAfterLastOccurrence(host, source, imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
80
|
-
}
|
81
|
-
return source;
|
82
|
-
}
|
83
|
-
// no such import declaration exists
|
84
|
-
const useStrict = (0, find_nodes_1.findNodes)(rootNode, ts.SyntaxKind.StringLiteral).filter((n) => n.text === 'use strict');
|
85
|
-
let fallbackPos = 0;
|
86
|
-
if (useStrict.length > 0) {
|
87
|
-
fallbackPos = useStrict[0].end;
|
88
|
-
}
|
89
|
-
const open = isDefault ? '' : '{ ';
|
90
|
-
const close = isDefault ? '' : ' }';
|
91
|
-
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
92
|
-
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
93
|
-
const separator = insertAtBeginning ? '' : ';\n';
|
94
|
-
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
95
|
-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
96
|
-
return insertAfterLastOccurrence(host, source, allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
97
|
-
}
|
98
|
-
exports.insertImport = insertImport;
|
99
|
-
function insertAfterLastOccurrence(host, sourceFile, nodes, toInsert, pathToFile, fallbackPos, syntaxKind) {
|
100
|
-
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
|
101
|
-
let lastItem = [...nodes].sort(nodesByPosition).pop();
|
102
|
-
if (!lastItem) {
|
103
|
-
throw new Error();
|
104
|
-
}
|
105
|
-
if (syntaxKind) {
|
106
|
-
lastItem = (0, find_nodes_1.findNodes)(lastItem, syntaxKind).sort(nodesByPosition).pop();
|
107
|
-
}
|
108
|
-
if (!lastItem && fallbackPos == undefined) {
|
109
|
-
throw new Error(`tried to insert ${toInsert} as first occurrence with no fallback position`);
|
110
|
-
}
|
111
|
-
const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
|
112
|
-
return insertChange(host, sourceFile, pathToFile, lastItemPosition, toInsert);
|
113
|
-
}
|
114
|
-
function addGlobal(host, source, modulePath, statement) {
|
115
|
-
const allImports = (0, find_nodes_1.findNodes)(source, ts.SyntaxKind.ImportDeclaration);
|
116
|
-
if (allImports.length > 0) {
|
117
|
-
const lastImport = allImports[allImports.length - 1];
|
118
|
-
return insertChange(host, source, modulePath, lastImport.end + 1, `\n${statement}\n`);
|
119
|
-
}
|
120
|
-
else {
|
121
|
-
return insertChange(host, source, modulePath, 0, `${statement}\n`);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
exports.addGlobal = addGlobal;
|
125
|
-
function getImport(source, predicate) {
|
126
|
-
const allImports = (0, find_nodes_1.findNodes)(source, ts.SyntaxKind.ImportDeclaration);
|
127
|
-
const matching = allImports.filter((i) => predicate(i.moduleSpecifier.getText()));
|
128
|
-
return matching.map((i) => {
|
129
|
-
const moduleSpec = i.moduleSpecifier
|
130
|
-
.getText()
|
131
|
-
.substring(1, i.moduleSpecifier.getText().length - 1);
|
132
|
-
const t = i.importClause.namedBindings.getText();
|
133
|
-
const bindings = t
|
134
|
-
.replace('{', '')
|
135
|
-
.replace('}', '')
|
136
|
-
.split(',')
|
137
|
-
.map((q) => q.trim());
|
138
|
-
return { moduleSpec, bindings };
|
139
|
-
});
|
140
|
-
}
|
141
|
-
exports.getImport = getImport;
|
142
|
-
function replaceNodeValue(host, sourceFile, modulePath, node, content) {
|
143
|
-
return replaceChange(host, sourceFile, modulePath, node.getStart(node.getSourceFile()), content, node.getText());
|
144
|
-
}
|
145
|
-
exports.replaceNodeValue = replaceNodeValue;
|
146
|
-
function addParameterToConstructor(tree, source, modulePath, opts) {
|
147
|
-
const clazz = findClass(source, opts.className);
|
148
|
-
const constructor = clazz.members.filter((m) => m.kind === ts.SyntaxKind.Constructor)[0];
|
149
|
-
if (constructor) {
|
150
|
-
throw new Error('Should be tested'); // TODO: check this
|
151
|
-
}
|
152
|
-
return addMethod(tree, source, modulePath, {
|
153
|
-
className: opts.className,
|
154
|
-
methodHeader: `constructor(${opts.param})`,
|
155
|
-
});
|
156
|
-
}
|
157
|
-
exports.addParameterToConstructor = addParameterToConstructor;
|
158
|
-
function addMethod(tree, source, modulePath, opts) {
|
159
|
-
const clazz = findClass(source, opts.className);
|
160
|
-
const body = opts.body
|
161
|
-
? `
|
162
|
-
${opts.methodHeader} {
|
163
|
-
${opts.body}
|
164
|
-
}
|
165
|
-
`
|
166
|
-
: `
|
167
|
-
${opts.methodHeader} {}
|
168
|
-
`;
|
169
|
-
return insertChange(tree, source, modulePath, clazz.end - 1, body);
|
170
|
-
}
|
171
|
-
exports.addMethod = addMethod;
|
172
|
-
function findClass(source, className, silent = false) {
|
173
|
-
const nodes = (0, typescript_1.getSourceNodes)(source);
|
174
|
-
const clazz = nodes.filter((n) => n.kind === ts.SyntaxKind.ClassDeclaration &&
|
175
|
-
n.name.text === className)[0];
|
176
|
-
if (!clazz && !silent) {
|
177
|
-
throw new Error(`Cannot find class '${className}'.`);
|
178
|
-
}
|
179
|
-
return clazz;
|
180
|
-
}
|
181
|
-
exports.findClass = findClass;
|
182
|
-
//# sourceMappingURL=ast-utils.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utilities/ast-utils.ts"],"names":[],"mappings":";;;AACA,iCAAiC;AACjC,6CAA8C;AAC9C,wDAAoD;AAEpD,SAAS,eAAe,CAAC,KAAc,EAAE,MAAe;IACtD,OAAO,KAAK,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,IAAU,EACV,UAAyB,EACzB,QAAgB;IAEhB,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9D,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE;QACxC,SAAS,EAAE,eAAe,CAAC,MAAM;QACjC,IAAI,EAAE;YACJ,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM;YAC9B,KAAK,EAAE,CAAC;SACT;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,YAAY,CAC1B,IAAU,EACV,UAAyB,EACzB,QAAgB,EAChB,cAAsB,EACtB,eAAuB;IAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,CAA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rwl/devkit';
|
2
|
-
/**
|
3
|
-
* Creates a package.json in the output directory for support to install dependencies within containers.
|
4
|
-
*
|
5
|
-
* If a package.json exists in the project, it will reuse that.
|
6
|
-
*/
|
7
|
-
export declare function createPackageJson(projectName: string, graph: ProjectGraph, options: {
|
8
|
-
projectRoot?: string;
|
9
|
-
root?: string;
|
10
|
-
}): any;
|
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createPackageJson = void 0;
|
4
|
-
const devkit_1 = require("@nrwl/devkit");
|
5
|
-
const object_sort_1 = require("nx/src/utils/object-sort");
|
6
|
-
/**
|
7
|
-
* Creates a package.json in the output directory for support to install dependencies within containers.
|
8
|
-
*
|
9
|
-
* If a package.json exists in the project, it will reuse that.
|
10
|
-
*/
|
11
|
-
function createPackageJson(projectName, graph, options) {
|
12
|
-
const npmDeps = findAllNpmDeps(projectName, graph);
|
13
|
-
// default package.json if one does not exist
|
14
|
-
let packageJson = {
|
15
|
-
name: projectName,
|
16
|
-
version: '0.0.1',
|
17
|
-
dependencies: {},
|
18
|
-
devDependencies: {},
|
19
|
-
};
|
20
|
-
try {
|
21
|
-
packageJson = (0, devkit_1.readJsonFile)(`${options.projectRoot}/package.json`);
|
22
|
-
if (!packageJson.dependencies) {
|
23
|
-
packageJson.dependencies = {};
|
24
|
-
}
|
25
|
-
if (!packageJson.devDependencies) {
|
26
|
-
packageJson.devDependencies = {};
|
27
|
-
}
|
28
|
-
}
|
29
|
-
catch (e) { }
|
30
|
-
const rootPackageJson = (0, devkit_1.readJsonFile)(`${options.root}/package.json`);
|
31
|
-
Object.entries(npmDeps).forEach(([packageName, version]) => {
|
32
|
-
var _a;
|
33
|
-
if ((_a = rootPackageJson.devDependencies) === null || _a === void 0 ? void 0 : _a[packageName]) {
|
34
|
-
packageJson.devDependencies[packageName] = version;
|
35
|
-
}
|
36
|
-
else {
|
37
|
-
packageJson.dependencies[packageName] = version;
|
38
|
-
}
|
39
|
-
});
|
40
|
-
packageJson.devDependencies && (packageJson.devDependencies = (0, object_sort_1.sortObjectByKeys)(packageJson.devDependencies));
|
41
|
-
packageJson.dependencies && (packageJson.dependencies = (0, object_sort_1.sortObjectByKeys)(packageJson.dependencies));
|
42
|
-
return packageJson;
|
43
|
-
}
|
44
|
-
exports.createPackageJson = createPackageJson;
|
45
|
-
function findAllNpmDeps(projectName, graph, list = {}, seen = new Set()) {
|
46
|
-
var _a;
|
47
|
-
if (seen.has(projectName)) {
|
48
|
-
return list;
|
49
|
-
}
|
50
|
-
seen.add(projectName);
|
51
|
-
const node = graph.externalNodes[projectName];
|
52
|
-
if (node) {
|
53
|
-
list[node.data.packageName] = node.data.version;
|
54
|
-
recursivelyCollectPeerDependencies(node.name, graph, list);
|
55
|
-
}
|
56
|
-
(_a = graph.dependencies[projectName]) === null || _a === void 0 ? void 0 : _a.forEach((dep) => {
|
57
|
-
findAllNpmDeps(dep.target, graph, list, seen);
|
58
|
-
});
|
59
|
-
return list;
|
60
|
-
}
|
61
|
-
function recursivelyCollectPeerDependencies(projectName, graph, list = {}, seen = new Set()) {
|
62
|
-
const npmPackage = graph.externalNodes[projectName];
|
63
|
-
if (!npmPackage || seen.has(projectName)) {
|
64
|
-
return list;
|
65
|
-
}
|
66
|
-
seen.add(projectName);
|
67
|
-
const packageName = npmPackage.data.packageName;
|
68
|
-
try {
|
69
|
-
const packageJson = require(`${packageName}/package.json`);
|
70
|
-
if (!packageJson.peerDependencies) {
|
71
|
-
return list;
|
72
|
-
}
|
73
|
-
Object.keys(packageJson.peerDependencies)
|
74
|
-
.map((dependencyName) => `npm:${dependencyName}`)
|
75
|
-
.map((dependency) => graph.externalNodes[dependency])
|
76
|
-
.filter(Boolean)
|
77
|
-
.forEach((node) => {
|
78
|
-
list[node.data.packageName] = node.data.version;
|
79
|
-
recursivelyCollectPeerDependencies(node.name, graph, list, seen);
|
80
|
-
});
|
81
|
-
return list;
|
82
|
-
}
|
83
|
-
catch (e) {
|
84
|
-
return list;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
//# sourceMappingURL=create-package-json.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"create-package-json.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utilities/create-package-json.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,0DAA4D;AAE5D;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,WAAmB,EACnB,KAAmB,EACnB,OAGC;IAED,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACnD,6CAA6C;IAC7C,IAAI,WAAW,GAAG;QAChB,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,OAAO;QAChB,YAAY,EAAE,EAAE;QAChB,eAAe,EAAE,EAAE;KACpB,CAAC;IACF,IAAI;QACF,WAAW,GAAG,IAAA,qBAAY,EAAC,GAAG,OAAO,CAAC,WAAW,eAAe,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE;YAC7B,WAAW,CAAC,YAAY,GAAG,EAAE,CAAC;SAC/B;QACD,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE;YAChC,WAAW,CAAC,eAAe,GAAG,EAAE,CAAC;SAClC;KACF;IAAC,OAAO,CAAC,EAAE,GAAE;IAEd,MAAM,eAAe,GAAG,IAAA,qBAAY,EAAC,GAAG,OAAO,CAAC,IAAI,eAAe,CAAC,CAAC;IACrE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE;;QACzD,IAAI,MAAA,eAAe,CAAC,eAAe,0CAAG,WAAW,CAAC,EAAE;YAClD,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC;SACpD;aAAM;YACL,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC;SACjD;IACH,CAAC,CA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EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACtB,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC;IAChD,IAAI;QACF,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,WAAW,eAAe,CAAC,CAAC;QAC3D,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;YACjC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC;aACtC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,OAAO,cAAc,EAAE,CAAC;aAChD,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;aACpD,MAAM,CAAC,OAAO,CAAC;aACf,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAChD,kCAAkC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QACL,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC"}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Tree } from '@nrwl/devkit';
|
2
|
-
/**
|
3
|
-
* Calls a function for each different options that an executor is configured with
|
4
|
-
*/
|
5
|
-
export declare function forEachExecutorOptions<Options>(tree: Tree,
|
6
|
-
/**
|
7
|
-
* Name of the executor to update options for
|
8
|
-
*/
|
9
|
-
executorName: string,
|
10
|
-
/**
|
11
|
-
* Callback that is called for each options configured for a builder
|
12
|
-
*/
|
13
|
-
callback: (currentValue: Options, project: string, target: string, configuration?: string) => void): void;
|
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.forEachExecutorOptions = void 0;
|
4
|
-
const devkit_1 = require("@nrwl/devkit");
|
5
|
-
/**
|
6
|
-
* Calls a function for each different options that an executor is configured with
|
7
|
-
*/
|
8
|
-
function forEachExecutorOptions(tree,
|
9
|
-
/**
|
10
|
-
* Name of the executor to update options for
|
11
|
-
*/
|
12
|
-
executorName,
|
13
|
-
/**
|
14
|
-
* Callback that is called for each options configured for a builder
|
15
|
-
*/
|
16
|
-
callback) {
|
17
|
-
for (const [projectName, project] of (0, devkit_1.getProjects)(tree)) {
|
18
|
-
for (const [targetName, target] of Object.entries(project.targets || {})) {
|
19
|
-
if (executorName !== target.executor) {
|
20
|
-
continue;
|
21
|
-
}
|
22
|
-
if (target.options) {
|
23
|
-
callback(target.options, projectName, targetName);
|
24
|
-
}
|
25
|
-
if (!target.configurations) {
|
26
|
-
continue;
|
27
|
-
}
|
28
|
-
Object.entries(target.configurations).forEach(([configName, options]) => {
|
29
|
-
callback(options, projectName, targetName, configName);
|
30
|
-
});
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
exports.forEachExecutorOptions = forEachExecutorOptions;
|
35
|
-
// TODO: add a method for updating options
|
36
|
-
//# sourceMappingURL=executor-options-utils.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"executor-options-utils.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utilities/executor-options-utils.ts"],"names":[],"mappings":";;;AAAA,yCAAiD;AAEjD;;GAEG;AACH,SAAgB,sBAAsB,CACpC,IAAU;AACV;;GAEG;AACH,YAAoB;AACpB;;GAEG;AACH,QAKS;IAET,KAAK,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,EAAE;QACtD,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE;YACxE,IAAI,YAAY,KAAK,MAAM,CAAC,QAAQ,EAAE;gBACpC,SAAS;aACV;YAED,IAAI,MAAM,CAAC,OAAO,EAAE;gBAClB,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;aACnD;YAED,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;gBAC1B,SAAS;aACV;YACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE;gBACtE,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;SACJ;KACF;AACH,CAAC;AAlCD,wDAkCC;AAED,0CAA0C"}
|
@@ -1,6 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Generates a set of glob patterns based off the source root of the app and its dependencies
|
3
|
-
* @param dirPath workspace relative directory path that will be used to infer the parent project and dependencies
|
4
|
-
* @param fileGlobPattern pass a custom glob pattern to be used
|
5
|
-
*/
|
6
|
-
export declare function createGlobPatternsForDependencies(dirPath: string, fileGlobPattern: string): string[];
|