npm run fmt
This commit is contained in:
parent
557fd6ac80
commit
c572f364e5
|
@ -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({
|
||||
export default ['chromium', 'firefox'].flatMap(platform =>
|
||||
buildConfig({
|
||||
manifest: `manifest-${platform}.json`,
|
||||
outDir: `build/${platform}`,
|
||||
// ...
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
|
|
@ -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) => ({
|
||||
...(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?.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) => ({
|
||||
...(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) => ({
|
||||
: (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),
|
||||
})))
|
||||
)
|
||||
}))
|
||||
)),
|
||||
];
|
||||
|
|
10
index.ts
10
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {defineConfig} from 'rollup';
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import {defineConfig} from 'rollup';
|
||||
|
||||
export default defineConfig({
|
||||
input: 'index.ts',
|
||||
|
|
Loading…
Reference in a new issue