diff --git a/packages/db-postgres/bundle.js b/packages/db-postgres/bundle.js index 653394a07..7b1718bda 100644 --- a/packages/db-postgres/bundle.js +++ b/packages/db-postgres/bundle.js @@ -6,8 +6,8 @@ const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) import { commonjs } from '@hyrious/esbuild-plugin-commonjs' -const resultServer = await esbuild - .build({ +async function build() { + const resultServer = await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, platform: 'node', @@ -30,10 +30,8 @@ const resultServer = await esbuild plugins: [commonjs()], sourcemap: true, }) - .then((res, err) => { - console.log('db-postgres bundled successfully') - return res - }) - .catch(() => process.exit(1)) + console.log('db-postgres bundled successfully') -fs.writeFileSync('meta_server.json', JSON.stringify(resultServer.metafile)) + fs.writeFileSync('meta_server.json', JSON.stringify(resultServer.metafile)) +} +await build() diff --git a/packages/next/bundleScss.js b/packages/next/bundleScss.js index d5c334091..45b07d895 100644 --- a/packages/next/bundleScss.js +++ b/packages/next/bundleScss.js @@ -1,14 +1,11 @@ import * as esbuild from 'esbuild' import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' -const filename = fileURLToPath(import.meta.url) -const dirname = path.dirname(filename) + import { sassPlugin } from 'esbuild-sass-plugin' -// Bundle only the .scss files into a single css file -await esbuild - .build({ +async function build() { + // Bundle only the .scss files into a single css file + await esbuild.build({ entryPoints: ['src/esbuildEntry.ts'], bundle: true, minify: true, @@ -16,30 +13,34 @@ await esbuild packages: 'external', plugins: [sassPlugin({ css: 'external' })], }) - .then(() => { - fs.rename('dist/prod/esbuildEntry.css', 'dist/prod/styles.css', (err) => { - if (err) console.error(`Error while renaming index.css: ${err}`) - }) - fs.unlink('dist/esbuildEntry.js', (err) => { - if (err) console.error(`Error while deleting dist/esbuildEntry.js: ${err}`) - }) - - fs.unlink('dist/prod/esbuildEntry.js', (err) => { - if (err) console.error(`Error while deleting dist/prod/esbuildEntry.js: ${err}`) - }) - - fs.unlink('dist/esbuildEntry.d.ts', (err) => { - if (err) console.error(`Error while deleting dist/esbuildEntry.d.ts: ${err}`) - }) - fs.unlink('dist/esbuildEntry.d.ts.map', (err) => { - if (err) console.error(`Error while deleting dist/esbuildEntry.d.ts.map: ${err}`) - }) - fs.unlink('dist/esbuildEntry.js.map', (err) => { - if (err) console.error(`Error while deleting dist/esbuildEntry.js.map: ${err}`) - }) - console.log('styles.css bundled successfully') - }) - .catch((e) => { - throw e + await fs.rename('dist/prod/esbuildEntry.css', 'dist/prod/styles.css', (err) => { + if (err) { + console.error(`Error while renaming index.css: ${err}`) + throw err + } }) + + console.log('styles.css bundled successfully') + + const filesToDelete = [ + 'dist/esbuildEntry.js', + 'dist/prod/esbuildEntry.js', + 'dist/esbuildEntry.d.ts', + 'dist/esbuildEntry.d.ts.map', + 'dist/esbuildEntry.js.map', + ] + + for (const file of filesToDelete) { + await fs.unlink(file, (err) => { + if (err) { + console.error(`Error while deleting ${file}: ${err}`) + throw err + } + }) + } + + console.log('Files renamed and deleted successfully') +} + +await build() diff --git a/packages/payload/bundle.js b/packages/payload/bundle.js index 1528f84c0..5e4ed18b9 100644 --- a/packages/payload/bundle.js +++ b/packages/payload/bundle.js @@ -4,10 +4,9 @@ import path from 'path' import { fileURLToPath } from 'url' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) -import { commonjs } from '@hyrious/esbuild-plugin-commonjs' -const resultIndex = await esbuild - .build({ +async function build() { + const resultIndex = await esbuild.build({ entryPoints: ['src/exports/index.ts'], bundle: true, platform: 'node', @@ -33,14 +32,9 @@ const resultIndex = await esbuild // plugins: [commonjs()], sourcemap: true, }) - .then((res, err) => { - console.log('payload server bundled successfully') - return res - }) - .catch(() => process.exit(1)) + console.log('payload server bundled successfully') -const resultShared = await esbuild - .build({ + const resultShared = await esbuild.build({ entryPoints: ['src/exports/shared.ts'], bundle: true, platform: 'node', @@ -65,11 +59,10 @@ const resultShared = await esbuild // plugins: [commonjs()], sourcemap: true, }) - .then((res, err) => { - console.log('payload shared bundled successfully') - return res - }) - .catch(() => process.exit(1)) + console.log('payload shared bundled successfully') -fs.writeFileSync('meta_index.json', JSON.stringify(resultIndex.metafile)) -fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile)) + fs.writeFileSync('meta_index.json', JSON.stringify(resultIndex.metafile)) + fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile)) +} + +await build() diff --git a/packages/richtext-lexical/bundle.js b/packages/richtext-lexical/bundle.js index c32fcb936..babb73f71 100644 --- a/packages/richtext-lexical/bundle.js +++ b/packages/richtext-lexical/bundle.js @@ -18,9 +18,9 @@ const removeCSSImports = { }, } -// Bundle only the .scss files into a single css file -await esbuild - .build({ +async function build() { + // Bundle only the .scss files into a single css file + await esbuild.build({ entryPoints: ['src/exports/client/index.ts'], bundle: true, minify: true, @@ -30,18 +30,14 @@ await esbuild //external: ['*.svg'], plugins: [sassPlugin({ css: 'external' })], }) - .then(() => { - fs.rename('dist/field/index.css', 'dist/exports/client/bundled.css', (err) => { - if (err) console.error(`Error while renaming index.css: ${err}`) - }) - - console.log('dist/field/bundled.css bundled successfully') + await fs.rename('dist/field/index.css', 'dist/exports/client/bundled.css', (err) => { + if (err) console.error(`Error while renaming index.css: ${err}`) }) - .catch(() => process.exit(1)) -// Bundle `client.ts` -const resultClient = await esbuild - .build({ + console.log('dist/field/bundled.css bundled successfully') + + // Bundle `client.ts` + const resultClient = await esbuild.build({ entryPoints: ['src/exports/client/index.ts'], bundle: true, platform: 'browser', @@ -90,15 +86,14 @@ const resultClient = await esbuild plugins: [ removeCSSImports, /*commonjs({ - ignore: ['date-fns', '@floating-ui/react'], - }),*/ + ignore: ['date-fns', '@floating-ui/react'], + }),*/ ], sourcemap: true, }) - .then((res, err) => { - console.log('client/index.ts bundled successfully') - return res - }) - .catch(() => process.exit(1)) + console.log('client/index.ts bundled successfully') -fs.writeFileSync('meta_client.json', JSON.stringify(resultClient.metafile)) + fs.writeFileSync('meta_client.json', JSON.stringify(resultClient.metafile)) +} + +await build() diff --git a/packages/ui/bundle.js b/packages/ui/bundle.js index a9ba020a9..952f45fef 100644 --- a/packages/ui/bundle.js +++ b/packages/ui/bundle.js @@ -58,9 +58,9 @@ const useClientPlugin = { }, } -// Bundle only the .scss files into a single css file -await esbuild - .build({ +async function build() { + // Bundle only the .scss files into a single css file + await esbuild.build({ entryPoints: ['src/exports/client/index.ts'], bundle: true, minify: true, @@ -68,24 +68,23 @@ await esbuild packages: 'external', plugins: [sassPlugin({ css: 'external' })], }) - .then(() => { - fs.rename('dist/index.css', 'dist/styles.css', (err) => { - if (err) console.error(`Error while renaming index.css: ${err}`) - }) - - fs.unlink('dist/index.js', (err) => { - if (err) console.error(`Error while deleting index.js: ${err}`) - }) - - console.log('styles.css bundled successfully') - }) - .catch((e) => { - throw e + await fs.rename('dist/index.css', 'dist/styles.css', (err) => { + if (err) { + console.error(`Error while renaming index.css: ${err}`) + throw err + } }) -// Bundle `client.ts` -const resultClient = await esbuild - .build({ + await fs.unlink('dist/index.js', (err) => { + if (err) { + console.error(`Error while deleting index.js: ${err}`) + throw err + } + }) + + console.log('styles.css bundled successfully') + // Bundle `client.ts` + const resultClient = await esbuild.build({ entryPoints: ['src/exports/client/index.ts'], bundle: true, platform: 'browser', @@ -138,21 +137,14 @@ function require(m) { removeCSSImports, useClientPlugin, // required for banner to work /*commonjs({ - ignore: ['date-fns', '@floating-ui/react'], - }),*/ + ignore: ['date-fns', '@floating-ui/react'], + }),*/ ], sourcemap: true, }) - .then((res, err) => { - console.log('client.ts bundled successfully') - return res - }) - .catch((e) => { - throw e - }) + console.log('client.ts bundled successfully') -const resultShared = await esbuild - .build({ + const resultShared = await esbuild.build({ entryPoints: ['src/exports/shared/index.ts'], bundle: true, platform: 'node', @@ -188,13 +180,10 @@ const resultShared = await esbuild plugins: [removeCSSImports, commonjs()], sourcemap: true, }) - .then((res, err) => { - console.log('shared.ts bundled successfully') - return res - }) - .catch((e) => { - throw e - }) + console.log('shared.ts bundled successfully') -fs.writeFileSync('meta_client.json', JSON.stringify(resultClient.metafile)) -fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile)) + fs.writeFileSync('meta_client.json', JSON.stringify(resultClient.metafile)) + fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile)) +} + +await build()