wext-manifest-transformer 1.2.3 → 1.3.1
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/constants.js +17 -0
- 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 -2
- package/package.json +25 -32
- 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 -38
- package/lib/esm/constants.d.ts +0 -18
- package/lib/esm/constants.js +0 -17
- 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/{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/constants.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const ENVKeys = {
|
|
2
|
+
DEV: "dev",
|
|
3
|
+
PROD: "prod",
|
|
4
|
+
};
|
|
5
|
+
export const Browser = {
|
|
6
|
+
CHROME: "chrome",
|
|
7
|
+
FIREFOX: "firefox",
|
|
8
|
+
EDGE: "edge",
|
|
9
|
+
BRAVE: "brave",
|
|
10
|
+
OPERA: "opera",
|
|
11
|
+
VIVALDI: "vivaldi",
|
|
12
|
+
ARC: "arc",
|
|
13
|
+
YANDEX: "yandex",
|
|
14
|
+
};
|
|
15
|
+
export const browserVendors = Object.values(Browser);
|
|
16
|
+
export const envVariables = [ENVKeys.DEV, ENVKeys.PROD];
|
|
17
|
+
export const CUSTOM_PREFIX_REGEX = new RegExp(`^__((?:(?:${[...browserVendors, ...envVariables].join("|")})\\|?)+)__(.*)`);
|
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) => {
|
|
@@ -8,7 +8,7 @@ export const transformer = (manifest, selectedVendor, nodeEnv) => {
|
|
|
8
8
|
if (typeof manifest === "object" && !!manifest) {
|
|
9
9
|
return Object.entries(manifest).reduce((newManifest, [key, value]) => {
|
|
10
10
|
const vendorMatch = key.match(CUSTOM_PREFIX_REGEX);
|
|
11
|
-
if (
|
|
11
|
+
if (vendorMatch) {
|
|
12
12
|
const matches = vendorMatch[1]?.split("|") || [];
|
|
13
13
|
const isProd = nodeEnv === "production";
|
|
14
14
|
const hasCurrentVendor = matches.includes(selectedVendor);
|
package/package.json
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wext-manifest-transformer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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": ">=
|
|
14
|
+
"node": ">=20"
|
|
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": "tsc --
|
|
23
|
-
"
|
|
24
|
-
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
|
|
25
|
-
"build:esm": "tsc --module esnext --outDir lib/esm",
|
|
26
|
-
"build": "rimraf lib && npm run build:cjs && npm run build:esm",
|
|
25
|
+
"dev": "tsc --outDir lib --watch",
|
|
26
|
+
"build": "rimraf lib && tsc --outDir lib",
|
|
27
27
|
"pack:list": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz",
|
|
28
|
-
"prepublishOnly": "npm run pack:list",
|
|
29
28
|
"test": "jest",
|
|
30
29
|
"test:watch": "jest --watch",
|
|
31
|
-
"lint": "eslint .
|
|
32
|
-
"lint:fix": "eslint . --
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"lint:fix": "eslint . --fix"
|
|
33
32
|
},
|
|
34
33
|
"husky": {
|
|
35
34
|
"hooks": {
|
|
@@ -38,7 +37,7 @@
|
|
|
38
37
|
},
|
|
39
38
|
"lint-staged": {
|
|
40
39
|
"*.ts": [
|
|
41
|
-
"eslint
|
|
40
|
+
"eslint"
|
|
42
41
|
]
|
|
43
42
|
},
|
|
44
43
|
"keywords": [
|
|
@@ -56,28 +55,22 @@
|
|
|
56
55
|
"yandex"
|
|
57
56
|
],
|
|
58
57
|
"devDependencies": {
|
|
59
|
-
"@abhijithvijayan/
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"@types/jest": "^26.0.23",
|
|
58
|
+
"@abhijithvijayan/tsconfig": "^1.5.1",
|
|
59
|
+
"@swc/core": "^1.12.7",
|
|
60
|
+
"@swc/jest": "^0.2.38",
|
|
61
|
+
"@types/jest": "^29.5.14",
|
|
64
62
|
"@types/node": "^20.19.1",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"eslint": "^
|
|
68
|
-
"eslint-config-prettier": "^8.10.0",
|
|
69
|
-
"eslint-plugin-import": "^2.29.1",
|
|
70
|
-
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
71
|
-
"eslint-plugin-node": "^11.1.0",
|
|
63
|
+
"cross-env": "^7.0.3",
|
|
64
|
+
"eslint": "^9.0.0",
|
|
65
|
+
"eslint-config-prettier": "^10.0.0",
|
|
72
66
|
"eslint-plugin-prettier": "^5.1.3",
|
|
73
|
-
"
|
|
74
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
67
|
+
"globals": "^16.0.0",
|
|
75
68
|
"husky": "^4.3.8",
|
|
76
|
-
"jest": "^
|
|
69
|
+
"jest": "^29.7.0",
|
|
77
70
|
"lint-staged": "^11.0.0",
|
|
78
71
|
"prettier": "^3.2.4",
|
|
79
72
|
"rimraf": "^3.0.2",
|
|
80
|
-
"
|
|
81
|
-
"typescript": "
|
|
73
|
+
"typescript": "5.8.3",
|
|
74
|
+
"typescript-eslint": "^8.0.0"
|
|
82
75
|
}
|
|
83
|
-
}
|
|
76
|
+
}
|
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,38 +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
|
-
const vendorMatch = key.match(constants_1.CUSTOM_PREFIX_REGEX);
|
|
14
|
-
if (!!vendorMatch) {
|
|
15
|
-
const matches = vendorMatch[1]?.split("|") || [];
|
|
16
|
-
const isProd = nodeEnv === "production";
|
|
17
|
-
const hasCurrentVendor = matches.includes(selectedVendor);
|
|
18
|
-
const hasVendorKeys = matches.some((m) => constants_1.browserVendors.includes(m));
|
|
19
|
-
const hasEnvKey = matches.some((m) => constants_1.envVariables.includes(m));
|
|
20
|
-
const hasCurrentEnvKey = hasEnvKey &&
|
|
21
|
-
((isProd && matches.includes(constants_1.ENVKeys.PROD)) ||
|
|
22
|
-
(!isProd && matches.includes(constants_1.ENVKeys.DEV)));
|
|
23
|
-
if ((hasCurrentVendor && hasCurrentEnvKey) ||
|
|
24
|
-
(!hasVendorKeys && hasCurrentEnvKey) ||
|
|
25
|
-
(!hasEnvKey && hasCurrentVendor)) {
|
|
26
|
-
newManifest[vendorMatch[2]] =
|
|
27
|
-
(0, exports.transformer)(value, selectedVendor, nodeEnv);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
newManifest[key] = (0, exports.transformer)(value, selectedVendor, nodeEnv);
|
|
32
|
-
}
|
|
33
|
-
return newManifest;
|
|
34
|
-
}, {});
|
|
35
|
-
}
|
|
36
|
-
return manifest;
|
|
37
|
-
};
|
|
38
|
-
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/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const ENVKeys = {
|
|
2
|
-
DEV: 'dev',
|
|
3
|
-
PROD: 'prod',
|
|
4
|
-
};
|
|
5
|
-
export const Browser = {
|
|
6
|
-
CHROME: 'chrome',
|
|
7
|
-
FIREFOX: 'firefox',
|
|
8
|
-
EDGE: 'edge',
|
|
9
|
-
BRAVE: 'brave',
|
|
10
|
-
OPERA: 'opera',
|
|
11
|
-
VIVALDI: 'vivaldi',
|
|
12
|
-
ARC: 'arc',
|
|
13
|
-
YANDEX: 'yandex',
|
|
14
|
-
};
|
|
15
|
-
export const browserVendors = Object.values(Browser);
|
|
16
|
-
export const envVariables = [ENVKeys.DEV, ENVKeys.PROD];
|
|
17
|
-
export const CUSTOM_PREFIX_REGEX = new RegExp(`^__((?:(?:${[...browserVendors, ...envVariables].join('|')})\\|?)+)__(.*)`);
|
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
|