diff --git a/dev-packages/native-webpack-plugin/src/native-webpack-plugin.ts b/dev-packages/native-webpack-plugin/src/native-webpack-plugin.ts index 56bcec68b4f6c..e3324c1d400f4 100644 --- a/dev-packages/native-webpack-plugin/src/native-webpack-plugin.ts +++ b/dev-packages/native-webpack-plugin/src/native-webpack-plugin.ts @@ -91,6 +91,7 @@ export class NativeWebpackPlugin { } ); compiler.hooks.afterEmit.tapAsync(NativeWebpackPlugin.name, async () => { + await this.copyTrashHelper(compiler); if (this.options.ripgrep) { await this.copyRipgrep(compiler); } @@ -127,6 +128,21 @@ export class NativeWebpackPlugin { } } + protected async copyTrashHelper(compiler: Compiler): Promise { + let sourceFile: string | undefined; + let targetFile: string | undefined; + if (process.platform === 'win32') { + sourceFile = require.resolve('trash/lib/windows-trash.exe'); + targetFile = path.join(compiler.outputPath, 'windows-trash.exe'); + } else if (process.platform === 'darwin') { + sourceFile = require.resolve('trash/lib/macos-trash'); + targetFile = path.join(compiler.outputPath, 'macos-trash'); + } + if (sourceFile && targetFile) { + await this.copyExecutable(sourceFile, targetFile); + } + } + protected async copyExecutable(source: string, target: string): Promise { const targetDirectory = path.dirname(target); await fs.promises.mkdir(targetDirectory, { recursive: true });