Skip to content

Commit d441e2e

Browse files
authored
chore: merge pull request #81 from addon-stack/develop
Release
2 parents b512755 + 9af389f commit d441e2e

21 files changed

Lines changed: 310 additions & 285 deletions

src/cli/builders/manifest/ManifestBase.ts

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import _ from "lodash";
2+
13
import {mergeWebAccessibleResources} from "./utils";
24

35
import {
46
CoreManifest,
5-
FirefoxManifest,
67
Manifest,
78
ManifestAccessibleResource,
89
ManifestAccessibleResources,
@@ -14,13 +15,13 @@ import {
1415
ManifestHostPermissions,
1516
ManifestIcons,
1617
ManifestIncognito,
17-
ManifestPermissions,
1818
ManifestOptionalPermissions,
19+
ManifestPermissions,
1920
ManifestPopup,
2021
ManifestSidebar,
2122
ManifestVersion,
2223
} from "@typing/manifest";
23-
import {Browser} from "@typing/browser";
24+
import {Browser, BrowserSpecific} from "@typing/browser";
2425
import {Language} from "@typing/locale";
2526
import {CommandExecuteActionName} from "@typing/command";
2627
import {DefaultIconGroupName} from "@typing/icon";
@@ -40,7 +41,6 @@ export class ManifestError extends Error {
4041

4142
export default abstract class<T extends CoreManifest> implements ManifestBuilder<T> {
4243
protected name: string = "__MSG_app_name__";
43-
protected email?: string;
4444
protected author?: string;
4545
protected homepage?: string;
4646
protected shortName?: string;
@@ -49,6 +49,7 @@ export default abstract class<T extends CoreManifest> implements ManifestBuilder
4949
protected version: string = "0.0.0";
5050
protected icon?: string;
5151
protected incognito?: ManifestIncognito;
52+
protected specific?: BrowserSpecific;
5253
protected locale?: Language;
5354
protected icons: ManifestIcons = new Map();
5455
protected background?: ManifestBackground;
@@ -91,12 +92,6 @@ export default abstract class<T extends CoreManifest> implements ManifestBuilder
9192
return this;
9293
}
9394

94-
public setEmail(email?: string): this {
95-
this.email = email;
96-
97-
return this;
98-
}
99-
10095
public setName(name: string): this {
10196
this.name = name;
10297

@@ -139,6 +134,12 @@ export default abstract class<T extends CoreManifest> implements ManifestBuilder
139134
return this;
140135
}
141136

137+
public setSpecific(settings?: BrowserSpecific): this {
138+
this.specific = settings;
139+
140+
return this;
141+
}
142+
142143
public setIcons(icons?: ManifestIcons): this {
143144
this.icons = icons || new Map();
144145

@@ -464,13 +465,52 @@ export default abstract class<T extends CoreManifest> implements ManifestBuilder
464465
}
465466
}
466467

467-
protected buildBrowserSpecificSettings(): Partial<FirefoxManifest> | undefined {
468-
if (this.browser === Browser.Firefox && this.email && this.permissions.has("storage")) {
468+
protected buildBrowserSpecificSettings(): Partial<Manifest> | undefined {
469+
const settings = this.specific || {};
470+
const {safari, gecko, geckoAndroid} = settings;
471+
472+
if (this.browser === Browser.Firefox) {
473+
const emptyGecko =
474+
_.isEmpty(gecko?.id) &&
475+
_.isEmpty(gecko?.strictMinVersion) &&
476+
_.isEmpty(gecko?.strictMaxVersion) &&
477+
_.isEmpty(gecko?.updateUrl);
478+
479+
const emptyGeckoAndroid =
480+
_.isEmpty(geckoAndroid?.strictMinVersion) && _.isEmpty(geckoAndroid?.strictMaxVersion);
481+
482+
if (emptyGecko && emptyGeckoAndroid) {
483+
return;
484+
}
485+
486+
return {
487+
browser_specific_settings: {
488+
gecko: emptyGecko
489+
? undefined
490+
: {
491+
id: gecko?.id,
492+
strict_min_version: gecko?.strictMinVersion,
493+
strict_max_version: gecko?.strictMaxVersion,
494+
update_url: gecko?.updateUrl,
495+
},
496+
gecko_android: emptyGeckoAndroid
497+
? undefined
498+
: {
499+
strict_min_version: geckoAndroid?.strictMinVersion,
500+
strict_max_version: geckoAndroid?.strictMaxVersion,
501+
},
502+
},
503+
};
504+
} else if (this.browser === Browser.Safari) {
505+
if (_.isEmpty(safari?.strictMinVersion) && _.isEmpty(safari?.strictMaxVersion)) {
506+
return;
507+
}
508+
469509
return {
470510
browser_specific_settings: {
471-
gecko: {
472-
id: this.email,
473-
// strict_min_version: this.minimumVersion,
511+
safari: {
512+
strict_min_version: safari?.strictMinVersion,
513+
strict_max_version: safari?.strictMaxVersion,
474514
},
475515
},
476516
};

src/cli/plugins/dotenv/crypt.test.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/cli/plugins/dotenv/crypt.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/cli/plugins/dotenv/index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
1-
import {createHash} from "crypto";
21
import {DefinePlugin} from "@rspack/core";
32

43
import {definePlugin} from "@main/plugin";
5-
6-
import {encryptData} from "./crypt";
74
import {filterEnvVars, resolveEnvOptions} from "./utils";
85

96
import {type DotenvParseOutput} from "dotenv";
107

11-
const generateKey = (value: string): string => {
12-
return createHash("sha256").update(value).digest("base64");
13-
};
14-
158
export default definePlugin((vars: DotenvParseOutput = {}) => {
169
return {
1710
name: "adnbn:dotenv",
1811
bundler: ({config}) => {
19-
const {filter, crypt} = resolveEnvOptions(config.env);
20-
21-
const filteredVars = filterEnvVars(vars, filter);
22-
23-
const key = generateKey([config.app, ...Object.keys(filteredVars)].join("-"));
12+
const {filter} = resolveEnvOptions(config.env);
2413

25-
const data = crypt ? encryptData(filteredVars, key) : filteredVars;
14+
const data = filterEnvVars(vars, filter);
2615

2716
return {
2817
plugins: [
2918
new DefinePlugin({
30-
__ADNBN_ENV_CRYPTO_KEY__: JSON.stringify(key),
3119
"process.env": JSON.stringify(data),
3220
}),
3321
],

src/cli/plugins/dotenv/utils.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {filterEnvVars, resolveEnvOptions} from "./utils";
2-
import {ReservedEnvKeys} from "../../../types/env";
2+
import {EnvReservedKeys} from "../../../types/env";
33

44
const baseVars = {
55
APP: "myapp",
@@ -38,9 +38,9 @@ describe("dotenv utils - filterEnvVars & resolveEnvOptions", () => {
3838
});
3939
});
4040

41-
test("object with filter and crypt true - filter selection plus crypt flag detection", () => {
41+
test("object with filter true - filter selection flag detection", () => {
4242
const option = {filter: "PUBLIC_", crypt: true} as const;
43-
const {filter, crypt} = resolveEnvOptions(option);
43+
const {filter} = resolveEnvOptions(option);
4444
const filtered = filterEnvVars(baseVars, filter);
4545
expect(filtered).toEqual({
4646
APP: baseVars.APP,
@@ -50,8 +50,6 @@ describe("dotenv utils - filterEnvVars & resolveEnvOptions", () => {
5050
PUBLIC_API_URL: baseVars.PUBLIC_API_URL,
5151
PUBLIC_FEATURE: baseVars.PUBLIC_FEATURE,
5252
});
53-
54-
expect(crypt).toBe(true);
5553
});
5654

5755
test("empty string filter results in all keys", () => {
@@ -71,7 +69,7 @@ describe("dotenv utils - filterEnvVars & resolveEnvOptions", () => {
7169
const {filter} = resolveEnvOptions(() => false);
7270
const filtered = filterEnvVars(baseVars, filter);
7371
const expected: any = {};
74-
for (const key of ReservedEnvKeys) expected[key] = (baseVars as any)[key];
72+
for (const key of EnvReservedKeys) expected[key] = (baseVars as any)[key];
7573
expect(filtered).toEqual(expected);
7674
});
7775

src/cli/plugins/dotenv/utils.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import _ from "lodash";
2-
import {EnvFilterFunction, EnvFilterOptions, EnvFilterVariant, ReservedEnvKeys} from "@typing/env";
2+
import {EnvFilterFunction, EnvFilterOptions, EnvFilterVariant, EnvReservedKeys} from "@typing/env";
33

44
export type EnvOption = EnvFilterVariant | Partial<EnvFilterOptions>;
55

6-
export const resolveEnvOptions = (option?: EnvOption): {filter: EnvFilterFunction; crypt: boolean} => {
6+
export const resolveEnvOptions = (option?: EnvOption): {filter: EnvFilterFunction} => {
77
let userFilter: EnvFilterVariant | undefined;
8-
let crypt: boolean = false;
98

109
if (_.isString(option)) {
1110
userFilter = option;
1211
} else if (_.isFunction(option)) {
1312
userFilter = option;
1413
} else if (option && _.isObject(option)) {
15-
const {filter: f, crypt: c} = option as Partial<EnvFilterOptions>;
14+
const {filter: f} = option as Partial<EnvFilterOptions>;
1615

1716
userFilter = f;
18-
crypt = Boolean(c);
1917
}
2018

2119
const filter = (key: string): boolean => {
22-
if (ReservedEnvKeys.has(key)) {
20+
if (EnvReservedKeys.has(key)) {
2321
return true;
2422
}
2523

@@ -34,7 +32,7 @@ export const resolveEnvOptions = (option?: EnvOption): {filter: EnvFilterFunctio
3432
return true;
3533
};
3634

37-
return {filter, crypt};
35+
return {filter};
3836
};
3937

4038
export const filterEnvVars = <T extends Record<string, any>>(vars: T, filter: EnvFilterFunction): Partial<T> => {

src/cli/plugins/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
export {default as assetPlugin} from "./asset";
2-
export {default as bundlerPlugin} from "./bundler";
3-
export {default as backgroundPlugin} from "./background";
4-
export {default as contentPlugin} from "./content";
5-
export {default as dotenvPlugin} from "./dotenv";
6-
export {default as htmlPlugin} from "./html";
7-
export {default as optimizationPlugin} from "./optimization";
8-
export {default as outputPlugin} from "./output";
9-
export {default as iconPlugin} from "./icon";
10-
export {default as localePlugin} from "./locale";
11-
export {default as metaPlugin} from "./meta";
12-
export {default as offscreenPlugin} from "./offscreen";
13-
export {default as pagePlugin} from "./page";
14-
export {default as popupPlugin} from "./popup";
15-
export {default as publicPlugin} from "./public";
16-
export {default as sidebarPlugin} from "./sidebar";
17-
export {default as typescriptPlugin, TypescriptConfig, FileBuilder, VendorDeclaration} from "./typescript";
18-
export {default as reactPlugin} from "./react";
19-
export {default as stylePlugin} from "./style";
20-
export {default as viewPlugin} from "./view";
21-
export {default as versionPlugin} from "./version";
1+
export {default as pluginAsset} from "./asset";
2+
export {default as pluginBundler} from "./bundler";
3+
export {default as pluginBackground} from "./background";
4+
export {default as pluginContent} from "./content";
5+
export {default as pluginDotenv} from "./dotenv";
6+
export {default as pluginHtml} from "./html";
7+
export {default as pluginOptimization} from "./optimization";
8+
export {default as pluginOutput} from "./output";
9+
export {default as pluginIcon} from "./icon";
10+
export {default as pluginLocale} from "./locale";
11+
export {default as pluginMeta} from "./meta";
12+
export {default as pluginOffscreen} from "./offscreen";
13+
export {default as pluginPage} from "./page";
14+
export {default as pluginPopup} from "./popup";
15+
export {default as pluginPublic} from "./public";
16+
export {default as pluginSidebar} from "./sidebar";
17+
export {default as pluginTypescript, TypescriptConfig, FileBuilder, VendorDeclaration} from "./typescript";
18+
export {default as pluginReact} from "./react";
19+
export {default as pluginStyle} from "./style";
20+
export {default as pluginView} from "./view";
21+
export {default as pluginVersion} from "./version";

src/cli/plugins/meta/AbstractMeta.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getEnv} from "@main/env";
44

55
import type {ReadonlyConfig} from "@typing/config";
66

7-
export default abstract class AbstractMeta<V extends string = string> {
7+
export default abstract class AbstractMeta<V = string> {
88
public static value<T extends AbstractMeta<any>>(
99
this: new (config: ReadonlyConfig) => T,
1010
config: ReadonlyConfig
@@ -19,22 +19,22 @@ export default abstract class AbstractMeta<V extends string = string> {
1919
public getResolved(): V | undefined {
2020
const value = this.getValue();
2121

22-
let resolved = _.isFunction(value) ? value() : value;
22+
const resolved = _.isFunction(value) ? value() : value;
2323

2424
if (this.isValid(resolved)) {
2525
return resolved;
2626
}
2727

2828
if (_.isString(resolved)) {
29-
resolved = getEnv(resolved);
29+
const valueFromEnv = getEnv(resolved);
3030

31-
if (this.isValid(resolved)) {
32-
return resolved;
31+
if (this.isValid(valueFromEnv)) {
32+
return valueFromEnv;
3333
}
3434
}
3535
}
3636

37-
protected isValid(value?: V): boolean {
37+
protected isValid(value?: unknown): value is V {
3838
return true;
3939
}
4040
}

0 commit comments

Comments
 (0)