@travetto/manifest 3.1.0-rc.0 → 3.1.0-rc.1
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 +4 -1
- package/bin/context.js +8 -3
- package/package.json +1 -1
- package/src/package.ts +4 -59
- package/src/root-index.ts +16 -23
- package/src/types.ts +3 -3
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ During the compilation process, it is helpful to know how the output content dif
|
|
|
36
36
|
## Class and Function Metadata
|
|
37
37
|
For the framework to work properly, metadata needs to be collected about files, classes and functions to uniquely identify them, with support for detecting changes during live reloads. To achieve this, every `class` is decorated with an additional field of `Ⲑid`. `Ⲑid` represents a computed id that is tied to the file/class combination.
|
|
38
38
|
|
|
39
|
-
`Ⲑid` is used heavily throughout the framework for determining which classes are owned by the framework, and being able to lookup the needed data from the [RootIndex](https://github.com/travetto/travetto/tree/main/module/manifest/src/root-index.ts#
|
|
39
|
+
`Ⲑid` is used heavily throughout the framework for determining which classes are owned by the framework, and being able to lookup the needed data from the [RootIndex](https://github.com/travetto/travetto/tree/main/module/manifest/src/root-index.ts#L11) using the `getFunctionMetadata` method.
|
|
40
40
|
|
|
41
41
|
**Code: Test Class**
|
|
42
42
|
```typescript
|
|
@@ -153,6 +153,9 @@ export function watchFolders(
|
|
|
153
153
|
"toolFolder": ".trv_build",
|
|
154
154
|
"compilerFolder": ".trv_compiler",
|
|
155
155
|
"packageManager": "npm",
|
|
156
|
+
"version": "3.1.0-rc.0",
|
|
157
|
+
"description": "Support for project indexing, manifesting, along with file watching",
|
|
158
|
+
"frameworkVersion": "3.1.0-rc.0",
|
|
156
159
|
"modules": {
|
|
157
160
|
"@travetto/manifest": {
|
|
158
161
|
"main": true,
|
package/bin/context.js
CHANGED
|
@@ -81,6 +81,7 @@ async function $getWorkspaceRoot(base = process.cwd()) {
|
|
|
81
81
|
*/
|
|
82
82
|
export async function getManifestContext(folder) {
|
|
83
83
|
const workspacePath = path.resolve(await $getWorkspaceRoot(folder));
|
|
84
|
+
const req = createRequire(`${workspacePath}/node_modules`);
|
|
84
85
|
|
|
85
86
|
// If manifest specified via env var, and is a package name
|
|
86
87
|
if (!folder && process.env.TRV_MODULE) {
|
|
@@ -88,7 +89,6 @@ export async function getManifestContext(folder) {
|
|
|
88
89
|
if (/[.](t|j)s$/.test(process.env.TRV_MODULE)) {
|
|
89
90
|
process.env.TRV_MODULE = await $getModuleFromFile(process.env.TRV_MODULE) ?? process.env.TRV_MODULE;
|
|
90
91
|
}
|
|
91
|
-
const req = createRequire(`${workspacePath}/node_modules`);
|
|
92
92
|
try {
|
|
93
93
|
folder = path.dirname(req.resolve(`${process.env.TRV_MODULE}/package.json`));
|
|
94
94
|
} catch {
|
|
@@ -102,7 +102,7 @@ export async function getManifestContext(folder) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
const mainPath = await $getModuleRoot(path.resolve(folder ?? '.'));
|
|
105
|
-
const { name: mainModule, workspaces, travetto } = (await $getPkg(mainPath));
|
|
105
|
+
const { name: mainModule, workspaces, travetto, version, description } = (await $getPkg(mainPath));
|
|
106
106
|
const monoRepo = workspacePath !== mainPath || !!workspaces;
|
|
107
107
|
const outputFolder = travetto?.outputFolder ?? '.trv_output';
|
|
108
108
|
|
|
@@ -111,6 +111,8 @@ export async function getManifestContext(folder) {
|
|
|
111
111
|
/** @type {'yarn'|'npm'} */
|
|
112
112
|
const packageManager = await fs.stat(path.resolve(workspacePath, 'yarn.lock')).then(() => 'yarn', () => 'npm');
|
|
113
113
|
|
|
114
|
+
const { version: frameworkVersion } = JSON.parse(await fs.readFile(req.resolve('@travetto/manifest/package.json'), 'utf8'));
|
|
115
|
+
|
|
114
116
|
const res = {
|
|
115
117
|
moduleType,
|
|
116
118
|
mainModule: mainModule ?? 'untitled', // When root package.json is missing a name
|
|
@@ -120,7 +122,10 @@ export async function getManifestContext(folder) {
|
|
|
120
122
|
outputFolder,
|
|
121
123
|
toolFolder: '.trv_build',
|
|
122
124
|
compilerFolder: '.trv_compiler',
|
|
123
|
-
packageManager
|
|
125
|
+
packageManager,
|
|
126
|
+
version,
|
|
127
|
+
description,
|
|
128
|
+
frameworkVersion
|
|
124
129
|
};
|
|
125
130
|
return res;
|
|
126
131
|
}
|
package/package.json
CHANGED
package/src/package.ts
CHANGED
|
@@ -3,13 +3,15 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
|
|
6
|
-
import { ManifestContext, Package,
|
|
6
|
+
import { ManifestContext, Package, PackageRel, PackageVisitor, PackageVisitReq, PackageWorkspaceEntry } from './types';
|
|
7
7
|
import { path } from './path';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Utilities for querying, traversing and reading package.json files.
|
|
11
|
+
*/
|
|
9
12
|
export class PackageUtil {
|
|
10
13
|
|
|
11
14
|
static #req = createRequire(path.resolve('node_modules'));
|
|
12
|
-
static #framework: Package;
|
|
13
15
|
static #cache: Record<string, Package> = {};
|
|
14
16
|
static #workspaces: Record<string, PackageWorkspaceEntry[]> = {};
|
|
15
17
|
|
|
@@ -114,18 +116,6 @@ export class PackageUtil {
|
|
|
114
116
|
return this.readPackage(this.resolvePackagePath(moduleName));
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
/**
|
|
118
|
-
* Write package
|
|
119
|
-
*/
|
|
120
|
-
static async writePackageIfChanged(modulePath: string, pkg: Package): Promise<void> {
|
|
121
|
-
const final = JSON.stringify(pkg, null, 2);
|
|
122
|
-
const target = path.resolve(modulePath, 'package.json');
|
|
123
|
-
const current = (await fs.readFile(target, 'utf8').catch(() => '')).trim();
|
|
124
|
-
if (final !== current) {
|
|
125
|
-
await fs.writeFile(target, `${final}\n`, 'utf8');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
119
|
/**
|
|
130
120
|
* Visit packages with ability to track duplicates
|
|
131
121
|
*/
|
|
@@ -164,21 +154,6 @@ export class PackageUtil {
|
|
|
164
154
|
return (await visitor.complete?.(out)) ?? out;
|
|
165
155
|
}
|
|
166
156
|
|
|
167
|
-
/**
|
|
168
|
-
* Get version of manifest package
|
|
169
|
-
*/
|
|
170
|
-
static getFrameworkVersion(): string {
|
|
171
|
-
return (this.#framework ??= this.importPackage('@travetto/manifest')).version;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Produce simple digest of
|
|
176
|
-
*/
|
|
177
|
-
static digest(pkg: Package): PackageDigest {
|
|
178
|
-
const { main, name, author, license, version } = pkg;
|
|
179
|
-
return { name, main, author, license, version, framework: this.getFrameworkVersion() };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
157
|
/**
|
|
183
158
|
* Find workspace values from rootPath
|
|
184
159
|
*/
|
|
@@ -210,34 +185,4 @@ export class PackageUtil {
|
|
|
210
185
|
}
|
|
211
186
|
return this.#workspaces[rootPath];
|
|
212
187
|
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Sync versions across a series of folders
|
|
216
|
-
*/
|
|
217
|
-
static async syncVersions(folders: string[], versionMapping: Record<string, string> = {}): Promise<void> {
|
|
218
|
-
const packages = folders.map(folder => {
|
|
219
|
-
const pkg = this.readPackage(folder, true);
|
|
220
|
-
versionMapping[pkg.name] = `^${pkg.version}`;
|
|
221
|
-
return { folder, pkg };
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
for (const { pkg } of packages) {
|
|
225
|
-
for (const group of [
|
|
226
|
-
pkg.dependencies ?? {},
|
|
227
|
-
pkg.devDependencies ?? {},
|
|
228
|
-
pkg.optionalDependencies ?? {},
|
|
229
|
-
pkg.peerDependencies ?? {}
|
|
230
|
-
]) {
|
|
231
|
-
for (const [mod, ver] of Object.entries(versionMapping)) {
|
|
232
|
-
if (mod in group && !/^[*]|(file:.*)$/.test(group[mod])) {
|
|
233
|
-
group[mod] = ver;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
for (const { folder, pkg } of packages) {
|
|
240
|
-
await this.writePackageIfChanged(folder, pkg);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
188
|
}
|
package/src/root-index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { path } from './path';
|
|
2
2
|
import { IndexedModule, ManifestIndex } from './manifest-index';
|
|
3
|
-
import { FunctionMetadata,
|
|
4
|
-
import { PackageUtil } from './package';
|
|
3
|
+
import { FunctionMetadata, ManifestContext, Package } from './types';
|
|
5
4
|
|
|
6
5
|
const METADATA = Symbol.for('@travetto/manifest:metadata');
|
|
7
6
|
type Metadated = { [METADATA]: FunctionMetadata };
|
|
@@ -11,7 +10,6 @@ type Metadated = { [METADATA]: FunctionMetadata };
|
|
|
11
10
|
*/
|
|
12
11
|
class $RootIndex extends ManifestIndex {
|
|
13
12
|
|
|
14
|
-
#config: Package | undefined;
|
|
15
13
|
#metadata = new Map<string, FunctionMetadata>();
|
|
16
14
|
|
|
17
15
|
/**
|
|
@@ -20,7 +18,6 @@ class $RootIndex extends ManifestIndex {
|
|
|
20
18
|
*/
|
|
21
19
|
reinitForModule(module: string): void {
|
|
22
20
|
this.init(`${this.outputRoot}/node_modules/${module}`);
|
|
23
|
-
this.#config = undefined;
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
/**
|
|
@@ -49,32 +46,28 @@ class $RootIndex extends ManifestIndex {
|
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
/**
|
|
52
|
-
* Get main module
|
|
49
|
+
* Get main module name
|
|
53
50
|
*/
|
|
54
|
-
get
|
|
55
|
-
return this.
|
|
51
|
+
get mainModuleName(): string {
|
|
52
|
+
return this.manifest.mainModule;
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
/**
|
|
59
|
-
* Get main
|
|
56
|
+
* Get main module for manifest
|
|
60
57
|
*/
|
|
61
|
-
get
|
|
62
|
-
|
|
63
|
-
const { outputPath } = this.getModule(this.manifest.mainModule)!;
|
|
64
|
-
this.#config = {
|
|
65
|
-
...{
|
|
66
|
-
name: 'untitled',
|
|
67
|
-
description: 'A Travetto application',
|
|
68
|
-
version: '0.0.0',
|
|
69
|
-
},
|
|
70
|
-
...PackageUtil.readPackage(outputPath)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return this.#config;
|
|
58
|
+
get mainModule(): IndexedModule {
|
|
59
|
+
return this.getModule(this.mainModuleName)!;
|
|
74
60
|
}
|
|
75
61
|
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Digest manifest
|
|
64
|
+
*/
|
|
65
|
+
manifestDigest(): Pick<ManifestContext, 'mainModule' | 'frameworkVersion' | 'version'> {
|
|
66
|
+
return {
|
|
67
|
+
mainModule: this.manifest.mainModule,
|
|
68
|
+
frameworkVersion: this.manifest.frameworkVersion,
|
|
69
|
+
version: this.manifest.version,
|
|
70
|
+
};
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
/**
|
package/src/types.ts
CHANGED
|
@@ -35,6 +35,9 @@ export type ManifestContext = {
|
|
|
35
35
|
monoRepo?: boolean;
|
|
36
36
|
moduleType: 'module' | 'commonjs';
|
|
37
37
|
packageManager: 'yarn' | 'npm';
|
|
38
|
+
frameworkVersion: string;
|
|
39
|
+
description: string;
|
|
40
|
+
version: string;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export type ManifestRoot = ManifestContext & {
|
|
@@ -86,9 +89,6 @@ export type Package = {
|
|
|
86
89
|
publishConfig?: { access?: 'restricted' | 'public' };
|
|
87
90
|
};
|
|
88
91
|
|
|
89
|
-
export type PackageDigestField = 'name' | 'main' | 'author' | 'license' | 'version';
|
|
90
|
-
export type PackageDigest = Pick<Package, PackageDigestField> & { framework: string };
|
|
91
|
-
|
|
92
92
|
type OrProm<T> = T | Promise<T>;
|
|
93
93
|
|
|
94
94
|
export type PackageVisitReq<T> = { pkg: Package, rel: PackageRel, sourcePath: string, parent?: T };
|