Initial commit

This commit is contained in:
Aditya Gupta
2026-06-29 19:29:19 +05:30
committed by GitHub
commit aabb8986aa
292 changed files with 17976 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# Shared Package
This package contains code which could helps you to develop.
To use the code in the package, you need to add the following to the package.json file.
```json
{
"devDependencies": {
"@extension/dev-utils": "workspace:*"
}
}
```
## Additional Information
`lib/shared-types.ts` contains the types from [type-fest](https://github.com/sindresorhus/type-fest?tab=readme-ov-file#install).

View File

@@ -0,0 +1 @@
export * from './lib/index.js';

View File

@@ -0,0 +1,2 @@
export * from './stream-file-to-zip.js';
export * from './manifest-parser/index.js';

View File

@@ -0,0 +1,39 @@
import type { IManifestParser } from './types.js';
import type { ManifestType } from '@extension/shared';
const convertToFirefoxCompatibleManifest = (manifest: ManifestType) => {
const manifestCopy = {
...manifest,
} as { [key: string]: unknown };
if (manifest.background?.service_worker) {
manifestCopy.background = {
scripts: [manifest.background.service_worker],
type: 'module',
};
}
if (manifest.options_page) {
manifestCopy.options_ui = {
page: manifest.options_page,
browser_style: false,
};
}
manifestCopy.content_security_policy = {
extension_pages: "script-src 'self'; object-src 'self'",
};
manifestCopy.permissions = (manifestCopy.permissions as string[]).filter(value => value !== 'sidePanel');
delete manifestCopy.options_page;
delete manifestCopy.side_panel;
return manifestCopy as ManifestType;
};
export const ManifestParserImpl: IManifestParser = {
convertManifestToString: (manifest, isFirefox) => {
if (isFirefox) {
manifest = convertToFirefoxCompatibleManifest(manifest);
}
return JSON.stringify(manifest, null, 2);
},
};

View File

@@ -0,0 +1,4 @@
import { ManifestParserImpl } from './impl.js';
export type * from './types.js';
export const ManifestParser = ManifestParserImpl;

View File

@@ -0,0 +1,5 @@
import type { ManifestType } from '@extension/shared';
export interface IManifestParser {
convertManifestToString: (manifest: ManifestType, isFirefox: boolean) => string;
}

View File

@@ -0,0 +1,24 @@
import { AsyncZipDeflate } from 'fflate';
import { createReadStream } from 'node:fs';
import type { Zip } from 'fflate';
export const streamFileToZip = (
absPath: string,
relPath: string,
zip: Zip,
onAbort: () => void,
onError: (error: Error) => void,
): void => {
const data = new AsyncZipDeflate(relPath, { level: 1 });
void zip.add(data);
createReadStream(absPath)
.on('data', (chunk: string | Buffer) =>
typeof chunk === 'string' ? data.push(Buffer.from(chunk), false) : data.push(chunk, false),
)
.on('end', () => data.push(new Uint8Array(0), true))
.on('error', error => {
onAbort();
onError(error);
});
};

View File

@@ -0,0 +1,29 @@
{
"name": "@extension/dev-utils",
"version": "0.5.0",
"description": "chrome extension - dev utils",
"type": "module",
"private": true,
"sideEffects": false,
"files": [
"dist/**"
],
"types": "index.mts",
"main": "dist/index.mjs",
"scripts": {
"clean:bundle": "rimraf dist",
"clean:node_modules": "pnpx rimraf node_modules",
"clean:turbo": "rimraf .turbo",
"clean": "pnpm clean:bundle && pnpm clean:node_modules && pnpm clean:turbo",
"ready": "tsc -b",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"format": "prettier . --write --ignore-path ../../.prettierignore",
"type-check": "tsc --noEmit",
"postinstall": "pnpm ready"
},
"devDependencies": {
"@extension/tsconfig": "workspace:*",
"@extension/shared": "workspace:*"
}
}

View File

@@ -0,0 +1,8 @@
{
"extends": "@extension/tsconfig/module",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist"
},
"include": ["index.mts", "lib"]
}