11const process = require ( "node:process" ) ;
22const console = require ( "node:console" ) ;
3+ const fs = require ( "node:fs" ) ;
4+ const path = require ( "node:path" ) ;
5+ const { copy } = require ( "esbuild-plugin-copy" ) ;
36const production = process . argv . includes ( "--production" ) ;
47const watch = process . argv . includes ( "--watch" ) ;
58
@@ -20,11 +23,28 @@ async function main() {
2023 define : production ? { "process.env.NODE_ENV" : '"production"' } : undefined ,
2124 minify : production ,
2225 sourcemap : ! production ,
23- plugins : [ workspacePackagesPlugin , esbuildProblemMatcherPlugin ] ,
26+ plugins : [
27+ workspacePackagesPlugin ,
28+ esbuildProblemMatcherPlugin ,
29+ copy ( {
30+ assets : [
31+ {
32+ from : [ "./node_modules/oxfmt/**/*" , "../../node_modules/oxfmt/**/*" ] ,
33+ to : [ "./node_modules/oxfmt" ] ,
34+ } ,
35+ {
36+ from : [ "./node_modules/@oxfmt/**/*" , "../../node_modules/@oxfmt/**/*" ] ,
37+ to : [ "./node_modules/@oxfmt" ] ,
38+ } ,
39+ ] ,
40+ once : true ,
41+ } ) ,
42+ ] ,
2443 } ) ;
2544 if ( watch ) {
2645 await ctx . watch ( ) ;
2746 } else {
47+ fs . rmSync ( "./dist" , { recursive : true , force : true } ) ;
2848 await ctx . rebuild ( ) ;
2949 await ctx . dispose ( ) ;
3050 }
@@ -42,9 +62,7 @@ const esbuildProblemMatcherPlugin = {
4262 build . onEnd ( ( result ) => {
4363 result . errors . forEach ( ( { text, location } ) => {
4464 console . error ( `✘ [ERROR] ${ text } ` ) ;
45- console . error (
46- ` ${ location . file } :${ location . line } :${ location . column } :`
47- ) ;
65+ console . error ( ` ${ location . file } :${ location . line } :${ location . column } :` ) ;
4866 } ) ;
4967 console . log ( "[watch] build finished" ) ;
5068 } ) ;
@@ -59,26 +77,19 @@ const esbuildProblemMatcherPlugin = {
5977const workspacePackagesPlugin = {
6078 name : "workspace-packages" ,
6179 setup ( build ) {
62- const path = require ( "node:path" ) ;
6380 const pkgRoot = path . resolve ( __dirname , "../../../packages" ) ;
6481 /** @type {Record<string, string> } */
6582 const alias = {
6683 "@pretty-ts-errors/utils" : path . join ( pkgRoot , "utils/src/index.ts" ) ,
67- "@pretty-ts-errors/formatter" : path . join (
68- pkgRoot ,
69- "formatter/src/index.ts"
70- ) ,
71- "@pretty-ts-errors/vscode-formatter" : path . join (
72- pkgRoot ,
73- "vscode-formatter/src/index.ts"
74- ) ,
84+ "@pretty-ts-errors/formatter" : path . join ( pkgRoot , "formatter/src/index.ts" ) ,
85+ "@pretty-ts-errors/vscode-formatter" : path . join ( pkgRoot , "vscode-formatter/src/index.ts" ) ,
7586 } ;
7687 build . onResolve (
7788 { filter : / ^ @ p r e t t y - t s - e r r o r s \/ ( u t i l s | f o r m a t t e r | v s c o d e - f o r m a t t e r ) $ / } ,
7889 ( args ) => {
7990 const target = alias [ args . path ] ;
8091 return target ? { path : target } : undefined ;
81- }
92+ } ,
8293 ) ;
8394 } ,
8495} ;
0 commit comments