@pithyjs/vite-plugin 0.2.0-beta.25 → 0.2.0-beta.27
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 -7
- package/dist/aotCodegen/generateBindings.d.ts +2 -0
- package/dist/aotCodegen/generateBindings.d.ts.map +1 -1
- package/dist/aotCodegen/generateBindings.js +2 -0
- package/dist/aotCodegen/generateBindings.js.map +1 -1
- package/dist/aotCodegen/generateDomFactory.js +6 -1
- package/dist/aotCodegen/generateDomFactory.js.map +1 -1
- package/dist/babelPlugin/babelPlugin.d.ts.map +1 -1
- package/dist/babelPlugin/babelPlugin.js +106 -33
- package/dist/babelPlugin/babelPlugin.js.map +1 -1
- package/dist/babelPlugin/validateTemplate.d.ts.map +1 -1
- package/dist/babelPlugin/validateTemplate.js +2 -8
- package/dist/babelPlugin/validateTemplate.js.map +1 -1
- package/dist/htmlTransform/htmlTransform.d.ts +2 -0
- package/dist/htmlTransform/htmlTransform.d.ts.map +1 -1
- package/dist/htmlTransform/htmlTransform.js +75 -19
- package/dist/htmlTransform/htmlTransform.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/** @codex { "id": "pithy.babel.validate-template", "title": "Template Validation", "category": "compiler", "risk": "medium" } */
|
|
2
|
-
import * as babel from '@babel/core';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
2
|
import pithyBabelPlugin from './babelPlugin.js';
|
|
5
3
|
import { compilePithyModule } from '../pithyPlugin/plugin.js';
|
|
6
|
-
import { readsTemplates } from '../htmlTransform/htmlTransform.js';
|
|
7
|
-
const presetTypescript = createRequire(import.meta.url).resolve('@babel/preset-typescript');
|
|
8
|
-
// Babel needs a name to pick the TS preset; it is not reported.
|
|
4
|
+
import { readsTemplates, transformTypeScriptModule, } from '../htmlTransform/htmlTransform.js';
|
|
9
5
|
const UNNAMED = 'module.ts';
|
|
10
6
|
/**
|
|
11
7
|
* The component-attribute findings the Vite plugin warns about, for one module,
|
|
@@ -37,7 +33,7 @@ export async function validateTemplate(code, options = {}) {
|
|
|
37
33
|
if (!readsTemplates(source))
|
|
38
34
|
return [];
|
|
39
35
|
const findings = [];
|
|
40
|
-
|
|
36
|
+
transformTypeScriptModule(source, {
|
|
41
37
|
filename,
|
|
42
38
|
plugins: [
|
|
43
39
|
() => pithyBabelPlugin({
|
|
@@ -46,8 +42,6 @@ export async function validateTemplate(code, options = {}) {
|
|
|
46
42
|
onFinding: finding => findings.push(finding),
|
|
47
43
|
}),
|
|
48
44
|
],
|
|
49
|
-
presets: [[presetTypescript, { onlyRemoveTypeImports: true }]],
|
|
50
|
-
parserOpts: { sourceType: 'module', plugins: ['typescript'] },
|
|
51
45
|
configFile: false,
|
|
52
46
|
babelrc: false,
|
|
53
47
|
code: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTemplate.js","sourceRoot":"","sources":["../../src/babelPlugin/validateTemplate.ts"],"names":[],"mappings":"AAAA,iIAAiI;AAEjI,OAAO,
|
|
1
|
+
{"version":3,"file":"validateTemplate.js","sourceRoot":"","sources":["../../src/babelPlugin/validateTemplate.ts"],"names":[],"mappings":"AAAA,iIAAiI;AAEjI,OAAO,gBAA0C,MAAM,eAAe,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,gCAAgC,CAAC;AAExC,MAAM,OAAO,GAAG,WAAW,CAAC;AAe5B;;;;;;;;;;;;;;;;GAgBG;AACH,8MAA8M;AAC9M,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,UAAmC,EAAE;IAErC,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC5B,MAAM,QAAQ,GAAG,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IACp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CAAC","sourcesContent":["/** @codex { \"id\": \"pithy.babel.validate-template\", \"title\": \"Template Validation\", \"category\": \"compiler\", \"risk\": \"medium\" } */\n\nimport pithyBabelPlugin, { type TemplateFinding } from './babelPlugin';\nimport type { ComponentScopesMap } from './extractUsedIdentifiers';\nimport { compilePithyModule } from '../pithyPlugin/plugin';\nimport {\n readsTemplates,\n transformTypeScriptModule,\n} from '../htmlTransform/htmlTransform';\n\nconst UNNAMED = 'module.ts';\n\n/** @codexApi {\"parent\":\"pithy.babel.validate-template\",\"name\":\"ValidateTemplateOptions\",\"stability\":\"experimental\",\"signature\":\"interface ValidateTemplateOptions\"} */\nexport interface ValidateTemplateOptions {\n /** The module's path or id. Without it the module is read as `.ts` and findings carry no location. */\n filename?: string;\n /**\n * The map `htmlTransformPlugin` is given. Pass ui-kit's `componentScopes`\n * for an app's findings: without it `<For>`'s loop names read as unbound.\n */\n componentScopes?: ComponentScopesMap;\n /** For a `.pithy` file, esbuild's tsconfig as JSON, in place of the `tsconfig.json` above `filename`. */\n tsconfigRaw?: string;\n}\n\n/**\n * The component-attribute findings the Vite plugin warns about, for one module,\n * without building it.\n *\n * Runs the steps the plugin chain runs: a `.pithy` file is compiled and\n * transpiled as `pithyPlugin` does, then the plugin's own Babel pass checks it.\n * A finding's `message`, `line` and `column` are those the dev server and the\n * build print; for a `.pithy` file they refer to the compiled module. Like the\n * chain, it checks `.ts` and `.pithy` files only, skips a module with no `html`\n * template, and returns `[]` for both.\n *\n * @param code - A `.ts` module using `html` templates, or a `.pithy` file.\n * @param options - The filename and the component scopes.\n * @returns One finding per attribute, in source order; empty when all is well.\n * @throws The parser's error when a module the transform reads does not parse,\n * as the build would.\n */\n/** @codexApi {\"parent\":\"pithy.babel.validate-template\",\"name\":\"validateTemplate\",\"stability\":\"experimental\",\"signature\":\"(code: string, options?: ValidateTemplateOptions) => Promise<TemplateFinding[]>\"} */\nexport async function validateTemplate(\n code: string,\n options: ValidateTemplateOptions = {}\n): Promise<TemplateFinding[]> {\n const id = options.filename;\n const filename = id?.split(/[?#]/, 1)[0] ?? UNNAMED;\n const isPithy = filename.endsWith('.pithy');\n if (!isPithy && !filename.endsWith('.ts')) return [];\n\n const source = isPithy\n ? (await compilePithyModule(code, id ?? filename, options.tsconfigRaw)).code\n : code;\n if (!readsTemplates(source)) return [];\n const findings: TemplateFinding[] = [];\n transformTypeScriptModule(source, {\n filename,\n plugins: [\n () =>\n pithyBabelPlugin({\n filename,\n componentScopes: options.componentScopes,\n onFinding: finding => findings.push(finding),\n }),\n ],\n configFile: false,\n babelrc: false,\n code: false,\n });\n if (id !== undefined) return findings;\n return findings.map(f => {\n const at = f.message.lastIndexOf(` (${UNNAMED}`);\n return {\n ...f,\n file: null,\n message: at < 0 ? f.message : f.message.slice(0, at),\n };\n });\n}\n"]}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { PluginOption } from 'vite';
|
|
17
17
|
import type { ComponentScopesMap } from '../babelPlugin/extractUsedIdentifiers.js';
|
|
18
|
+
import * as babel from '@babel/core';
|
|
18
19
|
/**
|
|
19
20
|
* Whether the template transform reads `code` at all: it holds an `html`
|
|
20
21
|
* tagged template, or imports `html` from `@pithyjs/core` (an alias included).
|
|
@@ -24,6 +25,7 @@ import type { ComponentScopesMap } from '../babelPlugin/extractUsedIdentifiers.j
|
|
|
24
25
|
* @returns `true` when the transform parses it.
|
|
25
26
|
*/
|
|
26
27
|
export declare function readsTemplates(code: string): boolean;
|
|
28
|
+
export declare function transformTypeScriptModule(code: string, options: Omit<babel.TransformOptions, 'parserOpts'>): babel.BabelFileResult | null;
|
|
27
29
|
/** @codexApi {"parent":"pithy.vite.html-transform-plugin","name":"HtmlTransformPluginOptions","stability":"stable","signature":"interface HtmlTransformPluginOptions"} */
|
|
28
30
|
export interface HtmlTransformPluginOptions {
|
|
29
31
|
/** Map of component names to variables they inject into children's scope */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlTransform.d.ts","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"htmlTransform.d.ts","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAkB,YAAY,EAAkB,MAAM,MAAM,CAAC;AAIzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAErC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMpD;AA2BD,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAClD,KAAK,CAAC,eAAe,GAAG,IAAI,CAoB9B;AAED,0KAA0K;AAC1K,MAAM,WAAW,0BAA0B;IACzC,4EAA4E;IAC5E,eAAe,CAAC,EAAE,kBAAkB,CAAC;IACrC,kFAAkF;IAClF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,oHAAoH;IACpH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qLAAqL;AACrL,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE,0BAA0B,GACnC,YAAY,CAwFd"}
|
|
@@ -15,9 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import pithyBabelPlugin from '../babelPlugin/babelPlugin.js';
|
|
17
17
|
import * as babel from '@babel/core';
|
|
18
|
-
import { createRequire } from 'node:module';
|
|
19
|
-
// Babel resolves preset names from the app, which may not see this package's deps.
|
|
20
|
-
const presetTypescript = createRequire(import.meta.url).resolve('@babel/preset-typescript');
|
|
21
18
|
/**
|
|
22
19
|
* Whether the template transform reads `code` at all: it holds an `html`
|
|
23
20
|
* tagged template, or imports `html` from `@pithyjs/core` (an alias included).
|
|
@@ -28,8 +25,55 @@ const presetTypescript = createRequire(import.meta.url).resolve('@babel/preset-t
|
|
|
28
25
|
*/
|
|
29
26
|
export function readsTemplates(code) {
|
|
30
27
|
return (code.includes('html`') ||
|
|
28
|
+
/\bhtml\s*(?:!|\s+as\s+[\w.]+)?[\s)]*`/.test(code) ||
|
|
31
29
|
/import\s*\{[^}]*\bhtml\b[^}]*\}\s*from\s+['"]@pithyjs\/core['"]/.test(code));
|
|
32
30
|
}
|
|
31
|
+
const DECORATOR_DIALECTS = [
|
|
32
|
+
[
|
|
33
|
+
'typescript',
|
|
34
|
+
'decorators-legacy',
|
|
35
|
+
'decoratorAutoAccessors',
|
|
36
|
+
'explicitResourceManagement',
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
'typescript',
|
|
40
|
+
['decorators', {}],
|
|
41
|
+
'decoratorAutoAccessors',
|
|
42
|
+
'explicitResourceManagement',
|
|
43
|
+
],
|
|
44
|
+
];
|
|
45
|
+
const dropTypeOnlyImportEquals = () => ({
|
|
46
|
+
visitor: {
|
|
47
|
+
TSImportEqualsDeclaration(path) {
|
|
48
|
+
if (path.node.importKind === 'type')
|
|
49
|
+
path.remove();
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const parsedTo = (err) => err.pos ?? -1;
|
|
54
|
+
export function transformTypeScriptModule(code, options) {
|
|
55
|
+
let parseError;
|
|
56
|
+
for (const plugins of DECORATOR_DIALECTS) {
|
|
57
|
+
try {
|
|
58
|
+
return babel.transformSync(code, {
|
|
59
|
+
...options,
|
|
60
|
+
plugins: [dropTypeOnlyImportEquals, ...(options.plugins ?? [])],
|
|
61
|
+
parserOpts: {
|
|
62
|
+
sourceType: 'module',
|
|
63
|
+
plugins,
|
|
64
|
+
createParenthesizedExpressions: true,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err.code !== 'BABEL_PARSE_ERROR')
|
|
70
|
+
throw err;
|
|
71
|
+
if (parseError === undefined || parsedTo(err) > parsedTo(parseError))
|
|
72
|
+
parseError = err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw parseError;
|
|
76
|
+
}
|
|
33
77
|
/**
|
|
34
78
|
* Vite plugin that transforms `html\`\`` tagged templates and literal `html()` calls
|
|
35
79
|
* in `.ts` and compiled `.pithy` modules using Babel.
|
|
@@ -55,6 +99,7 @@ export function readsTemplates(code) {
|
|
|
55
99
|
export function htmlTransformPlugin(options) {
|
|
56
100
|
let resolvedAot = false;
|
|
57
101
|
let sourceMaps = true;
|
|
102
|
+
let lowering = null;
|
|
58
103
|
const plugin = {
|
|
59
104
|
name: 'pithy:html-transform',
|
|
60
105
|
enforce: 'pre',
|
|
@@ -62,6 +107,8 @@ export function htmlTransformPlugin(options) {
|
|
|
62
107
|
// Default: AOT enabled in build, disabled in dev (for faster HMR)
|
|
63
108
|
resolvedAot = options?.aot ?? config.command === 'build';
|
|
64
109
|
sourceMaps = config.command === 'serve' || !!config.build?.sourcemap;
|
|
110
|
+
const { target, supported } = config.esbuild || {};
|
|
111
|
+
lowering = target || supported ? { target, supported } : null;
|
|
65
112
|
const plugins = config.plugins ?? [];
|
|
66
113
|
const sfc = plugins.findIndex(p => p.name === 'vite-plugin-pithy');
|
|
67
114
|
if (sfc !== -1 && sfc > plugins.indexOf(plugin)) {
|
|
@@ -74,40 +121,49 @@ export function htmlTransformPlugin(options) {
|
|
|
74
121
|
const normalizedId = id.split(/[?#]/, 1)[0];
|
|
75
122
|
// Fast-path: skip files with no pithy tagged templates.
|
|
76
123
|
// Check for html` (common case) or aliased html import from @pithyjs/core.
|
|
77
|
-
|
|
124
|
+
const isPithy = normalizedId.endsWith('.pithy');
|
|
125
|
+
if (!normalizedId.endsWith('.ts') && !isPithy)
|
|
78
126
|
return;
|
|
79
|
-
|
|
127
|
+
const reads = readsTemplates(code);
|
|
128
|
+
if (!reads && !(isPithy && lowering))
|
|
80
129
|
return;
|
|
130
|
+
if (!reads)
|
|
131
|
+
return lowerPithy(code, null, normalizedId);
|
|
81
132
|
const babelPluginOptions = {
|
|
82
133
|
componentScopes: options?.componentScopes,
|
|
83
134
|
aot: resolvedAot,
|
|
84
135
|
strictAot: options?.strictAot,
|
|
85
136
|
filename: normalizedId,
|
|
86
137
|
};
|
|
87
|
-
const result =
|
|
138
|
+
const result = transformTypeScriptModule(code, {
|
|
88
139
|
filename: normalizedId,
|
|
89
140
|
plugins: [() => pithyBabelPlugin(babelPluginOptions)],
|
|
90
|
-
presets: [
|
|
91
|
-
[
|
|
92
|
-
presetTypescript,
|
|
93
|
-
{
|
|
94
|
-
onlyRemoveTypeImports: true,
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
],
|
|
98
|
-
parserOpts: {
|
|
99
|
-
sourceType: 'module',
|
|
100
|
-
plugins: ['typescript'],
|
|
101
|
-
},
|
|
102
141
|
configFile: false,
|
|
103
142
|
sourceMaps,
|
|
104
143
|
});
|
|
105
|
-
|
|
144
|
+
const transformed = {
|
|
106
145
|
code: result?.code ?? code,
|
|
107
146
|
map: result?.map ?? null,
|
|
108
147
|
};
|
|
148
|
+
return isPithy && lowering
|
|
149
|
+
? lowerPithy(transformed.code, transformed.map, normalizedId)
|
|
150
|
+
: transformed;
|
|
109
151
|
},
|
|
110
152
|
};
|
|
153
|
+
async function lowerPithy(code, map, id) {
|
|
154
|
+
const { transformWithEsbuild } = await import('vite');
|
|
155
|
+
const lowered = await transformWithEsbuild(code, id, {
|
|
156
|
+
loader: 'js',
|
|
157
|
+
target: lowering?.target,
|
|
158
|
+
supported: {
|
|
159
|
+
'dynamic-import': true,
|
|
160
|
+
'import-meta': true,
|
|
161
|
+
...lowering?.supported,
|
|
162
|
+
},
|
|
163
|
+
sourcemap: sourceMaps,
|
|
164
|
+
}, map ?? undefined);
|
|
165
|
+
return { code: lowered.code, map: lowered.map };
|
|
166
|
+
}
|
|
111
167
|
return plugin;
|
|
112
168
|
}
|
|
113
169
|
//# sourceMappingURL=htmlTransform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlTransform.js","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,gBAEN,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,mFAAmF;AACnF,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAC7D,0BAA0B,CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACtB,iEAAiE,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7E,CAAC;AACJ,CAAC;AAYD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qLAAqL;AACrL,MAAM,UAAU,mBAAmB,CACjC,OAAoC;IAEpC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,KAAc;QAEvB,cAAc,CAAC,MAAsB;YACnC,kEAAkE;YAClE,WAAW,GAAG,OAAO,EAAE,GAAG,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO,CAAC;YAEzD,UAAU,GAAG,MAAM,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC;YAErE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;YACrC,MAAM,GAAG,GAAG,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,MAAM,EAAE,IAAI,IAAI,IAAI;gBAC1B,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,IAAI;aACzB,CAAC;QACJ,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite.html-transform-plugin\",\n \"title\": \"HTML Transform Vite Plugin\",\n \"category\": \"plugin\",\n \"description\": \"Babel-based Vite plugin that transforms html`…` tagged templates and literal html() calls in .ts and compiled .pithy modules, with optional AOT compilation to eliminate runtime HTML parsing.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"htmlTransformAot.test.ts\" },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { PluginOption, ResolvedConfig } from 'vite';\nimport pithyBabelPlugin, {\n type PithyBabelPluginOptions,\n} from '../babelPlugin/babelPlugin';\nimport type { ComponentScopesMap } from '../babelPlugin/extractUsedIdentifiers';\nimport * as babel from '@babel/core';\nimport { createRequire } from 'node:module';\n\n// Babel resolves preset names from the app, which may not see this package's deps.\nconst presetTypescript = createRequire(import.meta.url).resolve(\n '@babel/preset-typescript'\n);\n\n/**\n * Whether the template transform reads `code` at all: it holds an `html`\n * tagged template, or imports `html` from `@pithyjs/core` (an alias included).\n * Any other module skips Babel, so syntax only esbuild handles still builds.\n *\n * @param code - The module source.\n * @returns `true` when the transform parses it.\n */\nexport function readsTemplates(code: string): boolean {\n return (\n code.includes('html`') ||\n /import\\s*\\{[^}]*\\bhtml\\b[^}]*\\}\\s*from\\s+['\"]@pithyjs\\/core['\"]/.test(code)\n );\n}\n\n/** @codexApi {\"parent\":\"pithy.vite.html-transform-plugin\",\"name\":\"HtmlTransformPluginOptions\",\"stability\":\"stable\",\"signature\":\"interface HtmlTransformPluginOptions\"} */\nexport interface HtmlTransformPluginOptions {\n /** Map of component names to variables they inject into children's scope */\n componentScopes?: ComponentScopesMap;\n /** Enable AOT template compilation. Default: true in build mode, false in dev. */\n aot?: boolean;\n /** Fail the build if any template falls back to JIT, i.e. any `[pithy:aot:jit-fallback]` report. Default: false. */\n strictAot?: boolean;\n}\n\n/**\n * Vite plugin that transforms `html\\`\\`` tagged templates and literal `html()` calls\n * in `.ts` and compiled `.pithy` modules using Babel.\n *\n * In build mode, templates are AOT-compiled to eliminate runtime HTML parsing.\n * In dev mode, tagged templates only get their context injected and still render\n * through the runtime compiler, unless `aot` is explicitly enabled.\n * `pithyPlugin()` must be listed before this plugin.\n *\n * @param options - Plugin configuration for AOT mode, strict AOT, and component scopes\n * @returns A Vite plugin that transforms html tagged templates\n *\n * @example\n * ```ts\n * import { htmlTransformPlugin } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [htmlTransformPlugin({ aot: true })],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite.html-transform-plugin\",\"name\":\"htmlTransformPlugin\",\"stability\":\"stable\",\"signature\":\"(options?: HtmlTransformPluginOptions) => PluginOption\"} */\nexport function htmlTransformPlugin(\n options?: HtmlTransformPluginOptions\n): PluginOption {\n let resolvedAot = false;\n let sourceMaps = true;\n\n const plugin = {\n name: 'pithy:html-transform',\n enforce: 'pre' as const,\n\n configResolved(config: ResolvedConfig) {\n // Default: AOT enabled in build, disabled in dev (for faster HMR)\n resolvedAot = options?.aot ?? config.command === 'build';\n\n sourceMaps = config.command === 'serve' || !!config.build?.sourcemap;\n\n const plugins = config.plugins ?? [];\n const sfc = plugins.findIndex(p => p.name === 'vite-plugin-pithy');\n if (sfc !== -1 && sfc > plugins.indexOf(plugin)) {\n throw new Error(\n '[pithy:html-transform] pithyPlugin() must be listed before htmlTransformPlugin(), ' +\n 'so .pithy files reach the template transform already compiled.'\n );\n }\n },\n\n transform(code: string, id: string) {\n // Strip Vite query/hash suffixes (e.g. component.ts?import → component.ts)\n const normalizedId = id.split(/[?#]/, 1)[0];\n // Fast-path: skip files with no pithy tagged templates.\n // Check for html` (common case) or aliased html import from @pithyjs/core.\n if (!normalizedId.endsWith('.ts') && !normalizedId.endsWith('.pithy'))\n return;\n if (!readsTemplates(code)) return;\n\n const babelPluginOptions: PithyBabelPluginOptions = {\n componentScopes: options?.componentScopes,\n aot: resolvedAot,\n strictAot: options?.strictAot,\n filename: normalizedId,\n };\n\n const result = babel.transformSync(code, {\n filename: normalizedId,\n plugins: [() => pithyBabelPlugin(babelPluginOptions)],\n presets: [\n [\n presetTypescript,\n {\n onlyRemoveTypeImports: true,\n },\n ],\n ],\n parserOpts: {\n sourceType: 'module',\n plugins: ['typescript'],\n },\n configFile: false,\n sourceMaps,\n });\n\n return {\n code: result?.code ?? code,\n map: result?.map ?? null,\n };\n },\n };\n return plugin;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"htmlTransform.js","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,gBAEN,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACtB,uCAAuC,CAAC,IAAI,CAAC,IAAI,CAAC;QAClD,iEAAiE,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7E,CAAC;AACJ,CAAC;AAED,MAAM,kBAAkB,GAAqC;IAC3D;QACE,YAAY;QACZ,mBAAmB;QACnB,wBAAwB;QACxB,4BAA4B;KAC7B;IACD;QACE,YAAY;QACZ,CAAC,YAAY,EAAE,EAAE,CAAC;QAClB,wBAAwB;QACxB,4BAA4B;KAC7B;CACF,CAAC;AAEF,MAAM,wBAAwB,GAAG,GAAoB,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE;QACP,yBAAyB,CAAC,IAAI;YAC5B,IAAI,IAAI,CA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E,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite.html-transform-plugin\",\n \"title\": \"HTML Transform Vite Plugin\",\n \"category\": \"plugin\",\n \"description\": \"Babel-based Vite plugin that transforms html`…` tagged templates and literal html() calls in .ts and compiled .pithy modules, with optional AOT compilation to eliminate runtime HTML parsing.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": true, \"covered\": true, \"file\": \"htmlTransformAot.test.ts\" },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { ESBuildOptions, PluginOption, ResolvedConfig } from 'vite';\nimport pithyBabelPlugin, {\n type PithyBabelPluginOptions,\n} from '../babelPlugin/babelPlugin';\nimport type { ComponentScopesMap } from '../babelPlugin/extractUsedIdentifiers';\nimport * as babel from '@babel/core';\n\n/**\n * Whether the template transform reads `code` at all: it holds an `html`\n * tagged template, or imports `html` from `@pithyjs/core` (an alias included).\n * Any other module skips Babel, so syntax only esbuild handles still builds.\n *\n * @param code - The module source.\n * @returns `true` when the transform parses it.\n */\nexport function readsTemplates(code: string): boolean {\n return (\n code.includes('html`') ||\n /\\bhtml\\s*(?:!|\\s+as\\s+[\\w.]+)?[\\s)]*`/.test(code) ||\n /import\\s*\\{[^}]*\\bhtml\\b[^}]*\\}\\s*from\\s+['\"]@pithyjs\\/core['\"]/.test(code)\n );\n}\n\nconst DECORATOR_DIALECTS: babel.ParserOptions['plugins'][] = [\n [\n 'typescript',\n 'decorators-legacy',\n 'decoratorAutoAccessors',\n 'explicitResourceManagement',\n ],\n [\n 'typescript',\n ['decorators', {}],\n 'decoratorAutoAccessors',\n 'explicitResourceManagement',\n ],\n];\n\nconst dropTypeOnlyImportEquals = (): babel.PluginObj => ({\n visitor: {\n TSImportEqualsDeclaration(path) {\n if (path.node.importKind === 'type') path.remove();\n },\n },\n});\n\nconst parsedTo = (err: unknown): number => (err as { pos?: number }).pos ?? -1;\n\nexport function transformTypeScriptModule(\n code: string,\n options: Omit<babel.TransformOptions, 'parserOpts'>\n): babel.BabelFileResult | null {\n let parseError: unknown;\n for (const plugins of DECORATOR_DIALECTS) {\n try {\n return babel.transformSync(code, {\n ...options,\n plugins: [dropTypeOnlyImportEquals, ...(options.plugins ?? [])],\n parserOpts: {\n sourceType: 'module',\n plugins,\n createParenthesizedExpressions: true,\n },\n });\n } catch (err) {\n if ((err as { code?: string }).code !== 'BABEL_PARSE_ERROR') throw err;\n if (parseError === undefined || parsedTo(err) > parsedTo(parseError))\n parseError = err;\n }\n }\n throw parseError;\n}\n\n/** @codexApi {\"parent\":\"pithy.vite.html-transform-plugin\",\"name\":\"HtmlTransformPluginOptions\",\"stability\":\"stable\",\"signature\":\"interface HtmlTransformPluginOptions\"} */\nexport interface HtmlTransformPluginOptions {\n /** Map of component names to variables they inject into children's scope */\n componentScopes?: ComponentScopesMap;\n /** Enable AOT template compilation. Default: true in build mode, false in dev. */\n aot?: boolean;\n /** Fail the build if any template falls back to JIT, i.e. any `[pithy:aot:jit-fallback]` report. Default: false. */\n strictAot?: boolean;\n}\n\n/**\n * Vite plugin that transforms `html\\`\\`` tagged templates and literal `html()` calls\n * in `.ts` and compiled `.pithy` modules using Babel.\n *\n * In build mode, templates are AOT-compiled to eliminate runtime HTML parsing.\n * In dev mode, tagged templates only get their context injected and still render\n * through the runtime compiler, unless `aot` is explicitly enabled.\n * `pithyPlugin()` must be listed before this plugin.\n *\n * @param options - Plugin configuration for AOT mode, strict AOT, and component scopes\n * @returns A Vite plugin that transforms html tagged templates\n *\n * @example\n * ```ts\n * import { htmlTransformPlugin } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [htmlTransformPlugin({ aot: true })],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite.html-transform-plugin\",\"name\":\"htmlTransformPlugin\",\"stability\":\"stable\",\"signature\":\"(options?: HtmlTransformPluginOptions) => PluginOption\"} */\nexport function htmlTransformPlugin(\n options?: HtmlTransformPluginOptions\n): PluginOption {\n let resolvedAot = false;\n let sourceMaps = true;\n let lowering: Pick<ESBuildOptions, 'target' | 'supported'> | null = null;\n\n const plugin = {\n name: 'pithy:html-transform',\n enforce: 'pre' as const,\n\n configResolved(config: ResolvedConfig) {\n // Default: AOT enabled in build, disabled in dev (for faster HMR)\n resolvedAot = options?.aot ?? config.command === 'build';\n\n sourceMaps = config.command === 'serve' || !!config.build?.sourcemap;\n\n const { target, supported } = config.esbuild || {};\n lowering = target || supported ? { target, supported } : null;\n\n const plugins = config.plugins ?? [];\n const sfc = plugins.findIndex(p => p.name === 'vite-plugin-pithy');\n if (sfc !== -1 && sfc > plugins.indexOf(plugin)) {\n throw new Error(\n '[pithy:html-transform] pithyPlugin() must be listed before htmlTransformPlugin(), ' +\n 'so .pithy files reach the template transform already compiled.'\n );\n }\n },\n\n transform(code: string, id: string) {\n // Strip Vite query/hash suffixes (e.g. component.ts?import → component.ts)\n const normalizedId = id.split(/[?#]/, 1)[0];\n // Fast-path: skip files with no pithy tagged templates.\n // Check for html` (common case) or aliased html import from @pithyjs/core.\n const isPithy = normalizedId.endsWith('.pithy');\n if (!normalizedId.endsWith('.ts') && !isPithy) return;\n const reads = readsTemplates(code);\n if (!reads && !(isPithy && lowering)) return;\n if (!reads) return lowerPithy(code, null, normalizedId);\n\n const babelPluginOptions: PithyBabelPluginOptions = {\n componentScopes: options?.componentScopes,\n aot: resolvedAot,\n strictAot: options?.strictAot,\n filename: normalizedId,\n };\n\n const result = transformTypeScriptModule(code, {\n filename: normalizedId,\n plugins: [() => pithyBabelPlugin(babelPluginOptions)],\n configFile: false,\n sourceMaps,\n });\n\n const transformed = {\n code: result?.code ?? code,\n map: result?.map ?? null,\n };\n return isPithy && lowering\n ? lowerPithy(transformed.code, transformed.map, normalizedId)\n : transformed;\n },\n };\n\n async function lowerPithy(\n code: string,\n map: babel.BabelFileResult['map'] | null,\n id: string\n ) {\n const { transformWithEsbuild } = await import('vite');\n const lowered = await transformWithEsbuild(\n code,\n id,\n {\n loader: 'js',\n target: lowering?.target,\n supported: {\n 'dynamic-import': true,\n 'import-meta': true,\n ...lowering?.supported,\n },\n sourcemap: sourceMaps,\n },\n map ?? undefined\n );\n return { code: lowered.code, map: lowered.map };\n }\n\n return plugin;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithyjs/vite-plugin",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.27",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/PithyJS/pithyjs.git",
|
|
@@ -29,14 +29,13 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/core": "^7.27.4",
|
|
31
31
|
"@babel/parser": "^7.27.5",
|
|
32
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
33
32
|
"@babel/traverse": "^7.27.4",
|
|
34
33
|
"@babel/types": "^7.27.3",
|
|
35
34
|
"fast-glob": "^3.3.0",
|
|
36
35
|
"parse5": "^7.3.0",
|
|
37
|
-
"@pithyjs/compiler": "0.1.0-beta.
|
|
36
|
+
"@pithyjs/compiler": "0.1.0-beta.12",
|
|
38
37
|
"@pithyjs/design-system": "0.1.0-beta.12",
|
|
39
|
-
"@pithyjs/router": "0.2.0-beta.
|
|
38
|
+
"@pithyjs/router": "0.2.0-beta.24",
|
|
40
39
|
"@pithyjs/shared": "0.1.0-beta.4"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|