Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish-jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ Thumbs.db

# Testing
coverage
.wrangler
.wrangler
playground/dist-no-plugin
playground/node_modules
playground/package-lock.json
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions playground/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@jsr:registry=https://npm.jsr.io
85 changes: 44 additions & 41 deletions playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -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 +=
`<br><br><span style="color: #4ade80">✓ Verified CID: ${
cidMatch[0]
}</span>`;
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 +=
`<br><br><span style="color: #4ade80">✓ Verified CID: ${
cidMatch[0]
}</span>`;
}
}
}
}

// 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();
13 changes: 13 additions & 0 deletions playground/vite.config.no-plugin.ts
Original file line number Diff line number Diff line change
@@ -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,
},
});
1 change: 1 addition & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
14 changes: 2 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
}
},

Expand Down
Loading