@travetto/compiler 3.0.0-rc.29 → 3.0.0-rc.30

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/bin/trv.js CHANGED
@@ -16,7 +16,7 @@ const COMPILER_FILES = [...['launcher', 'transpile', 'lock', 'log', 'lock-pinger
16
16
  * @return {Promise<import('@travetto/compiler/support/launcher').launch>}
17
17
  */
18
18
  const $getLauncher = async (ctx) => {
19
- const compPkg = createRequire(path.resolve('node_modules')).resolve('@travetto/compiler/package.json');
19
+ const compPkg = createRequire(path.resolve(ctx.workspacePath, 'node_modules')).resolve('@travetto/compiler/package.json');
20
20
  const files = [];
21
21
 
22
22
  for (const file of COMPILER_FILES) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/compiler",
3
- "version": "3.0.0-rc.29",
3
+ "version": "3.0.0-rc.30",
4
4
  "description": "Compiler",
5
5
  "keywords": [
6
6
  "compiler",
@@ -31,12 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@parcel/watcher": "^2.1.0",
34
- "@travetto/manifest": "^3.0.0-rc.15",
34
+ "@travetto/manifest": "^3.0.0-rc.16",
35
35
  "@travetto/terminal": "^3.0.0-rc.10",
36
- "@travetto/transformer": "^3.0.0-rc.19"
36
+ "@travetto/transformer": "^3.0.0-rc.20"
37
37
  },
38
38
  "peerDependencies": {
39
- "@travetto/cli": "^3.0.0-rc.20"
39
+ "@travetto/cli": "^3.0.0-rc.21"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/cli": {
package/src/state.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import ts from 'typescript';
2
- import os from 'os';
3
2
 
4
3
  import { path, ManifestModuleUtil, ManifestModule, ManifestRoot, ManifestIndex } from '@travetto/manifest';
5
4
  import { TransformerManager } from '@travetto/transformer';
@@ -8,6 +7,16 @@ import { CompilerUtil } from './util';
8
7
  import { TranspileUtil } from '../support/transpile';
9
8
  import { CompileStateEntry } from './types';
10
9
 
10
+ function folderMapper(root: string, prefix: string): { dir: string, translate: (val: string) => string } {
11
+ let matched: string = '~~';
12
+ prefix = `/${prefix}`;
13
+ const final = path.resolve(root).replace(/\/[^\/+]/, m => {
14
+ matched = m;
15
+ return prefix;
16
+ });
17
+ return { dir: final, translate: (file: string) => file.replace(prefix, matched) };
18
+ }
19
+
11
20
  export class CompilerState implements ts.CompilerHost {
12
21
 
13
22
  static async get(idx: ManifestIndex): Promise<CompilerState> {
@@ -16,7 +25,8 @@ export class CompilerState implements ts.CompilerHost {
16
25
 
17
26
  private constructor() { }
18
27
 
19
- #rootDir = path.resolve(os.tmpdir(), '_');
28
+ #rootDir: string;
29
+ #inputPathToSource: (file: string) => string;
20
30
  #outputPath: string;
21
31
  #inputFiles = new Set<string>();
22
32
  #inputDirectoryToSource = new Map<string, string>();
@@ -36,6 +46,10 @@ export class CompilerState implements ts.CompilerHost {
36
46
  async init(idx: ManifestIndex): Promise<this> {
37
47
  this.#manifestIndex = idx;
38
48
  this.#manifest = idx.manifest;
49
+ const mapper = folderMapper(this.#manifest.workspacePath, '##');
50
+ this.#rootDir = mapper.dir;
51
+ this.#inputPathToSource = mapper.translate;
52
+
39
53
  this.#outputPath = path.resolve(this.#manifest.workspacePath, this.#manifest.outputFolder);
40
54
  this.#modules = Object.values(this.#manifest.modules);
41
55
 
@@ -153,28 +167,20 @@ export class CompilerState implements ts.CompilerHost {
153
167
  return [...this.#inputFiles];
154
168
  }
155
169
 
156
- /**
157
- * Used for translating non-project files (e.g. dependencies/node_modules) to the faux-root
158
- * that is used during compilation.
159
- */
160
- translateRawInput(input: string): string {
161
- return input.replace(this.#rootDir, this.#manifest.workspacePath);
162
- }
163
-
164
170
  /* Start Compiler Host */
165
171
  getCanonicalFileName(file: string): string { return file; }
166
- getCurrentDirectory(): string { return path.cwd(); }
172
+ getCurrentDirectory(): string { return this.#rootDir; }
167
173
  getDefaultLibFileName(opts: ts.CompilerOptions): string { return ts.getDefaultLibFileName(opts); }
168
174
  getNewLine(): string { return ts.sys.newLine; }
169
175
  useCaseSensitiveFileNames(): boolean { return ts.sys.useCaseSensitiveFileNames; }
170
176
  getDefaultLibLocation(): string { return path.dirname(ts.getDefaultLibFilePath(this.#compilerOptions)); }
171
177
 
172
178
  fileExists(inputFile: string): boolean {
173
- return this.#inputToEntry.has(inputFile) || ts.sys.fileExists(this.translateRawInput(inputFile));
179
+ return this.#inputToEntry.has(inputFile) || ts.sys.fileExists(this.#inputPathToSource(inputFile));
174
180
  }
175
181
 
176
182
  directoryExists(inputDir: string): boolean {
177
- return this.#inputDirectoryToSource.has(inputDir) || ts.sys.directoryExists(this.translateRawInput(inputDir));
183
+ return this.#inputDirectoryToSource.has(inputDir) || ts.sys.directoryExists(this.#inputPathToSource(inputDir));
178
184
  }
179
185
 
180
186
  writeFile(
@@ -197,7 +203,7 @@ export class CompilerState implements ts.CompilerHost {
197
203
 
198
204
  readFile(inputFile: string): string | undefined {
199
205
  const res = this.#sourceContents.get(inputFile) ?? ts.sys.readFile(
200
- this.#inputToEntry.get(inputFile)?.source ?? this.translateRawInput(inputFile)
206
+ this.#inputToEntry.get(inputFile)?.source ?? this.#inputPathToSource(inputFile)
201
207
  );
202
208
  this.#sourceContents.set(inputFile, res);
203
209
  return res;
package/support/log.ts CHANGED
@@ -10,7 +10,7 @@ export class LogUtil {
10
10
  debug: boolean;
11
11
  info: boolean;
12
12
  warn: boolean;
13
- }
13
+ };
14
14
 
15
15
  static set level(value: string) {
16
16
  this.levels = {