Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pert-with-wings",
"private": true,
"version": "2.1.0",
"version": "3.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
27 changes: 27 additions & 0 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"jsx": "react-jsx",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"moduleDetection": "force",
"useDefineForClassFields": true,
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "bundler",
"paths": {
"@/*": ["src/*"]
},
"types": ["vite/client", "chrome"],
"allowImportingTsExtensions": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
28 changes: 5 additions & 23 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"paths": {
"@/*": ["./src/*"]
},
"types": ["vite/client", "chrome"]
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"files": []
}
27 changes: 15 additions & 12 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"moduleDetection": "force",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,
"noUncheckedSideEffectImports": true
},
"include": [
"vite.config.ts",
"vite-utils.ts",
"src/background/service-worker.ts",
"manifest.config.ts",
"vite-plugin-package-extensions.ts",
"package.json"
]
"include": ["vite.config.ts"]
}
61 changes: 33 additions & 28 deletions vite-plugin-package-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export default function packageExtensions(): PluginOption {
const dir = zip!.folder(fileName);
addFilesToZipArchive(dir, filePath);
} else {
zip!.file(fileName, fs.readFileSync(filePath));
// JSZip expects ArrayBuffer | Uint8Array for binary data. Convert Node Buffer to ArrayBuffer.
const buf = fs.readFileSync(filePath);
// Ensure we pass a plain ArrayBuffer (not SharedArrayBuffer) to satisfy JSZip typings.
const copy = new Uint8Array(buf); // creates a Uint8Array backed by a real ArrayBuffer
const arrayBuffer = copy.buffer;
zip!.file(fileName, arrayBuffer);
}
});
}
Expand All @@ -45,7 +50,8 @@ export default function packageExtensions(): PluginOption {
fs.unlinkSync(fileName);
}

fs.writeFileSync(fileName, file);
// `file` is a Node Buffer (Uint8Array compatible). Cast to the type expected by fs.writeFileSync.
fs.writeFileSync(fileName, file as unknown as Uint8Array);
});
}

Expand All @@ -63,9 +69,9 @@ export default function packageExtensions(): PluginOption {
const bgData = jsonData['background'];

jsonData['background'] = {
scripts: [bgData["service_worker"]],
type: "module"
}
scripts: [bgData['service_worker']],
type: 'module',
};

// All Manifest V3 extensions need an add-on ID in their manifest.json when submitted to AMO.
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings#description
Expand All @@ -79,7 +85,7 @@ export default function packageExtensions(): PluginOption {
fs.writeFileSync(
path.join(inDir, 'manifest.json'),
JSON.stringify(jsonData, null, 2),
{ encoding: 'utf-8' }
{ encoding: 'utf-8' },
);

return data;
Expand All @@ -92,11 +98,11 @@ export default function packageExtensions(): PluginOption {
try {
gherSay(`Let's build v${version}`);
console.log(
' %s \x1b[42m\x1b[30m\033[1m %s \x1b[0m\x1b[32m\033[1m %s \x1b[0m%s',
' %s \x1b[42m\x1b[30m\x1B[1m %s \x1b[0m\x1b[32m\x1B[1m %s \x1b[0m%s',
'🧩',
'PERT WITH WINGS',
`v${version}`,
`started packaging extensions:`
`started packaging extensions:`,
);
console.log(' ');

Expand All @@ -112,12 +118,12 @@ export default function packageExtensions(): PluginOption {
console.log(' - Creating Chrome extension package.');
createZipArchive(
chromeZip,
`chrome-PERT-with-wings-package-${version}.zip`
`chrome-PERT-with-wings-package-${version}.zip`,
);

console.log(
'\x1b[32m\033[1m%s\x1b[0m',
' ✓ Chrome extension packaged.'
'\x1b[32m\x1B[1m%s\x1b[0m',
' ✓ Chrome extension packaged.',
);

const firefoxZip = new JSZip();
Expand All @@ -129,61 +135,60 @@ export default function packageExtensions(): PluginOption {
console.log(' - Creating Firefox extension package.');
createZipArchive(
firefoxZip,
`firefox-PERT-with-wings-package-${version}.zip`
`firefox-PERT-with-wings-package-${version}.zip`,
);
console.log(
'\x1b[32m\033[1m%s\x1b[0m',
' ✓ Firefox extension packaged.'
'\x1b[32m\x1B[1m%s\x1b[0m',
' ✓ Firefox extension packaged.',
);

console.log(' - Creating source code zip file.');
const gitArchive = childProcess.exec(
`git archive --format zip --output extensions/pert-extension-source-code-${version}.zip ${baseBranch}`
`git archive --format zip --output extensions/pert-extension-source-code-${version}.zip ${baseBranch}`,
);

gitArchive.stdout.on('close', () => {
// Listen for the child process to exit. Using the child process 'close' event is
// simpler and avoids accessing stdout which can be null in some environments.
gitArchive.on('close', () => {
console.log(
'\x1b[32m\033[1m%s\x1b[0m',
' Source code zip file created.'
'\x1b[32m\x1B[1m%s\x1b[0m',
' \u2713 Source code zip file created.',
);
console.log(' ');

console.log(
'\x1b[36m%s\x1b[0m',
' Packages successfully created in /extensions'
' Packages successfully created in /extensions',
);

console.log(' ');

console.log(
' - Reverting manifest to original.'
);
console.log(' - Reverting manifest to original.');

fs.writeFileSync(
path.join(inDir, 'manifest.json'),
originalManifestData,
{ encoding: 'utf-8' }
{ encoding: 'utf-8' },
);

console.log(
'\x1b[32m\033[1m%s\x1b[0m',
' Reverted manifest to original.'
'\x1b[32m\x1B[1m%s\x1b[0m',
' \u2713 Reverted manifest to original.',
);


console.log(' ');
console.log(' ');
});
} else {
console.log(
'\x1b[31m%s\x1b[0m',
` × "${inDir}" folder does not exist!`
` × "${inDir}" folder does not exist!`,
);
}
} catch (error) {
console.log(
'\x1b[31m%s\x1b[0m',
' × Something went wrong while building packages!'
' × Something went wrong while building packages!',
);
}
},
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export default defineConfig({
include: ['**/?(*.)+(spec|test).[jt]s?(x)'],
testTimeout: 60_000,
},
server: {
cors: {
origin: [/chrome-extension:\/\//],
},
},
});