Skip to content

Commit 99155f8

Browse files
feat: only hash assets (#1)
* feat: add playground environment and prevent CID renaming of manifest files. * refactor: remove playground package.json and apply minor formatting adjustments to playground configuration and display logic. * style: format test cleanup catch blocks and workflow script. * chore: bump version to 0.1.2 * No changes were made to deno.json.
1 parent 0147dd6 commit 99155f8

8 files changed

Lines changed: 70 additions & 59 deletions

File tree

.github/workflows/publish-jsr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141
run: |
4242
FILE_VERSION=$(deno eval 'console.log(JSON.parse(Deno.readTextFileSync("deno.json")).version)')
4343
TAG_VERSION=${TAG_NAME#v}
44-
44+
4545
echo "File version: $FILE_VERSION"
4646
echo "Tag version: $TAG_VERSION"
47-
47+
4848
if [ "$FILE_VERSION" != "$TAG_VERSION" ]; then
4949
echo "::error::Version mismatch! deno.json has $FILE_VERSION but tag is $TAG_VERSION"
5050
exit 1

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ Thumbs.db
1616

1717
# Testing
1818
coverage
19-
.wrangler
19+
.wrangler
20+
playground/dist-no-plugin
21+
playground/node_modules
22+
playground/package-lock.json

deno.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fusionstrings/vite-plugin-cid",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"exports": {
55
".": "./src/index.ts",
66
"./cid": "./src/cid.ts"
@@ -10,8 +10,8 @@
1010
"dev": "cd playground && deno run --watch -A npm:vite@7.2.4 build --watch",
1111
"build": "cd playground && deno run -A npm:vite@7.2.4 build",
1212
"test": "deno test --allow-read --allow-write --allow-env --allow-ffi --allow-run --allow-sys",
13-
"check": "deno check src/**/*.ts",
14-
"lint": "deno lint src/",
13+
"check": "deno check",
14+
"lint": "deno lint",
1515
"fmt": "deno fmt",
1616
"fmt:check": "deno fmt --check",
1717
"docs": "deno doc --html --name='CID Vite Plugin' --output=./docs ./src/index.ts ./src/cid.ts"

playground/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@jsr:registry=https://npm.jsr.io

playground/src/main.ts

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
import "./style.css";
2-
import { vendorName } from "./vendor";
3-
4-
console.log("Using vendor:", vendorName);
5-
6-
// Display the current script's source (which contains the CID)
7-
const script = document.querySelector('script[type="module"]');
8-
const display = document.querySelector("#cid-display");
9-
10-
if (script && display) {
11-
const src = script.getAttribute("src");
12-
if (src) {
13-
display.textContent = `Current Script: ${src}`;
14-
15-
// Extract CID if present (simple regex check)
16-
const cidMatch = src.match(/bafkrei[a-z0-9]+/);
17-
if (cidMatch) {
18-
display.innerHTML +=
19-
`<br><br><span style="color: #4ade80">✓ Verified CID: ${
20-
cidMatch[0]
21-
}</span>`;
2+
async function main() {
3+
const { vendorName } = await import("./vendor");
4+
5+
console.log("Using vendor:", vendorName);
6+
7+
// Display the current script's source (which contains the CID)
8+
const script = document.querySelector('script[type="module"]');
9+
const display = document.querySelector("#cid-display");
10+
11+
if (script && display) {
12+
const src = script.getAttribute("src");
13+
if (src) {
14+
display.textContent = `Current Script: ${src}`;
15+
16+
// Extract CID if present (simple regex check)
17+
const cidMatch = src.match(/bafkrei[a-z0-9]+/);
18+
if (cidMatch) {
19+
display.innerHTML +=
20+
`<br><br><span style="color: #4ade80">✓ Verified CID: ${
21+
cidMatch[0]
22+
}</span>`;
23+
}
2224
}
2325
}
24-
}
2526

26-
// Add a button to test dynamic import (which should generate a chunk)
27-
const btn = document.createElement("button");
28-
btn.textContent = "Load Dynamic Chunk";
29-
btn.style.marginTop = "1rem";
30-
btn.style.padding = "0.5rem 1rem";
31-
btn.style.background = "#3B82F6";
32-
btn.style.color = "white";
33-
btn.style.border = "none";
34-
btn.style.borderRadius = "0.5rem";
35-
btn.style.cursor = "pointer";
36-
37-
btn.addEventListener("click", async () => {
38-
const module = await import("./dynamic");
39-
console.log(module.msg);
40-
alert(module.msg);
41-
});
42-
43-
document.querySelector(".demo-section")?.appendChild(btn);
44-
45-
console.log("CID Vite Plugin Playground Loaded");
27+
// Add a button to test dynamic import (which should generate a chunk)
28+
const btn = document.createElement("button");
29+
btn.textContent = "Load Dynamic Chunk";
30+
btn.style.marginTop = "1rem";
31+
btn.style.padding = "0.5rem 1rem";
32+
btn.style.background = "#3B82F6";
33+
btn.style.color = "white";
34+
btn.style.border = "none";
35+
btn.style.borderRadius = "0.5rem";
36+
btn.style.cursor = "pointer";
37+
38+
btn.addEventListener("click", async () => {
39+
const module = await import("./dynamic");
40+
console.log(module.msg);
41+
alert(module.msg);
42+
});
43+
44+
document.querySelector(".demo-section")?.appendChild(btn);
45+
46+
console.log("CID Vite Plugin Playground Loaded");
47+
}
48+
main();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from "vite";
2+
3+
export default defineConfig({
4+
root: __dirname,
5+
plugins: [],
6+
build: {
7+
outDir: "dist-no-plugin",
8+
emptyOutDir: true,
9+
manifest: true,
10+
ssrManifest: true,
11+
modulePreload: true,
12+
},
13+
});

src/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Deno.test({
7474
files.push(name);
7575
}
7676

77+
// Find CSS and JS files by extension
7778
const cssFile = files.find((f) => f.endsWith(".css"));
7879
const jsFile = files.find((f) => f.endsWith(".js"));
7980

src/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,8 @@ export function cid(): Plugin {
248248
}
249249

250250
item.source = content;
251-
252-
const cid = await generateCID(content);
253-
const ext = path.extname(fileName);
254-
const dir = path.dirname(fileName);
255-
const newFileName = path.join(dir, `${cid}${ext}`);
256-
257-
if (newFileName !== fileName) {
258-
item.fileName = newFileName;
259-
delete bundle[fileName];
260-
bundle[newFileName] = item;
261-
fileMap.set(fileName, newFileName);
262-
}
251+
// Note: We do NOT rename manifest files themselves
252+
// They should keep their original names (.vite/manifest.json, etc.)
263253
}
264254
},
265255

0 commit comments

Comments
 (0)