@sparknest/ui-build-vue 1.2.1 → 1.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparknest/ui-build-vue",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "Shared Vue component-library build core for Cedar and Maple",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.mjs CHANGED
@@ -326,6 +326,39 @@ async function buildModules(config, format, outDir, extension) {
326
326
  })
327
327
  }
328
328
 
329
+ // A published library must not ship bundler-private helpers. Vite's module
330
+ // preload injection is the known offender: it emits `_virtual/preload-helper`
331
+ // and rewrites every dynamic `import()` into `__vitePreload(...)`. When a
332
+ // consumer bundles the library with rolldown (vite 8), rolldown injects its own
333
+ // helper into the same module -> `PARSE_ERROR: Identifier __vitePreload has
334
+ // already been declared`. `build.modulePreload: false` does NOT prevent this on
335
+ // vite 5 (insertPreload only checks ssr / build.lib / isWorker), so the fix has
336
+ // to happen in the library source: ship a static import (externalized) instead
337
+ // of a dynamic one.
338
+ async function assertNoBundlerHelpers(config) {
339
+ const root = resolve(config.root)
340
+ const markers = ['_virtual/preload-helper', '__vitePreload']
341
+ const offenders = []
342
+ for (const output of ['es', 'lib']) {
343
+ const dir = resolve(root, output)
344
+ if (!existsSync(dir)) continue
345
+ for (const path of await walk(dir)) {
346
+ if (!/\.[cm]?js$/.test(path)) continue
347
+ const code = await readFile(path, 'utf8')
348
+ if (markers.some((marker) => code.includes(marker))) {
349
+ offenders.push(relative(root, path))
350
+ }
351
+ }
352
+ }
353
+ if (offenders.length) {
354
+ throw new Error([
355
+ 'Library output contains bundler-private preload helpers; consumers bundling with rolldown/vite 8 cannot parse them:',
356
+ ...offenders.map((path) => ` ${path}`),
357
+ 'Replace the dynamic import() in the matching source file with a static import and mark the module external.',
358
+ ].join('\n'))
359
+ }
360
+ }
361
+
329
362
  async function buildBundle(config, format, outDir, fileName) {
330
363
  const root = resolve(config.root)
331
364
  await build({
@@ -408,6 +441,7 @@ export async function buildLibrary(userConfig) {
408
441
 
409
442
  await buildModules(config, 'es', 'es', 'mjs')
410
443
  await buildModules(config, 'cjs', 'lib', 'js')
444
+ await assertNoBundlerHelpers(config)
411
445
  await buildBundle(config, 'es', 'es', `${config.bundleName}.esm.js`)
412
446
  await buildBundle(config, 'cjs', 'lib', `${config.bundleName}.cjs.js`)
413
447
  await buildBundle(config, 'umd', 'umd', `${config.bundleName}.js`)