Skip to content

Commit

Permalink
🐛 fix(builder): update esbuild config
Browse files Browse the repository at this point in the history
  • Loading branch information
angelespejo committed Aug 29, 2024
1 parent 356ffb2 commit 2e186d3
Show file tree
Hide file tree
Showing 19 changed files with 5,991 additions and 4,608 deletions.
7 changes: 7 additions & 0 deletions packages/backan/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# backan

## 0.0.13

### Patch Changes

- Updated dependencies []:
- @backan/core@0.0.13

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backan/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backan",
"version": "0.0.12",
"version": "0.0.13",
"type": "module",
"license": "GPL-3.0",
"homepage": "https://backan.pigeonposse.com",
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @backan/builder

## 0.0.13

### Patch Changes

- Update esbuild config

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/examples/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from '@backan/core'
import { server } from '../../server/dist/main.js'
import { server } from '@backan/server'

export const app = new App( {
version : '1.0.0',
Expand Down
6 changes: 4 additions & 2 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@backan/builder",
"version": "0.0.12",
"version": "0.0.13",
"type": "module",
"license": "GPL-3.0",
"homepage": "https://backan.pigeonposse.com/",
Expand All @@ -17,7 +17,8 @@
"backan-builder": "dist/bin.js"
},
"files": [
"dist"
"dist",
"tsconfig.builder.json"
],
"module": "dist/main.js",
"main": "dist/main.js",
Expand Down Expand Up @@ -49,6 +50,7 @@
},
"devDependencies": {
"@backan/core": "workspace:*",
"@backan/server": "workspace:*",
"@types/archiver": "6.0.2"
},
"dependencies": {
Expand Down
28 changes: 28 additions & 0 deletions packages/builder/src/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {
BuilderErrors,
BuilderParams,
} from './types'

export class BuildError extends Error {

constructor(
message: BuilderErrors,
data: {
platform: string
arch: string
opts: BuilderParams
} & Record<string, unknown>,
) {

super( message )
this.name = this.constructor.name

Object.assign( this, {
data,
} )

if ( Error.captureStackTrace ) Error.captureStackTrace( this, this.constructor )

}

}
24 changes: 24 additions & 0 deletions packages/builder/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const logger = (
{
name,
isDebug = false,
}: {
name: string
isDebug?:boolean
},
) => ( {
debug : ( data: object | string ) => isDebug && console.debug( '\n🔥⬛', data ),
group : ( data: object | string ) => ( {
start : () => {

console.log( '\n🔥⬛', data )
console.group( )

},
end : () => console.groupEnd( ),
} ) ,
info : ( data: object | string ) => console.log( `\n🔥🟦 [${name}]`, data ),
success : ( data: object | string ) => console.log( `\n🔥✅ [${name}]`, data ),
warn : ( data: object | string ) => console.warn( `\n🔥🟡 [${name}]`, data ),
error : ( data: object | string ) => console.error( `\n🔥❌ [${name}]`, data ),
} )
65 changes: 19 additions & 46 deletions packages/builder/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import {
getFlagValue,
getPlatform,
joinPath,
packageDir,
resolvePath,
writeFile,
} from './utils'
import { zipFilesInDirectory } from './compress'
import type {
BuilderErrors,
BuilderParams,
} from './types'
import type { BuilderParams } from './types'
import { logger } from './logger'
import { BuildError } from './error'

export { buildSchema } from './schema'
export { buildMD } from './md'
Expand All @@ -41,47 +41,10 @@ export type * from './types'
* FUNCTIONS.
*/
const isDebug = existsFlag( 'debug' )
const log = {
debug : ( data: object | string ) => isDebug && console.debug( '\n🔥⬛', data )
,
group : ( data: object | string ) => ( {
start : () => {

console.log( '\n🔥⬛', data )
console.group( )

},
end : () => console.groupEnd( ),
} ) ,
info : ( data: object | string ) => console.log( `\n🔥🟦 [${name}]`, data ),
success : ( data: object | string ) => console.log( `\n🔥✅ [${name}]`, data ),
warn : ( data: object | string ) => console.warn( `\n🔥🟡 [${name}]`, data ),
error : ( data: object | string ) => console.error( `\n🔥❌ [${name}]`, data ),
}

class BuildError extends Error {

constructor(
message: BuilderErrors,
data: {
platform: string
arch: string
opts: BuilderParams
} & Record<string, unknown>,
) {

super( message )
this.name = this.constructor.name

Object.assign( this, {
data,
} )

if ( Error.captureStackTrace ) Error.captureStackTrace( this, this.constructor )

}

}
const log = logger( {
name,
isDebug,
} )

export const buildConstructor = async ( {
input,
Expand Down Expand Up @@ -178,17 +141,27 @@ export const buildConstructor = async ( {
const esbuildLog = log.group( 'Building cjs file...' )
esbuildLog.start()
const { build } = await import( 'esbuild' )

const getTsConfig = async () =>{

const userTs = resolvePath( 'tsconfig.json' )
const existUserTs = await existsPath( userTs )
if( existUserTs ) return userTs
return joinPath( packageDir, 'tsconfig.builder.json' )

}

await build( {
entryPoints : [
input,
],
// TODO FIX: This cause unexpected error in production
minify : true,
bundle : true,
format : 'cjs',
platform : 'node',
target,
outfile : projectBuildCjsFile,
tsconfig : await getTsConfig(),
} ).catch( err => {

esbuildLog.end()
Expand Down
3 changes: 3 additions & 0 deletions packages/builder/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
join,
resolve,
} from 'node:path'
import * as url from 'node:url'

export const packageDir = url.fileURLToPath( new URL( '..', import.meta.url ) )

export const joinPath = join
export const resolvePath = resolve
Expand Down
43 changes: 43 additions & 0 deletions packages/builder/tsconfig.builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
/**
* Options.
*/
"strict": true,
"alwaysStrict": true,
"strictPropertyInitialization": true,
"noImplicitAny": true,
"strictNullChecks": true,
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"useDefineForClassFields": true,
// "allowImportingTsExtensions": false,
// "baseUrl": ".",
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": true,
"noEmit": true,
"isolatedModules": true,
"importHelpers": true,
"removeComments": false,
"allowSyntheticDefaultImports": true,
"outDir": "./dist",
"baseUrl": "./src"
},
"include": [
"./src/",
"../../package.json",
"./package.json"
]
}
2 changes: 2 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @backan/core

## 0.0.13

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@backan/core",
"version": "0.0.12",
"version": "0.0.13",
"type": "module",
"license": "GPL-3.0",
"homepage": "https://backan.pigeonposse.com",
Expand Down
2 changes: 2 additions & 0 deletions packages/create/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# create-backan

## 0.0.13

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-backan",
"version": "0.0.12",
"version": "0.0.13",
"type": "module",
"license": "GPL-3.0",
"homepage": "https://backan.pigeonposse.com",
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @backan/docs

## 0.0.13

## 0.0.12

## 0.0.11
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@backan/docs",
"version": "0.0.12",
"version": "0.0.13",
"description": "Documentation for backan",
"type": "module",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions packages/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @backan/server

## 0.0.13

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@backan/server",
"version": "0.0.12",
"version": "0.0.13",
"type": "module",
"license": "GPL-3.0",
"homepage": "https://backan.pigeonposse.com",
Expand Down
Loading

0 comments on commit 2e186d3

Please sign in to comment.