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/.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/deno.json b/deno.json index 467a325..f99c537 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" 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/src/main.ts b/playground/src/main.ts index 5eb6f4b..394903a 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,45 +1,48 @@ 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..7978a5e --- /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/index.test.ts b/src/index.test.ts index 7b33f1f..9975a46 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")); 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.) } },