Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't use sub-dependency binaries directly #482

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bin/wxt-publish-extension.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +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');
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
"bin",
"dist"
],
"bin": "./bin/wxt.mjs",
"bin": {
"wxt": "./bin/wxt.mjs",
"wxt-publish-extension": "./bin/wxt-publish-extension.cjs"
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -103,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",
Expand All @@ -125,15 +129,13 @@
"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",
"ora": "^7.0.1",
"picocolors": "^1.0.0",
"prompts": "^2.4.2",
"publish-browser-extension": "^2.1.2",
"rollup-plugin-visualizer": "^5.9.2",
"publish-browser-extension": "^2.1.3",
"unimport": "^3.4.0",
"vite": "^5.1.3",
"web-ext-run": "^0.2.0",
Expand Down
53 changes: 23 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/cli/cli-utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -63,10 +62,18 @@
}

const aliasCommandNames = new Set<string>();
/**
* @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
Expand All @@ -79,7 +86,8 @@
const args = process.argv.slice(
process.argv.indexOf(aliasedCommand.name) + 1,
);
await exec(alias, args, {
const { execa } = await import('execa');
await execa(bin, args, {

Check warning on line 90 in src/cli/cli-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/cli-utils.ts#L89-L90

Added lines #L89 - L90 were not covered by tests
stdio: 'inherit',
});
} catch {
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ createAliasedCommand(
cli,
'submit',
'publish-extension',
'wxt-publish-extension',
'https://www.npmjs.com/publish-browser-extension',
);

Expand Down
2 changes: 1 addition & 1 deletion src/core/builders/vite/plugins/bundleAnalysis.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
18 changes: 6 additions & 12 deletions src/core/utils/building/internal-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
validateEntrypoints,
} from '../validation';
import consola from 'consola';
import { exec } from '../exec';
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
Expand Down Expand Up @@ -93,17 +93,11 @@ async function combineAnalysisStats(): Promise<void> {
});
const absolutePaths = unixFiles.map(unnormalizePath);

await exec(
'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)));
Expand Down
26 changes: 0 additions & 26 deletions src/core/utils/exec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 0 additions & 12 deletions src/types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down