@void/svelte 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 +1 -1
- package/dist/plugin.mjs +24 -15
- package/package.json +3 -3
package/dist/plugin.d.mts
CHANGED
|
@@ -11,6 +11,6 @@ type VoidSvelteOptions = Readonly<{
|
|
|
11
11
|
viewTransitions?: boolean;
|
|
12
12
|
prefetch?: PrefetchConfig;
|
|
13
13
|
}>;
|
|
14
|
-
declare function voidSvelte(options?: VoidSvelteOptions):
|
|
14
|
+
declare function voidSvelte(options?: VoidSvelteOptions): Array<Plugin>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { VoidSvelteOptions, voidSvelte };
|
package/dist/plugin.mjs
CHANGED
|
@@ -140,6 +140,22 @@ const COMPONENT_EXTENSIONS = [
|
|
|
140
140
|
".ts",
|
|
141
141
|
".js"
|
|
142
142
|
];
|
|
143
|
+
const ISLAND_IMPORT_RE = /import\s+([$_A-Za-z][$_\w]*)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*,?\s*\}/g;
|
|
144
|
+
function findIslandImports(code) {
|
|
145
|
+
const imports = [];
|
|
146
|
+
let match;
|
|
147
|
+
ISLAND_IMPORT_RE.lastIndex = 0;
|
|
148
|
+
while ((match = ISLAND_IMPORT_RE.exec(code)) !== null) {
|
|
149
|
+
const specifierRaw = match[2];
|
|
150
|
+
imports.push({
|
|
151
|
+
statement: match[0],
|
|
152
|
+
importName: match[1],
|
|
153
|
+
specifier: specifierRaw.slice(1, -1),
|
|
154
|
+
hydrate: match[3].slice(1, -1)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return imports;
|
|
158
|
+
}
|
|
143
159
|
/**
|
|
144
160
|
* Prefix for virtual island wrapper modules. Must NOT use the `\0` prefix
|
|
145
161
|
* because `@sveltejs/vite-plugin-svelte` skips `\0`-prefixed modules in
|
|
@@ -174,7 +190,6 @@ function islandsPlugin(pagesDir) {
|
|
|
174
190
|
async buildStart() {
|
|
175
191
|
if (existsSync(pagesDir)) {
|
|
176
192
|
pageScan = await scanPages(root);
|
|
177
|
-
const importAttrRe = /import\s+\w+\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*\}/g;
|
|
178
193
|
const filesToScan = [
|
|
179
194
|
...pageScan.pages.map((page) => ({
|
|
180
195
|
filePath: page.componentPath,
|
|
@@ -194,11 +209,9 @@ function islandsPlugin(pagesDir) {
|
|
|
194
209
|
const filePath = resolve(pagesDir, entry.filePath);
|
|
195
210
|
const code = readFileSync(filePath, "utf-8");
|
|
196
211
|
const importerDir = dirname(filePath);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const spec = importMatch[1].slice(1, -1);
|
|
201
|
-
const strategy = importMatch[2].slice(1, -1);
|
|
212
|
+
for (const islandImport of findIslandImports(code)) {
|
|
213
|
+
const spec = islandImport.specifier;
|
|
214
|
+
const strategy = islandImport.hydrate;
|
|
202
215
|
const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
|
|
203
216
|
if (absPath) {
|
|
204
217
|
const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "");
|
|
@@ -258,16 +271,12 @@ function islandsPlugin(pagesDir) {
|
|
|
258
271
|
filter: { id: /\.island\.svelte$/ },
|
|
259
272
|
handler(code, id) {
|
|
260
273
|
if (/import\s+\{[^}]*\buseForm\b/.test(code)) this.warn(`islands: useForm cannot be imported in island page '${id}'. Use useIslandForm instead.`);
|
|
261
|
-
const importAttrRe = /import\s+(\w+)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*\}/g;
|
|
262
274
|
const importerDir = dirname(id);
|
|
263
275
|
let transformed = code;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const strategyRaw = match[3];
|
|
269
|
-
const spec = specRaw.slice(1, -1);
|
|
270
|
-
const strategy = strategyRaw.slice(1, -1);
|
|
276
|
+
for (const islandImport of findIslandImports(code)) {
|
|
277
|
+
const name = islandImport.importName;
|
|
278
|
+
const spec = islandImport.specifier;
|
|
279
|
+
const strategy = islandImport.hydrate;
|
|
271
280
|
const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
|
|
272
281
|
if (absPath) {
|
|
273
282
|
const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "");
|
|
@@ -280,7 +289,7 @@ function islandsPlugin(pagesDir) {
|
|
|
280
289
|
const islandId = absPath ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") : spec;
|
|
281
290
|
const wrapperUrl = WRAPPER_PREFIX + encodeURIComponent(islandId) + ".svelte?src=" + encodeURIComponent(absPath || spec) + "&island=" + encodeURIComponent(islandId) + "&hydrate=" + encodeURIComponent(strategy);
|
|
282
291
|
const replacement = `import ${name} from ${JSON.stringify(wrapperUrl)}`;
|
|
283
|
-
transformed = transformed.replace(
|
|
292
|
+
transformed = transformed.replace(islandImport.statement, replacement);
|
|
284
293
|
}
|
|
285
294
|
if (transformed !== code) return {
|
|
286
295
|
code: transformed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/svelte",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"svelte": "^5.55.5",
|
|
45
45
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
|
|
46
46
|
"vite-plus": "^0.1.20",
|
|
47
|
-
"void": "0.7.
|
|
47
|
+
"void": "0.7.13"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"svelte": "^5.0.0",
|
|
51
51
|
"vite": "^8.0.0",
|
|
52
|
-
"void": "0.7.
|
|
52
|
+
"void": "0.7.13"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vp pack",
|