Skip to content

Commit 50613d5

Browse files
committed
Add eslint
1 parent 047834a commit 50613d5

28 files changed

+2897
-535
lines changed

eslint.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defaultConfig } from "@caido/eslint-config";
2+
3+
export default [
4+
...defaultConfig({
5+
vue: false,
6+
stylistic: false,
7+
compat: false,
8+
}),
9+
];

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"typecheck": "tsc --noEmit",
1818
"test": "pnpm build && vitest",
1919
"build": "tsup",
20-
"lint": "eslint src --ext .ts"
20+
"lint": "eslint --flag unstable_ts_config --fix ./src ./playgrounds"
2121
},
2222
"keywords": [
2323
"caido",
@@ -40,15 +40,15 @@
4040
"vite": "6.0.7",
4141
"tsup": "8.3.5"
4242
},
43-
4443
"devDependencies": {
44+
"@caido/eslint-config": "0.0.4",
4545
"@types/express": "5.0.0",
4646
"@types/node": "22.10.2",
4747
"@types/ws": "8.5.13",
48+
"eslint": "9.17.0",
4849
"tsup": "8.3.5",
4950
"tsx": "4.19.2",
5051
"typescript": "5.7.2",
51-
"vitest": "2.1.8",
52-
"vite": "6.0.6"
52+
"vitest": "2.1.8"
5353
}
5454
}

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

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
1-
import { describe, it, expect } from 'vitest';
1+
import path from "path";
22

3-
import { getZipFileContent } from '../../utils';
4-
import path from 'path';
3+
import { describe, expect, it } from "vitest";
54

6-
describe('build-backend', () => {
5+
import { getZipFileContent } from "../../utils";
6+
7+
describe("build-backend", () => {
78
it("should have manifest.json file", async () => {
8-
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip');
9-
10-
const manifestJsonContent = await getZipFileContent(zipPath, 'manifest.json');
11-
12-
expect(manifestJsonContent).toEqual(JSON.stringify({
13-
"id": "build-backend",
14-
"name": "Backend",
15-
"version": "1.0.0",
16-
"description": "Backend plugin",
17-
"author": {
18-
"name": "John Doe",
19-
"email": "[email protected]",
20-
"url": "https://example.com"
21-
},
22-
"plugins": [
9+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
10+
11+
const manifestJsonContent = await getZipFileContent(
12+
zipPath,
13+
"manifest.json",
14+
);
15+
16+
expect(manifestJsonContent).toEqual(
17+
JSON.stringify(
2318
{
24-
"id": "backend",
25-
"kind": "backend",
26-
"name": "backend",
27-
"entrypoint": "backend/index.js",
28-
"runtime": "javascript"
29-
}
30-
]
31-
}, undefined, 2));
19+
id: "build-backend",
20+
name: "Backend",
21+
version: "1.0.0",
22+
description: "Backend plugin",
23+
author: {
24+
name: "John Doe",
25+
26+
url: "https://example.com",
27+
},
28+
plugins: [
29+
{
30+
id: "backend",
31+
kind: "backend",
32+
name: "backend",
33+
entrypoint: "backend/index.js",
34+
runtime: "javascript",
35+
},
36+
],
37+
},
38+
undefined,
39+
2,
40+
),
41+
);
3242
});
3343

3444
it("should have index.js file", async () => {
35-
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip');
45+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
3646

37-
const indexJsContent = (await getZipFileContent(zipPath, 'backend/index.js'))?.replace(/\s+/g, '');
47+
const indexJsContent = (
48+
await getZipFileContent(zipPath, "backend/index.js")
49+
)?.replace(/\s+/g, "");
3850

3951
const expectedContent = `
4052
//packages/backend/src/index.ts
@@ -43,7 +55,7 @@ describe('build-backend', () => {
4355
export {
4456
init
4557
};
46-
`.replace(/\s+/g, '');
58+
`.replace(/\s+/g, "");
4759

4860
expect(indexJsContent).toEqual(expectedContent);
4961
});

playgrounds/build-backend/caido.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export default {
1313
kind: "backend",
1414
id: "backend",
1515
root: "./packages/backend",
16-
}
16+
},
1717
],
18-
};
18+
};
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,53 @@
1-
import { describe, it, expect } from 'vitest';
1+
import path from "path";
22

3-
import { getZipFileContent } from '../../../playgrounds/utils';
4-
import path from 'path';
3+
import { describe, expect, it } from "vitest";
54

6-
describe('build-frontend', () => {
5+
import { getZipFileContent } from "../../../playgrounds/utils";
6+
7+
describe("build-frontend", () => {
78
it("should have manifest.json file", async () => {
8-
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip');
9-
10-
const manifestJsonContent = await getZipFileContent(zipPath, 'manifest.json');
11-
12-
expect(manifestJsonContent).toEqual(JSON.stringify({
13-
"id": "build-frontend",
14-
"name": "Frontend",
15-
"version": "1.0.0",
16-
"description": "Frontend plugin",
17-
"author": {
18-
"name": "John Doe",
19-
"email": "[email protected]",
20-
"url": "https://example.com"
21-
},
22-
"plugins": [
9+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
10+
11+
const manifestJsonContent = await getZipFileContent(
12+
zipPath,
13+
"manifest.json",
14+
);
15+
16+
expect(manifestJsonContent).toEqual(
17+
JSON.stringify(
2318
{
24-
"id": "frontend",
25-
"kind": "frontend",
26-
"name": "frontend",
27-
"entrypoint": "frontend/index.js",
28-
"style": "frontend/index.css",
29-
"backend": null
30-
}
31-
]
32-
}, undefined, 2));
19+
id: "build-frontend",
20+
name: "Frontend",
21+
version: "1.0.0",
22+
description: "Frontend plugin",
23+
author: {
24+
name: "John Doe",
25+
26+
url: "https://example.com",
27+
},
28+
plugins: [
29+
{
30+
id: "frontend",
31+
kind: "frontend",
32+
name: "frontend",
33+
entrypoint: "frontend/index.js",
34+
style: "frontend/index.css",
35+
backend: null,
36+
},
37+
],
38+
},
39+
undefined,
40+
2,
41+
),
42+
);
3343
});
3444

3545
it("should have index.js file", async () => {
36-
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip');
46+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
3747

38-
const indexJsContent = (await getZipFileContent(zipPath, 'frontend/index.js'))?.replace(/\s+/g, '');
48+
const indexJsContent = (
49+
await getZipFileContent(zipPath, "frontend/index.js")
50+
)?.replace(/\s+/g, "");
3951

4052
const expectedContent = `
4153
const o = () => {
@@ -44,16 +56,19 @@ describe('build-frontend', () => {
4456
export {
4557
o as init
4658
};
47-
`.replace(/\s+/g, '');
59+
`.replace(/\s+/g, "");
4860

4961
expect(indexJsContent).toEqual(expectedContent);
5062
});
5163

5264
it("should have index.css file", async () => {
53-
const zipPath = path.resolve(__dirname, '../dist/plugin_package.zip');
65+
const zipPath = path.resolve(__dirname, "../dist/plugin_package.zip");
5466

55-
const indexCssContent = await getZipFileContent(zipPath, 'frontend/index.css');
67+
const indexCssContent = await getZipFileContent(
68+
zipPath,
69+
"frontend/index.css",
70+
);
5671

57-
expect(indexCssContent).toEqual('body{background-color:red}\n');
72+
expect(indexCssContent).toEqual("body{background-color:red}\n");
5873
});
5974
});

playgrounds/build-frontend/caido.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export default {
1313
kind: "frontend",
1414
id: "frontend",
1515
root: "./packages/frontend",
16-
}
16+
},
1717
],
18-
};
18+
};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import './index.css';
1+
import "./index.css";
22

33
export const init = () => {
4-
console.log('init');
5-
};
4+
console.log("init");
5+
};

playgrounds/setup.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { execSync } from 'child_process';
2-
import path from 'path';
3-
import { afterAll, beforeAll, expect } from 'vitest';
1+
import { execSync } from "child_process";
2+
import path from "path";
43

5-
beforeAll(async ({ file }) => {
4+
import { afterAll, beforeAll, expect } from "vitest";
5+
6+
beforeAll(({ file }) => {
67
// Get the test file path from the current test file
78
const testPath = file.filepath;
89

@@ -11,17 +12,17 @@ beforeAll(async ({ file }) => {
1112

1213
// Installing the dependencies
1314
console.log(`Installing dependencies in ${playgroundDir}...`);
14-
execSync('pnpm install', {
15+
execSync("pnpm install", {
1516
cwd: playgroundDir,
1617
});
1718

1819
// Run pnpm build in the playground directory
1920
console.log(`Building playground in ${playgroundDir}...`);
20-
execSync('node ../../dist/cli.js build', {
21+
execSync("node ../../dist/cli.js build", {
2122
cwd: playgroundDir,
2223
});
2324
});
2425

2526
afterAll(() => {
2627
// Clean up if needed
27-
});
28+
});

playgrounds/utils.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import JSZip from 'jszip';
2-
import fs from 'fs/promises';
1+
import fs from "fs/promises";
2+
3+
import JSZip from "jszip";
34

45
/**
56
* Extracts the content of a specific file from a zip archive
67
* @param zipPath - Path to the zip file
78
* @param filePath - The internal path of the file to extract
89
* @returns Promise resolving to the file content as a string or null if not found
910
*/
10-
export async function getZipFileContent(zipPath: string, filePath: string): Promise<string | null> {
11-
try {
12-
const zipBuffer = await fs.readFile(zipPath);
13-
const zip = new JSZip();
14-
const loadedZip = await zip.loadAsync(zipBuffer);
15-
const file = loadedZip.file(filePath);
16-
17-
if (!file) {
18-
return null;
19-
}
20-
21-
return await file.async('string');
22-
} catch (error) {
23-
console.error('Error extracting file from zip:', error);
24-
return null;
11+
export async function getZipFileContent(
12+
zipPath: string,
13+
filePath: string,
14+
): Promise<string | undefined> {
15+
try {
16+
const zipBuffer = await fs.readFile(zipPath);
17+
const zip = new JSZip();
18+
const loadedZip = await zip.loadAsync(zipBuffer);
19+
const file = loadedZip.file(filePath);
20+
21+
if (!file) {
22+
return undefined;
2523
}
24+
25+
return await file.async("string");
26+
} catch (error) {
27+
console.error("Error extracting file from zip:", error);
28+
return undefined;
29+
}
2630
}

0 commit comments

Comments
 (0)