@@ -27,7 +27,7 @@ const testDependencies = [
2727
2828let configs = [
2929 esmConfig ( ) ,
30- esmTemplateCompiler ( ) ,
30+ esmProdConfig ( ) ,
3131 legacyBundleConfig ( './broccoli/amd-compat-entrypoints/ember.debug.js' , 'ember.debug.js' , {
3232 isDeveloping : true ,
3333 } ) ,
@@ -55,79 +55,90 @@ export default configs;
5555
5656function esmConfig ( ) {
5757 return sharedESMConfig ( {
58- input : {
59- ...renameEntrypoints ( exposedDependencies ( ) , ( name ) => join ( 'packages' , name , 'index' ) ) ,
60- ...renameEntrypoints ( packages ( ) , ( name ) => join ( 'packages' , name ) ) ,
61- } ,
58+ input : esmInputs ( ) ,
6259 debugMacrosMode : '@embroider/macros' ,
60+ includePackageMeta : true ,
6361 } ) ;
6462}
6563
66- function esmTemplateCompiler ( ) {
64+ function esmProdConfig ( ) {
6765 return sharedESMConfig ( {
68- input : {
69- // the actual authored "./packages/ember-template-compiler/index.ts" is
70- // part of what powers the historical dist/ember-template-compiler.js AMD
71- // bundle. It has historical cruft that has never been present in our ESM
72- // builds.
73- //
74- // On the ESM build, the main entrypoint of ember-template-compiler is the
75- // "minimal.ts" version, which has a lot less in it.
76-
77- 'packages/ember-template-compiler/index' : 'ember-template-compiler/minimal.ts' ,
78- } ,
79- // the template compiler is always in debug mode (and doesn't use
80- // embroider/macros, so it's directly invokable on node)
81- debugMacrosMode : true ,
66+ input : esmInputs ( ) ,
67+ debugMacrosMode : 'production' ,
8268 } ) ;
8369}
8470
85- function sharedESMConfig ( { input, debugMacrosMode } ) {
71+ function esmInputs ( ) {
72+ return {
73+ ...renameEntrypoints ( exposedDependencies ( ) , ( name ) => join ( 'packages' , name , 'index' ) ) ,
74+ ...renameEntrypoints ( packages ( ) , ( name ) => join ( 'packages' , name ) ) ,
75+ // the actual authored "./packages/ember-template-compiler/index.ts" is
76+ // part of what powers the historical dist/ember-template-compiler.js AMD
77+ // bundle. It has historical cruft that has never been present in our ESM
78+ // builds.
79+ //
80+ // On the ESM build, the main entrypoint of ember-template-compiler is the
81+ // "minimal.ts" version, which has a lot less in it.
82+
83+ 'packages/ember-template-compiler/index' : 'ember-template-compiler/minimal.ts' ,
84+ } ;
85+ }
86+
87+ function sharedESMConfig ( { input, debugMacrosMode, includePackageMeta = false } ) {
88+ let outputDir = debugMacrosMode === 'production' ? 'dist-prod' : 'dist' ;
8689 let babelConfig = { ...sharedBabelConfig } ;
8790 babelConfig . plugins = [
8891 ...babelConfig . plugins ,
8992 // buildDebugMacroPlugin(debugMacrosMode),
9093 canaryFeatures ( ) ,
9194 ] ;
9295
96+ let plugins = [
97+ babel ( {
98+ babelHelpers : 'bundled' ,
99+ extensions : [ '.js' , '.ts' ] ,
100+ configFile : false ,
101+ ...babelConfig ,
102+ } ) ,
103+ {
104+ name : 'define custom import.meta.env' ,
105+ async transform ( code ) {
106+ if ( debugMacrosMode === 'production' ) {
107+ if ( code . includes ( 'import.meta.env?.DEV' ) ) {
108+ return code . replace ( / i m p o r t .m e t a .e n v \? .D E V / g, 'false' ) ;
109+ }
110+ }
111+
112+ if ( debugMacrosMode === true ) {
113+ if ( code . includes ( 'import.meta.env?.DEV' ) ) {
114+ return code . replace ( / i m p o r t .m e t a .e n v \? .D E V / g, 'true' ) ;
115+ }
116+ }
117+
118+ return undefined ;
119+ } ,
120+ } ,
121+ resolveTS ( ) ,
122+ version ( ) ,
123+ resolvePackages ( { ...exposedDependencies ( ) , ...hiddenDependencies ( ) } ) ,
124+ pruneEmptyBundles ( ) ,
125+ ] ;
126+
127+ if ( includePackageMeta ) {
128+ plugins . push ( packageMeta ( ) ) ;
129+ }
130+
93131 return {
94132 onLog : handleRollupWarnings ,
95133 input,
96134 output : {
97135 format : 'es' ,
98- dir : 'dist' ,
136+ dir : outputDir ,
99137 hoistTransitiveImports : false ,
100138 generatedCode : 'es2015' ,
101139 chunkFileNames : 'packages/shared-chunks/[name]-[hash].js' ,
102140 } ,
103- plugins : [
104- {
105- name : 'define custom import.meta.env' ,
106- async transform ( code ) {
107- if ( debugMacrosMode === true ) {
108- if ( code . includes ( 'import.meta.env?.DEV' ) ) {
109- return code . replace ( / i m p o r t .m e t a .e n v \? .D E V / g, 'true' ) ;
110- }
111- } else if ( debugMacrosMode === false ) {
112- if ( code . includes ( 'import.meta.env?.DEV' ) ) {
113- return code . replace ( / i m p o r t .m e t a .e n v \? .D E V / g, 'false' ) ;
114- }
115- }
116- return undefined ;
117- } ,
118- } ,
119- babel ( {
120- babelHelpers : 'bundled' ,
121- extensions : [ '.js' , '.ts' ] ,
122- configFile : false ,
123- ...babelConfig ,
124- } ) ,
125- resolveTS ( ) ,
126- version ( ) ,
127- resolvePackages ( { ...exposedDependencies ( ) , ...hiddenDependencies ( ) } ) ,
128- pruneEmptyBundles ( ) ,
129- packageMeta ( ) ,
130- ] ,
141+ plugins,
131142 } ;
132143}
133144
@@ -659,11 +670,15 @@ function pruneEmptyBundles() {
659670function packageMeta ( ) {
660671 return {
661672 name : 'package-meta' ,
662- generateBundle ( ) {
673+ generateBundle ( _outputOptions , bundle ) {
663674 let renamedModules = Object . fromEntries (
664- glob
665- . sync ( 'packages/**/*.js' , { cwd : 'dist' , nodir : true } )
666- . filter ( ( name ) => ! name . startsWith ( 'packages/shared-chunks/' ) )
675+ Object . keys ( bundle )
676+ . filter (
677+ ( name ) =>
678+ name . startsWith ( 'packages/' ) &&
679+ ! name . startsWith ( 'packages/shared-chunks/' ) &&
680+ name . endsWith ( '.js' )
681+ )
667682 . sort ( )
668683 . map ( ( name ) => {
669684 return [
0 commit comments