From 65dd4e906893b39af06b546063a0128e37e54cf4 Mon Sep 17 00:00:00 2001 From: KaKa <23028015+climba03003@users.noreply.github.com> Date: Sat, 14 Sep 2024 01:43:09 +0800 Subject: [PATCH] build: update build scripts (#244) --- packages/config/lib/mjs/package.json | 3 --- packages/cronjob/lib/mjs/package.json | 3 --- packages/mongodb/lib/mjs/package.json | 3 --- packages/multipart/lib/mjs/package.json | 3 --- packages/oauth2/lib/mjs/package.json | 3 --- scripts/build.mjs | 33 +++++++++++-------------- 6 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 packages/config/lib/mjs/package.json delete mode 100644 packages/cronjob/lib/mjs/package.json delete mode 100644 packages/mongodb/lib/mjs/package.json delete mode 100644 packages/multipart/lib/mjs/package.json delete mode 100644 packages/oauth2/lib/mjs/package.json diff --git a/packages/config/lib/mjs/package.json b/packages/config/lib/mjs/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/packages/config/lib/mjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/packages/cronjob/lib/mjs/package.json b/packages/cronjob/lib/mjs/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/packages/cronjob/lib/mjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/packages/mongodb/lib/mjs/package.json b/packages/mongodb/lib/mjs/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/packages/mongodb/lib/mjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/packages/multipart/lib/mjs/package.json b/packages/multipart/lib/mjs/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/packages/multipart/lib/mjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/packages/oauth2/lib/mjs/package.json b/packages/oauth2/lib/mjs/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/packages/oauth2/lib/mjs/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/scripts/build.mjs b/scripts/build.mjs index 28fa098d..8781d820 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -11,17 +11,20 @@ const { values } = parseArgs({ } }) -function isBuildAsset (name) { +function isBuildAsset(name) { return String(name).endsWith('.js') || - String(name).endsWith('.cjs') || - String(name).endsWith('.mjs') || - String(name).endsWith('.map') || - String(name).endsWith('.d.ts') || - String(name).endsWith('.d.cts') || - String(name).endsWith('.d.mts') + String(name).endsWith('.cjs') || + String(name).endsWith('.mjs') || + String(name).endsWith('.map') || + String(name).endsWith('.d.ts') || + String(name).endsWith('.d.cts') || + String(name).endsWith('.d.mts') } -async function clean () { +async function clean() { + // remove ESM folder + await fs.rm(path.resolve('lib', 'mjs'), { recursive: true, force: true }) + for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) { if (isBuildAsset(file)) { await fs.rm(path.resolve('lib', file), { force: true }) @@ -35,25 +38,17 @@ async function clean () { } } -async function build (mode = 'all') { +async function build(mode = 'all') { if (mode === 'all' || mode === 'cjs') { console.log('build cjs - start') execSync('tsc -p tsconfig.cjs.json', { stdio: 'pipe' }) - // for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) { - // if (isBuildAsset(file)) { - // await fs.rename(path.resolve('lib', file), path.resolve('lib', file).replace('.js', '.cjs').replace('.d.ts', '.d.cts')) - // } - // } console.log('build cjs - end') } if (mode === 'all' || mode === 'mjs') { console.log('build mjs - start') + await fs.mkdir(path.resolve('lib', 'mjs'), { recursive: true }) + await fs.writeFile(path.resolve('lib', 'mjs', 'package.json'), JSON.stringify({ type: 'module' }, null, 2)) execSync('tsc -p tsconfig.mjs.json', { stdio: 'pipe' }) - // for (const file of await fs.readdir(path.resolve('lib'), { recursive: true })) { - // if (isBuildAsset(file)) { - // await fs.rename(path.resolve('lib', file), path.resolve('lib', file).replace('.js', '.mjs').replace('.d.ts', '.d.mts')) - // } - // } execSync('tsc-alias -p tsconfig.mjs.json', { stdio: 'pipe' }) console.log('build mjs - end') }