@nrwl/workspace 15.8.4 → 15.9.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/index.d.ts +3 -8
  2. package/index.js +2 -36
  3. package/index.js.map +1 -1
  4. package/package.json +30 -39
  5. package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ +1 -0
  6. package/src/generators/library/library.js +1 -2
  7. package/src/generators/library/library.js.map +1 -1
  8. package/src/generators/new/files-integrated-repo/package.json__tmpl__ +1 -2
  9. package/src/generators/new/files-package-based-repo/__dot__vscode/extensions.json__tmpl__ +1 -2
  10. package/src/generators/new/files-package-based-repo/package.json__tmpl__ +1 -2
  11. package/src/generators/new/files-root-app/__dot__vscode/extensions.json__tmpl__ +1 -2
  12. package/src/generators/new/files-root-app/package.json__tmpl__ +1 -2
  13. package/src/generators/new/generate-workspace-files.d.ts +0 -3
  14. package/src/generators/new/generate-workspace-files.js +2 -9
  15. package/src/generators/new/generate-workspace-files.js.map +1 -1
  16. package/src/generators/new/new.js +0 -1
  17. package/src/generators/new/new.js.map +1 -1
  18. package/src/generators/new/schema.json +1 -1
  19. package/src/generators/preset/preset.d.ts +1 -1
  20. package/src/generators/preset/preset.js +18 -15
  21. package/src/generators/preset/preset.js.map +1 -1
  22. package/src/generators/preset/schema.json +1 -1
  23. package/src/migrations/update-14-0-0/change-npm-script-executor.js +1 -1
  24. package/src/migrations/update-14-0-0/change-npm-script-executor.js.map +1 -1
  25. package/src/migrations/update-14-8-0/change-run-commands-executor.js +1 -1
  26. package/src/migrations/update-14-8-0/change-run-commands-executor.js.map +1 -1
  27. package/src/utilities/buildable-libs-utils.d.ts +17 -6
  28. package/src/utilities/buildable-libs-utils.js +17 -8
  29. package/src/utilities/buildable-libs-utils.js.map +1 -1
  30. package/src/utilities/run-tasks-in-serial.d.ts +6 -0
  31. package/src/utilities/run-tasks-in-serial.js +6 -0
  32. package/src/utilities/run-tasks-in-serial.js.map +1 -1
  33. package/src/utilities/typescript/get-source-nodes.d.ts +3 -0
  34. package/src/utilities/typescript/get-source-nodes.js +3 -0
  35. package/src/utilities/typescript/get-source-nodes.js.map +1 -1
  36. package/src/utilities/version-utils.d.ts +3 -0
  37. package/src/utilities/version-utils.js +7 -12
  38. package/src/utilities/version-utils.js.map +1 -1
  39. package/src/utils/ast-utils.d.ts +0 -118
  40. package/src/utils/ast-utils.js +3 -543
  41. package/src/utils/ast-utils.js.map +1 -1
  42. package/src/utils/cli-config-utils.d.ts +0 -2
  43. package/src/utils/cli-config-utils.js +1 -47
  44. package/src/utils/cli-config-utils.js.map +1 -1
  45. package/src/utils/lint.d.ts +0 -22
  46. package/src/utils/lint.js +0 -164
  47. package/src/utils/lint.js.map +1 -1
  48. package/src/utils/project-type.d.ts +1 -3
  49. package/src/utils/project-type.js +1 -8
  50. package/src/utils/project-type.js.map +1 -1
  51. package/src/utils/strings.d.ts +12 -0
  52. package/src/utils/strings.js +12 -0
  53. package/src/utils/strings.js.map +1 -1
  54. package/src/utils/versions.d.ts +0 -1
  55. package/src/utils/versions.js +1 -2
  56. package/src/utils/versions.js.map +1 -1
  57. package/src/generators/new/files-integrated-repo/__dot__prettierignore +0 -4
  58. package/src/generators/new/files-package-based-repo/__dot__prettierignore +0 -4
  59. package/src/generators/new/files-root-app/__dot__prettierignore +0 -4
  60. package/src/utilities/ast-utils.d.ts +0 -22
  61. package/src/utilities/ast-utils.js +0 -197
  62. package/src/utilities/ast-utils.js.map +0 -1
  63. package/src/utilities/executor-options-utils.d.ts +0 -20
  64. package/src/utilities/executor-options-utils.js +0 -49
  65. package/src/utilities/executor-options-utils.js.map +0 -1
  66. package/src/utilities/generate-globs.d.ts +0 -6
  67. package/src/utilities/generate-globs.js +0 -81
  68. package/src/utilities/generate-globs.js.map +0 -1
  69. package/src/utilities/prettier.d.ts +0 -6
  70. package/src/utilities/prettier.js +0 -38
  71. package/src/utilities/prettier.js.map +0 -1
  72. package/src/utils/rules/move-npm-packages.d.ts +0 -11
  73. package/src/utils/rules/move-npm-packages.js +0 -76
  74. package/src/utils/rules/move-npm-packages.js.map +0 -1
  75. package/src/utils/rules/to-js.d.ts +0 -8
  76. package/src/utils/rules/to-js.js +0 -82
  77. package/src/utils/rules/to-js.js.map +0 -1
  78. package/src/utils/rules/update-karma-conf.d.ts +0 -8
  79. package/src/utils/rules/update-karma-conf.js +0 -36
  80. package/src/utils/rules/update-karma-conf.js.map +0 -1
  81. package/src/utils/update-packages-in-package-json.d.ts +0 -3
  82. package/src/utils/update-packages-in-package-json.js +0 -56
  83. package/src/utils/update-packages-in-package-json.js.map +0 -1
  84. package/src/utils/update-task.d.ts +0 -2
  85. package/src/utils/update-task.js +0 -83
  86. package/src/utils/update-task.js.map +0 -1
@@ -1,26 +1,4 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
1
  export declare const enum Linter {
3
2
  EsLint = "eslint",
4
3
  None = "none"
5
4
  }
6
- export declare function generateProjectLint(projectRoot: string, tsConfigPath: string, linter: Linter, eslintFilePatterns: string[]): {
7
- builder: string;
8
- options: {
9
- lintFilePatterns: string[];
10
- };
11
- };
12
- interface AddLintFileOptions {
13
- onlyGlobal?: boolean;
14
- localConfig?: any;
15
- extraPackageDeps?: {
16
- dependencies: {
17
- [key: string]: string;
18
- };
19
- devDependencies: {
20
- [key: string]: string;
21
- };
22
- };
23
- setParserOptionsProject?: boolean;
24
- }
25
- export declare function addLintFiles(projectRoot: string, linter: Linter, options?: AddLintFileOptions): Rule;
26
- export {};
package/src/utils/lint.js CHANGED
@@ -1,167 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addLintFiles = exports.generateProjectLint = void 0;
4
- const tslib_1 = require("tslib");
5
- const core_1 = require("@angular-devkit/core");
6
- const schematics_1 = require("@angular-devkit/schematics");
7
- const ast_utils_1 = require("./ast-utils");
8
- const versions_1 = require("./versions");
9
- const devkit_1 = require("@nrwl/devkit");
10
- function generateProjectLint(projectRoot, tsConfigPath, linter, eslintFilePatterns) {
11
- if (linter === "eslint" /* Linter.EsLint */) {
12
- return {
13
- builder: '@nrwl/linter:eslint',
14
- options: {
15
- lintFilePatterns: eslintFilePatterns,
16
- },
17
- };
18
- }
19
- else {
20
- return undefined;
21
- }
22
- }
23
- exports.generateProjectLint = generateProjectLint;
24
- function addLintFiles(projectRoot, linter, options = {}) {
25
- return (host, context) => {
26
- var _a, _b;
27
- if (options.onlyGlobal && options.localConfig) {
28
- throw new Error('onlyGlobal and localConfig cannot be used at the same time');
29
- }
30
- const chainedCommands = [];
31
- if (linter === 'eslint') {
32
- if (!host.exists('/.eslintrc.json')) {
33
- host.create('/.eslintrc.json', globalESLint);
34
- }
35
- chainedCommands.push((0, ast_utils_1.addDepsToPackageJson)(Object.assign({}, (options.extraPackageDeps
36
- ? options.extraPackageDeps.dependencies
37
- : {})), Object.assign({ '@nrwl/linter': versions_1.nxVersion, '@nrwl/eslint-plugin-nx': versions_1.nxVersion, '@typescript-eslint/parser': versions_1.typescriptESLintVersion, '@typescript-eslint/eslint-plugin': versions_1.typescriptESLintVersion, eslint: versions_1.eslintVersion, 'eslint-config-prettier': versions_1.eslintConfigPrettierVersion }, ((_b = (_a = options.extraPackageDeps) === null || _a === void 0 ? void 0 : _a.devDependencies) !== null && _b !== void 0 ? _b : {}))));
38
- if (!options.onlyGlobal) {
39
- chainedCommands.push((host) => {
40
- let configJson;
41
- const rootConfig = `${(0, devkit_1.offsetFromRoot)(projectRoot)}.eslintrc.json`;
42
- // Include all project files to be linted (since they are turned off in the root eslintrc file).
43
- const ignorePatterns = ['!**/*'];
44
- if (options.localConfig) {
45
- /**
46
- * The end config is much easier to reason about if "extends" comes first,
47
- * so as well as applying the extension from the root lint config, we also
48
- * adjust the config to make extends come first.
49
- */
50
- const _a = options.localConfig, { extends: extendsVal } = _a, localConfigExceptExtends = tslib_1.__rest(_a, ["extends"]);
51
- const extendsOption = extendsVal
52
- ? Array.isArray(extendsVal)
53
- ? extendsVal
54
- : [extendsVal]
55
- : [];
56
- configJson = Object.assign({ extends: [...extendsOption, rootConfig], ignorePatterns }, localConfigExceptExtends);
57
- }
58
- else {
59
- configJson = {
60
- extends: rootConfig,
61
- ignorePatterns,
62
- overrides: [
63
- {
64
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
65
- /**
66
- * NOTE: We no longer set parserOptions.project by default when creating new projects.
67
- *
68
- * We have observed that users rarely add rules requiring type-checking to their Nx workspaces, and therefore
69
- * do not actually need the capabilites which parserOptions.project provides. When specifying parserOptions.project,
70
- * typescript-eslint needs to create full TypeScript Programs for you. When omitting it, it can perform a simple
71
- * parse (and AST tranformation) of the source files it encounters during a lint run, which is much faster and much
72
- * less memory intensive.
73
- *
74
- * In the rare case that users attempt to add rules requiring type-checking to their setup later on (and haven't set
75
- * parserOptions.project), the executor will attempt to look for the particular error typescript-eslint gives you
76
- * and provide feedback to the user.
77
- */
78
- parserOptions: !options.setParserOptionsProject
79
- ? undefined
80
- : {
81
- project: [`${projectRoot}/tsconfig.*?.json`],
82
- },
83
- /**
84
- * Having an empty rules object present makes it more obvious to the user where they would
85
- * extend things from if they needed to
86
- */
87
- rules: {},
88
- },
89
- {
90
- files: ['*.ts', '*.tsx'],
91
- rules: {},
92
- },
93
- {
94
- files: ['*.js', '*.jsx'],
95
- rules: {},
96
- },
97
- ],
98
- };
99
- }
100
- host.create((0, core_1.join)(projectRoot, `.eslintrc.json`), JSON.stringify(configJson));
101
- });
102
- }
103
- return (0, schematics_1.chain)(chainedCommands);
104
- }
105
- };
106
- }
107
- exports.addLintFiles = addLintFiles;
108
- const globalESLint = JSON.stringify({
109
- root: true,
110
- ignorePatterns: ['**/*'],
111
- plugins: ['@nrwl/nx'],
112
- /**
113
- * We leverage ESLint's "overrides" capability so that we can set up a root config which will support
114
- * all permutations of Nx workspaces across all frameworks, libraries and tools.
115
- *
116
- * The key point is that we need entirely different ESLint config to apply to different types of files,
117
- * but we still want to share common config where possible.
118
- */
119
- overrides: [
120
- /**
121
- * This configuration is intended to apply to all "source code" (but not
122
- * markup like HTML, or other custom file types like GraphQL)
123
- */
124
- {
125
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
126
- rules: {
127
- '@nrwl/nx/enforce-module-boundaries': [
128
- 'error',
129
- {
130
- enforceBuildableLibDependency: true,
131
- allow: [],
132
- depConstraints: [
133
- { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] },
134
- ],
135
- },
136
- ],
137
- },
138
- },
139
- /**
140
- * This configuration is intended to apply to all TypeScript source files.
141
- * See the eslint-plugin-nx package for what is in the referenced shareable config.
142
- */
143
- {
144
- files: ['*.ts', '*.tsx'],
145
- extends: ['plugin:@nrwl/nx/typescript'],
146
- /**
147
- * Having an empty rules object present makes it more obvious to the user where they would
148
- * extend things from if they needed to
149
- */
150
- rules: {},
151
- },
152
- /**
153
- * This configuration is intended to apply to all JavaScript source files.
154
- * See the eslint-plugin-nx package for what is in the referenced shareable config.
155
- */
156
- {
157
- files: ['*.js', '*.jsx'],
158
- extends: ['plugin:@nrwl/nx/javascript'],
159
- /**
160
- * Having an empty rules object present makes it more obvious to the user where they would
161
- * extend things from if they needed to
162
- */
163
- rules: {},
164
- },
165
- ],
166
- });
167
3
  //# sourceMappingURL=lint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/lint.ts"],"names":[],"mappings":";;;;AAAA,+CAA4C;AAC5C,2DAKoC;AACpC,2CAAmD;AACnD,yCAKoB;AACpB,yCAA8C;AAO9C,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,YAAoB,EACpB,MAAc,EACd,kBAA4B;IAE5B,IAAI,MAAM,iCAAkB,EAAE;QAC5B,OAAO;YACL,OAAO,EAAE,qBAAqB;YAC9B,OAAO,EAAE;gBACP,gBAAgB,EAAE,kBAAkB;aACrC;SACF,CAAC;KACH;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAhBD,kDAgBC;AAWD,SAAgB,YAAY,CAC1B,WAAmB,E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ACV,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB;;;;;;OAMG;IACH,SAAS,EAAE;QACT;;;WAGG;QACH;YACE,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;YACzC,KAAK,EAAE;gBACL,oCAAoC,EAAE;oBACpC,OAAO;oBACP;wBACE,6BAA6B,EAAE,IAAI;wBACnC,KAAK,EAAE,EAAE;wBACT,cAAc,EAAE;4BACd,EAAE,SAAS,EAAE,GAAG,EAAE,wBAAwB,EAAE,CAAC,GAAG,CAAC,EAAE;yBACpD;qBACF;iBACF;aACF;SACF;QAED;;;WAGG;QACH;YACE,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACxB,OAAO,EAAE,CAAC,4BAA4B,CAAC;YACvC;;;eAGG;YACH,KAAK,EAAE,EAAE;SACV;QAED;;;WAGG;QACH;YACE,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACxB,OAAO,EAAE,CAAC,4BAA4B,CAAC;YACvC;;;eAGG;YACH,KAAK,EAAE,EAAE;SACV;KACF;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/lint.ts"],"names":[],"mappings":""}
@@ -1,8 +1,6 @@
1
- import type { Tree } from '@angular-devkit/schematics';
2
1
  export declare enum ProjectType {
3
2
  Application = "application",
4
3
  Library = "library"
5
4
  }
6
- export declare function projectRootDir(projectType: ProjectType): "libs" | "apps";
5
+ export declare function projectRootDir(projectType: ProjectType): "apps" | "libs";
7
6
  export declare function projectDir(projectType: ProjectType): "app" | "lib";
8
- export declare function projectRootPath(tree: Tree, projectName: string): string;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projectRootPath = exports.projectDir = exports.projectRootDir = exports.ProjectType = void 0;
4
- const ast_utils_1 = require("./ast-utils");
5
- const core_1 = require("@angular-devkit/core");
3
+ exports.projectDir = exports.projectRootDir = exports.ProjectType = void 0;
6
4
  var ProjectType;
7
5
  (function (ProjectType) {
8
6
  ProjectType["Application"] = "application";
@@ -28,9 +26,4 @@ function projectDir(projectType) {
28
26
  }
29
27
  }
30
28
  exports.projectDir = projectDir;
31
- function projectRootPath(tree, projectName) {
32
- const { sourceRoot: projectSrcRoot, projectType } = (0, ast_utils_1.getProjectConfig)(tree, projectName);
33
- return (0, core_1.join)(projectSrcRoot, projectDir(projectType));
34
- }
35
- exports.projectRootPath = projectRootPath;
36
29
  //# sourceMappingURL=project-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project-type.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/project-type.ts"],"names":[],"mappings":";;;AACA,2CAA+C;AAC/C,+CAA4C;AAE5C,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,0CAA2B,CAAA;IAC3B,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AAED,SAAgB,cAAc,CAAC,WAAwB;IACrD,IAAI,WAAW,IAAI,WAAW,CAAC,WAAW,EAAE;QAC1C,OAAO,MAAM,CAAC;KACf;SAAM,IAAI,WAAW,IAAI,WAAW,CAAC,OAAO,EAAE;QAC7C,OAAO,MAAM,CAAC;KACf;AACH,CAAC;AAND,wCAMC;AAED,SAAgB,UAAU,CAAC,WAAwB;IACjD,IAAI,WAAW,IAAI,WAAW,CAAC,WAAW,EAAE;QAC1C,wBAAwB;QACxB,OAAO,KAAK,CAAC;KACd;SAAM,IAAI,WAAW,IAAI,WAAW,CAAC,OAAO,EAAE;QAC7C,wBAAwB;QACxB,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AARD,gCAQC;AAED,SAAgB,eAAe,CAAC,IAAU,EAAE,WAAmB;IAC7D,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,IAAA,4BAAgB,EAClE,IAAI,EACJ,WAAW,CACZ,CAAC;IACF,OAAO,IAAA,WAAI,EAAC,cAAc,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;AACvD,CAAC;AAND,0CAMC"}
1
+ {"version":3,"file":"project-type.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/project-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,0CAA2B,CAAA;IAC3B,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AAED,SAAgB,cAAc,CAAC,WAAwB;IACrD,IAAI,WAAW,IAAI,WAAW,CAAC,WAAW,EAAE;QAC1C,OAAO,MAAM,CAAC;KACf;SAAM,IAAI,WAAW,IAAI,WAAW,CAAC,OAAO,EAAE;QAC7C,OAAO,MAAM,CAAC;KACf;AACH,CAAC;AAND,wCAMC;AAED,SAAgB,UAAU,CAAC,WAAwB;IACjD,IAAI,WAAW,IAAI,WAAW,CAAC,WAAW,EAAE;QAC1C,wBAAwB;QACxB,OAAO,KAAK,CAAC;KACd;SAAM,IAAI,WAAW,IAAI,WAAW,CAAC,OAAO,EAAE;QAC7C,wBAAwB;QACxB,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AARD,gCAQC"}
@@ -9,6 +9,7 @@
9
9
  ```
10
10
 
11
11
  @method decamelize
12
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
12
13
  @param {String} str The string to decamelize.
13
14
  @return {String} the decamelized string.
14
15
  */
@@ -25,6 +26,7 @@ export declare function decamelize(str: string): string;
25
26
  ```
26
27
 
27
28
  @method dasherize
29
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
28
30
  @param {String} str The string to dasherize.
29
31
  @return {String} the dasherized string.
30
32
  */
@@ -41,6 +43,7 @@ export declare function dasherize(str?: string): string;
41
43
  ```
42
44
 
43
45
  @method camelize
46
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
44
47
  @param {String} str The string to camelize.
45
48
  @return {String} the camelized string.
46
49
  */
@@ -56,6 +59,7 @@ export declare function camelize(str: string): string;
56
59
  ```
57
60
 
58
61
  @method classify
62
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
59
63
  @param {String} str the string to classify
60
64
  @return {String} the classified string
61
65
  */
@@ -72,6 +76,7 @@ export declare function classify(str: string): string;
72
76
  ```
73
77
 
74
78
  @method underscore
79
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
75
80
  @param {String} str The string to underscore.
76
81
  @return {String} the underscored string.
77
82
  */
@@ -87,9 +92,16 @@ export declare function underscore(str: string): string;
87
92
  ```
88
93
 
89
94
  @method capitalize
95
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
90
96
  @param {String} str The string to capitalize.
91
97
  @return {String} The capitalized string.
92
98
  */
93
99
  export declare function capitalize(str: string): string;
100
+ /**
101
+ * @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
102
+ */
94
103
  export declare function group(name: string, group: string | undefined): string;
104
+ /**
105
+ * @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
106
+ */
95
107
  export declare function featurePath(group: boolean | undefined, flat: boolean | undefined, path: string, name: string): string;
@@ -24,6 +24,7 @@ const STRING_UNDERSCORE_REGEXP_2 = /-|\s+/g;
24
24
  ```
25
25
 
26
26
  @method decamelize
27
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
27
28
  @param {String} str The string to decamelize.
28
29
  @return {String} the decamelized string.
29
30
  */
@@ -43,6 +44,7 @@ exports.decamelize = decamelize;
43
44
  ```
44
45
 
45
46
  @method dasherize
47
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
46
48
  @param {String} str The string to dasherize.
47
49
  @return {String} the dasherized string.
48
50
  */
@@ -62,6 +64,7 @@ exports.dasherize = dasherize;
62
64
  ```
63
65
 
64
66
  @method camelize
67
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
65
68
  @param {String} str The string to camelize.
66
69
  @return {String} the camelized string.
67
70
  */
@@ -84,6 +87,7 @@ exports.camelize = camelize;
84
87
  ```
85
88
 
86
89
  @method classify
90
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
87
91
  @param {String} str the string to classify
88
92
  @return {String} the classified string
89
93
  */
@@ -106,6 +110,7 @@ exports.classify = classify;
106
110
  ```
107
111
 
108
112
  @method underscore
113
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
109
114
  @param {String} str The string to underscore.
110
115
  @return {String} the underscored string.
111
116
  */
@@ -127,6 +132,7 @@ exports.underscore = underscore;
127
132
  ```
128
133
 
129
134
  @method capitalize
135
+ @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
130
136
  @param {String} str The string to capitalize.
131
137
  @return {String} The capitalized string.
132
138
  */
@@ -134,10 +140,16 @@ function capitalize(str) {
134
140
  return str.charAt(0).toUpperCase() + str.slice(1);
135
141
  }
136
142
  exports.capitalize = capitalize;
143
+ /**
144
+ * @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
145
+ */
137
146
  function group(name, group) {
138
147
  return group ? `${group}/${name}` : name;
139
148
  }
140
149
  exports.group = group;
150
+ /**
151
+ * @deprecated This will be removed from `@nrwl/workspace` in version 17. Prefer `@nrwl/js` when importing.
152
+ */
141
153
  function featurePath(group, flat, path, name) {
142
154
  if (group && !flat) {
143
155
  return `../../${path}/${name}/`;
@@ -1 +1 @@
1
- {"version":3,"file":"strings.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/strings.ts"],"names":[],"mappings":";;;A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GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAC,IAAY,EAAE,KAAyB;IAC3D,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3C,CAAC;AAFD,sBAEC;AAED;;GAEG;AACH,SAAgB,WAAW,CACzB,KAA0B,EAC1B,IAAyB,EACzB,IAAY,EACZ,IAAY;IAEZ,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;QAClB,OAAO,SAAS,IAAI,IAAI,IAAI,GAAG,CAAC;KACjC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACtC,CAAC;AAXD,kCAWC"}
@@ -1,7 +1,6 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const angularCliVersion = "~15.2.0";
3
3
  export declare const typescriptVersion = "~4.9.5";
4
- export declare const prettierVersion = "^2.6.2";
5
4
  export declare const typescriptESLintVersion = "^5.36.1";
6
5
  export declare const eslintVersion = "~8.15.0";
7
6
  export declare const eslintConfigPrettierVersion = "8.1.0";
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eslintConfigPrettierVersion = exports.eslintVersion = exports.typescriptESLintVersion = exports.prettierVersion = exports.typescriptVersion = exports.angularCliVersion = exports.nxVersion = void 0;
3
+ exports.eslintConfigPrettierVersion = exports.eslintVersion = exports.typescriptESLintVersion = exports.typescriptVersion = exports.angularCliVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.angularCliVersion = '~15.2.0';
6
6
  exports.typescriptVersion = '~4.9.5';
7
- exports.prettierVersion = '^2.6.2';
8
7
  exports.typescriptESLintVersion = '^5.36.1';
9
8
  exports.eslintVersion = '~8.15.0';
10
9
  exports.eslintConfigPrettierVersion = '8.1.0';
@@ -1 +1 @@
1
- {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/versions.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;AAElD,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAC9B,QAAA,iBAAiB,GAAG,QAAQ,CAAC;AAC7B,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,uBAAuB,GAAG,SAAS,CAAC;AACpC,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,2BAA2B,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../../../../packages/workspace/src/utils/versions.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;AAElD,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAC9B,QAAA,iBAAiB,GAAG,QAAQ,CAAC;AAC7B,QAAA,uBAAuB,GAAG,SAAS,CAAC;AACpC,QAAA,aAAa,GAAG,SAAS,CAAC;AAC1B,QAAA,2BAA2B,GAAG,OAAO,CAAC"}
@@ -1,4 +0,0 @@
1
- # Add files here to ignore them from prettier formatting
2
-
3
- /dist
4
- /coverage
@@ -1,4 +0,0 @@
1
- # Add files here to ignore them from prettier formatting
2
-
3
- /dist
4
- /coverage
@@ -1,4 +0,0 @@
1
- # Add files here to ignore them from prettier formatting
2
-
3
- /dist
4
- /coverage
@@ -1,22 +0,0 @@
1
- import type { Tree } from '@nrwl/devkit';
2
- import type * 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,197 +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 typescript_1 = require("./typescript");
5
- const typescript_2 = require("nx/src/utils/typescript");
6
- let tsModule;
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
- if (!tsModule) {
50
- tsModule = (0, typescript_1.ensureTypescript)();
51
- }
52
- const rootNode = source;
53
- const allImports = (0, typescript_2.findNodes)(rootNode, tsModule.SyntaxKind.ImportDeclaration);
54
- // get nodes that map to import statements from the file fileName
55
- const relevantImports = allImports.filter((node) => {
56
- // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
57
- const importFiles = node
58
- .getChildren()
59
- .filter((child) => child.kind === tsModule.SyntaxKind.StringLiteral)
60
- .map((n) => n.text);
61
- return importFiles.filter((file) => file === fileName).length === 1;
62
- });
63
- if (relevantImports.length > 0) {
64
- let importsAsterisk = false;
65
- // imports from import file
66
- const imports = [];
67
- relevantImports.forEach((n) => {
68
- Array.prototype.push.apply(imports, (0, typescript_2.findNodes)(n, tsModule.SyntaxKind.Identifier));
69
- if ((0, typescript_2.findNodes)(n, tsModule.SyntaxKind.AsteriskToken).length > 0) {
70
- importsAsterisk = true;
71
- }
72
- });
73
- // if imports * from fileName, don't add symbolName
74
- if (importsAsterisk) {
75
- return source;
76
- }
77
- const importTextNodes = imports.filter((n) => n.text === symbolName);
78
- // insert import if it's not there
79
- if (importTextNodes.length === 0) {
80
- const fallbackPos = (0, typescript_2.findNodes)(relevantImports[0], tsModule.SyntaxKind.CloseBraceToken)[0].getStart() ||
81
- (0, typescript_2.findNodes)(relevantImports[0], tsModule.SyntaxKind.FromKeyword)[0].getStart();
82
- return insertAfterLastOccurrence(host, source, imports, `, ${symbolName}`, fileToEdit, fallbackPos);
83
- }
84
- return source;
85
- }
86
- // no such import declaration exists
87
- const useStrict = (0, typescript_2.findNodes)(rootNode, tsModule.SyntaxKind.StringLiteral).filter((n) => n.text === 'use strict');
88
- let fallbackPos = 0;
89
- if (useStrict.length > 0) {
90
- fallbackPos = useStrict[0].end;
91
- }
92
- const open = isDefault ? '' : '{ ';
93
- const close = isDefault ? '' : ' }';
94
- // if there are no imports or 'use strict' statement, insert import at beginning of file
95
- const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
96
- const separator = insertAtBeginning ? '' : ';\n';
97
- const toInsert = `${separator}import ${open}${symbolName}${close}` +
98
- ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
99
- return insertAfterLastOccurrence(host, source, allImports, toInsert, fileToEdit, fallbackPos, tsModule.SyntaxKind.StringLiteral);
100
- }
101
- exports.insertImport = insertImport;
102
- function insertAfterLastOccurrence(host, sourceFile, nodes, toInsert, pathToFile, fallbackPos, syntaxKind) {
103
- // sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
104
- let lastItem = [...nodes].sort(nodesByPosition).pop();
105
- if (!lastItem) {
106
- throw new Error();
107
- }
108
- if (syntaxKind) {
109
- lastItem = (0, typescript_2.findNodes)(lastItem, syntaxKind).sort(nodesByPosition).pop();
110
- }
111
- if (!lastItem && fallbackPos == undefined) {
112
- throw new Error(`tried to insert ${toInsert} as first occurrence with no fallback position`);
113
- }
114
- const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
115
- return insertChange(host, sourceFile, pathToFile, lastItemPosition, toInsert);
116
- }
117
- function addGlobal(host, source, modulePath, statement) {
118
- if (!tsModule) {
119
- tsModule = (0, typescript_1.ensureTypescript)();
120
- }
121
- const allImports = (0, typescript_2.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
122
- if (allImports.length > 0) {
123
- const lastImport = allImports[allImports.length - 1];
124
- return insertChange(host, source, modulePath, lastImport.end + 1, `\n${statement}\n`);
125
- }
126
- else {
127
- return insertChange(host, source, modulePath, 0, `${statement}\n`);
128
- }
129
- }
130
- exports.addGlobal = addGlobal;
131
- function getImport(source, predicate) {
132
- if (!tsModule) {
133
- tsModule = (0, typescript_1.ensureTypescript)();
134
- }
135
- const allImports = (0, typescript_2.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
136
- const matching = allImports.filter((i) => predicate(i.moduleSpecifier.getText()));
137
- return matching.map((i) => {
138
- const moduleSpec = i.moduleSpecifier
139
- .getText()
140
- .substring(1, i.moduleSpecifier.getText().length - 1);
141
- const t = i.importClause.namedBindings.getText();
142
- const bindings = t
143
- .replace('{', '')
144
- .replace('}', '')
145
- .split(',')
146
- .map((q) => q.trim());
147
- return { moduleSpec, bindings };
148
- });
149
- }
150
- exports.getImport = getImport;
151
- function replaceNodeValue(host, sourceFile, modulePath, node, content) {
152
- return replaceChange(host, sourceFile, modulePath, node.getStart(node.getSourceFile()), content, node.getText());
153
- }
154
- exports.replaceNodeValue = replaceNodeValue;
155
- function addParameterToConstructor(tree, source, modulePath, opts) {
156
- if (!tsModule) {
157
- tsModule = (0, typescript_1.ensureTypescript)();
158
- }
159
- const clazz = findClass(source, opts.className);
160
- const constructor = clazz.members.filter((m) => m.kind === tsModule.SyntaxKind.Constructor)[0];
161
- if (constructor) {
162
- throw new Error('Should be tested'); // TODO: check this
163
- }
164
- return addMethod(tree, source, modulePath, {
165
- className: opts.className,
166
- methodHeader: `constructor(${opts.param})`,
167
- });
168
- }
169
- exports.addParameterToConstructor = addParameterToConstructor;
170
- function addMethod(tree, source, modulePath, opts) {
171
- const clazz = findClass(source, opts.className);
172
- const body = opts.body
173
- ? `
174
- ${opts.methodHeader} {
175
- ${opts.body}
176
- }
177
- `
178
- : `
179
- ${opts.methodHeader} {}
180
- `;
181
- return insertChange(tree, source, modulePath, clazz.end - 1, body);
182
- }
183
- exports.addMethod = addMethod;
184
- function findClass(source, className, silent = false) {
185
- if (!tsModule) {
186
- tsModule = (0, typescript_1.ensureTypescript)();
187
- }
188
- const nodes = (0, typescript_1.getSourceNodes)(source);
189
- const clazz = nodes.filter((n) => n.kind === tsModule.SyntaxKind.ClassDeclaration &&
190
- n.name.text === className)[0];
191
- if (!clazz && !silent) {
192
- throw new Error(`Cannot find class '${className}'.`);
193
- }
194
- return clazz;
195
- }
196
- exports.findClass = findClass;
197
- //# sourceMappingURL=ast-utils.js.map