@glint/ember-tsc 1.7.0 → 1.7.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"run-volar-tsc.d.ts","sourceRoot":"","sources":["../../src/cli/run-volar-tsc.ts"],"names":[],"mappings":"AAOA,wBAAgB,GAAG,IAAI,IAAI,CA6B1B"}
1
+ {"version":3,"file":"run-volar-tsc.d.ts","sourceRoot":"","sources":["../../src/cli/run-volar-tsc.ts"],"names":[],"mappings":"AAWA,wBAAgB,GAAG,IAAI,IAAI,CA+B1B"}
@@ -3,7 +3,12 @@ import { createEmberLanguagePlugin } from '../volar/ember-language-plugin.js';
3
3
  import { findConfig } from '../config/index.js';
4
4
  import { createRequire } from 'node:module';
5
5
  const require = createRequire(import.meta.url);
6
+ // Loaded via CJS require so we can monkey-patch readFileSync; the ESM namespace
7
+ // object would be frozen.
8
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
9
+ const fs = require('node:fs');
6
10
  export function run() {
11
+ patchVolarProxyForExtensionlessImports();
7
12
  let cwd = process.cwd();
8
13
  const options = {
9
14
  extraSupportedExtensions: ['.gjs', '.gts'],
@@ -29,4 +34,43 @@ export function run() {
29
34
  });
30
35
  main();
31
36
  }
37
+ // Volar's proxyCreateProgram fast-paths module resolution back to the
38
+ // original compiler host when no import literal ends in a `.gts`/`.gjs`
39
+ // extension. In one-shot `tsc` the original host has no resolver, so volar's
40
+ // wrapper (which makes `Bang.gts` look like `Bang.d.ts` to tsc's extensionless
41
+ // resolver via `resolveHiddenExtensions`) runs and extensionless imports work.
42
+ // But `tsc --watch` installs a cached resolver on the host before volar's
43
+ // proxy runs, so extensionless `.gts` imports skip the wrapper and fail with
44
+ // TS2307. Patch the compiled volar source so the fast-path is also disabled
45
+ // whenever any plugin sets `resolveHiddenExtensions: true`.
46
+ //
47
+ // Upstream fix: https://github.com/volarjs/volar.js/pull/309 — once that ships
48
+ // in a `@volar/typescript` release we depend on, this monkey-patch can go.
49
+ // Tracking: https://github.com/typed-ember/glint/issues/806
50
+ function patchVolarProxyForExtensionlessImports() {
51
+ const originalReadFileSync = fs.readFileSync;
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ fs.readFileSync = function (...args) {
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ const result = originalReadFileSync.apply(fs, args);
56
+ const filePath = args[0];
57
+ if (typeof filePath === 'string' && filePath.endsWith('/proxyCreateProgram.js')) {
58
+ const text = typeof result === 'string' ? result : result.toString('utf8');
59
+ const patched = applyProxyPatches(text);
60
+ return typeof result === 'string' ? patched : Buffer.from(patched);
61
+ }
62
+ return result;
63
+ };
64
+ }
65
+ function applyProxyPatches(source) {
66
+ const guard = '!languagePlugins.some(p => p.typescript?.resolveHiddenExtensions) && ';
67
+ const literalsPattern = /(if \(resolveModuleNameLiterals\s+&& )(moduleLiterals\.every\(name => !pluginExtensions\.some\(ext => name\.text\.endsWith\(ext\)\)\)\) \{)/;
68
+ const namesPattern = /(if \(resolveModuleNames && )(moduleNames\.every\(name => !pluginExtensions\.some\(ext => name\.endsWith\(ext\)\)\)\) \{)/;
69
+ if (!literalsPattern.test(source) || !namesPattern.test(source)) {
70
+ throw new Error('[glint] failed to patch @volar/typescript proxyCreateProgram.js: ' +
71
+ 'fast-path conditions not found in expected shape. ' +
72
+ 'The volar dep may have changed; update applyProxyPatches() in run-volar-tsc.ts.');
73
+ }
74
+ return source.replace(literalsPattern, `$1${guard}$2`).replace(namesPattern, `$1${guard}$2`);
75
+ }
32
76
  //# sourceMappingURL=run-volar-tsc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-volar-tsc.js","sourceRoot":"","sources":["../../src/cli/run-volar-tsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,UAAU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6 @@
1
1
  {
2
2
  "name": "@glint/ember-tsc",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "repository": "typed-ember/glint",
5
5
  "description": "A CLI for performing typechecking on Glimmer templates",
6
6
  "license": "MIT",
@@ -4,8 +4,14 @@ import { findConfig } from '../config/index.js';
4
4
 
5
5
  import { createRequire } from 'node:module';
6
6
  const require = createRequire(import.meta.url);
7
+ // Loaded via CJS require so we can monkey-patch readFileSync; the ESM namespace
8
+ // object would be frozen.
9
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
10
+ const fs = require('node:fs') as typeof import('node:fs');
7
11
 
8
12
  export function run(): void {
13
+ patchVolarProxyForExtensionlessImports();
14
+
9
15
  let cwd = process.cwd();
10
16
 
11
17
  const options = {
@@ -35,3 +41,51 @@ export function run(): void {
35
41
  });
36
42
  main();
37
43
  }
44
+
45
+ // Volar's proxyCreateProgram fast-paths module resolution back to the
46
+ // original compiler host when no import literal ends in a `.gts`/`.gjs`
47
+ // extension. In one-shot `tsc` the original host has no resolver, so volar's
48
+ // wrapper (which makes `Bang.gts` look like `Bang.d.ts` to tsc's extensionless
49
+ // resolver via `resolveHiddenExtensions`) runs and extensionless imports work.
50
+ // But `tsc --watch` installs a cached resolver on the host before volar's
51
+ // proxy runs, so extensionless `.gts` imports skip the wrapper and fail with
52
+ // TS2307. Patch the compiled volar source so the fast-path is also disabled
53
+ // whenever any plugin sets `resolveHiddenExtensions: true`.
54
+ //
55
+ // Upstream fix: https://github.com/volarjs/volar.js/pull/309 — once that ships
56
+ // in a `@volar/typescript` release we depend on, this monkey-patch can go.
57
+ // Tracking: https://github.com/typed-ember/glint/issues/806
58
+ function patchVolarProxyForExtensionlessImports(): void {
59
+ const originalReadFileSync = fs.readFileSync;
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ (fs as any).readFileSync = function (...args: unknown[]) {
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ const result = (originalReadFileSync as any).apply(fs, args);
64
+ const filePath = args[0];
65
+ if (typeof filePath === 'string' && filePath.endsWith('/proxyCreateProgram.js')) {
66
+ const text = typeof result === 'string' ? result : (result as Buffer).toString('utf8');
67
+ const patched = applyProxyPatches(text);
68
+ return typeof result === 'string' ? patched : Buffer.from(patched);
69
+ }
70
+ return result;
71
+ };
72
+ }
73
+
74
+ function applyProxyPatches(source: string): string {
75
+ const guard = '!languagePlugins.some(p => p.typescript?.resolveHiddenExtensions) && ';
76
+
77
+ const literalsPattern =
78
+ /(if \(resolveModuleNameLiterals\s+&& )(moduleLiterals\.every\(name => !pluginExtensions\.some\(ext => name\.text\.endsWith\(ext\)\)\)\) \{)/;
79
+ const namesPattern =
80
+ /(if \(resolveModuleNames && )(moduleNames\.every\(name => !pluginExtensions\.some\(ext => name\.endsWith\(ext\)\)\)\) \{)/;
81
+
82
+ if (!literalsPattern.test(source) || !namesPattern.test(source)) {
83
+ throw new Error(
84
+ '[glint] failed to patch @volar/typescript proxyCreateProgram.js: ' +
85
+ 'fast-path conditions not found in expected shape. ' +
86
+ 'The volar dep may have changed; update applyProxyPatches() in run-volar-tsc.ts.',
87
+ );
88
+ }
89
+
90
+ return source.replace(literalsPattern, `$1${guard}$2`).replace(namesPattern, `$1${guard}$2`);
91
+ }