chore: run esbuild scripts in sync, hopefully fixing publishing issues (#7159)

We are suspecting that operations within those esbuild scripts are not
awaited properly - potentially causing issues in the publish script,
publishing the next package without any built .js files
This commit is contained in:
Alessio Gravili
2024-07-15 17:31:48 -04:00
committed by GitHub
parent 2925c3bb90
commit 08f50bb441
5 changed files with 93 additions and 117 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()