diff --git a/README.md b/README.md index c49d4c2..fb9f9bd 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,10 @@ The use of `context` is illustrated by these [`examples`](#examples). #### `globOptions` +> [!WARNING] +> +> The _onlyDirectories_ does not work because the plugin is designed to copy files. + Type: ```ts diff --git a/src/index.js b/src/index.js index de80f1d..250933d 100644 --- a/src/index.js +++ b/src/index.js @@ -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} WebpackLogger */ /** @typedef {ReturnType} CacheFacade */ /** @typedef {ReturnType["getLazyHashedEtag"]>} Etag */ @@ -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 @@ -407,7 +408,7 @@ class CopyPlugin { logger.log(`begin globbing '${glob}'...`); /** - * @type {GlobEntry[]} + * @type {string[]} */ let globEntries; @@ -444,20 +445,15 @@ class CopyPlugin { copiedResult = await Promise.all( globEntries.map( /** - * @param {GlobEntry} globEntry + * @param {string} globEntry * @returns {Promise} */ 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)); @@ -465,13 +461,13 @@ class CopyPlugin { } 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}'`); diff --git a/test/globOptions-option.test.js b/test/globOptions-option.test.js index 0db6709..eda0fa7 100644 --- a/test/globOptions-option.test.js +++ b/test/globOptions-option.test.js @@ -400,23 +400,6 @@ describe("globOptions option", () => { .catch(done); }); - it('should work with the "onlyDirectories" option', (done) => { - runEmit({ - expectedAssetKeys: [], - patterns: [ - { - noErrorOnMissing: true, - from: "directory", - globOptions: { - onlyDirectories: true, - }, - }, - ], - }) - .then(done) - .catch(done); - }); - it("should emit error when not found assets for copy", (done) => { expect.assertions(1); diff --git a/types/index.d.ts b/types/index.d.ts index 2d8a973..97267cc 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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} WebpackLogger */ /** @typedef {ReturnType} CacheFacade */ /** @typedef {ReturnType["getLazyHashedEtag"]>} Etag */ @@ -165,7 +164,6 @@ declare namespace CopyPlugin { WebpackError, Asset, GlobbyOptions, - GlobEntry, WebpackLogger, CacheFacade, Etag, @@ -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; type CacheFacade = ReturnType; type Etag = ReturnType<