@vizejs/vite-plugin-musea 0.242.0 → 0.250.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/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +45 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/plugin.ts","../src/plugin/index.ts","../src/tokens/parser.ts","../src/tokens/usage.ts","../src/tokens/resolver.ts","../src/tokens/generator.ts"],"mappings":";;;;;;;;;;UAMiB,gBAAA;EACf,SAAA;EACA,WAAA;EACA,UAAA;EACA,UAAA;EACA,MAAA;EACA,WAAA;EACA,cAAA;EACA,YAAA;EACA,IAAA;EACA,aAAA;EACA,SAAA;EACA,MAAA;EACA,YAAA;EACA,OAAA;EACA,KAAA;EACA,IAAA;EACA,OAAA;EACA,MAAA;AAAA;;;;UAMe,UAAA;EANT;EAQN,IAAA;EAFyB;EAIzB,IAAA;EAEwB;EAAxB,MAAA,EAAQ,gBAAA;AAAA;;;;UAMO,YAAA;EAAA;;;;EAKf,OAAA;EAsDmD;;;;EAhDnD,OAAA;EAMA;;;;EAAA,QAAA;EAyBM;;;;EAnBN,eAAA;EA8CA;;;;EAxCA,eAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/plugin.ts","../src/plugin/index.ts","../src/tokens/parser.ts","../src/tokens/usage.ts","../src/tokens/resolver.ts","../src/tokens/generator.ts"],"mappings":";;;;;;;;;;UAMiB,gBAAA;EACf,SAAA;EACA,WAAA;EACA,UAAA;EACA,UAAA;EACA,MAAA;EACA,WAAA;EACA,cAAA;EACA,YAAA;EACA,IAAA;EACA,aAAA;EACA,SAAA;EACA,MAAA;EACA,YAAA;EACA,OAAA;EACA,KAAA;EACA,IAAA;EACA,OAAA;EACA,MAAA;AAAA;;;;UAMe,UAAA;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AAA;EACA,WAAA;EACA,QAAA;AAAA;;;;UAMe,eAAA;EACf,OAAA;EACA,QAAA;EACA,WAAA;EACA,OAAA,EAAS,eAAA;AAAA;;;;KAMC,aAAA,GAAgB,MAAA,SAAe,eAAA;;AJV3C;;iBI+BgB,aAAA,CAAc,UAAA,EAAY,aAAA,KAAkB,MAAA,SAAe,WAAA;;;;iBAO3D,iBAAA,CACd,UAAA,EAAY,aAAA,IACZ,SAAA,EAAW,MAAA,SAAe,WAAA;;;;;;iBC/BZ,kBAAA,CAAmB,UAAA,EAAY,aAAA;;;;iBAgI/B,sBAAA,CAAuB,UAAA,EAAY,aAAA;;;;;iBAQ7B,sBAAA,CACpB,MAAA,EAAQ,qBAAA,GACP,OAAA,CAAQ,qBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -178,16 +178,28 @@ async function generateStorybookFiles(artFiles, root, outDir) {
|
|
|
178
178
|
const binding = loadNative();
|
|
179
179
|
const outputDir = path.resolve(root, outDir);
|
|
180
180
|
await fs.promises.mkdir(outputDir, { recursive: true });
|
|
181
|
-
for (const [filePath,
|
|
181
|
+
for (const [filePath, art] of artFiles) try {
|
|
182
182
|
const source = await fs.promises.readFile(filePath, "utf-8");
|
|
183
183
|
const csf = binding.artToCsf(source, { filename: filePath });
|
|
184
184
|
const outputPath = path.join(outputDir, csf.filename);
|
|
185
|
-
|
|
185
|
+
const code = rewriteStorybookComponentImport(csf.code, art, filePath, outputPath);
|
|
186
|
+
await fs.promises.writeFile(outputPath, code, "utf-8");
|
|
186
187
|
console.log(`[musea] Generated: ${path.relative(root, outputPath)}`);
|
|
187
188
|
} catch (e) {
|
|
188
189
|
console.error(`[musea] Failed to generate CSF for ${filePath}:`, e);
|
|
189
190
|
}
|
|
190
191
|
}
|
|
192
|
+
function rewriteStorybookComponentImport(code, art, artPath, outputPath) {
|
|
193
|
+
const component = art.isInline && art.componentPath ? art.componentPath : art.metadata.component;
|
|
194
|
+
if (!component || isBareImport(component)) return code;
|
|
195
|
+
const resolvedComponent = path.isAbsolute(component) ? component : path.resolve(path.dirname(artPath), component);
|
|
196
|
+
let relativeComponent = normalizeGlobPath(path.relative(path.dirname(outputPath), resolvedComponent));
|
|
197
|
+
if (!relativeComponent.startsWith(".")) relativeComponent = `./${relativeComponent}`;
|
|
198
|
+
return code.replace(/import\s+(__museaComponent)\s+from\s+(['"])([^'"]+)\2;/, `import $1 from $2${relativeComponent}$2;`);
|
|
199
|
+
}
|
|
200
|
+
function isBareImport(source) {
|
|
201
|
+
return !source.startsWith(".") && !path.isAbsolute(source);
|
|
202
|
+
}
|
|
191
203
|
function toPascalCase(str) {
|
|
192
204
|
const pascal = str.normalize("NFKD").replace(/[^\p{L}\p{N}]+/gu, " ").trim().split(/\s+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
193
205
|
if (!pascal) return "Variant";
|
|
@@ -2894,6 +2906,22 @@ function watchMuseaArtFiles(watcher, files) {
|
|
|
2894
2906
|
watcher.add(targets);
|
|
2895
2907
|
}
|
|
2896
2908
|
//#endregion
|
|
2909
|
+
//#region src/plugin/vue-alias.ts
|
|
2910
|
+
const require = createRequire(import.meta.url);
|
|
2911
|
+
function createVueRuntimeCompilerAlias() {
|
|
2912
|
+
return {
|
|
2913
|
+
find: /^vue$/,
|
|
2914
|
+
replacement: resolveVueRuntimeCompiler()
|
|
2915
|
+
};
|
|
2916
|
+
}
|
|
2917
|
+
function resolveVueRuntimeCompiler() {
|
|
2918
|
+
try {
|
|
2919
|
+
return require.resolve("vue/dist/vue.esm-bundler.js");
|
|
2920
|
+
} catch {
|
|
2921
|
+
return "vue/dist/vue.esm-bundler.js";
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
//#endregion
|
|
2897
2925
|
//#region src/static-data.ts
|
|
2898
2926
|
function staticPreviewId(artPath, variantName) {
|
|
2899
2927
|
return crypto.createHash("sha256").update(artPath).update("\0").update(variantName).digest("hex").slice(0, 20);
|
|
@@ -3032,6 +3060,9 @@ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
|
3032
3060
|
function isMuseaStaticBuild() {
|
|
3033
3061
|
return process.env[MUSEA_STATIC_BUILD_ENV] === "1";
|
|
3034
3062
|
}
|
|
3063
|
+
function shouldEnableMuseaStaticBuild(command) {
|
|
3064
|
+
return isMuseaStaticBuild() || command === "build";
|
|
3065
|
+
}
|
|
3035
3066
|
function museaStaticBuildInput(input) {
|
|
3036
3067
|
const entries = {};
|
|
3037
3068
|
if (typeof input === "string") entries[STATIC_USER_INPUT_NAME] = input;
|
|
@@ -3047,6 +3078,9 @@ function applyMuseaStaticBuildInput(options) {
|
|
|
3047
3078
|
options.input = museaStaticBuildInput(options.input);
|
|
3048
3079
|
return null;
|
|
3049
3080
|
}
|
|
3081
|
+
function museaStaticBuildConfig(input) {
|
|
3082
|
+
return { build: { rollupOptions: { input: museaStaticBuildInput(input) } } };
|
|
3083
|
+
}
|
|
3050
3084
|
function resolveStaticRuntimeId(id) {
|
|
3051
3085
|
return id === "virtual:musea-static-runtime" ? RESOLVED_STATIC_RUNTIME : null;
|
|
3052
3086
|
}
|
|
@@ -3234,14 +3268,6 @@ function relativeUrl(fromDir, toFile) {
|
|
|
3234
3268
|
}
|
|
3235
3269
|
//#endregion
|
|
3236
3270
|
//#region src/plugin/index.ts
|
|
3237
|
-
const require = createRequire(import.meta.url);
|
|
3238
|
-
function resolveVueRuntimeCompiler() {
|
|
3239
|
-
try {
|
|
3240
|
-
return require.resolve("vue/dist/vue.esm-bundler.js");
|
|
3241
|
-
} catch {
|
|
3242
|
-
return "vue/dist/vue.esm-bundler.js";
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
3271
|
function extractArtTagAttributes(source) {
|
|
3246
3272
|
const artTagMatch = source.match(/<art\b([\s\S]*?)>/i);
|
|
3247
3273
|
if (!artTagMatch) return {};
|
|
@@ -3295,6 +3321,7 @@ function musea(options = {}) {
|
|
|
3295
3321
|
let resolvedPreviewCss = [];
|
|
3296
3322
|
let resolvedPreviewSetup = null;
|
|
3297
3323
|
let scanRoots = [];
|
|
3324
|
+
let staticBuildEnabled = isMuseaStaticBuild();
|
|
3298
3325
|
const virtualState = {
|
|
3299
3326
|
basePath,
|
|
3300
3327
|
get inlineArt() {
|
|
@@ -3316,8 +3343,13 @@ function musea(options = {}) {
|
|
|
3316
3343
|
apply(_config, env) {
|
|
3317
3344
|
return shouldApplyMuseaPlugin(env);
|
|
3318
3345
|
},
|
|
3319
|
-
config() {
|
|
3320
|
-
|
|
3346
|
+
config(userConfig, env) {
|
|
3347
|
+
staticBuildEnabled = shouldEnableMuseaStaticBuild(env.command);
|
|
3348
|
+
const staticBuildConfig = staticBuildEnabled ? museaStaticBuildConfig(userConfig.build?.rollupOptions?.input) : {};
|
|
3349
|
+
return {
|
|
3350
|
+
resolve: { alias: [createVueRuntimeCompilerAlias()] },
|
|
3351
|
+
...staticBuildConfig
|
|
3352
|
+
};
|
|
3321
3353
|
},
|
|
3322
3354
|
options: applyMuseaStaticBuildInput,
|
|
3323
3355
|
configResolved(resolvedConfig) {
|
|
@@ -3423,7 +3455,7 @@ function musea(options = {}) {
|
|
|
3423
3455
|
return loadStaticRuntimeModule(id, artFiles) ?? virtualLoad(id);
|
|
3424
3456
|
},
|
|
3425
3457
|
async generateBundle(_options, bundle) {
|
|
3426
|
-
if (!
|
|
3458
|
+
if (!staticBuildEnabled) return;
|
|
3427
3459
|
await emitStaticGallery((asset) => void this.emitFile(asset), bundle, {
|
|
3428
3460
|
config,
|
|
3429
3461
|
artFiles,
|