Skip to content

Commit

Permalink
try fixing cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-peruzzo committed Nov 26, 2024
1 parent a61f958 commit 04bb2a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 9 additions & 7 deletions scripts/shared/postBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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, '/'),
},
};
}
5 changes: 4 additions & 1 deletion src/bin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"moduleResolution": "node"
},
"include": ["**/*.ts"],
"exclude": ["initialize-account-theme/boilerplate"]
"exclude": ["initialize-account-theme/boilerplate"],
"ts-node": {
"esm": true
}
}

0 comments on commit 04bb2a6

Please sign in to comment.