wext-manifest-transformer 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -0
- package/lib/tests/match.test.js +35 -0
- package/lib/{esm/tests → tests}/transform.test.js +2 -2
- package/lib/{cjs/transform.d.ts → transform.d.ts} +1 -1
- package/lib/{esm/transform.js → transform.js} +2 -3
- package/package.json +21 -17
- package/readme.md +1 -4
- package/lib/cjs/constants.js +0 -20
- package/lib/cjs/index.d.ts +0 -4
- package/lib/cjs/index.js +0 -13
- package/lib/cjs/tests/match.test.js +0 -37
- package/lib/cjs/tests/transform.test.js +0 -128
- package/lib/cjs/transform.js +0 -39
- package/lib/esm/constants.d.ts +0 -18
- package/lib/esm/index.d.ts +0 -4
- package/lib/esm/index.js +0 -5
- package/lib/esm/tests/chrome.json +0 -39
- package/lib/esm/tests/firefox.json +0 -41
- package/lib/esm/tests/manifest.json +0 -56
- package/lib/esm/tests/match.test.d.ts +0 -1
- package/lib/esm/tests/match.test.js +0 -35
- package/lib/esm/tests/transform.test.d.ts +0 -1
- package/lib/esm/transform.d.ts +0 -2
- /package/lib/{cjs/constants.d.ts → constants.d.ts} +0 -0
- /package/lib/{esm/constants.js → constants.js} +0 -0
- /package/lib/{cjs/tests → tests}/chrome.json +0 -0
- /package/lib/{cjs/tests → tests}/firefox.json +0 -0
- /package/lib/{cjs/tests → tests}/manifest.json +0 -0
- /package/lib/{cjs/tests → tests}/match.test.d.ts +0 -0
- /package/lib/{cjs/tests → tests}/transform.test.d.ts +0 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CUSTOM_PREFIX_REGEX } from "../constants.js";
|
|
2
|
+
describe("RegExp tests", () => {
|
|
3
|
+
const invalidMatches = [
|
|
4
|
+
"key",
|
|
5
|
+
"__key__",
|
|
6
|
+
"chrome",
|
|
7
|
+
"CHROME",
|
|
8
|
+
"dev",
|
|
9
|
+
"DEV",
|
|
10
|
+
"__dev_",
|
|
11
|
+
"prod",
|
|
12
|
+
"__DEV__",
|
|
13
|
+
"__PROD__",
|
|
14
|
+
"__chrome|typo__",
|
|
15
|
+
];
|
|
16
|
+
test.each(invalidMatches)("should return false for %s", (input) => {
|
|
17
|
+
expect(CUSTOM_PREFIX_REGEX.test(input)).toEqual(false);
|
|
18
|
+
});
|
|
19
|
+
const validMatches = [
|
|
20
|
+
"__dev__",
|
|
21
|
+
"__prod__",
|
|
22
|
+
"__chrome__key",
|
|
23
|
+
"__chrome|firefox__key",
|
|
24
|
+
"__chrome|firefox|opera__key",
|
|
25
|
+
"__chrome|firefox|opera|edge__key",
|
|
26
|
+
"__chrome|chrome__key",
|
|
27
|
+
"__chrome|dev__key",
|
|
28
|
+
"__chrome|prod__key",
|
|
29
|
+
"__chrome|firefox|dev__key",
|
|
30
|
+
"__chrome|firefox|prod__key",
|
|
31
|
+
];
|
|
32
|
+
test.each(validMatches)("should return true for %s", (input) => {
|
|
33
|
+
expect(CUSTOM_PREFIX_REGEX.test(input)).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import manifest from "./manifest.json";
|
|
2
2
|
import chromeOutput from "./chrome.json";
|
|
3
3
|
import firefoxOutput from "./firefox.json";
|
|
4
|
-
import { transformer } from "../transform";
|
|
5
|
-
import { Browser } from "../constants";
|
|
4
|
+
import { transformer } from "../transform.js";
|
|
5
|
+
import { Browser } from "../constants.js";
|
|
6
6
|
describe("transformer tests", () => {
|
|
7
7
|
it("should return empty object", () => {
|
|
8
8
|
expect(transformer({}, "chrome", "development")).toEqual({});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BrowserType } from "./constants";
|
|
1
|
+
import { BrowserType } from "./constants.js";
|
|
2
2
|
export declare const transformer: (manifest: Record<string, string> | string | number | unknown, selectedVendor: BrowserType, nodeEnv: "production" | "development" | string) => any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CUSTOM_PREFIX_REGEX, browserVendors, envVariables, ENVKeys, } from "./constants";
|
|
1
|
+
import { CUSTOM_PREFIX_REGEX, browserVendors, envVariables, ENVKeys, } from "./constants.js";
|
|
2
2
|
export const transformer = (manifest, selectedVendor, nodeEnv) => {
|
|
3
3
|
if (Array.isArray(manifest)) {
|
|
4
4
|
return manifest.map((newManifest) => {
|
|
@@ -7,10 +7,9 @@ export const transformer = (manifest, selectedVendor, nodeEnv) => {
|
|
|
7
7
|
}
|
|
8
8
|
if (typeof manifest === "object" && !!manifest) {
|
|
9
9
|
return Object.entries(manifest).reduce((newManifest, [key, value]) => {
|
|
10
|
-
var _a;
|
|
11
10
|
const vendorMatch = key.match(CUSTOM_PREFIX_REGEX);
|
|
12
11
|
if (!!vendorMatch) {
|
|
13
|
-
const matches =
|
|
12
|
+
const matches = vendorMatch[1]?.split("|") || [];
|
|
14
13
|
const isProd = nodeEnv === "production";
|
|
15
14
|
const hasCurrentVendor = matches.includes(selectedVendor);
|
|
16
15
|
const hasVendorKeys = matches.some((m) => browserVendors.includes(m));
|
package/package.json
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wext-manifest-transformer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Transformer that lets you specify `manifest.json` properties to appear only in specific browsers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/abhijithvijayan/wext-manifest-transformer.git",
|
|
7
|
+
"funding": "https://github.com/sponsors/abhijithvijayan",
|
|
7
8
|
"author": {
|
|
8
9
|
"name": "abhijithvijayan",
|
|
9
10
|
"email": "email@abhijithvijayan.in",
|
|
10
11
|
"url": "https://abhijithvijayan.in"
|
|
11
12
|
},
|
|
12
13
|
"engines": {
|
|
13
|
-
"node": ">=18
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./lib/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
14
20
|
},
|
|
15
|
-
"main": "lib/cjs/index.js",
|
|
16
|
-
"module": "lib/esm/index.js",
|
|
17
|
-
"types": "lib/cjs/index.d.ts",
|
|
18
21
|
"files": [
|
|
19
22
|
"lib"
|
|
20
23
|
],
|
|
21
24
|
"scripts": {
|
|
22
|
-
"dev": "
|
|
23
|
-
"
|
|
24
|
-
"build
|
|
25
|
-
"build:esm": "tsc --module esnext --outDir lib/esm",
|
|
26
|
-
"build": "rimraf lib && npm run build:cjs && npm run build:esm",
|
|
25
|
+
"dev": "npm run build:esm -- --watch",
|
|
26
|
+
"build:esm": "tsc --outDir lib",
|
|
27
|
+
"build": "rimraf lib && npm run build:esm",
|
|
27
28
|
"pack:list": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz",
|
|
28
29
|
"prepublishOnly": "npm run pack:list",
|
|
29
|
-
"
|
|
30
|
-
"test
|
|
30
|
+
"jest": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
31
|
+
"test": "npm run jest",
|
|
32
|
+
"test:watch": "npm run jest -- --watch",
|
|
31
33
|
"lint": "eslint . --ext .ts",
|
|
32
34
|
"lint:fix": "eslint . --ext .ts --fix"
|
|
33
35
|
},
|
|
@@ -58,12 +60,15 @@
|
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@abhijithvijayan/eslint-config": "^2.8.0",
|
|
60
62
|
"@abhijithvijayan/eslint-config-airbnb": "^1.1.0",
|
|
61
|
-
"@abhijithvijayan/tsconfig": "^1.
|
|
63
|
+
"@abhijithvijayan/tsconfig": "^1.5.1",
|
|
62
64
|
"@babel/eslint-parser": "^7.23.9",
|
|
63
|
-
"@
|
|
65
|
+
"@swc/core": "^1.12.7",
|
|
66
|
+
"@swc/jest": "^0.2.38",
|
|
67
|
+
"@types/jest": "^29.5.14",
|
|
64
68
|
"@types/node": "^20.19.1",
|
|
65
69
|
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
66
70
|
"@typescript-eslint/parser": "^6.20.0",
|
|
71
|
+
"cross-env": "^7.0.3",
|
|
67
72
|
"eslint": "^8.56.0",
|
|
68
73
|
"eslint-config-prettier": "^8.10.0",
|
|
69
74
|
"eslint-plugin-import": "^2.29.1",
|
|
@@ -73,11 +78,10 @@
|
|
|
73
78
|
"eslint-plugin-react": "^7.33.2",
|
|
74
79
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
75
80
|
"husky": "^4.3.8",
|
|
76
|
-
"jest": "^
|
|
81
|
+
"jest": "^29.7.0",
|
|
77
82
|
"lint-staged": "^11.0.0",
|
|
78
83
|
"prettier": "^3.2.4",
|
|
79
84
|
"rimraf": "^3.0.2",
|
|
80
|
-
"
|
|
81
|
-
"typescript": "4.9.5"
|
|
85
|
+
"typescript": "5.8.3"
|
|
82
86
|
}
|
|
83
87
|
}
|
package/readme.md
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
<a href="https://www.npmjs.com/package/wext-manifest-transformer">
|
|
5
5
|
<img src="https://img.shields.io/npm/v/wext-manifest-transformer" alt="NPM" />
|
|
6
6
|
</a>
|
|
7
|
-
<a href="https://david-dm.org/abhijithvijayan/wext-manifest-transformer">
|
|
8
|
-
<img src="https://img.shields.io/david/abhijithvijayan/wext-manifest-transformer.svg?colorB=orange" alt="DEPENDENCIES" />
|
|
9
|
-
</a>
|
|
10
7
|
<a href="https://github.com/abhijithvijayan/wext-manifest-transformer/blob/main/license">
|
|
11
8
|
<img src="https://img.shields.io/github/license/abhijithvijayan/wext-manifest-transformer.svg" alt="LICENSE" />
|
|
12
9
|
</a>
|
|
@@ -48,7 +45,7 @@ Checkout [web-extension-starter](https://github.com/abhijithvijayan/web-extensio
|
|
|
48
45
|
|
|
49
46
|
## Installation
|
|
50
47
|
|
|
51
|
-
Ensure you have [Node.js](https://nodejs.org)
|
|
48
|
+
Ensure you have [Node.js](https://nodejs.org) 18 or later installed. Then run the following:
|
|
52
49
|
|
|
53
50
|
```sh
|
|
54
51
|
# via npm
|
package/lib/cjs/constants.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CUSTOM_PREFIX_REGEX = exports.envVariables = exports.browserVendors = exports.Browser = exports.ENVKeys = void 0;
|
|
4
|
-
exports.ENVKeys = {
|
|
5
|
-
DEV: 'dev',
|
|
6
|
-
PROD: 'prod',
|
|
7
|
-
};
|
|
8
|
-
exports.Browser = {
|
|
9
|
-
CHROME: 'chrome',
|
|
10
|
-
FIREFOX: 'firefox',
|
|
11
|
-
EDGE: 'edge',
|
|
12
|
-
BRAVE: 'brave',
|
|
13
|
-
OPERA: 'opera',
|
|
14
|
-
VIVALDI: 'vivaldi',
|
|
15
|
-
ARC: 'arc',
|
|
16
|
-
YANDEX: 'yandex',
|
|
17
|
-
};
|
|
18
|
-
exports.browserVendors = Object.values(exports.Browser);
|
|
19
|
-
exports.envVariables = [exports.ENVKeys.DEV, exports.ENVKeys.PROD];
|
|
20
|
-
exports.CUSTOM_PREFIX_REGEX = new RegExp(`^__((?:(?:${[...exports.browserVendors, ...exports.envVariables].join('|')})\\|?)+)__(.*)`);
|
package/lib/cjs/index.d.ts
DELETED
package/lib/cjs/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENVKeys = exports.CUSTOM_PREFIX_REGEX = exports.Browser = exports.envVariables = exports.browserVendors = void 0;
|
|
4
|
-
const transform_1 = require("./transform");
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
Object.defineProperty(exports, "browserVendors", { enumerable: true, get: function () { return constants_1.browserVendors; } });
|
|
7
|
-
Object.defineProperty(exports, "envVariables", { enumerable: true, get: function () { return constants_1.envVariables; } });
|
|
8
|
-
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return constants_1.Browser; } });
|
|
9
|
-
Object.defineProperty(exports, "CUSTOM_PREFIX_REGEX", { enumerable: true, get: function () { return constants_1.CUSTOM_PREFIX_REGEX; } });
|
|
10
|
-
Object.defineProperty(exports, "ENVKeys", { enumerable: true, get: function () { return constants_1.ENVKeys; } });
|
|
11
|
-
exports.default = transform_1.transformer;
|
|
12
|
-
module.exports = transform_1.transformer;
|
|
13
|
-
module.exports.default = transform_1.transformer;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../constants");
|
|
4
|
-
describe('RegExp tests', () => {
|
|
5
|
-
const invalidMatches = [
|
|
6
|
-
'key',
|
|
7
|
-
'__key__',
|
|
8
|
-
'chrome',
|
|
9
|
-
'CHROME',
|
|
10
|
-
'dev',
|
|
11
|
-
'DEV',
|
|
12
|
-
'__dev_',
|
|
13
|
-
'prod',
|
|
14
|
-
'__DEV__',
|
|
15
|
-
'__PROD__',
|
|
16
|
-
'__chrome|typo__',
|
|
17
|
-
];
|
|
18
|
-
test.each(invalidMatches)('should return false for %s', (input) => {
|
|
19
|
-
expect(constants_1.CUSTOM_PREFIX_REGEX.test(input)).toEqual(false);
|
|
20
|
-
});
|
|
21
|
-
const validMatches = [
|
|
22
|
-
'__dev__',
|
|
23
|
-
'__prod__',
|
|
24
|
-
'__chrome__key',
|
|
25
|
-
'__chrome|firefox__key',
|
|
26
|
-
'__chrome|firefox|opera__key',
|
|
27
|
-
'__chrome|firefox|opera|edge__key',
|
|
28
|
-
'__chrome|chrome__key',
|
|
29
|
-
'__chrome|dev__key',
|
|
30
|
-
'__chrome|prod__key',
|
|
31
|
-
'__chrome|firefox|dev__key',
|
|
32
|
-
'__chrome|firefox|prod__key',
|
|
33
|
-
];
|
|
34
|
-
test.each(validMatches)('should return true for %s', (input) => {
|
|
35
|
-
expect(constants_1.CUSTOM_PREFIX_REGEX.test(input)).toEqual(true);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const manifest_json_1 = __importDefault(require("./manifest.json"));
|
|
7
|
-
const chrome_json_1 = __importDefault(require("./chrome.json"));
|
|
8
|
-
const firefox_json_1 = __importDefault(require("./firefox.json"));
|
|
9
|
-
const transform_1 = require("../transform");
|
|
10
|
-
const constants_1 = require("../constants");
|
|
11
|
-
describe("transformer tests", () => {
|
|
12
|
-
it("should return empty object", () => {
|
|
13
|
-
expect((0, transform_1.transformer)({}, "chrome", "development")).toEqual({});
|
|
14
|
-
});
|
|
15
|
-
it("should return correct JSON for JSON without vendor prefixes", () => {
|
|
16
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
17
|
-
{
|
|
18
|
-
"name": "test",
|
|
19
|
-
"manifest_version": 2
|
|
20
|
-
}
|
|
21
|
-
`), constants_1.Browser.CHROME, "development")).toEqual(JSON.parse(`
|
|
22
|
-
{
|
|
23
|
-
"name": "test",
|
|
24
|
-
"manifest_version": 2
|
|
25
|
-
}
|
|
26
|
-
`));
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe("ENV Tests", () => {
|
|
30
|
-
it("should return correct JSON for development", () => {
|
|
31
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
32
|
-
{
|
|
33
|
-
"__dev__content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'",
|
|
34
|
-
"__prod__content_security_policy": "script-src 'self'; object-src 'self'"
|
|
35
|
-
}
|
|
36
|
-
`), constants_1.Browser.CHROME, "development")).toEqual(JSON.parse(`
|
|
37
|
-
{
|
|
38
|
-
"content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'"
|
|
39
|
-
}
|
|
40
|
-
`));
|
|
41
|
-
});
|
|
42
|
-
it("should return correct JSON for production", () => {
|
|
43
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
44
|
-
{
|
|
45
|
-
"__dev__content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'",
|
|
46
|
-
"__prod__content_security_policy": "script-src 'self'; object-src 'self'"
|
|
47
|
-
}
|
|
48
|
-
`), constants_1.Browser.CHROME, "production")).toEqual(JSON.parse(`
|
|
49
|
-
{
|
|
50
|
-
"content_security_policy": "script-src 'self'; object-src 'self'"
|
|
51
|
-
}
|
|
52
|
-
`));
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe("chrome tests", () => {
|
|
56
|
-
it("should return correct JSON for chrome", () => {
|
|
57
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
58
|
-
{
|
|
59
|
-
"__chrome|opera|edge__manifest_version": 3,
|
|
60
|
-
"__firefox__manifest_version": 2
|
|
61
|
-
}
|
|
62
|
-
`), constants_1.Browser.CHROME, "development")).toEqual(JSON.parse(`
|
|
63
|
-
{
|
|
64
|
-
"manifest_version": 3
|
|
65
|
-
}
|
|
66
|
-
`));
|
|
67
|
-
});
|
|
68
|
-
it("nested vendor keys", () => {
|
|
69
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
70
|
-
{
|
|
71
|
-
"options_ui": {
|
|
72
|
-
"page": "options.html",
|
|
73
|
-
"open_in_tab": true,
|
|
74
|
-
"__chrome__chrome_style": false,
|
|
75
|
-
"__firefox|opera__browser_style": false
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
`), constants_1.Browser.CHROME, "development")).toEqual(JSON.parse(`
|
|
79
|
-
{
|
|
80
|
-
"options_ui": {
|
|
81
|
-
"page": "options.html",
|
|
82
|
-
"open_in_tab": true,
|
|
83
|
-
"chrome_style": false
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
`));
|
|
87
|
-
});
|
|
88
|
-
it("should transform whole JSON", () => {
|
|
89
|
-
expect((0, transform_1.transformer)(manifest_json_1.default, constants_1.Browser.CHROME, "development")).toEqual(chrome_json_1.default);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe("firefox tests", () => {
|
|
93
|
-
it("should return correct JSON for firefox", () => {
|
|
94
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
95
|
-
{
|
|
96
|
-
"__chrome|opera|edge__manifest_version": 3,
|
|
97
|
-
"__firefox__manifest_version": 2
|
|
98
|
-
}
|
|
99
|
-
`), constants_1.Browser.FIREFOX, "development")).toEqual(JSON.parse(`
|
|
100
|
-
{
|
|
101
|
-
"manifest_version": 2
|
|
102
|
-
}
|
|
103
|
-
`));
|
|
104
|
-
});
|
|
105
|
-
it("nested vendor keys", () => {
|
|
106
|
-
expect((0, transform_1.transformer)(JSON.parse(`
|
|
107
|
-
{
|
|
108
|
-
"options_ui": {
|
|
109
|
-
"page": "options.html",
|
|
110
|
-
"open_in_tab": true,
|
|
111
|
-
"__chrome__chrome_style": false,
|
|
112
|
-
"__firefox|opera__browser_style": false
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
`), constants_1.Browser.FIREFOX, "development")).toEqual(JSON.parse(`
|
|
116
|
-
{
|
|
117
|
-
"options_ui": {
|
|
118
|
-
"page": "options.html",
|
|
119
|
-
"open_in_tab": true,
|
|
120
|
-
"browser_style": false
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
`));
|
|
124
|
-
});
|
|
125
|
-
it("should transform whole JSON", () => {
|
|
126
|
-
expect((0, transform_1.transformer)(manifest_json_1.default, constants_1.Browser.FIREFOX, "development")).toEqual(firefox_json_1.default);
|
|
127
|
-
});
|
|
128
|
-
});
|
package/lib/cjs/transform.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformer = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const transformer = (manifest, selectedVendor, nodeEnv) => {
|
|
6
|
-
if (Array.isArray(manifest)) {
|
|
7
|
-
return manifest.map((newManifest) => {
|
|
8
|
-
return (0, exports.transformer)(newManifest, selectedVendor, nodeEnv);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (typeof manifest === "object" && !!manifest) {
|
|
12
|
-
return Object.entries(manifest).reduce((newManifest, [key, value]) => {
|
|
13
|
-
var _a;
|
|
14
|
-
const vendorMatch = key.match(constants_1.CUSTOM_PREFIX_REGEX);
|
|
15
|
-
if (!!vendorMatch) {
|
|
16
|
-
const matches = ((_a = vendorMatch[1]) === null || _a === void 0 ? void 0 : _a.split("|")) || [];
|
|
17
|
-
const isProd = nodeEnv === "production";
|
|
18
|
-
const hasCurrentVendor = matches.includes(selectedVendor);
|
|
19
|
-
const hasVendorKeys = matches.some((m) => constants_1.browserVendors.includes(m));
|
|
20
|
-
const hasEnvKey = matches.some((m) => constants_1.envVariables.includes(m));
|
|
21
|
-
const hasCurrentEnvKey = hasEnvKey &&
|
|
22
|
-
((isProd && matches.includes(constants_1.ENVKeys.PROD)) ||
|
|
23
|
-
(!isProd && matches.includes(constants_1.ENVKeys.DEV)));
|
|
24
|
-
if ((hasCurrentVendor && hasCurrentEnvKey) ||
|
|
25
|
-
(!hasVendorKeys && hasCurrentEnvKey) ||
|
|
26
|
-
(!hasEnvKey && hasCurrentVendor)) {
|
|
27
|
-
newManifest[vendorMatch[2]] =
|
|
28
|
-
(0, exports.transformer)(value, selectedVendor, nodeEnv);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
newManifest[key] = (0, exports.transformer)(value, selectedVendor, nodeEnv);
|
|
33
|
-
}
|
|
34
|
-
return newManifest;
|
|
35
|
-
}, {});
|
|
36
|
-
}
|
|
37
|
-
return manifest;
|
|
38
|
-
};
|
|
39
|
-
exports.transformer = transformer;
|
package/lib/esm/constants.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const ENVKeys: {
|
|
2
|
-
readonly DEV: "dev";
|
|
3
|
-
readonly PROD: "prod";
|
|
4
|
-
};
|
|
5
|
-
export declare const Browser: {
|
|
6
|
-
readonly CHROME: "chrome";
|
|
7
|
-
readonly FIREFOX: "firefox";
|
|
8
|
-
readonly EDGE: "edge";
|
|
9
|
-
readonly BRAVE: "brave";
|
|
10
|
-
readonly OPERA: "opera";
|
|
11
|
-
readonly VIVALDI: "vivaldi";
|
|
12
|
-
readonly ARC: "arc";
|
|
13
|
-
readonly YANDEX: "yandex";
|
|
14
|
-
};
|
|
15
|
-
export type BrowserType = (typeof Browser)[keyof typeof Browser];
|
|
16
|
-
export declare const browserVendors: BrowserType[];
|
|
17
|
-
export declare const envVariables: string[];
|
|
18
|
-
export declare const CUSTOM_PREFIX_REGEX: RegExp;
|
package/lib/esm/index.d.ts
DELETED
package/lib/esm/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 3,
|
|
3
|
-
"name": "web.site",
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"icons": {
|
|
6
|
-
"16": "assets/icons/favicon-16.png",
|
|
7
|
-
"32": "assets/icons/favicon-32.png",
|
|
8
|
-
"48": "assets/icons/favicon-48.png",
|
|
9
|
-
"128": "assets/icons/favicon-128.png"
|
|
10
|
-
},
|
|
11
|
-
"description": "web.site",
|
|
12
|
-
"homepage_url": "https://web.site",
|
|
13
|
-
"short_name": "web.site",
|
|
14
|
-
"host_permissions": [
|
|
15
|
-
"*://*.web.site/*"
|
|
16
|
-
],
|
|
17
|
-
"content_security_policy": {
|
|
18
|
-
"extension_pages": "script-src 'self' http://localhost:8097; object-src 'self'"
|
|
19
|
-
},
|
|
20
|
-
"author": "abhijithvijayan",
|
|
21
|
-
"minimum_chrome_version": "88",
|
|
22
|
-
"background": {
|
|
23
|
-
"scripts": [
|
|
24
|
-
"js/background.bundle.js"
|
|
25
|
-
],
|
|
26
|
-
"persistent": false
|
|
27
|
-
},
|
|
28
|
-
"content_scripts": [
|
|
29
|
-
{
|
|
30
|
-
"matches": [
|
|
31
|
-
"http://web.site/*",
|
|
32
|
-
"https://web.site/*"
|
|
33
|
-
],
|
|
34
|
-
"js": [
|
|
35
|
-
"js/contentScript.bundle.js"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 2,
|
|
3
|
-
"name": "web.site",
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"icons": {
|
|
6
|
-
"16": "assets/icons/favicon-16.png",
|
|
7
|
-
"32": "assets/icons/favicon-32.png",
|
|
8
|
-
"48": "assets/icons/favicon-48.png",
|
|
9
|
-
"128": "assets/icons/favicon-128.png"
|
|
10
|
-
},
|
|
11
|
-
"description": "web.site",
|
|
12
|
-
"homepage_url": "https://web.site",
|
|
13
|
-
"short_name": "web.site",
|
|
14
|
-
"host_permissions": [
|
|
15
|
-
"*://*.web.site/*"
|
|
16
|
-
],
|
|
17
|
-
"content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'",
|
|
18
|
-
"author": "abhijithvijayan",
|
|
19
|
-
"applications": {
|
|
20
|
-
"gecko": {
|
|
21
|
-
"id": "{754FB1AD-CC3B-4856-B6A0-7786F8CA9D17}",
|
|
22
|
-
"strict_min_version": "52.0"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"background": {
|
|
26
|
-
"scripts": [
|
|
27
|
-
"js/background.bundle.js"
|
|
28
|
-
]
|
|
29
|
-
},
|
|
30
|
-
"content_scripts": [
|
|
31
|
-
{
|
|
32
|
-
"matches": [
|
|
33
|
-
"http://web.site/*",
|
|
34
|
-
"https://web.site/*"
|
|
35
|
-
],
|
|
36
|
-
"js": [
|
|
37
|
-
"js/contentScript.bundle.js"
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"__chrome|opera|edge__manifest_version": 3,
|
|
3
|
-
"__firefox__manifest_version": 2,
|
|
4
|
-
"name": "web.site",
|
|
5
|
-
"version": "0.0.0",
|
|
6
|
-
"icons": {
|
|
7
|
-
"16": "assets/icons/favicon-16.png",
|
|
8
|
-
"32": "assets/icons/favicon-32.png",
|
|
9
|
-
"48": "assets/icons/favicon-48.png",
|
|
10
|
-
"128": "assets/icons/favicon-128.png"
|
|
11
|
-
},
|
|
12
|
-
"description": "web.site",
|
|
13
|
-
"homepage_url": "https://web.site",
|
|
14
|
-
"short_name": "web.site",
|
|
15
|
-
"__dev__host_permissions": [
|
|
16
|
-
"*://*.web.site/*"
|
|
17
|
-
],
|
|
18
|
-
"__prod__host_permissions": [
|
|
19
|
-
"https://*.web.site/*"
|
|
20
|
-
],
|
|
21
|
-
"__chrome|opera|edge|dev__content_security_policy": {
|
|
22
|
-
"extension_pages": "script-src 'self' http://localhost:8097; object-src 'self'"
|
|
23
|
-
},
|
|
24
|
-
"__chrome|opera|edge|prod__content_security_policy": {
|
|
25
|
-
"extension_pages": "script-src 'self'; object-src 'self'"
|
|
26
|
-
},
|
|
27
|
-
"__firefox|dev__content_security_policy": "script-src 'self' http://localhost:8097; object-src 'self'",
|
|
28
|
-
"__firefox|prod__content_security_policy": "script-src 'self'; object-src 'self'",
|
|
29
|
-
"__chrome|firefox__author": "abhijithvijayan",
|
|
30
|
-
"__opera__developer": {
|
|
31
|
-
"name": "abhijithvijayan"
|
|
32
|
-
},
|
|
33
|
-
"__firefox__applications": {
|
|
34
|
-
"gecko": {
|
|
35
|
-
"id": "{754FB1AD-CC3B-4856-B6A0-7786F8CA9D17}",
|
|
36
|
-
"strict_min_version": "52.0"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"__chrome__minimum_chrome_version": "88",
|
|
40
|
-
"__opera__minimum_opera_version": "74",
|
|
41
|
-
"background": {
|
|
42
|
-
"scripts": [
|
|
43
|
-
"js/background.bundle.js"
|
|
44
|
-
],
|
|
45
|
-
"__chrome|opera__persistent": false
|
|
46
|
-
},
|
|
47
|
-
"content_scripts": [{
|
|
48
|
-
"matches": [
|
|
49
|
-
"http://web.site/*",
|
|
50
|
-
"https://web.site/*"
|
|
51
|
-
],
|
|
52
|
-
"js": [
|
|
53
|
-
"js/contentScript.bundle.js"
|
|
54
|
-
]
|
|
55
|
-
}]
|
|
56
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { CUSTOM_PREFIX_REGEX } from '../constants';
|
|
2
|
-
describe('RegExp tests', () => {
|
|
3
|
-
const invalidMatches = [
|
|
4
|
-
'key',
|
|
5
|
-
'__key__',
|
|
6
|
-
'chrome',
|
|
7
|
-
'CHROME',
|
|
8
|
-
'dev',
|
|
9
|
-
'DEV',
|
|
10
|
-
'__dev_',
|
|
11
|
-
'prod',
|
|
12
|
-
'__DEV__',
|
|
13
|
-
'__PROD__',
|
|
14
|
-
'__chrome|typo__',
|
|
15
|
-
];
|
|
16
|
-
test.each(invalidMatches)('should return false for %s', (input) => {
|
|
17
|
-
expect(CUSTOM_PREFIX_REGEX.test(input)).toEqual(false);
|
|
18
|
-
});
|
|
19
|
-
const validMatches = [
|
|
20
|
-
'__dev__',
|
|
21
|
-
'__prod__',
|
|
22
|
-
'__chrome__key',
|
|
23
|
-
'__chrome|firefox__key',
|
|
24
|
-
'__chrome|firefox|opera__key',
|
|
25
|
-
'__chrome|firefox|opera|edge__key',
|
|
26
|
-
'__chrome|chrome__key',
|
|
27
|
-
'__chrome|dev__key',
|
|
28
|
-
'__chrome|prod__key',
|
|
29
|
-
'__chrome|firefox|dev__key',
|
|
30
|
-
'__chrome|firefox|prod__key',
|
|
31
|
-
];
|
|
32
|
-
test.each(validMatches)('should return true for %s', (input) => {
|
|
33
|
-
expect(CUSTOM_PREFIX_REGEX.test(input)).toEqual(true);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/esm/transform.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|