Skip to content

Commit 454e18f

Browse files
committed
fix(build): detect user manifest existence before read
resolve: #162 (comment)
1 parent fc90c40 commit 454e18f

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/core/builder/manifest.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Context } from "../../types/index.js";
22
import type { Manifest } from "../../types/manifest.js";
33
import { toMerged } from "es-toolkit";
4-
import { outputJSON, readJSON } from "fs-extra/esm";
4+
import { outputJSON, pathExists, readJSON } from "fs-extra/esm";
55
import { logger } from "../../utils/logger.js";
66

77
export default async function buildManifest(ctx: Context): Promise<void> {
@@ -10,13 +10,14 @@ export default async function buildManifest(ctx: Context): Promise<void> {
1010

1111
const { name, id, updateURL, dist, version } = ctx;
1212

13-
const userData = await readJSON(
14-
`${dist}/addon/manifest.json`,
15-
) as Manifest;
13+
const manifestPath = `${dist}/addon/manifest.json`;
14+
const manifestExists = await pathExists(manifestPath);
15+
const userData = (manifestExists ? await readJSON(manifestPath) : {}) as Partial<Manifest>;
16+
1617
const template: Manifest = {
17-
...userData,
18-
...((!userData.name && name) && { name }),
19-
...(version && { version }),
18+
...(userData as Manifest),
19+
name: userData.name || name,
20+
version: userData.version || version,
2021
manifest_version: 2,
2122
applications: {
2223
zotero: {
@@ -29,7 +30,7 @@ export default async function buildManifest(ctx: Context): Promise<void> {
2930
const data: Manifest = toMerged(userData, template);
3031
logger.debug(`manifest: ${JSON.stringify(data, null, 2)}`);
3132

32-
outputJSON(`${dist}/addon/manifest.json`, data, { spaces: 2 });
33+
outputJSON(manifestPath, data, { spaces: 2 });
3334
}
3435

3536
// TODO: process i10n in manifest.json

0 commit comments

Comments
 (0)