@@ -16,12 +16,17 @@ const browserifyPlugin = {
1616 } ,
1717} ;
1818
19+ const nodeExternals = [
20+ ...Object . keys ( require ( "./package.json" ) . dependencies ) ,
21+ ...require ( "module" ) . builtinModules ,
22+ ] ;
23+
1924// Build both CJS and ESM versions
2025Promise . all ( [
2126 // Browser builds:
2227 // CommonJS build
2328 esbuild . build ( {
24- entryPoints : [ "src/browser.ts" ] ,
29+ entryPoints : [ "src/browser/index .ts" ] ,
2530 bundle : true ,
2631 format : "cjs" ,
2732 // .cjs extension is required because "type": "module" is set in package.json
@@ -41,10 +46,10 @@ Promise.all([
4146
4247 // ESM build
4348 esbuild . build ( {
44- entryPoints : [ "src/browser.ts" ] ,
49+ entryPoints : [ "src/browser/index .ts" ] ,
4550 bundle : true ,
4651 format : "esm" ,
47- outdir : "dist/esm" ,
52+ outfile : "dist/esm/browser.js " ,
4853 platform : "browser" ,
4954 // pitcher-common currently requires this, but breaks the first experience
5055 banner : {
@@ -68,7 +73,7 @@ Promise.all([
6873 platform : "node" ,
6974 // .cjs extension is required because "type": "module" is set in package.json
7075 outfile : "dist/cjs/index.cjs" ,
71- plugins : [ browserifyPlugin ] ,
76+ external : nodeExternals ,
7277 } ) ,
7378
7479 // ESM build
@@ -77,37 +82,8 @@ Promise.all([
7782 bundle : true ,
7883 format : "esm" ,
7984 platform : "node" ,
80- banner : {
81- js : `
82- import { fileURLToPath } from 'url';
83- import { createRequire as topLevelCreateRequire } from 'module';
84- const require = topLevelCreateRequire(import.meta.url);
85- ` . trim ( ) ,
86- } ,
8785 outfile : "dist/esm/index.js" ,
88- plugins : [ browserifyPlugin ] ,
89- } ) ,
90-
91- // Edge:
92- // CommonJS build
93- esbuild . build ( {
94- entryPoints : [ "src/index.ts" ] ,
95- // .cjs extension is required because "type": "module" is set in package.json
96- outfile : "dist/cjs/index.edge.cjs" ,
97- bundle : true ,
98- format : "cjs" ,
99- platform : "browser" ,
100- plugins : [ browserifyPlugin ] ,
101- } ) ,
102-
103- // ESM build
104- esbuild . build ( {
105- entryPoints : [ "src/index.ts" ] ,
106- outfile : "dist/esm/index.edge.js" ,
107- bundle : true ,
108- format : "esm" ,
109- platform : "browser" ,
110- plugins : [ browserifyPlugin ] ,
86+ external : nodeExternals ,
11187 } ) ,
11288
11389 // Bin builds:
@@ -120,12 +96,10 @@ const require = topLevelCreateRequire(import.meta.url);
12096 banner : {
12197 js : `#!/usr/bin/env node\n\n` ,
12298 } ,
123- external : [
124- ...Object . keys ( require ( "./package.json" ) . dependencies || { } ) ,
125- ...Object . keys ( require ( "./package.json" ) . devDependencies || { } ) ,
126- ...require ( "module" ) . builtinModules ,
127- "@codesandbox/sdk" ,
128- ] ,
99+ // ORA is an ESM module so we have to include it in the build
100+ external : [ ...nodeExternals , "@codesandbox/sdk" ] . filter (
101+ ( mod ) => mod !== "ora"
102+ ) ,
129103 } ) ,
130104] ) . catch ( ( ) => {
131105 process . exit ( 1 ) ;
0 commit comments