@void/react 0.7.12 → 0.7.13

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/plugin.d.mts CHANGED
@@ -11,6 +11,6 @@ type VoidReactOptions = Readonly<{
11
11
  viewTransitions?: boolean;
12
12
  prefetch?: PrefetchConfig;
13
13
  }>;
14
- declare function voidReact(options?: VoidReactOptions): ReadonlyArray<Plugin>;
14
+ declare function voidReact(options?: VoidReactOptions): Array<Plugin>;
15
15
  //#endregion
16
16
  export { VoidReactOptions, voidReact };
package/dist/plugin.mjs CHANGED
@@ -141,6 +141,23 @@ const COMPONENT_EXTENSIONS = [
141
141
  ".ts",
142
142
  ".js"
143
143
  ];
144
+ const ISLAND_IMPORT_RE = /import\s+([$_A-Za-z][$_\w]*)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*,?\s*\}/g;
145
+ function findIslandImports(code) {
146
+ const imports = [];
147
+ let match;
148
+ ISLAND_IMPORT_RE.lastIndex = 0;
149
+ while ((match = ISLAND_IMPORT_RE.exec(code)) !== null) {
150
+ const specifierRaw = match[2];
151
+ imports.push({
152
+ statement: match[0],
153
+ importName: match[1],
154
+ specifierRaw,
155
+ specifier: specifierRaw.slice(1, -1),
156
+ hydrate: match[3].slice(1, -1)
157
+ });
158
+ }
159
+ return imports;
160
+ }
144
161
  function islandsPlugin(pagesDir) {
145
162
  let pageScan = null;
146
163
  let isDev = false;
@@ -168,7 +185,6 @@ function islandsPlugin(pagesDir) {
168
185
  async buildStart() {
169
186
  if (existsSync(pagesDir)) {
170
187
  pageScan = await scanPages(root);
171
- const importAttrRe = /import\s+\w+\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*\}/g;
172
188
  const filesToScan = [
173
189
  ...pageScan.pages.map((page) => ({
174
190
  filePath: page.componentPath,
@@ -188,11 +204,9 @@ function islandsPlugin(pagesDir) {
188
204
  const filePath = resolve(pagesDir, entry.filePath);
189
205
  const code = readFileSync(filePath, "utf-8");
190
206
  const importerDir = dirname(filePath);
191
- importAttrRe.lastIndex = 0;
192
- let importMatch;
193
- while ((importMatch = importAttrRe.exec(code)) !== null) {
194
- const spec = importMatch[1].slice(1, -1);
195
- const strategy = importMatch[2].slice(1, -1);
207
+ for (const islandImport of findIslandImports(code)) {
208
+ const spec = islandImport.specifier;
209
+ const strategy = islandImport.hydrate;
196
210
  const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
197
211
  if (absPath) {
198
212
  const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "");
@@ -250,18 +264,15 @@ function islandsPlugin(pagesDir) {
250
264
  filter: { id: /\.island\.(tsx|jsx)$/ },
251
265
  handler(code, id) {
252
266
  if (/import\s+\{[^}]*\buseForm\b/.test(code)) this.warn(`islands: useForm cannot be imported in island page '${id}'. Use useIslandForm instead.`);
253
- const importAttrRe = /import\s+(\w+)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*\}/g;
254
267
  const importerDir = dirname(id);
255
268
  let transformed = code;
256
269
  const wrappers = [];
257
270
  let idx = 0;
258
- let match;
259
- while ((match = importAttrRe.exec(code)) !== null) {
260
- const name = match[1];
261
- const specRaw = match[2];
262
- const strategyRaw = match[3];
263
- const spec = specRaw.slice(1, -1);
264
- const strategy = strategyRaw.slice(1, -1);
271
+ for (const islandImport of findIslandImports(code)) {
272
+ const name = islandImport.importName;
273
+ const specRaw = islandImport.specifierRaw;
274
+ const strategy = islandImport.hydrate;
275
+ const spec = islandImport.specifier;
265
276
  const rawName = `_raw_island_${idx++}`;
266
277
  const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
267
278
  if (absPath) {
@@ -274,7 +285,7 @@ function islandsPlugin(pagesDir) {
274
285
  }
275
286
  const islandId = absPath ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") : spec;
276
287
  const replacement = `import ${rawName} from ${specRaw}`;
277
- transformed = transformed.replace(match[0], replacement);
288
+ transformed = transformed.replace(islandImport.statement, replacement);
278
289
  wrappers.push(`var ${name} = function ${name}(props) { return _React_island.createElement("div", { "data-island": ${JSON.stringify(islandId)}, "data-props": JSON.stringify(props), "data-hydrate": ${JSON.stringify(strategy)} }, _React_island.createElement(${rawName}, props)); };`);
279
290
  }
280
291
  if (wrappers.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/react",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voidzero-dev/void.git",
@@ -51,13 +51,13 @@
51
51
  "react-dom": "^19.2.6",
52
52
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
53
53
  "vite-plus": "^0.1.20",
54
- "void": "0.7.12"
54
+ "void": "0.7.13"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "react": "^19.0.0",
58
58
  "react-dom": "^19.0.0",
59
59
  "vite": "^8.0.0",
60
- "void": "0.7.12"
60
+ "void": "0.7.13"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "vp pack",