Skip to content

Commit

Permalink
feat!: switch from globby and fast-glob to tinyglobby (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Feb 26, 2025
1 parent 49df230 commit 19fd937
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 89 deletions.
95 changes: 30 additions & 65 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@
"webpack": "^5.1.0"
},
"dependencies": {
"fast-glob": "^3.3.2",
"glob-parent": "^6.0.1",
"globby": "^14.0.1",
"normalize-path": "^3.0.0",
"schema-utils": "^4.2.0",
"serialize-javascript": "^6.0.2"
"serialize-javascript": "^6.0.2",
"tinyglobby": "^0.2.12"
},
"devDependencies": {
"@babel/cli": "^7.24.6",
Expand Down
27 changes: 10 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,17 @@ const getSerializeJavascript = memoize(() =>
require("serialize-javascript"),
);

const getFastGlob = memoize(() =>
const getTinyGlobby = memoize(() =>
// eslint-disable-next-line global-require
require("fast-glob"),
require("tinyglobby"),
);

const getGlobby = memoize(async () => {
// @ts-ignore
const { globby } = await import("globby");

return globby;
});

/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
/** @typedef {import("webpack").WebpackError} WebpackError */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("globby").Options} GlobbyOptions */
/** @typedef {import("tinyglobby").GlobOptions} GlobbyOptions */
/** @typedef {ReturnType<Compilation["getLogger"]>} WebpackLogger */
/** @typedef {ReturnType<Compilation["getCache"]>} CacheFacade */
/** @typedef {ReturnType<ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]>} Etag */
Expand Down Expand Up @@ -267,7 +260,7 @@ class CopyPlugin {

/**
* @private
* @param {typeof import("globby").globby} globby
* @param {typeof import("tinyglobby").glob} globby
* @param {Compiler} compiler
* @param {Compilation} compilation
* @param {WebpackLogger} logger
Expand Down Expand Up @@ -339,10 +332,10 @@ class CopyPlugin {

/** @type {GlobbyOptions} */
const globOptions = {
absolute: true,
followSymbolicLinks: true,
...(pattern.globOptions || {}),
cwd: pattern.context,
objectMode: false,
onlyFiles: true,
};

Expand All @@ -359,7 +352,7 @@ class CopyPlugin {

pattern.context = absoluteFrom;
glob = path.posix.join(
getFastGlob().escapePath(
getTinyGlobby().escapePath(
getNormalizePath()(path.resolve(absoluteFrom)),
),
"**/*",
Expand All @@ -376,7 +369,7 @@ class CopyPlugin {
logger.debug(`added '${absoluteFrom}' as a file dependency`);

pattern.context = path.dirname(absoluteFrom);
glob = getFastGlob().escapePath(
glob = getTinyGlobby().escapePath(
getNormalizePath()(path.resolve(absoluteFrom)),
);

Expand All @@ -397,7 +390,7 @@ class CopyPlugin {
glob = path.isAbsolute(originalFrom)
? originalFrom
: path.posix.join(
getFastGlob().escapePath(
getTinyGlobby().escapePath(
getNormalizePath()(path.resolve(pattern.context)),
),
originalFrom,
Expand Down Expand Up @@ -815,7 +808,7 @@ class CopyPlugin {
const cache = compilation.getCache("CopyWebpackPlugin");

/**
* @type {typeof import("globby").globby}
* @type {typeof import("tinyglobby").glob}
*/
let globby;

Expand All @@ -827,7 +820,7 @@ class CopyPlugin {
async (unusedAssets, callback) => {
if (typeof globby === "undefined") {
try {
globby = await getGlobby();
globby = await getTinyGlobby().glob;
} catch (error) {
callback(/** @type {Error} */ (error));

Expand Down
Loading

0 comments on commit 19fd937

Please # to comment.