From e5a8479de05976bdb770228919aabc0d96b430d6 Mon Sep 17 00:00:00 2001 From: linbudu Date: Sun, 26 Mar 2023 14:49:15 +0800 Subject: [PATCH] =?UTF-8?q?release(esbuild):=20=F0=9F=8F=B9=20Release=20es?= =?UTF-8?q?build-plugin-copy@2.1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/esbuild-plugin-copy/.gitignore | 1 + packages/esbuild-plugin-copy/.npmignore | 3 ++- packages/esbuild-plugin-copy/CHANGELOG.md | 6 +++++- packages/esbuild-plugin-copy/package.json | 2 +- .../src/lib/esbuild-plugin-copy.ts | 2 +- .../esbuild-plugin-copy/src/lib/handler.ts | 9 +++----- .../esbuild-plugin-copy/tests/plugin.spec.ts | 21 +++++++++++++++++++ 7 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 packages/esbuild-plugin-copy/.gitignore diff --git a/packages/esbuild-plugin-copy/.gitignore b/packages/esbuild-plugin-copy/.gitignore new file mode 100644 index 0000000..b2c1e5c --- /dev/null +++ b/packages/esbuild-plugin-copy/.gitignore @@ -0,0 +1 @@ +issues \ No newline at end of file diff --git a/packages/esbuild-plugin-copy/.npmignore b/packages/esbuild-plugin-copy/.npmignore index cdfd266..b97c1cd 100644 --- a/packages/esbuild-plugin-copy/.npmignore +++ b/packages/esbuild-plugin-copy/.npmignore @@ -1,2 +1,3 @@ src -tests \ No newline at end of file +tests +issues \ No newline at end of file diff --git a/packages/esbuild-plugin-copy/CHANGELOG.md b/packages/esbuild-plugin-copy/CHANGELOG.md index 4274221..9fda5a0 100644 --- a/packages/esbuild-plugin-copy/CHANGELOG.md +++ b/packages/esbuild-plugin-copy/CHANGELOG.md @@ -1,8 +1,12 @@ # CHANGELOG +## Release 2.1.1 + +- BugFix: When copy with `file-to-file`, and the `to` path contains nested unexist path, the plugin will throw error as it doesnot create the nested path by `fs.ensureDirSync`. + ## Release 2.1.0 -- Feature: `Watc hMode` support for plugin-level and asset pair level. +- Feature: `Watch Mode` support for plugin-level and asset pair level. ## Released 2.0.1 diff --git a/packages/esbuild-plugin-copy/package.json b/packages/esbuild-plugin-copy/package.json index 6baee8c..a751b2b 100644 --- a/packages/esbuild-plugin-copy/package.json +++ b/packages/esbuild-plugin-copy/package.json @@ -1,6 +1,6 @@ { "name": "esbuild-plugin-copy", - "version": "2.1.0", + "version": "2.1.1", "description": "ESBuild plugin for assets copy.", "keywords": [ "esbuild", diff --git a/packages/esbuild-plugin-copy/src/lib/esbuild-plugin-copy.ts b/packages/esbuild-plugin-copy/src/lib/esbuild-plugin-copy.ts index dd5c114..53384cf 100644 --- a/packages/esbuild-plugin-copy/src/lib/esbuild-plugin-copy.ts +++ b/packages/esbuild-plugin-copy/src/lib/esbuild-plugin-copy.ts @@ -104,7 +104,7 @@ export const copy = (options: Partial = {}): Plugin => { if (!build.initialOptions.watch) { verboseLog( - `Watching mode diabled. You need to enable ${chalk.white( + `Watching mode disabled. You need to enable ${chalk.white( 'build.watch' )} option for watch mode to work.`, verbose diff --git a/packages/esbuild-plugin-copy/src/lib/handler.ts b/packages/esbuild-plugin-copy/src/lib/handler.ts index 59c3db3..53ede14 100644 --- a/packages/esbuild-plugin-copy/src/lib/handler.ts +++ b/packages/esbuild-plugin-copy/src/lib/handler.ts @@ -57,7 +57,8 @@ export function copyOperationHandler( const isToPathDir = path.extname(baseToPath) === ''; const composedDistDirPath = isToPathDir - ? path.resolve( + ? // /RESOLVE_FROM_DIR/SPECIFIED_TO_DIR/LEFT_FILE_STRUCTURE + path.resolve( // base resolve destination dir outDirResolveFrom, // configures destination dir @@ -72,11 +73,7 @@ export function copyOperationHandler( baseToPath ); - dryRun - ? void 0 - : isToPathDir - ? fs.ensureDirSync(path.dirname(composedDistDirPath)) - : void 0; + dryRun ? void 0 : fs.ensureDirSync(path.dirname(composedDistDirPath)); dryRun ? void 0 : fs.copyFileSync(sourcePath, composedDistDirPath); diff --git a/packages/esbuild-plugin-copy/tests/plugin.spec.ts b/packages/esbuild-plugin-copy/tests/plugin.spec.ts index 22ac4b7..8fe9cbb 100644 --- a/packages/esbuild-plugin-copy/tests/plugin.spec.ts +++ b/packages/esbuild-plugin-copy/tests/plugin.spec.ts @@ -372,6 +372,27 @@ describe('CopyPlugin:Core', async () => { expect(d1).toEqual(['hello.txt', 'index.js']); }); + it.only('should copy from file to file with nested dest dir', async () => { + const outDir = tmp.dirSync().name; + + await builder( + outDir, + { outdir: outDir }, + { + assets: { + from: path.resolve(__dirname, './fixtures/assets/note.txt'), + to: './unexist/nest/dir/hello.txt', + }, + resolveFrom: 'out', + verbose: false, + dryRun: false, + } + ); + + const d1 = fs.readdirSync(path.join(outDir, 'unexist/nest/dir'), {}); + + expect(d1).toEqual(['hello.txt']); + }); }); describe('CopyPlugin:Utils', async () => {