version 0.2 ready for upload
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
import esbuild from 'esbuild';
|
||||
import process from 'process';
|
||||
import { cp, mkdir, readdir } from 'node:fs/promises';
|
||||
import { cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
||||
|
||||
const banner = `/*
|
||||
* logsdu - fills and submits a three-field academic portal login.
|
||||
@@ -37,16 +37,40 @@ const banner = `/*
|
||||
const prod = process.argv[2] === 'production';
|
||||
const outdir = 'build';
|
||||
|
||||
// Target browser. Firefox and Chrome disagree on exactly one manifest key, so
|
||||
// the manifest is written per target rather than duplicated in the tree.
|
||||
const target = process.env.TARGET === 'chrome' ? 'chrome' : 'firefox';
|
||||
|
||||
/**
|
||||
* Write the manifest for the target browser.
|
||||
*
|
||||
* Firefox MV3 runs the background as an event page ("scripts"); Chrome MV3
|
||||
* requires a service worker and rejects "scripts" outright, so the two cannot
|
||||
* simply coexist in one file. Chrome also has no use for the gecko block.
|
||||
*/
|
||||
async function writeManifest() {
|
||||
const manifest = JSON.parse(await readFile('src/manifest.json', 'utf8'));
|
||||
if (target === 'chrome') {
|
||||
delete manifest.browser_specific_settings;
|
||||
manifest.background = { service_worker: 'background.js' };
|
||||
}
|
||||
await writeFile(
|
||||
`${outdir}/manifest.json`,
|
||||
`${JSON.stringify(manifest, null, '\t')}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
// Everything that is not TypeScript is copied verbatim into build/, so that
|
||||
// the directory can be handed straight to about:debugging.
|
||||
async function copyStatic() {
|
||||
await mkdir(outdir, { recursive: true });
|
||||
for (const name of await readdir('src')) {
|
||||
if (name.endsWith('.json') || name.endsWith('.html') || name.endsWith('.css')) {
|
||||
if (name.endsWith('.html') || name.endsWith('.css')) {
|
||||
await cp(`src/${name}`, `${outdir}/${name}`);
|
||||
}
|
||||
}
|
||||
await cp('icons', `${outdir}/icons`, { recursive: true });
|
||||
await writeManifest();
|
||||
}
|
||||
|
||||
await copyStatic();
|
||||
@@ -65,10 +89,11 @@ const context = await esbuild.context({
|
||||
js: banner,
|
||||
},
|
||||
plugins: [staticPlugin],
|
||||
// Four independent entry points: no shared runtime, no imports at load
|
||||
// Five independent entry points: no shared runtime, no imports at load
|
||||
// time. Content scripts and page-world scripts cannot be ES modules, so
|
||||
// every bundle has to stand alone.
|
||||
entryPoints: [
|
||||
'src/background.ts',
|
||||
'src/content.ts',
|
||||
'src/injected.ts',
|
||||
'src/options.ts',
|
||||
@@ -81,7 +106,14 @@ const context = await esbuild.context({
|
||||
sourcemap: prod ? false : 'inline',
|
||||
treeShaking: true,
|
||||
outdir,
|
||||
minify: prod,
|
||||
// Deliberately never minified. addons.mozilla.org requires a separate
|
||||
// source-code submission for any add-on whose uploaded code is minified or
|
||||
// otherwise machine-generated, and that obligation would apply to every
|
||||
// release from now on. The whole extension is a few tens of kilobytes, so
|
||||
// the saving would not pay for the process, and shipping readable code
|
||||
// makes the review -- and anyone auditing what handles their credentials --
|
||||
// straightforward.
|
||||
minify: false,
|
||||
});
|
||||
|
||||
if (prod) {
|
||||
|
||||
Reference in New Issue
Block a user