vite-plugin-sinwan 0.2.2 → 0.2.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.
- package/__tests__/plugin.test.ts +12 -0
- package/bun.lock +26 -27
- package/dist/compiler/hmr.d.ts +3 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +9 -60
- package/package.json +2 -3
- package/src/compiler/hmr.ts +5 -87
- package/src/index.ts +10 -2
package/__tests__/plugin.test.ts
CHANGED
|
@@ -15,4 +15,16 @@ describe("sinwan vite plugin", () => {
|
|
|
15
15
|
});
|
|
16
16
|
expect(plugin.name).toBe("sinwan");
|
|
17
17
|
});
|
|
18
|
+
|
|
19
|
+
it("enables explicit bindings and the incremental analyzer by default", () => {
|
|
20
|
+
const plugin = sinwan();
|
|
21
|
+
expect(plugin.name).toBe("sinwan");
|
|
22
|
+
expect(typeof plugin.configResolved).toBe("function");
|
|
23
|
+
expect(typeof plugin.transform).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("allows disabling the cache and explicit bindings", () => {
|
|
27
|
+
const plugin = sinwan({ cache: false, explicitBindings: false });
|
|
28
|
+
expect(plugin.name).toBe("sinwan");
|
|
29
|
+
});
|
|
18
30
|
});
|
package/bun.lock
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "vite-plugin-sinwan",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"
|
|
9
|
-
"sinwan-compiler": "^0.2.2",
|
|
8
|
+
"sinwan-compiler": "^0.2.3",
|
|
10
9
|
},
|
|
11
10
|
"devDependencies": {
|
|
12
11
|
"@types/bun": "latest",
|
|
@@ -19,37 +18,37 @@
|
|
|
19
18
|
},
|
|
20
19
|
},
|
|
21
20
|
"packages": {
|
|
22
|
-
"@babel/code-frame": ["@babel/code-frame@7.29.
|
|
21
|
+
"@babel/code-frame": ["@babel/code-frame@7.29.7", "", { "dependencies": { "@babel/helper-validator-identifier": "^7.29.7", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" } }, "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw=="],
|
|
23
22
|
|
|
24
|
-
"@babel/compat-data": ["@babel/compat-data@7.29.
|
|
23
|
+
"@babel/compat-data": ["@babel/compat-data@7.29.7", "", {}, "sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg=="],
|
|
25
24
|
|
|
26
|
-
"@babel/core": ["@babel/core@7.29.
|
|
25
|
+
"@babel/core": ["@babel/core@7.29.7", "", { "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.7", "@babel/helper-compilation-targets": "^7.29.7", "@babel/helper-module-transforms": "^7.29.7", "@babel/helpers": "^7.29.7", "@babel/parser": "^7.29.7", "@babel/template": "^7.29.7", "@babel/traverse": "^7.29.7", "@babel/types": "^7.29.7", "@jridgewell/remapping": "^2.3.5", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", "json5": "^2.2.3", "semver": "^6.3.1" } }, "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA=="],
|
|
27
26
|
|
|
28
|
-
"@babel/generator": ["@babel/generator@7.29.
|
|
27
|
+
"@babel/generator": ["@babel/generator@7.29.8", "", { "dependencies": { "@babel/parser": "^7.29.8", "@babel/types": "^7.29.8", "@jridgewell/gen-mapping": "^0.3.12", "@jridgewell/trace-mapping": "^0.3.28", "jsesc": "^3.0.2" } }, "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg=="],
|
|
29
28
|
|
|
30
|
-
"@babel/helper-compilation-targets": ["@babel/helper-compilation-targets@7.
|
|
29
|
+
"@babel/helper-compilation-targets": ["@babel/helper-compilation-targets@7.29.7", "", { "dependencies": { "@babel/compat-data": "^7.29.7", "@babel/helper-validator-option": "^7.29.7", "browserslist": "^4.24.0", "lru-cache": "^5.1.1", "semver": "^6.3.1" } }, "sha512-wem6WaBj4NaVYVdNhLPPVacES6ZJ+KBBfSkTMD3YZxbP3rm3Di85tJU5ljaUNhaOynt+Aj0xruhYuzQBt8n71g=="],
|
|
31
30
|
|
|
32
|
-
"@babel/helper-globals": ["@babel/helper-globals@7.
|
|
31
|
+
"@babel/helper-globals": ["@babel/helper-globals@7.29.7", "", {}, "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA=="],
|
|
33
32
|
|
|
34
|
-
"@babel/helper-module-imports": ["@babel/helper-module-imports@7.
|
|
33
|
+
"@babel/helper-module-imports": ["@babel/helper-module-imports@7.29.7", "", { "dependencies": { "@babel/traverse": "^7.29.7", "@babel/types": "^7.29.7" } }, "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g=="],
|
|
35
34
|
|
|
36
|
-
"@babel/helper-module-transforms": ["@babel/helper-module-transforms@7.
|
|
35
|
+
"@babel/helper-module-transforms": ["@babel/helper-module-transforms@7.29.7", "", { "dependencies": { "@babel/helper-module-imports": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7", "@babel/traverse": "^7.29.7" }, "peerDependencies": { "@babel/core": "^7.0.0" } }, "sha512-UPUVSyXbOh627KiCIGQSgwWzGeBKLkaJ9PJEdrngIwMSzxLR4jS4+f1f1jb7VzBbg8nFLaYotvVPFCTqdrmTAg=="],
|
|
37
36
|
|
|
38
|
-
"@babel/helper-string-parser": ["@babel/helper-string-parser@7.
|
|
37
|
+
"@babel/helper-string-parser": ["@babel/helper-string-parser@7.29.7", "", {}, "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw=="],
|
|
39
38
|
|
|
40
|
-
"@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.
|
|
39
|
+
"@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="],
|
|
41
40
|
|
|
42
|
-
"@babel/helper-validator-option": ["@babel/helper-validator-option@7.
|
|
41
|
+
"@babel/helper-validator-option": ["@babel/helper-validator-option@7.29.7", "", {}, "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw=="],
|
|
43
42
|
|
|
44
|
-
"@babel/helpers": ["@babel/helpers@7.29.
|
|
43
|
+
"@babel/helpers": ["@babel/helpers@7.29.7", "", { "dependencies": { "@babel/template": "^7.29.7", "@babel/types": "^7.29.7" } }, "sha512-1k2lAGRMfHTcwuNYcCNUmaUffmQv8KWMfh2iJUUeRlwlwH4FdNG7mfPI10NPfLHJFThE4Tyr4mv7kTNZOiPuBg=="],
|
|
45
44
|
|
|
46
|
-
"@babel/parser": ["@babel/parser@7.29.
|
|
45
|
+
"@babel/parser": ["@babel/parser@7.29.8", "", { "dependencies": { "@babel/types": "^7.29.8" }, "bin": "./bin/babel-parser.js" }, "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA=="],
|
|
47
46
|
|
|
48
|
-
"@babel/template": ["@babel/template@7.
|
|
47
|
+
"@babel/template": ["@babel/template@7.29.7", "", { "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/parser": "^7.29.7", "@babel/types": "^7.29.7" } }, "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg=="],
|
|
49
48
|
|
|
50
|
-
"@babel/traverse": ["@babel/traverse@7.29.
|
|
49
|
+
"@babel/traverse": ["@babel/traverse@7.29.8", "", { "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.8", "@babel/helper-globals": "^7.29.7", "@babel/parser": "^7.29.8", "@babel/template": "^7.29.7", "@babel/types": "^7.29.8", "debug": "^4.3.1" } }, "sha512-I5z7H3bf/41ktsNVLtpN0wAa336HkqIHQ5BuPLEhTkt1jVSyZpeNKIzTgEWmlxjdg81R0IgUCcaE+Ok3NvrfZg=="],
|
|
51
50
|
|
|
52
|
-
"@babel/types": ["@babel/types@7.29.
|
|
51
|
+
"@babel/types": ["@babel/types@7.29.8", "", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg=="],
|
|
53
52
|
|
|
54
53
|
"@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.21.5", "", { "os": "aix", "cpu": "ppc64" }, "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ=="],
|
|
55
54
|
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
|
|
104
103
|
"@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="],
|
|
105
104
|
|
|
106
|
-
"@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.
|
|
105
|
+
"@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="],
|
|
107
106
|
|
|
108
107
|
"@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
|
|
109
108
|
|
|
@@ -163,19 +162,19 @@
|
|
|
163
162
|
|
|
164
163
|
"@types/node": ["@types/node@25.6.2", "", { "dependencies": { "undici-types": "~7.19.0" } }, "sha512-sokuT28dxf9JT5Kady1fsXOvI4HVpjZa95NKT5y9PNTIrs2AsobR4GFAA90ZG8M+nxVRLysCXsVj6eGC7Vbrlw=="],
|
|
165
164
|
|
|
166
|
-
"baseline-browser-mapping": ["baseline-browser-mapping@2.
|
|
165
|
+
"baseline-browser-mapping": ["baseline-browser-mapping@2.11.20", "", { "bin": { "baseline-browser-mapping": "dist/cli.cjs" } }, "sha512-H0ulySigv6icDJ1F7SjtdCD6PrhTpdYCmP0CactWy1+ekh0AFd0o1Wn5T8b+hnTmdBx19u9yhL6wvCylXMY7zw=="],
|
|
167
166
|
|
|
168
|
-
"browserslist": ["browserslist@4.28.
|
|
167
|
+
"browserslist": ["browserslist@4.28.8", "", { "dependencies": { "baseline-browser-mapping": "^2.11.12", "caniuse-lite": "^1.0.30001809", "electron-to-chromium": "^1.5.402", "node-releases": "^2.0.53", "update-browserslist-db": "^1.3.0" }, "bin": { "browserslist": "cli.js" } }, "sha512-V2NpofLblG64mfOtSgDhOJESZEGogzDMBv/q+W6oc4LXWP/q75eOXoOaaOu1EOadB9U4Bwx/e0yzbvwKH8zalA=="],
|
|
169
168
|
|
|
170
169
|
"bun-types": ["bun-types@1.3.13", "", { "dependencies": { "@types/node": "*" } }, "sha512-QXKeHLlOLqQX9LgYaHJfzdBaV21T63HhFJnvuRCcjZiaUDpbs5ED1MgxbMra71CsryN/1dAoXuJJJwIv/2drVA=="],
|
|
171
170
|
|
|
172
|
-
"caniuse-lite": ["caniuse-lite@1.0.
|
|
171
|
+
"caniuse-lite": ["caniuse-lite@1.0.30001810", "", {}, "sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg=="],
|
|
173
172
|
|
|
174
173
|
"convert-source-map": ["convert-source-map@2.0.0", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="],
|
|
175
174
|
|
|
176
|
-
"debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
|
|
175
|
+
"debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" }, "peerDependencies": { "supports-color": "*" }, "optionalPeers": ["supports-color"] }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
|
|
177
176
|
|
|
178
|
-
"electron-to-chromium": ["electron-to-chromium@1.5.
|
|
177
|
+
"electron-to-chromium": ["electron-to-chromium@1.5.416", "", {}, "sha512-K6bvB2BjnNrugtIih6ewlbBI9DXa976jIdiIlRLHhBoEI9a4JaQjjHyF+A1IQI543aQYR4LnmOrT/K5fZj0aPA=="],
|
|
179
178
|
|
|
180
179
|
"esbuild": ["esbuild@0.21.5", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.21.5", "@esbuild/android-arm": "0.21.5", "@esbuild/android-arm64": "0.21.5", "@esbuild/android-x64": "0.21.5", "@esbuild/darwin-arm64": "0.21.5", "@esbuild/darwin-x64": "0.21.5", "@esbuild/freebsd-arm64": "0.21.5", "@esbuild/freebsd-x64": "0.21.5", "@esbuild/linux-arm": "0.21.5", "@esbuild/linux-arm64": "0.21.5", "@esbuild/linux-ia32": "0.21.5", "@esbuild/linux-loong64": "0.21.5", "@esbuild/linux-mips64el": "0.21.5", "@esbuild/linux-ppc64": "0.21.5", "@esbuild/linux-riscv64": "0.21.5", "@esbuild/linux-s390x": "0.21.5", "@esbuild/linux-x64": "0.21.5", "@esbuild/netbsd-x64": "0.21.5", "@esbuild/openbsd-x64": "0.21.5", "@esbuild/sunos-x64": "0.21.5", "@esbuild/win32-arm64": "0.21.5", "@esbuild/win32-ia32": "0.21.5", "@esbuild/win32-x64": "0.21.5" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw=="],
|
|
181
180
|
|
|
@@ -197,7 +196,7 @@
|
|
|
197
196
|
|
|
198
197
|
"nanoid": ["nanoid@3.3.12", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-ZB9RH/39qpq5Vu6Y+NmUaFhQR6pp+M2Xt76XBnEwDaGcVAqhlvxrl3B2bKS5D3NH3QR76v3aSrKaF/Kiy7lEtQ=="],
|
|
199
198
|
|
|
200
|
-
"node-releases": ["node-releases@2.0.
|
|
199
|
+
"node-releases": ["node-releases@2.0.54", "", {}, "sha512-YHs7BmmcsdAI5Ozuf8JZo6PT0mv2GIWC9vMfvUC3dp65M8hn7Ux8CPL+2oBI7juNuj9d0ndhTcznq2ODBps9cQ=="],
|
|
201
200
|
|
|
202
201
|
"picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="],
|
|
203
202
|
|
|
@@ -207,7 +206,7 @@
|
|
|
207
206
|
|
|
208
207
|
"semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
|
209
208
|
|
|
210
|
-
"sinwan-compiler": ["sinwan-compiler@0.2.
|
|
209
|
+
"sinwan-compiler": ["sinwan-compiler@0.2.3", "", { "dependencies": { "@babel/core": "^7.24.0", "@babel/generator": "^7.24.0", "@babel/parser": "^7.24.0", "@babel/traverse": "^7.24.0", "@babel/types": "^7.24.0" }, "peerDependencies": { "typescript": "^5" }, "bin": { "sinwan": "dist/cli.js" } }, "sha512-Lt8CSorN5Xue1WKxnrZoweT87oBZMIeVb7KVURKMu3cEVttJnyvmcDo3j2BxZvjm7Lju1HnzxqaPqZUjCwle1w=="],
|
|
211
210
|
|
|
212
211
|
"source-map-js": ["source-map-js@1.2.1", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],
|
|
213
212
|
|
|
@@ -215,7 +214,7 @@
|
|
|
215
214
|
|
|
216
215
|
"undici-types": ["undici-types@7.19.2", "", {}, "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg=="],
|
|
217
216
|
|
|
218
|
-
"update-browserslist-db": ["update-browserslist-db@1.2
|
|
217
|
+
"update-browserslist-db": ["update-browserslist-db@1.3.2", "", { "dependencies": { "escalade": "^3.2.0", "picocolors": "^1.1.1" }, "peerDependencies": { "browserslist": ">= 4.21.0" }, "bin": { "update-browserslist-db": "cli.js" } }, "sha512-UQ+MSxlhRm1bzjhU+DcuXfjFO1FzNtqhK5+9Yvlp90ItDLk5vT932A0rFu619nf7RVS+Y/VeaUW1jaRDqZ8VJw=="],
|
|
219
218
|
|
|
220
219
|
"vite": ["vite@5.4.21", "", { "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", "rollup": "^4.20.0" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^18.0.0 || >=20.0.0", "less": "*", "lightningcss": "^1.21.0", "sass": "*", "sass-embedded": "*", "stylus": "*", "sugarss": "*", "terser": "^5.4.0" }, "optionalPeers": ["@types/node", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser"], "bin": { "vite": "bin/vite.js" } }, "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw=="],
|
|
221
220
|
|
package/dist/compiler/hmr.d.ts
CHANGED
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
* instead of falling back to the entry — and state is preserved by the
|
|
10
10
|
* runtime's resolve-to-latest mechanism.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* component, so over-matching is harmless.
|
|
12
|
+
* Component detection is delegated to `sinwan-compiler`'s shared
|
|
13
|
+
* `collectExportedComponents` utility so both Vite and Bun plugins use the
|
|
14
|
+
* same logic without duplicating Babel parsing.
|
|
16
15
|
*/
|
|
17
16
|
/**
|
|
18
17
|
* Append a Fast Refresh HMR footer to a component module's source.
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type SinwanCacheOptions = boolean | {
|
|
|
12
12
|
export interface SinwanOptions {
|
|
13
13
|
/** Enable template hoisting (default: true) */
|
|
14
14
|
hoist?: boolean;
|
|
15
|
-
/** Emit explicit compiler-driven binding descriptors (
|
|
15
|
+
/** Emit explicit compiler-driven binding descriptors (default: true). */
|
|
16
16
|
explicitBindings?: boolean;
|
|
17
17
|
/** Path to the reactive-props metadata file produced by `sinwan analyze`. */
|
|
18
18
|
analyze?: string;
|
|
@@ -20,6 +20,8 @@ export interface SinwanOptions {
|
|
|
20
20
|
* Enable incremental in-memory cross-file analysis for dev/HMR. When true,
|
|
21
21
|
* the plugin analyzes each transformed file and passes the current metadata
|
|
22
22
|
* to the transform without requiring a separate `sinwan analyze` step.
|
|
23
|
+
* Default: true (in-memory only; set to `false` to disable, or pass an object
|
|
24
|
+
* to configure root/paths and persistent cache).
|
|
23
25
|
*/
|
|
24
26
|
cache?: SinwanCacheOptions;
|
|
25
27
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3,61 +3,7 @@
|
|
|
3
3
|
import { transformJSX, AnalyzerCache } from "sinwan-compiler";
|
|
4
4
|
|
|
5
5
|
// src/compiler/hmr.ts
|
|
6
|
-
import {
|
|
7
|
-
function isComponentName(name) {
|
|
8
|
-
return !!name && name[0] === name[0].toUpperCase() && /^[A-Z]/.test(name);
|
|
9
|
-
}
|
|
10
|
-
function collectExportedComponents(code, filename) {
|
|
11
|
-
let ast;
|
|
12
|
-
try {
|
|
13
|
-
ast = parse(code, {
|
|
14
|
-
sourceType: "module",
|
|
15
|
-
plugins: ["jsx", "typescript"],
|
|
16
|
-
sourceFilename: filename
|
|
17
|
-
});
|
|
18
|
-
} catch {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
const found = [];
|
|
22
|
-
const seen = new Set;
|
|
23
|
-
const add = (local, key) => {
|
|
24
|
-
const sig = `${local}::${key}`;
|
|
25
|
-
if (seen.has(sig))
|
|
26
|
-
return;
|
|
27
|
-
seen.add(sig);
|
|
28
|
-
found.push({ local, key });
|
|
29
|
-
};
|
|
30
|
-
for (const node of ast.program.body) {
|
|
31
|
-
if (node.type === "ExportNamedDeclaration") {
|
|
32
|
-
if (node.declaration) {
|
|
33
|
-
const decl = node.declaration;
|
|
34
|
-
if (decl.type === "FunctionDeclaration" && decl.id && isComponentName(decl.id.name)) {
|
|
35
|
-
add(decl.id.name, decl.id.name);
|
|
36
|
-
} else if (decl.type === "VariableDeclaration") {
|
|
37
|
-
for (const d of decl.declarations) {
|
|
38
|
-
if (d.id?.type === "Identifier" && isComponentName(d.id.name)) {
|
|
39
|
-
add(d.id.name, d.id.name);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else if (node.specifiers && !node.source) {
|
|
44
|
-
for (const spec of node.specifiers) {
|
|
45
|
-
if (spec.type === "ExportSpecifier" && spec.local?.type === "Identifier" && spec.exported?.type === "Identifier" && isComponentName(spec.exported.name)) {
|
|
46
|
-
add(spec.local.name, spec.exported.name);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} else if (node.type === "ExportDefaultDeclaration") {
|
|
51
|
-
const decl = node.declaration;
|
|
52
|
-
if (decl.type === "Identifier") {
|
|
53
|
-
add(decl.name, "default");
|
|
54
|
-
} else if (decl.type === "FunctionDeclaration" && decl.id) {
|
|
55
|
-
add(decl.id.name, "default");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return found;
|
|
60
|
-
}
|
|
6
|
+
import { collectExportedComponents } from "sinwan-compiler";
|
|
61
7
|
function injectComponentHmr(code, filename) {
|
|
62
8
|
const components = collectExportedComponents(code, filename);
|
|
63
9
|
if (components.length === 0)
|
|
@@ -69,7 +15,7 @@ function injectComponentHmr(code, filename) {
|
|
|
69
15
|
`);
|
|
70
16
|
const footer = `
|
|
71
17
|
|
|
72
|
-
import { $$sinwanReplace as __$sinwanReplace, $$sinwanRefresh as __$sinwanRefresh } from "sinwan/react
|
|
18
|
+
import { $$sinwanReplace as __$sinwanReplace, $$sinwanRefresh as __$sinwanRefresh } from "sinwan/react";
|
|
73
19
|
if (import.meta.hot) {
|
|
74
20
|
import.meta.hot.accept((__m) => {
|
|
75
21
|
if (!__m) return;
|
|
@@ -88,7 +34,8 @@ var DEFAULT_SINWAN_OPTIONS = {
|
|
|
88
34
|
hoist: true,
|
|
89
35
|
explicitBindings: false,
|
|
90
36
|
fastRefresh: true,
|
|
91
|
-
analyze: undefined
|
|
37
|
+
analyze: undefined,
|
|
38
|
+
cache: true
|
|
92
39
|
};
|
|
93
40
|
function sinwan(options = {}) {
|
|
94
41
|
const opts = { ...DEFAULT_SINWAN_OPTIONS, ...options };
|
|
@@ -125,8 +72,10 @@ function sinwan(options = {}) {
|
|
|
125
72
|
result = transformJSX(code, id, {
|
|
126
73
|
hoist: opts.hoist,
|
|
127
74
|
explicitBindings: opts.explicitBindings,
|
|
75
|
+
dev: true,
|
|
128
76
|
analyze: opts.analyze,
|
|
129
|
-
analyzeMetadata: cache ? cache.reactiveProps : undefined
|
|
77
|
+
analyzeMetadata: cache ? cache.reactiveProps : undefined,
|
|
78
|
+
resolveImport: cache ? cache.resolve : undefined
|
|
130
79
|
});
|
|
131
80
|
}
|
|
132
81
|
const idPath = id.split("?")[0];
|
|
@@ -142,6 +91,6 @@ function sinwan(options = {}) {
|
|
|
142
91
|
};
|
|
143
92
|
}
|
|
144
93
|
export {
|
|
145
|
-
|
|
146
|
-
|
|
94
|
+
sinwan,
|
|
95
|
+
transformJSX
|
|
147
96
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-sinwan",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Vite plugin for sinwan",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"typescript": "^5"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"sinwan-compiler": "^0.2.2"
|
|
39
|
+
"sinwan-compiler": "^0.2.3"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"typescript": "^5",
|
package/src/compiler/hmr.ts
CHANGED
|
@@ -9,94 +9,12 @@
|
|
|
9
9
|
* instead of falling back to the entry — and state is preserved by the
|
|
10
10
|
* runtime's resolve-to-latest mechanism.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* component, so over-matching is harmless.
|
|
12
|
+
* Component detection is delegated to `sinwan-compiler`'s shared
|
|
13
|
+
* `collectExportedComponents` utility so both Vite and Bun plugins use the
|
|
14
|
+
* same logic without duplicating Babel parsing.
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
interface ExportedComponent {
|
|
21
|
-
/** Local binding name in the module (referenced in the accept callback). */
|
|
22
|
-
local: string;
|
|
23
|
-
/** Export key on the module namespace ("default" for the default export). */
|
|
24
|
-
key: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isComponentName(name: string | undefined): name is string {
|
|
28
|
-
return !!name && name[0] === name[0]!.toUpperCase() && /^[A-Z]/.test(name);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Collect top-level exported component bindings from a module.
|
|
33
|
-
*/
|
|
34
|
-
function collectExportedComponents(
|
|
35
|
-
code: string,
|
|
36
|
-
filename: string,
|
|
37
|
-
): ExportedComponent[] {
|
|
38
|
-
let ast: any;
|
|
39
|
-
try {
|
|
40
|
-
ast = parse(code, {
|
|
41
|
-
sourceType: "module",
|
|
42
|
-
plugins: ["jsx", "typescript"],
|
|
43
|
-
sourceFilename: filename,
|
|
44
|
-
});
|
|
45
|
-
} catch {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const found: ExportedComponent[] = [];
|
|
50
|
-
const seen = new Set<string>();
|
|
51
|
-
const add = (local: string, key: string) => {
|
|
52
|
-
const sig = `${local}::${key}`;
|
|
53
|
-
if (seen.has(sig)) return;
|
|
54
|
-
seen.add(sig);
|
|
55
|
-
found.push({ local, key });
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
for (const node of ast.program.body as any[]) {
|
|
59
|
-
if (node.type === "ExportNamedDeclaration") {
|
|
60
|
-
if (node.declaration) {
|
|
61
|
-
const decl = node.declaration;
|
|
62
|
-
if (
|
|
63
|
-
decl.type === "FunctionDeclaration" &&
|
|
64
|
-
decl.id &&
|
|
65
|
-
isComponentName(decl.id.name)
|
|
66
|
-
) {
|
|
67
|
-
add(decl.id.name, decl.id.name);
|
|
68
|
-
} else if (decl.type === "VariableDeclaration") {
|
|
69
|
-
for (const d of decl.declarations) {
|
|
70
|
-
if (d.id?.type === "Identifier" && isComponentName(d.id.name)) {
|
|
71
|
-
add(d.id.name, d.id.name);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} else if (node.specifiers && !node.source) {
|
|
76
|
-
// export { A, B as C }
|
|
77
|
-
for (const spec of node.specifiers) {
|
|
78
|
-
if (
|
|
79
|
-
spec.type === "ExportSpecifier" &&
|
|
80
|
-
spec.local?.type === "Identifier" &&
|
|
81
|
-
spec.exported?.type === "Identifier" &&
|
|
82
|
-
isComponentName(spec.exported.name)
|
|
83
|
-
) {
|
|
84
|
-
add(spec.local.name, spec.exported.name);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} else if (node.type === "ExportDefaultDeclaration") {
|
|
89
|
-
const decl = node.declaration;
|
|
90
|
-
if (decl.type === "Identifier") {
|
|
91
|
-
add(decl.name, "default");
|
|
92
|
-
} else if (decl.type === "FunctionDeclaration" && decl.id) {
|
|
93
|
-
add(decl.id.name, "default");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return found;
|
|
99
|
-
}
|
|
17
|
+
import { collectExportedComponents } from "sinwan-compiler";
|
|
100
18
|
|
|
101
19
|
/**
|
|
102
20
|
* Append a Fast Refresh HMR footer to a component module's source.
|
|
@@ -120,7 +38,7 @@ export function injectComponentHmr(
|
|
|
120
38
|
|
|
121
39
|
const footer = `
|
|
122
40
|
|
|
123
|
-
import { $$sinwanReplace as __$sinwanReplace, $$sinwanRefresh as __$sinwanRefresh } from "sinwan/react
|
|
41
|
+
import { $$sinwanReplace as __$sinwanReplace, $$sinwanRefresh as __$sinwanRefresh } from "sinwan/react";
|
|
124
42
|
if (import.meta.hot) {
|
|
125
43
|
import.meta.hot.accept((__m) => {
|
|
126
44
|
if (!__m) return;
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type SinwanCacheOptions =
|
|
|
19
19
|
export interface SinwanOptions {
|
|
20
20
|
/** Enable template hoisting (default: true) */
|
|
21
21
|
hoist?: boolean;
|
|
22
|
-
/** Emit explicit compiler-driven binding descriptors (
|
|
22
|
+
/** Emit explicit compiler-driven binding descriptors (default: true). */
|
|
23
23
|
explicitBindings?: boolean;
|
|
24
24
|
/** Path to the reactive-props metadata file produced by `sinwan analyze`. */
|
|
25
25
|
analyze?: string;
|
|
@@ -27,6 +27,8 @@ export interface SinwanOptions {
|
|
|
27
27
|
* Enable incremental in-memory cross-file analysis for dev/HMR. When true,
|
|
28
28
|
* the plugin analyzes each transformed file and passes the current metadata
|
|
29
29
|
* to the transform without requiring a separate `sinwan analyze` step.
|
|
30
|
+
* Default: true (in-memory only; set to `false` to disable, or pass an object
|
|
31
|
+
* to configure root/paths and persistent cache).
|
|
30
32
|
*/
|
|
31
33
|
cache?: SinwanCacheOptions;
|
|
32
34
|
/**
|
|
@@ -39,12 +41,16 @@ export interface SinwanOptions {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
const DEFAULT_SINWAN_OPTIONS: Required<
|
|
42
|
-
Pick<
|
|
44
|
+
Pick<
|
|
45
|
+
SinwanOptions,
|
|
46
|
+
"hoist" | "explicitBindings" | "fastRefresh" | "analyze" | "cache"
|
|
47
|
+
>
|
|
43
48
|
> = {
|
|
44
49
|
hoist: true,
|
|
45
50
|
explicitBindings: false,
|
|
46
51
|
fastRefresh: true,
|
|
47
52
|
analyze: undefined as any,
|
|
53
|
+
cache: true,
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
/**
|
|
@@ -111,8 +117,10 @@ export function sinwan(options: SinwanOptions = {}) {
|
|
|
111
117
|
result = transformJSX(code, id, {
|
|
112
118
|
hoist: opts.hoist,
|
|
113
119
|
explicitBindings: opts.explicitBindings,
|
|
120
|
+
dev: process.env.NODE_ENV !== "production",
|
|
114
121
|
analyze: opts.analyze,
|
|
115
122
|
analyzeMetadata: cache ? cache.reactiveProps : undefined,
|
|
123
|
+
resolveImport: cache ? cache.resolve : undefined,
|
|
116
124
|
});
|
|
117
125
|
}
|
|
118
126
|
|