@styloviz/schematics 2.0.1 → 2.1.0
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/README.md +64 -2
- package/collection.json +12 -0
- package/lib/sources-block.js +48 -0
- package/lib/workspace.js +54 -0
- package/migrate-primeng/index.js +1 -1
- package/migrate-primeng/map.json +63 -0
- package/ng-add/index.js +151 -35
- package/ng-add/schema.json +2 -1
- package/ng-add/sources-schema.json +9 -0
- package/package.json +4 -2
- package/sources/build-stats.js +139 -0
- package/sources/index.js +404 -0
- package/sources/parts.js +70 -0
- package/sources/schema.json +13 -0
- package/sources/walk.js +426 -0
package/sources/walk.js
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Which shipped kit files an app's imports reach (live-user test M-1, step A1).
|
|
4
|
+
*
|
|
5
|
+
* Starts from the app's own files, follows each import into the installed kit
|
|
6
|
+
* packages and on through the files those import, and returns every kit file
|
|
7
|
+
* reached. Tailwind is then pointed at exactly those files.
|
|
8
|
+
*
|
|
9
|
+
* Why per file works: a multi-component package ships one fesm2022 file per
|
|
10
|
+
* component, and its barrel only imports and re-exports by name. A barrel is
|
|
11
|
+
* therefore followed NAME BY NAME — `import { SvCheckboxComponent } from
|
|
12
|
+
* '@styloviz/forms'` reaches the checkbox file, not the 20 others. Any other
|
|
13
|
+
* kit file is taken whole, with everything it imports: per file it is a
|
|
14
|
+
* superset, never a guess. Type-only imports reach nothing (types are erased),
|
|
15
|
+
* and a namespace or dynamic import takes the whole entry point.
|
|
16
|
+
*/
|
|
17
|
+
const { posix } = require('node:path');
|
|
18
|
+
const { SchematicsException } = require('@angular-devkit/schematics');
|
|
19
|
+
|
|
20
|
+
const KIT_SCOPES = ['@styloviz/', '@styloviz-pro/'];
|
|
21
|
+
/** Every export of a module. */
|
|
22
|
+
const ALL = Symbol('all');
|
|
23
|
+
const CODE_FILE = /\.(?:[mc]?ts|tsx|[mc]?js|jsx)$/;
|
|
24
|
+
const NOT_APP_CODE = /\.spec\.[mc]?[tj]sx?$|\.d\.[mc]?ts$/;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The workspace's own TypeScript compiler — every Angular workspace has one,
|
|
28
|
+
* and parsing with it is what makes the import list exact. Looked up from the
|
|
29
|
+
* workspace first: under pnpm this package does not see the app's devDependencies.
|
|
30
|
+
*/
|
|
31
|
+
function loadTypeScript() {
|
|
32
|
+
for (const from of [process.cwd(), __dirname]) {
|
|
33
|
+
try {
|
|
34
|
+
return require(require.resolve('typescript', { paths: [from] }));
|
|
35
|
+
} catch {
|
|
36
|
+
// try the next place
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new SchematicsException('`sources` needs the workspace\'s TypeScript compiler. Run it from the workspace root, after npm install.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isKitSpecifier = (spec) => KIT_SCOPES.some((scope) => spec.startsWith(scope));
|
|
43
|
+
const isInNodeModules = (path) => path.includes('/node_modules/');
|
|
44
|
+
/** `@styloviz/forms/checkbox` → `@styloviz/forms`. */
|
|
45
|
+
const packageName = (spec) => spec.split('/').slice(0, 2).join('/');
|
|
46
|
+
|
|
47
|
+
function modifiers(ts, node) {
|
|
48
|
+
return ts.canHaveModifiers(node) ? ts.getModifiers(node) ?? [] : [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Interfaces, type aliases and `declare` statements: erased, so they import and export nothing at runtime. */
|
|
52
|
+
function isTypeOnlyStatement(ts, st) {
|
|
53
|
+
return (
|
|
54
|
+
ts.isInterfaceDeclaration(st) ||
|
|
55
|
+
ts.isTypeAliasDeclaration(st) ||
|
|
56
|
+
ts.isEmptyStatement(st) ||
|
|
57
|
+
modifiers(ts, st).some((m) => m.kind === ts.SyntaxKind.DeclareKeyword)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function addLocalExports(ts, st, locals) {
|
|
62
|
+
if (ts.isExportAssignment(st)) {
|
|
63
|
+
locals.add('default');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const mods = modifiers(ts, st);
|
|
67
|
+
if (!mods.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) return;
|
|
68
|
+
if (mods.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
69
|
+
locals.add('default');
|
|
70
|
+
} else if ((ts.isClassDeclaration(st) || ts.isFunctionDeclaration(st) || ts.isEnumDeclaration(st)) && st.name) {
|
|
71
|
+
locals.add(st.name.text);
|
|
72
|
+
} else if (ts.isVariableStatement(st)) {
|
|
73
|
+
for (const d of st.declarationList.declarations) if (ts.isIdentifier(d.name)) locals.add(d.name.text);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* One module's import and export surface.
|
|
79
|
+
*
|
|
80
|
+
* `pure` is true for a barrel: nothing but imports and re-exports. Only a pure
|
|
81
|
+
* module may be followed by name; anything with code of its own is taken whole.
|
|
82
|
+
*/
|
|
83
|
+
function parseModule(ts, path, text) {
|
|
84
|
+
const kind = /\.[mc]?jsx?$/.test(path) ? ts.ScriptKind.JS : /\.tsx$/.test(path) ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
85
|
+
const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, kind);
|
|
86
|
+
/** @type {{ spec: string, names: Set<string> | symbol, sideEffect: boolean }[]} */
|
|
87
|
+
const imports = [];
|
|
88
|
+
const bindings = new Map(); // local name → { spec, imported }
|
|
89
|
+
const reexports = new Map(); // exported name → { spec, imported }
|
|
90
|
+
const stars = [];
|
|
91
|
+
const locals = new Set();
|
|
92
|
+
const localExportLists = [];
|
|
93
|
+
let pure = true;
|
|
94
|
+
|
|
95
|
+
for (const st of source.statements) {
|
|
96
|
+
if (ts.isImportDeclaration(st)) {
|
|
97
|
+
const spec = st.moduleSpecifier.text;
|
|
98
|
+
const clause = st.importClause;
|
|
99
|
+
if (!clause) {
|
|
100
|
+
imports.push({ spec, names: new Set(), sideEffect: true });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (clause.isTypeOnly) continue;
|
|
104
|
+
const names = new Set();
|
|
105
|
+
let all = false;
|
|
106
|
+
if (clause.name) {
|
|
107
|
+
names.add('default');
|
|
108
|
+
bindings.set(clause.name.text, { spec, imported: 'default' });
|
|
109
|
+
}
|
|
110
|
+
const named = clause.namedBindings;
|
|
111
|
+
if (named && ts.isNamespaceImport(named)) {
|
|
112
|
+
all = true;
|
|
113
|
+
bindings.set(named.name.text, { spec, imported: ALL });
|
|
114
|
+
} else if (named) {
|
|
115
|
+
for (const el of named.elements) {
|
|
116
|
+
if (el.isTypeOnly) continue;
|
|
117
|
+
const imported = (el.propertyName ?? el.name).text;
|
|
118
|
+
names.add(imported);
|
|
119
|
+
bindings.set(el.name.text, { spec, imported });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// `import { type A, type B } from 'x'` keeps nothing at runtime.
|
|
123
|
+
if (all || names.size) imports.push({ spec, names: all ? ALL : names, sideEffect: false });
|
|
124
|
+
} else if (ts.isExportDeclaration(st)) {
|
|
125
|
+
if (st.isTypeOnly) continue;
|
|
126
|
+
const spec = st.moduleSpecifier && ts.isStringLiteral(st.moduleSpecifier) ? st.moduleSpecifier.text : null;
|
|
127
|
+
const clause = st.exportClause;
|
|
128
|
+
if (!clause) {
|
|
129
|
+
if (spec) stars.push(spec);
|
|
130
|
+
} else if (ts.isNamespaceExport(clause)) {
|
|
131
|
+
reexports.set(clause.name.text, { spec, imported: ALL });
|
|
132
|
+
} else {
|
|
133
|
+
for (const el of clause.elements) {
|
|
134
|
+
if (el.isTypeOnly) continue;
|
|
135
|
+
const local = (el.propertyName ?? el.name).text;
|
|
136
|
+
if (spec) reexports.set(el.name.text, { spec, imported: local });
|
|
137
|
+
else localExportLists.push([local, el.name.text]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else if (!isTypeOnlyStatement(ts, st)) {
|
|
141
|
+
pure = false;
|
|
142
|
+
addLocalExports(ts, st, locals);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// `import { X } from './x'; export { X };` is a re-export, the shape of every kit barrel.
|
|
146
|
+
for (const [local, exported] of localExportLists) {
|
|
147
|
+
const binding = bindings.get(local);
|
|
148
|
+
if (binding) reexports.set(exported, binding);
|
|
149
|
+
else locals.add(exported);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const dynamic = [];
|
|
153
|
+
const visit = (node) => {
|
|
154
|
+
if (
|
|
155
|
+
ts.isCallExpression(node) &&
|
|
156
|
+
node.expression.kind === ts.SyntaxKind.ImportKeyword &&
|
|
157
|
+
node.arguments.length &&
|
|
158
|
+
ts.isStringLiteralLike(node.arguments[0])
|
|
159
|
+
) {
|
|
160
|
+
dynamic.push(node.arguments[0].text);
|
|
161
|
+
}
|
|
162
|
+
ts.forEachChild(node, visit);
|
|
163
|
+
};
|
|
164
|
+
visit(source);
|
|
165
|
+
|
|
166
|
+
return { pure, imports, reexports, stars, locals, dynamic };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The file a package.json condition object points at. */
|
|
170
|
+
function pickTarget(value) {
|
|
171
|
+
if (typeof value === 'string') return value;
|
|
172
|
+
if (Array.isArray(value)) {
|
|
173
|
+
for (const v of value) {
|
|
174
|
+
const target = pickTarget(v);
|
|
175
|
+
if (target) return target;
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (value && typeof value === 'object') {
|
|
180
|
+
for (const condition of ['browser', 'module', 'import', 'default']) {
|
|
181
|
+
if (condition in value) {
|
|
182
|
+
const target = pickTarget(value[condition]);
|
|
183
|
+
if (target) return target;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A package's file for `.` or `./sub`, by its `exports` map (patterns included). */
|
|
191
|
+
function packageEntry(pkg, subpath) {
|
|
192
|
+
const exportsField = pkg.exports;
|
|
193
|
+
if (exportsField === undefined) {
|
|
194
|
+
if (subpath === '.') return pkg.module ?? pkg.main ?? 'index.js';
|
|
195
|
+
return subpath;
|
|
196
|
+
}
|
|
197
|
+
const map =
|
|
198
|
+
typeof exportsField === 'string' || Array.isArray(exportsField) || !Object.keys(exportsField).some((k) => k.startsWith('.'))
|
|
199
|
+
? { '.': exportsField }
|
|
200
|
+
: exportsField;
|
|
201
|
+
if (map[subpath] !== undefined) return pickTarget(map[subpath]);
|
|
202
|
+
for (const [key, value] of Object.entries(map)) {
|
|
203
|
+
const star = key.indexOf('*');
|
|
204
|
+
if (star < 0) continue;
|
|
205
|
+
const before = key.slice(0, star);
|
|
206
|
+
const after = key.slice(star + 1);
|
|
207
|
+
if (subpath.length >= before.length + after.length && subpath.startsWith(before) && subpath.endsWith(after)) {
|
|
208
|
+
const target = pickTarget(value);
|
|
209
|
+
return target && target.replace('*', subpath.slice(before.length, subpath.length - after.length));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {object} o
|
|
217
|
+
* @param {typeof import('typescript')} o.ts
|
|
218
|
+
* @param {(path: string) => string | null} o.read file text by workspace path, null if absent
|
|
219
|
+
* @param {string[]} o.roots folders Tailwind already scans whole (the app's and libraries' source roots)
|
|
220
|
+
* @param {{ base: string, entries: [string, string[]][] }} o.paths tsconfig path mapping
|
|
221
|
+
* @param {(spec: string, from: string, reason: 'missing' | 'unresolved') => void} o.onUnresolved
|
|
222
|
+
*/
|
|
223
|
+
function createWalker({ ts, read, roots, paths, onUnresolved }) {
|
|
224
|
+
const parsed = new Map();
|
|
225
|
+
const exportNames = new Map();
|
|
226
|
+
const seen = new Map(); // kit file → Set of names already followed, or ALL
|
|
227
|
+
const kitFiles = new Set();
|
|
228
|
+
const barrels = new Set(); // kit files reached that only import and re-export: no classes to scan
|
|
229
|
+
const localFiles = new Set(); // app code outside the roots, reached by import
|
|
230
|
+
const visitedLocal = new Set();
|
|
231
|
+
|
|
232
|
+
const inRoots = (path) => roots.some((r) => r === '/' || path === r || path.startsWith(`${r}/`));
|
|
233
|
+
const exists = (path) => read(path) !== null;
|
|
234
|
+
|
|
235
|
+
function parse(file) {
|
|
236
|
+
if (!parsed.has(file)) {
|
|
237
|
+
const text = read(file);
|
|
238
|
+
parsed.set(file, text === null ? null : parseModule(ts, file, text));
|
|
239
|
+
}
|
|
240
|
+
return parsed.get(file);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A kit specifier to its installed file: undefined when the package is not installed, null when it has no such entry. */
|
|
244
|
+
function resolveKit(spec, fromDir) {
|
|
245
|
+
const name = packageName(spec);
|
|
246
|
+
const rest = spec.slice(name.length);
|
|
247
|
+
const subpath = rest ? `.${rest}` : '.';
|
|
248
|
+
for (let dir = fromDir; ; dir = posix.dirname(dir)) {
|
|
249
|
+
if (posix.basename(dir) !== 'node_modules') {
|
|
250
|
+
const pkgDir = posix.join(dir, 'node_modules', name);
|
|
251
|
+
const text = read(`${pkgDir}/package.json`);
|
|
252
|
+
if (text !== null) {
|
|
253
|
+
let pkg;
|
|
254
|
+
try {
|
|
255
|
+
pkg = JSON.parse(text);
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const target = packageEntry(pkg, subpath);
|
|
260
|
+
const file = target && posix.join(pkgDir, target);
|
|
261
|
+
return file && exists(file) ? file : null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (dir === '/') return undefined;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function firstExisting(base, suffixes) {
|
|
269
|
+
for (const suffix of suffixes) {
|
|
270
|
+
const candidate = `${base}${suffix}`;
|
|
271
|
+
if (exists(candidate)) return candidate;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const LOCAL_SUFFIXES = ['', '.ts', '.tsx', '.mts', '.js', '.mjs', '/index.ts', '/index.tsx', '/index.js', '/index.mjs'];
|
|
277
|
+
|
|
278
|
+
/** An app-side specifier to a workspace file: relative, or through the tsconfig `paths`. */
|
|
279
|
+
function resolveLocal(spec, fromDir) {
|
|
280
|
+
if (spec.startsWith('.') || spec.startsWith('/')) return firstExisting(posix.join(fromDir, spec), LOCAL_SUFFIXES);
|
|
281
|
+
for (const [pattern, targets] of paths.entries) {
|
|
282
|
+
const star = pattern.indexOf('*');
|
|
283
|
+
let captured;
|
|
284
|
+
if (star < 0) {
|
|
285
|
+
if (spec !== pattern) continue;
|
|
286
|
+
captured = '';
|
|
287
|
+
} else {
|
|
288
|
+
const before = pattern.slice(0, star);
|
|
289
|
+
const after = pattern.slice(star + 1);
|
|
290
|
+
if (!(spec.length >= before.length + after.length && spec.startsWith(before) && spec.endsWith(after))) continue;
|
|
291
|
+
captured = spec.slice(before.length, spec.length - after.length);
|
|
292
|
+
}
|
|
293
|
+
for (const target of targets) {
|
|
294
|
+
const found = firstExisting(posix.join(paths.base, target.replace('*', captured)), LOCAL_SUFFIXES);
|
|
295
|
+
if (found) return found;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Every name a module exports, `export *` included (for following a star by name). */
|
|
302
|
+
function namesOf(file, stack = new Set()) {
|
|
303
|
+
if (exportNames.has(file)) return exportNames.get(file);
|
|
304
|
+
const names = new Set();
|
|
305
|
+
const mod = parse(file);
|
|
306
|
+
if (!mod || stack.has(file)) return names;
|
|
307
|
+
stack.add(file);
|
|
308
|
+
for (const n of mod.locals) names.add(n);
|
|
309
|
+
for (const n of mod.reexports.keys()) names.add(n);
|
|
310
|
+
for (const spec of mod.stars) {
|
|
311
|
+
const target = resolveFromKit(spec, file);
|
|
312
|
+
if (target) for (const n of namesOf(target, stack)) if (n !== 'default') names.add(n);
|
|
313
|
+
}
|
|
314
|
+
stack.delete(file);
|
|
315
|
+
exportNames.set(file, names);
|
|
316
|
+
return names;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function resolveFromKit(spec, fromFile) {
|
|
320
|
+
const fromDir = posix.dirname(fromFile);
|
|
321
|
+
if (spec.startsWith('.')) return firstExisting(posix.join(fromDir, spec), ['', '.mjs', '.js']);
|
|
322
|
+
if (isKitSpecifier(spec)) {
|
|
323
|
+
const file = resolveKit(spec, fromDir);
|
|
324
|
+
if (!file) onUnresolved(spec, fromFile, file === undefined ? 'missing' : 'unresolved');
|
|
325
|
+
return file;
|
|
326
|
+
}
|
|
327
|
+
return null; // Angular, third-party: Tailwind never scanned those.
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function follow(spec, names, fromFile) {
|
|
331
|
+
if (isInNodeModules(fromFile)) {
|
|
332
|
+
const file = resolveFromKit(spec, fromFile);
|
|
333
|
+
if (file) visitKit(file, names);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const local = resolveLocal(spec, posix.dirname(fromFile));
|
|
337
|
+
if (local) {
|
|
338
|
+
if (isInNodeModules(local)) visitKit(local, names);
|
|
339
|
+
else visitLocal(local);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (isKitSpecifier(spec)) {
|
|
343
|
+
const file = resolveKit(spec, posix.dirname(fromFile));
|
|
344
|
+
if (file) visitKit(file, names);
|
|
345
|
+
else onUnresolved(spec, fromFile, file === undefined ? 'missing' : 'unresolved');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const single = (name) => (name === ALL ? ALL : new Set([name]));
|
|
350
|
+
|
|
351
|
+
function visitKit(file, names) {
|
|
352
|
+
const before = seen.get(file);
|
|
353
|
+
if (before === ALL) return;
|
|
354
|
+
const mod = parse(file);
|
|
355
|
+
if (!mod) return;
|
|
356
|
+
if (!mod.pure) {
|
|
357
|
+
seen.set(file, ALL);
|
|
358
|
+
kitFiles.add(file);
|
|
359
|
+
for (const imp of mod.imports) follow(imp.spec, imp.names, file);
|
|
360
|
+
for (const [, r] of mod.reexports) if (r.spec) follow(r.spec, single(r.imported), file);
|
|
361
|
+
for (const spec of mod.stars) follow(spec, ALL, file);
|
|
362
|
+
for (const spec of mod.dynamic) follow(spec, ALL, file);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
barrels.add(file);
|
|
366
|
+
const firstVisit = before === undefined;
|
|
367
|
+
let todo;
|
|
368
|
+
if (names === ALL) {
|
|
369
|
+
todo = ALL;
|
|
370
|
+
seen.set(file, ALL);
|
|
371
|
+
} else {
|
|
372
|
+
todo = [...names].filter((n) => !before?.has(n));
|
|
373
|
+
if (!todo.length && !firstVisit) return;
|
|
374
|
+
seen.set(file, new Set([...(before ?? []), ...todo]));
|
|
375
|
+
}
|
|
376
|
+
if (firstVisit) for (const imp of mod.imports) if (imp.sideEffect) follow(imp.spec, imp.names, file);
|
|
377
|
+
if (todo === ALL) {
|
|
378
|
+
for (const [, r] of mod.reexports) follow(r.spec, single(r.imported), file);
|
|
379
|
+
for (const spec of mod.stars) follow(spec, ALL, file);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
for (const name of todo) {
|
|
383
|
+
const r = mod.reexports.get(name);
|
|
384
|
+
if (r) {
|
|
385
|
+
follow(r.spec, single(r.imported), file);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
// Not re-exported by name: whichever `export *` provides it. An unknown
|
|
389
|
+
// name is a type — erased from the shipped file, so it reaches nothing.
|
|
390
|
+
for (const spec of mod.stars) {
|
|
391
|
+
const target = resolveFromKit(spec, file);
|
|
392
|
+
if (target && namesOf(target).has(name)) visitKit(target, new Set([name]));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function visitLocal(file) {
|
|
398
|
+
if (visitedLocal.has(file)) return;
|
|
399
|
+
visitedLocal.add(file);
|
|
400
|
+
if (!inRoots(file)) localFiles.add(file);
|
|
401
|
+
const mod = parse(file);
|
|
402
|
+
if (!mod) return;
|
|
403
|
+
for (const imp of mod.imports) follow(imp.spec, imp.names, file);
|
|
404
|
+
for (const [, r] of mod.reexports) if (r.spec) follow(r.spec, single(r.imported), file);
|
|
405
|
+
for (const spec of mod.stars) follow(spec, ALL, file);
|
|
406
|
+
for (const spec of mod.dynamic) follow(spec, ALL, file);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
/** Walk one of the app's own files. */
|
|
411
|
+
addAppFile: visitLocal,
|
|
412
|
+
result: () => ({ kitFiles: [...kitFiles].sort(), barrels: [...barrels].sort(), localFiles: [...localFiles].sort() }),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** The app's code files under a folder: no tests, no declaration files, nothing installed or built. */
|
|
417
|
+
function codeFilesUnder(tree, dir) {
|
|
418
|
+
const files = [];
|
|
419
|
+
tree.getDir(dir).visit((path) => {
|
|
420
|
+
if (/\/(?:node_modules|\.angular|\.git|dist)\//.test(path)) return;
|
|
421
|
+
if (CODE_FILE.test(path) && !NOT_APP_CODE.test(path)) files.push(path);
|
|
422
|
+
});
|
|
423
|
+
return files.sort();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
module.exports = { loadTypeScript, createWalker, codeFilesUnder, parseModule, packageEntry, packageName, ALL };
|