Skip to content

Commit b6ae9e0

Browse files
committed
Add README.md into plugin package
1 parent ff1b0d5 commit b6ae9e0

11 files changed

Lines changed: 981 additions & 7 deletions

File tree

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@
4141
"glob": "11.0.1",
4242
"jiti": "2.4.2",
4343
"jszip": "3.10.1",
44-
"ws": "8.18.0",
45-
"zod": "3.24.1",
44+
"remark": "^15.0.1",
45+
"remark-parse": "^11.0.0",
46+
"remark-stringify": "^11.0.0",
47+
"tsup": "8.3.5",
48+
"unified": "^11.0.5",
49+
"unist-util-visit": "^5.1.0",
4650
"vite": "6.0.7",
47-
"tsup": "8.3.5"
51+
"ws": "8.18.0",
52+
"zod": "3.24.1"
4853
},
4954
"devDependencies": {
5055
"@caido/eslint-config": "0.0.6",
5156
"@types/express": "5.0.0",
57+
"@types/mdast": "^4.0.4",
5258
"@types/node": "22.10.2",
5359
"@types/ws": "8.5.13",
5460
"eslint": "9.17.0",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Backend Plugin Playground
2+
3+
This is a test playground for building backend plugins.
4+
5+
![Test Asset](assets/test.txt)
6+
![External Image](https://example.com/image.png)
7+
8+
The plugin includes a backend plugin with assets.

playgrounds/build-backend/__tests__/build-backend.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@ describe("build-backend", () => {
8383

8484
expect(assetContent).toBeUndefined();
8585
});
86+
87+
it("should have README.md file", async () => {
88+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
89+
const readmeContent = await getZipFileContent(zipPath, "README.md");
90+
expect(readmeContent).toBeDefined();
91+
expect(readmeContent).toContain("Backend Plugin Playground");
92+
});
93+
94+
it("should transform README image links to GitHub raw URLs", async () => {
95+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
96+
const readmeContent = await getZipFileContent(zipPath, "README.md");
97+
expect(readmeContent).toBeDefined();
98+
// Verify that the image link was transformed to a GitHub raw URL
99+
expect(readmeContent).toMatch(
100+
/https:\/\/raw\.githubusercontent\.com\/.*\/assets\/test\.txt/,
101+
);
102+
});
103+
104+
it("should remove external image URLs (http, https, data)", async () => {
105+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
106+
const readmeContent = await getZipFileContent(zipPath, "README.md");
107+
expect(readmeContent).toBeDefined();
108+
// Verify that external URLs are removed (set to empty string)
109+
// The README has: ![External Image](https://example.com/image.png)
110+
// After transformation, it should be: ![](...)
111+
expect(readmeContent).toMatch(/!\[External Image\]\(\)/);
112+
});
86113
});

playgrounds/build-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"email": "hello@caido.com",
1010
"url": "https://caido.com"
1111
},
12+
"repository": "https://github.com/caido-community/dev",
1213
"license": "ISC"
1314
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Frontend Build Playground
2+
3+
This directory serves as a test fixture for validating frontend plugin build behavior in `@caido-community/dev`.
4+
5+
## Purpose
6+
7+
It demonstrates a minimal frontend Caido plugin configuration and is used in integration tests to verify:
8+
9+
- Vite-based frontend builds
10+
- Asset bundling
11+
- README and referenced asset inclusion in final plugin packages
12+
13+
## Test Asset Reference
14+
15+
The following image reference is used to test automatic asset detection from README content:
16+
17+
![Test Asset](assets/test.txt)
18+
19+
## Link Test Cases
20+
21+
Local link that should be transformed to a GitHub raw URL:
22+
23+
[Local Doc](assets/test.txt)
24+
25+
External link that should be removed:
26+
27+
[External Link](https://example.com/docs)
28+
29+
Fragment-only link that should be preserved:
30+
31+
[Jump to section](#purpose)
32+
33+
## Reference-Style Definition Test Cases
34+
35+
Reference-style image and link using definitions:
36+
37+
![Ref Image][ref-image]
38+
[Ref Link][ref-link]
39+
40+
[ref-image]: assets/test.txt
41+
[ref-link]: https://example.com/docs
42+
43+
## HTML Test Cases
44+
45+
Raw HTML with local and external URLs:
46+
47+
<img src="assets/test.txt" alt="HTML Local Image" />
48+
<img src="https://example.com/image.png" alt="HTML External Image" />
49+
<a href="assets/test.txt">HTML Local Link</a>
50+
<a href="https://example.com/docs">HTML External Link</a>
51+
52+
## External URL Test Cases
53+
54+
The following images test external URL handling (should be removed):
55+
56+
![External HTTP](http://example.com/image.png)
57+
![External HTTPS](https://example.com/image.png)
58+
![Data URI](data:image/png;base64,abc123)

playgrounds/build-frontend/__tests__/build-frontend.spec.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,100 @@ import { describe, expect, it } from "vitest";
55
import { getZipFileContent } from "../../../playgrounds/utils";
66

77
describe("build-frontend", () => {
8+
it("should have README.md file", async () => {
9+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
10+
const readmeContent = await getZipFileContent(zipPath, "README.md");
11+
expect(readmeContent).toBeDefined();
12+
expect(readmeContent).toContain("Frontend Build Playground");
13+
});
14+
15+
it("should transform README image links to GitHub raw URLs", async () => {
16+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
17+
const readmeContent = await getZipFileContent(zipPath, "README.md");
18+
expect(readmeContent).toBeDefined();
19+
expect(readmeContent).toContain("raw.githubusercontent.com");
20+
expect(readmeContent).toContain("assets/test.txt");
21+
});
22+
23+
it("should remove external image URLs", async () => {
24+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
25+
const readmeContent = await getZipFileContent(zipPath, "README.md");
26+
expect(readmeContent).toBeDefined();
27+
// External URLs should be removed (set to empty string)
28+
expect(readmeContent).not.toContain("http://example.com/image.png");
29+
expect(readmeContent).not.toContain("https://example.com/image.png");
30+
// data: URIs should be kept as-is (not removed)
31+
expect(readmeContent).toContain("data:image/png;base64,abc123");
32+
// Image syntax should still exist but with empty URLs (alt text preserved)
33+
expect(readmeContent).toContain("![External HTTP]()");
34+
expect(readmeContent).toContain("![External HTTPS]()");
35+
expect(readmeContent).toContain(
36+
"![Data URI](data:image/png;base64,abc123)",
37+
);
38+
});
39+
40+
it("should transform local markdown links to GitHub raw URLs", async () => {
41+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
42+
const readmeContent = await getZipFileContent(zipPath, "README.md");
43+
expect(readmeContent).toBeDefined();
44+
// [Local Doc](assets/test.txt) should become a GitHub raw URL
45+
expect(readmeContent).toMatch(
46+
/\[Local Doc\]\(https:\/\/raw\.githubusercontent\.com\/.*\/assets\/test\.txt\)/,
47+
);
48+
});
49+
50+
it("should remove external markdown link URLs", async () => {
51+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
52+
const readmeContent = await getZipFileContent(zipPath, "README.md");
53+
expect(readmeContent).toBeDefined();
54+
// External link URL should be removed but link text preserved
55+
expect(readmeContent).not.toContain("https://example.com/docs");
56+
expect(readmeContent).toContain("[External Link]()");
57+
});
58+
59+
it("should preserve fragment-only links", async () => {
60+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
61+
const readmeContent = await getZipFileContent(zipPath, "README.md");
62+
expect(readmeContent).toBeDefined();
63+
// Same-document anchors should be preserved as-is
64+
expect(readmeContent).toContain("[Jump to section](#purpose)");
65+
});
66+
67+
it("should transform reference-style definition URLs", async () => {
68+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
69+
const readmeContent = await getZipFileContent(zipPath, "README.md");
70+
expect(readmeContent).toBeDefined();
71+
// [ref-image]: assets/test.txt should be transformed to a GitHub raw URL
72+
expect(readmeContent).toMatch(
73+
/\[ref-image\]:\s*https:\/\/raw\.githubusercontent\.com\/.*\/assets\/test\.txt/,
74+
);
75+
// [ref-link]: https://example.com/docs is external and should be removed
76+
expect(readmeContent).not.toContain("https://example.com/docs");
77+
});
78+
79+
it("should transform local HTML src/href attributes", async () => {
80+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
81+
const readmeContent = await getZipFileContent(zipPath, "README.md");
82+
expect(readmeContent).toBeDefined();
83+
// HTML <img src="assets/test.txt"> and <a href="assets/test.txt"> should be transformed
84+
expect(readmeContent).toMatch(
85+
/src="https:\/\/raw\.githubusercontent\.com\/.*\/assets\/test\.txt"/,
86+
);
87+
expect(readmeContent).toMatch(
88+
/href="https:\/\/raw\.githubusercontent\.com\/.*\/assets\/test\.txt"/,
89+
);
90+
});
91+
92+
it("should remove external URLs in HTML attributes", async () => {
93+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
94+
const readmeContent = await getZipFileContent(zipPath, "README.md");
95+
expect(readmeContent).toBeDefined();
96+
// External URLs in HTML should be emptied
97+
expect(readmeContent).not.toContain("https://example.com/image.png");
98+
expect(readmeContent).not.toContain("https://example.com/docs");
99+
expect(readmeContent).toContain('src=""');
100+
expect(readmeContent).toContain('href=""');
101+
});
8102
it("should have manifest.json file", async () => {
9103
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
10104

playgrounds/build-frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"email": "hello@caido.com",
1010
"url": "https://caido.com"
1111
},
12+
"repository": "https://github.com/caido-community/dev",
1213
"license": "ISC"
1314
}

0 commit comments

Comments
 (0)