@void/vue 0.21.1 → 0.21.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.
Files changed (2) hide show
  1. package/dist/plugin.mjs +23 -36
  2. package/package.json +3 -3
package/dist/plugin.mjs CHANGED
@@ -3,7 +3,7 @@ import { generateComponentManifest, resolveEffectiveLayoutChain, resolvePagesDir
3
3
  import { existsSync, readFileSync, readdirSync } from "node:fs";
4
4
  import nodePath from "node:path";
5
5
  import { normalizePath } from "vite";
6
- import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
6
+ import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource, findIslandImports, findStaticCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
7
7
  //#region ../../node_modules/.pnpm/pathslash@0.1.0/node_modules/pathslash/dist/index.mjs
8
8
  const BACKSLASH_RE = /\\/g;
9
9
  const isWindows = process.platform === "win32";
@@ -51,23 +51,6 @@ const COMPONENT_EXTENSIONS = [
51
51
  ".ts",
52
52
  ".js"
53
53
  ];
54
- const ISLAND_IMPORT_RE = /import\s+([$_A-Za-z][$_\w]*)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*,?\s*\}/g;
55
- function findIslandImports(code) {
56
- const imports = [];
57
- let match;
58
- ISLAND_IMPORT_RE.lastIndex = 0;
59
- while ((match = ISLAND_IMPORT_RE.exec(code)) !== null) {
60
- const specifierRaw = match[2];
61
- imports.push({
62
- statement: match[0],
63
- importName: match[1],
64
- specifierRaw,
65
- specifier: specifierRaw.slice(1, -1),
66
- hydrate: match[3].slice(1, -1)
67
- });
68
- }
69
- return imports;
70
- }
71
54
  function extractCss(filePath) {
72
55
  const code = readFileSync(filePath, "utf-8");
73
56
  const parts = [];
@@ -130,7 +113,7 @@ function islandsPlugin(pagesDir, options) {
130
113
  const filePath = resolve(pagesDir, entry.filePath);
131
114
  const code = readFileSync(filePath, "utf-8");
132
115
  const importerDir = dirname(filePath);
133
- for (const islandImport of findIslandImports(code)) {
116
+ for (const islandImport of findIslandImports(code, filePath)) {
134
117
  const spec = islandImport.specifier;
135
118
  const strategy = islandImport.hydrate;
136
119
  const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
@@ -191,10 +174,10 @@ function islandsPlugin(pagesDir, options) {
191
174
  handler(code, id) {
192
175
  if (/import\s+\{[^}]*\buseForm\b/.test(code)) this.warn(`islands: useForm cannot be imported in island page '${id}'. Use useIslandForm instead.`);
193
176
  const importerDir = dirname(id);
194
- let transformed = code;
177
+ const edits = [];
195
178
  const wrappers = [];
196
179
  let idx = 0;
197
- for (const islandImport of findIslandImports(code)) {
180
+ for (const islandImport of findIslandImports(code, id)) {
198
181
  const name = islandImport.importName;
199
182
  const specRaw = islandImport.specifierRaw;
200
183
  const strategy = islandImport.hydrate;
@@ -211,20 +194,26 @@ function islandsPlugin(pagesDir, options) {
211
194
  }
212
195
  const islandId = absPath ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") : spec;
213
196
  const replacement = `import ${rawName} from ${specRaw}`;
214
- transformed = transformed.replace(islandImport.statement, replacement);
197
+ edits.push({
198
+ start: islandImport.start,
199
+ end: islandImport.end,
200
+ text: replacement
201
+ });
215
202
  wrappers.push(`const ${name} = { inheritAttrs: false, render() { const props = this.$attrs; return _h_island("div", { "data-island": ${JSON.stringify(islandId)}, "data-props": JSON.stringify(props), "data-hydrate": ${JSON.stringify(strategy)} }, _h_island(${rawName}, props)); } };`);
216
203
  }
217
204
  if (wrappers.length > 0) {
218
- const setupMatch = transformed.match(/<script\b[^>]*\bsetup\b[^>]*>/);
219
- if (setupMatch) {
220
- const openEnd = setupMatch.index + setupMatch[0].length;
221
- const closeIdx = transformed.indexOf("<\/script>", openEnd);
222
- if (closeIdx !== -1) transformed = transformed.slice(0, openEnd) + "\nimport { h as _h_island } from \"vue\";" + transformed.slice(openEnd, closeIdx) + "\n" + wrappers.join("\n") + "\n" + transformed.slice(closeIdx);
223
- }
224
- return {
225
- code: transformed,
226
- map: null
227
- };
205
+ const setupMatch = code.match(/<script\b[^>]*\bsetup\b[^>]*>/);
206
+ if (!setupMatch) throw new Error(`islands: Expected a <script setup> block in '${id}'.`);
207
+ const openEnd = setupMatch.index + setupMatch[0].length;
208
+ const closeIdx = code.indexOf("<\/script>", openEnd);
209
+ if (closeIdx === -1) throw new Error(`islands: Expected a closing <\/script> tag in '${id}'.`);
210
+ return editIslandSource(code, edits, { insert: [{
211
+ offset: openEnd,
212
+ text: "\nimport { h as _h_island } from \"vue\";"
213
+ }, {
214
+ offset: closeIdx,
215
+ text: "\n" + wrappers.join("\n") + "\n"
216
+ }] });
228
217
  }
229
218
  }
230
219
  },
@@ -306,7 +295,6 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
306
295
  lines.push("import { initIslands } from \"void/pages-client\";");
307
296
  if (!isDev) {
308
297
  const styleRe = /<style\b([^>]*)>/g;
309
- const cssImportRe = /^\s*import\b[^"']*["']([^"']+\.(?:css|scss|sass|less|styl|stylus|pcss|postcss))["']/gm;
310
298
  for (const file of cssFiles) {
311
299
  const content = readFileSync(file, "utf-8");
312
300
  styleRe.lastIndex = 0;
@@ -322,8 +310,7 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
322
310
  lines.push(`import ${JSON.stringify(file + query)};`);
323
311
  index++;
324
312
  }
325
- cssImportRe.lastIndex = 0;
326
- while ((match = cssImportRe.exec(content)) !== null) lines.push(rewriteCssImportForVirtualModule(match[0], match[1], file));
313
+ for (const item of findStaticCssImports(content, file)) lines.push(rewriteCssImportForVirtualModule(item.statement, item.specifier, file));
327
314
  }
328
315
  }
329
316
  lines.push("const islands = {");
@@ -593,7 +580,7 @@ const { router, initialPageData, initialComponent, initialLayouts, start } =
593
580
  isLoading: (ref) => ref.loading,
594
581
  applyUpdate(pageData, comp, layouts, options) {
595
582
  if (!options?.preserveState) currentPageKey.value++;
596
- Object.assign(shared, pageData.shared || {});
583
+ replaceRecord(shared, pageData.shared || {});
597
584
  replaceRecord(errors, pageData.errors || {});
598
585
  replaceRecord(params, pageData.params || {});
599
586
  currentProps.value = pageData.props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/vue",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voidzero-dev/void.git",
@@ -35,12 +35,12 @@
35
35
  "pathslash": "^0.1.0",
36
36
  "vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
37
37
  "vite-plus": "0.3.1",
38
- "void": "0.21.1",
38
+ "void": "0.21.3",
39
39
  "vue": "^3.5.42"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vite": "^8.0.0",
43
- "void": "0.21.1",
43
+ "void": "0.21.3",
44
44
  "vue": "^3.5.0"
45
45
  },
46
46
  "scripts": {