@angular-devkit/schematics 9.1.0 → 9.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-devkit/schematics",
3
- "version": "9.1.0",
3
+ "version": "9.1.4",
4
4
  "description": "Angular Schematics - Library",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "schematics"
19
19
  ],
20
20
  "dependencies": {
21
- "@angular-devkit/core": "9.1.0",
21
+ "@angular-devkit/core": "9.1.4",
22
22
  "ora": "4.0.3",
23
23
  "rxjs": "6.5.4"
24
24
  },
@@ -18,6 +18,7 @@ export declare class NodePackageDoesNotSupportSchematics extends BaseException {
18
18
  export declare class NodeModulesEngineHost extends FileSystemEngineHostBase {
19
19
  private readonly paths?;
20
20
  constructor(paths?: string[] | undefined);
21
+ private resolve;
21
22
  protected _resolveCollectionPath(name: string): string;
22
23
  protected _resolveReferenceString(refString: string, parentPath: string): {
23
24
  ref: RuleFactory<{}>;
@@ -26,23 +26,57 @@ class NodeModulesEngineHost extends file_system_engine_host_base_1.FileSystemEng
26
26
  super();
27
27
  this.paths = paths;
28
28
  }
29
- _resolveCollectionPath(name) {
30
- let collectionPath = undefined;
31
- if (name.startsWith('.') || name.startsWith('/')) {
32
- name = path_1.resolve(name);
29
+ resolve(name, requester, references = new Set()) {
30
+ if (requester) {
31
+ if (references.has(requester)) {
32
+ references.add(requester);
33
+ throw new Error('Circular schematic reference detected: ' + JSON.stringify(Array.from(references)));
34
+ }
35
+ else {
36
+ references.add(requester);
37
+ }
33
38
  }
34
- if (path_1.extname(name)) {
35
- // When having an extension let's just resolve the provided path.
36
- collectionPath = require.resolve(name, { paths: this.paths });
39
+ const relativeBase = requester ? path_1.dirname(requester) : process.cwd();
40
+ let collectionPath = undefined;
41
+ if (name.startsWith('.')) {
42
+ name = path_1.resolve(relativeBase, name);
37
43
  }
38
- else {
39
- const packageJsonPath = require.resolve(path_1.join(name, 'package.json'), { paths: this.paths });
44
+ const resolveOptions = {
45
+ paths: requester ? [path_1.dirname(requester), ...(this.paths || [])] : this.paths,
46
+ };
47
+ // Try to resolve as a package
48
+ try {
49
+ const packageJsonPath = require.resolve(path_1.join(name, 'package.json'), resolveOptions);
40
50
  const { schematics } = require(packageJsonPath);
41
51
  if (!schematics || typeof schematics !== 'string') {
42
52
  throw new NodePackageDoesNotSupportSchematics(name);
43
53
  }
44
- collectionPath = path_1.resolve(path_1.dirname(packageJsonPath), schematics);
54
+ collectionPath = this.resolve(schematics, packageJsonPath, references);
45
55
  }
56
+ catch (e) {
57
+ if (e.code !== 'MODULE_NOT_FOUND') {
58
+ throw e;
59
+ }
60
+ }
61
+ // If not a package, try to resolve as a file
62
+ if (!collectionPath) {
63
+ try {
64
+ collectionPath = require.resolve(name, resolveOptions);
65
+ }
66
+ catch (e) {
67
+ if (e.code !== 'MODULE_NOT_FOUND') {
68
+ throw e;
69
+ }
70
+ }
71
+ }
72
+ // If not a package or a file, error
73
+ if (!collectionPath) {
74
+ throw new file_system_engine_host_base_1.CollectionCannotBeResolvedException(name);
75
+ }
76
+ return collectionPath;
77
+ }
78
+ _resolveCollectionPath(name) {
79
+ const collectionPath = this.resolve(name);
46
80
  try {
47
81
  file_system_utility_1.readJsonFile(collectionPath);
48
82
  return collectionPath;
@@ -51,8 +85,10 @@ class NodeModulesEngineHost extends file_system_engine_host_base_1.FileSystemEng
51
85
  if (e instanceof core_1.InvalidJsonCharacterException || e instanceof core_1.UnexpectedEndOfInputException) {
52
86
  throw new file_system_engine_host_base_1.InvalidCollectionJsonException(name, collectionPath, e);
53
87
  }
88
+ else {
89
+ throw e;
90
+ }
54
91
  }
55
- throw new file_system_engine_host_base_1.CollectionCannotBeResolvedException(name);
56
92
  }
57
93
  _resolveReferenceString(refString, parentPath) {
58
94
  const ref = new export_ref_1.ExportStringRef(refString, parentPath);