From 57e409b77593babd9285338d329c1d07c870f041 Mon Sep 17 00:00:00 2001 From: "Dilip Kr. Shukla" Date: Mon, 1 Dec 2025 23:57:36 +0100 Subject: [PATCH 1/5] feat: add playground environment and prevent CID renaming of manifest files. --- .gitignore | 5 +- playground/.npmrc | 1 + playground/package.json | 10 ++++ playground/src/main.ts | 84 +++++++++++++++-------------- playground/vite.config.no-plugin.ts | 13 +++++ src/edge-cases.test.ts | 8 +-- src/index.test.ts | 3 +- src/index.ts | 14 +---- src/mpa.test.ts | 2 +- 9 files changed, 80 insertions(+), 60 deletions(-) create mode 100644 playground/.npmrc create mode 100644 playground/package.json create mode 100644 playground/vite.config.no-plugin.ts diff --git a/.gitignore b/.gitignore index 85915e8..1bcb938 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ Thumbs.db # Testing coverage -.wrangler \ No newline at end of file +.wrangler +playground/dist-no-plugin +playground/node_modules +playground/package-lock.json diff --git a/playground/.npmrc b/playground/.npmrc new file mode 100644 index 0000000..41583e3 --- /dev/null +++ b/playground/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/playground/package.json b/playground/package.json new file mode 100644 index 0000000..fa1ccf3 --- /dev/null +++ b/playground/package.json @@ -0,0 +1,10 @@ +{ + "name": "vite-plugin-cid-playground", + "version": "0.0.0", + "type": "module", + "private": true, + "dependencies": { + "@std/path": "npm:@jsr/std__path@^1.1.3", + "multiformats": "^13.4.1" + } +} diff --git a/playground/src/main.ts b/playground/src/main.ts index 5eb6f4b..87fec16 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,45 +1,47 @@ import "./style.css"; -import { vendorName } from "./vendor"; - -console.log("Using vendor:", vendorName); - -// Display the current script's source (which contains the CID) -const script = document.querySelector('script[type="module"]'); -const display = document.querySelector("#cid-display"); - -if (script && display) { - const src = script.getAttribute("src"); - if (src) { - display.textContent = `Current Script: ${src}`; - - // Extract CID if present (simple regex check) - const cidMatch = src.match(/bafkrei[a-z0-9]+/); - if (cidMatch) { - display.innerHTML += - `

✓ Verified CID: ${ - cidMatch[0] - }`; +async function main() { + const { vendorName } = await import("./vendor"); + + console.log("Using vendor:", vendorName); + + // Display the current script's source (which contains the CID) + const script = document.querySelector('script[type="module"]'); + const display = document.querySelector("#cid-display"); + + if (script && display) { + const src = script.getAttribute("src"); + if (src) { + display.textContent = `Current Script: ${src}`; + + // Extract CID if present (simple regex check) + const cidMatch = src.match(/bafkrei[a-z0-9]+/); + if (cidMatch) { + display.innerHTML += + `

✓ Verified CID: ${cidMatch[0] + }`; + } } } -} -// Add a button to test dynamic import (which should generate a chunk) -const btn = document.createElement("button"); -btn.textContent = "Load Dynamic Chunk"; -btn.style.marginTop = "1rem"; -btn.style.padding = "0.5rem 1rem"; -btn.style.background = "#3B82F6"; -btn.style.color = "white"; -btn.style.border = "none"; -btn.style.borderRadius = "0.5rem"; -btn.style.cursor = "pointer"; - -btn.addEventListener("click", async () => { - const module = await import("./dynamic"); - console.log(module.msg); - alert(module.msg); -}); - -document.querySelector(".demo-section")?.appendChild(btn); - -console.log("CID Vite Plugin Playground Loaded"); + // Add a button to test dynamic import (which should generate a chunk) + const btn = document.createElement("button"); + btn.textContent = "Load Dynamic Chunk"; + btn.style.marginTop = "1rem"; + btn.style.padding = "0.5rem 1rem"; + btn.style.background = "#3B82F6"; + btn.style.color = "white"; + btn.style.border = "none"; + btn.style.borderRadius = "0.5rem"; + btn.style.cursor = "pointer"; + + btn.addEventListener("click", async () => { + const module = await import("./dynamic"); + console.log(module.msg); + alert(module.msg); + }); + + document.querySelector(".demo-section")?.appendChild(btn); + + console.log("CID Vite Plugin Playground Loaded"); +} +main(); diff --git a/playground/vite.config.no-plugin.ts b/playground/vite.config.no-plugin.ts new file mode 100644 index 0000000..d8c74f9 --- /dev/null +++ b/playground/vite.config.no-plugin.ts @@ -0,0 +1,13 @@ +import { defineConfig } from "vite"; + +export default defineConfig({ + root: __dirname, + plugins: [], + build: { + outDir: "dist-no-plugin", + emptyOutDir: true, + manifest: true, + ssrManifest: true, + modulePreload: true, + }, +}); diff --git a/src/edge-cases.test.ts b/src/edge-cases.test.ts index 2eec3b6..baee00c 100644 --- a/src/edge-cases.test.ts +++ b/src/edge-cases.test.ts @@ -79,7 +79,7 @@ Deno.test({ assertMatch(basename, /^bafkrei/); } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); @@ -156,7 +156,7 @@ Deno.test({ assertMatch(cssContent, /url\([^)]*bafkrei[^)]*\)/); } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); @@ -202,7 +202,7 @@ Deno.test({ } assert(files.length > 0); } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); @@ -276,7 +276,7 @@ Deno.test({ } } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); diff --git a/src/index.test.ts b/src/index.test.ts index 7b33f1f..c888b06 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -74,6 +74,7 @@ Deno.test({ files.push(name); } + // Find CSS and JS files by extension const cssFile = files.find((f) => f.endsWith(".css")); const jsFile = files.find((f) => f.endsWith(".js")); @@ -118,7 +119,7 @@ Deno.test({ } } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); diff --git a/src/index.ts b/src/index.ts index 3c3b8de..6587027 100644 --- a/src/index.ts +++ b/src/index.ts @@ -248,18 +248,8 @@ export function cid(): Plugin { } item.source = content; - - const cid = await generateCID(content); - const ext = path.extname(fileName); - const dir = path.dirname(fileName); - const newFileName = path.join(dir, `${cid}${ext}`); - - if (newFileName !== fileName) { - item.fileName = newFileName; - delete bundle[fileName]; - bundle[newFileName] = item; - fileMap.set(fileName, newFileName); - } + // Note: We do NOT rename manifest files themselves + // They should keep their original names (.vite/manifest.json, etc.) } }, diff --git a/src/mpa.test.ts b/src/mpa.test.ts index 2d78ca9..f7c4c86 100644 --- a/src/mpa.test.ts +++ b/src/mpa.test.ts @@ -102,7 +102,7 @@ Deno.test({ const jsBasename = path.basename(jsFiles[0]); assertMatch(jsBasename, /^bafkrei/); } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => {}); + await Deno.remove(tempDir, { recursive: true }).catch(() => { }); } }, }); From ad1731657dfc5cfdaec589dc6877a4b55707d3ee Mon Sep 17 00:00:00 2001 From: "Dilip Kr. Shukla" Date: Tue, 2 Dec 2025 00:11:35 +0100 Subject: [PATCH 2/5] refactor: remove playground package.json and apply minor formatting adjustments to playground configuration and display logic. --- playground/package.json | 10 ---------- playground/src/main.ts | 3 ++- playground/vite.config.no-plugin.ts | 18 +++++++++--------- 3 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 playground/package.json diff --git a/playground/package.json b/playground/package.json deleted file mode 100644 index fa1ccf3..0000000 --- a/playground/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "vite-plugin-cid-playground", - "version": "0.0.0", - "type": "module", - "private": true, - "dependencies": { - "@std/path": "npm:@jsr/std__path@^1.1.3", - "multiformats": "^13.4.1" - } -} diff --git a/playground/src/main.ts b/playground/src/main.ts index 87fec16..394903a 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -17,7 +17,8 @@ async function main() { const cidMatch = src.match(/bafkrei[a-z0-9]+/); if (cidMatch) { display.innerHTML += - `

✓ Verified CID: ${cidMatch[0] + `

✓ Verified CID: ${ + cidMatch[0] }`; } } diff --git a/playground/vite.config.no-plugin.ts b/playground/vite.config.no-plugin.ts index d8c74f9..7978a5e 100644 --- a/playground/vite.config.no-plugin.ts +++ b/playground/vite.config.no-plugin.ts @@ -1,13 +1,13 @@ import { defineConfig } from "vite"; export default defineConfig({ - root: __dirname, - plugins: [], - build: { - outDir: "dist-no-plugin", - emptyOutDir: true, - manifest: true, - ssrManifest: true, - modulePreload: true, - }, + root: __dirname, + plugins: [], + build: { + outDir: "dist-no-plugin", + emptyOutDir: true, + manifest: true, + ssrManifest: true, + modulePreload: true, + }, }); From 77a98759ffbe9147a79865d0ee9839d562a9dc55 Mon Sep 17 00:00:00 2001 From: "Dilip Kr. Shukla" Date: Tue, 2 Dec 2025 00:18:11 +0100 Subject: [PATCH 3/5] style: format test cleanup catch blocks and workflow script. --- .github/workflows/publish-jsr.yml | 4 ++-- src/edge-cases.test.ts | 8 ++++---- src/index.test.ts | 2 +- src/mpa.test.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-jsr.yml b/.github/workflows/publish-jsr.yml index ce6f035..94b0689 100644 --- a/.github/workflows/publish-jsr.yml +++ b/.github/workflows/publish-jsr.yml @@ -41,10 +41,10 @@ jobs: run: | FILE_VERSION=$(deno eval 'console.log(JSON.parse(Deno.readTextFileSync("deno.json")).version)') TAG_VERSION=${TAG_NAME#v} - + echo "File version: $FILE_VERSION" echo "Tag version: $TAG_VERSION" - + if [ "$FILE_VERSION" != "$TAG_VERSION" ]; then echo "::error::Version mismatch! deno.json has $FILE_VERSION but tag is $TAG_VERSION" exit 1 diff --git a/src/edge-cases.test.ts b/src/edge-cases.test.ts index baee00c..2eec3b6 100644 --- a/src/edge-cases.test.ts +++ b/src/edge-cases.test.ts @@ -79,7 +79,7 @@ Deno.test({ assertMatch(basename, /^bafkrei/); } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); @@ -156,7 +156,7 @@ Deno.test({ assertMatch(cssContent, /url\([^)]*bafkrei[^)]*\)/); } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); @@ -202,7 +202,7 @@ Deno.test({ } assert(files.length > 0); } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); @@ -276,7 +276,7 @@ Deno.test({ } } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); diff --git a/src/index.test.ts b/src/index.test.ts index c888b06..9975a46 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -119,7 +119,7 @@ Deno.test({ } } } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); diff --git a/src/mpa.test.ts b/src/mpa.test.ts index f7c4c86..2d78ca9 100644 --- a/src/mpa.test.ts +++ b/src/mpa.test.ts @@ -102,7 +102,7 @@ Deno.test({ const jsBasename = path.basename(jsFiles[0]); assertMatch(jsBasename, /^bafkrei/); } finally { - await Deno.remove(tempDir, { recursive: true }).catch(() => { }); + await Deno.remove(tempDir, { recursive: true }).catch(() => {}); } }, }); From 0c5f5ec2dab6ff16041f967dca5e3b5436ce2b98 Mon Sep 17 00:00:00 2001 From: "Dilip Kr. Shukla" Date: Tue, 2 Dec 2025 00:24:20 +0100 Subject: [PATCH 4/5] chore: bump version to 0.1.2 --- deno.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deno.json b/deno.json index 467a325..8e6e33d 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@fusionstrings/vite-plugin-cid", - "version": "0.1.1", + "version": "0.1.2", "exports": { ".": "./src/index.ts", "./cid": "./src/cid.ts" @@ -10,8 +10,8 @@ "dev": "cd playground && deno run --watch -A npm:vite@7.2.4 build --watch", "build": "cd playground && deno run -A npm:vite@7.2.4 build", "test": "deno test --allow-read --allow-write --allow-env --allow-ffi --allow-run --allow-sys", - "check": "deno check src/**/*.ts", - "lint": "deno lint src/", + "check": "deno check", + "lint": "deno lint", "fmt": "deno fmt", "fmt:check": "deno fmt --check", "docs": "deno doc --html --name='CID Vite Plugin' --output=./docs ./src/index.ts ./src/cid.ts" @@ -40,4 +40,4 @@ "fmt": { "useTabs": true } -} +} \ No newline at end of file From b9fd5361716d614b692ea9efe9fa5ca3891602ef Mon Sep 17 00:00:00 2001 From: "Dilip Kr. Shukla" Date: Tue, 2 Dec 2025 00:27:50 +0100 Subject: [PATCH 5/5] No changes were made to deno.json. --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 8e6e33d..f99c537 100644 --- a/deno.json +++ b/deno.json @@ -40,4 +40,4 @@ "fmt": { "useTabs": true } -} \ No newline at end of file +}