@ilha/astro 0.1.4 → 0.1.6
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/README.md +10 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +36 -3
- package/dist/server.js +6 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -24,6 +24,16 @@ export default defineConfig({
|
|
|
24
24
|
});
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
When you use multiple JSX frameworks, restrict each integration to its own files:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
integrations: [ilha({ include: ["**/ilha/**"] })],
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
You can also pass `exclude` globs. Files outside the filter remain available to other Astro JSX renderers.
|
|
36
|
+
|
|
27
37
|
Then use any Ilha island as an Astro component, with a [client directive](https://docs.astro.build/en/reference/directives-reference/#client-directives) to control hydration:
|
|
28
38
|
|
|
29
39
|
```astro
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { AstroIntegration, AstroRenderer } from "astro";
|
|
2
|
+
export interface IlhaIntegrationOptions {
|
|
3
|
+
include?: string | string[];
|
|
4
|
+
exclude?: string | string[];
|
|
5
|
+
}
|
|
2
6
|
export declare function getRenderer(): AstroRenderer;
|
|
3
7
|
/**
|
|
4
8
|
* Vite's dependency optimizer otherwise inlines peer `ilha` into prebundled
|
|
@@ -7,7 +11,12 @@ export declare function getRenderer(): AstroRenderer;
|
|
|
7
11
|
*
|
|
8
12
|
* `resolve.dedupe` + `optimizeDeps.exclude` keep a single module instance.
|
|
9
13
|
*/
|
|
10
|
-
export declare function getViteConfig(): {
|
|
14
|
+
export declare function getViteConfig(options?: IlhaIntegrationOptions): {
|
|
15
|
+
plugins: {
|
|
16
|
+
name: string;
|
|
17
|
+
resolveId(id: string): "\0virtual:@ilha/astro/options" | undefined;
|
|
18
|
+
load(id: string): string | undefined;
|
|
19
|
+
}[];
|
|
11
20
|
resolve: {
|
|
12
21
|
dedupe: string[];
|
|
13
22
|
};
|
|
@@ -15,4 +24,4 @@ export declare function getViteConfig(): {
|
|
|
15
24
|
exclude: string[];
|
|
16
25
|
};
|
|
17
26
|
};
|
|
18
|
-
export default function ilhaIntegration(): AstroIntegration;
|
|
27
|
+
export default function ilhaIntegration(options?: IlhaIntegrationOptions): AstroIntegration;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
|
+
const OPTIONS_MODULE = "virtual:@ilha/astro/options";
|
|
3
|
+
function globToRegExp(pattern) {
|
|
4
|
+
let source = "^";
|
|
5
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
6
|
+
const char = pattern[i];
|
|
7
|
+
if (char === "*") if (pattern[i + 1] === "*") {
|
|
8
|
+
i++;
|
|
9
|
+
if (pattern[i + 1] === "/") {
|
|
10
|
+
i++;
|
|
11
|
+
source += "(?:.*/)?";
|
|
12
|
+
} else source += ".*";
|
|
13
|
+
} else source += "[^/]*";
|
|
14
|
+
else if (char === "?") source += "[^/]";
|
|
15
|
+
else source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
16
|
+
}
|
|
17
|
+
return new RegExp(`${source}$`);
|
|
18
|
+
}
|
|
19
|
+
function patternList(patterns) {
|
|
20
|
+
return (typeof patterns === "string" ? [patterns] : patterns ?? []).map(globToRegExp).join(",");
|
|
21
|
+
}
|
|
22
|
+
function optionsPlugin(options) {
|
|
23
|
+
return {
|
|
24
|
+
name: "@ilha/astro:options",
|
|
25
|
+
resolveId(id) {
|
|
26
|
+
return id === OPTIONS_MODULE ? `\0${OPTIONS_MODULE}` : void 0;
|
|
27
|
+
},
|
|
28
|
+
load(id) {
|
|
29
|
+
if (id !== `\0${OPTIONS_MODULE}`) return;
|
|
30
|
+
return `const include=[${patternList(options.include)}],exclude=[${patternList(options.exclude)}];export default id=>(!include.length||include.some(pattern=>pattern.test(id)))&&!exclude.some(pattern=>pattern.test(id));`;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
2
34
|
function getRenderer() {
|
|
3
35
|
return {
|
|
4
36
|
name: "@ilha/astro",
|
|
@@ -13,18 +45,19 @@ function getRenderer() {
|
|
|
13
45
|
*
|
|
14
46
|
* `resolve.dedupe` + `optimizeDeps.exclude` keep a single module instance.
|
|
15
47
|
*/
|
|
16
|
-
function getViteConfig() {
|
|
48
|
+
function getViteConfig(options = {}) {
|
|
17
49
|
return {
|
|
50
|
+
plugins: [optionsPlugin(options)],
|
|
18
51
|
resolve: { dedupe: ["ilha"] },
|
|
19
52
|
optimizeDeps: { exclude: ["ilha"] }
|
|
20
53
|
};
|
|
21
54
|
}
|
|
22
|
-
function ilhaIntegration() {
|
|
55
|
+
function ilhaIntegration(options = {}) {
|
|
23
56
|
return {
|
|
24
57
|
name: "@ilha/astro",
|
|
25
58
|
hooks: { "astro:config:setup": ({ addRenderer, updateConfig }) => {
|
|
26
59
|
addRenderer(getRenderer());
|
|
27
|
-
updateConfig({ vite: getViteConfig() });
|
|
60
|
+
updateConfig({ vite: getViteConfig(options) });
|
|
28
61
|
} }
|
|
29
62
|
};
|
|
30
63
|
}
|
package/dist/server.js
CHANGED
|
@@ -3,6 +3,10 @@ import ilha, { raw } from "ilha";
|
|
|
3
3
|
//#region src/server.ts
|
|
4
4
|
const ISLAND = Symbol.for("ilha.island");
|
|
5
5
|
const RAW = Symbol.for("ilha.raw");
|
|
6
|
+
let componentFilter;
|
|
7
|
+
function getComponentFilter() {
|
|
8
|
+
return componentFilter ??= import("virtual:@ilha/astro/options").then(({ default: filter }) => filter).catch(() => () => true);
|
|
9
|
+
}
|
|
6
10
|
function isIsland(Component) {
|
|
7
11
|
return typeof Component === "function" && ISLAND in Component;
|
|
8
12
|
}
|
|
@@ -73,7 +77,8 @@ async function renderPlainComponent(Component, props, slots, metadata) {
|
|
|
73
77
|
skipOnMount: true
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
|
-
async function check(Component, props, slots) {
|
|
80
|
+
async function check(Component, props, slots, metadata) {
|
|
81
|
+
if (metadata?.componentUrl && !(await getComponentFilter())(metadata.componentUrl)) return false;
|
|
77
82
|
if (isIsland(Component)) return true;
|
|
78
83
|
if (typeof Component !== "function") return false;
|
|
79
84
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilha/astro",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Astro integration for Ilha islands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-component",
|
|
@@ -48,14 +48,15 @@
|
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsdown && tsc -p tsconfig.build.json",
|
|
51
|
+
"cleanup": "rimraf dist node_modules",
|
|
51
52
|
"test": "bun test"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"astro": "^7.
|
|
55
|
-
"ilha": "^0.10.
|
|
55
|
+
"astro": "^7.2.0",
|
|
56
|
+
"ilha": "^0.10.2"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"astro": "^7.
|
|
59
|
-
"ilha": ">=0.10.
|
|
59
|
+
"astro": "^7.2.0",
|
|
60
|
+
"ilha": ">=0.10.2"
|
|
60
61
|
}
|
|
61
62
|
}
|