Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { rename } from 'node:fs/promises';
import { dirname, basename, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { build, type Plugin } from 'esbuild';

import { moveFile } from './files.js';
import { swallowTopLevelExportsPlugin } from './swallowTopLevelExportsPlugin.js';

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -197,8 +197,8 @@ export async function bundle(
inject,
});

await rename(bundle, outfile);
await moveFile(bundle, outfile);
if (enableStackTraces) {
await rename(bundle + '.map', outfile + '.map');
await moveFile(bundle + '.map', outfile + '.map');
}
}
2 changes: 1 addition & 1 deletion src/compileApplicationToWasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { rmSync } from 'node:fs';
import weval from '@bytecodealliance/weval';
import wizer from '@bytecodealliance/wizer';

import { isDirectory, isFile } from './isFile.js';
import { isDirectory, isFile } from './files.js';
import { postbundle } from './postbundle.js';
import { bundle } from './bundle.js';
import { composeSourcemaps, ExcludePattern } from './composeSourcemaps.js';
Expand Down
34 changes: 34 additions & 0 deletions src/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { stat, rename, copyFile, unlink } from 'node:fs/promises';

export async function isFile(path: string) {
const stats = await stat(path);
return stats.isFile();
}

export async function isDirectory(path: string) {
const stats = await stat(path);
return stats.isDirectory();
}

export async function moveFile(src: string, dest: string): Promise<void> {
try {
await rename(src, dest);
} catch (err: unknown) {
if (!isErrnoException(err) || err.code !== 'EXDEV') {
throw err;
}

// Cross-device move: copy + delete
await copyFile(src, dest);
await unlink(src);
}
}

function isErrnoException(err: unknown): err is NodeJS.ErrnoException {
return (
typeof err === 'object' &&
err !== null &&
'code' in err &&
typeof err.code === 'string'
);
}
11 changes: 0 additions & 11 deletions src/isFile.ts

This file was deleted.

Loading