UNPKG

27.6 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define("@angular/compiler-cli/ngcc/src/entry_point_finder/directory_walker_entry_point_finder", ["require", "exports", "tslib", "@angular/compiler-cli/ngcc/src/packages/entry_point", "@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer", "@angular/compiler-cli/ngcc/src/entry_point_finder/utils"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 var tslib_1 = require("tslib");
13 var entry_point_1 = require("@angular/compiler-cli/ngcc/src/packages/entry_point");
14 var new_entry_point_file_writer_1 = require("@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer");
15 var utils_1 = require("@angular/compiler-cli/ngcc/src/entry_point_finder/utils");
16 /**
17 * An EntryPointFinder that searches for all entry-points that can be found given a `basePath` and
18 * `pathMappings`.
19 */
20 var DirectoryWalkerEntryPointFinder = /** @class */ (function () {
21 function DirectoryWalkerEntryPointFinder(fs, config, logger, resolver, entryPointManifest, sourceDirectory, pathMappings) {
22 this.fs = fs;
23 this.config = config;
24 this.logger = logger;
25 this.resolver = resolver;
26 this.entryPointManifest = entryPointManifest;
27 this.sourceDirectory = sourceDirectory;
28 this.pathMappings = pathMappings;
29 this.basePaths = utils_1.getBasePaths(this.logger, this.sourceDirectory, this.pathMappings);
30 }
31 /**
32 * Search the `sourceDirectory`, and sub-directories, using `pathMappings` as necessary, to find
33 * all package entry-points.
34 */
35 DirectoryWalkerEntryPointFinder.prototype.findEntryPoints = function () {
36 var e_1, _a;
37 var unsortedEntryPoints = [];
38 try {
39 for (var _b = tslib_1.__values(this.basePaths), _c = _b.next(); !_c.done; _c = _b.next()) {
40 var basePath = _c.value;
41 var entryPoints = this.entryPointManifest.readEntryPointsUsingManifest(basePath) ||
42 this.walkBasePathForPackages(basePath);
43 unsortedEntryPoints.push.apply(unsortedEntryPoints, tslib_1.__spread(entryPoints));
44 }
45 }
46 catch (e_1_1) { e_1 = { error: e_1_1 }; }
47 finally {
48 try {
49 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
50 }
51 finally { if (e_1) throw e_1.error; }
52 }
53 return this.resolver.sortEntryPointsByDependency(unsortedEntryPoints);
54 };
55 /**
56 * Search the `basePath` for possible Angular packages and entry-points.
57 *
58 * @param basePath The path at which to start the search
59 * @returns an array of `EntryPoint`s that were found within `basePath`.
60 */
61 DirectoryWalkerEntryPointFinder.prototype.walkBasePathForPackages = function (basePath) {
62 var _this = this;
63 this.logger.debug("No manifest found for " + basePath + " so walking the directories for entry-points.");
64 var entryPoints = utils_1.trackDuration(function () { return _this.walkDirectoryForPackages(basePath); }, function (duration) { return _this.logger.debug("Walking " + basePath + " for entry-points took " + duration + "s."); });
65 this.entryPointManifest.writeEntryPointManifest(basePath, entryPoints);
66 return entryPoints;
67 };
68 /**
69 * Look for Angular packages that need to be compiled, starting at the source directory.
70 * The function will recurse into directories that start with `@...`, e.g. `@angular/...`.
71 *
72 * @param sourceDirectory An absolute path to the root directory where searching begins.
73 * @returns an array of `EntryPoint`s that were found within `sourceDirectory`.
74 */
75 DirectoryWalkerEntryPointFinder.prototype.walkDirectoryForPackages = function (sourceDirectory) {
76 var e_2, _a;
77 // Try to get a primary entry point from this directory
78 var primaryEntryPoint = entry_point_1.getEntryPointInfo(this.fs, this.config, this.logger, sourceDirectory, sourceDirectory);
79 // If there is an entry-point but it is not compatible with ngcc (it has a bad package.json or
80 // invalid typings) then exit. It is unlikely that such an entry point has a dependency on an
81 // Angular library.
82 if (primaryEntryPoint === entry_point_1.INCOMPATIBLE_ENTRY_POINT) {
83 return [];
84 }
85 var entryPoints = [];
86 if (primaryEntryPoint !== entry_point_1.NO_ENTRY_POINT) {
87 entryPoints.push(primaryEntryPoint);
88 this.collectSecondaryEntryPoints(entryPoints, sourceDirectory, sourceDirectory, this.fs.readdir(sourceDirectory));
89 // Also check for any nested node_modules in this package but only if at least one of the
90 // entry-points was compiled by Angular.
91 if (entryPoints.some(function (e) { return e.compiledByAngular; })) {
92 var nestedNodeModulesPath = this.fs.join(sourceDirectory, 'node_modules');
93 if (this.fs.exists(nestedNodeModulesPath)) {
94 entryPoints.push.apply(entryPoints, tslib_1.__spread(this.walkDirectoryForPackages(nestedNodeModulesPath)));
95 }
96 }
97 return entryPoints;
98 }
99 try {
100 // The `sourceDirectory` was not a package (i.e. there was no package.json)
101 // So search its sub-directories for Angular packages and entry-points
102 for (var _b = tslib_1.__values(this.fs.readdir(sourceDirectory)), _c = _b.next(); !_c.done; _c = _b.next()) {
103 var path = _c.value;
104 if (isIgnorablePath(path)) {
105 // Ignore hidden files, node_modules and ngcc directory
106 continue;
107 }
108 var absolutePath = this.fs.resolve(sourceDirectory, path);
109 var stat = this.fs.lstat(absolutePath);
110 if (stat.isSymbolicLink() || !stat.isDirectory()) {
111 // Ignore symbolic links and non-directories
112 continue;
113 }
114 entryPoints.push.apply(entryPoints, tslib_1.__spread(this.walkDirectoryForPackages(this.fs.join(sourceDirectory, path))));
115 }
116 }
117 catch (e_2_1) { e_2 = { error: e_2_1 }; }
118 finally {
119 try {
120 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
121 }
122 finally { if (e_2) throw e_2.error; }
123 }
124 return entryPoints;
125 };
126 /**
127 * Search the `directory` looking for any secondary entry-points for a package, adding any that
128 * are found to the `entryPoints` array.
129 *
130 * @param entryPoints An array where we will add any entry-points found in this directory
131 * @param packagePath The absolute path to the package that may contain entry-points
132 * @param directory The current directory being searched
133 * @param paths The paths contained in the current `directory`.
134 */
135 DirectoryWalkerEntryPointFinder.prototype.collectSecondaryEntryPoints = function (entryPoints, packagePath, directory, paths) {
136 var e_3, _a;
137 var _this = this;
138 var _loop_1 = function (path) {
139 if (isIgnorablePath(path)) {
140 return "continue";
141 }
142 var absolutePath = this_1.fs.resolve(directory, path);
143 var stat = this_1.fs.lstat(absolutePath);
144 if (stat.isSymbolicLink()) {
145 return "continue";
146 }
147 var isDirectory = stat.isDirectory();
148 if (!path.endsWith('.js') && !isDirectory) {
149 return "continue";
150 }
151 // If the path is a JS file then strip its extension and see if we can match an
152 // entry-point.
153 var possibleEntryPointPath = isDirectory ? absolutePath : stripJsExtension(absolutePath);
154 var isEntryPoint = false;
155 var subEntryPoint = entry_point_1.getEntryPointInfo(this_1.fs, this_1.config, this_1.logger, packagePath, possibleEntryPointPath);
156 if (subEntryPoint !== entry_point_1.NO_ENTRY_POINT && subEntryPoint !== entry_point_1.INCOMPATIBLE_ENTRY_POINT) {
157 entryPoints.push(subEntryPoint);
158 isEntryPoint = true;
159 }
160 if (!isDirectory) {
161 return "continue";
162 }
163 // This directory may contain entry-points of its own.
164 var childPaths = this_1.fs.readdir(absolutePath);
165 if (!isEntryPoint &&
166 childPaths.some(function (childPath) { return childPath.endsWith('.js') &&
167 _this.fs.stat(_this.fs.resolve(absolutePath, childPath)).isFile(); })) {
168 return "continue";
169 }
170 this_1.collectSecondaryEntryPoints(entryPoints, packagePath, absolutePath, childPaths);
171 };
172 var this_1 = this;
173 try {
174 for (var paths_1 = tslib_1.__values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
175 var path = paths_1_1.value;
176 _loop_1(path);
177 }
178 }
179 catch (e_3_1) { e_3 = { error: e_3_1 }; }
180 finally {
181 try {
182 if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
183 }
184 finally { if (e_3) throw e_3.error; }
185 }
186 };
187 return DirectoryWalkerEntryPointFinder;
188 }());
189 exports.DirectoryWalkerEntryPointFinder = DirectoryWalkerEntryPointFinder;
190 function stripJsExtension(filePath) {
191 return filePath.replace(/\.js$/, '');
192 }
193 function isIgnorablePath(path) {
194 return path.startsWith('.') || path === 'node_modules' || path === new_entry_point_file_writer_1.NGCC_DIRECTORY;
195 }
196});
197//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9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