@torpor/unplugin 1.0.2 → 1.0.3
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.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ const unpluginFactory = (options) => ({
|
|
|
30
30
|
let name = id.split(/[\\/]/).at(-1).replace(/\.torp$/, "");
|
|
31
31
|
let errorMessages = parsed.errors.map((e) => `${e.startLine + 1},${e.startChar}: ${e.message}`);
|
|
32
32
|
console.log(`\nERRORS: ${id}\n======\n${errorMessages.join("\n")}`);
|
|
33
|
-
let
|
|
33
|
+
let errorCode = `
|
|
34
34
|
export default function Error() {
|
|
35
35
|
@render {
|
|
36
36
|
<div style="background-color: #222; color: #f44"; font-size: 15px; line-height: 1.5;">
|
|
@@ -42,7 +42,8 @@ export default function Error() {
|
|
|
42
42
|
</ul>
|
|
43
43
|
</div>
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}`;
|
|
46
|
+
let errorParsed = parse(errorCode);
|
|
46
47
|
if (errorParsed.ok && errorParsed.template) return transform(errorParsed.template, id, options);
|
|
47
48
|
throw new Error(`Parse failed for ${id}, ${errorMessages.join("\n")}`);
|
|
48
49
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type Template, build, parse } from \"@torpor/view/compile\";\nimport { type UnpluginFactory, type UnpluginInstance } from \"unplugin\";\nimport { createUnplugin } from \"unplugin\";\nimport { transformWithOxc } from \"vite\";\nimport type Options from \"./types\";\n\nconst styles = new Map<string, string>();\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options) => ({\n\tname: \"unplugin-torpor\",\n\tresolveId(id /*, importer, options*/) {\n\t\tif (styles.has(id)) {\n\t\t\treturn id;\n\t\t}\n\t\treturn undefined;\n\t},\n\tload(id) {\n\t\tif (styles.has(id)) {\n\t\t\treturn styles.get(id);\n\t\t}\n\t\treturn undefined;\n\t},\n\ttransformInclude(id) {\n\t\t// Check for *.torp files\n\t\treturn /\\.torp\\?*/.test(id);\n\t},\n\t// @ts-ignore\n\ttransform(code, id, viteOptions) {\n\t\t// We may be in dev mode\n\t\tif (viteOptions && viteOptions.dev !== undefined) {\n\t\t\toptions ??= {};\n\t\t\toptions.dev = viteOptions.dev;\n\t\t}\n\n\t\t// Vite can override user server options\n\t\tif (viteOptions && viteOptions.ssr !== undefined) {\n\t\t\toptions ??= {};\n\t\t\toptions.server = viteOptions.ssr;\n\t\t}\n\n\t\t// But when testing we always generate for the server\n\t\tif (options?.test) {\n\t\t\toptions.server = true;\n\t\t}\n\n\t\t// Try to parse the code\n\t\tlet parsed = parse(code);\n\t\tif (parsed.ok && parsed.template) {\n\t\t\t// Transform for server or client\n\t\t\treturn transform(parsed.template, id, options);\n\t\t} else {\n\t\t\t// Show an error component\n\t\t\tlet name = id\n\t\t\t\t.split(/[\\\\/]/)\n\t\t\t\t.at(-1)\n\t\t\t\t.replace(/\\.torp$/, \"\")!;\n\t\t\tlet errorMessages = parsed.errors.map(\n\t\t\t\t(e) => `${e.startLine + 1},${e.startChar}: ${e.message}`,\n\t\t\t);\n\t\t\tconsole.log(`\\nERRORS: ${id}\\n======\\n${errorMessages.join(\"\\n\")}`);\n\t\t\tlet errorCode = `\nexport default function Error() {\n\t@render {\n\t\t<div style=\"background-color: #222; color: #f44\"; font-size: 15px; line-height: 1.5;\">\n\t\t\t<p style=\"margin: 0; padding: 0;\">\n\t\t\t\t<strong>Error${parsed.errors.length === 1 ? \"\" : \"s\"} in ${name}:</strong>\n\t\t\t</p>\n\t\t\t<ul style=\"margin: 0; padding: 0 20px\">\n\t\t\t\t${errorMessages.map((e) => `<li>${e}</li>`).join(\"\\n\")}\n\t\t\t</ul>\n\t\t</div>\n\t}\n}`;\n\t\t\tlet errorParsed = parse(errorCode);\n\t\t\tif (errorParsed.ok && errorParsed.template) {\n\t\t\t\treturn transform(errorParsed.template, id, options);\n\t\t\t}\n\t\t\t// This should never be reached, but just in case...\n\t\t\tthrow new Error(`Parse failed for ${id}, ${errorMessages.join(\"\\n\")}`);\n\t\t}\n\t},\n});\n\nfunction transform(template: Template, id: string, options?: Options) {\n\tconst built = build(template, options);\n\tlet transformed = built.code;\n\n\tif (built.styles) {\n\t\tfor (let style of built.styles) {\n\t\t\t// Add a dynamic import for the component's CSS with a name from\n\t\t\t// the hash and add the styles to a map. Then resolveId will\n\t\t\t// pass the CSS id onto load, which will load the the actual CSS\n\t\t\t// from the map\n\t\t\ttransformed = `import '${style.hash}.css';\\n` + transformed;\n\t\t\tstyles.set(style.hash + \".css\", style.style);\n\t\t}\n\t}\n\n\t//printTransformed(transformed);\n\n\t// TODO: Compile typescript only if script lang=\"ts\" or config.lang=\"ts\"\n\treturn transformWithOxc(transformed, id.replace(/\\.torp.*$/, \".ts\"));\n}\n\n/*\nfunction printTransformed(transformed: string) {\n\tconsole.log(\n\t\ttransformed\n\t\t\t.split(\"\\n\")\n\t\t\t.map((l, i) => `${(i + 1).toString().padEnd(3)} ${l}`)\n\t\t\t.join(\"\\n\"),\n\t);\n}\n*/\n\nexport const unplugin: UnpluginInstance<Options | undefined, boolean> =\n\t/* #__PURE__ */ createUnplugin(unpluginFactory);\n\nexport default unplugin;\n"],"mappings":";;;;AAMA,MAAM,yBAAS,IAAI,IAAoB;AAEvC,MAAa,mBAAyD,aAAa;CAClF,MAAM;CACN,UAAU,IAA4B;EACrC,IAAI,OAAO,IAAI,EAAE,GAChB,OAAO;CAGT;CACA,KAAK,IAAI;EACR,IAAI,OAAO,IAAI,EAAE,GAChB,OAAO,OAAO,IAAI,EAAE;CAGtB;CACA,iBAAiB,IAAI;EAEpB,OAAO,YAAY,KAAK,EAAE;CAC3B;CAEA,UAAU,MAAM,IAAI,aAAa;EAEhC,IAAI,eAAe,YAAY,QAAQ,KAAA,GAAW;GACjD,YAAY,CAAC;GACb,QAAQ,MAAM,YAAY;EAC3B;EAGA,IAAI,eAAe,YAAY,QAAQ,KAAA,GAAW;GACjD,YAAY,CAAC;GACb,QAAQ,SAAS,YAAY;EAC9B;EAGA,IAAI,SAAS,MACZ,QAAQ,SAAS;EAIlB,IAAI,SAAS,MAAM,IAAI;EACvB,IAAI,OAAO,MAAM,OAAO,UAEvB,OAAO,UAAU,OAAO,UAAU,IAAI,OAAO;OACvC;GAEN,IAAI,OAAO,GACT,MAAM,OAAO,CAAC,CACd,GAAG,EAAE,CAAC,CACN,QAAQ,WAAW,EAAE;GACvB,IAAI,gBAAgB,OAAO,OAAO,KAChC,MAAM,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE,SAChD;GACA,QAAQ,IAAI,aAAa,GAAG,YAAY,cAAc,KAAK,IAAI,GAAG;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type Template, build, parse } from \"@torpor/view/compile\";\nimport { type UnpluginFactory, type UnpluginInstance } from \"unplugin\";\nimport { createUnplugin } from \"unplugin\";\nimport { transformWithOxc } from \"vite\";\nimport type Options from \"./types\";\n\nconst styles = new Map<string, string>();\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options) => ({\n\tname: \"unplugin-torpor\",\n\tresolveId(id /*, importer, options*/) {\n\t\tif (styles.has(id)) {\n\t\t\treturn id;\n\t\t}\n\t\treturn undefined;\n\t},\n\tload(id) {\n\t\tif (styles.has(id)) {\n\t\t\treturn styles.get(id);\n\t\t}\n\t\treturn undefined;\n\t},\n\ttransformInclude(id) {\n\t\t// Check for *.torp files\n\t\treturn /\\.torp\\?*/.test(id);\n\t},\n\t// @ts-ignore\n\ttransform(code, id, viteOptions) {\n\t\t// We may be in dev mode\n\t\tif (viteOptions && viteOptions.dev !== undefined) {\n\t\t\toptions ??= {};\n\t\t\toptions.dev = viteOptions.dev;\n\t\t}\n\n\t\t// Vite can override user server options\n\t\tif (viteOptions && viteOptions.ssr !== undefined) {\n\t\t\toptions ??= {};\n\t\t\toptions.server = viteOptions.ssr;\n\t\t}\n\n\t\t// But when testing we always generate for the server\n\t\tif (options?.test) {\n\t\t\toptions.server = true;\n\t\t}\n\n\t\t// Try to parse the code\n\t\tlet parsed = parse(code);\n\t\tif (parsed.ok && parsed.template) {\n\t\t\t// Transform for server or client\n\t\t\treturn transform(parsed.template, id, options);\n\t\t} else {\n\t\t\t// Show an error component\n\t\t\tlet name = id\n\t\t\t\t.split(/[\\\\/]/)\n\t\t\t\t.at(-1)\n\t\t\t\t.replace(/\\.torp$/, \"\")!;\n\t\t\tlet errorMessages = parsed.errors.map(\n\t\t\t\t(e) => `${e.startLine + 1},${e.startChar}: ${e.message}`,\n\t\t\t);\n\t\t\tconsole.log(`\\nERRORS: ${id}\\n======\\n${errorMessages.join(\"\\n\")}`);\n\t\t\tlet errorCode = `\nexport default function Error() {\n\t@render {\n\t\t<div style=\"background-color: #222; color: #f44\"; font-size: 15px; line-height: 1.5;\">\n\t\t\t<p style=\"margin: 0; padding: 0;\">\n\t\t\t\t<strong>Error${parsed.errors.length === 1 ? \"\" : \"s\"} in ${name}:</strong>\n\t\t\t</p>\n\t\t\t<ul style=\"margin: 0; padding: 0 20px\">\n\t\t\t\t${errorMessages.map((e) => `<li>${e}</li>`).join(\"\\n\")}\n\t\t\t</ul>\n\t\t</div>\n\t}\n}`;\n\t\t\tlet errorParsed = parse(errorCode);\n\t\t\tif (errorParsed.ok && errorParsed.template) {\n\t\t\t\treturn transform(errorParsed.template, id, options);\n\t\t\t}\n\t\t\t// This should never be reached, but just in case...\n\t\t\tthrow new Error(`Parse failed for ${id}, ${errorMessages.join(\"\\n\")}`);\n\t\t}\n\t},\n});\n\nfunction transform(template: Template, id: string, options?: Options) {\n\tconst built = build(template, options);\n\tlet transformed = built.code;\n\n\tif (built.styles) {\n\t\tfor (let style of built.styles) {\n\t\t\t// Add a dynamic import for the component's CSS with a name from\n\t\t\t// the hash and add the styles to a map. Then resolveId will\n\t\t\t// pass the CSS id onto load, which will load the the actual CSS\n\t\t\t// from the map\n\t\t\ttransformed = `import '${style.hash}.css';\\n` + transformed;\n\t\t\tstyles.set(style.hash + \".css\", style.style);\n\t\t}\n\t}\n\n\t//printTransformed(transformed);\n\n\t// TODO: Compile typescript only if script lang=\"ts\" or config.lang=\"ts\"\n\treturn transformWithOxc(transformed, id.replace(/\\.torp.*$/, \".ts\"));\n}\n\n/*\nfunction printTransformed(transformed: string) {\n\tconsole.log(\n\t\ttransformed\n\t\t\t.split(\"\\n\")\n\t\t\t.map((l, i) => `${(i + 1).toString().padEnd(3)} ${l}`)\n\t\t\t.join(\"\\n\"),\n\t);\n}\n*/\n\nexport const unplugin: UnpluginInstance<Options | undefined, boolean> =\n\t/* #__PURE__ */ createUnplugin(unpluginFactory);\n\nexport default unplugin;\n"],"mappings":";;;;AAMA,MAAM,yBAAS,IAAI,IAAoB;AAEvC,MAAa,mBAAyD,aAAa;CAClF,MAAM;CACN,UAAU,IAA4B;EACrC,IAAI,OAAO,IAAI,EAAE,GAChB,OAAO;CAGT;CACA,KAAK,IAAI;EACR,IAAI,OAAO,IAAI,EAAE,GAChB,OAAO,OAAO,IAAI,EAAE;CAGtB;CACA,iBAAiB,IAAI;EAEpB,OAAO,YAAY,KAAK,EAAE;CAC3B;CAEA,UAAU,MAAM,IAAI,aAAa;EAEhC,IAAI,eAAe,YAAY,QAAQ,KAAA,GAAW;GACjD,YAAY,CAAC;GACb,QAAQ,MAAM,YAAY;EAC3B;EAGA,IAAI,eAAe,YAAY,QAAQ,KAAA,GAAW;GACjD,YAAY,CAAC;GACb,QAAQ,SAAS,YAAY;EAC9B;EAGA,IAAI,SAAS,MACZ,QAAQ,SAAS;EAIlB,IAAI,SAAS,MAAM,IAAI;EACvB,IAAI,OAAO,MAAM,OAAO,UAEvB,OAAO,UAAU,OAAO,UAAU,IAAI,OAAO;OACvC;GAEN,IAAI,OAAO,GACT,MAAM,OAAO,CAAC,CACd,GAAG,EAAE,CAAC,CACN,QAAQ,WAAW,EAAE;GACvB,IAAI,gBAAgB,OAAO,OAAO,KAChC,MAAM,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,IAAI,EAAE,SAChD;GACA,QAAQ,IAAI,aAAa,GAAG,YAAY,cAAc,KAAK,IAAI,GAAG;GAClE,IAAI,YAAY;;;;;mBAKA,OAAO,OAAO,WAAW,IAAI,KAAK,IAAI,MAAM,KAAK;;;MAG9D,cAAc,KAAK,MAAM,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE;;;;;GAKxD,IAAI,cAAc,MAAM,SAAS;GACjC,IAAI,YAAY,MAAM,YAAY,UACjC,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;GAGnD,MAAM,IAAI,MAAM,oBAAoB,GAAG,IAAI,cAAc,KAAK,IAAI,GAAG;EACtE;CACD;AACD;AAEA,SAAS,UAAU,UAAoB,IAAY,SAAmB;CACrE,MAAM,QAAQ,MAAM,UAAU,OAAO;CACrC,IAAI,cAAc,MAAM;CAExB,IAAI,MAAM,QACT,KAAK,IAAI,SAAS,MAAM,QAAQ;EAK/B,cAAc,WAAW,MAAM,KAAK,YAAY;EAChD,OAAO,IAAI,MAAM,OAAO,QAAQ,MAAM,KAAK;CAC5C;CAMD,OAAO,iBAAiB,aAAa,GAAG,QAAQ,aAAa,KAAK,CAAC;AACpE;AAaA,MAAa,WACI,+BAAe,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/unplugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Unplugin package to compile Torpor components for Vite, Rollup, and other bundlers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"torpor",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"unplugin": "^3.3.0",
|
|
93
|
-
"@torpor/view": "^1.0.
|
|
93
|
+
"@torpor/view": "^1.0.3"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@antfu/eslint-config": "^9.2.0",
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"rimraf": "^6.1.3",
|
|
108
108
|
"rollup": "^4.62.4",
|
|
109
109
|
"typescript": "^7.0.2",
|
|
110
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@0.
|
|
111
|
-
"vite-plus": "0.
|
|
110
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
|
|
111
|
+
"vite-plus": "0.3.0",
|
|
112
112
|
"webpack": "^5.109.2"
|
|
113
113
|
},
|
|
114
114
|
"scripts": {
|