From c572f364e5cbfb9066f331675468a9c8d63887a8 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 14 Aug 2023 14:07:31 -0400 Subject: [PATCH] npm run fmt --- README.md | 15 ++++++++------ entrypoints.ts | 54 +++++++++++++++++++++++++++--------------------- index.ts | 10 ++++++--- rollup.config.js | 2 +- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 8df3f2d..0ccc269 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ manifest versions 2 and 3. // rollup.config.js import {buildConfig} from 'rollup-build-webext-config'; -import {nodeResolve} from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; +import {nodeResolve} from '@rollup/plugin-node-resolve'; export default buildConfig({ manifest: 'path/to/your/manifest.json', @@ -32,8 +32,11 @@ export default buildConfig({ // rollup.config.js import {buildConfig} from 'rollup-build-webext-config'; -export default ['chromium', 'firefox'].flatMap(platform => buildConfig({ - manifest: `manifest-${platform}.json`, - outDir: `build/${platform}`, - // ... -})); +export default ['chromium', 'firefox'].flatMap(platform => + buildConfig({ + manifest: `manifest-${platform}.json`, + outDir: `build/${platform}`, + // ... + }) +); +``` diff --git a/entrypoints.ts b/entrypoints.ts index 4d51425..4e5dcde 100644 --- a/entrypoints.ts +++ b/entrypoints.ts @@ -38,23 +38,26 @@ interface ManifestEntrypoint { * @param manifest Parsed `manifest.json` data. */ export const getScriptEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [ - ...(manifest.content_scripts ?? []).flatMap(script => (script.js ?? []).map((path, i) => ({ - type: ManifestEntrypointKind.CONTENT_SCRIPT_JS, - path, - replacePath: (newPath: string) => script.js!.splice(i, 1, newPath), - }))), + ...(manifest.content_scripts ?? []).flatMap(script => + (script.js ?? []).map((path, i) => ({ + type: ManifestEntrypointKind.CONTENT_SCRIPT_JS, + path, + replacePath: (newPath: string) => script.js!.splice(i, 1, newPath), + })) + ), ...(manifest.manifest_version === 2 - ? (manifest.background?.scripts || []).map((path, i) => ({ - type: ManifestEntrypointKind.BACKGROUND_SCRIPT, - path, - replacePath: (newPath: string) => manifest.background!.scripts!.splice(i, 1, newPath), - })) - : (manifest.background?.service_worker ? [{ + ? (manifest.background?.scripts || []).map((path, i) => ({ + type: ManifestEntrypointKind.BACKGROUND_SCRIPT, + path, + replacePath: (newPath: string) => manifest.background!.scripts!.splice(i, 1, newPath), + })) + : (manifest.background?.service_worker + ? [{ type: ManifestEntrypointKind.BACKGROUND_SERVICE_WORKER, path: manifest.background.service_worker, 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. */ export const getAssetEntrypoints = (manifest: chrome.runtime.Manifest): ManifestEntrypoint[] => [ - ...(manifest.content_scripts ?? []).flatMap(script => (script.css ?? []).map((path, i) => ({ - type: ManifestEntrypointKind.CONTENT_SCRIPT_CSS, - path, - replacePath: (newPath: string) => script.css!.splice(i, 1, newPath), - }))), + ...(manifest.content_scripts ?? []).flatMap(script => + (script.css ?? []).map((path, i) => ({ + type: ManifestEntrypointKind.CONTENT_SCRIPT_CSS, + path, + replacePath: (newPath: string) => script.css!.splice(i, 1, newPath), + })) + ), ...Object.entries(manifest.icons || {}).map(([iconSize, path]) => ({ type: ManifestEntrypointKind.ICON, path, @@ -80,10 +85,11 @@ export const getAssetEntrypoints = (manifest: chrome.runtime.Manifest): Manifest path, replacePath: (newPath: string) => manifest.web_accessible_resources![i] = newPath, })) - : (manifest.web_accessible_resources ?? []).flatMap(entry => entry.resources.map((path, i) => ({ - type: ManifestEntrypointKind.WEB_ACCESSIBLE_RESOURCE_V3, - path, - replacePath: (newPath: string) => entry.resources.splice(i, 1, newPath), - }))) - ) + : (manifest.web_accessible_resources ?? []).flatMap(entry => + entry.resources.map((path, i) => ({ + type: ManifestEntrypointKind.WEB_ACCESSIBLE_RESOURCE_V3, + path, + replacePath: (newPath: string) => entry.resources.splice(i, 1, newPath), + })) + )), ]; diff --git a/index.ts b/index.ts index 5c96b71..c8cf59b 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,9 @@ /* eslint-env node */ 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'; @@ -59,7 +59,11 @@ export function buildConfig ({ let uniquenessNum = 0; 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; } diff --git a/rollup.config.js b/rollup.config.js index a098d2d..fc11268 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,5 @@ -import {defineConfig} from 'rollup'; import typescript from '@rollup/plugin-typescript'; +import {defineConfig} from 'rollup'; export default defineConfig({ input: 'index.ts',