@swiftuijs/twill 0.1.0
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/LICENSE +21 -0
- package/README.md +138 -0
- package/bin/twill.mjs +12 -0
- package/dist/branches.d.ts +12 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +128 -0
- package/dist/cli.js.map +1 -0
- package/dist/compiler-Bi9TNOhX.js +1127 -0
- package/dist/compiler-Bi9TNOhX.js.map +1 -0
- package/dist/compiler.d.ts +50 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/declarations.d.ts +14 -0
- package/dist/declarations.js +132 -0
- package/dist/declarations.js.map +1 -0
- package/dist/defer.d.ts +17 -0
- package/dist/doctor.d.ts +20 -0
- package/dist/doctor.js +198 -0
- package/dist/doctor.js.map +1 -0
- package/dist/editor.d.ts +53 -0
- package/dist/editor.js +261 -0
- package/dist/editor.js.map +1 -0
- package/dist/esbuild.d.ts +3 -0
- package/dist/esbuild.js +7 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/files-D1mERoxc.js +46 -0
- package/dist/files-D1mERoxc.js.map +1 -0
- package/dist/files.d.ts +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/loader.d.ts +3 -0
- package/dist/loader.js +54 -0
- package/dist/loader.js.map +1 -0
- package/dist/parser.d.ts +9 -0
- package/dist/plugin-BGabvyT6.js +112 -0
- package/dist/plugin-BGabvyT6.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/project.d.ts +62 -0
- package/dist/project.js +416 -0
- package/dist/project.js.map +1 -0
- package/dist/recovery.d.ts +3 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +7 -0
- package/dist/register.js.map +1 -0
- package/dist/rollup.d.ts +3 -0
- package/dist/rollup.js +7 -0
- package/dist/rollup.js.map +1 -0
- package/dist/rspack.d.ts +3 -0
- package/dist/rspack.js +7 -0
- package/dist/rspack.js.map +1 -0
- package/dist/syntax.d.ts +11 -0
- package/dist/syntax.js +10 -0
- package/dist/syntax.js.map +1 -0
- package/dist/transpile-DwVekVFM.js +51 -0
- package/dist/transpile-DwVekVFM.js.map +1 -0
- package/dist/transpile.d.ts +11 -0
- package/dist/typescript-plugin.LICENSE.txt +375 -0
- package/dist/typescript-plugin.cjs +17741 -0
- package/dist/typescript-plugin.cjs.map +1 -0
- package/dist/typescript-plugin.d.ts +5 -0
- package/dist/vite-react.d.ts +10 -0
- package/dist/vite-react.js +22 -0
- package/dist/vite-react.js.map +1 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +7 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +7 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +180 -0
- package/schemas/twill.schema.json +16 -0
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const sourceExtensions: string[];
|
|
2
|
+
export declare function isDependency(filename: string): boolean;
|
|
3
|
+
export declare function needsTypeEmission(filename: string): boolean;
|
|
4
|
+
export declare function splitId(id: string): [string, string];
|
|
5
|
+
export declare function resolveSourceFile(base: string): string | undefined;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as isTwillFile, i as inferLanguage, n as extensions, o as originalPosition, r as generatedPosition, s as transform, t as TwillSyntaxError } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
export { TwillSyntaxError, extensions, generatedPosition, inferLanguage, isTwillFile, originalPosition, transform };
|
package/dist/loader.d.ts
ADDED
package/dist/loader.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { a as isTwillFile } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
import { loadConfig } from "./config.js";
|
|
3
|
+
import { n as needsTypeEmission, r as resolveSourceFile, t as isDependency } from "./files-D1mERoxc.js";
|
|
4
|
+
import { n as transpileNative, t as transpile } from "./transpile-DwVekVFM.js";
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { dirname, resolve as resolve$1 } from "node:path";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
//#region src/loader.ts
|
|
10
|
+
function configuration(filename) {
|
|
11
|
+
let root = dirname(filename);
|
|
12
|
+
for (;;) {
|
|
13
|
+
if (existsSync(resolve$1(root, "twill.config.json")) || existsSync(resolve$1(root, "tsconfig.json"))) return loadConfig(root);
|
|
14
|
+
const parent = dirname(root);
|
|
15
|
+
if (parent === root) return {};
|
|
16
|
+
root = parent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
var resolve = async (specifier, context, nextResolve) => {
|
|
20
|
+
try {
|
|
21
|
+
return await nextResolve(specifier, context);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT"].includes(error.code ?? "") && specifier.startsWith(".") && context.parentURL?.startsWith("file:")) {
|
|
24
|
+
const target = new URL(specifier, context.parentURL);
|
|
25
|
+
const base = fileURLToPath(target);
|
|
26
|
+
const candidate = resolveSourceFile(base);
|
|
27
|
+
if (candidate) return {
|
|
28
|
+
url: pathToFileURL(candidate).href + target.search + target.hash,
|
|
29
|
+
shortCircuit: true
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var load = async (url, context, nextLoad) => {
|
|
36
|
+
if (!url.startsWith("file:")) return nextLoad(url, context);
|
|
37
|
+
const filename = fileURLToPath(url);
|
|
38
|
+
const dialect = isTwillFile(filename);
|
|
39
|
+
if (!dialect && (isDependency(filename) || !needsTypeEmission(filename))) return nextLoad(url, context);
|
|
40
|
+
const source = readFileSync(filename, "utf8");
|
|
41
|
+
const result = dialect ? transpile(source, {
|
|
42
|
+
...configuration(filename),
|
|
43
|
+
filename
|
|
44
|
+
}, ts.ScriptTarget.ES2022) : transpileNative(source, filename, void 0, void 0, configuration(filename).jsxImportSource, ts.ScriptTarget.ES2022);
|
|
45
|
+
return {
|
|
46
|
+
format: "module",
|
|
47
|
+
source: result.code + "\n//# sourceMappingURL=data:application/json;base64," + Buffer.from(result.map).toString("base64"),
|
|
48
|
+
shortCircuit: true
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { load, resolve };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","names":["resolvePath"],"sources":["../src/loader.ts"],"sourcesContent":["import { readFileSync, existsSync } from 'node:fs';\nimport { dirname, resolve as resolvePath } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type { ResolveHook, LoadHook } from 'node:module';\nimport { isTwillFile } from './compiler.js';\nimport { transpile, transpileNative } from './transpile.js';\nimport { loadConfig } from './config.js';\nimport { isDependency, needsTypeEmission, resolveSourceFile } from './files.js';\nimport ts from 'typescript';\n\nfunction configuration(filename: string) {\n let root = dirname(filename);\n for (;;) {\n if (\n existsSync(resolvePath(root, 'twill.config.json')) ||\n existsSync(resolvePath(root, 'tsconfig.json'))\n )\n return loadConfig(root);\n const parent = dirname(root);\n if (parent === root) return {};\n root = parent;\n }\n}\n\nexport const resolve: ResolveHook = async (specifier, context, nextResolve) => {\n try {\n return await nextResolve(specifier, context);\n } catch (error) {\n if (\n ['ERR_MODULE_NOT_FOUND', 'ERR_UNSUPPORTED_DIR_IMPORT'].includes(\n (error as NodeJS.ErrnoException).code ?? '',\n ) &&\n specifier.startsWith('.') &&\n context.parentURL?.startsWith('file:')\n ) {\n const target = new URL(specifier, context.parentURL);\n const base = fileURLToPath(target);\n const candidate = resolveSourceFile(base);\n if (candidate)\n return {\n url: pathToFileURL(candidate).href + target.search + target.hash,\n shortCircuit: true,\n };\n }\n throw error;\n }\n};\n\nexport const load: LoadHook = async (url, context, nextLoad) => {\n if (!url.startsWith('file:')) return nextLoad(url, context);\n const filename = fileURLToPath(url);\n const dialect = isTwillFile(filename);\n if (!dialect && (isDependency(filename) || !needsTypeEmission(filename)))\n return nextLoad(url, context);\n const source = readFileSync(filename, 'utf8');\n const result = dialect\n ? transpile(source, { ...configuration(filename), filename }, ts.ScriptTarget.ES2022)\n : transpileNative(\n source,\n filename,\n undefined,\n undefined,\n configuration(filename).jsxImportSource,\n ts.ScriptTarget.ES2022,\n );\n return {\n format: 'module',\n source:\n result.code +\n '\\n//# sourceMappingURL=data:application/json;base64,' +\n Buffer.from(result.map).toString('base64'),\n shortCircuit: true,\n };\n};\n"],"mappings":";;;;;;;;;AAUA,SAAS,cAAc,UAAkB;CACvC,IAAI,OAAO,QAAQ,QAAQ;CAC3B,SAAS;EACP,IACE,WAAWA,UAAY,MAAM,mBAAmB,CAAC,KACjD,WAAWA,UAAY,MAAM,eAAe,CAAC,GAE7C,OAAO,WAAW,IAAI;EACxB,MAAM,SAAS,QAAQ,IAAI;EAC3B,IAAI,WAAW,MAAM,OAAO,CAAC;EAC7B,OAAO;CACT;AACF;AAEA,IAAa,UAAuB,OAAO,WAAW,SAAS,gBAAgB;CAC7E,IAAI;EACF,OAAO,MAAM,YAAY,WAAW,OAAO;CAC7C,SAAS,OAAO;EACd,IACE,CAAC,wBAAwB,4BAA4B,CAAC,CAAC,SACpD,MAAgC,QAAQ,EAC3C,KACA,UAAU,WAAW,GAAG,KACxB,QAAQ,WAAW,WAAW,OAAO,GACrC;GACA,MAAM,SAAS,IAAI,IAAI,WAAW,QAAQ,SAAS;GACnD,MAAM,OAAO,cAAc,MAAM;GACjC,MAAM,YAAY,kBAAkB,IAAI;GACxC,IAAI,WACF,OAAO;IACL,KAAK,cAAc,SAAS,CAAC,CAAC,OAAO,OAAO,SAAS,OAAO;IAC5D,cAAc;GAChB;EACJ;EACA,MAAM;CACR;AACF;AAEA,IAAa,OAAiB,OAAO,KAAK,SAAS,aAAa;CAC9D,IAAI,CAAC,IAAI,WAAW,OAAO,GAAG,OAAO,SAAS,KAAK,OAAO;CAC1D,MAAM,WAAW,cAAc,GAAG;CAClC,MAAM,UAAU,YAAY,QAAQ;CACpC,IAAI,CAAC,YAAY,aAAa,QAAQ,KAAK,CAAC,kBAAkB,QAAQ,IACpE,OAAO,SAAS,KAAK,OAAO;CAC9B,MAAM,SAAS,aAAa,UAAU,MAAM;CAC5C,MAAM,SAAS,UACX,UAAU,QAAQ;EAAE,GAAG,cAAc,QAAQ;EAAG;CAAS,GAAG,GAAG,aAAa,MAAM,IAClF,gBACE,QACA,UACA,KAAA,GACA,KAAA,GACA,cAAc,QAAQ,CAAC,CAAC,iBACxB,GAAG,aAAa,MAClB;CACJ,OAAO;EACL,QAAQ;EACR,QACE,OAAO,OACP,yDACA,OAAO,KAAK,OAAO,GAAG,CAAC,CAAC,SAAS,QAAQ;EAC3C,cAAc;CAChB;AACF"}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { a as isTwillFile } from "./compiler-Bi9TNOhX.js";
|
|
2
|
+
import { configurationFiles, loadConfig } from "./config.js";
|
|
3
|
+
import { a as splitId, i as sourceExtensions, n as needsTypeEmission, r as resolveSourceFile, t as isDependency } from "./files-D1mERoxc.js";
|
|
4
|
+
import { n as transpileNative, t as transpile } from "./transpile-DwVekVFM.js";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
7
|
+
import { createUnplugin } from "unplugin";
|
|
8
|
+
//#region src/plugin.ts
|
|
9
|
+
var twillPlugin = createUnplugin((options = {}, meta) => {
|
|
10
|
+
let root = options.root ?? process.cwd();
|
|
11
|
+
let config = {
|
|
12
|
+
...loadConfig(root),
|
|
13
|
+
...options
|
|
14
|
+
};
|
|
15
|
+
let servingVite = false;
|
|
16
|
+
const nativeSources = options.nativeSources ?? !["vite", "esbuild"].includes(meta.framework);
|
|
17
|
+
return {
|
|
18
|
+
name: "twill",
|
|
19
|
+
enforce: "pre",
|
|
20
|
+
esbuild: { setup(build) {
|
|
21
|
+
build.onResolve({
|
|
22
|
+
filter: /.*/,
|
|
23
|
+
namespace: "twill"
|
|
24
|
+
}, (args) => build.resolve(args.path, {
|
|
25
|
+
resolveDir: dirname(args.importer),
|
|
26
|
+
kind: args.kind
|
|
27
|
+
}));
|
|
28
|
+
} },
|
|
29
|
+
vite: {
|
|
30
|
+
configResolved(viteConfig) {
|
|
31
|
+
root = options.root ?? viteConfig.root;
|
|
32
|
+
config = {
|
|
33
|
+
...loadConfig(root),
|
|
34
|
+
...options
|
|
35
|
+
};
|
|
36
|
+
servingVite = viteConfig.command === "serve";
|
|
37
|
+
},
|
|
38
|
+
config() {
|
|
39
|
+
return { resolve: { extensions: sourceExtensions } };
|
|
40
|
+
},
|
|
41
|
+
configureServer(server) {
|
|
42
|
+
let files = new Set(configurationFiles(root).map((file) => resolve(file)));
|
|
43
|
+
const watch = () => server.watcher.add([...files].map((file) => existsSync(file) ? file : dirname(file)));
|
|
44
|
+
watch();
|
|
45
|
+
let update;
|
|
46
|
+
const changed = (filename) => {
|
|
47
|
+
if (files.has(resolve(filename))) {
|
|
48
|
+
clearTimeout(update);
|
|
49
|
+
update = setTimeout(() => {
|
|
50
|
+
try {
|
|
51
|
+
config = {
|
|
52
|
+
...loadConfig(root),
|
|
53
|
+
...options
|
|
54
|
+
};
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
57
|
+
server.config.logger.error(error.message);
|
|
58
|
+
server.ws.send({
|
|
59
|
+
type: "error",
|
|
60
|
+
err: {
|
|
61
|
+
message: error.message,
|
|
62
|
+
stack: error.stack ?? "",
|
|
63
|
+
plugin: "twill"
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
files = new Set(configurationFiles(root).map((file) => resolve(file)));
|
|
69
|
+
watch();
|
|
70
|
+
if (server.environments) for (const environment of Object.values(server.environments)) environment.moduleGraph.invalidateAll();
|
|
71
|
+
else server.moduleGraph.invalidateAll();
|
|
72
|
+
server.ws.send({ type: "full-reload" });
|
|
73
|
+
}, 75);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
server.watcher.on("change", changed).on("add", changed).on("unlink", changed);
|
|
77
|
+
server.httpServer?.once("close", () => clearTimeout(update));
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
resolveId(id, importer) {
|
|
81
|
+
if (options.resolveExtensions === false || !id.startsWith(".") && !isAbsolute(id)) return null;
|
|
82
|
+
const [path, query] = splitId(id);
|
|
83
|
+
const base = isAbsolute(path) ? path : resolve(importer ? dirname(splitId(importer)[0]) : root, path);
|
|
84
|
+
const candidate = resolveSourceFile(base);
|
|
85
|
+
if (!candidate || candidate === base) return null;
|
|
86
|
+
if (meta.framework === "esbuild" && !isTwillFile(candidate)) return null;
|
|
87
|
+
return candidate + query;
|
|
88
|
+
},
|
|
89
|
+
transformInclude(id) {
|
|
90
|
+
const filename = splitId(id)[0];
|
|
91
|
+
return !isDependency(filename) && (isTwillFile(filename) || nativeSources && needsTypeEmission(filename));
|
|
92
|
+
},
|
|
93
|
+
transform(source, id) {
|
|
94
|
+
const filename = splitId(id)[0];
|
|
95
|
+
if (isDependency(filename)) return null;
|
|
96
|
+
if (isTwillFile(filename)) {
|
|
97
|
+
if (!servingVite) {
|
|
98
|
+
for (const file of configurationFiles(root)) if (existsSync(file)) this.addWatchFile(file);
|
|
99
|
+
}
|
|
100
|
+
return transpile(source, {
|
|
101
|
+
...config,
|
|
102
|
+
filename
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return nativeSources && needsTypeEmission(filename) ? transpileNative(source, filename, void 0, void 0, config.jsxImportSource) : null;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
//#endregion
|
|
110
|
+
export { twillPlugin as t };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=plugin-BGabvyT6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-BGabvyT6.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { dirname, isAbsolute, resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { createUnplugin } from 'unplugin';\nimport { isTwillFile, type TransformOptions } from './compiler.js';\nimport { loadConfig, configurationFiles } from './config.js';\nimport { transpile, transpileNative } from './transpile.js';\nimport {\n isDependency,\n needsTypeEmission,\n splitId,\n resolveSourceFile,\n sourceExtensions,\n} from './files.js';\n\nexport interface PluginOptions extends Omit<TransformOptions, 'filename' | 'language'> {\n root?: string;\n /** Resolve relative extensionless native/Twill sources. Defaults to true. */\n resolveExtensions?: boolean;\n /** Native TS/JSX emission: defaults off for Vite/esbuild, on for Rollup/webpack/rspack. */\n nativeSources?: boolean;\n}\n\nexport const twillPlugin = createUnplugin<PluginOptions | undefined, false>(\n (options = {}, meta) => {\n let root = options.root ?? process.cwd();\n let config = { ...loadConfig(root), ...options };\n let servingVite = false;\n // Reuse native host emission where it already exists.\n const nativeSources = options.nativeSources ?? !['vite', 'esbuild'].includes(meta.framework);\n return {\n name: 'twill',\n enforce: 'pre',\n esbuild: {\n setup(build) {\n // unplugin tags its resolved files with a custom namespace. Native\n // dependencies of those files must re-enter esbuild's normal resolver.\n build.onResolve({ filter: /.*/, namespace: 'twill' }, (args) =>\n build.resolve(args.path, {\n resolveDir: dirname(args.importer),\n kind: args.kind,\n }),\n );\n },\n },\n vite: {\n configResolved(viteConfig) {\n root = options.root ?? viteConfig.root;\n config = { ...loadConfig(root), ...options };\n servingVite = viteConfig.command === 'serve';\n },\n config() {\n return {\n resolve: {\n extensions: sourceExtensions,\n },\n };\n },\n configureServer(server) {\n let files = new Set(configurationFiles(root).map((file) => resolve(file)));\n // Watch the parent of an absent file. Registering a missing path\n // directly can narrow Chokidar's directory filter and lose additions.\n const watch = () =>\n server.watcher.add([...files].map((file) => (existsSync(file) ? file : dirname(file))));\n watch();\n let update: ReturnType<typeof setTimeout> | undefined;\n const changed = (filename: string) => {\n if (files.has(resolve(filename))) {\n clearTimeout(update);\n // Chokidar throttles rapid changes for 50 ms. Read after that\n // window so consecutive saves use the final contents, and a\n // correction after an error overlay produces another event.\n update = setTimeout(() => {\n try {\n config = { ...loadConfig(root), ...options };\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n server.config.logger.error(error.message);\n server.ws.send({\n type: 'error',\n err: { message: error.message, stack: error.stack ?? '', plugin: 'twill' },\n });\n return;\n }\n files = new Set(configurationFiles(root).map((file) => resolve(file)));\n watch();\n if (server.environments)\n for (const environment of Object.values(server.environments))\n environment.moduleGraph.invalidateAll();\n else server.moduleGraph.invalidateAll();\n server.ws.send({ type: 'full-reload' });\n }, 75);\n }\n };\n server.watcher.on('change', changed).on('add', changed).on('unlink', changed);\n server.httpServer?.once('close', () => clearTimeout(update));\n // Chokidar removes listeners when the watcher closes. HTTP can close\n // and reopen independently of the watcher during server setup.\n },\n },\n resolveId(id, importer) {\n if (options.resolveExtensions === false || (!id.startsWith('.') && !isAbsolute(id)))\n return null;\n const [path, query] = splitId(id);\n const base = isAbsolute(path!)\n ? path!\n : resolve(importer ? dirname(splitId(importer)[0]) : root, path!);\n const candidate = resolveSourceFile(base);\n if (!candidate || candidate === base) return null;\n if (meta.framework === 'esbuild' && !isTwillFile(candidate)) return null;\n return candidate + query;\n },\n transformInclude(id) {\n const filename = splitId(id)[0];\n return (\n !isDependency(filename) &&\n (isTwillFile(filename) || (nativeSources && needsTypeEmission(filename)))\n );\n },\n transform(source, id) {\n const filename = splitId(id)[0];\n if (isDependency(filename)) return null;\n if (isTwillFile(filename)) {\n // Vite's dev import analysis treats addWatchFile as a browser import.\n // Watch config with the server instead; a missing optional config\n // must never become an unresolved browser module.\n if (!servingVite)\n for (const file of configurationFiles(root))\n if (existsSync(file)) this.addWatchFile(file);\n return transpile(source, { ...config, filename });\n }\n return nativeSources && needsTypeEmission(filename)\n ? transpileNative(source, filename, undefined, undefined, config.jsxImportSource)\n : null;\n },\n };\n },\n);\n"],"mappings":"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"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TransformOptions } from './compiler.js';
|
|
2
|
+
export interface PluginOptions extends Omit<TransformOptions, 'filename' | 'language'> {
|
|
3
|
+
root?: string;
|
|
4
|
+
/** Resolve relative extensionless native/Twill sources. Defaults to true. */
|
|
5
|
+
resolveExtensions?: boolean;
|
|
6
|
+
/** Native TS/JSX emission: defaults off for Vite/esbuild, on for Rollup/webpack/rspack. */
|
|
7
|
+
nativeSources?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const twillPlugin: import('unplugin').UnpluginInstance<PluginOptions | undefined, false>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
import { TransformOptions, TransformResult } from './compiler.js';
|
|
3
|
+
export { isDependency } from './files.js';
|
|
4
|
+
export declare function virtualFilename(filename: string): string;
|
|
5
|
+
export declare function sourceFilename(filename: string): string;
|
|
6
|
+
export interface ProjectDiagnostic {
|
|
7
|
+
filename?: string;
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
length: number;
|
|
11
|
+
code: number;
|
|
12
|
+
category: 'error' | 'warning' | 'message';
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
/** A virtual-source TypeScript project shared by the CLI and VS Code extension. */
|
|
16
|
+
export declare class TwillProject {
|
|
17
|
+
readonly root: string;
|
|
18
|
+
readonly service: ts.LanguageService;
|
|
19
|
+
readonly compilerOptions: ts.CompilerOptions;
|
|
20
|
+
readonly configFiles: readonly string[];
|
|
21
|
+
private files;
|
|
22
|
+
private overlays;
|
|
23
|
+
private results;
|
|
24
|
+
private lineMaps;
|
|
25
|
+
private version;
|
|
26
|
+
private invalidation;
|
|
27
|
+
private fileVersions;
|
|
28
|
+
private configurationErrors;
|
|
29
|
+
private options;
|
|
30
|
+
private readonly host;
|
|
31
|
+
private recover;
|
|
32
|
+
private discoverFiles;
|
|
33
|
+
constructor(tsconfig: string, options?: TransformOptions, projectOptions?: {
|
|
34
|
+
inferred?: boolean;
|
|
35
|
+
recover?: boolean;
|
|
36
|
+
defaultLibFileName?: (options: ts.CompilerOptions) => string;
|
|
37
|
+
declarationRedirects?: ReadonlyMap<string, string>;
|
|
38
|
+
});
|
|
39
|
+
/** Declaration-only native TypeScript emit from the checked virtual program. */
|
|
40
|
+
declarationOutput(outDir: string, declarationMap?: boolean): {
|
|
41
|
+
diagnostics: ProjectDiagnostic[];
|
|
42
|
+
files: {
|
|
43
|
+
filename: string;
|
|
44
|
+
text: string;
|
|
45
|
+
sources: string[];
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
private result;
|
|
49
|
+
update(filename: string, text?: string): void;
|
|
50
|
+
invalidate(): void;
|
|
51
|
+
/** Refresh a disk version without discarding unsaved overlays or other transforms. */
|
|
52
|
+
refresh(filename: string, discover?: boolean): void;
|
|
53
|
+
text(filename: string): string | undefined;
|
|
54
|
+
transformed(filename: string): TransformResult | undefined;
|
|
55
|
+
sourceFiles(): string[];
|
|
56
|
+
private lines;
|
|
57
|
+
toGeneratedOffset(filename: string, offset: number): number;
|
|
58
|
+
toOriginalOffset(filename: string, offset: number): number;
|
|
59
|
+
private diagnostic;
|
|
60
|
+
diagnostics(filename?: string): ProjectDiagnostic[];
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|