From 58892cbb5657c523dfdc4d18f36cb68fc90222c7 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Thu, 6 Jun 2024 06:11:34 +0200 Subject: [PATCH] Change first level build target of bin --- scripts/build.ts | 38 ++++++++++++++++++++++++++++++++++---- src/bin/tsconfig.json | 7 ++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index d31655ac..86ed0f16 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -52,7 +52,25 @@ transformCodebase({ fs.rmSync(join("dist", "ncc_out"), { recursive: true }); -patchDeprecatedBufferApiUsage(join("dist", "bin", "main.js")); +{ + let hasBeenPatched = false; + + fs.readdirSync(join("dist", "bin")).forEach(fileBasename => { + if (fileBasename !== "main.js" && !fileBasename.endsWith(".index.js")) { + return; + } + + const { hasBeenPatched: hasBeenPatched_i } = patchDeprecatedBufferApiUsage( + join("dist", "bin", fileBasename) + ); + + if (hasBeenPatched_i) { + hasBeenPatched = true; + } + }); + + assert(hasBeenPatched); +} fs.chmodSync( join("dist", "bin", "main.js"), @@ -93,6 +111,10 @@ run( )}` ); +fs.readdirSync(join("dist", "ncc_out")).forEach(fileBasename => + assert(!fileBasename.endsWith(".index.js")) +); + transformCodebase({ srcDirPath: join("dist", "ncc_out"), destDirPath: join("dist", "vite-plugin"), @@ -105,7 +127,13 @@ transformCodebase({ fs.rmSync(join("dist", "ncc_out"), { recursive: true }); -patchDeprecatedBufferApiUsage(join("dist", "vite-plugin", "index.js")); +{ + const { hasBeenPatched } = patchDeprecatedBufferApiUsage( + join("dist", "vite-plugin", "index.js") + ); + + assert(hasBeenPatched); +} fs.rmSync(join("dist", "src"), { recursive: true, force: true }); @@ -127,7 +155,9 @@ function patchDeprecatedBufferApiUsage(filePath: string) { `var buffer = Buffer.allocUnsafe ? Buffer.allocUnsafe(toRead) : new Buffer(toRead);` ); - assert(after !== before, `Patch failed for ${relative(process.cwd(), filePath)}`); - fs.writeFileSync(filePath, Buffer.from(after, "utf8")); + + const hasBeenPatched = after !== before; + + return { hasBeenPatched }; } diff --git a/src/bin/tsconfig.json b/src/bin/tsconfig.json index e1a849fc..164e263c 100644 --- a/src/bin/tsconfig.json +++ b/src/bin/tsconfig.json @@ -1,10 +1,11 @@ { "extends": "../../tsproject.json", "compilerOptions": { - "module": "CommonJS", - "target": "ES5", + "module": "ES2020", + "target": "ES2017", "esModuleInterop": true, - "lib": ["es2015", "DOM", "ES2019.Object"], + "lib": ["es2015", "ES2019.Object"], + "moduleResolution": "node", "outDir": "../../dist/bin", "rootDir": "." }