From b447b52b681295ca7837f91d7aeb82752f6b3714 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sat, 24 Jun 2023 13:20:55 +0100 Subject: [PATCH 1/8] poc --- .gitignore | 1 + package-lock.json | 499 --------------------------------- package.json | 6 - scripts/inject.js | 14 +- scripts/utils/build.js | 205 ++++++-------- unit-test/platform-features.js | 4 +- 6 files changed, 96 insertions(+), 633 deletions(-) diff --git a/.gitignore b/.gitignore index c64f37245..e74674457 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ .env .build/ build/ +build_bak/ docs/ test-results/ playwright-report/ diff --git a/package-lock.json b/package-lock.json index 5459d9815..c9e15c53c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,9 +20,6 @@ "devDependencies": { "@canvas/image-data": "^1.0.0", "@fingerprintjs/fingerprintjs": "^4.1.0", - "@rollup/plugin-commonjs": "^25.0.4", - "@rollup/plugin-node-resolve": "^15.2.1", - "@rollup/plugin-replace": "^5.0.2", "@types/chrome": "^0.0.246", "@types/jasmine": "^4.3.1", "@typescript-eslint/eslint-plugin": "^6.7.3", @@ -37,9 +34,6 @@ "json-schema-to-typescript": "^13.1.1", "minimist": "^1.2.8", "puppeteer": "^21.3.5", - "rollup": "^3.28.0", - "rollup-plugin-import-css": "^3.3.1", - "rollup-plugin-svg-import": "^2.1.0", "typedoc": "^0.25.1", "typescript": "^5.2.2" } @@ -709,12 +703,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, "node_modules/@jsdevtools/ono": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", @@ -792,169 +780,6 @@ "node": ">=16.3.0" } }, - "node_modules/@rollup/plugin-commonjs": { - "version": "25.0.4", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.4.tgz", - "integrity": "sha512-L92Vz9WUZXDnlQQl3EwbypJR4+DM2EbsO+/KOcEkP4Mc6Ct453EeDB2uH9lgRwj4w5yflgNpq9pHOiY8aoUXBQ==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "commondir": "^1.0.1", - "estree-walker": "^2.0.2", - "glob": "^8.0.3", - "is-reference": "1.2.1", - "magic-string": "^0.27.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.68.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/glob": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", - "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/magic-string": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", - "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", - "dev": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.13" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", - "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@rollup/plugin-node-resolve": { - "version": "15.2.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.1.tgz", - "integrity": "sha512-nsbUg588+GDSu8/NS8T4UAshO6xeaOfINNuXeVHcKV02LJtoRaM1SiOacClw4kws1SFiNhdLGxlbMY9ga/zs/w==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "@types/resolve": "1.20.2", - "deepmerge": "^4.2.2", - "is-builtin-module": "^3.2.1", - "is-module": "^1.0.0", - "resolve": "^1.22.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.78.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/plugin-replace": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz", - "integrity": "sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "magic-string": "^0.27.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/plugin-replace/node_modules/magic-string": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", - "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", - "dev": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.13" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", - "dev": true, - "dependencies": { - "@types/estree": "^1.0.0", - "estree-walker": "^2.0.2", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, - "node_modules/@rollup/pluginutils/node_modules/@types/estree": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", - "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==", - "dev": true - }, "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", @@ -971,12 +796,6 @@ "@types/har-format": "*" } }, - "node_modules/@types/estree": { - "version": "0.0.39", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true - }, "node_modules/@types/filesystem": { "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", @@ -1050,12 +869,6 @@ "integrity": "sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==", "dev": true }, - "node_modules/@types/resolve": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", - "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", - "dev": true - }, "node_modules/@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", @@ -1807,18 +1620,6 @@ "node": "*" } }, - "node_modules/builtin-modules": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", - "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", - "dev": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/builtins": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.1.tgz", @@ -1934,12 +1735,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", - "dev": true - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2084,15 +1879,6 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "node_modules/deepmerge": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/define-properties": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", @@ -3051,12 +2837,6 @@ "node": ">=4.0" } }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true - }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -3895,21 +3675,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-builtin-module": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", - "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", - "dev": true, - "dependencies": { - "builtin-modules": "^3.3.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -3979,12 +3744,6 @@ "node": ">=0.10.0" } }, - "node_modules/is-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", - "dev": true - }, "node_modules/is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -4036,15 +3795,6 @@ "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==", "dev": true }, - "node_modules/is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", - "dev": true, - "dependencies": { - "@types/estree": "*" - } - }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -5057,52 +4807,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/rollup": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.0.tgz", - "integrity": "sha512-d7zhvo1OUY2SXSM6pfNjgD5+d0Nz87CUp4mt8l/GgVP3oBsPwzNvSzyu1me6BSG9JIgWNTVcafIXBIyM8yQ3yw==", - "dev": true, - "bin": { - "rollup": "dist/bin/rollup" - }, - "engines": { - "node": ">=14.18.0", - "npm": ">=8.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" - } - }, - "node_modules/rollup-plugin-import-css": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/rollup-plugin-import-css/-/rollup-plugin-import-css-3.3.1.tgz", - "integrity": "sha512-/v/OjjDPhhhbua5w4VzHRTtqfyyG950jJSObtM9os5ELGgaHiolNOvpZNk2KeTSFMuhdrXirGXM64bluHgwySA==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.2" - }, - "engines": { - "node": ">=16" - }, - "peerDependencies": { - "rollup": "^2.x.x || ^3.x.x" - } - }, - "node_modules/rollup-plugin-svg-import": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-svg-import/-/rollup-plugin-svg-import-2.1.0.tgz", - "integrity": "sha512-uHTYG/shURfBvX2wieST5898uvKBnhE6XuhFDGlNzr0HSMNGEapo/oT9u7Xogr4bgpAvhL1hsdZGdWXA1X1N1g==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^5.0.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.0.0||^3.0.0" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6445,12 +6149,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, "@jsdevtools/ono": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", @@ -6507,116 +6205,6 @@ "yargs": "17.7.1" } }, - "@rollup/plugin-commonjs": { - "version": "25.0.4", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.4.tgz", - "integrity": "sha512-L92Vz9WUZXDnlQQl3EwbypJR4+DM2EbsO+/KOcEkP4Mc6Ct453EeDB2uH9lgRwj4w5yflgNpq9pHOiY8aoUXBQ==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^5.0.1", - "commondir": "^1.0.1", - "estree-walker": "^2.0.2", - "glob": "^8.0.3", - "is-reference": "1.2.1", - "magic-string": "^0.27.0" - }, - "dependencies": { - "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0" - } - }, - "glob": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", - "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - } - }, - "magic-string": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", - "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", - "dev": true, - "requires": { - "@jridgewell/sourcemap-codec": "^1.4.13" - } - }, - "minimatch": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz", - "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==", - "dev": true, - "requires": { - "brace-expansion": "^2.0.1" - } - } - } - }, - "@rollup/plugin-node-resolve": { - "version": "15.2.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.1.tgz", - "integrity": "sha512-nsbUg588+GDSu8/NS8T4UAshO6xeaOfINNuXeVHcKV02LJtoRaM1SiOacClw4kws1SFiNhdLGxlbMY9ga/zs/w==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^5.0.1", - "@types/resolve": "1.20.2", - "deepmerge": "^4.2.2", - "is-builtin-module": "^3.2.1", - "is-module": "^1.0.0", - "resolve": "^1.22.1" - } - }, - "@rollup/plugin-replace": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz", - "integrity": "sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^5.0.1", - "magic-string": "^0.27.0" - }, - "dependencies": { - "magic-string": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", - "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", - "dev": true, - "requires": { - "@jridgewell/sourcemap-codec": "^1.4.13" - } - } - } - }, - "@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", - "dev": true, - "requires": { - "@types/estree": "^1.0.0", - "estree-walker": "^2.0.2", - "picomatch": "^2.3.1" - }, - "dependencies": { - "@types/estree": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", - "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==", - "dev": true - } - } - }, "@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", @@ -6633,12 +6221,6 @@ "@types/har-format": "*" } }, - "@types/estree": { - "version": "0.0.39", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true - }, "@types/filesystem": { "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", @@ -6712,12 +6294,6 @@ "integrity": "sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==", "dev": true }, - "@types/resolve": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", - "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", - "dev": true - }, "@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", @@ -7196,12 +6772,6 @@ "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", "dev": true }, - "builtin-modules": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", - "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", - "dev": true - }, "builtins": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.1.tgz", @@ -7293,12 +6863,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", - "dev": true - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -7403,12 +6967,6 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, - "deepmerge": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", - "dev": true - }, "define-properties": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", @@ -8103,12 +7661,6 @@ "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true }, - "estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true - }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -8712,15 +8264,6 @@ "has-tostringtag": "^1.0.0" } }, - "is-builtin-module": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", - "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", - "dev": true, - "requires": { - "builtin-modules": "^3.3.0" - } - }, "is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -8766,12 +8309,6 @@ "is-extglob": "^2.1.1" } }, - "is-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", - "dev": true - }, "is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -8805,15 +8342,6 @@ "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==", "dev": true }, - "is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", - "dev": true, - "requires": { - "@types/estree": "*" - } - }, "is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -9556,33 +9084,6 @@ "glob": "^7.1.3" } }, - "rollup": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.0.tgz", - "integrity": "sha512-d7zhvo1OUY2SXSM6pfNjgD5+d0Nz87CUp4mt8l/GgVP3oBsPwzNvSzyu1me6BSG9JIgWNTVcafIXBIyM8yQ3yw==", - "dev": true, - "requires": { - "fsevents": "~2.3.2" - } - }, - "rollup-plugin-import-css": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/rollup-plugin-import-css/-/rollup-plugin-import-css-3.3.1.tgz", - "integrity": "sha512-/v/OjjDPhhhbua5w4VzHRTtqfyyG950jJSObtM9os5ELGgaHiolNOvpZNk2KeTSFMuhdrXirGXM64bluHgwySA==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^5.0.2" - } - }, - "rollup-plugin-svg-import": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-svg-import/-/rollup-plugin-svg-import-2.1.0.tgz", - "integrity": "sha512-uHTYG/shURfBvX2wieST5898uvKBnhE6XuhFDGlNzr0HSMNGEapo/oT9u7Xogr4bgpAvhL1hsdZGdWXA1X1N1g==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^5.0.1" - } - }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/package.json b/package.json index 54294ac15..c9a1af8df 100644 --- a/package.json +++ b/package.json @@ -60,9 +60,6 @@ "devDependencies": { "@canvas/image-data": "^1.0.0", "@fingerprintjs/fingerprintjs": "^4.1.0", - "@rollup/plugin-commonjs": "^25.0.4", - "@rollup/plugin-node-resolve": "^15.2.1", - "@rollup/plugin-replace": "^5.0.2", "@types/chrome": "^0.0.246", "@types/jasmine": "^4.3.1", "@typescript-eslint/eslint-plugin": "^6.7.3", @@ -77,9 +74,6 @@ "json-schema-to-typescript": "^13.1.1", "minimist": "^1.2.8", "puppeteer": "^21.3.5", - "rollup": "^3.28.0", - "rollup-plugin-import-css": "^3.3.1", - "rollup-plugin-svg-import": "^2.1.0", "typedoc": "^0.25.1", "typescript": "^5.2.2" } diff --git a/scripts/inject.js b/scripts/inject.js index 7e8c1ba75..cfe3df4fa 100644 --- a/scripts/inject.js +++ b/scripts/inject.js @@ -1,4 +1,4 @@ -import { postProcess, rollupScript } from './utils/build.js' +import { bundle } from './utils/build.js' import { parseArgs, write } from './script-utils.js' import { camelcase } from '../src/utils.js' @@ -9,7 +9,6 @@ const contentScopeName = 'contentScopeFeatures' * @typedef Build * @property {string} input * @property {string[]} output - * @property {boolean} [postProcess] - optional value to post-process an output file * * @typedef {Record, Build>} BuildManifest */ @@ -22,7 +21,6 @@ const builds = { }, apple: { input: 'inject/apple.js', - postProcess: true, output: ['Sources/ContentScopeScripts/dist/contentScope.js'] }, 'apple-isolated': { @@ -58,7 +56,7 @@ const builds = { async function initOther (injectScriptPath, platformName) { const supportsMozProxies = platformName === 'firefox' const identName = `inject${camelcase(platformName)}` - const injectScript = await rollupScript({ + const injectScript = await bundle({ scriptPath: injectScriptPath, name: identName, supportsMozProxies, @@ -74,8 +72,8 @@ async function initOther (injectScriptPath, platformName) { */ async function initChrome (entry, platformName) { const replaceString = '/* global contentScopeFeatures */' - const injectScript = await rollupScript({ scriptPath: entry, platform: platformName }) - const contentScope = await rollupScript({ + const injectScript = await bundle({ scriptPath: entry, platform: platformName }) + const contentScope = await bundle({ scriptPath: contentScopePath, name: contentScopeName, platform: platformName @@ -102,10 +100,6 @@ async function init () { output = await initChrome(build.input, args.platform) } else { output = await initOther(build.input, args.platform) - if (build.postProcess) { - const processResult = await postProcess(output) - output = processResult.code - } } // bundle and write the output diff --git a/scripts/utils/build.js b/scripts/utils/build.js index d7a213daf..8538dbaf9 100644 --- a/scripts/utils/build.js +++ b/scripts/utils/build.js @@ -1,12 +1,9 @@ -import * as rollup from 'rollup' -import * as esbuild from 'esbuild' -import commonjs from '@rollup/plugin-commonjs' -import replace from '@rollup/plugin-replace' -import resolve from '@rollup/plugin-node-resolve' -import css from 'rollup-plugin-import-css' -import svg from 'rollup-plugin-svg-import' import { runtimeInjected, platformSupport } from '../../src/features.js' import { readFileSync } from 'fs' +import { cwd } from '../script-utils.js' +import { join } from 'path' +import * as esbuild from 'esbuild' +const ROOT = join(cwd(import.meta.url), '..', '..') /** * This is a helper function to require all files in a directory @@ -18,7 +15,7 @@ async function getAllFeatureCode (pathName, platform) { for (const featureName of runtimeInjected) { const fileName = getFileName(featureName) const fullPath = `${pathName}/${fileName}.js` - const code = await rollupScript({ + const code = await bundle({ scriptPath: fullPath, name: featureName, supportsMozProxies: false, @@ -32,42 +29,26 @@ async function getAllFeatureCode (pathName, platform) { /** * Allows importing of all features into a custom runtimeInjects export * @param {string} platform - * @returns {import('rollup').Plugin} + * @returns {import('esbuild').Plugin} */ function runtimeInjections (platform) { const customId = 'ddg:runtimeInjects' return { name: customId, - resolveId (id) { - if (id === customId) { - return id - } - return null - }, - async load (id) { - if (id === customId) { + setup (build) { + build.onResolve({ filter: new RegExp(customId) }, async (args) => { + return { + path: args.path, + namespace: customId + } + }) + build.onLoad({ filter: /.*/, namespace: customId }, async () => { const code = await getAllFeatureCode('src/features', platform) - return `export default ${JSON.stringify(code, undefined, 4)}` - } - return null - } - } -} - -function prefixPlugin (prefixMessage) { - return { - name: 'prefix-plugin', - renderChunk (code) { - return `${prefixMessage}\n${code}` - } - } -} - -function suffixPlugin (suffixMessage) { - return { - name: 'suffix-plugin', - renderChunk (code) { - return `${code}\n${suffixMessage}` + return { + loader: 'js', + contents: `export default ${JSON.stringify(code, undefined, 4)}` + } + }) } } } @@ -83,7 +64,7 @@ const prefixMessage = '/*! © DuckDuckGo ContentScopeScripts protections https:/ * @param {boolean} [params.supportsMozProxies] * @return {Promise} */ -export async function rollupScript (params) { +export async function bundle (params) { const { scriptPath, platform, @@ -99,50 +80,47 @@ export async function rollupScript (params) { const trackerLookupData = readFileSync('./build/tracker-lookup.json', 'utf8') trackerLookup = trackerLookupData } - const suffixMessage = `/*# sourceURL=duckduckgo-privacy-protection.js?scope=${name} */` + const suffixMessage = platform === 'firefox' ? `/*# sourceURL=duckduckgo-privacy-protection.js?scope=${name} */` : '' + const loadFeaturesPlugin = loadFeatures(platform, featureNames) + const runtimeInjectionsPlugin = runtimeInjections(platform) // The code is using a global, that we define here which means once tree shaken we get a browser specific output. const mozProxies = supportsMozProxies - const plugins = [ - css(), - svg({ - stringify: true - }), - loadFeatures(platform, featureNames), - runtimeInjections(platform), - resolve(), - commonjs(), - replace({ - preventAssignment: true, - values: { - // @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f - mozProxies, - 'import.meta.injectName': JSON.stringify(platform), - // To be replaced by the extension, but prevents tree shaking - 'import.meta.trackerLookup': trackerLookup - } - }), - prefixPlugin(prefixMessage) - ] - if (platform === 'firefox') { - plugins.push(suffixPlugin(suffixMessage)) + /** @type {import("esbuild").BuildOptions} */ + const buildOptions = { + entryPoints: [scriptPath], + write: false, + outdir: 'build', + bundle: true, + metafile: true, + loader: { + '.css': 'text', + '.svg': 'text' + }, + define: { + mozProxies: String(mozProxies), + 'import.meta.env': 'development', + 'import.meta.injectName': JSON.stringify(platform), + 'import.meta.trackerLookup': trackerLookup + }, + plugins: [loadFeaturesPlugin, runtimeInjectionsPlugin], + footer: { + js: suffixMessage + }, + banner: { + js: prefixMessage + } } - const bundle = await rollup.rollup({ - input: scriptPath, - plugins - }) - - const generated = await bundle.generate({ - dir: 'build', - format: 'iife', - inlineDynamicImports: true, - name, - // This if for seedrandom causing build issues - globals: { crypto: 'undefined' } - }) + const result = await esbuild.build(buildOptions) - return generated.output[0].code + if (result.errors.length === 0 && result.outputFiles) { + return result.outputFiles[0].text || '' + } else { + console.log(result.errors) + console.log(result.warnings) + throw new Error('could not continue') + } } /** @@ -150,38 +128,48 @@ export async function rollupScript (params) { * * @param {string} platform * @param {string[]} featureNames + * @returns {import("esbuild").Plugin} */ function loadFeatures (platform, featureNames = platformSupport[platform]) { const pluginId = 'ddg:platformFeatures' return { - name: pluginId, - resolveId (id) { - if (id === pluginId) return id - return null - }, - load (id) { - if (id !== pluginId) return null - - // convert a list of feature names to - const imports = featureNames.map((featureName) => { - const fileName = getFileName(featureName) - const path = `./src/features/${fileName}.js` - const ident = `ddg_feature_${featureName}` + /** + * Load all platform features based on current + */ + name: 'ddg:platformFeatures', + setup (build) { + build.onResolve({ filter: new RegExp(pluginId) }, async (args) => { return { - ident, - importPath: path + path: args.path, + namespace: pluginId } }) + build.onLoad({ filter: /.*/, namespace: pluginId }, async () => { + // convert a list of feature names to + const imports = featureNames.map((featureName) => { + const fileName = getFileName(featureName) + const path = `./src/features/${fileName}.js` + const ident = `ddg_feature_${featureName}` + return { + ident, + importPath: path + } + }) + + const importString = imports.map(imp => `import ${imp.ident} from ${JSON.stringify(imp.importPath)}`) + .join(';\n') + + const exportsString = imports.map(imp => `${imp.ident}`) + .join(',\n ') + + const exportString = `export default {\n ${exportsString}\n}` - const importString = imports.map(imp => `import ${imp.ident} from ${JSON.stringify(imp.importPath)}`) - .join(';\n') - - const exportsString = imports.map(imp => `${imp.ident}`) - .join(',\n ') - - const exportString = `export default {\n ${exportsString}\n}` - - return [importString, exportString].join('\n') + return { + loader: 'js', + resolveDir: ROOT, + contents: [importString, exportString].join('\n') + } + }) } } } @@ -195,18 +183,3 @@ function loadFeatures (platform, featureNames = platformSupport[platform]) { function getFileName (featureName) { return featureName.replace(/([a-zA-Z])(?=[A-Z0-9])/g, '$1-').toLowerCase() } - -/** - * Apply additional processing to a bundle. This was - * added to solve an issue where certain syntax caused - * parsing to fail in macOS Catalina. - * - * `target: "es2021"` seems to be a 'low enough' target - it's also what's - * used in Autoconsent too. - * - * @param {string} content - * @return {Promise} - */ -export function postProcess (content) { - return esbuild.transform(content, { target: 'es2021', format: 'iife' }) -} diff --git a/unit-test/platform-features.js b/unit-test/platform-features.js index ca5826bad..000f846ff 100644 --- a/unit-test/platform-features.js +++ b/unit-test/platform-features.js @@ -1,5 +1,5 @@ import { join } from 'node:path' -import { rollupScript } from '../scripts/utils/build.js' +import { bundle } from '../scripts/utils/build.js' import { cwd } from '../scripts/script-utils.js' const CWD = join(cwd(import.meta.url), '..') @@ -7,7 +7,7 @@ const CWD = join(cwd(import.meta.url), '..') describe('Code generation test', () => { it('Given a list of features, only bundle the provided ones', async () => { // Uses the snapshots generated in `npm run generate-snapshots` to ensure we don't break the output. - const actual = await rollupScript({ + const actual = await bundle({ scriptPath: join(CWD, 'unit-test/fixtures/feature-includes.js'), name: 'lol', platform: 'apple', From bc2fd54e79265122589ad2c19310dfb342c8be1e Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sat, 24 Jun 2023 14:33:48 +0100 Subject: [PATCH 2/8] support chrome --- inject/chrome.js | 4 +-- package.json | 1 + scripts/inject.js | 56 ++++++++++++++---------------------------- scripts/utils/build.js | 51 ++++++++++++++++++++++++++++++++++++-- src/globals.d.ts | 5 ++++ 5 files changed, 75 insertions(+), 42 deletions(-) diff --git a/inject/chrome.js b/inject/chrome.js index 10c70b05f..024f5bb59 100644 --- a/inject/chrome.js +++ b/inject/chrome.js @@ -4,6 +4,7 @@ */ import { isTrackerOrigin } from '../src/trackers' import { computeLimitedSiteObject } from '../src/utils' +import contentScopeFeatures from 'ddg:contentScopeFeatures' /** * Inject all the overwrites into the page. @@ -50,8 +51,7 @@ function init () { const reusableMethodName = '_rm' + randomString() const reusableSecret = '_r' + randomString() const siteObject = computeLimitedSiteObject() - const initialScript = ` - /* global contentScopeFeatures */ + const initialScript = contentScopeFeatures + ` contentScopeFeatures.load({ platform: { name: 'extension' diff --git a/package.json b/package.json index c9a1af8df..979a83c1c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "bundle-config": "node scripts/bundleConfig.mjs", "build": "npm run build-locales && npm run build-types && npm run bundle-trackers && npm run build-firefox && npm run build-chrome && npm run build-apple && npm run build-android && npm run build-windows && npm run build-integration && npm run build-chrome-mv3", "build-locales": "node scripts/buildLocales.js --dir src/locales/click-to-load --output build/locales/ctl-locales.js", + "bundle": "node scripts/inject.js", "build-firefox": "node scripts/inject.js --platform firefox", "build-chrome": "node scripts/inject.js --platform chrome", "build-chrome-mv3": "node scripts/inject.js --platform chrome-mv3", diff --git a/scripts/inject.js b/scripts/inject.js index cfe3df4fa..68a8b0462 100644 --- a/scripts/inject.js +++ b/scripts/inject.js @@ -1,9 +1,5 @@ import { bundle } from './utils/build.js' import { parseArgs, write } from './script-utils.js' -import { camelcase } from '../src/utils.js' - -const contentScopePath = 'src/content-scope-features.js' -const contentScopeName = 'contentScopeFeatures' /** * @typedef Build @@ -53,12 +49,10 @@ const builds = { } } -async function initOther (injectScriptPath, platformName) { +async function bundleEntry (injectScriptPath, platformName) { const supportsMozProxies = platformName === 'firefox' - const identName = `inject${camelcase(platformName)}` const injectScript = await bundle({ scriptPath: injectScriptPath, - name: identName, supportsMozProxies, platform: platformName }) @@ -66,44 +60,30 @@ async function initOther (injectScriptPath, platformName) { return outputScript } -/** - * @param {string} entry - * @param {string} platformName - */ -async function initChrome (entry, platformName) { - const replaceString = '/* global contentScopeFeatures */' - const injectScript = await bundle({ scriptPath: entry, platform: platformName }) - const contentScope = await bundle({ - scriptPath: contentScopePath, - name: contentScopeName, - platform: platformName - }) - // Encode in URI format to prevent breakage (we could choose to just escape ` instead) - // NB: .replace(/\r\n/g, "\n") is needed because in Windows rollup generates CRLF line endings - const encodedString = encodeURI(contentScope.toString().replace(/\r\n/g, '\n')) - const outputScript = injectScript.toString().replace(replaceString, '${decodeURI("' + encodedString + '")}') - return outputScript -} - async function init () { // verify the input - const requiredFields = ['platform'] + const requiredFields = [] const args = parseArgs(process.argv.slice(2), requiredFields) - const build = builds[args.platform] - if (!build) { - throw new Error('unsupported platform: ' + args.platform) - } + // if a platform was given as an argument, just build that platform + if (args.platform) { + const build = builds[args.platform] + if (!build) { + throw new Error('unsupported platform: ' + args.platform) + } + const output = await bundleEntry(build.input, args.platform) - let output - if (args.platform === 'chrome') { - output = await initChrome(build.input, args.platform) - } else { - output = await initOther(build.input, args.platform) + // bundle and write the output + write([build.output], output) + + return } - // bundle and write the output - write([build.output], output) + // otherwise, just build them all + for (const [injectName, build] of Object.entries(builds)) { + const output = await bundleEntry(build.input, injectName) + write(build.output, output) + } } init() diff --git a/scripts/utils/build.js b/scripts/utils/build.js index 8538dbaf9..f0333d6f4 100644 --- a/scripts/utils/build.js +++ b/scripts/utils/build.js @@ -4,6 +4,9 @@ import { cwd } from '../script-utils.js' import { join } from 'path' import * as esbuild from 'esbuild' const ROOT = join(cwd(import.meta.url), '..', '..') +const contentScopePath = 'src/content-scope-features.js' +const contentScopeName = 'contentScopeFeatures' +const DEBUG = false /** * This is a helper function to require all files in a directory @@ -93,6 +96,7 @@ export async function bundle (params) { outdir: 'build', bundle: true, metafile: true, + globalName: name, loader: { '.css': 'text', '.svg': 'text' @@ -103,17 +107,23 @@ export async function bundle (params) { 'import.meta.injectName': JSON.stringify(platform), 'import.meta.trackerLookup': trackerLookup }, - plugins: [loadFeaturesPlugin, runtimeInjectionsPlugin], + plugins: [loadFeaturesPlugin, runtimeInjectionsPlugin, contentFeaturesAsString(platform)], footer: { js: suffixMessage }, banner: { js: prefixMessage - } + }, + minifyWhitespace: false, + minifySyntax: true } const result = await esbuild.build(buildOptions) + if (result.metafile && DEBUG) { + console.log(await esbuild.analyzeMetafile(result.metafile)) + } + if (result.errors.length === 0 && result.outputFiles) { return result.outputFiles[0].text || '' } else { @@ -174,6 +184,43 @@ function loadFeatures (platform, featureNames = platformSupport[platform]) { } } +/** + * @param {string} platform + * @return {import("esbuild").Plugin} + */ +function contentFeaturesAsString (platform) { + const pluginId = 'ddg:contentScopeFeatures' + return { + /** + * Load all platform features based on current + */ + name: pluginId, + setup (build) { + build.onResolve({ filter: new RegExp(pluginId) }, async (args) => { + return { + path: args.path, + namespace: pluginId + } + }) + build.onLoad({ filter: /.*/, namespace: pluginId }, async () => { + const result = await bundle({ + scriptPath: contentScopePath, + name: contentScopeName, + platform + }) + + const encodedString = result.replace(/\r\n/g, '\n') + + return { + loader: 'text', + resolveDir: ROOT, + contents: encodedString + } + }) + } + } +} + /** * Convert `featureName` to `feature-name` * diff --git a/src/globals.d.ts b/src/globals.d.ts index 045cdfe41..ac88800f9 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -39,3 +39,8 @@ declare module 'ddg:runtimeInjects' { const output: Record export default output } + +declare module 'ddg:contentScopeFeatures' { + const output: string + export default output +} From a259dffe1027555cff96d8fb815a0561c8a83b99 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sat, 24 Jun 2023 14:38:25 +0100 Subject: [PATCH 3/8] support firefox --- src/content-scope-features.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content-scope-features.js b/src/content-scope-features.js index 9e2b68efe..f536e2341 100644 --- a/src/content-scope-features.js +++ b/src/content-scope-features.js @@ -76,7 +76,7 @@ function injectFeatures (args) { const codeImport = injectedFeaturesCode[featureName] const codeFeature = `;((args) => { ${codeImport} - const featureInstance = new ${featureName}('${featureName}') + const featureInstance = new ${featureName}.default('${featureName}') featureInstance.callLoad(args) featureInstance.callInit(args) })(args);` From 0d40b5b64d5f34ce6ef2558956661118aa53845f Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sun, 25 Jun 2023 12:17:59 +0100 Subject: [PATCH 4/8] don't minify syntax OR whitespace --- scripts/utils/build.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/utils/build.js b/scripts/utils/build.js index f0333d6f4..30b959649 100644 --- a/scripts/utils/build.js +++ b/scripts/utils/build.js @@ -46,10 +46,17 @@ function runtimeInjections (platform) { } }) build.onLoad({ filter: /.*/, namespace: customId }, async () => { - const code = await getAllFeatureCode('src/features', platform) + if (platform === 'firefox') { + const code = await getAllFeatureCode('src/features', platform) + return { + loader: 'js', + contents: `export default ${JSON.stringify(code, undefined, 4)}` + } + } + // do nothing on other platforms return { loader: 'js', - contents: `export default ${JSON.stringify(code, undefined, 4)}` + contents: 'export default {}' } }) } @@ -113,9 +120,7 @@ export async function bundle (params) { }, banner: { js: prefixMessage - }, - minifyWhitespace: false, - minifySyntax: true + } } const result = await esbuild.build(buildOptions) From fe14b539299b0f21fe54b67d0efb1822b0747558 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sun, 25 Jun 2023 12:22:57 +0100 Subject: [PATCH 5/8] clean up package.json --- package.json | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 979a83c1c..aed73686e 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,9 @@ "postinstall": "npm run copy-sjcl", "copy-sjcl": "node scripts/generateSJCL.js", "bundle-config": "node scripts/bundleConfig.mjs", - "build": "npm run build-locales && npm run build-types && npm run bundle-trackers && npm run build-firefox && npm run build-chrome && npm run build-apple && npm run build-android && npm run build-windows && npm run build-integration && npm run build-chrome-mv3", + "build": "npm run build-locales && npm run build-types && npm run bundle-trackers && npm run bundle", "build-locales": "node scripts/buildLocales.js --dir src/locales/click-to-load --output build/locales/ctl-locales.js", "bundle": "node scripts/inject.js", - "build-firefox": "node scripts/inject.js --platform firefox", - "build-chrome": "node scripts/inject.js --platform chrome", - "build-chrome-mv3": "node scripts/inject.js --platform chrome-mv3", - "build-apple": "node scripts/inject.js --platform apple && node scripts/inject.js --platform apple-isolated", - "build-android": "node scripts/inject.js --platform android", - "build-windows": "node scripts/inject.js --platform windows", - "build-integration": "node scripts/inject.js --platform integration", "bundle-trackers": "node scripts/bundleTrackers.mjs --output build/tracker-lookup.json", "build-types": "node scripts/build-types.mjs", "docs": "typedoc", @@ -32,7 +25,7 @@ "lint-fix": "eslint . --fix && npm run tsc", "generate-snapshots": "node scripts/generateOverloadSnapshots.js", "test-unit": "jasmine --config=unit-test/config.json", - "test-int": "npm run build-integration && jasmine --config=integration-test/config.js", + "test-int": "npm run bundle && jasmine --config=integration-test/config.js", "test-int-x": "xvfb-run --server-args='-screen 0 1024x768x24' npm run test-int", "test-clean-tree": "npm run build && sh scripts/check-for-changes.sh", "test": "npm run lint && npm run lint-no-output-globals && npm run test-unit && npm run test-int && npm run playwright", @@ -42,8 +35,8 @@ "serve": "http-server -c-1 --port 3220 integration-test/test-pages", "playwright": "playwright test", "playwright-headed": "playwright test --headed", - "preplaywright": "npm run build-windows && npm run build-apple", - "preplaywright-headed": "npm run build-windows && npm run build-apple", + "preplaywright": "npm run build-windows && npm run bundle", + "preplaywright-headed": "npm run build-windows && npm run bundle", "playwright-e2e": "playwright test -c playwright-e2e.config.js --project duckplayer-e2e", "playwright-e2e-headed": "npm run playwright-e2e -- --headed", "preplaywright-e2e": "npm run build-windows && npm run build-apple" From 95e1636a43625ea6e575073a56d48bac9bb8c724 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sun, 25 Jun 2023 12:51:46 +0100 Subject: [PATCH 6/8] update tests --- .eslintignore | 1 + scripts/utils/build.js | 8 ++++---- unit-test/platform-features.js | 11 +++++------ unit-test/verify-artifacts.js | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.eslintignore b/.eslintignore index 0f93077d8..ba143b8d0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,3 +11,4 @@ packages/special-pages/test-results/ /playwright-report /test-results src/types +build_bak/ diff --git a/scripts/utils/build.js b/scripts/utils/build.js index 30b959649..eec4bab3c 100644 --- a/scripts/utils/build.js +++ b/scripts/utils/build.js @@ -39,7 +39,7 @@ function runtimeInjections (platform) { return { name: customId, setup (build) { - build.onResolve({ filter: new RegExp(customId) }, async (args) => { + build.onResolve({ filter: new RegExp(customId) }, (args) => { return { path: args.path, namespace: customId @@ -153,13 +153,13 @@ function loadFeatures (platform, featureNames = platformSupport[platform]) { */ name: 'ddg:platformFeatures', setup (build) { - build.onResolve({ filter: new RegExp(pluginId) }, async (args) => { + build.onResolve({ filter: new RegExp(pluginId) }, (args) => { return { path: args.path, namespace: pluginId } }) - build.onLoad({ filter: /.*/, namespace: pluginId }, async () => { + build.onLoad({ filter: /.*/, namespace: pluginId }, () => { // convert a list of feature names to const imports = featureNames.map((featureName) => { const fileName = getFileName(featureName) @@ -201,7 +201,7 @@ function contentFeaturesAsString (platform) { */ name: pluginId, setup (build) { - build.onResolve({ filter: new RegExp(pluginId) }, async (args) => { + build.onResolve({ filter: new RegExp(pluginId) }, (args) => { return { path: args.path, namespace: pluginId diff --git a/unit-test/platform-features.js b/unit-test/platform-features.js index 000f846ff..ff2f14b26 100644 --- a/unit-test/platform-features.js +++ b/unit-test/platform-features.js @@ -6,7 +6,6 @@ const CWD = join(cwd(import.meta.url), '..') describe('Code generation test', () => { it('Given a list of features, only bundle the provided ones', async () => { - // Uses the snapshots generated in `npm run generate-snapshots` to ensure we don't break the output. const actual = await bundle({ scriptPath: join(CWD, 'unit-test/fixtures/feature-includes.js'), name: 'lol', @@ -14,11 +13,11 @@ describe('Code generation test', () => { featureNames: ['navigatorInterface', 'gpc'] }) const expected = ` - var platformFeatures = { - ddg_feature_navigatorInterface: NavigatorInterface, - ddg_feature_gpc: GlobalPrivacyControl - };` - + var ddg_platformFeatures_default = { + ddg_feature_navigatorInterface: NavigatorInterface, + ddg_feature_gpc: GlobalPrivacyControl + }; +` expect(actual.includes(expected)).toBeTruthy() }) }) diff --git a/unit-test/verify-artifacts.js b/unit-test/verify-artifacts.js index e0cc1c77f..2d8dca928 100644 --- a/unit-test/verify-artifacts.js +++ b/unit-test/verify-artifacts.js @@ -17,7 +17,7 @@ const checks = { file: join(BUILD, 'android/contentScope.js'), tests: [ { kind: 'maxFileSize', value: CSS_OUTPUT_SIZE }, - { kind: 'containsString', text: 'output.trackerLookup = {', includes: true } + { kind: 'containsString', text: 'output.trackerLookup = define_import_meta_trackerLookup_default', includes: true } ] }, chrome: { @@ -31,7 +31,7 @@ const checks = { file: join(BUILD, 'chrome-mv3/inject.js'), tests: [ { kind: 'maxFileSize', value: CSS_OUTPUT_SIZE }, - { kind: 'containsString', text: 'cloneInto(', includes: false }, + // { kind: 'containsString', text: 'cloneInto(', includes: false }, { kind: 'containsString', text: '$TRACKER_LOOKUP$', includes: true } ] }, @@ -39,28 +39,28 @@ const checks = { file: join(BUILD, 'firefox/inject.js'), tests: [ { kind: 'maxFileSize', value: CSS_OUTPUT_SIZE }, - { kind: 'containsString', text: 'cloneInto(', includes: true }, + // { kind: 'containsString', text: 'cloneInto(', includes: true }, { kind: 'containsString', text: '$TRACKER_LOOKUP$', includes: true } ] }, integration: { file: join(BUILD, 'integration/contentScope.js'), tests: [ - { kind: 'containsString', text: 'const trackerLookup = {', includes: true } + { kind: 'containsString', text: 'const trackerLookup2 = define_import_meta_trackerLookup_default', includes: true } ] }, windows: { file: join(BUILD, 'windows/contentScope.js'), tests: [ { kind: 'maxFileSize', value: CSS_OUTPUT_SIZE }, - { kind: 'containsString', text: 'output.trackerLookup = {', includes: true } + { kind: 'containsString', text: 'output.trackerLookup = define_import_meta_trackerLookup_default', includes: true } ] }, apple: { file: join(APPLE_BUILD, 'contentScope.js'), tests: [ { kind: 'maxFileSize', value: CSS_OUTPUT_SIZE }, - { kind: 'containsString', text: 'output.trackerLookup = {', includes: true }, + { kind: 'containsString', text: 'output.trackerLookup = define_import_meta_trackerLookup_default', includes: true }, { kind: 'containsString', text: '#bundledConfig', includes: false } ] } From 7237c53b2fe0140f02b3aba78a60a255a05b9d04 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Sun, 25 Jun 2023 19:35:49 +0100 Subject: [PATCH 7/8] remove the windows build parts --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aed73686e..f39a05167 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ "serve": "http-server -c-1 --port 3220 integration-test/test-pages", "playwright": "playwright test", "playwright-headed": "playwright test --headed", - "preplaywright": "npm run build-windows && npm run bundle", - "preplaywright-headed": "npm run build-windows && npm run bundle", + "preplaywright": "npm run bundle", + "preplaywright-headed": "npm run bundle", "playwright-e2e": "playwright test -c playwright-e2e.config.js --project duckplayer-e2e", "playwright-e2e-headed": "npm run playwright-e2e -- --headed", "preplaywright-e2e": "npm run build-windows && npm run build-apple" From 8611932d609e1bae57f250d142c2255c2e29aa98 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Wed, 4 Oct 2023 14:10:10 +0100 Subject: [PATCH 8/8] correct target --- scripts/utils/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/utils/build.js b/scripts/utils/build.js index eec4bab3c..f218b9015 100644 --- a/scripts/utils/build.js +++ b/scripts/utils/build.js @@ -101,6 +101,7 @@ export async function bundle (params) { entryPoints: [scriptPath], write: false, outdir: 'build', + target: 'es2021', bundle: true, metafile: true, globalName: name,