@travetto/manifest 5.0.0-rc.3 → 5.0.0-rc.5

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 CHANGED
@@ -30,7 +30,7 @@ During the compilation process, the compiler needs to know every file that is el
30
30
  Additionally, once the code has been compiled (or even bundled after that), the executing process needs to know what files are available for loading, and any patterns necessary for knowing which files to load versus which ones to ignore. This allows for dynamic loading of modules/files without knowledge/access to the file system, and in a more performant manner.
31
31
 
32
32
  ## Manifest Delta
33
- During the compilation process, it is helpful to know how the output content differs from the manifest, which is produced from the source input. The [ManifestDeltaUtil](https://github.com/travetto/travetto/tree/main/module/manifest/src/delta.ts#L21) provides the functionality for a given manifest, and will produce a stream of changes grouped by module. This is the primary input into the [Compiler](https://github.com/travetto/travetto/tree/main/module/compiler#readme "The compiler infrastructure for the Travetto framework")'s incremental behavior to know when a file has changed and needs to be recompiled.
33
+ During the compilation process, it is helpful to know how the output content differs from the manifest, which is produced from the source input. The [ManifestDeltaUtil](https://github.com/travetto/travetto/tree/main/module/manifest/src/delta.ts#L23) provides the functionality for a given manifest, and will produce a stream of changes grouped by module. This is the primary input into the [Compiler](https://github.com/travetto/travetto/tree/main/module/compiler#readme "The compiler infrastructure for the Travetto framework")'s incremental behavior to know when a file has changed and needs to be recompiled.
34
34
 
35
35
  ## Class and Function Metadata
36
36
  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.
@@ -51,7 +51,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.TestClass = void 0;
52
52
  const tslib_1 = require("tslib");
53
53
  const Ⲑ_function_1 = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
54
- var ᚕm = ["@travetto/manifest", "doc/test-class"];
54
+ var ᚕm = ["@travetto/manifest", "doc/test-class.ts"];
55
55
  class TestClass {
56
56
  static Ⲑinit = Ⲑ_function_1.registerFunction(TestClass, ᚕm, { hash: 197152026, lines: [1, 3] }, { doStuff: { hash: 51337554, lines: [2, 2] } }, false, false);
57
57
  async doStuff() { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/manifest",
3
- "version": "5.0.0-rc.3",
3
+ "version": "5.0.0-rc.5",
4
4
  "description": "Support for project indexing, manifesting, along with file watching",
5
5
  "keywords": [
6
6
  "path",
package/src/delta.ts CHANGED
@@ -15,6 +15,8 @@ const VALID_SOURCE_FOLDERS = new Set<ManifestModuleFolderType>(['bin', 'src', 't
15
15
  const VALID_OUTPUT_TYPE = new Set<ManifestModuleFileType>(['js', 'ts', 'package-json']);
16
16
  const VALID_SOURCE_TYPE = new Set<ManifestModuleFileType>([...VALID_OUTPUT_TYPE, 'typings']);
17
17
 
18
+ const TypedObject: { keys<T = unknown, K extends keyof T = keyof T>(o: T): K[] } & ObjectConstructor = Object;
19
+
18
20
  /**
19
21
  * Produce delta for the manifest
20
22
  */
@@ -40,14 +42,14 @@ export class ManifestDeltaUtil {
40
42
  const type = ManifestModuleUtil.getFileType(x);
41
43
  return VALID_SOURCE_TYPE.has(type);
42
44
  })
43
- .map(x => ManifestModuleUtil.sourceToBlankExt(x.replace(`${root}/`, '')))
45
+ .map(x => ManifestModuleUtil.withoutSourceExtension(x.replace(`${root}/`, '')))
44
46
  );
45
47
 
46
48
  for (const el of Object.keys(left.files)) {
47
- const output = ManifestModuleUtil.sourceToOutputExt(`${outputFolder}/${left.outputFolder}/${el}`);
49
+ const output = ManifestModuleUtil.withOutputExtension(`${outputFolder}/${left.outputFolder}/${el}`);
48
50
  const [, , leftTs] = left.files[el];
49
51
  const stat = await fs.stat(output).catch(() => undefined);
50
- right.delete(ManifestModuleUtil.sourceToBlankExt(el));
52
+ right.delete(ManifestModuleUtil.withoutSourceExtension(el));
51
53
 
52
54
  if (!stat) {
53
55
  add(el, 'added');
@@ -72,8 +74,7 @@ export class ManifestDeltaUtil {
72
74
  */
73
75
  static #flattenModuleFiles(m: ManifestModule): Record<string, ManifestModuleFile> {
74
76
  const out: Record<string, ManifestModuleFile> = {};
75
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
76
- for (const key of Object.keys(m.files) as (ManifestModuleFolderType[])) {
77
+ for (const key of TypedObject.keys(m.files)) {
77
78
  if (!VALID_SOURCE_FOLDERS.has(key)) {
78
79
  continue;
79
80
  }
@@ -4,7 +4,6 @@ import { ManifestModuleUtil } from './module';
4
4
  import { path } from './path';
5
5
  import { ManifestUtil } from './util';
6
6
 
7
- import type { ManifestModuleFolderType } from './types/common';
8
7
  import type { ManifestModule, ManifestRoot, ManifestModuleFile, IndexedModule, IndexedFile, FindConfig } from './types/manifest';
9
8
 
10
9
  const TypedObject: {
@@ -61,12 +60,12 @@ export class ManifestIndex {
61
60
  return files.map(([f, type, ts, role = 'std']) => {
62
61
  const isSource = type === 'ts' || type === 'js';
63
62
  const sourceFile = path.resolve(this.#manifest.workspace.path, m.sourceFolder, f);
64
- const js = isSource ? ManifestModuleUtil.sourceToOutputExt(f) : f;
63
+ const js = isSource ? ManifestModuleUtil.withOutputExtension(f) : f;
65
64
  const outputFile = this.#resolveOutput(m.outputFolder, js);
66
- const modImport = `${m.name}/${js}`;
67
- let id = modImport.replace(`${m.name}/`, _ => _.replace(/[/]$/, ':'));
65
+ const modImport = `${m.name}/${f}`;
66
+ let id = `${m.name}:${f}`;
68
67
  if (isSource) {
69
- id = ManifestModuleUtil.sourceToBlankExt(id);
68
+ id = ManifestModuleUtil.withoutSourceExtension(id);
70
69
  }
71
70
 
72
71
  return { id, type, sourceFile, outputFile, import: modImport, role, relativeFile: f, module: m.name };
@@ -88,10 +87,9 @@ export class ManifestIndex {
88
87
  outputPath: this.#resolveOutput(m.outputFolder),
89
88
  sourcePath: path.resolve(this.#manifest.workspace.path, m.sourceFolder),
90
89
  children: new Set(),
91
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
92
- files: Object.fromEntries(
93
- Object.entries(m.files).map(([folder, files]) => [folder, this.#moduleFiles(m, files ?? [])])
94
- ) as Record<ManifestModuleFolderType, IndexedFile[]>
90
+ files: TypedObject.fromEntries(
91
+ TypedObject.entries(m.files).map(([folder, files]) => [folder, this.#moduleFiles(m, files ?? [])])
92
+ )
95
93
  }));
96
94
 
97
95
  for (const mod of this.#modules) {
@@ -100,7 +98,8 @@ export class ManifestIndex {
100
98
  this.#outputToEntry.set(entry.outputFile, entry);
101
99
  this.#sourceToEntry.set(entry.sourceFile, entry);
102
100
  this.#importToEntry.set(entry.import, entry);
103
- this.#importToEntry.set(entry.import.replace(/[.]js$/, ''), entry);
101
+ this.#importToEntry.set(ManifestModuleUtil.withoutSourceExtension(entry.import), entry);
102
+ this.#importToEntry.set(ManifestModuleUtil.withOutputExtension(entry.import), entry);
104
103
  }
105
104
  }
106
105
  }
@@ -189,7 +188,7 @@ export class ManifestIndex {
189
188
  */
190
189
  getFromImport(imp: string): IndexedFile | undefined {
191
190
  // Strip ext
192
- imp = ManifestModuleUtil.sourceToBlankExt(imp);
191
+ imp = ManifestModuleUtil.withoutSourceExtension(imp);
193
192
  return this.#importToEntry.get(imp);
194
193
  }
195
194
 
@@ -212,8 +211,8 @@ export class ManifestIndex {
212
211
  for (const expr of exprList.split(/\s*,\s*/g)) {
213
212
  const [, neg, mod] = expr.match(/(-|[+])?([^+\- ]+)$/) ?? [];
214
213
  if (mod) {
215
- const patt = new RegExp(`^${mod.replace(/[*]/g, '.*')}$`);
216
- for (const m of allMods.filter(x => patt.test(x))) {
214
+ const pattern = new RegExp(`^${mod.replace(/[*]/g, '.*')}$`);
215
+ for (const m of allMods.filter(x => pattern.test(x))) {
217
216
  active[neg ? 'delete' : 'add'](m);
218
217
  }
219
218
  }
package/src/module.ts CHANGED
@@ -48,7 +48,7 @@ export class ManifestModuleUtil {
48
48
  /**
49
49
  * Replace a source file's extension with a given value
50
50
  */
51
- static #sourceToExtension(inputFile: string, ext: string): string {
51
+ static #pathToExtension(inputFile: string, ext: string): string {
52
52
  return inputFile.replace(/[.][tj]sx?$/, ext);
53
53
  }
54
54
 
@@ -227,14 +227,14 @@ export class ManifestModuleUtil {
227
227
  /**
228
228
  * Get the output file name for a given input
229
229
  */
230
- static sourceToOutputExt(inputFile: string): string {
231
- return this.#sourceToExtension(inputFile, '.js');
230
+ static withOutputExtension(inputFile: string): string {
231
+ return this.#pathToExtension(inputFile, '.js');
232
232
  }
233
233
 
234
234
  /**
235
235
  * Get the file without an extension
236
236
  */
237
- static sourceToBlankExt(inputFile: string): string {
238
- return this.#sourceToExtension(inputFile, '');
237
+ static withoutSourceExtension(inputFile: string): string {
238
+ return this.#pathToExtension(inputFile, '');
239
239
  }
240
240
  }