diff --git a/deps.ts b/deps.ts index c65f49b..e8ea477 100644 --- a/deps.ts +++ b/deps.ts @@ -7,7 +7,7 @@ export { resolve, toFileUrl, } from "https://deno.land/std@0.173.0/path/mod.ts"; -export { copy } from "https://deno.land/std@0.173.0/fs/mod.ts"; +export { copy, exists, move } from "https://deno.land/std@0.173.0/fs/mod.ts"; export { basename, extname } from "https://deno.land/std@0.173.0/path/mod.ts"; export * as JSONC from "https://deno.land/std@0.173.0/encoding/jsonc.ts"; export { encode as base32Encode } from "https://deno.land/std@0.173.0/encoding/base32.ts"; diff --git a/src/loader_native.ts b/src/loader_native.ts index 4f17619..fc3ee8b 100644 --- a/src/loader_native.ts +++ b/src/loader_native.ts @@ -3,8 +3,10 @@ import { DenoDir, dirname, esbuild, + exists, fromFileUrl, join, + move, } from "../deps.ts"; import * as deno from "./deno.ts"; import { @@ -120,21 +122,16 @@ export class NativeLoader implements Loader { // check if the package is already linked, if so, return the link and skip // a bunch of work - try { - await Deno.stat(linkDir); - this.#linkDirCache.set(npmPackageId, linkDir); - return linkDir; - } catch { - // directory does not yet exist - } + if (await exists(linkDir)) return linkDir; // create a temporary directory, recursively hardlink the package contents // into it, and then rename it to the final location const tmpDir = await Deno.makeTempDir(); + await linkRecursive(packageDir, tmpDir); try { await Deno.mkdir(linkDirParent, { recursive: true }); - await Deno.rename(tmpDir, linkDir); + await move(tmpDir, linkDir); } catch (err) { if (err instanceof Deno.errors.AlreadyExists) { // ignore