Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 13 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const getGlobby = memoize(async () => {
/** @typedef {import("webpack").WebpackError} WebpackError */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("globby").Options} GlobbyOptions */
/** @typedef {import("globby").GlobEntry} GlobEntry */
/** @typedef {ReturnType<Compilation["getLogger"]>} WebpackLogger */
/** @typedef {ReturnType<Compilation["getCache"]>} CacheFacade */
/** @typedef {ReturnType<ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]>} Etag */
Expand Down Expand Up @@ -338,11 +337,13 @@ class CopyPlugin {
logger.debug(`determined '${absoluteFrom}' is a glob`);
}

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

// @ts-ignore
Expand Down Expand Up @@ -407,12 +408,14 @@ class CopyPlugin {
logger.log(`begin globbing '${glob}'...`);

/**
* @type {GlobEntry[]}
* @type {string[]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the typedef change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objectMode: true changes the return type from the default string[] to GlobEntry[]. Since we've removed objectMode: true we can go back to string[], which is simpler and has better performance

*/
let globEntries;

try {
globEntries = await globby(glob, globOptions);
globEntries = globOptions.onlyDirectories
Copy link
Member

@alexander-akait alexander-akait Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid it and just add the onlyDirectories doesn't supported in documentation. It doesn't make sense for our plugin anyway.

? []
: await globby(glob, globOptions);
} catch (error) {
compilation.errors.push(/** @type {WebpackError} */ (error));

Expand Down Expand Up @@ -444,34 +447,29 @@ class CopyPlugin {
copiedResult = await Promise.all(
globEntries.map(
/**
* @param {GlobEntry} globEntry
* @param {string} globEntry
* @returns {Promise<CopiedResult | undefined>}
*/
async (globEntry) => {
// Exclude directories
if (!globEntry.dirent.isFile()) {
return;
}

if (pattern.filter) {
let isFiltered;

try {
isFiltered = await pattern.filter(globEntry.path);
isFiltered = await pattern.filter(globEntry);
} catch (error) {
compilation.errors.push(/** @type {WebpackError} */ (error));

return;
}

if (!isFiltered) {
logger.log(`skip '${globEntry.path}', because it was filtered`);
logger.log(`skip '${globEntry}', because it was filtered`);

return;
}
}

const from = globEntry.path;
const from = globEntry;

logger.debug(`found '${from}'`);

Expand Down
3 changes: 0 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export = CopyPlugin;
/** @typedef {import("webpack").WebpackError} WebpackError */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("globby").Options} GlobbyOptions */
/** @typedef {import("globby").GlobEntry} GlobEntry */
/** @typedef {ReturnType<Compilation["getLogger"]>} WebpackLogger */
/** @typedef {ReturnType<Compilation["getCache"]>} CacheFacade */
/** @typedef {ReturnType<ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]>} Etag */
Expand Down Expand Up @@ -165,7 +164,6 @@ declare namespace CopyPlugin {
WebpackError,
Asset,
GlobbyOptions,
GlobEntry,
WebpackLogger,
CacheFacade,
Etag,
Expand Down Expand Up @@ -198,7 +196,6 @@ type Compilation = import("webpack").Compilation;
type WebpackError = import("webpack").WebpackError;
type Asset = import("webpack").Asset;
type GlobbyOptions = import("globby").Options;
type GlobEntry = import("globby").GlobEntry;
type WebpackLogger = ReturnType<Compilation["getLogger"]>;
type CacheFacade = ReturnType<Compilation["getCache"]>;
type Etag = ReturnType<
Expand Down