@travetto/manifest 7.0.0-rc.1 → 7.0.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 +1 -3
- package/__index__.ts +1 -1
- package/package.json +2 -1
- package/src/context.ts +5 -1
- package/src/delta.ts +6 -6
- package/src/dependencies.ts +1 -1
- package/src/file.ts +1 -8
- package/src/manifest-index.ts +18 -1
- package/src/module.ts +2 -2
- package/src/package.ts +15 -14
- package/src/path.ts +2 -2
- package/src/types/common.ts +3 -2
- package/src/types/context.ts +1 -3
- package/src/types/package.ts +2 -2
- package/src/util.ts +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Once the manifest is created, the application runtime can now read this manifest
|
|
|
43
43
|
* Providing contextual information when provided a filename, import name, etc (e.g. logging, testing output)
|
|
44
44
|
|
|
45
45
|
## Path Normalization
|
|
46
|
-
By default, all paths within the framework are assumed to be in a POSIX style, and all input paths are converted to the POSIX style. This works appropriately within a Unix and a Windows environment. This module offers up [path](https://github.com/travetto/travetto/tree/main/module/manifest/src/path.ts#
|
|
46
|
+
By default, all paths within the framework are assumed to be in a POSIX style, and all input paths are converted to the POSIX style. This works appropriately within a Unix and a Windows environment. This module offers up [path](https://github.com/travetto/travetto/tree/main/module/manifest/src/path.ts#L46) as an equivalent to [Node](https://nodejs.org)'s [path](https://nodejs.org/api/path.html) library. This allows for consistent behavior across all file-interactions.
|
|
47
47
|
|
|
48
48
|
## Anatomy of a Manifest
|
|
49
49
|
|
|
@@ -56,7 +56,6 @@ By default, all paths within the framework are assumed to be in a POSIX style, a
|
|
|
56
56
|
"path": "<generated>",
|
|
57
57
|
"mono": true,
|
|
58
58
|
"manager": "npm",
|
|
59
|
-
"type": "commonjs",
|
|
60
59
|
"defaultEnv": "local"
|
|
61
60
|
},
|
|
62
61
|
"build": {
|
|
@@ -132,7 +131,6 @@ The general context describes the project-space and any important information fo
|
|
|
132
131
|
|
|
133
132
|
The context contains:
|
|
134
133
|
* A generated timestamp
|
|
135
|
-
* Module Type: `commonjs`([CommonJS](https://nodejs.org/api/modules.html)) or `module`([Ecmascript Module](https://nodejs.org/api/esm.html))
|
|
136
134
|
* The main module to execute. (*This primarily pertains to mono-repo support when there are multiple modules in the project*)
|
|
137
135
|
* The root path of the project/workspace
|
|
138
136
|
* Whether or not the project is a mono-repo. (*This is determined by using the 'workspaces' field in your [Package JSON](https://docs.npmjs.com/cli/v9/configuring-npm/package-json)*)
|
package/__index__.ts
CHANGED
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -53,13 +53,17 @@ export function getManifestContext(root: string = process.cwd()): ManifestContex
|
|
|
53
53
|
readPackage(resolve(`${process.env.TRV_MODULE}/package.json`)) :
|
|
54
54
|
findPackage(root, pkg => !!pkg) ?? workspace;
|
|
55
55
|
|
|
56
|
+
if (workspace.type !== 'module') {
|
|
57
|
+
console.error('ERROR: Only ESM modules are supported, package.json must be of type module');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
return {
|
|
57
62
|
workspace: {
|
|
58
63
|
name: workspace.name ?? 'untitled',
|
|
59
64
|
path: workspace.path,
|
|
60
65
|
mono: !!workspace.workspaces,
|
|
61
66
|
manager: existsSync(path.resolve(workspace.path, 'yarn.lock')) ? 'yarn' : 'npm',
|
|
62
|
-
type: workspace.type ?? 'commonjs',
|
|
63
67
|
defaultEnv: workspace.travetto?.defaultEnv ?? 'local'
|
|
64
68
|
},
|
|
65
69
|
build: {
|
package/src/delta.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
3
|
import { ManifestModuleUtil } from './module.ts';
|
|
4
|
-
import
|
|
4
|
+
import path from './path.ts';
|
|
5
5
|
|
|
6
6
|
import type { ManifestModule, ManifestModuleCore, ManifestModuleFile, ManifestRoot } from './types/manifest.ts';
|
|
7
|
-
import type { ManifestModuleFileType, ManifestModuleFolderType } from './types/common.ts';
|
|
7
|
+
import type { ChangeEventType, ManifestModuleFileType, ManifestModuleFolderType } from './types/common.ts';
|
|
8
8
|
import type { ManifestContext } from './types/context.ts';
|
|
9
9
|
|
|
10
|
-
type DeltaEventType =
|
|
10
|
+
type DeltaEventType = ChangeEventType | 'missing' | 'dirty';
|
|
11
11
|
type DeltaModule = ManifestModuleCore & { files: Record<string, ManifestModuleFile> };
|
|
12
12
|
export type DeltaEvent = { file: string, type: DeltaEventType, module: string, sourceFile: string };
|
|
13
13
|
|
|
@@ -52,17 +52,17 @@ export class ManifestDeltaUtil {
|
|
|
52
52
|
right.delete(ManifestModuleUtil.withoutSourceExtension(file));
|
|
53
53
|
|
|
54
54
|
if (!stat) {
|
|
55
|
-
add(file, '
|
|
55
|
+
add(file, 'create');
|
|
56
56
|
} else {
|
|
57
57
|
const rightTimestamp = this.#getNewest(stat);
|
|
58
58
|
if (leftTimestamp > rightTimestamp) {
|
|
59
|
-
add(file, '
|
|
59
|
+
add(file, 'update');
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
// Deleted
|
|
64
64
|
for (const file of right) {
|
|
65
|
-
add(file, '
|
|
65
|
+
add(file, 'delete');
|
|
66
66
|
}
|
|
67
67
|
return out;
|
|
68
68
|
}
|
package/src/dependencies.ts
CHANGED
package/src/file.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import path from './path.ts';
|
|
6
6
|
|
|
7
7
|
export class ManifestFileUtil {
|
|
8
8
|
/**
|
|
@@ -16,13 +16,6 @@ export class ManifestFileUtil {
|
|
|
16
16
|
await fs.rm(temp, { force: true });
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Read as json
|
|
21
|
-
*/
|
|
22
|
-
static async readAsJson<T = unknown>(file: string): Promise<T> {
|
|
23
|
-
return JSON.parse(await fs.readFile(file, 'utf8'));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
/**
|
|
27
20
|
* Read as json, sync
|
|
28
21
|
*/
|
package/src/manifest-index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
|
|
3
3
|
import { ManifestModuleUtil } from './module.ts';
|
|
4
|
-
import
|
|
4
|
+
import path from './path.ts';
|
|
5
5
|
import { ManifestUtil } from './util.ts';
|
|
6
6
|
|
|
7
7
|
import type { ManifestModule, ManifestRoot, ManifestModuleFile, IndexedModule, IndexedFile, FindConfig } from './types/manifest.ts';
|
|
@@ -192,6 +192,14 @@ export class ManifestIndex {
|
|
|
192
192
|
return this.#importToEntry.get(imp);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Get from import path or source file
|
|
197
|
+
* @param importOrSource
|
|
198
|
+
*/
|
|
199
|
+
getFromImportOrSource(importOrSource: string): IndexedFile | undefined {
|
|
200
|
+
return this.getFromImport(importOrSource) ?? this.getFromSource(path.resolve(importOrSource));
|
|
201
|
+
}
|
|
202
|
+
|
|
195
203
|
/**
|
|
196
204
|
* Get module from source file
|
|
197
205
|
* @param source
|
|
@@ -256,6 +264,15 @@ export class ManifestIndex {
|
|
|
256
264
|
return lookup(file.replace(`${base}/`, '').split('/'));
|
|
257
265
|
}
|
|
258
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Find the module for an arbitrary import
|
|
269
|
+
*/
|
|
270
|
+
findModuleForArbitraryImport(imp: string): IndexedModule | undefined {
|
|
271
|
+
const importParts = imp.split('/');
|
|
272
|
+
const module = imp.startsWith('@') ? importParts.slice(0, 2).join('/') : importParts[0];
|
|
273
|
+
return this.getModule(module);
|
|
274
|
+
}
|
|
275
|
+
|
|
259
276
|
/**
|
|
260
277
|
* Get manifest module by name
|
|
261
278
|
*/
|
package/src/module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import path from './path.ts';
|
|
4
4
|
import { PackageModuleVisitor } from './dependencies.ts';
|
|
5
5
|
|
|
6
6
|
import type { ManifestModuleFileType, ManifestModuleRole, ManifestModuleFolderType } from './types/common.ts';
|
|
@@ -18,7 +18,7 @@ const EXT_MAPPING: Record<string, ManifestModuleFileType> = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const INDEX_FILES = new Set(
|
|
21
|
-
['__index__', '__index', 'index'
|
|
21
|
+
['__index__', '__index', 'index'].flatMap(file =>
|
|
22
22
|
['ts', 'tsx', 'js'].map(ext => `${file}.${ext}`)
|
|
23
23
|
)
|
|
24
24
|
);
|
package/src/package.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { execSync } from 'node:child_process';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import path from './path.ts';
|
|
6
6
|
import { ManifestFileUtil } from './file.ts';
|
|
7
7
|
|
|
8
8
|
import { PackagePathSymbol, type Package, type PackageWorkspaceEntry } from './types/package.ts';
|
|
@@ -99,20 +99,21 @@ export class PackageUtil {
|
|
|
99
99
|
static async resolveWorkspaces(ctx: ManifestContext): Promise<PackageWorkspaceEntry[]> {
|
|
100
100
|
const rootPath = ctx.workspace.path;
|
|
101
101
|
const cache = path.resolve(rootPath, ctx.build.outputFolder, 'workspaces.json');
|
|
102
|
-
|
|
103
|
-
.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
try {
|
|
103
|
+
return this.#workspaces[rootPath] ??= ManifestFileUtil.readAsJsonSync<PackageWorkspaceEntry[]>(cache);
|
|
104
|
+
} catch {
|
|
105
|
+
let out: PackageWorkspaceEntry[];
|
|
106
|
+
switch (ctx.workspace.manager) {
|
|
107
|
+
case 'yarn':
|
|
108
|
+
case 'npm': {
|
|
109
|
+
const workspaces = await this.#exec<{ location: string, name: string }[]>(rootPath, 'npm query .workspace');
|
|
110
|
+
out = workspaces.map(mod => ({ path: path.resolve(ctx.workspace.path, mod.location), name: mod.name }));
|
|
111
|
+
break;
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
}
|
|
114
|
+
await ManifestFileUtil.bufferedFileWrite(cache, JSON.stringify(out));
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
/**
|
package/src/path.ts
CHANGED
|
@@ -6,8 +6,8 @@ const toPosix = (file: string): string => file.replaceAll('\\', '/');
|
|
|
6
6
|
const toNative = (file: string): string => file.replace(/[\/]/g, native.sep);
|
|
7
7
|
const cwd = (): string => toPosix(process.cwd());
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
native: posix
|
|
9
|
+
const path: typeof posix & {
|
|
10
|
+
native: typeof posix;
|
|
11
11
|
toPosix: typeof toPosix;
|
|
12
12
|
toNative: typeof toNative;
|
|
13
13
|
} = {
|
package/src/types/common.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type NodeModuleType = 'module' | 'commonjs';
|
|
2
1
|
export type NodePackageManager = 'yarn' | 'npm';
|
|
3
2
|
|
|
4
3
|
export type ManifestModuleFileType = 'typings' | 'ts' | 'js' | 'json' | 'package-json' | 'unknown' | 'fixture' | 'md';
|
|
@@ -8,4 +7,6 @@ export type ManifestModuleFolderType =
|
|
|
8
7
|
'test/fixtures' | 'support/fixtures' | 'support/resources' |
|
|
9
8
|
'$transformer';
|
|
10
9
|
|
|
11
|
-
export type ManifestModuleRole = 'std' | 'test' | 'doc' | 'compile' | 'build';
|
|
10
|
+
export type ManifestModuleRole = 'std' | 'test' | 'doc' | 'compile' | 'build';
|
|
11
|
+
|
|
12
|
+
export type ChangeEventType = 'create' | 'update' | 'delete';
|
package/src/types/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NodePackageManager } from './common.ts';
|
|
2
2
|
|
|
3
3
|
export type ManifestContext = {
|
|
4
4
|
workspace: {
|
|
@@ -8,8 +8,6 @@ export type ManifestContext = {
|
|
|
8
8
|
name: string;
|
|
9
9
|
/** Is the workspace a monorepo? */
|
|
10
10
|
mono?: boolean;
|
|
11
|
-
/** The module type of the workspace */
|
|
12
|
-
type: NodeModuleType;
|
|
13
11
|
/** The package manager of the workspace */
|
|
14
12
|
manager: NodePackageManager;
|
|
15
13
|
/** The default env name */
|
package/src/types/package.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ManifestModuleRole
|
|
1
|
+
import type { ManifestModuleRole } from './common.ts';
|
|
2
2
|
import type { ManifestContext } from './context.ts';
|
|
3
3
|
|
|
4
4
|
export const PackagePathSymbol = Symbol.for('@travetto/manifest:package-path');
|
|
@@ -6,7 +6,7 @@ export const PackagePathSymbol = Symbol.for('@travetto/manifest:package-path');
|
|
|
6
6
|
export type Package = {
|
|
7
7
|
[PackagePathSymbol]?: string;
|
|
8
8
|
name: string;
|
|
9
|
-
type?:
|
|
9
|
+
type?: string;
|
|
10
10
|
version: string;
|
|
11
11
|
description?: string;
|
|
12
12
|
license?: string;
|
package/src/util.ts
CHANGED