@vizejs/unplugin 0.660.0 → 0.661.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 +1 -1
- package/dist/babel.cjs +1 -1
- package/dist/babel.mjs +1 -1
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.mjs +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.mjs +1 -1
- package/dist/{unplugin-DPYDTPhZ.mjs → unplugin-Bs967qTR.mjs} +113 -35
- package/dist/{unplugin-BErqvAH5.cjs → unplugin-CpAttP-g.cjs} +114 -36
- package/dist/webpack-style-loader.cjs +1 -1
- package/dist/webpack-style-loader.mjs +1 -1
- package/dist/{webpack-styles-ClGUhlPP.mjs → webpack-styles-Ca7spvMb.mjs} +4 -3
- package/dist/{webpack-styles-BzhQ3HGs.cjs → webpack-styles-IFEnxDay.cjs} +4 -3
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
|
|
|
116
116
|
|
|
117
117
|
- Vite is still the recommended integration if you need the most complete behavior today.
|
|
118
118
|
- Plain inline CSS is injected into JavaScript at runtime; CSS asset extraction and SSR stylesheet delivery are not provided by this path.
|
|
119
|
-
- `<style src>`, `<script src>` and `<template src>`
|
|
119
|
+
- `<style src>`, `<script src>` and `<template src>` follow Vue's SFC spec, as in `@vitejs/plugin-vue`: a `./` or `../` path is read next to the SFC, and any other `src` (a package such as `modern-normalize/modern-normalize.css`, an alias, an absolute path, or a bare `foo.css`) is a module request resolved by the bundler's own resolver. The file is inlined before compilation and watched. A request that resolves to no file, including an external module, is a build error.
|
|
120
120
|
- `@import` in plain CSS is a build error. Plain CSS is injected at runtime as a string, so an `@import` would be fetched relative to the page. Inline the imported CSS, move the block to a preprocessor or CSS Module (handled by the host CSS pipeline), or use `@vizejs/vite-plugin`.
|
|
121
121
|
- CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
|
|
122
122
|
- Scoped preprocessor styles are compiled before they are scoped, as in Vue: Webpack uses your `.scss`/`.less`/`.styl` rules, while Rollup, Rolldown and esbuild run the project's installed `sass` (or `sass-embedded`), `less` or `stylus`.
|
package/dist/babel.cjs
CHANGED
package/dist/babel.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-
|
|
1
|
+
import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-Bs967qTR.mjs";
|
|
2
2
|
//#region src/babel.ts
|
|
3
3
|
function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
4
4
|
const options = normalizeOptions(rawOptions);
|
package/dist/esbuild.cjs
CHANGED
package/dist/esbuild.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_unplugin = require("./unplugin-
|
|
5
|
+
const require_unplugin = require("./unplugin-CpAttP-g.cjs");
|
|
6
6
|
exports.default = require_unplugin.vizeUnplugin;
|
|
7
7
|
exports.vizeUnplugin = require_unplugin.vizeUnplugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as vizeUnplugin } from "./unplugin-
|
|
1
|
+
import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
|
|
2
2
|
export { vizeUnplugin as default, vizeUnplugin };
|
package/dist/rolldown.cjs
CHANGED
package/dist/rolldown.mjs
CHANGED
package/dist/rollup.cjs
CHANGED
package/dist/rollup.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-
|
|
1
|
+
import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-Ca7spvMb.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
import { createUnplugin } from "unplugin";
|
|
5
6
|
import { createHash } from "node:crypto";
|
|
6
7
|
import * as native from "@vizejs/native";
|
|
7
8
|
import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
|
|
8
|
-
import path from "node:path";
|
|
9
9
|
import { transform } from "oxc-transform";
|
|
10
10
|
//#region src/filter.ts
|
|
11
11
|
function createFilter(include, exclude) {
|
|
@@ -227,6 +227,33 @@ function assertSupportedStyleDependencies(styles, filename) {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
//#endregion
|
|
230
|
+
//#region ../shared/sfc-src.ts
|
|
231
|
+
/**
|
|
232
|
+
* Whether a block `src` is a path relative to the SFC. Any other `src`
|
|
233
|
+
* (package, alias, absolute) is a module request that the bundler resolves,
|
|
234
|
+
* as in Vue's SFC spec and `@vitejs/plugin-vue`.
|
|
235
|
+
*/
|
|
236
|
+
function isRelativeSfcSrc(src) {
|
|
237
|
+
return src.startsWith("./") || src.startsWith("../");
|
|
238
|
+
}
|
|
239
|
+
/** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
|
|
240
|
+
function sfcSrcFile(importer, tag, src, resolutions) {
|
|
241
|
+
if (isRelativeSfcSrc(src)) return path.resolve(path.dirname(importer), src);
|
|
242
|
+
const file = resolutions?.get(src);
|
|
243
|
+
if (file !== void 0) return file;
|
|
244
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
|
|
245
|
+
}
|
|
246
|
+
/** Resolve an SFC's `src` module requests with the bundler's own resolver. */
|
|
247
|
+
async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
248
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
249
|
+
for (const request of new Set(requests)) {
|
|
250
|
+
if (isRelativeSfcSrc(request)) continue;
|
|
251
|
+
const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
|
|
252
|
+
if (file && path.isAbsolute(file)) resolutions.set(request, file);
|
|
253
|
+
}
|
|
254
|
+
return resolutions;
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
230
257
|
//#region src/src-blocks.ts
|
|
231
258
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
232
259
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
@@ -250,8 +277,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
250
277
|
openTag: `${head}${rest}>`
|
|
251
278
|
};
|
|
252
279
|
}
|
|
253
|
-
function readSrcBlock(filePath, tag, src) {
|
|
254
|
-
const resolved =
|
|
280
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
281
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
255
282
|
try {
|
|
256
283
|
return {
|
|
257
284
|
path: resolved,
|
|
@@ -261,44 +288,58 @@ function readSrcBlock(filePath, tag, src) {
|
|
|
261
288
|
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
262
289
|
}
|
|
263
290
|
}
|
|
264
|
-
|
|
265
|
-
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
266
|
-
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
267
|
-
* parser, so `src` text inside scripts or comments is left alone.
|
|
268
|
-
*/
|
|
269
|
-
function inlineSfcSrcBlocks(filePath, source) {
|
|
270
|
-
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
271
|
-
source,
|
|
272
|
-
dependencies: []
|
|
273
|
-
};
|
|
291
|
+
function collectSrcBlocks(filePath, bytes, source) {
|
|
274
292
|
let parsed;
|
|
275
293
|
try {
|
|
276
294
|
parsed = parseSfc(source, { filename: filePath });
|
|
277
295
|
} catch {
|
|
278
|
-
return
|
|
279
|
-
source,
|
|
280
|
-
dependencies: []
|
|
281
|
-
};
|
|
296
|
+
return [];
|
|
282
297
|
}
|
|
283
298
|
const blocks = [
|
|
284
299
|
["template", parsed.template],
|
|
285
300
|
["script", parsed.script],
|
|
286
301
|
...parsed.styles.map((style) => ["style", style])
|
|
287
302
|
];
|
|
288
|
-
const
|
|
289
|
-
const edits = [];
|
|
290
|
-
const dependencies = [];
|
|
303
|
+
const found = [];
|
|
291
304
|
for (const [tag, block] of blocks) {
|
|
292
305
|
if (!block) continue;
|
|
293
306
|
const { start, tagStart, tagEnd } = block.loc;
|
|
294
307
|
const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
|
|
295
|
-
if (
|
|
296
|
-
|
|
308
|
+
if (split) found.push({
|
|
309
|
+
tag,
|
|
310
|
+
...split,
|
|
311
|
+
tagStart,
|
|
312
|
+
tagEnd
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return found;
|
|
316
|
+
}
|
|
317
|
+
/** The `src` values of an SFC's blocks, in source order. */
|
|
318
|
+
function listSfcSrcBlocks(filePath, source) {
|
|
319
|
+
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
320
|
+
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
324
|
+
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
325
|
+
* parser, so `src` text inside scripts or comments is left alone. Module
|
|
326
|
+
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
327
|
+
*/
|
|
328
|
+
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
329
|
+
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
330
|
+
source,
|
|
331
|
+
dependencies: []
|
|
332
|
+
};
|
|
333
|
+
const bytes = Buffer.from(source);
|
|
334
|
+
const edits = [];
|
|
335
|
+
const dependencies = [];
|
|
336
|
+
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
337
|
+
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
297
338
|
dependencies.push(file.path);
|
|
298
339
|
edits.push({
|
|
299
|
-
start: tagStart,
|
|
300
|
-
end: tagEnd,
|
|
301
|
-
text: `${
|
|
340
|
+
start: block.tagStart,
|
|
341
|
+
end: block.tagEnd,
|
|
342
|
+
text: `${block.openTag}\n${file.content}\n</${block.tag}>`
|
|
302
343
|
});
|
|
303
344
|
}
|
|
304
345
|
if (edits.length === 0) return {
|
|
@@ -346,8 +387,8 @@ function buildSignature(options) {
|
|
|
346
387
|
function buildSourceHash(source) {
|
|
347
388
|
return createHash("sha256").update(source).digest("hex");
|
|
348
389
|
}
|
|
349
|
-
function compileVueModule(filePath, source, options, cache) {
|
|
350
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
|
|
390
|
+
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
391
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
351
392
|
const sourceHash = buildSourceHash(inlined);
|
|
352
393
|
const signature = buildSignature(options);
|
|
353
394
|
const cached = cache.get(filePath);
|
|
@@ -374,7 +415,9 @@ function compileVueModule(filePath, source, options, cache) {
|
|
|
374
415
|
runtimeModuleName: options.runtimeModuleName,
|
|
375
416
|
runtimeGlobalName: options.runtimeGlobalName,
|
|
376
417
|
vueVersion: String(options.vueVersion),
|
|
377
|
-
scopeId: `data-v-${scopeId}
|
|
418
|
+
scopeId: `data-v-${scopeId}`,
|
|
419
|
+
isProd: options.isProduction,
|
|
420
|
+
inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
|
|
378
421
|
});
|
|
379
422
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
380
423
|
assertSupportedStyleDependencies(result.styles, filePath);
|
|
@@ -572,22 +615,57 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
572
615
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
573
616
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
574
617
|
}
|
|
575
|
-
async function loadStyleBlock(id, options, cache) {
|
|
618
|
+
async function loadStyleBlock(context, id, options, cache) {
|
|
576
619
|
const request = parseVueRequest(id);
|
|
577
620
|
const index = request.query.index ?? -1;
|
|
578
621
|
if (index < 0) return "";
|
|
579
622
|
let compiled = cache.get(request.filename)?.compiled;
|
|
580
623
|
if (!compiled && fs.existsSync(request.filename)) {
|
|
581
624
|
const source = fs.readFileSync(request.filename, "utf8");
|
|
582
|
-
|
|
625
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
626
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
583
627
|
}
|
|
584
628
|
const block = compiled?.styles[index];
|
|
585
629
|
if (!compiled || !block) return "";
|
|
586
|
-
const source = transformStyleVars(block.content, compiled.scopeId);
|
|
630
|
+
const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
587
631
|
const scoped = request.query.scoped;
|
|
588
632
|
if (!scoped) return source;
|
|
589
633
|
return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
|
|
590
634
|
}
|
|
635
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
636
|
+
function hostResolver(context) {
|
|
637
|
+
const ctx = context;
|
|
638
|
+
if (typeof ctx.resolve === "function") {
|
|
639
|
+
const resolve = ctx.resolve;
|
|
640
|
+
return async (request, importer) => {
|
|
641
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
642
|
+
return result && !result.external ? result.id : null;
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const native = ctx.getNativeBuildContext?.();
|
|
646
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
647
|
+
const resolve = native.loaderContext.getResolve();
|
|
648
|
+
return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
|
|
649
|
+
}
|
|
650
|
+
if (native && "build" in native) {
|
|
651
|
+
const { build } = native;
|
|
652
|
+
return async (request, importer) => {
|
|
653
|
+
const result = await build.resolve(request, {
|
|
654
|
+
kind: "import-statement",
|
|
655
|
+
resolveDir: path.dirname(importer),
|
|
656
|
+
importer
|
|
657
|
+
});
|
|
658
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
664
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
665
|
+
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
666
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
667
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
668
|
+
}
|
|
591
669
|
const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
592
670
|
const options = normalizeOptions(rawOptions);
|
|
593
671
|
const filter = createFilter(options.include, options.exclude);
|
|
@@ -609,7 +687,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
609
687
|
if (options.hostCompiler) return null;
|
|
610
688
|
if (!isVirtualStyleId(id)) return null;
|
|
611
689
|
return {
|
|
612
|
-
code: await loadStyleBlock(id, options, cache),
|
|
690
|
+
code: await loadStyleBlock(this, id, options, cache),
|
|
613
691
|
map: null
|
|
614
692
|
};
|
|
615
693
|
},
|
|
@@ -632,7 +710,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
632
710
|
};
|
|
633
711
|
}
|
|
634
712
|
if (!isVueFile(id) || !filter(id)) return null;
|
|
635
|
-
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
|
|
713
|
+
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache, await resolveSrcRequests(this, id, code));
|
|
636
714
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
637
715
|
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
638
716
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
@@ -642,7 +720,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
642
720
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
643
721
|
const stylePath = webpackStylePath(id, block, scoped);
|
|
644
722
|
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
645
|
-
virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId));
|
|
723
|
+
virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
646
724
|
return webpackStyleRequest(stylePath, block);
|
|
647
725
|
} : void 0
|
|
648
726
|
}), options.sourceMap);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
1
|
+
const require_webpack_styles = require("./webpack-styles-IFEnxDay.cjs");
|
|
2
2
|
let node_fs = require("node:fs");
|
|
3
3
|
node_fs = require_webpack_styles.__toESM(node_fs, 1);
|
|
4
4
|
let node_module = require("node:module");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
5
7
|
let unplugin = require("unplugin");
|
|
6
8
|
let node_crypto = require("node:crypto");
|
|
7
9
|
let _vizejs_native = require("@vizejs/native");
|
|
8
10
|
_vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
|
|
9
|
-
let node_path = require("node:path");
|
|
10
|
-
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
11
11
|
let oxc_transform = require("oxc-transform");
|
|
12
12
|
//#region src/filter.ts
|
|
13
13
|
function createFilter(include, exclude) {
|
|
@@ -229,6 +229,33 @@ function assertSupportedStyleDependencies(styles, filename) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
//#endregion
|
|
232
|
+
//#region ../shared/sfc-src.ts
|
|
233
|
+
/**
|
|
234
|
+
* Whether a block `src` is a path relative to the SFC. Any other `src`
|
|
235
|
+
* (package, alias, absolute) is a module request that the bundler resolves,
|
|
236
|
+
* as in Vue's SFC spec and `@vitejs/plugin-vue`.
|
|
237
|
+
*/
|
|
238
|
+
function isRelativeSfcSrc(src) {
|
|
239
|
+
return src.startsWith("./") || src.startsWith("../");
|
|
240
|
+
}
|
|
241
|
+
/** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
|
|
242
|
+
function sfcSrcFile(importer, tag, src, resolutions) {
|
|
243
|
+
if (isRelativeSfcSrc(src)) return node_path.default.resolve(node_path.default.dirname(importer), src);
|
|
244
|
+
const file = resolutions?.get(src);
|
|
245
|
+
if (file !== void 0) return file;
|
|
246
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
|
|
247
|
+
}
|
|
248
|
+
/** Resolve an SFC's `src` module requests with the bundler's own resolver. */
|
|
249
|
+
async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
250
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
251
|
+
for (const request of new Set(requests)) {
|
|
252
|
+
if (isRelativeSfcSrc(request)) continue;
|
|
253
|
+
const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
|
|
254
|
+
if (file && node_path.default.isAbsolute(file)) resolutions.set(request, file);
|
|
255
|
+
}
|
|
256
|
+
return resolutions;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
232
259
|
//#region src/src-blocks.ts
|
|
233
260
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
234
261
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
@@ -252,8 +279,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
252
279
|
openTag: `${head}${rest}>`
|
|
253
280
|
};
|
|
254
281
|
}
|
|
255
|
-
function readSrcBlock(filePath, tag, src) {
|
|
256
|
-
const resolved =
|
|
282
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
283
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
257
284
|
try {
|
|
258
285
|
return {
|
|
259
286
|
path: resolved,
|
|
@@ -263,44 +290,58 @@ function readSrcBlock(filePath, tag, src) {
|
|
|
263
290
|
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
264
291
|
}
|
|
265
292
|
}
|
|
266
|
-
|
|
267
|
-
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
268
|
-
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
269
|
-
* parser, so `src` text inside scripts or comments is left alone.
|
|
270
|
-
*/
|
|
271
|
-
function inlineSfcSrcBlocks(filePath, source) {
|
|
272
|
-
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
273
|
-
source,
|
|
274
|
-
dependencies: []
|
|
275
|
-
};
|
|
293
|
+
function collectSrcBlocks(filePath, bytes, source) {
|
|
276
294
|
let parsed;
|
|
277
295
|
try {
|
|
278
296
|
parsed = (0, _vizejs_native.parseSfc)(source, { filename: filePath });
|
|
279
297
|
} catch {
|
|
280
|
-
return
|
|
281
|
-
source,
|
|
282
|
-
dependencies: []
|
|
283
|
-
};
|
|
298
|
+
return [];
|
|
284
299
|
}
|
|
285
300
|
const blocks = [
|
|
286
301
|
["template", parsed.template],
|
|
287
302
|
["script", parsed.script],
|
|
288
303
|
...parsed.styles.map((style) => ["style", style])
|
|
289
304
|
];
|
|
290
|
-
const
|
|
291
|
-
const edits = [];
|
|
292
|
-
const dependencies = [];
|
|
305
|
+
const found = [];
|
|
293
306
|
for (const [tag, block] of blocks) {
|
|
294
307
|
if (!block) continue;
|
|
295
308
|
const { start, tagStart, tagEnd } = block.loc;
|
|
296
309
|
const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
|
|
297
|
-
if (
|
|
298
|
-
|
|
310
|
+
if (split) found.push({
|
|
311
|
+
tag,
|
|
312
|
+
...split,
|
|
313
|
+
tagStart,
|
|
314
|
+
tagEnd
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return found;
|
|
318
|
+
}
|
|
319
|
+
/** The `src` values of an SFC's blocks, in source order. */
|
|
320
|
+
function listSfcSrcBlocks(filePath, source) {
|
|
321
|
+
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
322
|
+
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
326
|
+
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
327
|
+
* parser, so `src` text inside scripts or comments is left alone. Module
|
|
328
|
+
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
329
|
+
*/
|
|
330
|
+
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
331
|
+
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
332
|
+
source,
|
|
333
|
+
dependencies: []
|
|
334
|
+
};
|
|
335
|
+
const bytes = Buffer.from(source);
|
|
336
|
+
const edits = [];
|
|
337
|
+
const dependencies = [];
|
|
338
|
+
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
339
|
+
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
299
340
|
dependencies.push(file.path);
|
|
300
341
|
edits.push({
|
|
301
|
-
start: tagStart,
|
|
302
|
-
end: tagEnd,
|
|
303
|
-
text: `${
|
|
342
|
+
start: block.tagStart,
|
|
343
|
+
end: block.tagEnd,
|
|
344
|
+
text: `${block.openTag}\n${file.content}\n</${block.tag}>`
|
|
304
345
|
});
|
|
305
346
|
}
|
|
306
347
|
if (edits.length === 0) return {
|
|
@@ -348,8 +389,8 @@ function buildSignature(options) {
|
|
|
348
389
|
function buildSourceHash(source) {
|
|
349
390
|
return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
|
|
350
391
|
}
|
|
351
|
-
function compileVueModule(filePath, source, options, cache) {
|
|
352
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
|
|
392
|
+
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
393
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
353
394
|
const sourceHash = buildSourceHash(inlined);
|
|
354
395
|
const signature = buildSignature(options);
|
|
355
396
|
const cached = cache.get(filePath);
|
|
@@ -376,7 +417,9 @@ function compileVueModule(filePath, source, options, cache) {
|
|
|
376
417
|
runtimeModuleName: options.runtimeModuleName,
|
|
377
418
|
runtimeGlobalName: options.runtimeGlobalName,
|
|
378
419
|
vueVersion: String(options.vueVersion),
|
|
379
|
-
scopeId: `data-v-${scopeId}
|
|
420
|
+
scopeId: `data-v-${scopeId}`,
|
|
421
|
+
isProd: options.isProduction,
|
|
422
|
+
inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
|
|
380
423
|
});
|
|
381
424
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
382
425
|
assertSupportedStyleDependencies(result.styles, filePath);
|
|
@@ -574,22 +617,57 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
574
617
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
575
618
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
576
619
|
}
|
|
577
|
-
async function loadStyleBlock(id, options, cache) {
|
|
620
|
+
async function loadStyleBlock(context, id, options, cache) {
|
|
578
621
|
const request = parseVueRequest(id);
|
|
579
622
|
const index = request.query.index ?? -1;
|
|
580
623
|
if (index < 0) return "";
|
|
581
624
|
let compiled = cache.get(request.filename)?.compiled;
|
|
582
625
|
if (!compiled && node_fs.default.existsSync(request.filename)) {
|
|
583
626
|
const source = node_fs.default.readFileSync(request.filename, "utf8");
|
|
584
|
-
|
|
627
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
628
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
585
629
|
}
|
|
586
630
|
const block = compiled?.styles[index];
|
|
587
631
|
if (!compiled || !block) return "";
|
|
588
|
-
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId);
|
|
632
|
+
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
589
633
|
const scoped = request.query.scoped;
|
|
590
634
|
if (!scoped) return source;
|
|
591
635
|
return require_webpack_styles.scopeCss(block.lang && require_webpack_styles.isPreprocessorLang(block.lang) ? await require_webpack_styles.preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
|
|
592
636
|
}
|
|
637
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
638
|
+
function hostResolver(context) {
|
|
639
|
+
const ctx = context;
|
|
640
|
+
if (typeof ctx.resolve === "function") {
|
|
641
|
+
const resolve = ctx.resolve;
|
|
642
|
+
return async (request, importer) => {
|
|
643
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
644
|
+
return result && !result.external ? result.id : null;
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
const native = ctx.getNativeBuildContext?.();
|
|
648
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
649
|
+
const resolve = native.loaderContext.getResolve();
|
|
650
|
+
return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
|
|
651
|
+
}
|
|
652
|
+
if (native && "build" in native) {
|
|
653
|
+
const { build } = native;
|
|
654
|
+
return async (request, importer) => {
|
|
655
|
+
const result = await build.resolve(request, {
|
|
656
|
+
kind: "import-statement",
|
|
657
|
+
resolveDir: node_path.default.dirname(importer),
|
|
658
|
+
importer
|
|
659
|
+
});
|
|
660
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
666
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
667
|
+
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
668
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
669
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
670
|
+
}
|
|
593
671
|
const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
594
672
|
const options = normalizeOptions(rawOptions);
|
|
595
673
|
const filter = createFilter(options.include, options.exclude);
|
|
@@ -611,7 +689,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
611
689
|
if (options.hostCompiler) return null;
|
|
612
690
|
if (!isVirtualStyleId(id)) return null;
|
|
613
691
|
return {
|
|
614
|
-
code: await loadStyleBlock(id, options, cache),
|
|
692
|
+
code: await loadStyleBlock(this, id, options, cache),
|
|
615
693
|
map: null
|
|
616
694
|
};
|
|
617
695
|
},
|
|
@@ -634,7 +712,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
634
712
|
};
|
|
635
713
|
}
|
|
636
714
|
if (!isVueFile(id) || !filter(id)) return null;
|
|
637
|
-
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
|
|
715
|
+
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache, await resolveSrcRequests(this, id, code));
|
|
638
716
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
639
717
|
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
640
718
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
@@ -644,7 +722,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
644
722
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
645
723
|
const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
|
|
646
724
|
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
647
|
-
virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId));
|
|
725
|
+
virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
648
726
|
return require_webpack_styles.webpackStyleRequest(stylePath, block);
|
|
649
727
|
} : void 0
|
|
650
728
|
}), options.sourceMap);
|
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
5
|
+
const require_webpack_styles = require("./webpack-styles-IFEnxDay.cjs");
|
|
6
6
|
//#region src/webpack-style-loader.ts
|
|
7
7
|
const SCOPE_QUERY = "?scope";
|
|
8
8
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-
|
|
1
|
+
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-Ca7spvMb.mjs";
|
|
2
2
|
//#region src/webpack-style-loader.ts
|
|
3
3
|
const SCOPE_QUERY = "?scope";
|
|
4
4
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
//#region src/style-scope.ts
|
|
6
6
|
const PREPROCESSOR_LANGS = new Set([
|
|
@@ -20,8 +20,9 @@ function scopeCss(css, scoped) {
|
|
|
20
20
|
* `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
|
|
21
21
|
* The plugin compiles without `isProd`, so both sides use the dev names.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** `productionFilename` selects the hashed production names `useCssVars` uses. */
|
|
24
|
+
function transformStyleVars(css, scopeId, productionFilename) {
|
|
25
|
+
return transformViteCssVarsForPipeline(css, scopeId, productionFilename);
|
|
25
26
|
}
|
|
26
27
|
function loadPreprocessor(root, names, lang) {
|
|
27
28
|
const requireFromRoot = createRequire(path.join(root, "package.json"));
|
|
@@ -21,9 +21,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
23
|
let node_module = require("node:module");
|
|
24
|
-
let _vizejs_native = require("@vizejs/native");
|
|
25
24
|
let node_path = require("node:path");
|
|
26
25
|
node_path = __toESM(node_path, 1);
|
|
26
|
+
let _vizejs_native = require("@vizejs/native");
|
|
27
27
|
let node_url = require("node:url");
|
|
28
28
|
//#region src/style-scope.ts
|
|
29
29
|
const PREPROCESSOR_LANGS = new Set([
|
|
@@ -43,8 +43,9 @@ function scopeCss(css, scoped) {
|
|
|
43
43
|
* `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
|
|
44
44
|
* The plugin compiles without `isProd`, so both sides use the dev names.
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
/** `productionFilename` selects the hashed production names `useCssVars` uses. */
|
|
47
|
+
function transformStyleVars(css, scopeId, productionFilename) {
|
|
48
|
+
return (0, _vizejs_native.transformViteCssVarsForPipeline)(css, scopeId, productionFilename);
|
|
48
49
|
}
|
|
49
50
|
function loadPreprocessor(root, names, lang) {
|
|
50
51
|
const requireFromRoot = (0, node_module.createRequire)(node_path.default.join(root, "package.json"));
|
package/dist/webpack.cjs
CHANGED
package/dist/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/unplugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.661.0",
|
|
4
4
|
"description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@vizejs/native": "0.
|
|
71
|
+
"@vizejs/native": "0.661.0",
|
|
72
72
|
"oxc-transform": "0.144.0",
|
|
73
73
|
"unplugin": "3.3.0"
|
|
74
74
|
},
|