@nola-lang/typescript-plugin 0.1.4 → 0.1.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs +806 -492
- package/dist/runtime-stub-host.d.ts +39 -0
- package/dist/runtime-stub-host.d.ts.map +1 -0
- package/dist/runtime-stub-host.js +81 -0
- package/dist/runtime-stub-host.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* The virtual file the stub is served under — the same path `nola check`
|
|
4
|
+
* (tshost) uses for its bare-project fallback, so both tools name the one
|
|
5
|
+
* surface the same way.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RUNTIME_STUB_FILE = "/__nola_stubs__/runtime.d.ts";
|
|
8
|
+
/**
|
|
9
|
+
* Serves the compiler's ambient stub as `@nola-lang/runtime` whenever that
|
|
10
|
+
* specifier does NOT resolve from the importing file — the installed package
|
|
11
|
+
* wins every time it exists.
|
|
12
|
+
*
|
|
13
|
+
* Why: lowered code imports the runtime in its appendix. In a project where
|
|
14
|
+
* the package is not installed yet (the window between `npm create nola` and
|
|
15
|
+
* `npm install`, or a bare `.tsi` opened on its own) that import fails, and
|
|
16
|
+
* because the appendix is unmapped the TS2307 never reaches the editor —
|
|
17
|
+
* only its derivative does: `__nola` is `any`, so the wrapper's
|
|
18
|
+
* `(__frame) => …` loses its contextual type and the user sees "Parameter
|
|
19
|
+
* '__frame' implicitly has an 'any' type" on the infer function header.
|
|
20
|
+
* `nola check` answers the same situation with RUNTIME_AMBIENT_STUB (tshost's
|
|
21
|
+
* bare-project fallback); the editor hosts do the same here, so a .tsi is
|
|
22
|
+
* fully typed before the install and the editor agrees with `nola check`.
|
|
23
|
+
*
|
|
24
|
+
* The stub is resolved as an external-library file (no diagnostics of its
|
|
25
|
+
* own, like anything under node_modules) and served through the same four
|
|
26
|
+
* host seams companions use: resolveModuleNameLiterals (ONE batch call to the
|
|
27
|
+
* prior resolver — the full literal array, never per literal; see
|
|
28
|
+
* companion-host.ts for why tsserver's resolution cache needs that),
|
|
29
|
+
* fileExists / readFile / getScriptSnapshot / getScriptVersion.
|
|
30
|
+
*
|
|
31
|
+
* Note the stale window: Volar's language server caches a failed lookup until
|
|
32
|
+
* a watched-file event for that very path, and VS Code never reports
|
|
33
|
+
* `node_modules` changes (files.watcherExclude) — so after `npm install` the
|
|
34
|
+
* stub keeps serving until the window reloads. That is benign by design: the
|
|
35
|
+
* stub and the real `__nola` surface are held in lockstep
|
|
36
|
+
* (emit-surface.test.ts), so types do not change, only F12 targets do.
|
|
37
|
+
*/
|
|
38
|
+
export declare function decorateHostWithRuntimeStub(typescript: typeof ts, host: ts.LanguageServiceHost): void;
|
|
39
|
+
//# sourceMappingURL=runtime-stub-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-stub-host.d.ts","sourceRoot":"","sources":["../src/runtime-stub-host.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,iCAAiC,CAAC;AAQhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,mBAAmB,GAAG,IAAI,CA4CrG"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RUNTIME_AMBIENT_STUB } from "@nola-lang/compiler";
|
|
2
|
+
/**
|
|
3
|
+
* The virtual file the stub is served under — the same path `nola check`
|
|
4
|
+
* (tshost) uses for its bare-project fallback, so both tools name the one
|
|
5
|
+
* surface the same way.
|
|
6
|
+
*/
|
|
7
|
+
export const RUNTIME_STUB_FILE = "/__nola_stubs__/runtime.d.ts";
|
|
8
|
+
const RUNTIME_SPECIFIER = "@nola-lang/runtime";
|
|
9
|
+
function norm(p) {
|
|
10
|
+
return p.replace(/\\/g, "/");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Serves the compiler's ambient stub as `@nola-lang/runtime` whenever that
|
|
14
|
+
* specifier does NOT resolve from the importing file — the installed package
|
|
15
|
+
* wins every time it exists.
|
|
16
|
+
*
|
|
17
|
+
* Why: lowered code imports the runtime in its appendix. In a project where
|
|
18
|
+
* the package is not installed yet (the window between `npm create nola` and
|
|
19
|
+
* `npm install`, or a bare `.tsi` opened on its own) that import fails, and
|
|
20
|
+
* because the appendix is unmapped the TS2307 never reaches the editor —
|
|
21
|
+
* only its derivative does: `__nola` is `any`, so the wrapper's
|
|
22
|
+
* `(__frame) => …` loses its contextual type and the user sees "Parameter
|
|
23
|
+
* '__frame' implicitly has an 'any' type" on the infer function header.
|
|
24
|
+
* `nola check` answers the same situation with RUNTIME_AMBIENT_STUB (tshost's
|
|
25
|
+
* bare-project fallback); the editor hosts do the same here, so a .tsi is
|
|
26
|
+
* fully typed before the install and the editor agrees with `nola check`.
|
|
27
|
+
*
|
|
28
|
+
* The stub is resolved as an external-library file (no diagnostics of its
|
|
29
|
+
* own, like anything under node_modules) and served through the same four
|
|
30
|
+
* host seams companions use: resolveModuleNameLiterals (ONE batch call to the
|
|
31
|
+
* prior resolver — the full literal array, never per literal; see
|
|
32
|
+
* companion-host.ts for why tsserver's resolution cache needs that),
|
|
33
|
+
* fileExists / readFile / getScriptSnapshot / getScriptVersion.
|
|
34
|
+
*
|
|
35
|
+
* Note the stale window: Volar's language server caches a failed lookup until
|
|
36
|
+
* a watched-file event for that very path, and VS Code never reports
|
|
37
|
+
* `node_modules` changes (files.watcherExclude) — so after `npm install` the
|
|
38
|
+
* stub keeps serving until the window reloads. That is benign by design: the
|
|
39
|
+
* stub and the real `__nola` surface are held in lockstep
|
|
40
|
+
* (emit-surface.test.ts), so types do not change, only F12 targets do.
|
|
41
|
+
*/
|
|
42
|
+
export function decorateHostWithRuntimeStub(typescript, host) {
|
|
43
|
+
const isStub = (f) => norm(f) === RUNTIME_STUB_FILE;
|
|
44
|
+
let snapshot;
|
|
45
|
+
const stubSnapshot = () => {
|
|
46
|
+
snapshot ??= typescript.ScriptSnapshot.fromString(RUNTIME_AMBIENT_STUB);
|
|
47
|
+
return snapshot;
|
|
48
|
+
};
|
|
49
|
+
const priorResolve = host.resolveModuleNameLiterals?.bind(host);
|
|
50
|
+
host.resolveModuleNameLiterals = (literals, containingFile, redirected, opts, file, reused) => {
|
|
51
|
+
const base = priorResolve
|
|
52
|
+
? priorResolve(literals, containingFile, redirected, opts, file, reused)
|
|
53
|
+
: literals.map((literal) => typescript.resolveModuleName(literal.text, containingFile, opts, {
|
|
54
|
+
fileExists: (f) => host.fileExists?.(f) ?? typescript.sys.fileExists(f),
|
|
55
|
+
readFile: (f) => host.readFile?.(f) ?? typescript.sys.readFile(f),
|
|
56
|
+
directoryExists: host.directoryExists?.bind(host),
|
|
57
|
+
realpath: host.realpath?.bind(host),
|
|
58
|
+
}));
|
|
59
|
+
return literals.map((literal, i) => {
|
|
60
|
+
const result = base[i];
|
|
61
|
+
if (literal.text !== RUNTIME_SPECIFIER || result.resolvedModule)
|
|
62
|
+
return result;
|
|
63
|
+
return {
|
|
64
|
+
resolvedModule: {
|
|
65
|
+
resolvedFileName: RUNTIME_STUB_FILE,
|
|
66
|
+
extension: typescript.Extension.Dts,
|
|
67
|
+
isExternalLibraryImport: true,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const priorFileExists = host.fileExists?.bind(host);
|
|
73
|
+
host.fileExists = (f) => isStub(f) || (priorFileExists?.(f) ?? false);
|
|
74
|
+
const priorReadFile = host.readFile?.bind(host);
|
|
75
|
+
host.readFile = (f, encoding) => (isStub(f) ? RUNTIME_AMBIENT_STUB : priorReadFile?.(f, encoding));
|
|
76
|
+
const priorGetSnapshot = host.getScriptSnapshot.bind(host);
|
|
77
|
+
host.getScriptSnapshot = (f) => (isStub(f) ? stubSnapshot() : priorGetSnapshot(f));
|
|
78
|
+
const priorGetVersion = host.getScriptVersion.bind(host);
|
|
79
|
+
host.getScriptVersion = (f) => (isStub(f) ? "nola-runtime-stub" : priorGetVersion(f));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=runtime-stub-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-stub-host.js","sourceRoot":"","sources":["../src/runtime-stub-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEhE,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAE/C,SAAS,IAAI,CAAC,CAAS;IACrB,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,2BAA2B,CAAC,UAAqB,EAAE,IAA4B;IAC7F,MAAM,MAAM,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC;IACrE,IAAI,QAAwC,CAAC;IAC7C,MAAM,YAAY,GAAG,GAAuB,EAAE;QAC5C,QAAQ,KAAK,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;QACxE,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,IAAI,CAAC,yBAAyB,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,MAA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C,IAAI,CAAC,CAAC;IACpD,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnG,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnF,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nola-lang/typescript-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "tsserver plugin serving .tsi to TypeScript editors (internal editor layer)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nola"
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"bundle": "node scripts/bundle.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nola-lang/compiler": "0.1.
|
|
40
|
-
"@nola-lang/language-core": "0.1.
|
|
41
|
-
"@nola-lang/node-loader": "0.1.
|
|
39
|
+
"@nola-lang/compiler": "0.1.5",
|
|
40
|
+
"@nola-lang/language-core": "0.1.5",
|
|
41
|
+
"@nola-lang/node-loader": "0.1.5",
|
|
42
42
|
"@volar/typescript": "2.4.28"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|