Skip to content

Commit

Permalink
Bundle trash dependency helpers in backend (#12797)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Aug 22, 2023
1 parent a2a42b7 commit 628d6d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dev-packages/native-webpack-plugin/src/native-webpack-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -127,6 +128,21 @@ export class NativeWebpackPlugin {
}
}

protected async copyTrashHelper(compiler: Compiler): Promise<void> {
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<void> {
const targetDirectory = path.dirname(target);
await fs.promises.mkdir(targetDirectory, { recursive: true });
Expand Down

0 comments on commit 628d6d2

Please sign in to comment.