don't use readFileSync
This commit is contained in:
parent
c22c6db195
commit
e1a4f59516
16
index.ts
16
index.ts
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-env node */
|
/* eslint-env node */
|
||||||
|
|
||||||
import {readFileSync} from 'node:fs';
|
import {readFile} from 'node:fs/promises';
|
||||||
import {basename, dirname, extname, join, relative, resolve} from 'node:path';
|
import {basename, dirname, extname, join, relative, resolve} from 'node:path';
|
||||||
|
|
||||||
import {type Plugin, type RollupOptions} from 'rollup';
|
import {type Plugin, type RollupOptions} from 'rollup';
|
||||||
|
@ -21,7 +21,7 @@ import {getAssetEntrypoints, getScriptEntrypoints} from './entrypoints';
|
||||||
* Javascript entry point
|
* Javascript entry point
|
||||||
* @param options.sourcemap Controls inclusion of sourcemaps in the output
|
* @param options.sourcemap Controls inclusion of sourcemaps in the output
|
||||||
*/
|
*/
|
||||||
export function buildConfig ({
|
export async function buildConfig ({
|
||||||
manifest: manifestPathRelative,
|
manifest: manifestPathRelative,
|
||||||
outDir,
|
outDir,
|
||||||
plugins = [],
|
plugins = [],
|
||||||
|
@ -31,14 +31,14 @@ export function buildConfig ({
|
||||||
outDir: string;
|
outDir: string;
|
||||||
plugins: Plugin[];
|
plugins: Plugin[];
|
||||||
sourcemap: boolean | 'inline' | 'hidden';
|
sourcemap: boolean | 'inline' | 'hidden';
|
||||||
}): RollupOptions[] {
|
}): Promise<RollupOptions[]> {
|
||||||
const manifestPath = resolve(process.cwd(), manifestPathRelative);
|
const manifestPath = resolve(process.cwd(), manifestPathRelative);
|
||||||
const manifestDirname = dirname(manifestPath);
|
const manifestDirname = dirname(manifestPath);
|
||||||
|
|
||||||
// Load the manifest
|
// Load the manifest
|
||||||
let manifestContent: chrome.runtime.Manifest;
|
let manifestContent: chrome.runtime.Manifest;
|
||||||
try {
|
try {
|
||||||
manifestContent = JSON.parse(readFileSync(manifestPath, {encoding: 'utf-8'}));
|
manifestContent = JSON.parse(await readFile(manifestPath, {encoding: 'utf-8'}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Failed to load manifest');
|
throw new Error('Failed to load manifest');
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,8 @@ export function buildConfig ({
|
||||||
{
|
{
|
||||||
name: '_manifest-asset-processing',
|
name: '_manifest-asset-processing',
|
||||||
// emit other assets
|
// emit other assets
|
||||||
buildStart () {
|
async buildStart () {
|
||||||
assets.forEach(({path, replacePath}) => {
|
await Promise.all(assets.map(async ({path, replacePath}) => {
|
||||||
// Figure out where the asset will live in output
|
// Figure out where the asset will live in output
|
||||||
const outPath = ensureUniquePath(path);
|
const outPath = ensureUniquePath(path);
|
||||||
|
|
||||||
|
@ -118,9 +118,9 @@ export function buildConfig ({
|
||||||
this.emitFile({
|
this.emitFile({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
fileName: outPath,
|
fileName: outPath,
|
||||||
source: readFileSync(join(manifestDirname, path)),
|
source: await readFile(join(manifestDirname, path)),
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
// hacks to make sure the manifest is emitted as bare JSON
|
// hacks to make sure the manifest is emitted as bare JSON
|
||||||
|
|
Loading…
Reference in a new issue