From e37f73880dd387f576065764100e40f8bc843159 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 29 Oct 2023 21:19:31 -0500 Subject: [PATCH] feat: Refactor project structure to export `initialize`, `prepare`, and `zip` functions (#182) --- docs/typedoc.json | 4 +- package.json | 8 +- pnpm-lock.yaml | 238 +++--------------- scripts/build.ts | 134 +++++----- src/@types/modules.d.ts | 16 -- src/{client => }/browser.ts | 0 src/cli.ts | 164 ++++++++++++ src/cli/commands/build.ts | 31 --- src/cli/commands/clean.ts | 11 - src/cli/commands/dev.ts | 30 --- src/cli/commands/index.ts | 7 - src/cli/commands/prepare.ts | 27 -- src/cli/commands/publish.ts | 11 - src/cli/commands/zip.ts | 32 --- src/cli/index.ts | 64 ----- ...ound.test.ts => define-background.test.ts} | 4 +- .../__tests__/content-script-ui.test.ts} | 19 +- .../__tests__/define-content-script.test.ts} | 4 +- .../content-script-context.ts} | 6 +- .../content-script-ui.ts} | 8 +- .../define-content-script.ts} | 2 +- src/client/content-scripts/index.ts | 3 + ...fineBackground.ts => define-background.ts} | 2 +- src/client/index.ts | 6 +- src/client/sandbox/index.ts | 4 - ...rAlive.ts => keep-service-worker-alive.ts} | 0 ...entScript.ts => reload-content-scripts.ts} | 0 ...{setupWebSocket.ts => setup-web-socket.ts} | 0 src/client/virtual-modules/fake-browser.ts | 3 - src/core/build.ts | 152 ++--------- src/core/{server.ts => create-server.ts} | 124 ++++++++- .../defineConfig.ts => define-config.ts} | 2 +- ...unnerConfig.ts => define-runner-config.ts} | 2 +- src/core/index.ts | 8 + .../commands/init.ts => core/initialize.ts} | 125 +++++---- src/core/prepare.ts | 15 ++ src/core/runners/__tests__/index.test.ts | 4 +- src/core/runners/extension-runner.ts | 6 - src/core/runners/index.ts | 5 +- src/core/runners/manual.ts | 2 +- src/core/runners/safari.ts | 2 +- src/core/runners/web-ext.ts | 2 +- src/core/runners/wsl.ts | 2 +- src/core/utils/__tests__/arrays.test.ts | 2 +- .../utils/__tests__/content-scripts.test.ts | 4 +- ...est.ts => content-security-policy.test.ts} | 2 +- src/core/utils/__tests__/entrypoints.test.ts | 4 +- src/core/utils/__tests__/package.test.ts | 26 ++ src/core/utils/__tests__/strings.test.ts | 5 +- .../__tests__/test-entrypoints/background.ts | 2 +- .../__tests__/test-entrypoints/content.ts | 2 +- .../__tests__/test-entrypoints/react.tsx | 2 +- .../__tests__/test-entrypoints/unlisted.ts | 2 +- .../__tests__/test-entrypoints/with-named.ts | 2 +- .../__tests__/detect-dev-changes.test.ts} | 6 +- .../__tests__/find-entrypoints.test.ts} | 12 +- .../__tests__/group-entrypoints.test.ts} | 4 +- .../__tests__/import-entrypoint.test.ts} | 4 +- .../building/build-entrypoints.ts} | 12 +- .../detect-dev-changes.ts} | 6 +- .../building/find-entrypoints.ts} | 10 +- .../building/generate-wxt-dir.ts} | 15 +- .../get-internal-config.ts} | 6 +- .../group-entrypoints.ts} | 3 +- .../import-entrypoint.ts} | 10 +- src/core/utils/building/index.ts | 9 + src/core/utils/building/internal-build.ts | 76 ++++++ src/core/utils/building/rebuild.ts | 71 ++++++ src/core/utils/{createFsCache.ts => cache.ts} | 2 +- .../defineCommand.ts => core/utils/cli.ts} | 4 +- src/core/utils/content-scripts.ts | 2 +- ...tyPolicy.ts => content-security-policy.ts} | 0 src/core/utils/entrypoints.ts | 2 +- src/core/utils/formatDuration.ts | 6 - src/core/utils/fs.ts | 37 +++ src/core/utils/globals.ts | 2 +- src/core/utils/log/index.ts | 4 + src/core/{ => utils}/log/printBuildSummary.ts | 2 +- src/core/{ => utils}/log/printFileList.ts | 0 src/core/{ => utils}/log/printHeader.ts | 2 +- src/core/{ => utils}/log/printTable.ts | 0 src/core/utils/manifest.ts | 6 +- src/core/utils/network.ts | 4 +- src/core/utils/package.ts | 2 +- src/core/utils/public.ts | 17 -- src/core/utils/removeEmptyDirs.ts | 19 -- .../utils/testing}/fake-objects.ts | 14 +- src/core/utils/{promises.ts => time.ts} | 7 + .../utils/{auto-imports.ts => unimport.ts} | 2 +- src/core/vite-plugins/cssEntrypoints.ts | 4 +- src/core/vite-plugins/devHtmlPrerender.ts | 6 +- src/core/vite-plugins/devServerGlobals.ts | 2 +- src/core/vite-plugins/download.ts | 4 +- src/core/vite-plugins/globals.ts | 2 +- src/core/vite-plugins/multipageMove.ts | 6 +- src/core/vite-plugins/tsconfigPaths.ts | 2 +- src/core/vite-plugins/unimport.ts | 4 +- src/core/vite-plugins/virtualEntrypoint.ts | 6 +- .../vite-plugins/webextensionPolyfillAlias.ts | 4 +- src/core/zip.ts | 74 +++--- src/index.ts | 130 +--------- .../__tests__/define-unlisted-script.test.ts} | 4 +- .../define-unlisted-script.ts} | 2 +- src/sandbox/index.ts | 4 + src/testing/wxt-vitest-plugin.ts | 8 +- src/{core => }/types/external.ts | 7 +- src/{core => }/types/index.ts | 0 src/{core => }/types/internal.ts | 10 +- .../web-ext-run.d.ts => types/modules.d.ts} | 19 ++ src/{@types => types}/vitest-defines.d.ts | 0 src/version.ts | 1 + .../background-entrypoint.ts | 8 +- .../content-script-entrypoint.ts | 4 +- src/virtual/mock-browser.ts | 3 + .../reload-html.ts | 4 +- .../unlisted-script-entrypoint.ts | 2 +- .../virtual-module-globals.d.ts | 6 +- tsconfig.json | 5 + vitest.workspace.ts | 9 + 119 files changed, 969 insertions(+), 1091 deletions(-) delete mode 100644 src/@types/modules.d.ts rename src/{client => }/browser.ts (100%) create mode 100644 src/cli.ts delete mode 100644 src/cli/commands/build.ts delete mode 100644 src/cli/commands/clean.ts delete mode 100644 src/cli/commands/dev.ts delete mode 100644 src/cli/commands/index.ts delete mode 100644 src/cli/commands/prepare.ts delete mode 100644 src/cli/commands/publish.ts delete mode 100644 src/cli/commands/zip.ts delete mode 100644 src/cli/index.ts rename src/client/__tests__/{defineBackground.test.ts => define-background.test.ts} (83%) rename src/client/{__tests__/createContentScriptUi.test.ts => content-scripts/__tests__/content-script-ui.test.ts} (94%) rename src/client/{__tests__/defineContentScript.test.ts => content-scripts/__tests__/define-content-script.test.ts} (72%) rename src/client/{utils/ContentScriptContext.ts => content-scripts/content-script-context.ts} (97%) rename src/client/{createContentScriptUi.ts => content-scripts/content-script-ui.ts} (97%) rename src/client/{defineContentScript.ts => content-scripts/define-content-script.ts} (69%) create mode 100644 src/client/content-scripts/index.ts rename src/client/{defineBackground.ts => define-background.ts} (87%) delete mode 100644 src/client/sandbox/index.ts rename src/client/utils/{keepServiceWorkerAlive.ts => keep-service-worker-alive.ts} (100%) rename src/client/utils/{reloadContentScript.ts => reload-content-scripts.ts} (100%) rename src/client/utils/{setupWebSocket.ts => setup-web-socket.ts} (100%) delete mode 100644 src/client/virtual-modules/fake-browser.ts rename src/core/{server.ts => create-server.ts} (50%) rename src/core/{utils/defineConfig.ts => define-config.ts} (68%) rename src/core/{utils/defineRunnerConfig.ts => define-runner-config.ts} (69%) create mode 100644 src/core/index.ts rename src/{cli/commands/init.ts => core/initialize.ts} (56%) create mode 100644 src/core/prepare.ts delete mode 100644 src/core/runners/extension-runner.ts rename src/core/utils/__tests__/{ContentSecurityPolicy.test.ts => content-security-policy.test.ts} (93%) create mode 100644 src/core/utils/__tests__/package.test.ts rename src/core/utils/{__tests__/detectDevChanges.test.ts => building/__tests__/detect-dev-changes.test.ts} (97%) rename src/core/{build/__tests__/findEntrypoints.test.ts => utils/building/__tests__/find-entrypoints.test.ts} (98%) rename src/core/utils/{__tests__/groupEntrypoints.test.ts => building/__tests__/group-entrypoints.test.ts} (96%) rename src/core/utils/{__tests__/importEntrypointFile.test.ts => building/__tests__/import-entrypoint.test.ts} (89%) rename src/core/{build/buildEntrypoints.ts => utils/building/build-entrypoints.ts} (94%) rename src/core/utils/{detectDevChanges.ts => building/detect-dev-changes.ts} (96%) rename src/core/{build/findEntrypoints.ts => utils/building/find-entrypoints.ts} (97%) rename src/core/{build/generateTypesDir.ts => utils/building/generate-wxt-dir.ts} (92%) rename src/core/utils/{getInternalConfig.ts => building/get-internal-config.ts} (98%) rename src/core/utils/{groupEntrypoints.ts => building/group-entrypoints.ts} (94%) rename src/core/utils/{importEntrypointFile.ts => building/import-entrypoint.ts} (89%) create mode 100644 src/core/utils/building/index.ts create mode 100644 src/core/utils/building/internal-build.ts create mode 100644 src/core/utils/building/rebuild.ts rename src/core/utils/{createFsCache.ts => cache.ts} (96%) rename src/{cli/utils/defineCommand.ts => core/utils/cli.ts} (88%) rename src/core/utils/{ContentSecurityPolicy.ts => content-security-policy.ts} (100%) delete mode 100644 src/core/utils/formatDuration.ts create mode 100644 src/core/utils/log/index.ts rename src/core/{ => utils}/log/printBuildSummary.ts (95%) rename src/core/{ => utils}/log/printFileList.ts (100%) rename src/core/{ => utils}/log/printHeader.ts (83%) rename src/core/{ => utils}/log/printTable.ts (100%) delete mode 100644 src/core/utils/public.ts delete mode 100644 src/core/utils/removeEmptyDirs.ts rename src/{testing-utils => core/utils/testing}/fake-objects.ts (98%) rename src/core/utils/{promises.ts => time.ts} (66%) rename src/core/utils/{auto-imports.ts => unimport.ts} (94%) rename src/{client/sandbox/__tests__/defineUnlistedScript.test.ts => sandbox/__tests__/define-unlisted-script.test.ts} (81%) rename src/{client/sandbox/defineUnlistedScript.ts => sandbox/define-unlisted-script.ts} (86%) create mode 100644 src/sandbox/index.ts rename src/{core => }/types/external.ts (98%) rename src/{core => }/types/index.ts (100%) rename src/{core => }/types/internal.ts (89%) rename src/{@types/web-ext-run.d.ts => types/modules.d.ts} (65%) rename src/{@types => types}/vitest-defines.d.ts (100%) create mode 100644 src/version.ts rename src/{client/virtual-modules => virtual}/background-entrypoint.ts (81%) rename src/{client/virtual-modules => virtual}/content-script-entrypoint.ts (71%) create mode 100644 src/virtual/mock-browser.ts rename src/{client/virtual-modules => virtual}/reload-html.ts (82%) rename src/{client/virtual-modules => virtual}/unlisted-script-entrypoint.ts (83%) rename src/{client/virtual-modules => virtual}/virtual-module-globals.d.ts (79%) diff --git a/docs/typedoc.json b/docs/typedoc.json index 59340f4e..d39d1f3b 100644 --- a/docs/typedoc.json +++ b/docs/typedoc.json @@ -2,8 +2,8 @@ "entryPoints": [ "../src", "../src/client", - "../src/client/browser.ts", - "../src/client/sandbox", + "../src/browser.ts", + "../src/sandbox", "../src/testing" ], "plugin": ["typedoc-plugin-markdown", "typedoc-vitepress-theme"], diff --git a/package.json b/package.json index 5c8ce707..47807c14 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "types": "./dist/index.d.ts" }, "./client": { + "require": "./dist/client.cjs", "import": "./dist/client.js", "types": "./dist/client.d.ts" }, @@ -59,13 +60,13 @@ } }, "scripts": { - "wxt": "tsx src/cli/index.ts", + "wxt": "tsx src/cli.ts", "build": "tsx scripts/build.ts", "format": "prettier --write .", "format:check": "prettier --write .", "compile": "tsc --noEmit", "test": "vitest", - "test:coverage": "vitest run --coverage.enabled --coverage.exclude=e2e --coverage.exclude=src/testing", + "test:coverage": "vitest run --coverage", "prepare": "simple-git-hooks", "prepublish": "pnpm -s build", "docs:gen": "typedoc --options docs/typedoc.json", @@ -113,10 +114,11 @@ "@types/prompts": "^2.4.4", "@vitest/coverage-v8": "^0.34.6", "execa": "^7.2.0", - "jsdom": "^22.1.0", + "happy-dom": "^12.4.0", "lint-staged": "^14.0.0", "lodash.merge": "^4.6.2", "npm-run-all": "^4.1.5", + "p-map": "^6.0.0", "prettier": "^3.0.1", "simple-git-hooks": "^2.9.0", "tsup": "^7.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5ff6710..75c814ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -117,9 +117,9 @@ importers: execa: specifier: ^7.2.0 version: 7.2.0 - jsdom: - specifier: ^22.1.0 - version: 22.1.0 + happy-dom: + specifier: ^12.4.0 + version: 12.4.0 lint-staged: specifier: ^14.0.0 version: 14.0.1 @@ -129,6 +129,9 @@ importers: npm-run-all: specifier: ^4.1.5 version: 4.1.5 + p-map: + specifier: ^6.0.0 + version: 6.0.0 prettier: specifier: ^3.0.1 version: 3.0.3 @@ -158,7 +161,7 @@ importers: version: 1.0.0-rc.10(@types/node@20.8.6) vitest: specifier: ^0.34.6 - version: 0.34.6(jsdom@22.1.0) + version: 0.34.6(happy-dom@12.4.0) vitest-mock-extended: specifier: ^1.3.1 version: 1.3.1(typescript@5.2.2)(vitest@0.34.6) @@ -176,7 +179,7 @@ importers: version: 18.2.0(react@18.2.0) vitest: specifier: ^0.34.6 - version: 0.34.6(jsdom@22.1.0)(sass@1.64.0) + version: 0.34.6(happy-dom@12.4.0)(sass@1.64.0) webextension-polyfill: specifier: ^0.10.0 version: 0.10.0 @@ -980,10 +983,6 @@ packages: defer-to-connect: 2.0.1 dev: false - /@tootallnate/once@2.0.0: - resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==} - engines: {node: '>= 10'} - /@types/chai-subset@1.3.3: resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} dependencies: @@ -1093,7 +1092,7 @@ packages: std-env: 3.3.3 test-exclude: 6.0.0 v8-to-istanbul: 9.1.0 - vitest: 0.34.6(jsdom@22.1.0) + vitest: 0.34.6(happy-dom@12.4.0) transitivePeerDependencies: - supports-color dev: true @@ -1313,9 +1312,6 @@ packages: '@webcomponents/webcomponentsjs': 2.8.0 dev: false - /abab@2.0.6: - resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} - /acorn-walk@8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} @@ -1337,6 +1333,7 @@ packages: debug: 4.3.4 transitivePeerDependencies: - supports-color + dev: false /algoliasearch@4.19.1: resolution: {integrity: sha512-IJF5b93b2MgAzcE/tuzW0yOPnuUyRgGAtaPv5UUywXM8kzqfdwZTO4sPJBzoGz1eOy6H9uEchsJsBFTELZSu+g==} @@ -1449,9 +1446,6 @@ packages: resolution: {integrity: sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==} dev: false - /asynckit@0.4.0: - resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - /at-least-node@1.0.0: resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==} engines: {node: '>= 4.0.0'} @@ -1724,12 +1718,6 @@ packages: /colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} - /combined-stream@1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - /commander@11.0.0: resolution: {integrity: sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==} engines: {node: '>=16'} @@ -1838,28 +1826,17 @@ packages: engines: {node: '>= 6'} dev: false + /css.escape@1.5.1: + resolution: {integrity: sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==} + /cssom@0.5.0: resolution: {integrity: sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw==} dev: false - /cssstyle@3.0.0: - resolution: {integrity: sha512-N4u2ABATi3Qplzf0hWbVCdjenim8F3ojEXpBDF5hBpjzW182MjNGLqfmQ0SkSPeQ+V86ZXgeH8aXj6kayd4jgg==} - engines: {node: '>=14'} - dependencies: - rrweb-cssom: 0.6.0 - /csstype@3.1.2: resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} dev: true - /data-urls@4.0.0: - resolution: {integrity: sha512-/mMTei/JXPqvFqQtfyTowxmJVwr2PVAeCcDxyFf6LhoOu/09TX2OX3kb2wzi4DMXcfj4OItwDOnhl5oziPnT6g==} - engines: {node: '>=14'} - dependencies: - abab: 2.0.6 - whatwg-mimetype: 3.0.0 - whatwg-url: 12.0.1 - /debounce@1.2.1: resolution: {integrity: sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==} dev: false @@ -1886,9 +1863,6 @@ packages: dependencies: ms: 2.1.2 - /decimal.js@10.4.3: - resolution: {integrity: sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==} - /decompress-response@6.0.0: resolution: {integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==} engines: {node: '>=10'} @@ -1929,10 +1903,6 @@ packages: resolution: {integrity: sha512-+uO4+qr7msjNNWKYPHqN/3+Dx3NFkmIzayk2L1MyZQlvgZb/J1A0fo410dpKrN2SnqFjt8n4JL8fDJE0wIgjFQ==} dev: false - /delayed-stream@1.0.0: - resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} - engines: {node: '>=0.4.0'} - /destr@2.0.0: resolution: {integrity: sha512-FJ9RDpf3GicEBvzI3jxc2XhHzbqD8p4ANw/1kPsFBfTvP1b7Gn/Lg1vO7R9J4IVgoMbyUmFrFGZafJ1hPZpvlg==} dev: false @@ -1960,12 +1930,6 @@ packages: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} dev: false - /domexception@4.0.0: - resolution: {integrity: sha512-A2is4PLG+eeSfoTMA95/s4pvAoSo2mKtiM5jlHkAVewmiO8ISFTFKZjH7UAM1Atli/OT/7JHOrJRJiMKUZKYBw==} - engines: {node: '>=12'} - dependencies: - webidl-conversions: 7.0.0 - /domhandler@5.0.3: resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==} engines: {node: '>= 4'} @@ -2266,14 +2230,6 @@ packages: engines: {node: '>= 14.17'} dev: false - /form-data@4.0.0: - resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - /fs-extra@11.1.1: resolution: {integrity: sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==} engines: {node: '>=14.14'} @@ -2490,6 +2446,16 @@ packages: resolution: {integrity: sha512-+xGQY0YyAWCnqy7Cd++hc2JqMYzlm0dG30Jd0beaA64sROr8C4nt8Yc9V5Ro3avlSUDTN0ulqP/VBKi1/lLygw==} dev: false + /happy-dom@12.4.0: + resolution: {integrity: sha512-I3MUV+70GG4UfPuPLATndGwSZcB1q0EdJtwFTiC5nCNLGQY5tPdloyIJdq94lgVjH537gLFmo8zJgDvqvP/FDw==} + dependencies: + css.escape: 1.5.1 + entities: 4.5.0 + iconv-lite: 0.6.3 + webidl-conversions: 7.0.0 + whatwg-encoding: 2.0.0 + whatwg-mimetype: 3.0.0 + /has-bigints@1.0.2: resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==} dev: true @@ -2542,12 +2508,6 @@ packages: resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==} dev: true - /html-encoding-sniffer@3.0.0: - resolution: {integrity: sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==} - engines: {node: '>=12'} - dependencies: - whatwg-encoding: 2.0.0 - /html-escaper@2.0.2: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} dev: true @@ -2569,16 +2529,6 @@ packages: resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==} dev: false - /http-proxy-agent@5.0.0: - resolution: {integrity: sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==} - engines: {node: '>= 6'} - dependencies: - '@tootallnate/once': 2.0.0 - agent-base: 6.0.2 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - /http2-wrapper@2.2.0: resolution: {integrity: sha512-kZB0wxMo0sh1PehyjJUWRFEd99KC5TLjZ2cULC4f9iqJBAmKQQXEICjxl5iPJRwP40dpeHFqqhm7tYCvODpqpQ==} engines: {node: '>=10.19.0'} @@ -2595,6 +2545,7 @@ packages: debug: 4.3.4 transitivePeerDependencies: - supports-color + dev: false /human-signals@2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} @@ -2808,9 +2759,6 @@ packages: engines: {node: '>=8'} dev: false - /is-potential-custom-element-name@1.0.1: - resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} - /is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -2957,43 +2905,6 @@ packages: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} dev: false - /jsdom@22.1.0: - resolution: {integrity: sha512-/9AVW7xNbsBv6GfWho4TTNjEo9fe6Zhf9O7s0Fhhr3u+awPwAJMKwAMXnkk5vBxflqLW9hTHX/0cs+P3gW+cQw==} - engines: {node: '>=16'} - peerDependencies: - canvas: ^2.5.0 - peerDependenciesMeta: - canvas: - optional: true - dependencies: - abab: 2.0.6 - cssstyle: 3.0.0 - data-urls: 4.0.0 - decimal.js: 10.4.3 - domexception: 4.0.0 - form-data: 4.0.0 - html-encoding-sniffer: 3.0.0 - http-proxy-agent: 5.0.0 - https-proxy-agent: 5.0.1 - is-potential-custom-element-name: 1.0.1 - nwsapi: 2.2.7 - parse5: 7.1.2 - rrweb-cssom: 0.6.0 - saxes: 6.0.0 - symbol-tree: 3.2.4 - tough-cookie: 4.1.3 - w3c-xmlserializer: 4.0.0 - webidl-conversions: 7.0.0 - whatwg-encoding: 2.0.0 - whatwg-mimetype: 3.0.0 - whatwg-url: 12.0.1 - ws: 8.13.0 - xml-name-validator: 4.0.0 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - /json-buffer@3.0.1: resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==} dev: false @@ -3256,16 +3167,6 @@ packages: braces: 3.0.2 picomatch: 2.3.1 - /mime-db@1.52.0: - resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} - engines: {node: '>= 0.6'} - - /mime-types@2.1.35: - resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.52.0 - /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} @@ -3495,9 +3396,6 @@ packages: boolbase: 1.0.0 dev: false - /nwsapi@2.2.7: - resolution: {integrity: sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==} - /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} @@ -3583,6 +3481,11 @@ packages: dependencies: yocto-queue: 1.0.0 + /p-map@6.0.0: + resolution: {integrity: sha512-T8BatKGY+k5rU+Q/GTYgrEf2r4xRMevAN5mtXc2aPc4rS1j3s+vWTaO2Wag94neXuCAUAs8cxBL9EeB5EA6diw==} + engines: {node: '>=16'} + dev: true + /package-json@8.1.1: resolution: {integrity: sha512-cbH9IAIJHNj9uXi196JVsRlt7cHKak6u/e6AkL/bkRelZ7rlL3X1YKxsZwa36xipOEKAsdtmaG6aAJoM1fx2zA==} engines: {node: '>=14.16'} @@ -3616,11 +3519,6 @@ packages: type-fest: 3.13.1 dev: false - /parse5@7.1.2: - resolution: {integrity: sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==} - dependencies: - entities: 4.5.0 - /path-is-absolute@1.0.1: resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} engines: {node: '>=0.10.0'} @@ -3767,12 +3665,10 @@ packages: resolution: {integrity: sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==} dev: false - /psl@1.9.0: - resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==} - /punycode@2.3.0: resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==} engines: {node: '>=6'} + dev: true /pupa@3.1.0: resolution: {integrity: sha512-FLpr4flz5xZTSJxSeaheeMKN/EDzMdK7b8PTOC6a5PYFKTucWbdqjgqaEyH0shFiSJrVB1+Qqi4Tk19ccU6Aug==} @@ -3781,9 +3677,6 @@ packages: escape-goat: 4.0.0 dev: false - /querystringify@2.2.0: - resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} - /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -3898,9 +3791,6 @@ packages: engines: {node: '>=0.10.0'} dev: false - /requires-port@1.0.0: - resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} - /resolve-alpn@1.2.1: resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==} dev: false @@ -3991,9 +3881,6 @@ packages: optionalDependencies: fsevents: 2.3.3 - /rrweb-cssom@0.6.0: - resolution: {integrity: sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==} - /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: @@ -4033,12 +3920,6 @@ packages: resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==} dev: false - /saxes@6.0.0: - resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==} - engines: {node: '>=v12.22.7'} - dependencies: - xmlchars: 2.2.0 - /scheduler@0.23.0: resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==} dependencies: @@ -4380,9 +4261,6 @@ packages: engines: {node: '>= 0.4'} dev: true - /symbol-tree@3.2.4: - resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} - /tabbable@6.2.0: resolution: {integrity: sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==} dev: true @@ -4452,27 +4330,12 @@ packages: dependencies: is-number: 7.0.0 - /tough-cookie@4.1.3: - resolution: {integrity: sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==} - engines: {node: '>=6'} - dependencies: - psl: 1.9.0 - punycode: 2.3.0 - universalify: 0.2.0 - url-parse: 1.5.10 - /tr46@1.0.1: resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} dependencies: punycode: 2.3.0 dev: true - /tr46@4.1.1: - resolution: {integrity: sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==} - engines: {node: '>=14'} - dependencies: - punycode: 2.3.0 - /tree-kill@1.2.2: resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} hasBin: true @@ -4661,10 +4524,6 @@ packages: crypto-random-string: 4.0.0 dev: false - /universalify@0.2.0: - resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} - engines: {node: '>= 4.0.0'} - /universalify@1.0.0: resolution: {integrity: sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==} engines: {node: '>= 10.0.0'} @@ -4704,12 +4563,6 @@ packages: xdg-basedir: 5.1.0 dev: false - /url-parse@1.5.10: - resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} - dependencies: - querystringify: 2.2.0 - requires-port: 1.0.0 - /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: false @@ -4842,10 +4695,10 @@ packages: dependencies: ts-essentials: 9.3.2(typescript@5.2.2) typescript: 5.2.2 - vitest: 0.34.6(jsdom@22.1.0) + vitest: 0.34.6(happy-dom@12.4.0) dev: true - /vitest@0.34.6(jsdom@22.1.0): + /vitest@0.34.6(happy-dom@12.4.0): resolution: {integrity: sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==} engines: {node: '>=v14.18.0'} hasBin: true @@ -4889,7 +4742,7 @@ packages: cac: 6.7.14 chai: 4.3.10 debug: 4.3.4 - jsdom: 22.1.0 + happy-dom: 12.4.0 local-pkg: 0.4.3 magic-string: 0.30.2 pathe: 1.1.1 @@ -4911,7 +4764,7 @@ packages: - terser dev: true - /vitest@0.34.6(jsdom@22.1.0)(sass@1.64.0): + /vitest@0.34.6(happy-dom@12.4.0)(sass@1.64.0): resolution: {integrity: sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==} engines: {node: '>=v14.18.0'} hasBin: true @@ -4955,7 +4808,7 @@ packages: cac: 6.7.14 chai: 4.3.10 debug: 4.3.4 - jsdom: 22.1.0 + happy-dom: 12.4.0 local-pkg: 0.4.3 magic-string: 0.30.3 pathe: 1.1.1 @@ -5010,12 +4863,6 @@ packages: '@vue/shared': 3.3.4 dev: true - /w3c-xmlserializer@4.0.0: - resolution: {integrity: sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==} - engines: {node: '>=14'} - dependencies: - xml-name-validator: 4.0.0 - /watchpack@2.4.0: resolution: {integrity: sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==} engines: {node: '>=10.13.0'} @@ -5088,13 +4935,6 @@ packages: resolution: {integrity: sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==} engines: {node: '>=12'} - /whatwg-url@12.0.1: - resolution: {integrity: sha512-Ed/LrqB8EPlGxjS+TrsXcpUond1mhccS3pchLhzSgPCnTimUCKj3IZE75pAs5m6heB2U2TMerKFUXheyHY+VDQ==} - engines: {node: '>=14'} - dependencies: - tr46: 4.1.1 - webidl-conversions: 7.0.0 - /whatwg-url@7.1.0: resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} dependencies: @@ -5210,16 +5050,13 @@ packages: optional: true utf-8-validate: optional: true + dev: false /xdg-basedir@5.1.0: resolution: {integrity: sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==} engines: {node: '>=12'} dev: false - /xml-name-validator@4.0.0: - resolution: {integrity: sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==} - engines: {node: '>=12'} - /xml2js@0.5.0: resolution: {integrity: sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==} engines: {node: '>=4.0.0'} @@ -5233,9 +5070,6 @@ packages: engines: {node: '>=4.0'} dev: false - /xmlchars@2.2.0: - resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==} - /y18n@5.0.8: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} diff --git a/scripts/build.ts b/scripts/build.ts index 42b33159..fcef3a01 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,12 +1,15 @@ import tsup from 'tsup'; import glob from 'fast-glob'; -import { printFileList } from '../src/core/log/printFileList'; -import { formatDuration } from '../src/core/utils/formatDuration'; +import { printFileList } from '~/core/utils/log'; +import { formatDuration } from '~/core/utils/time'; import ora from 'ora'; import fs from 'fs-extra'; import { consola } from 'consola'; +import pMap from 'p-map'; +import os from 'node:os'; -const spinner = ora('Building WXT').start(); +const spinnerText = 'Building WXT'; +const spinner = ora(spinnerText).start(); const startTime = Date.now(); const outDir = 'dist'; @@ -14,83 +17,92 @@ const virtualEntrypoints = ['background', 'content-script', 'unlisted-script']; await fs.rm(outDir, { recursive: true, force: true }); -await Promise.all([ - tsup.build({ - entry: { - index: 'src/index.ts', +const baseConfig: tsup.Options = { + format: ['cjs', 'esm'], + sourcemap: true, + dts: true, + silent: true, + external: ['vite'], +}; + +function spinnerPMap(configs: tsup.Options[]) { + let completed = 0; + const updateSpinner = () => { + spinner.text = `${spinnerText} [${completed}/${configs.length}]`; + }; + updateSpinner(); + + return pMap( + config, + async (config) => { + const res = await tsup.build(config); + completed++; + updateSpinner(); + return res; }, - format: ['cjs', 'esm'], - sourcemap: true, - dts: true, - silent: true, - external: ['vite'], - }), - tsup.build({ - entry: { cli: 'src/cli/index.ts' }, + { + stopOnError: true, + concurrency: process.env.CI === 'true' ? os.cpus().length : Infinity, + }, + ); +} + +const config: tsup.Options[] = [ + { + ...baseConfig, + entry: { index: 'src/index.ts' }, + }, + { + ...baseConfig, + entry: { cli: 'src/cli.ts' }, format: ['cjs'], sourcemap: 'inline', - silent: true, - external: ['vite'], - }), - tsup.build({ + }, + { + ...baseConfig, entry: { client: 'src/client/index.ts' }, - format: ['esm'], sourcemap: 'inline', - dts: true, - silent: true, - external: ['vite'], - }), - tsup.build({ - entry: { browser: 'src/client/browser.ts' }, + }, + { + ...baseConfig, + entry: { browser: 'src/browser.ts' }, format: ['esm'], - sourcemap: 'inline', - dts: true, - silent: true, - external: ['vite'], - }), - tsup.build({ - entry: { sandbox: 'src/client/sandbox/index.ts' }, + }, + { + ...baseConfig, + entry: { sandbox: 'src/sandbox/index.ts' }, format: ['esm'], - sourcemap: 'inline', - dts: true, - silent: true, - }), - tsup.build({ + }, + { + ...baseConfig, entry: { testing: 'src/testing/index.ts' }, - format: ['esm', 'cjs'], - sourcemap: 'inline', - dts: true, - silent: true, - }), - ...virtualEntrypoints.map((entryName) => - tsup.build({ + }, + ...virtualEntrypoints.map( + (entryName): tsup.Options => ({ + ...baseConfig, entry: { - [`virtual-modules/${entryName}-entrypoint`]: `src/client/virtual-modules/${entryName}-entrypoint.ts`, + [`virtual/${entryName}-entrypoint`]: `src/virtual/${entryName}-entrypoint.ts`, }, format: ['esm'], - sourcemap: true, - silent: true, external: [`virtual:user-${entryName}`, 'vite'], }), ), - tsup.build({ + { + ...baseConfig, entry: { - 'virtual-modules/reload-html': `src/client/virtual-modules/reload-html.ts`, + 'virtual/reload-html': `src/virtual/reload-html.ts`, }, format: ['esm'], - sourcemap: true, - silent: true, - external: ['vite'], - }), - tsup.build({ + }, + { + ...baseConfig, entry: { - 'virtual-modules/fake-browser': `src/client/virtual-modules/fake-browser.ts`, + 'virtual/mock-browser': `src/virtual/mock-browser.ts`, }, - format: ['esm', 'cjs'], - silent: true, - external: ['vite'], - }), -]).catch((err) => { + }, +]; + +await spinnerPMap(config).catch((err) => { spinner.fail(); console.error(err); process.exit(1); diff --git a/src/@types/modules.d.ts b/src/@types/modules.d.ts deleted file mode 100644 index cd6aa5d6..00000000 --- a/src/@types/modules.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -declare module 'zip-dir' { - // Represents the options object for zipdir function - interface ZipDirOptions { - saveTo?: string; - filter?: (path: string, stat: import('fs').Stats) => boolean; - each?: (path: string) => void; - } - - function zipdir( - dirPath: string, - options?: ZipDirOptions, - callback?: (error: Error | null, buffer: Buffer) => void, - ): Promise; - - export = zipdir; -} diff --git a/src/client/browser.ts b/src/browser.ts similarity index 100% rename from src/client/browser.ts rename to src/browser.ts diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 00000000..f49d6113 --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,164 @@ +import cac from 'cac'; +import { version } from '~/version'; +import { build, clean, createServer, initialize, prepare, zip } from '~/core'; +import consola, { LogLevels } from 'consola'; +import { printHeader } from '~/core/utils/log'; +import { formatDuration } from '~/core/utils/time'; + +const cli = cac('wxt'); +cli.help(); +cli.version(version); + +cli.option('--debug', 'enable debug mode'); + +// DEV +cli + .command('[root]', 'start dev server') + .option('-c, --config ', 'use specified config file') + .option('-m, --mode ', 'set env mode') + .option('-b, --browser ', 'specify a browser') + .option('--mv3', 'target manifest v3') + .option('--mv2', 'target manifest v2') + .action( + wrapAction(async (root, flags) => { + const server = await createServer({ + root, + mode: flags.mode, + browser: flags.browser, + manifestVersion: flags.mv3 ? 3 : flags.mv2 ? 2 : undefined, + configFile: flags.config, + debug: flags.debug, + }); + await server.start(); + return { isOngoing: true }; + }), + ); + +// BUILD +cli + .command('build [root]', 'build for production') + .option('-c, --config ', 'use specified config file') + .option('-m, --mode ', 'set env mode') + .option('-b, --browser ', 'specify a browser') + .option('--mv3', 'target manifest v3') + .option('--mv2', 'target manifest v2') + .option('--analyze', 'visualize extension bundle') + .action( + wrapAction(async (root, flags) => { + await build({ + root, + mode: flags.mode, + browser: flags.browser, + manifestVersion: flags.mv3 ? 3 : flags.mv2 ? 2 : undefined, + configFile: flags.config, + debug: flags.debug, + analysis: { + enabled: flags.analyze, + }, + }); + }), + ); + +// ZIP +cli + .command('zip [root]', 'build for production and zip output') + .option('-c, --config ', 'use specified config file') + .option('-m, --mode ', 'set env mode') + .option('-b, --browser ', 'specify a browser') + .option('--mv3', 'target manifest v3') + .option('--mv2', 'target manifest v2') + .action( + wrapAction(async (root, flags) => { + await zip({ + root, + mode: flags.mode, + browser: flags.browser, + manifestVersion: flags.mv3 ? 3 : flags.mv2 ? 2 : undefined, + configFile: flags.config, + debug: flags.debug, + }); + }), + ); + +// PREPARE +cli + .command('prepare [root]', 'prepare typescript project') + .option('-c, --config ', 'use specified config file') + .action( + wrapAction(async (root, flags) => { + await prepare({ + root, + configFile: flags.config, + debug: flags.debug, + }); + }), + ); + +// CLEAN +cli + .command('clean [root]', 'clean generated files and caches') + .alias('cleanup') + .action( + wrapAction(async (root, flags) => { + await clean(root); + }), + ); + +// INIT +cli + .command('init [directory]', 'initialize a new project') + .option('-t, --template