From 681993e7c3fbec89b052c762321bd2fd32dbfd2c Mon Sep 17 00:00:00 2001 From: Ajitomi Daisuke Date: Sat, 16 Nov 2024 18:08:07 +0900 Subject: [PATCH] base: add removeNodeModules. --- packages/chacha20poly1305/dnt.ts | 6 ++++-- packages/core/dnt.ts | 6 ++++-- packages/dhkem-secp256k1/dnt.ts | 6 ++++-- packages/dhkem-x25519/dnt.ts | 6 ++++-- packages/dhkem-x448/dnt.ts | 6 ++++-- packages/hpke-js/dnt.ts | 6 ++++-- packages/hybridkem-x-wing/dnt.ts | 6 ++++-- packages/hybridkem-x25519-kyber768/dnt.ts | 6 ++++-- packages/ml-kem/dnt.ts | 6 ++++-- utils/misc.ts | 24 +++++++++++++++++++++++ 10 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 utils/misc.ts diff --git a/packages/chacha20poly1305/dnt.ts b/packages/chacha20poly1305/dnt.ts index 4f91481f0..e66eb68be 100644 --- a/packages/chacha20poly1305/dnt.ts +++ b/packages/chacha20poly1305/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/chacha20poly1305"); await emptyDir("../../npm/samples/chacha20poly1305"); await emptyDir("../../npm/test/chacha20poly1305/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/core/dnt.ts b/packages/core/dnt.ts index 22f0a00b5..16b0fccef 100644 --- a/packages/core/dnt.ts +++ b/packages/core/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/core"); await emptyDir("../../npm/samples/core"); await emptyDir("../../npm/test/core/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/dhkem-secp256k1/dnt.ts b/packages/dhkem-secp256k1/dnt.ts index 2ce12252d..e96df1446 100644 --- a/packages/dhkem-secp256k1/dnt.ts +++ b/packages/dhkem-secp256k1/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/dhkem-secp256k1"); await emptyDir("../../npm/samples/dhkem-secp256k1"); await emptyDir("../../npm/test/dhkem-secp256k1/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/dhkem-x25519/dnt.ts b/packages/dhkem-x25519/dnt.ts index 55f48166b..cd3e2ce1b 100644 --- a/packages/dhkem-x25519/dnt.ts +++ b/packages/dhkem-x25519/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "jsr:@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/dhkem-x25519"); await emptyDir("../../npm/samples/dhkem-x25519"); await emptyDir("../../npm/test/dhkem-x25519/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/dhkem-x448/dnt.ts b/packages/dhkem-x448/dnt.ts index c42314cbd..ed4340e07 100644 --- a/packages/dhkem-x448/dnt.ts +++ b/packages/dhkem-x448/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/dhkem-x448"); await emptyDir("../../npm/samples/dhkem-x448"); await emptyDir("../../npm/test/dhkem-x448/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/hpke-js/dnt.ts b/packages/hpke-js/dnt.ts index 1ac192989..d1b13d151 100644 --- a/packages/hpke-js/dnt.ts +++ b/packages/hpke-js/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/hpke-js"); await emptyDir("../../npm/samples/hpke-js"); await emptyDir("../../npm/test/hpke-js/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/hybridkem-x-wing/dnt.ts b/packages/hybridkem-x-wing/dnt.ts index a76074475..b54edb278 100644 --- a/packages/hybridkem-x-wing/dnt.ts +++ b/packages/hybridkem-x-wing/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/hybridkem-x-wing"); await emptyDir("../../npm/samples/hybridkem-x-wing"); await emptyDir("../../npm/test/hybridkem-x-wing/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/hybridkem-x25519-kyber768/dnt.ts b/packages/hybridkem-x25519-kyber768/dnt.ts index c3dd31aa4..413d9c98f 100644 --- a/packages/hybridkem-x25519-kyber768/dnt.ts +++ b/packages/hybridkem-x25519-kyber768/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/hybridkem-x25519-kyber768"); await emptyDir("../../npm/samples/hybridkem-x25519-kyber768"); await emptyDir("../../npm/test/hybridkem-x25519-kyber768/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/packages/ml-kem/dnt.ts b/packages/ml-kem/dnt.ts index 8ac0c46a9..067590912 100644 --- a/packages/ml-kem/dnt.ts +++ b/packages/ml-kem/dnt.ts @@ -1,12 +1,14 @@ import { build, emptyDir } from "@deno/dnt"; import { copySync } from "@std/fs"; +import { removeNodeModules } from "../../utils/misc.ts"; +// clean up dist await emptyDir("../../npm/packages/ml-kem"); await emptyDir("../../npm/samples/ml-kem"); await emptyDir("../../npm/test/ml-kem/runtimes/cloudflare"); -await emptyDir("test/runtimes/browsers/node_modules"); -await emptyDir("test/runtimes/bun/node_modules"); +// clean up node_modules +await removeNodeModules(); const denoPkg = JSON.parse(await Deno.readTextFile("./deno.json")); diff --git a/utils/misc.ts b/utils/misc.ts new file mode 100644 index 000000000..7a3f39247 --- /dev/null +++ b/utils/misc.ts @@ -0,0 +1,24 @@ +export async function removeNodeModules() { + try { + await Deno.remove("test/runtimes/browsers/node_modules", { + recursive: true, + }); + } catch { + // ignore + } + try { + await Deno.remove("test/runtimes/bun/node_modules", { + recursive: true, + }); + } catch { + // ignore + } + try { + await Deno.remove("test/runtimes/cloudflare/node_modules", { + recursive: true, + }); + } catch { + // ignore + } + return; +}