Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"jszip": "^3.10.1",
"linkedom": "^0.18.12",
"magicast": "^0.5.2",
"minimatch": "^10.2.4",
"nano-spawn": "^2.0.0",
"nanospinner": "^1.2.2",
"normalize-path": "^3.0.0",
Expand All @@ -52,6 +51,7 @@
"open": "^11.0.0",
"perfect-debounce": "^2.1.0",
"picocolors": "^1.1.1",
"picomatch": "^4.0.3",
"prompts": "^2.4.2",
"publish-browser-extension": "^2.3.0 || ^3.0.2 || ^4.0.4",
"scule": "^1.3.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/wxt/src/@types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ declare module 'web-ext-run/util/logger' {
}
export const consoleStream: IConsoleStream;
}

declare module 'picomatch' {
export interface PicomatchOptions {
[key: string]: unknown;
}

export default function picomatch(
glob: string | readonly string[],
options?: PicomatchOptions,
): (input: string) => boolean;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, it, expect } from 'vitest';
import { picomatchMultiple } from '../picomatch-multiple';

describe('picomatchMultiple', () => {
it('should return false if the pattern array is undefined', () => {
const patterns = undefined;
const search = 'test.json';

expect(picomatchMultiple(search, patterns)).toBe(false);
});

it('should return false if the pattern array is empty', () => {
const patterns: string[] = [];
const search = 'test.json';

expect(picomatchMultiple(search, patterns)).toBe(false);
});

it('should return true if the pattern array contains a match', () => {
const patterns = ['test.yml', 'test.json'];
const search = 'test.json';

expect(picomatchMultiple(search, patterns)).toBe(true);
});

it('should return false if the pattern array does not contain a match', () => {
const patterns = ['test.yml', 'test.json'];
const search = 'test.txt';

expect(picomatchMultiple(search, patterns)).toBe(false);
});

it('should return false if the pattern matches a negative pattern', () => {
const patterns = ['test.*', '!test.json'];
const search = 'test.json';

expect(picomatchMultiple(search, patterns)).toBe(false);
});

it('should return false if the pattern matches a negative pattern, regardless of order', () => {
const patterns = ['!test.json', 'test.*'];
const search = 'test.json';

expect(picomatchMultiple(search, patterns)).toBe(false);
});

it('should support extglob-like extension matching', () => {
const patterns = ['content.[jt]s?(x)'];

expect(picomatchMultiple('content.ts', patterns)).toBe(true);
expect(picomatchMultiple('content.jsx', patterns)).toBe(true);
expect(picomatchMultiple('content.css', patterns)).toBe(false);
});

it('should support nested paths', () => {
const patterns = ['foo/**/*.ts'];

expect(picomatchMultiple('foo/bar/baz.ts', patterns)).toBe(true);
expect(picomatchMultiple('foo/bar/baz.js', patterns)).toBe(false);
});

it('should preserve include/exclude interaction used by zip filtering', () => {
const include = ['special.txt'];
const exclude = ['**/*.txt'];
const search = 'special.txt';
const shouldInclude =
picomatchMultiple(search, include) || !picomatchMultiple(search, exclude);

expect(shouldInclude).toBe(true);
});
});
4 changes: 2 additions & 2 deletions packages/wxt/src/core/utils/building/find-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UnlistedScriptEntrypoint,
} from '../../../types';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { minimatch } from 'minimatch';
import picomatch from 'picomatch';
import { parseHTML } from 'linkedom';
import JSON5 from 'json5';
import { glob } from 'tinyglobby';
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function findEntrypoints(): Promise<Entrypoint[]> {
const inputPath = resolve(wxt.config.entrypointsDir, relativePath);
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
const matchingGlob = pathGlobs.find((glob) =>
minimatch(relativePath, glob),
picomatch(glob)(relativePath),
);
if (matchingGlob) {
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { minimatch, MinimatchOptions } from 'minimatch';
import picomatch, { PicomatchOptions } from 'picomatch';

/**
* Run [`minimatch`](https://npmjs.com/package/minimatch) against multiple
* Run [`picomatch`](https://npmjs.com/package/picomatch) against multiple
* patterns.
*
* Supports negated patterns, the order does not matter. If your `search` string
* matches any of the negative patterns, it will return `false`.
*
* @example
* ```ts
* minimatchMultiple('a.json', ['*.json', '!b.json']); // => true
* minimatchMultiple('b.json', ['*.json', '!b.json']); // => false
* picomatchMultiple('a.json', ['*.json', '!b.json']); // => true
* picomatchMultiple('b.json', ['*.json', '!b.json']); // => false
* ```;
*/
export function minimatchMultiple(
export function picomatchMultiple(
search: string,
patterns: string[] | undefined,
options?: MinimatchOptions,
options?: PicomatchOptions,
): boolean {
if (patterns == null) return false;

Expand All @@ -29,12 +29,12 @@ export function minimatchMultiple(

if (
negatePatterns.some((negatePattern) =>
minimatch(search, negatePattern, options),
picomatch(negatePattern, options)(search),
)
)
return false;

return positivePatterns.some((positivePattern) =>
minimatch(search, positivePattern, options),
picomatch(positivePattern, options)(search),
);
}
6 changes: 3 additions & 3 deletions packages/wxt/src/core/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { registerWxt, wxt } from './wxt';
import JSZip from 'jszip';
import { glob } from 'tinyglobby';
import { normalizePath } from './utils';
import { minimatchMultiple } from './utils/minimatch-multiple';
import { picomatchMultiple } from './utils/picomatch-multiple';

/**
* Build and zip the extension for distribution.
Expand Down Expand Up @@ -125,8 +125,8 @@ async function zipDir(
})
).filter((relativePath) => {
return (
minimatchMultiple(relativePath, options?.include) ||
!minimatchMultiple(relativePath, options?.exclude)
picomatchMultiple(relativePath, options?.include) ||
!picomatchMultiple(relativePath, options?.exclude)
);
});
const filesToZip = [
Expand Down
6 changes: 3 additions & 3 deletions packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export interface InlineConfig {
*/
sourcesRoot?: string;
/**
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to
* [Picomatch](https://www.npmjs.com/package/picomatch) patterns of files to
* include when creating a ZIP of all your source code for Firefox. Patterns
* are relative to your `config.zip.sourcesRoot`.
*
Expand All @@ -226,7 +226,7 @@ export interface InlineConfig {
*/
includeSources?: string[];
/**
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to
* [Picomatch](https://www.npmjs.com/package/picomatch) patterns of files to
* exclude when creating a ZIP of all your source code for Firefox. Patterns
* are relative to your `config.zip.sourcesRoot`.
*
Expand All @@ -239,7 +239,7 @@ export interface InlineConfig {
*/
excludeSources?: string[];
/**
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to
* [Picomatch](https://www.npmjs.com/package/picomatch) patterns of files to
* exclude when zipping the extension.
*
* @example
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

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