From efecebd04357f19d05aa12cae04c988ee60226aa Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Fri, 23 Feb 2024 13:17:50 -0600 Subject: [PATCH 1/5] fix: Resolve aliased commands properly --- bin/wxt-publish-extension.mjs | 2 ++ bin/wxt-rollup-plugin-visualizer.mjs | 2 ++ src/cli/cli-utils.ts | 4 ++-- src/core/utils/building/internal-build.ts | 4 ++-- src/core/utils/exec.ts | 26 ----------------------- src/types/modules.d.ts | 12 ----------- 6 files changed, 8 insertions(+), 42 deletions(-) create mode 100755 bin/wxt-publish-extension.mjs create mode 100755 bin/wxt-rollup-plugin-visualizer.mjs delete mode 100644 src/core/utils/exec.ts diff --git a/bin/wxt-publish-extension.mjs b/bin/wxt-publish-extension.mjs new file mode 100755 index 000000000..205e0a81b --- /dev/null +++ b/bin/wxt-publish-extension.mjs @@ -0,0 +1,2 @@ +#!/usr/bin/env node +await import('publish-browser-extension/dist/cli.cjs'); diff --git a/bin/wxt-rollup-plugin-visualizer.mjs b/bin/wxt-rollup-plugin-visualizer.mjs new file mode 100755 index 000000000..6b64a507e --- /dev/null +++ b/bin/wxt-rollup-plugin-visualizer.mjs @@ -0,0 +1,2 @@ +#!/usr/bin/env node +await import('rollup-plugin-visualizer/dist/bin/cli.js'); diff --git a/src/cli/cli-utils.ts b/src/cli/cli-utils.ts index b48241fc4..f67b652a8 100644 --- a/src/cli/cli-utils.ts +++ b/src/cli/cli-utils.ts @@ -1,6 +1,5 @@ import { CAC, Command } from 'cac'; import consola, { LogLevels } from 'consola'; -import { exec } from '~/core/utils/exec'; import { printHeader } from '~/core/utils/log'; import { formatDuration } from '~/core/utils/time'; import { ValidationError } from '~/core/utils/validation'; @@ -79,7 +78,8 @@ export function createAliasedCommand( const args = process.argv.slice( process.argv.indexOf(aliasedCommand.name) + 1, ); - await exec(alias, args, { + const { execa } = await import('execa'); + await execa(alias, args, { stdio: 'inherit', }); } catch { diff --git a/src/core/utils/building/internal-build.ts b/src/core/utils/building/internal-build.ts index ce8816a10..bcf30081e 100644 --- a/src/core/utils/building/internal-build.ts +++ b/src/core/utils/building/internal-build.ts @@ -16,7 +16,6 @@ import { validateEntrypoints, } from '../validation'; import consola from 'consola'; -import { exec } from '../exec'; import { wxt } from '../../wxt'; /** @@ -93,7 +92,8 @@ async function combineAnalysisStats(): Promise { }); const absolutePaths = unixFiles.map(unnormalizePath); - await exec( + const { execa } = await import('execa'); + await execa( 'rollup-plugin-visualizer', [ ...absolutePaths, diff --git a/src/core/utils/exec.ts b/src/core/utils/exec.ts deleted file mode 100644 index 8574cb437..000000000 --- a/src/core/utils/exec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { Options } from 'execa'; -import managePath from 'manage-path'; -import { resolve } from 'node:path'; -import { wxt } from '../wxt'; - -const managedPath = managePath(process.env); - -/** - * Wrapper around `execa` with a modified `PATH` variable containing CLI tools from WXT's dependencies. - */ -export const exec = async ( - file: string, - args?: readonly string[], - options?: Options, -) => { - // Reset so the same path isn't added multiple times - managedPath.restore(); - - // Add subdependency path for PNPM shamefully-hoist=false - managedPath.push( - resolve(wxt.config.root, 'node_modules/wxt/node_modules/.bin'), - ); - - const { execa } = await import('execa'); - return await execa(file, args, options); -}; diff --git a/src/types/modules.d.ts b/src/types/modules.d.ts index c424b5323..49fb40ff4 100644 --- a/src/types/modules.d.ts +++ b/src/types/modules.d.ts @@ -50,18 +50,6 @@ declare module 'web-ext-run/util/logger' { export const consoleStream: IConsoleStream; } -declare module 'manage-path' { - export interface ManagedPath { - push(...paths: string[]); - push(paths: string[]); - shift(...paths: string[]); - shift(paths: string[]); - get(): string; - restore(): void; - } - export default function managePath(env: object): ManagedPath; -} - declare module 'wxt/browser' { // Overridden when types are generated per project export type PublicPath = string; From edbe14a7db66cb8c77afd9a4e411929dbb1136dd Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Fri, 23 Feb 2024 13:18:15 -0600 Subject: [PATCH 2/5] Cleanup --- package.json | 9 ++++++--- pnpm-lock.yaml | 7 ------- src/cli/commands.ts | 2 +- src/core/utils/building/internal-build.ts | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5851ccfd5..71052e3df 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wxt", "type": "module", - "version": "0.17.1", + "version": "0.17.2-alpha1", "description": "Next gen framework for developing web extensions", "engines": { "node": ">=18", @@ -30,7 +30,11 @@ "bin", "dist" ], - "bin": "./bin/wxt.mjs", + "bin": { + "wxt": "./bin/wxt.mjs", + "wxt-publish-extension": "./bin/wxt-publish-extension.mjs", + "wxt-rollup-plugin-visualizer": "./bin/wxt-rollup-plugin-visualizer.mjs" + }, "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", @@ -125,7 +129,6 @@ "jiti": "^1.21.0", "json5": "^2.2.3", "linkedom": "^0.16.1", - "manage-path": "^2.0.0", "minimatch": "^9.0.3", "natural-compare": "^1.4.0", "normalize-path": "^3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c3eacf9e..66601cfa4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,9 +74,6 @@ importers: linkedom: specifier: ^0.16.1 version: 0.16.1 - manage-path: - specifier: ^2.0.0 - version: 2.0.0 minimatch: specifier: ^9.0.3 version: 9.0.3 @@ -3544,10 +3541,6 @@ packages: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} dev: false - /manage-path@2.0.0: - resolution: {integrity: sha512-NJhyB+PJYTpxhxZJ3lecIGgh4kwIY2RAh44XvAz9UlqthlQwtPBf62uBVR8XaD8CRuSjQ6TnZH2lNJkbLPZM2A==} - dev: false - /mark.js@8.11.1: resolution: {integrity: sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==} dev: true diff --git a/src/cli/commands.ts b/src/cli/commands.ts index 57e5a9306..c3d482186 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -139,7 +139,7 @@ cli createAliasedCommand( cli, 'submit', - 'publish-extension', + 'wxt-publish-extension', 'https://www.npmjs.com/publish-browser-extension', ); diff --git a/src/core/utils/building/internal-build.ts b/src/core/utils/building/internal-build.ts index bcf30081e..d599959f0 100644 --- a/src/core/utils/building/internal-build.ts +++ b/src/core/utils/building/internal-build.ts @@ -94,7 +94,7 @@ async function combineAnalysisStats(): Promise { const { execa } = await import('execa'); await execa( - 'rollup-plugin-visualizer', + 'wxt-rollup-plugin-visualizer', [ ...absolutePaths, '--template', From 99779eb6f8914c24cea5dad664651a8c8a5a4658 Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Fri, 23 Feb 2024 15:08:41 -0600 Subject: [PATCH 3/5] Fix submit error --- bin/wxt-publish-extension.cjs | 2 ++ bin/wxt-publish-extension.mjs | 2 -- bin/wxt-rollup-plugin-visualizer.mjs | 2 -- package.json | 7 +++---- pnpm-lock.yaml | 8 ++++---- 5 files changed, 9 insertions(+), 12 deletions(-) create mode 100755 bin/wxt-publish-extension.cjs delete mode 100755 bin/wxt-publish-extension.mjs delete mode 100755 bin/wxt-rollup-plugin-visualizer.mjs diff --git a/bin/wxt-publish-extension.cjs b/bin/wxt-publish-extension.cjs new file mode 100755 index 000000000..86253c078 --- /dev/null +++ b/bin/wxt-publish-extension.cjs @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('publish-browser-extension/cli'); diff --git a/bin/wxt-publish-extension.mjs b/bin/wxt-publish-extension.mjs deleted file mode 100755 index 205e0a81b..000000000 --- a/bin/wxt-publish-extension.mjs +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -await import('publish-browser-extension/dist/cli.cjs'); diff --git a/bin/wxt-rollup-plugin-visualizer.mjs b/bin/wxt-rollup-plugin-visualizer.mjs deleted file mode 100755 index 6b64a507e..000000000 --- a/bin/wxt-rollup-plugin-visualizer.mjs +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -await import('rollup-plugin-visualizer/dist/bin/cli.js'); diff --git a/package.json b/package.json index 71052e3df..9016fac3b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wxt", "type": "module", - "version": "0.17.2-alpha1", + "version": "0.17.2-alpha5", "description": "Next gen framework for developing web extensions", "engines": { "node": ">=18", @@ -32,8 +32,7 @@ ], "bin": { "wxt": "./bin/wxt.mjs", - "wxt-publish-extension": "./bin/wxt-publish-extension.mjs", - "wxt-rollup-plugin-visualizer": "./bin/wxt-rollup-plugin-visualizer.mjs" + "wxt-publish-extension": "./bin/wxt-publish-extension.cjs" }, "main": "./dist/index.cjs", "module": "./dist/index.js", @@ -135,7 +134,7 @@ "ora": "^7.0.1", "picocolors": "^1.0.0", "prompts": "^2.4.2", - "publish-browser-extension": "^2.1.2", + "publish-browser-extension": "^2.1.3", "rollup-plugin-visualizer": "^5.9.2", "unimport": "^3.4.0", "vite": "^5.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66601cfa4..d8490f6c4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,8 +93,8 @@ importers: specifier: ^2.4.2 version: 2.4.2 publish-browser-extension: - specifier: ^2.1.2 - version: 2.1.2 + specifier: ^2.1.3 + version: 2.1.3 rollup-plugin-visualizer: specifier: ^5.9.2 version: 5.12.0 @@ -4168,8 +4168,8 @@ packages: sade: 1.8.1 dev: true - /publish-browser-extension@2.1.2: - resolution: {integrity: sha512-g6+mtdR4Z+GYHPIrfaAwC7Kbt1oQlpJ8r0x1PAytScy33OFdK+HVUeDDYorBpPAiQlmYJRQga7rY9QVTyTw34g==} + /publish-browser-extension@2.1.3: + resolution: {integrity: sha512-qisnXUUwjvu5kMvObfG7UQ9rPU3t0XfbKdCdCrwAXaLUySdC25nlM4gxi+CBvL7LiwvK494GJyEK/weQBhIyTQ==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true dependencies: From bb3f14d31cec46a167ab599f78d379cd851befc4 Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Fri, 23 Feb 2024 15:35:25 -0600 Subject: [PATCH 4/5] Fix rollup-plugin-visualizer --- bin/wxt-publish-extension.cjs | 5 +++ package.json | 4 +- pnpm-lock.yaml | 38 +++++++++---------- src/cli/cli-utils.ts | 10 ++++- src/cli/commands.ts | 1 + .../builders/vite/plugins/bundleAnalysis.ts | 2 +- src/core/utils/building/internal-build.ts | 18 +++------ src/types/index.ts | 2 +- 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/bin/wxt-publish-extension.cjs b/bin/wxt-publish-extension.cjs index 86253c078..265200caa 100755 --- a/bin/wxt-publish-extension.cjs +++ b/bin/wxt-publish-extension.cjs @@ -1,2 +1,7 @@ #!/usr/bin/env node +/** + * A alias around `publish-extension` that is always installed on the path without having to install + * `publish-browser-extension` as a direct dependency (like for PNPM, which doesn't link + * sub-dependency binaries to "node_modules/.bin") + */ require('publish-browser-extension/cli'); diff --git a/package.json b/package.json index 9016fac3b..a24911ee0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wxt", "type": "module", - "version": "0.17.2-alpha5", + "version": "0.17.2-alpha6", "description": "Next gen framework for developing web extensions", "engines": { "node": ">=18", @@ -106,6 +106,7 @@ "sync-releases": "pnpx changelogen@latest gh release" }, "dependencies": { + "@aklinker1/rollup-plugin-visualizer": "5.12.0", "@types/webextension-polyfill": "^0.10.5", "@webext-core/fake-browser": "^1.3.1", "@webext-core/isolated-element": "^1.1.1", @@ -135,7 +136,6 @@ "picocolors": "^1.0.0", "prompts": "^2.4.2", "publish-browser-extension": "^2.1.3", - "rollup-plugin-visualizer": "^5.9.2", "unimport": "^3.4.0", "vite": "^5.1.3", "web-ext-run": "^0.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d8490f6c4..92d69cc11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@aklinker1/rollup-plugin-visualizer': + specifier: 5.12.0 + version: 5.12.0 '@types/webextension-polyfill': specifier: ^0.10.5 version: 0.10.7 @@ -95,9 +98,6 @@ importers: publish-browser-extension: specifier: ^2.1.3 version: 2.1.3 - rollup-plugin-visualizer: - specifier: ^5.9.2 - version: 5.12.0 unimport: specifier: ^3.4.0 version: 3.4.0 @@ -223,6 +223,22 @@ importers: packages: + /@aklinker1/rollup-plugin-visualizer@5.12.0: + resolution: {integrity: sha512-X24LvEGw6UFmy0lpGJDmXsMyBD58XmX1bbwsaMLhNoM+UMQfQ3b2RtC+nz4b/NoRK5r6QJSKJHBNVeUdwqybaQ==} + engines: {node: '>=14'} + hasBin: true + peerDependencies: + rollup: 2.x || 3.x || 4.x + peerDependenciesMeta: + rollup: + optional: true + dependencies: + open: 8.4.2 + picomatch: 2.3.1 + source-map: 0.7.4 + yargs: 17.7.2 + dev: false + /@algolia/autocomplete-core@1.9.3(algoliasearch@4.20.0): resolution: {integrity: sha512-009HdfugtGCdC4JdXUbVJClA0q0zh24yyePn+KUGk3rP7j8FEe/m5Yo/z65gn6nP/cM39PxpzqKrL7A6fP6PPw==} dependencies: @@ -4384,22 +4400,6 @@ packages: glob: 7.1.6 dev: false - /rollup-plugin-visualizer@5.12.0: - resolution: {integrity: sha512-8/NU9jXcHRs7Nnj07PF2o4gjxmm9lXIrZ8r175bT9dK8qoLlvKTwRMArRCMgpMGlq8CTLugRvEmyMeMXIU2pNQ==} - engines: {node: '>=14'} - hasBin: true - peerDependencies: - rollup: 2.x || 3.x || 4.x - peerDependenciesMeta: - rollup: - optional: true - dependencies: - open: 8.4.2 - picomatch: 2.3.1 - source-map: 0.7.4 - yargs: 17.7.2 - dev: false - /rollup@4.6.1: resolution: {integrity: sha512-jZHaZotEHQaHLgKr8JnQiDT1rmatjgKlMekyksz+yk9jt/8z9quNjnKNRoaM0wd9DC2QKXjmWWuDYtM3jfF8pQ==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} diff --git a/src/cli/cli-utils.ts b/src/cli/cli-utils.ts index f67b652a8..539b61162 100644 --- a/src/cli/cli-utils.ts +++ b/src/cli/cli-utils.ts @@ -62,10 +62,18 @@ export function getArrayFromFlags( } const aliasCommandNames = new Set(); +/** + * @param base Command to add this one to + * @param name The command name to add + * @param alias The CLI tool being aliased + * @param bin The CLI tool binary name. Usually the same as the alias + * @param docsUrl URL to the docs for the aliased CLI tool + */ export function createAliasedCommand( base: CAC, name: string, alias: string, + bin: string, docsUrl: string, ) { const aliasedCommand = base @@ -79,7 +87,7 @@ export function createAliasedCommand( process.argv.indexOf(aliasedCommand.name) + 1, ); const { execa } = await import('execa'); - await execa(alias, args, { + await execa(bin, args, { stdio: 'inherit', }); } catch { diff --git a/src/cli/commands.ts b/src/cli/commands.ts index c3d482186..b8133c100 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -139,6 +139,7 @@ cli createAliasedCommand( cli, 'submit', + 'publish-extension', 'wxt-publish-extension', 'https://www.npmjs.com/publish-browser-extension', ); diff --git a/src/core/builders/vite/plugins/bundleAnalysis.ts b/src/core/builders/vite/plugins/bundleAnalysis.ts index 150beb6b8..2468628b6 100644 --- a/src/core/builders/vite/plugins/bundleAnalysis.ts +++ b/src/core/builders/vite/plugins/bundleAnalysis.ts @@ -1,5 +1,5 @@ import type * as vite from 'vite'; -import { visualizer } from 'rollup-plugin-visualizer'; +import { visualizer } from '@aklinker1/rollup-plugin-visualizer'; import { ResolvedConfig } from '~/types'; import path from 'node:path'; diff --git a/src/core/utils/building/internal-build.ts b/src/core/utils/building/internal-build.ts index d599959f0..412694f13 100644 --- a/src/core/utils/building/internal-build.ts +++ b/src/core/utils/building/internal-build.ts @@ -17,6 +17,7 @@ import { } from '../validation'; import consola from 'consola'; import { wxt } from '../../wxt'; +import { mergeJsonOutputs } from '@aklinker1/rollup-plugin-visualizer'; /** * Builds the extension based on an internal config. No more config discovery is performed, the @@ -92,18 +93,11 @@ async function combineAnalysisStats(): Promise { }); const absolutePaths = unixFiles.map(unnormalizePath); - const { execa } = await import('execa'); - await execa( - 'wxt-rollup-plugin-visualizer', - [ - ...absolutePaths, - '--template', - wxt.config.analysis.template, - '--filename', - wxt.config.analysis.outputFile, - ], - { cwd: wxt.config.root, stdio: 'inherit' }, - ); + await mergeJsonOutputs({ + inputs: absolutePaths, + template: wxt.config.analysis.template, + filename: wxt.config.analysis.outputFile, + }); if (!wxt.config.analysis.keepArtifacts) { await Promise.all(absolutePaths.map((statsFile) => fs.remove(statsFile))); diff --git a/src/types/index.ts b/src/types/index.ts index c292e0ff4..8a0fef42b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,7 +3,7 @@ import type { Manifest, Scripting } from '~/browser'; import { UnimportOptions } from 'unimport'; import { LogLevel } from 'consola'; import { ContentScriptContext } from '../client/content-scripts/content-script-context'; -import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer'; +import type { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer'; import type { FSWatcher } from 'chokidar'; import { ResolvedConfig as C12ResolvedConfig } from 'c12'; import { Hookable, NestedHooks } from 'hookable'; From 36ba914fcc13c3775e8940a7aedfc1f1c20c4f2a Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Fri, 23 Feb 2024 15:42:44 -0600 Subject: [PATCH 5/5] Cleanup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a24911ee0..a2c12e6c0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wxt", "type": "module", - "version": "0.17.2-alpha6", + "version": "0.17.1", "description": "Next gen framework for developing web extensions", "engines": { "node": ">=18",