From 04bb2a638f1f5cde4972fc34402b167f23c04cfb Mon Sep 17 00:00:00 2001 From: Luca Peruzzo Date: Tue, 26 Nov 2024 10:16:37 +0100 Subject: [PATCH] try fixing cjs --- scripts/shared/postBuild.ts | 16 +++++++++------- src/bin/tsconfig.json | 5 ++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/shared/postBuild.ts b/scripts/shared/postBuild.ts index 2ffde7a..eb6cce8 100644 --- a/scripts/shared/postBuild.ts +++ b/scripts/shared/postBuild.ts @@ -15,13 +15,13 @@ function buildBin() { const binDirPath = pathJoin(getThisCodebaseRootDirPath(), 'src', 'bin'); const distDirPath_bin = pathJoin(distDirPath, 'bin'); - run(`npx tsc -p ${binDirPath} --outDir ${distDirPath_bin}`); + fs.cpSync(binDirPath, distDirPath_bin, { recursive: true }); const nccOutDirPath = pathJoin(distDirPath_bin, 'ncc_out'); - const entrypointFilePath = pathJoin(distDirPath_bin, 'main.js'); + const entrypointFilePath = pathJoin(distDirPath_bin, 'main.ts'); - run(`npx ncc build ${entrypointFilePath} --external prettier -o ${nccOutDirPath}`); + run(`npx ncc build ${entrypointFilePath} --external prettier -t -o ${nccOutDirPath}`); transformCodebase({ srcDirPath: distDirPath_bin, @@ -35,9 +35,11 @@ function buildBin() { }, }); + const newEntrypointFilePath = entrypointFilePath.replace('main.ts', 'index.js'); + fs.readdirSync(nccOutDirPath).forEach((basename) => { const destFilePath = - basename === 'index.js' ? entrypointFilePath : pathJoin(pathDirname(entrypointFilePath), basename); + basename === 'index.js' ? newEntrypointFilePath : pathJoin(pathDirname(newEntrypointFilePath), basename); const srcFilePath = pathJoin(nccOutDirPath, basename); fs.cpSync(srcFilePath, destFilePath); @@ -46,13 +48,13 @@ function buildBin() { fs.rmSync(nccOutDirPath, { recursive: true }); fs.chmodSync( - entrypointFilePath, - fs.statSync(entrypointFilePath).mode | fs.constants.S_IXUSR | fs.constants.S_IXGRP | fs.constants.S_IXOTH, + newEntrypointFilePath, + fs.statSync(newEntrypointFilePath).mode | fs.constants.S_IXUSR | fs.constants.S_IXGRP | fs.constants.S_IXOTH, ); return { packageJsonBinProperty: { - [BIN_NAME]: pathRelative(distDirPath, entrypointFilePath).replaceAll(pathSep, '/'), + [BIN_NAME]: pathRelative(distDirPath, newEntrypointFilePath).replaceAll(pathSep, '/'), }, }; } diff --git a/src/bin/tsconfig.json b/src/bin/tsconfig.json index a2a432f..06dc5eb 100644 --- a/src/bin/tsconfig.json +++ b/src/bin/tsconfig.json @@ -16,5 +16,8 @@ "moduleResolution": "node" }, "include": ["**/*.ts"], - "exclude": ["initialize-account-theme/boilerplate"] + "exclude": ["initialize-account-theme/boilerplate"], + "ts-node": { + "esm": true + } }