@travetto/transformer 5.0.0-rc.0 → 5.0.0-rc.2

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
@@ -104,11 +104,11 @@ export class Test {
104
104
  Object.defineProperty(exports, "__esModule", { value: true });
105
105
  exports.TEST = void 0;
106
106
  const tslib_1 = require("tslib");
107
- const Ⲑ_runtime_1 = tslib_1.__importStar(require("@travetto/manifest/src/runtime.js"));
108
107
  const Ⲑ_decorator_1 = tslib_1.__importStar(require("@travetto/registry/src/decorator.js"));
109
- var ᚕf = "@travetto/transformer/doc/upper.js";
108
+ const Ⲑ_function_1 = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
109
+ var ᚕm = ["@travetto/transformer", "doc/upper"];
110
110
  let TEST = class TEST {
111
- static Ⲑinit = Ⲑ_runtime_1.RuntimeIndex.registerFunction(TEST, ᚕf, { hash: 649563175, lines: [1, 9] }, { COMPUTEAGE: { hash: 1286718349, lines: [6, 8] } }, false, false);
111
+ static Ⲑinit = Ⲑ_function_1.register(TEST, ᚕm, { hash: 649563175, lines: [1, 9] }, { COMPUTEAGE: { hash: 1286718349, lines: [6, 8] } }, false, false);
112
112
  NAME;
113
113
  AGE;
114
114
  DOB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/transformer",
3
- "version": "5.0.0-rc.0",
3
+ "version": "5.0.0-rc.2",
4
4
  "description": "Functionality for AST transformations, with transformer registration, and general utils",
5
5
  "keywords": [
6
6
  "typescript",
@@ -24,7 +24,7 @@
24
24
  "directory": "module/transformer"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/manifest": "^5.0.0-rc.0",
27
+ "@travetto/manifest": "^5.0.0-rc.2",
28
28
  "tslib": "^2.6.3",
29
29
  "typescript": "^5.5.3"
30
30
  },
package/src/manager.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import { ManifestIndex, RuntimeIndex } from '@travetto/manifest';
3
+ import { ManifestIndex } from '@travetto/manifest';
4
4
 
5
5
  import { NodeTransformer } from './types/visitor';
6
6
  import { VisitorFactory } from './visitor';
@@ -19,12 +19,12 @@ export class TransformerManager {
19
19
  * @returns
20
20
  */
21
21
  static async create(manifestIndex: ManifestIndex): Promise<TransformerManager> {
22
- const transformerFiles = RuntimeIndex.find({ folder: f => f === '$transformer' }).map(f => f.sourceFile);
22
+ const transformerFiles = manifestIndex.find({ folder: f => f === '$transformer' }).map(f => f.sourceFile);
23
23
 
24
24
  const transformers: NodeTransformer<TransformerState>[] = [];
25
25
 
26
26
  for (const file of transformerFiles) { // Exclude based on blacklist
27
- const entry = RuntimeIndex.getEntry(file)!;
27
+ const entry = manifestIndex.getEntry(file)!;
28
28
  transformers.push(...getAllTransformers(await import(entry.import), entry.module));
29
29
  }
30
30
 
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import { path, ManifestIndex, ManifestModuleUtil } from '@travetto/manifest';
3
+ import { path, ManifestIndex, ManifestModuleUtil, IndexedFile } from '@travetto/manifest';
4
4
 
5
5
  import type { AnyType, TransformResolver } from './types';
6
6
  import { TypeCategorize, TypeBuilder } from './builder';
@@ -29,9 +29,9 @@ export class SimpleResolver implements TransformResolver {
29
29
  }
30
30
 
31
31
  /**
32
- * Resolve an import name (e.g. @module/path/file) for a file
32
+ * Resolve an import for a file
33
33
  */
34
- getFileImportName(file: string, removeExt?: boolean): string {
34
+ getFileImport(file: string): IndexedFile | undefined {
35
35
  let sourceFile = path.toPosix(file);
36
36
 
37
37
  const type = ManifestModuleUtil.getFileType(file);
@@ -40,11 +40,14 @@ export class SimpleResolver implements TransformResolver {
40
40
  sourceFile = `${sourceFile}.ts`;
41
41
  }
42
42
 
43
- const imp =
44
- this.#manifestIndex.getEntry(ManifestModuleUtil.getFileType(sourceFile) === 'ts' ? sourceFile : `${sourceFile}.js`)?.import ??
45
- this.#manifestIndex.getFromImport(ManifestModuleUtil.sourceToBlankExt(sourceFile).replace(/^.*node_modules\//, ''))?.import ??
46
- file;
47
-
43
+ return this.#manifestIndex.getEntry(ManifestModuleUtil.getFileType(sourceFile) === 'ts' ? sourceFile : `${sourceFile}.js`) ??
44
+ this.#manifestIndex.getFromImport(ManifestModuleUtil.sourceToBlankExt(sourceFile).replace(/^.*node_modules\//, ''));
45
+ }
46
+ /**
47
+ * Resolve an import name (e.g. @module/path/file) for a file
48
+ */
49
+ getFileImportName(file: string, removeExt?: boolean): string {
50
+ const imp = this.getFileImport(file)?.import ?? file;
48
51
  return removeExt ? ManifestModuleUtil.sourceToBlankExt(imp) : imp;
49
52
  }
50
53
 
package/src/state.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import { path, ManifestIndex } from '@travetto/manifest';
3
+ import { path, ManifestIndex, ManifestModuleUtil } from '@travetto/manifest';
4
4
 
5
5
  import { ManagedType, AnyType, ForeignType } from './resolver/types';
6
6
  import { State, DecoratorMeta, Transformer, ModuleNameⲐ } from './types/visitor';
@@ -33,7 +33,7 @@ export class TransformerState implements State {
33
33
 
34
34
  #resolver: SimpleResolver;
35
35
  #imports: ImportManager;
36
- #fileIdent: ts.Identifier;
36
+ #modIdent: ts.Identifier;
37
37
  #manifestIndex: ManifestIndex;
38
38
  #syntheticIdentifiers = new Map<string, ts.Identifier>();
39
39
  #decorators = new Map<string, ts.PropertyAccessExpression>();
@@ -261,17 +261,18 @@ export class TransformerState implements State {
261
261
  /**
262
262
  * Get filename identifier, regardless of module system
263
263
  */
264
- getFilenameIdentifier(): ts.Expression {
265
- if (this.#fileIdent === undefined) {
266
- this.#fileIdent = this.createIdentifier('ᚕf');
267
- const decl = this.factory.createVariableDeclaration(this.#fileIdent, undefined, undefined,
268
- this.fromLiteral(this.#resolver.getFileImportName(this.source.fileName) ?? this.source.fileName)
264
+ getModuleIdentifier(): ts.Expression {
265
+ if (this.#modIdent === undefined) {
266
+ this.#modIdent = this.createIdentifier('ᚕm');
267
+ const entry = this.#resolver.getFileImport(this.source.fileName);
268
+ const decl = this.factory.createVariableDeclaration(this.#modIdent, undefined, undefined,
269
+ this.fromLiteral([entry?.module, ManifestModuleUtil.sourceToBlankExt(entry?.relativeFile ?? '')])
269
270
  );
270
271
  this.addStatements([
271
272
  this.factory.createVariableStatement([], this.factory.createVariableDeclarationList([decl]))
272
273
  ], -1);
273
274
  }
274
- return this.#fileIdent;
275
+ return this.#modIdent;
275
276
  }
276
277
 
277
278
  /**