@travetto/manifest 4.0.0-rc.2 → 4.0.0-rc.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/bin/context.js +9 -15
- package/package.json +1 -1
- package/src/dependencies.ts +37 -17
- package/src/runtime.ts +7 -0
- package/src/types/package.ts +3 -1
- package/support/transformer.function-metadata.ts +1 -4
package/bin/context.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {import('../src/types/package').Package & { path:string }} Pkg
|
|
5
|
-
* @typedef {Pkg & { mono: boolean, manager: 'yarn'|'npm', resolve: (file:string) => string}} Workspace
|
|
5
|
+
* @typedef {Pkg & { mono: boolean, manager: 'yarn'|'npm', resolve: (file:string) => string, stripRoot: (file:string)=>string}} Workspace
|
|
6
6
|
* @typedef {import('../src/types/context').ManifestContext} ManifestContext
|
|
7
7
|
*/
|
|
8
|
-
import { existsSync,
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
11
|
|
|
@@ -79,6 +79,7 @@ function $resolveWorkspace(base = process.cwd()) {
|
|
|
79
79
|
type: pkg.type,
|
|
80
80
|
manager: existsSync(path.resolve(pkg.path, 'yarn.lock')) ? 'yarn' : 'npm',
|
|
81
81
|
resolve: createRequire(`${pkg.path}/node_modules`).resolve.bind(null),
|
|
82
|
+
stripRoot: (full) => full === pkg.path ? '' : full.replace(`${pkg.path}/`, ''),
|
|
82
83
|
mono: !!pkg.workspaces || (!pkg.travetto?.build?.isolated && !!prevPkg) // Workspaces or nested projects
|
|
83
84
|
};
|
|
84
85
|
}
|
|
@@ -86,18 +87,11 @@ function $resolveWorkspace(base = process.cwd()) {
|
|
|
86
87
|
/**
|
|
87
88
|
* Get Compiler url
|
|
88
89
|
* @param {Workspace} ws
|
|
89
|
-
* @param {string} toolFolder
|
|
90
90
|
*/
|
|
91
|
-
function $getCompilerUrl(ws
|
|
92
|
-
const file = path.resolve(ws.path, toolFolder, 'build.compilerUrl');
|
|
91
|
+
function $getCompilerUrl(ws) {
|
|
93
92
|
// eslint-disable-next-line no-bitwise
|
|
94
|
-
const port = (Math.abs([...
|
|
95
|
-
|
|
96
|
-
if (!existsSync(file)) {
|
|
97
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
98
|
-
writeFileSync(file, out, 'utf8');
|
|
99
|
-
}
|
|
100
|
-
return out;
|
|
93
|
+
const port = (Math.abs([...ws.path].reduce((a, b) => (a * 33) ^ b.charCodeAt(0), 5381)) % 29000) + 20000;
|
|
94
|
+
return `http://localhost:${port}`;
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
/**
|
|
@@ -156,14 +150,14 @@ export function getManifestContext(folder) {
|
|
|
156
150
|
},
|
|
157
151
|
build: {
|
|
158
152
|
compilerFolder: build.compilerFolder ?? COMPILER_FOLDER,
|
|
159
|
-
compilerUrl: build.compilerUrl ?? $getCompilerUrl(workspace
|
|
160
|
-
compilerModuleFolder: path.dirname(workspace.resolve('@travetto/compiler/package.json'))
|
|
153
|
+
compilerUrl: build.compilerUrl ?? $getCompilerUrl(workspace),
|
|
154
|
+
compilerModuleFolder: workspace.stripRoot(path.dirname(workspace.resolve('@travetto/compiler/package.json'))),
|
|
161
155
|
outputFolder: build.outputFolder ?? OUTPUT_FOLDER,
|
|
162
156
|
toolFolder
|
|
163
157
|
},
|
|
164
158
|
main: {
|
|
165
159
|
name: mod.name ?? 'untitled',
|
|
166
|
-
folder:
|
|
160
|
+
folder: workspace.stripRoot(mod.path),
|
|
167
161
|
version: mod.version,
|
|
168
162
|
description: mod.description
|
|
169
163
|
}
|
package/package.json
CHANGED
package/src/dependencies.ts
CHANGED
|
@@ -31,32 +31,52 @@ export class PackageModuleVisitor {
|
|
|
31
31
|
#cache: Record<string, PackageModule> = {};
|
|
32
32
|
#workspaceModules: Map<string, string>;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Get monorepo root includes
|
|
36
|
+
*/
|
|
37
|
+
#getMonoRootIncludes(parent: Req): Req[] {
|
|
38
|
+
if (!(this.ctx.workspace.mono && !this.ctx.main.folder)) { // If not mono root, bail
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return [...this.#workspaceModules.values()]
|
|
43
|
+
.map(loc => this.#create(loc, { main: true, workspace: true, roleRoot: true, parent: parent.value }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Determine default includes
|
|
48
|
+
*/
|
|
49
|
+
#getIncludes(parent: Req): Req[] {
|
|
50
|
+
if (this.ctx.workspace.mono && !this.ctx.main.folder) { // If mono and not at mono root, bail
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const root = PackageUtil.readPackage(this.ctx.workspace.path);
|
|
55
|
+
if (root.travetto?.build?.includes) {
|
|
56
|
+
return Object.entries(root.travetto.build.includes).map(([name, type]) =>
|
|
57
|
+
this.#create(PackageUtil.resolvePackagePath(name), { main: type === 'main', workspace: true, parent: parent.value })
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
return [...this.#workspaceModules.values()]
|
|
61
|
+
.filter((loc) => PackageUtil.readPackage(loc).travetto?.workspaceInclude)
|
|
62
|
+
.map(loc => this.#create(loc, { workspace: true, parent: parent.value }));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
34
66
|
/**
|
|
35
67
|
* Initialize visitor, and provide global dependencies
|
|
36
68
|
*/
|
|
37
69
|
async init(): Promise<Iterable<Req>> {
|
|
38
70
|
const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
|
|
39
|
-
const globals = [mainReq];
|
|
40
71
|
this.#workspaceModules = new Map(
|
|
41
72
|
(await PackageUtil.resolveWorkspaces(this.ctx)).map(x => [x.name, x.path])
|
|
42
73
|
);
|
|
43
74
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else {
|
|
50
|
-
// If we have 'withModules' at workspace root
|
|
51
|
-
const root = PackageUtil.readPackage(this.ctx.workspace.path);
|
|
52
|
-
for (const [name, type] of Object.entries(root.travetto?.build?.withModules ?? {})) {
|
|
53
|
-
globals.push(this.#create(PackageUtil.resolvePackagePath(name),
|
|
54
|
-
{ main: type === 'main', workspace: true, parent: mainReq.value }
|
|
55
|
-
));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return globals;
|
|
75
|
+
return [
|
|
76
|
+
mainReq,
|
|
77
|
+
...this.#getMonoRootIncludes(mainReq),
|
|
78
|
+
...this.#getIncludes(mainReq)
|
|
79
|
+
];
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
/**
|
package/src/runtime.ts
CHANGED
|
@@ -126,6 +126,13 @@ export const RuntimeContext = build({
|
|
|
126
126
|
workspaceRelative(...rel: string[]): string {
|
|
127
127
|
return path.resolve(RuntimeIndex.manifest.workspace.path, ...rel);
|
|
128
128
|
},
|
|
129
|
+
/**
|
|
130
|
+
* Strip off the workspace path from a file
|
|
131
|
+
* @param full A full path
|
|
132
|
+
*/
|
|
133
|
+
stripWorkspacePath(full: string): string {
|
|
134
|
+
return full === RuntimeIndex.manifest.workspace.path ? '' : full.replace(`${RuntimeIndex.manifest.workspace.path}/`, '');
|
|
135
|
+
},
|
|
129
136
|
/**
|
|
130
137
|
* Produce a workspace path for tooling, with '@' being replaced by node_module/name folder
|
|
131
138
|
* @param rel The relative path
|
package/src/types/package.ts
CHANGED
|
@@ -41,9 +41,11 @@ export type Package = {
|
|
|
41
41
|
outputs?: string[];
|
|
42
42
|
};
|
|
43
43
|
defaultEnv?: string;
|
|
44
|
+
workspaceInclude?: boolean;
|
|
44
45
|
build?: Partial<ManifestContext['build']> & {
|
|
45
46
|
isolated?: boolean;
|
|
46
|
-
|
|
47
|
+
includes?: Record<string, 'main' | true>;
|
|
48
|
+
watchIgnores?: string[];
|
|
47
49
|
};
|
|
48
50
|
};
|
|
49
51
|
workspaces?: string[];
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const MANIFEST_MOD = '@travetto/manifest';
|
|
9
9
|
const MANIFEST_IDX = `${MANIFEST_MOD}/__index__`;
|
|
10
|
-
const ENTRY_POINT = 'support/entry';
|
|
11
10
|
|
|
12
11
|
const RUNTIME_IDX_IMPORT = `${MANIFEST_MOD}/src/runtime`;
|
|
13
12
|
const RUNTIME_IDX_CLS = 'RuntimeIndex';
|
|
@@ -32,9 +31,7 @@ interface MetadataInfo {
|
|
|
32
31
|
export class RegisterTransformer {
|
|
33
32
|
|
|
34
33
|
static #valid({ importName: imp }: TransformerState): boolean {
|
|
35
|
-
return !imp.startsWith(MANIFEST_MOD)
|
|
36
|
-
!imp.includes(ENTRY_POINT) :
|
|
37
|
-
!(/[/](src|support)[/]/.test(imp) || imp === MANIFEST_IDX);
|
|
34
|
+
return !imp.startsWith(MANIFEST_MOD) || !(/[/](src|support)[/]/.test(imp) || imp === MANIFEST_IDX);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
/**
|