@travetto/manifest 6.0.0-rc.1 → 6.0.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 +2 -1
- package/__index__.ts +12 -12
- package/package.json +2 -2
- package/src/context.ts +2 -2
- package/src/delta.ts +5 -5
- package/src/dependencies.ts +6 -6
- package/src/file.ts +1 -1
- package/src/manifest-index.ts +6 -6
- package/src/module.ts +19 -12
- package/src/package.ts +12 -12
- package/src/types/context.ts +1 -1
- package/src/types/manifest.ts +3 -3
- package/src/types/package.ts +4 -4
- package/src/util.ts +6 -6
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#L9) as an equivalent to [Node](https://nodejs.org)'s [
|
|
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#L9) 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
|
|
|
@@ -171,6 +171,7 @@ The module files are a simple categorization of files into a predetermined set o
|
|
|
171
171
|
* `doc` - Documentation files. `DOC.tsx` and All .ts/.tsx files under the `doc/` folder
|
|
172
172
|
* `$transformer` - All .ts files under the pattern `support/transform*`. These are used during compilation and never at runtime
|
|
173
173
|
* `bin` - Entry point .js files. All .js files under the `bin/` folder
|
|
174
|
+
|
|
174
175
|
Within each file there is a pattern of either a 3 or 4 element array:
|
|
175
176
|
|
|
176
177
|
**Code: Sample file**
|
package/__index__.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './src/context';
|
|
2
|
-
export * from './src/module';
|
|
3
|
-
export * from './src/delta';
|
|
4
|
-
export * from './src/manifest-index';
|
|
5
|
-
export * from './src/package';
|
|
6
|
-
export * from './src/util';
|
|
7
|
-
export * from './src/file';
|
|
8
|
-
export * from './src/types/context';
|
|
9
|
-
export * from './src/types/package';
|
|
10
|
-
export * from './src/types/manifest';
|
|
11
|
-
export * from './src/types/common';
|
|
12
|
-
export { path } from './src/path';
|
|
1
|
+
export * from './src/context.ts';
|
|
2
|
+
export * from './src/module.ts';
|
|
3
|
+
export * from './src/delta.ts';
|
|
4
|
+
export * from './src/manifest-index.ts';
|
|
5
|
+
export * from './src/package.ts';
|
|
6
|
+
export * from './src/util.ts';
|
|
7
|
+
export * from './src/file.ts';
|
|
8
|
+
export * from './src/types/context.ts';
|
|
9
|
+
export * from './src/types/package.ts';
|
|
10
|
+
export * from './src/types/manifest.ts';
|
|
11
|
+
export * from './src/types/common.ts';
|
|
12
|
+
export { path } from './src/path.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/manifest",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Support for project indexing, manifesting, along with file watching",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"path",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"node": ">=23.0.0"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@types/node": "^22.
|
|
29
|
+
"@types/node": "^22.15.0"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"url": "git+https://github.com/travetto/travetto.git",
|
package/src/context.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
|
|
5
|
-
import type { Package } from './types/package';
|
|
6
|
-
import type { ManifestContext } from './types/context';
|
|
5
|
+
import type { Package } from './types/package.ts';
|
|
6
|
+
import type { ManifestContext } from './types/context.ts';
|
|
7
7
|
|
|
8
8
|
type Pkg = Package & { path: string };
|
|
9
9
|
|
package/src/delta.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { ManifestModuleUtil } from './module';
|
|
4
|
-
import { path } from './path';
|
|
3
|
+
import { ManifestModuleUtil } from './module.ts';
|
|
4
|
+
import { path } from './path.ts';
|
|
5
5
|
|
|
6
|
-
import type { ManifestModule, ManifestModuleCore, ManifestModuleFile, ManifestRoot } from './types/manifest';
|
|
7
|
-
import type { ManifestModuleFileType, ManifestModuleFolderType } from './types/common';
|
|
8
|
-
import type { ManifestContext } from './types/context';
|
|
6
|
+
import type { ManifestModule, ManifestModuleCore, ManifestModuleFile, ManifestRoot } from './types/manifest.ts';
|
|
7
|
+
import type { ManifestModuleFileType, ManifestModuleFolderType } from './types/common.ts';
|
|
8
|
+
import type { ManifestContext } from './types/context.ts';
|
|
9
9
|
|
|
10
10
|
type DeltaEventType = 'added' | 'changed' | 'removed' | 'missing' | 'dirty';
|
|
11
11
|
type DeltaModule = ManifestModuleCore & { files: Record<string, ManifestModuleFile> };
|
package/src/dependencies.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { PackageUtil } from './package';
|
|
2
|
-
import { path } from './path';
|
|
1
|
+
import { PackageUtil } from './package.ts';
|
|
2
|
+
import { path } from './path.ts';
|
|
3
3
|
|
|
4
|
-
import type { Package, PackageDepType } from './types/package';
|
|
5
|
-
import type { ManifestContext } from './types/context';
|
|
6
|
-
import type { PackageModule } from './types/manifest';
|
|
4
|
+
import type { Package, PackageDepType } from './types/package.ts';
|
|
5
|
+
import type { ManifestContext } from './types/context.ts';
|
|
6
|
+
import type { PackageModule } from './types/manifest.ts';
|
|
7
7
|
|
|
8
8
|
type CreateOpts = Partial<Pick<PackageModule, 'main' | 'workspace' | 'prod'>> & { roleRoot?: boolean, parent?: PackageModule };
|
|
9
9
|
|
|
@@ -146,7 +146,7 @@ export class PackageModuleVisitor {
|
|
|
146
146
|
dep.state.roleSet = new Set(['std']);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
return [...mods].
|
|
149
|
+
return [...mods].toSorted((a, b) => a.name.localeCompare(b.name));
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
/**
|
package/src/file.ts
CHANGED
package/src/manifest-index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
|
|
3
|
-
import { ManifestModuleUtil } from './module';
|
|
4
|
-
import { path } from './path';
|
|
5
|
-
import { ManifestUtil } from './util';
|
|
3
|
+
import { ManifestModuleUtil } from './module.ts';
|
|
4
|
+
import { path } from './path.ts';
|
|
5
|
+
import { ManifestUtil } from './util.ts';
|
|
6
6
|
|
|
7
|
-
import type { ManifestModule, ManifestRoot, ManifestModuleFile, IndexedModule, IndexedFile, FindConfig } from './types/manifest';
|
|
7
|
+
import type { ManifestModule, ManifestRoot, ManifestModuleFile, IndexedModule, IndexedFile, FindConfig } from './types/manifest.ts';
|
|
8
8
|
|
|
9
9
|
const TypedObject: {
|
|
10
10
|
keys<T = unknown, K extends keyof T = keyof T>(o: T): K[];
|
|
@@ -57,7 +57,7 @@ export class ManifestIndex {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
#moduleFiles(m: ManifestModule, files: ManifestModuleFile[]): IndexedFile[] {
|
|
60
|
-
return files.map(([f, type,
|
|
60
|
+
return files.map(([f, type, _ts, role = 'std']) => {
|
|
61
61
|
const isSource = type === 'ts' || type === 'js';
|
|
62
62
|
const sourceFile = path.resolve(this.#manifest.workspace.path, m.sourceFolder, f);
|
|
63
63
|
const js = isSource ? ManifestModuleUtil.withOutputExtension(f) : f;
|
|
@@ -202,7 +202,7 @@ export class ManifestIndex {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
* Build module list from an expression list (e.g. `@travetto/
|
|
205
|
+
* Build module list from an expression list (e.g. `@travetto/web,-@travetto/log)
|
|
206
206
|
*/
|
|
207
207
|
getModuleList(mode: 'workspace' | 'all', exprList: string = ''): Set<string> {
|
|
208
208
|
const allMods = Object.keys(this.#manifest.modules);
|
package/src/module.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { path } from './path';
|
|
4
|
-
import { PackageModuleVisitor } from './dependencies';
|
|
3
|
+
import { path } from './path.ts';
|
|
4
|
+
import { PackageModuleVisitor } from './dependencies.ts';
|
|
5
5
|
|
|
6
|
-
import type { ManifestModuleFileType, ManifestModuleRole, ManifestModuleFolderType } from './types/common';
|
|
7
|
-
import type { ManifestModuleFile, ManifestModule, PackageModule } from './types/manifest';
|
|
8
|
-
import type { ManifestContext } from './types/context';
|
|
6
|
+
import type { ManifestModuleFileType, ManifestModuleRole, ManifestModuleFolderType } from './types/common.ts';
|
|
7
|
+
import type { ManifestModuleFile, ManifestModule, PackageModule } from './types/manifest.ts';
|
|
8
|
+
import type { ManifestContext } from './types/context.ts';
|
|
9
9
|
|
|
10
10
|
const EXT_MAPPING: Record<string, ManifestModuleFileType> = {
|
|
11
11
|
'.js': 'js',
|
|
@@ -41,6 +41,13 @@ const SUPPORT_FILE_RE = new RegExp(`^support[/](?<name>${Object.keys(SUPPORT_FIL
|
|
|
41
41
|
|
|
42
42
|
export class ManifestModuleUtil {
|
|
43
43
|
|
|
44
|
+
static TYPINGS_EXT = '.d.ts';
|
|
45
|
+
static OUTPUT_EXT = '.js';
|
|
46
|
+
static SOURCE_DEF_EXT = '.ts';
|
|
47
|
+
static SOURCE_EXT_RE = /[.][cm]?[tj]sx?$/;
|
|
48
|
+
static TYPINGS_EXT_RE = /[.]d[.][cm]?ts$/;
|
|
49
|
+
static TYPINGS_WITH_MAP_EXT_RE = /[.]d[.][cm]?ts([.]map)?$/;
|
|
50
|
+
|
|
44
51
|
static #scanCache: Record<string, string[]> = {};
|
|
45
52
|
|
|
46
53
|
static #getNewest(stat: { mtimeMs: number, ctimeMs: number }): number {
|
|
@@ -51,7 +58,7 @@ export class ManifestModuleUtil {
|
|
|
51
58
|
* Replace a source file's extension with a given value
|
|
52
59
|
*/
|
|
53
60
|
static #pathToExtension(sourceFile: string, ext: string): string {
|
|
54
|
-
return sourceFile.replace(
|
|
61
|
+
return sourceFile.replace(ManifestModuleUtil.SOURCE_EXT_RE, ext);
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
/**
|
|
@@ -127,7 +134,7 @@ export class ManifestModuleUtil {
|
|
|
127
134
|
moduleFile.startsWith('support/resources/')
|
|
128
135
|
) {
|
|
129
136
|
return 'fixture';
|
|
130
|
-
} else if (moduleFile.endsWith(
|
|
137
|
+
} else if (moduleFile.endsWith(this.TYPINGS_EXT)) {
|
|
131
138
|
return 'typings';
|
|
132
139
|
} else {
|
|
133
140
|
const ext = path.extname(moduleFile);
|
|
@@ -216,8 +223,8 @@ export class ManifestModuleUtil {
|
|
|
216
223
|
|
|
217
224
|
return {
|
|
218
225
|
...rest,
|
|
219
|
-
roles: [...state.roleSet].
|
|
220
|
-
parents: [...state.parentSet].
|
|
226
|
+
roles: [...state.roleSet].toSorted(),
|
|
227
|
+
parents: [...state.parentSet].toSorted(),
|
|
221
228
|
files
|
|
222
229
|
};
|
|
223
230
|
}
|
|
@@ -235,17 +242,17 @@ export class ManifestModuleUtil {
|
|
|
235
242
|
* Get the output file name for a given input
|
|
236
243
|
*/
|
|
237
244
|
static withOutputExtension(sourceFile: string): string {
|
|
238
|
-
if (sourceFile.endsWith(
|
|
245
|
+
if (sourceFile.endsWith(this.TYPINGS_EXT)) {
|
|
239
246
|
return sourceFile;
|
|
240
247
|
}
|
|
241
|
-
return this.#pathToExtension(sourceFile,
|
|
248
|
+
return this.#pathToExtension(sourceFile, ManifestModuleUtil.OUTPUT_EXT);
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
/**
|
|
245
252
|
* Get the file without an extension
|
|
246
253
|
*/
|
|
247
254
|
static withoutSourceExtension(sourceFile: string): string {
|
|
248
|
-
if (sourceFile.endsWith(
|
|
255
|
+
if (sourceFile.endsWith(this.TYPINGS_EXT)) {
|
|
249
256
|
return sourceFile;
|
|
250
257
|
}
|
|
251
258
|
return this.#pathToExtension(sourceFile, '');
|
package/src/package.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { execSync } from 'node:child_process';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
|
|
5
|
-
import { path } from './path';
|
|
6
|
-
import { ManifestFileUtil } from './file';
|
|
5
|
+
import { path } from './path.ts';
|
|
6
|
+
import { ManifestFileUtil } from './file.ts';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import type { ManifestContext } from './types/context';
|
|
10
|
-
import type { NodePackageManager } from './types/common';
|
|
8
|
+
import { PackagePathSymbol, type Package, type PackageWorkspaceEntry } from './types/package.ts';
|
|
9
|
+
import type { ManifestContext } from './types/context.ts';
|
|
10
|
+
import type { NodePackageManager } from './types/common.ts';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Utilities for querying, traversing and reading package.json files.
|
|
@@ -76,21 +76,21 @@ export class PackageUtil {
|
|
|
76
76
|
if (forceRead) {
|
|
77
77
|
delete this.#cache[modulePath];
|
|
78
78
|
}
|
|
79
|
-
const
|
|
79
|
+
const nodePackage = this.#cache[modulePath] ??= ManifestFileUtil.readAsJsonSync(
|
|
80
80
|
modulePath.endsWith('.json') ? modulePath : path.resolve(modulePath, 'package.json'),
|
|
81
81
|
);
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
nodePackage.name ??= 'untitled'; // If a package.json (root-only) is missing a name, allows for npx execution
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
return
|
|
85
|
+
nodePackage[PackagePathSymbol] = modulePath;
|
|
86
|
+
return nodePackage;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Get the package path
|
|
91
91
|
*/
|
|
92
92
|
static getPackagePath(pkg: Package): string {
|
|
93
|
-
return pkg[
|
|
93
|
+
return pkg[PackagePathSymbol]!;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -105,8 +105,8 @@ export class PackageUtil {
|
|
|
105
105
|
switch (ctx.workspace.manager) {
|
|
106
106
|
case 'yarn':
|
|
107
107
|
case 'npm': {
|
|
108
|
-
const
|
|
109
|
-
out =
|
|
108
|
+
const workspaces = await this.#exec<{ location: string, name: string }[]>(rootPath, 'npm query .workspace');
|
|
109
|
+
out = workspaces.map(d => ({ path: path.resolve(ctx.workspace.path, d.location), name: d.name }));
|
|
110
110
|
break;
|
|
111
111
|
}
|
|
112
112
|
}
|
package/src/types/context.ts
CHANGED
package/src/types/manifest.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ManifestModuleFileType, ManifestModuleFolderType, ManifestModuleRole } from './common';
|
|
2
|
-
import type { ManifestContext } from './context';
|
|
3
|
-
import { Package } from './package';
|
|
1
|
+
import type { ManifestModuleFileType, ManifestModuleFolderType, ManifestModuleRole } from './common.ts';
|
|
2
|
+
import type { ManifestContext } from './context.ts';
|
|
3
|
+
import { Package } from './package.ts';
|
|
4
4
|
|
|
5
5
|
export type ManifestModuleFile =
|
|
6
6
|
[path: string, type: ManifestModuleFileType, updated: number] |
|
package/src/types/package.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ManifestModuleRole, NodeModuleType } from './common';
|
|
2
|
-
import type { ManifestContext } from './context';
|
|
1
|
+
import type { ManifestModuleRole, NodeModuleType } from './common.ts';
|
|
2
|
+
import type { ManifestContext } from './context.ts';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const PackagePathSymbol = Symbol.for('@travetto/manifest:package-path');
|
|
5
5
|
|
|
6
6
|
export type Package = {
|
|
7
|
-
[
|
|
7
|
+
[PackagePathSymbol]?: string;
|
|
8
8
|
name: string;
|
|
9
9
|
type?: NodeModuleType;
|
|
10
10
|
version: string;
|
package/src/util.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { path } from './path';
|
|
2
|
-
import { ManifestModuleUtil } from './module';
|
|
3
|
-
import { ManifestFileUtil } from './file';
|
|
4
|
-
import { PackageUtil } from './package';
|
|
1
|
+
import { path } from './path.ts';
|
|
2
|
+
import { ManifestModuleUtil } from './module.ts';
|
|
3
|
+
import { ManifestFileUtil } from './file.ts';
|
|
4
|
+
import { PackageUtil } from './package.ts';
|
|
5
5
|
|
|
6
|
-
import type { ManifestContext } from './types/context';
|
|
7
|
-
import type { ManifestRoot } from './types/manifest';
|
|
6
|
+
import type { ManifestContext } from './types/context.ts';
|
|
7
|
+
import type { ManifestRoot } from './types/manifest.ts';
|
|
8
8
|
|
|
9
9
|
const MANIFEST_FILE = 'manifest.json';
|
|
10
10
|
|