@travetto/manifest 3.4.0-rc.0 → 3.4.0-rc.3
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 +5 -4
- package/package.json +2 -2
- package/src/dependencies.ts +34 -35
- package/src/manifest-index.ts +32 -59
- package/src/module.ts +8 -7
- package/src/package.ts +19 -21
- package/src/root-index.ts +0 -9
- package/src/types.ts +10 -8
- package/src/util.ts +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ By default, all paths within the framework are assumed to be in a POSIX style, a
|
|
|
99
99
|
"outputFolder": ".trv/output",
|
|
100
100
|
"toolFolder": ".trv/tool",
|
|
101
101
|
"compilerFolder": ".trv/compiler",
|
|
102
|
-
"compilerUrl": "http://127.0.0.1:
|
|
102
|
+
"compilerUrl": "http://127.0.0.1:26803",
|
|
103
103
|
"frameworkVersion": "x.x.x",
|
|
104
104
|
"mainModule": "@travetto/manifest",
|
|
105
105
|
"mainFolder": "module/manifest",
|
|
@@ -114,6 +114,9 @@ By default, all paths within the framework are assumed to be in a POSIX style, a
|
|
|
114
114
|
"internal": false,
|
|
115
115
|
"sourceFolder": "module/manifest",
|
|
116
116
|
"outputFolder": "node_modules/@travetto/manifest",
|
|
117
|
+
"roles": [ "std" ],
|
|
118
|
+
"parents": [],
|
|
119
|
+
"prod": true,
|
|
117
120
|
"files": {
|
|
118
121
|
"$root": [
|
|
119
122
|
[ "DOC.html", "unknown", 1868155200000 ],
|
|
@@ -158,9 +161,7 @@ By default, all paths within the framework are assumed to be in a POSIX style, a
|
|
|
158
161
|
[ "bin/context.d.ts", "typings", 1868155200000 ],
|
|
159
162
|
[ "bin/context.js", "js", 1868155200000 ]
|
|
160
163
|
]
|
|
161
|
-
}
|
|
162
|
-
"profiles": [ "std" ],
|
|
163
|
-
"parents": []
|
|
164
|
+
}
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/manifest",
|
|
3
|
-
"version": "3.4.0-rc.
|
|
3
|
+
"version": "3.4.0-rc.3",
|
|
4
4
|
"description": "Support for project indexing, manifesting, along with file watching",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"path",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"main": "__index__.ts",
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"url": "https://github.com/travetto/travetto.git",
|
package/src/dependencies.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PackageUtil } from './package';
|
|
2
2
|
import { path } from './path';
|
|
3
|
-
import { ManifestContext,
|
|
3
|
+
import { ManifestContext, ManifestModuleRole, PackageVisitor, PackageVisitReq, Package } from './types';
|
|
4
4
|
|
|
5
5
|
export type ModuleDep = {
|
|
6
|
+
pkg: Package;
|
|
6
7
|
version: string;
|
|
7
8
|
name: string;
|
|
8
9
|
main?: boolean;
|
|
@@ -10,9 +11,11 @@ export type ModuleDep = {
|
|
|
10
11
|
local?: boolean;
|
|
11
12
|
internal?: boolean;
|
|
12
13
|
sourcePath: string;
|
|
13
|
-
childSet:
|
|
14
|
+
childSet: Set<string>;
|
|
14
15
|
parentSet: Set<string>;
|
|
15
|
-
|
|
16
|
+
roleSet: Set<ManifestModuleRole>;
|
|
17
|
+
prod: boolean;
|
|
18
|
+
topLevel?: boolean;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -60,19 +63,13 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
60
63
|
...workspaceModules.map(x => x.name)
|
|
61
64
|
]);
|
|
62
65
|
|
|
63
|
-
const globals = [
|
|
64
|
-
|
|
65
|
-
...(pkg.travetto?.globalModules ?? [])
|
|
66
|
-
]
|
|
67
|
-
.map(f => PackageUtil.resolvePackagePath(f));
|
|
66
|
+
const globals = (workspacePkg.travetto?.globalModules ?? [])
|
|
67
|
+
.map(name => PackageUtil.packageReq<ModuleDep>(PackageUtil.resolvePackagePath(name), name in (workspacePkg.dependencies ?? {}), true));
|
|
68
68
|
|
|
69
69
|
const workspaceModuleDeps = workspaceModules
|
|
70
|
-
.map(entry => path.resolve(req.sourcePath, entry.sourcePath));
|
|
70
|
+
.map(entry => PackageUtil.packageReq<ModuleDep>(path.resolve(req.sourcePath, entry.sourcePath), false, true));
|
|
71
71
|
|
|
72
|
-
return [
|
|
73
|
-
...globals,
|
|
74
|
-
...workspaceModuleDeps
|
|
75
|
-
].map(s => PackageUtil.packageReq(s, 'global'));
|
|
72
|
+
return [...globals, ...workspaceModuleDeps];
|
|
76
73
|
}
|
|
77
74
|
|
|
78
75
|
/**
|
|
@@ -80,8 +77,7 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
80
77
|
*/
|
|
81
78
|
valid(req: PackageVisitReq<ModuleDep>): boolean {
|
|
82
79
|
return req.sourcePath === this.#mainSourcePath || (
|
|
83
|
-
req.
|
|
84
|
-
(!!req.pkg.travetto || req.pkg.private === true || !req.sourcePath.includes('node_modules') || req.rel === 'global')
|
|
80
|
+
(!!req.pkg.travetto || req.pkg.private === true || !req.sourcePath.includes('node_modules'))
|
|
85
81
|
);
|
|
86
82
|
}
|
|
87
83
|
|
|
@@ -89,18 +85,16 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
89
85
|
* Create dependency from request
|
|
90
86
|
*/
|
|
91
87
|
create(req: PackageVisitReq<ModuleDep>): ModuleDep {
|
|
92
|
-
const { pkg
|
|
93
|
-
const
|
|
94
|
-
...profiles ?? []
|
|
95
|
-
]);
|
|
88
|
+
const { pkg, sourcePath } = req;
|
|
89
|
+
const { name, version } = pkg;
|
|
96
90
|
const main = name === this.ctx.mainModule;
|
|
97
91
|
const mainSource = main || this.#mainPatterns.some(x => x.test(name));
|
|
98
92
|
const internal = pkg.private === true;
|
|
99
93
|
const local = internal || mainSource || !sourcePath.includes('node_modules');
|
|
100
94
|
|
|
101
95
|
const dep = {
|
|
102
|
-
name, version, sourcePath, main, mainSource, local, internal,
|
|
103
|
-
parentSet: new Set([]), childSet: new
|
|
96
|
+
name, version, sourcePath, main, mainSource, local, internal, pkg: req.pkg,
|
|
97
|
+
parentSet: new Set([]), childSet: new Set([]), roleSet: new Set([]), prod: req.prod, topLevel: req.topLevel
|
|
104
98
|
};
|
|
105
99
|
|
|
106
100
|
return dep;
|
|
@@ -113,28 +107,30 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
113
107
|
const { parent } = req;
|
|
114
108
|
if (parent && dep.name !== this.ctx.mainModule) {
|
|
115
109
|
dep.parentSet.add(parent.name);
|
|
116
|
-
|
|
117
|
-
parent.childSet.set(dep.name, set);
|
|
118
|
-
set.add(req.rel);
|
|
110
|
+
parent.childSet.add(dep.name);
|
|
119
111
|
}
|
|
120
112
|
}
|
|
121
113
|
|
|
122
114
|
/**
|
|
123
|
-
* Propagate
|
|
115
|
+
* Propagate prod, role information through graph
|
|
124
116
|
*/
|
|
125
117
|
complete(deps: Set<ModuleDep>): Set<ModuleDep> {
|
|
126
|
-
const mapping = new Map<string, { parent: Set<string>, child:
|
|
118
|
+
const mapping = new Map<string, { parent: Set<string>, child: Set<string>, el: ModuleDep }>();
|
|
127
119
|
for (const el of deps) {
|
|
128
|
-
mapping.set(el.name, { parent: new Set(el.parentSet), child: new
|
|
120
|
+
mapping.set(el.name, { parent: new Set(el.parentSet), child: new Set(el.childSet), el });
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
const main = mapping.get(this.ctx.mainModule)!;
|
|
132
124
|
|
|
133
125
|
// Visit all direct dependencies and mark
|
|
134
|
-
for (const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
for (const { el } of mapping.values()) {
|
|
127
|
+
if (el.topLevel) {
|
|
128
|
+
el.roleSet = new Set(el.pkg.travetto?.roles ?? []);
|
|
129
|
+
if (!el.roleSet.size) {
|
|
130
|
+
el.roleSet.add('std');
|
|
131
|
+
}
|
|
132
|
+
} else if (!main.child.has(el.name)) { // Not a direct descendent
|
|
133
|
+
el.prod = false;
|
|
138
134
|
}
|
|
139
135
|
}
|
|
140
136
|
|
|
@@ -148,9 +144,10 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
148
144
|
for (const c of child.keys()) {
|
|
149
145
|
const { el: cDep, parent } = mapping.get(c)!;
|
|
150
146
|
parent.delete(el.name); // Remove from child
|
|
151
|
-
for (const
|
|
152
|
-
cDep.
|
|
147
|
+
for (const role of el.roleSet) {
|
|
148
|
+
cDep.roleSet.add(role);
|
|
153
149
|
}
|
|
150
|
+
cDep.prod ||= el.prod; // Allow prod to trickle down as needed
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
153
|
// Remove from mapping
|
|
@@ -159,8 +156,10 @@ export class ModuleDependencyVisitor implements PackageVisitor<ModuleDep> {
|
|
|
159
156
|
}
|
|
160
157
|
}
|
|
161
158
|
|
|
162
|
-
// Color
|
|
163
|
-
main.el.
|
|
159
|
+
// Color parent as final step
|
|
160
|
+
main.el.prod = true;
|
|
161
|
+
main.el.roleSet.add('std');
|
|
162
|
+
|
|
164
163
|
return deps;
|
|
165
164
|
}
|
|
166
165
|
}
|
package/src/manifest-index.ts
CHANGED
|
@@ -3,18 +3,16 @@ import { path } from './path';
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
ManifestModule, ManifestModuleCore, ManifestModuleFile,
|
|
6
|
-
ManifestModuleFileType, ManifestModuleFolderType,
|
|
6
|
+
ManifestModuleFileType, ManifestModuleFolderType, ManifestModuleRole, ManifestRoot
|
|
7
7
|
} from './types';
|
|
8
8
|
|
|
9
9
|
import { ManifestUtil } from './util';
|
|
10
10
|
|
|
11
|
-
type ScanTest = ((full: string) => boolean) | { test: (full: string) => boolean };
|
|
12
11
|
export type FindConfig = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
checkProfile?: boolean;
|
|
12
|
+
folder?: (folder: ManifestModuleFolderType) => boolean;
|
|
13
|
+
module?: (module: IndexedModule) => boolean;
|
|
14
|
+
file?: (file: IndexedFile) => boolean;
|
|
15
|
+
sourceOnly?: boolean;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
export type IndexedFile = {
|
|
@@ -24,7 +22,7 @@ export type IndexedFile = {
|
|
|
24
22
|
sourceFile: string;
|
|
25
23
|
outputFile: string;
|
|
26
24
|
relativeFile: string;
|
|
27
|
-
|
|
25
|
+
role: ManifestModuleRole;
|
|
28
26
|
type: ManifestModuleFileType;
|
|
29
27
|
};
|
|
30
28
|
|
|
@@ -34,6 +32,12 @@ export type IndexedModule = ManifestModuleCore & {
|
|
|
34
32
|
files: Record<ManifestModuleFolderType, IndexedFile[]>;
|
|
35
33
|
};
|
|
36
34
|
|
|
35
|
+
const TypedObject: {
|
|
36
|
+
keys<T = unknown, K extends keyof T = keyof T>(o: T): K[];
|
|
37
|
+
fromEntries<K extends string | symbol, V>(items: ([K, V] | readonly [K, V])[]): Record<K, V>;
|
|
38
|
+
entries<K extends Record<symbol | string, unknown>>(record: K): [keyof K, K[keyof K]][];
|
|
39
|
+
} & ObjectConstructor = Object;
|
|
40
|
+
|
|
37
41
|
/**
|
|
38
42
|
* Manifest index
|
|
39
43
|
*/
|
|
@@ -78,7 +82,7 @@ export class ManifestIndex {
|
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
#moduleFiles(m: ManifestModule, files: ManifestModuleFile[]): IndexedFile[] {
|
|
81
|
-
return files.map(([f, type, ts,
|
|
85
|
+
return files.map(([f, type, ts, role = 'std']) => {
|
|
82
86
|
const isSource = type === 'ts' || type === 'js';
|
|
83
87
|
const sourceFile = path.resolve(this.#manifest.workspacePath, m.sourceFolder, f);
|
|
84
88
|
const js = isSource ? ManifestModuleUtil.sourceToOutputExt(f) : f;
|
|
@@ -89,7 +93,7 @@ export class ManifestIndex {
|
|
|
89
93
|
id = ManifestModuleUtil.sourceToBlankExt(id);
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
return { id, type, sourceFile, outputFile, import: modImport,
|
|
96
|
+
return { id, type, sourceFile, outputFile, import: modImport, role, relativeFile: f, module: m.name };
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -143,58 +147,27 @@ export class ManifestIndex {
|
|
|
143
147
|
|
|
144
148
|
/**
|
|
145
149
|
* Find files from the index
|
|
146
|
-
* @param
|
|
147
|
-
* @param filter The filter to determine if this is a valid support file
|
|
150
|
+
* @param config The configuration for controlling the find process
|
|
148
151
|
*/
|
|
149
152
|
find(config: FindConfig): IndexedFile[] {
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (checkProfile) {
|
|
168
|
-
searchSpace = searchSpace.filter(fi => activeProfiles.has(fi.profile));
|
|
153
|
+
const searchSpace: IndexedFile[] = [];
|
|
154
|
+
for (const m of this.#modules) {
|
|
155
|
+
if (config.module?.(m) ?? true) {
|
|
156
|
+
for (const [folder, files] of TypedObject.entries(m.files)) {
|
|
157
|
+
if (config.folder?.(folder) ?? true) {
|
|
158
|
+
for (const file of files) {
|
|
159
|
+
if (
|
|
160
|
+
(config.file?.(file) ?? true) &&
|
|
161
|
+
(config.sourceOnly === false || file.type === 'ts')
|
|
162
|
+
) {
|
|
163
|
+
searchSpace.push(file);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
return searchSpace
|
|
172
|
-
.filter(({ type }) => type === 'ts')
|
|
173
|
-
.filter(({ sourceFile: source }) => filter?.(source) ?? true);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Find files from the index
|
|
178
|
-
* @param filter The filter to determine if this is a valid support file
|
|
179
|
-
*/
|
|
180
|
-
findSupport(config: Omit<FindConfig, 'folder'>): IndexedFile[] {
|
|
181
|
-
return this.find({ ...config, folders: ['support'] });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Find files from the index
|
|
186
|
-
* @param filter The filter to determine if this is a valid support file
|
|
187
|
-
*/
|
|
188
|
-
findSrc(config: Omit<FindConfig, 'folder'> = {}): IndexedFile[] {
|
|
189
|
-
return this.find({ ...config, includeIndex: true, folders: ['src'] });
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Find files from the index
|
|
194
|
-
* @param filter The filter to determine if this is a valid support file
|
|
195
|
-
*/
|
|
196
|
-
findTest(config: Omit<FindConfig, 'folder'>): IndexedFile[] {
|
|
197
|
-
return this.find({ ...config, folders: ['test'] });
|
|
170
|
+
return searchSpace;
|
|
198
171
|
}
|
|
199
172
|
|
|
200
173
|
/**
|
package/src/module.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { path } from './path';
|
|
|
4
4
|
import {
|
|
5
5
|
ManifestContext,
|
|
6
6
|
ManifestModule, ManifestModuleFile, ManifestModuleFileType,
|
|
7
|
-
ManifestModuleFolderType,
|
|
7
|
+
ManifestModuleFolderType,
|
|
8
|
+
ManifestModuleRole
|
|
8
9
|
} from './types';
|
|
9
10
|
import { ModuleDep, ModuleDependencyVisitor } from './dependencies';
|
|
10
11
|
import { PackageUtil } from './package';
|
|
@@ -114,7 +115,7 @@ export class ManifestModuleUtil {
|
|
|
114
115
|
/**
|
|
115
116
|
* Get file type for a file name
|
|
116
117
|
*/
|
|
117
|
-
static
|
|
118
|
+
static getFileRole(moduleFile: string): ManifestModuleRole | undefined {
|
|
118
119
|
if (moduleFile.startsWith('support/transform')) {
|
|
119
120
|
return 'compile';
|
|
120
121
|
} else if (moduleFile.startsWith('support/test/') || moduleFile.startsWith('test/')) {
|
|
@@ -167,15 +168,15 @@ export class ManifestModuleUtil {
|
|
|
167
168
|
*/
|
|
168
169
|
static async transformFile(moduleFile: string, full: string): Promise<ManifestModuleFile> {
|
|
169
170
|
const res: ManifestModuleFile = [moduleFile, this.getFileType(moduleFile), this.#getNewest(await fs.stat(full))];
|
|
170
|
-
const
|
|
171
|
-
return
|
|
171
|
+
const role = this.getFileRole(moduleFile);
|
|
172
|
+
return role ? [...res, role] : res;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
/**
|
|
175
176
|
* Visit a module and describe files, and metadata
|
|
176
177
|
*/
|
|
177
178
|
static async describeModule(ctx: ManifestContext, dep: ModuleDep): Promise<ManifestModule> {
|
|
178
|
-
const { main, mainSource, local, name, version, sourcePath,
|
|
179
|
+
const { main, mainSource, local, name, version, sourcePath, roleSet, prod, parentSet, internal } = dep;
|
|
179
180
|
|
|
180
181
|
const files: ManifestModule['files'] = {};
|
|
181
182
|
|
|
@@ -192,12 +193,12 @@ export class ManifestModuleUtil {
|
|
|
192
193
|
files.$root = files.$root?.filter(([file, type]) => type !== 'ts');
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
const
|
|
196
|
+
const roles = [...roleSet ?? []].sort();
|
|
196
197
|
const parents = [...parentSet].sort();
|
|
197
198
|
const outputFolder = `node_modules/${name}`;
|
|
198
199
|
const sourceFolder = sourcePath === ctx.workspacePath ? '' : sourcePath.replace(`${ctx.workspacePath}/`, '');
|
|
199
200
|
|
|
200
|
-
const res = { main, name, version, local, internal, sourceFolder, outputFolder,
|
|
201
|
+
const res = { main, name, version, local, internal, sourceFolder, outputFolder, roles, parents, prod, files };
|
|
201
202
|
return res;
|
|
202
203
|
}
|
|
203
204
|
|
package/src/package.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
3
|
|
|
4
|
-
import { ManifestContext, Package,
|
|
4
|
+
import { ManifestContext, Package, PackageVisitor, PackageVisitReq, PackageWorkspaceEntry } from './types';
|
|
5
5
|
import { path } from './path';
|
|
6
6
|
import { ManifestFileUtil } from './file';
|
|
7
7
|
|
|
@@ -59,33 +59,23 @@ export class PackageUtil {
|
|
|
59
59
|
/**
|
|
60
60
|
* Build a package visit req
|
|
61
61
|
*/
|
|
62
|
-
static packageReq<T>(sourcePath: string,
|
|
63
|
-
return { pkg: this.readPackage(sourcePath), sourcePath,
|
|
62
|
+
static packageReq<T>(sourcePath: string, prod: boolean, topLevel?: boolean): PackageVisitReq<T> {
|
|
63
|
+
return { pkg: this.readPackage(sourcePath), sourcePath, prod, topLevel };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Extract all dependencies from a package
|
|
68
68
|
*/
|
|
69
|
-
static getAllDependencies<T = unknown>(modulePath: string,
|
|
69
|
+
static getAllDependencies<T = unknown>(modulePath: string, local: boolean): PackageVisitReq<T>[] {
|
|
70
70
|
const pkg = this.readPackage(modulePath);
|
|
71
71
|
const children: Record<string, PackageVisitReq<T>> = {};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
[pkg.
|
|
75
|
-
[pkg.peerDependencies, 'peer'],
|
|
76
|
-
[pkg.optionalDependencies, 'opt'],
|
|
77
|
-
...(local ? [[pkg.devDependencies, 'dev'] as const] : []),
|
|
72
|
+
for (const [deps, prod] of [
|
|
73
|
+
[pkg.dependencies, true],
|
|
74
|
+
...(local ? [[pkg.devDependencies, false] as const] : []),
|
|
78
75
|
] as const) {
|
|
79
76
|
for (const [name, version] of Object.entries(deps ?? {})) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
children[`${name}#${version}`] = this.packageReq<T>(depPath, rel);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
if (rel === 'opt' || (rel === 'peer' && !!pkg.peerDependenciesMeta?.[name].optional)) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
throw err;
|
|
88
|
-
}
|
|
77
|
+
const depPath = this.resolveVersionPath(modulePath, version) ?? this.resolvePackagePath(name);
|
|
78
|
+
children[`${name}#${version}`] = this.packageReq<T>(depPath, prod, false);
|
|
89
79
|
}
|
|
90
80
|
}
|
|
91
81
|
return Object.values(children).sort((a, b) => a.pkg.name.localeCompare(b.pkg.name));
|
|
@@ -123,7 +113,7 @@ export class PackageUtil {
|
|
|
123
113
|
): Promise<Set<T>> {
|
|
124
114
|
|
|
125
115
|
const root = typeof rootOrPath === 'string' ?
|
|
126
|
-
this.packageReq<T>(rootOrPath,
|
|
116
|
+
this.packageReq<T>(rootOrPath, false, true) :
|
|
127
117
|
rootOrPath;
|
|
128
118
|
|
|
129
119
|
const seen = new Map<string, T>();
|
|
@@ -145,7 +135,15 @@ export class PackageUtil {
|
|
|
145
135
|
out.add(dep);
|
|
146
136
|
await visitor.visit?.(req, dep);
|
|
147
137
|
seen.set(key, dep);
|
|
148
|
-
const children = this.getAllDependencies<T>(
|
|
138
|
+
const children = this.getAllDependencies<T>(
|
|
139
|
+
req.sourcePath,
|
|
140
|
+
// We consider a module local if its not in the node_modules
|
|
141
|
+
!req.sourcePath.includes('node_modules') && (
|
|
142
|
+
// And its the root or we are in a monorepo
|
|
143
|
+
root.sourcePath === req.sourcePath ||
|
|
144
|
+
!!root.pkg.workspaces
|
|
145
|
+
)
|
|
146
|
+
);
|
|
149
147
|
queue.push(...children.map(x => ({ ...x, parent: dep })));
|
|
150
148
|
}
|
|
151
149
|
}
|
package/src/root-index.ts
CHANGED
|
@@ -27,15 +27,6 @@ class $RootIndex extends ManifestIndex {
|
|
|
27
27
|
return !!this.manifest.monoRepo && !this.manifest.mainFolder;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* Asynchronously load all source files from manifest
|
|
32
|
-
*/
|
|
33
|
-
async loadSource(): Promise<void> {
|
|
34
|
-
for (const { import: imp } of this.findSrc()) {
|
|
35
|
-
await import(imp);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
30
|
/**
|
|
40
31
|
* Get internal id from file name and optionally, class name
|
|
41
32
|
*/
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type NodeModuleType = 'module' | 'commonjs';
|
|
2
|
+
|
|
1
3
|
export type ManifestModuleFileType = 'typings' | 'ts' | 'js' | 'json' | 'package-json' | 'unknown' | 'fixture' | 'md';
|
|
2
4
|
export type ManifestModuleFolderType =
|
|
3
5
|
'$root' | '$index' | '$package' |
|
|
@@ -5,10 +7,9 @@ export type ManifestModuleFolderType =
|
|
|
5
7
|
'test/fixtures' | 'support/fixtures' | 'support/resources' |
|
|
6
8
|
'$other' | '$transformer';
|
|
7
9
|
|
|
8
|
-
export type
|
|
9
|
-
export type PackageRel = 'dev' | 'prod' | 'peer' | 'opt' | 'root' | 'global';
|
|
10
|
+
export type ManifestModuleRole = 'std' | 'test' | 'doc' | 'compile' | 'build';
|
|
10
11
|
|
|
11
|
-
export type ManifestModuleFile = [string, ManifestModuleFileType, number] | [string, ManifestModuleFileType, number,
|
|
12
|
+
export type ManifestModuleFile = [string, ManifestModuleFileType, number] | [string, ManifestModuleFileType, number, ManifestModuleRole];
|
|
12
13
|
export type ManifestModuleCore = {
|
|
13
14
|
name: string;
|
|
14
15
|
main?: boolean;
|
|
@@ -16,7 +17,8 @@ export type ManifestModuleCore = {
|
|
|
16
17
|
version: string;
|
|
17
18
|
sourceFolder: string;
|
|
18
19
|
outputFolder: string;
|
|
19
|
-
|
|
20
|
+
prod: boolean;
|
|
21
|
+
roles: ManifestModuleRole[];
|
|
20
22
|
parents: string[];
|
|
21
23
|
internal?: boolean;
|
|
22
24
|
};
|
|
@@ -33,7 +35,7 @@ export type ManifestContext = {
|
|
|
33
35
|
toolFolder: string;
|
|
34
36
|
compilerFolder: string;
|
|
35
37
|
monoRepo?: boolean;
|
|
36
|
-
moduleType:
|
|
38
|
+
moduleType: NodeModuleType;
|
|
37
39
|
packageManager: 'yarn' | 'npm';
|
|
38
40
|
frameworkVersion: string;
|
|
39
41
|
description?: string;
|
|
@@ -48,7 +50,7 @@ export type ManifestRoot = ManifestContext & {
|
|
|
48
50
|
|
|
49
51
|
export type Package = {
|
|
50
52
|
name: string;
|
|
51
|
-
type?:
|
|
53
|
+
type?: NodeModuleType;
|
|
52
54
|
version: string;
|
|
53
55
|
description?: string;
|
|
54
56
|
license?: string;
|
|
@@ -76,7 +78,7 @@ export type Package = {
|
|
|
76
78
|
travetto?: {
|
|
77
79
|
isolated?: boolean;
|
|
78
80
|
displayName?: string;
|
|
79
|
-
|
|
81
|
+
roles?: ManifestModuleRole[];
|
|
80
82
|
globalModules?: string[];
|
|
81
83
|
mainSource?: string[];
|
|
82
84
|
docOutput?: string[];
|
|
@@ -95,7 +97,7 @@ export type Package = {
|
|
|
95
97
|
|
|
96
98
|
type OrProm<T> = T | Promise<T>;
|
|
97
99
|
|
|
98
|
-
export type PackageVisitReq<T> = { pkg: Package,
|
|
100
|
+
export type PackageVisitReq<T> = { pkg: Package, prod: boolean, sourcePath: string, parent?: T, topLevel?: boolean };
|
|
99
101
|
export type PackageVisitor<T> = {
|
|
100
102
|
init?(req: PackageVisitReq<T>): OrProm<undefined | void | PackageVisitReq<T>[]>;
|
|
101
103
|
valid?(req: PackageVisitReq<T>): boolean;
|
package/src/util.ts
CHANGED
|
@@ -38,7 +38,7 @@ export class ManifestUtil {
|
|
|
38
38
|
// If in prod mode, only include std modules
|
|
39
39
|
modules: Object.fromEntries(
|
|
40
40
|
Object.values(manifest.modules)
|
|
41
|
-
.filter(x => x.
|
|
41
|
+
.filter(x => x.prod)
|
|
42
42
|
.map(m => [m.name, m])
|
|
43
43
|
),
|
|
44
44
|
// Mark output folder/workspace path as portable
|