@browse-sent-event/plugin-vite 0.1.0-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @browse-sent-event/plugin-vite
2
+
3
+ Vite 개발 서버 entry에 browse-sent-event runtime bootstrap을 주입하는 플러그인입니다.
4
+
5
+ ## 설치
6
+
7
+ ```bash
8
+ pnpm add -D @browse-sent-event/plugin-vite
9
+ ```
10
+
11
+ ## 사용
12
+
13
+ ```ts
14
+ import { defineConfig } from "vite";
15
+ import browseSentEvent from "@browse-sent-event/plugin-vite";
16
+
17
+ export default defineConfig({
18
+ plugins: [browseSentEvent()],
19
+ });
20
+ ```
21
+
22
+ ## 문서
23
+
24
+ 공개 기술 문서는 <https://songforthemute.github.io/browse-sent-event/>에서 확인합니다.
@@ -0,0 +1,10 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/index.d.ts
4
+ interface BrowseSentEventVitePluginOptions {
5
+ readonly enabled?: boolean;
6
+ }
7
+ declare function browseSentEvent(options?: BrowseSentEventVitePluginOptions): Plugin;
8
+ //#endregion
9
+ export { BrowseSentEventVitePluginOptions, browseSentEvent as default };
10
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAUiB,gCAAA;EAAA,SACN,OAAA;AAAA;AAAA,iBAGa,eAAA,CAAgB,OAAA,GAAS,gCAAA,GAAwC,MAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,74 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { normalizePath } from "vite";
4
+ //#region src/injection.ts
5
+ const bootstrapModuleId = "virtual:browse-sent-event/bootstrap";
6
+ const resolvedBootstrapModuleId = `\0${bootstrapModuleId}`;
7
+ const moduleScriptPattern = /<script\b(?=[^>]*\btype=["']module["'])(?=[^>]*\bsrc=["']([^"']+)["'])[^>]*><\/script>/gi;
8
+ function collectHtmlModuleEntries(html) {
9
+ const entries = /* @__PURE__ */ new Set();
10
+ for (const match of html.matchAll(moduleScriptPattern)) {
11
+ const src = match[1];
12
+ if (src) entries.add(src);
13
+ }
14
+ return [...entries];
15
+ }
16
+ function createBootstrapImport() {
17
+ return `import "${bootstrapModuleId}";`;
18
+ }
19
+ function createBootstrapModuleCode() {
20
+ return [`import { installBrowseSentEvent } from "@browse-sent-event/core";`, `installBrowseSentEvent();`].join("\n");
21
+ }
22
+ function normalizeRealPath(path) {
23
+ try {
24
+ return normalizePath(realpathSync(path));
25
+ } catch {
26
+ return normalizePath(path);
27
+ }
28
+ }
29
+ function isEntryModuleId(id, entries, root) {
30
+ const cleanId = normalizePath(id.split("?")[0] ?? id);
31
+ const realCleanId = normalizeRealPath(cleanId);
32
+ for (const entry of entries) {
33
+ const resolvedEntry = normalizePath(resolve(root, (entry.split("?")[0] ?? entry).replace(/^\//, "")));
34
+ const realResolvedEntry = normalizeRealPath(resolvedEntry);
35
+ if (cleanId === resolvedEntry || cleanId === realResolvedEntry || realCleanId === resolvedEntry) return true;
36
+ }
37
+ return false;
38
+ }
39
+ //#endregion
40
+ //#region src/index.ts
41
+ function browseSentEvent(options = {}) {
42
+ const enabled = options.enabled ?? true;
43
+ const htmlEntries = /* @__PURE__ */ new Set();
44
+ let config;
45
+ return {
46
+ name: "browse-sent-event:vite",
47
+ enforce: "pre",
48
+ apply: "serve",
49
+ configResolved(resolvedConfig) {
50
+ config = resolvedConfig;
51
+ },
52
+ transformIndexHtml(html) {
53
+ if (!enabled) return;
54
+ for (const entry of collectHtmlModuleEntries(html)) htmlEntries.add(entry);
55
+ },
56
+ resolveId(id) {
57
+ if (id === "virtual:browse-sent-event/bootstrap") return resolvedBootstrapModuleId;
58
+ },
59
+ load(id) {
60
+ if (id === resolvedBootstrapModuleId) return createBootstrapModuleCode();
61
+ },
62
+ transform(code, id) {
63
+ if (!enabled || !config || !isEntryModuleId(id, htmlEntries, config.root)) return;
64
+ return {
65
+ code: `${createBootstrapImport()}\n${code}`,
66
+ map: null
67
+ };
68
+ }
69
+ };
70
+ }
71
+ //#endregion
72
+ export { browseSentEvent as default };
73
+
74
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/injection.ts","../src/index.ts"],"sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { normalizePath } from \"vite\";\n\nexport const bootstrapModuleId: string = \"virtual:browse-sent-event/bootstrap\";\nexport const resolvedBootstrapModuleId: string = `\\0${bootstrapModuleId}`;\n\nconst moduleScriptPattern =\n /<script\\b(?=[^>]*\\btype=[\"']module[\"'])(?=[^>]*\\bsrc=[\"']([^\"']+)[\"'])[^>]*><\\/script>/gi;\n\nexport function collectHtmlModuleEntries(html: string): string[] {\n const entries = new Set<string>();\n\n for (const match of html.matchAll(moduleScriptPattern)) {\n const src = match[1];\n\n if (src) {\n entries.add(src);\n }\n }\n\n return [...entries];\n}\n\nexport function createBootstrapImport(): string {\n return `import \"${bootstrapModuleId}\";`;\n}\n\nexport function createBootstrapModuleCode(): string {\n return [\n `import { installBrowseSentEvent } from \"@browse-sent-event/core\";`,\n `installBrowseSentEvent();`,\n ].join(\"\\n\");\n}\n\nfunction normalizeRealPath(path: string): string {\n try {\n return normalizePath(realpathSync(path));\n } catch {\n return normalizePath(path);\n }\n}\n\nexport function isEntryModuleId(id: string, entries: Iterable<string>, root: string): boolean {\n const cleanId = normalizePath(id.split(\"?\")[0] ?? id);\n const realCleanId = normalizeRealPath(cleanId);\n\n for (const entry of entries) {\n const cleanEntry = entry.split(\"?\")[0] ?? entry;\n const resolvedEntry = normalizePath(resolve(root, cleanEntry.replace(/^\\//, \"\")));\n const realResolvedEntry = normalizeRealPath(resolvedEntry);\n\n if (\n cleanId === resolvedEntry ||\n cleanId === realResolvedEntry ||\n realCleanId === resolvedEntry\n ) {\n return true;\n }\n }\n\n return false;\n}\n","import type { Plugin, ResolvedConfig, Rolldown } from \"vite\";\nimport {\n bootstrapModuleId,\n collectHtmlModuleEntries,\n createBootstrapImport,\n createBootstrapModuleCode,\n isEntryModuleId,\n resolvedBootstrapModuleId,\n} from \"./injection.js\";\n\nexport interface BrowseSentEventVitePluginOptions {\n readonly enabled?: boolean;\n}\n\nexport default function browseSentEvent(options: BrowseSentEventVitePluginOptions = {}): Plugin {\n const enabled = options.enabled ?? true;\n const htmlEntries = new Set<string>();\n let config: ResolvedConfig | undefined;\n\n return {\n name: \"browse-sent-event:vite\",\n enforce: \"pre\",\n apply: \"serve\",\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n transformIndexHtml(html) {\n if (!enabled) {\n return;\n }\n\n for (const entry of collectHtmlModuleEntries(html)) {\n htmlEntries.add(entry);\n }\n },\n resolveId(id) {\n if (id === bootstrapModuleId) {\n return resolvedBootstrapModuleId;\n }\n\n return undefined;\n },\n load(id) {\n if (id === resolvedBootstrapModuleId) {\n return createBootstrapModuleCode();\n }\n\n return undefined;\n },\n transform(code, id): Rolldown.TransformResult {\n if (!enabled || !config || !isEntryModuleId(id, htmlEntries, config.root)) {\n return undefined;\n }\n\n return {\n code: `${createBootstrapImport()}\\n${code}`,\n map: null,\n };\n },\n };\n}\n"],"mappings":";;;;AAIA,MAAa,oBAA4B;AACzC,MAAa,4BAAoC,KAAK;AAEtD,MAAM,sBACJ;AAEF,SAAgB,yBAAyB,MAAwB;CAC/D,MAAM,0BAAU,IAAI,IAAY;CAEhC,KAAK,MAAM,SAAS,KAAK,SAAS,mBAAmB,GAAG;EACtD,MAAM,MAAM,MAAM;EAElB,IAAI,KACF,QAAQ,IAAI,GAAG;CAEnB;CAEA,OAAO,CAAC,GAAG,OAAO;AACpB;AAEA,SAAgB,wBAAgC;CAC9C,OAAO,WAAW,kBAAkB;AACtC;AAEA,SAAgB,4BAAoC;CAClD,OAAO,CACL,qEACA,2BACF,EAAE,KAAK,IAAI;AACb;AAEA,SAAS,kBAAkB,MAAsB;CAC/C,IAAI;EACF,OAAO,cAAc,aAAa,IAAI,CAAC;CACzC,QAAQ;EACN,OAAO,cAAc,IAAI;CAC3B;AACF;AAEA,SAAgB,gBAAgB,IAAY,SAA2B,MAAuB;CAC5F,MAAM,UAAU,cAAc,GAAG,MAAM,GAAG,EAAE,MAAM,EAAE;CACpD,MAAM,cAAc,kBAAkB,OAAO;CAE7C,KAAK,MAAM,SAAS,SAAS;EAE3B,MAAM,gBAAgB,cAAc,QAAQ,OADzB,MAAM,MAAM,GAAG,EAAE,MAAM,OACmB,QAAQ,OAAO,EAAE,CAAC,CAAC;EAChF,MAAM,oBAAoB,kBAAkB,aAAa;EAEzD,IACE,YAAY,iBACZ,YAAY,qBACZ,gBAAgB,eAEhB,OAAO;CAEX;CAEA,OAAO;AACT;;;AChDA,SAAwB,gBAAgB,UAA4C,CAAC,GAAW;CAC9F,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,8BAAc,IAAI,IAAY;CACpC,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO;EACP,eAAe,gBAAgB;GAC7B,SAAS;EACX;EACA,mBAAmB,MAAM;GACvB,IAAI,CAAC,SACH;GAGF,KAAK,MAAM,SAAS,yBAAyB,IAAI,GAC/C,YAAY,IAAI,KAAK;EAEzB;EACA,UAAU,IAAI;GACZ,IAAI,OAAA,uCACF,OAAO;EAIX;EACA,KAAK,IAAI;GACP,IAAI,OAAO,2BACT,OAAO,0BAA0B;EAIrC;EACA,UAAU,MAAM,IAA8B;GAC5C,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,gBAAgB,IAAI,aAAa,OAAO,IAAI,GACtE;GAGF,OAAO;IACL,MAAM,GAAG,sBAAsB,EAAE,IAAI;IACrC,KAAK;GACP;EACF;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@browse-sent-event/plugin-vite",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Vite plugin for injecting browse-sent-event into browser development entries.",
5
+ "keywords": [
6
+ "devtools",
7
+ "eventsource",
8
+ "fetch",
9
+ "realtime",
10
+ "vite",
11
+ "vite-plugin",
12
+ "websocket",
13
+ "xhr"
14
+ ],
15
+ "homepage": "https://songforthemute.github.io/browse-sent-event/",
16
+ "bugs": {
17
+ "url": "https://github.com/songforthemute/browse-sent-event/issues"
18
+ },
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/songforthemute/browse-sent-event.git",
23
+ "directory": "packages/plugin-vite"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "type": "module",
31
+ "sideEffects": false,
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.mts",
35
+ "import": "./dist/index.mjs"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "build": "tsdown",
43
+ "test": "vitest run",
44
+ "typecheck": "tsc --noEmit"
45
+ },
46
+ "dependencies": {
47
+ "@browse-sent-event/core": "workspace:*"
48
+ },
49
+ "devDependencies": {
50
+ "vite": "^8.0.16"
51
+ },
52
+ "peerDependencies": {
53
+ "vite": ">=5.0.0 <9.0.0"
54
+ }
55
+ }