npm run fmt

This commit is contained in:
Erin 2023-08-14 14:07:31 -04:00
parent 557fd6ac80
commit c572f364e5
4 changed files with 47 additions and 34 deletions

View file

@ -12,8 +12,8 @@ manifest versions 2 and 3.
// rollup.config.js // rollup.config.js
import {buildConfig} from 'rollup-build-webext-config'; import {buildConfig} from 'rollup-build-webext-config';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'; import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
export default buildConfig({ export default buildConfig({
manifest: 'path/to/your/manifest.json', manifest: 'path/to/your/manifest.json',
@ -32,8 +32,11 @@ export default buildConfig({
// rollup.config.js // rollup.config.js
import {buildConfig} from 'rollup-build-webext-config'; import {buildConfig} from 'rollup-build-webext-config';
export default ['chromium', 'firefox'].flatMap(platform => buildConfig({ export default ['chromium', 'firefox'].flatMap(platform =>
buildConfig({
manifest: `manifest-${platform}.json`, manifest: `manifest-${platform}.json`,
outDir: `build/${platform}`, outDir: `build/${platform}`,
// ... // ...
})); })
);
```

View file

@ -38,23 +38,26 @@ interface ManifestEntrypoint {
* @param manifest Parsed `manifest.json` data. * @param manifest Parsed `manifest.json` data.
*/ */
export const getScriptEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [ export const getScriptEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [
...(manifest.content_scripts ?? []).flatMap(script => (script.js ?? []).map((path, i) => ({ ...(manifest.content_scripts ?? []).flatMap(script =>
(script.js ?? []).map((path, i) => ({
type: ManifestEntrypointKind.CONTENT_SCRIPT_JS, type: ManifestEntrypointKind.CONTENT_SCRIPT_JS,
path, path,
replacePath: (newPath: string) => script.js!.splice(i, 1, newPath), replacePath: (newPath: string) => script.js!.splice(i, 1, newPath),
}))), }))
),
...(manifest.manifest_version === 2 ...(manifest.manifest_version === 2
? (manifest.background?.scripts || []).map((path, i) => ({ ? (manifest.background?.scripts || []).map((path, i) => ({
type: ManifestEntrypointKind.BACKGROUND_SCRIPT, type: ManifestEntrypointKind.BACKGROUND_SCRIPT,
path, path,
replacePath: (newPath: string) => manifest.background!.scripts!.splice(i, 1, newPath), replacePath: (newPath: string) => manifest.background!.scripts!.splice(i, 1, newPath),
})) }))
: (manifest.background?.service_worker ? [{ : (manifest.background?.service_worker
? [{
type: ManifestEntrypointKind.BACKGROUND_SERVICE_WORKER, type: ManifestEntrypointKind.BACKGROUND_SERVICE_WORKER,
path: manifest.background.service_worker, path: manifest.background.service_worker,
replacePath: (newPath: string) => manifest.background!.service_worker = newPath, replacePath: (newPath: string) => manifest.background!.service_worker = newPath,
}] : []) }]
), : [])),
]; ];
/** /**
@ -64,11 +67,13 @@ export const getScriptEntrypoints = (manifest: chrome.runtime.Manifest): Manifes
* @param manifest Parsed `manifest.json` data. * @param manifest Parsed `manifest.json` data.
*/ */
export const getAssetEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [ export const getAssetEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [
...(manifest.content_scripts ?? []).flatMap(script => (script.css ?? []).map((path, i) => ({ ...(manifest.content_scripts ?? []).flatMap(script =>
(script.css ?? []).map((path, i) => ({
type: ManifestEntrypointKind.CONTENT_SCRIPT_CSS, type: ManifestEntrypointKind.CONTENT_SCRIPT_CSS,
path, path,
replacePath: (newPath: string) => script.css!.splice(i, 1, newPath), replacePath: (newPath: string) => script.css!.splice(i, 1, newPath),
}))), }))
),
...Object.entries(manifest.icons || {}).map(([iconSize, path]) => ({ ...Object.entries(manifest.icons || {}).map(([iconSize, path]) => ({
type: ManifestEntrypointKind.ICON, type: ManifestEntrypointKind.ICON,
path, path,
@ -80,10 +85,11 @@ export const getAssetEntrypoints = (manifest: chrome.runtime.Manifest): Manifest
path, path,
replacePath: (newPath: string) => manifest.web_accessible_resources![i] = newPath, replacePath: (newPath: string) => manifest.web_accessible_resources![i] = newPath,
})) }))
: (manifest.web_accessible_resources ?? []).flatMap(entry => entry.resources.map((path, i) => ({ : (manifest.web_accessible_resources ?? []).flatMap(entry =>
entry.resources.map((path, i) => ({
type: ManifestEntrypointKind.WEB_ACCESSIBLE_RESOURCE_V3, type: ManifestEntrypointKind.WEB_ACCESSIBLE_RESOURCE_V3,
path, path,
replacePath: (newPath: string) => entry.resources.splice(i, 1, newPath), replacePath: (newPath: string) => entry.resources.splice(i, 1, newPath),
}))) }))
) )),
]; ];

View file

@ -1,9 +1,9 @@
/* eslint-env node */ /* eslint-env node */
import {readFileSync} from 'node:fs'; import {readFileSync} from 'node:fs';
import {resolve, basename, extname, dirname, relative, join} from 'node:path'; import {basename, dirname, extname, join, relative, resolve} from 'node:path';
import {type RollupOptions, type Plugin} from 'rollup'; import {type Plugin, type RollupOptions} from 'rollup';
import {getAssetEntrypoints, getScriptEntrypoints} from './entrypoints'; import {getAssetEntrypoints, getScriptEntrypoints} from './entrypoints';
@ -59,7 +59,11 @@ export function buildConfig ({
let uniquenessNum = 0; let uniquenessNum = 0;
const existingNames = [...uniqueFileNameSegmentCache.values()]; const existingNames = [...uniqueFileNameSegmentCache.values()];
while (existingNames.some(existingName => existingName.toLowerCase() === buildName(idealName, uniquenessNum).toLowerCase())) { while (
existingNames.some(existingName =>
existingName.toLowerCase() === buildName(idealName, uniquenessNum).toLowerCase()
)
) {
uniquenessNum += 1; uniquenessNum += 1;
} }

View file

@ -1,5 +1,5 @@
import {defineConfig} from 'rollup';
import typescript from '@rollup/plugin-typescript'; import typescript from '@rollup/plugin-typescript';
import {defineConfig} from 'rollup';
export default defineConfig({ export default defineConfig({
input: 'index.ts', input: 'index.ts',