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,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);
});
};