@swiftuijs/twill 0.3.0 → 0.4.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/README.md +8 -3
- package/bin/run.mjs +2 -2
- package/dist/branches.d.ts +7 -1
- package/dist/cli.js +7 -8
- package/dist/{compilation-cache-7SugqJ4n.js → compilation-cache-BrV71YKt.js} +2 -3
- package/dist/{compilation-cache-7SugqJ4n.js.map → compilation-cache-BrV71YKt.js.map} +1 -1
- package/dist/{compiler-CbNSBUI2.js → compiler-DI0H4d1R.js} +178 -66
- package/dist/compiler-DI0H4d1R.js.map +1 -0
- package/dist/compiler.d.ts +2 -0
- package/dist/config-la_KkjCS.js +1 -0
- package/dist/config.js +2 -2
- package/dist/{configuration-BVMf6Q_j.js → configuration-ppqhmuy4.js} +7 -5
- package/dist/configuration-ppqhmuy4.js.map +1 -0
- package/dist/configuration.d.ts +1 -1
- package/dist/declarations-DXtb1AHP.js +131 -0
- package/dist/declarations-DXtb1AHP.js.map +1 -0
- package/dist/declarations.js +1 -132
- package/dist/doctor-BHwU_YBw.js +200 -0
- package/dist/doctor-BHwU_YBw.js.map +1 -0
- package/dist/doctor.js +1 -202
- package/dist/editor.d.ts +1 -0
- package/dist/editor.js +31 -5
- package/dist/editor.js.map +1 -1
- package/dist/esbuild.js +2 -3
- package/dist/{extensions-B1xTkoYP.js → extensions-7ixttcoK.js} +2 -3
- package/dist/{extensions-B1xTkoYP.js.map → extensions-7ixttcoK.js.map} +1 -1
- package/dist/{files-BW9geU0_.js → files-CgwJJ992.js} +3 -4
- package/dist/{files-BW9geU0_.js.map → files-CgwJJ992.js.map} +1 -1
- package/dist/index.js +2 -2
- package/dist/{loader-compiler-D1teTrXw.js → loader-compiler.js} +4 -5
- package/dist/loader-compiler.js.map +1 -0
- package/dist/loader-registration-BO43rvVU.js +14 -0
- package/dist/loader-registration-BO43rvVU.js.map +1 -0
- package/dist/loader-registration.d.ts +4 -0
- package/dist/loader-registration.js +1 -0
- package/dist/loader-state-DB7sONR_.js +60 -0
- package/dist/loader-state-DB7sONR_.js.map +1 -0
- package/dist/loader-state.d.ts +34 -0
- package/dist/loader-sync.d.ts +3 -0
- package/dist/loader-sync.js +27 -0
- package/dist/loader-sync.js.map +1 -0
- package/dist/loader.d.ts +2 -4
- package/dist/loader.js +10 -48
- package/dist/loader.js.map +1 -1
- package/dist/{plugin-BHfiQ2L-.js → plugin-DDOHhv7Z.js} +6 -7
- package/dist/{plugin-BHfiQ2L-.js.map → plugin-DDOHhv7Z.js.map} +1 -1
- package/dist/project-DYXf2Kgt.js +442 -0
- package/dist/project-DYXf2Kgt.js.map +1 -0
- package/dist/project.js +2 -443
- package/dist/register.js +3 -4
- package/dist/register.js.map +1 -1
- package/dist/rollup.js +2 -3
- package/dist/rspack.js +2 -3
- package/dist/syntax.js +2 -3
- package/dist/{transpile-D8P8Lsbx.js → transpile--6CFGUm0.js} +3 -4
- package/dist/{transpile-D8P8Lsbx.js.map → transpile--6CFGUm0.js.map} +1 -1
- package/dist/typescript-plugin.cjs +252 -128
- package/dist/typescript-plugin.cjs.map +1 -1
- package/dist/vite-D0Ct4uy4.js +6 -0
- package/dist/vite-D0Ct4uy4.js.map +1 -0
- package/dist/vite-react.js +2 -3
- package/dist/vite.js +1 -7
- package/dist/webpack.js +2 -3
- package/package.json +3 -3
- package/schemas/twill.schema.json +6 -0
- package/dist/compiler-CbNSBUI2.js.map +0 -1
- package/dist/configuration-BVMf6Q_j.js.map +0 -1
- package/dist/declarations.js.map +0 -1
- package/dist/doctor.js.map +0 -1
- package/dist/loader-compiler-D1teTrXw.js.map +0 -1
- package/dist/project.js.map +0 -1
- package/dist/vite.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type LoaderOptions = {
|
|
2
|
+
entries?: string[];
|
|
3
|
+
cache?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type PreparedModule = {
|
|
6
|
+
url: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
source: string;
|
|
9
|
+
dialect: boolean;
|
|
10
|
+
cached: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare function resolveMissing(specifier: string, parentURL: string | undefined, error: unknown): {
|
|
13
|
+
url: string;
|
|
14
|
+
shortCircuit: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function moduleSource(source: string): {
|
|
17
|
+
format: "module";
|
|
18
|
+
source: string;
|
|
19
|
+
shortCircuit: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Shared I/O and cache policy; only the small Node hook adapters differ. */
|
|
22
|
+
export declare class LoaderState {
|
|
23
|
+
private entries;
|
|
24
|
+
private cacheEnabled;
|
|
25
|
+
private cache;
|
|
26
|
+
private cacheInitialized;
|
|
27
|
+
constructor(data?: LoaderOptions);
|
|
28
|
+
prepare(url: string): PreparedModule | undefined;
|
|
29
|
+
complete(plan: PreparedModule, result: ReturnType<typeof import('./loader-compiler.js').compileModule>): {
|
|
30
|
+
format: "module";
|
|
31
|
+
source: string;
|
|
32
|
+
shortCircuit: boolean;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { n as moduleSource, r as resolveMissing, t as LoaderState } from "./loader-state-DB7sONR_.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
// src/loader-sync.ts
|
|
4
|
+
var require = createRequire(import.meta.url);
|
|
5
|
+
function createHooks(data = {}) {
|
|
6
|
+
const state = new LoaderState(data);
|
|
7
|
+
let compileModule;
|
|
8
|
+
return {
|
|
9
|
+
resolve(specifier, context, nextResolve) {
|
|
10
|
+
try {
|
|
11
|
+
return nextResolve(specifier, context);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return resolveMissing(specifier, context.parentURL, error);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
load(url, context, nextLoad) {
|
|
17
|
+
const plan = state.prepare(url);
|
|
18
|
+
if (!plan) return nextLoad(url, context);
|
|
19
|
+
if (plan.cached !== void 0) return moduleSource(plan.cached);
|
|
20
|
+
compileModule ??= require("./loader-compiler.js").compileModule;
|
|
21
|
+
return state.complete(plan, compileModule(plan.source, plan.filename, plan.dialect));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { createHooks };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=loader-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-sync.js","names":[],"sources":["../src/loader-sync.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type { RegisterHooksOptions } from 'node:module';\nimport { LoaderState, moduleSource, resolveMissing, type LoaderOptions } from './loader-state.js';\n\nconst require = createRequire(import.meta.url);\n\nexport function createHooks(data: LoaderOptions = {}): RegisterHooksOptions {\n const state = new LoaderState(data);\n let compileModule: typeof import('./loader-compiler.js').compileModule | undefined;\n return {\n resolve(specifier, context, nextResolve) {\n try {\n return nextResolve(specifier, context);\n } catch (error) {\n return resolveMissing(specifier, context.parentURL, error);\n }\n },\n load(url, context, nextLoad) {\n const plan = state.prepare(url);\n if (!plan) return nextLoad(url, context);\n if (plan.cached !== undefined) return moduleSource(plan.cached);\n // require(ESM) is available on every Node version with registerHooks.\n // Never evaluate the compiler on native delegation or a disk-cache hit.\n compileModule ??= (require('./loader-compiler.js') as typeof import('./loader-compiler.js'))\n .compileModule;\n return state.complete(plan, compileModule(plan.source, plan.filename, plan.dialect));\n },\n };\n}\n"],"mappings":";;;AAIA,IAAM,UAAU,cAAc,YAAY,GAAG;AAE7C,SAAgB,YAAY,OAAsB,CAAC,GAAyB;CAC1E,MAAM,QAAQ,IAAI,YAAY,IAAI;CAClC,IAAI;CACJ,OAAO;EACL,QAAQ,WAAW,SAAS,aAAa;GACvC,IAAI;IACF,OAAO,YAAY,WAAW,OAAO;GACvC,SAAS,OAAO;IACd,OAAO,eAAe,WAAW,QAAQ,WAAW,KAAK;GAC3D;EACF;EACA,KAAK,KAAK,SAAS,UAAU;GAC3B,MAAM,OAAO,MAAM,QAAQ,GAAG;GAC9B,IAAI,CAAC,MAAM,OAAO,SAAS,KAAK,OAAO;GACvC,IAAI,KAAK,WAAW,KAAA,GAAW,OAAO,aAAa,KAAK,MAAM;GAG9D,kBAAmB,QAAQ,sBAAsB,CAAC,CAC/C;GACH,OAAO,MAAM,SAAS,MAAM,cAAc,KAAK,QAAQ,KAAK,UAAU,KAAK,OAAO,CAAC;EACrF;CACF;AACF"}
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ResolveHook, LoadHook } from 'node:module';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
cache?: boolean;
|
|
5
|
-
} | undefined): void;
|
|
2
|
+
import { LoaderOptions } from './loader-state.js';
|
|
3
|
+
export declare function initialize(data: LoaderOptions | undefined): void;
|
|
6
4
|
export declare const resolve: ResolveHook;
|
|
7
5
|
export declare const load: LoadHook;
|
package/dist/loader.js
CHANGED
|
@@ -1,61 +1,23 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
-
//#region src/loader.ts
|
|
7
|
-
var entries = /* @__PURE__ */ new Set();
|
|
8
|
-
var cacheEnabled = false;
|
|
9
|
-
var cache;
|
|
10
|
-
var cacheInitialized = false;
|
|
1
|
+
import { n as moduleSource, r as resolveMissing, t as LoaderState } from "./loader-state-DB7sONR_.js";
|
|
2
|
+
// src/loader.ts
|
|
3
|
+
var state = new LoaderState();
|
|
11
4
|
function initialize(data) {
|
|
12
|
-
|
|
13
|
-
cacheEnabled = data?.cache === true && process.env.TWILL_CACHE !== "0";
|
|
14
|
-
cache = void 0;
|
|
15
|
-
cacheInitialized = false;
|
|
5
|
+
state = new LoaderState(data);
|
|
16
6
|
}
|
|
17
7
|
var resolve = async (specifier, context, nextResolve) => {
|
|
18
8
|
try {
|
|
19
9
|
return await nextResolve(specifier, context);
|
|
20
10
|
} catch (error) {
|
|
21
|
-
|
|
22
|
-
const target = new URL(specifier, context.parentURL);
|
|
23
|
-
const base = fileURLToPath(target);
|
|
24
|
-
const candidate = resolveSourceFile(base);
|
|
25
|
-
if (candidate) return {
|
|
26
|
-
url: pathToFileURL(candidate).href + target.search + target.hash,
|
|
27
|
-
shortCircuit: true
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
throw error;
|
|
11
|
+
return resolveMissing(specifier, context.parentURL, error);
|
|
31
12
|
}
|
|
32
13
|
};
|
|
33
14
|
var load = async (url, context, nextLoad) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (cacheEnabled && !cacheInitialized) {
|
|
40
|
-
cache = openCompilationCache();
|
|
41
|
-
cacheInitialized = true;
|
|
42
|
-
}
|
|
43
|
-
const cached = cache?.read(url, source, dialect);
|
|
44
|
-
if (cached !== void 0) return {
|
|
45
|
-
format: "module",
|
|
46
|
-
source: cached,
|
|
47
|
-
shortCircuit: true
|
|
48
|
-
};
|
|
49
|
-
const { compileModule } = await import("./loader-compiler-D1teTrXw.js");
|
|
50
|
-
const result = compileModule(source, filename, dialect);
|
|
51
|
-
cache?.write(url, source, dialect, result.source, result.observations);
|
|
52
|
-
return {
|
|
53
|
-
format: "module",
|
|
54
|
-
source: result.source,
|
|
55
|
-
shortCircuit: true
|
|
56
|
-
};
|
|
15
|
+
const plan = state.prepare(url);
|
|
16
|
+
if (!plan) return nextLoad(url, context);
|
|
17
|
+
if (plan.cached !== void 0) return moduleSource(plan.cached);
|
|
18
|
+
const { compileModule } = await import("./loader-compiler.js");
|
|
19
|
+
return state.complete(plan, compileModule(plan.source, plan.filename, plan.dialect));
|
|
57
20
|
};
|
|
58
|
-
//#endregion
|
|
59
21
|
export { initialize, load, resolve };
|
|
60
22
|
|
|
61
23
|
//# sourceMappingURL=loader.js.map
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","names":[],"sources":["../src/loader.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"loader.js","names":[],"sources":["../src/loader.ts"],"sourcesContent":["import type { ResolveHook, LoadHook } from 'node:module';\nimport { LoaderState, moduleSource, resolveMissing, type LoaderOptions } from './loader-state.js';\n\nlet state = new LoaderState();\nexport function initialize(data: LoaderOptions | undefined) {\n state = new LoaderState(data);\n}\n\nexport const resolve: ResolveHook = async (specifier, context, nextResolve) => {\n try {\n return await nextResolve(specifier, context);\n } catch (error) {\n return resolveMissing(specifier, context.parentURL, error);\n }\n};\n\nexport const load: LoadHook = async (url, context, nextLoad) => {\n const plan = state.prepare(url);\n if (!plan) return nextLoad(url, context);\n if (plan.cached !== undefined) return moduleSource(plan.cached);\n const { compileModule } = await import('./loader-compiler.js');\n return state.complete(plan, compileModule(plan.source, plan.filename, plan.dialect));\n};\n"],"mappings":";;AAGA,IAAI,QAAQ,IAAI,YAAY;AAC5B,SAAgB,WAAW,MAAiC;CAC1D,QAAQ,IAAI,YAAY,IAAI;AAC9B;AAEA,IAAa,UAAuB,OAAO,WAAW,SAAS,gBAAgB;CAC7E,IAAI;EACF,OAAO,MAAM,YAAY,WAAW,OAAO;CAC7C,SAAS,OAAO;EACd,OAAO,eAAe,WAAW,QAAQ,WAAW,KAAK;CAC3D;AACF;AAEA,IAAa,OAAiB,OAAO,KAAK,SAAS,aAAa;CAC9D,MAAM,OAAO,MAAM,QAAQ,GAAG;CAC9B,IAAI,CAAC,MAAM,OAAO,SAAS,KAAK,OAAO;CACvC,IAAI,KAAK,WAAW,KAAA,GAAW,OAAO,aAAa,KAAK,MAAM;CAC9D,MAAM,EAAE,kBAAkB,MAAM,OAAO;CACvC,OAAO,MAAM,SAAS,MAAM,cAAc,KAAK,QAAQ,KAAK,UAAU,KAAK,OAAO,CAAC;AACrF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as isTwillFile } from "./extensions-
|
|
2
|
-
import { n as loadConfig, t as configurationFiles } from "./configuration-
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
1
|
+
import { n as isTwillFile } from "./extensions-7ixttcoK.js";
|
|
2
|
+
import { n as loadConfig, t as configurationFiles } from "./configuration-ppqhmuy4.js";
|
|
3
|
+
import { n as transpileNative, t as transpile } from "./transpile--6CFGUm0.js";
|
|
4
|
+
import { a as splitId, i as sourceExtensions, n as needsTypeEmission, r as resolveSourceFile, t as isDependency } from "./files-CgwJJ992.js";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
7
7
|
import { createUnplugin } from "unplugin";
|
|
8
|
-
|
|
8
|
+
// src/plugin.ts
|
|
9
9
|
var twillPlugin = createUnplugin((options = {}, meta) => {
|
|
10
10
|
let root = options.root ?? process.cwd();
|
|
11
11
|
let config = {
|
|
@@ -135,7 +135,6 @@ var twillPlugin = createUnplugin((options = {}, meta) => {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
});
|
|
138
|
-
//#endregion
|
|
139
138
|
export { twillPlugin as t };
|
|
140
139
|
|
|
141
|
-
//# sourceMappingURL=plugin-
|
|
140
|
+
//# sourceMappingURL=plugin-DDOHhv7Z.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-BHfiQ2L-.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 configFiles = configurationFiles(root);\n let configError: unknown;\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 buildStart() {\n // Refresh once per build, including incremental contexts. Vite dev\n // uses its server watcher to report errors and invalidate the graph.\n if (!servingVite) {\n configError = undefined;\n try {\n config = { ...loadConfig(root), ...options };\n configFiles = configurationFiles(root);\n } catch (cause) {\n // Report through transformed modules, retaining their watch\n // dependencies. A fatal make/start error can stop host watching.\n configError = cause;\n }\n }\n },\n webpack(compiler) {\n if (nativeSources)\n compiler.options.module.rules.push({\n include: (file) => !isDependency(file) && needsTypeEmission(file),\n // Twill already emits JS. Webpack's automatic TS stripper rejects\n // .tsx by extension even when a loader has lowered all JSX.\n parser: { typescript: false },\n });\n },\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 const dialect = isTwillFile(filename);\n if (!dialect && !(nativeSources && needsTypeEmission(filename))) return null;\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) for (const file of configFiles) this.addWatchFile(file);\n try {\n if (configError !== undefined) throw configError;\n return dialect\n ? transpile(source, { ...config, filename })\n : transpileNative(source, filename, undefined, undefined, config.jsxImportSource);\n } catch (cause) {\n if (meta.framework !== 'esbuild') throw cause;\n // Throwing from esbuild's onLoad discards its watchFiles. Report a\n // failed build while returning dependency metadata for recovery.\n this.error(cause instanceof Error ? cause : String(cause));\n return { code: ';', map: null };\n }\n },\n };\n },\n);\n"],"mappings":";;;;;;;;AAsBA,IAAa,cAAc,gBACxB,UAAU,CAAC,GAAG,SAAS;CACtB,IAAI,OAAO,QAAQ,QAAQ,QAAQ,IAAI;CACvC,IAAI,SAAS;EAAE,GAAG,WAAW,IAAI;EAAG,GAAG;CAAQ;CAC/C,IAAI,cAAc,mBAAmB,IAAI;CACzC,IAAI;CACJ,IAAI,cAAc;CAElB,MAAM,gBAAgB,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC,SAAS,KAAK,SAAS;CAC3F,OAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;GAGX,IAAI,CAAC,aAAa;IAChB,cAAc,KAAA;IACd,IAAI;KACF,SAAS;MAAE,GAAG,WAAW,IAAI;MAAG,GAAG;KAAQ;KAC3C,cAAc,mBAAmB,IAAI;IACvC,SAAS,OAAO;KAGd,cAAc;IAChB;GACF;EACF;EACA,QAAQ,UAAU;GAChB,IAAI,eACF,SAAS,QAAQ,OAAO,MAAM,KAAK;IACjC,UAAU,SAAS,CAAC,aAAa,IAAI,KAAK,kBAAkB,IAAI;IAGhE,QAAQ,EAAE,YAAY,MAAM;GAC9B,CAAC;EACL;EACA,SAAS,EACP,MAAM,OAAO;GAGX,MAAM,UAAU;IAAE,QAAQ;IAAM,WAAW;GAAQ,IAAI,SACrD,MAAM,QAAQ,KAAK,MAAM;IACvB,YAAY,QAAQ,KAAK,QAAQ;IACjC,MAAM,KAAK;GACb,CAAC,CACH;EACF,EACF;EACA,MAAM;GACJ,eAAe,YAAY;IACzB,OAAO,QAAQ,QAAQ,WAAW;IAClC,SAAS;KAAE,GAAG,WAAW,IAAI;KAAG,GAAG;IAAQ;IAC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
+
{"version":3,"file":"plugin-DDOHhv7Z.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 configFiles = configurationFiles(root);\n let configError: unknown;\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 buildStart() {\n // Refresh once per build, including incremental contexts. Vite dev\n // uses its server watcher to report errors and invalidate the graph.\n if (!servingVite) {\n configError = undefined;\n try {\n config = { ...loadConfig(root), ...options };\n configFiles = configurationFiles(root);\n } catch (cause) {\n // Report through transformed modules, retaining their watch\n // dependencies. A fatal make/start error can stop host watching.\n configError = cause;\n }\n }\n },\n webpack(compiler) {\n if (nativeSources)\n compiler.options.module.rules.push({\n include: (file) => !isDependency(file) && needsTypeEmission(file),\n // Twill already emits JS. Webpack's automatic TS stripper rejects\n // .tsx by extension even when a loader has lowered all JSX.\n parser: { typescript: false },\n });\n },\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 const dialect = isTwillFile(filename);\n if (!dialect && !(nativeSources && needsTypeEmission(filename))) return null;\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) for (const file of configFiles) this.addWatchFile(file);\n try {\n if (configError !== undefined) throw configError;\n return dialect\n ? transpile(source, { ...config, filename })\n : transpileNative(source, filename, undefined, undefined, config.jsxImportSource);\n } catch (cause) {\n if (meta.framework !== 'esbuild') throw cause;\n // Throwing from esbuild's onLoad discards its watchFiles. Report a\n // failed build while returning dependency metadata for recovery.\n this.error(cause instanceof Error ? cause : String(cause));\n return { code: ';', map: null };\n }\n },\n };\n },\n);\n"],"mappings":";;;;;;;;AAsBA,IAAa,cAAc,gBACxB,UAAU,CAAC,GAAG,SAAS;CACtB,IAAI,OAAO,QAAQ,QAAQ,QAAQ,IAAI;CACvC,IAAI,SAAS;EAAE,GAAG,WAAW,IAAI;EAAG,GAAG;CAAQ;CAC/C,IAAI,cAAc,mBAAmB,IAAI;CACzC,IAAI;CACJ,IAAI,cAAc;CAElB,MAAM,gBAAgB,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,SAAS,CAAC,CAAC,SAAS,KAAK,SAAS;CAC3F,OAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;GAGX,IAAI,CAAC,aAAa;IAChB,cAAc,KAAA;IACd,IAAI;KACF,SAAS;MAAE,GAAG,WAAW,IAAI;MAAG,GAAG;KAAQ;KAC3C,cAAc,mBAAmB,IAAI;IACvC,SAAS,OAAO;KAGd,cAAc;IAChB;GACF;EACF;EACA,QAAQ,UAAU;GAChB,IAAI,eACF,SAAS,QAAQ,OAAO,MAAM,KAAK;IACjC,UAAU,SAAS,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