@@ -18,7 +18,7 @@ jest.mock('fs-extra');
1818jest . mock ( '../lib/packagers/index' , ( ) => {
1919 const packagerMock = {
2020 lockfileName : 'mocked-lock.json' ,
21- copyPackageSectionNames : [ 'section1' , 'section2' ] ,
21+ copyPackageSectionNames : jest . requireActual ( '../lib/packagers/npm' ) . copyPackageSectionNames ,
2222 mustCopyModules : true ,
2323 rebaseLockfile : jest . fn ( ) ,
2424 getPackagerVersion : jest . fn ( ) ,
@@ -196,6 +196,15 @@ describe('packExternalModules', () => {
196196 section1 : originalPackageJSON . section1
197197 } ;
198198
199+ module . configuration = new Configuration ( {
200+ webpack : {
201+ includeModules : true ,
202+ packager : 'npm' ,
203+ packagerOptions : {
204+ copyPackageSectionNames : [ 'section1' , 'section2' ]
205+ }
206+ }
207+ } ) ;
199208 module . webpackOutputPath = '/my/Service/Path/outputPath' ;
200209 readFileSyncStub . mockReturnValueOnce ( originalPackageJSON ) ;
201210 readFileSyncStub . mockImplementation ( ( ) => {
@@ -229,6 +238,79 @@ describe('packExternalModules', () => {
229238 ) ;
230239 } ) ;
231240
241+ it ( 'should include ESM type from package.json according to packagerOptions' , ( ) => {
242+ const originalPackageJSON = {
243+ name : 'test-service' ,
244+ version : '1.0.0' ,
245+ description : 'Packaged externals for test-service' ,
246+ private : true ,
247+ type : 'module' ,
248+ dependencies : {
249+ '@scoped/vendor' : '1.0.0' ,
250+ bluebird : '^3.4.0' ,
251+ uuid : '^5.4.1'
252+ }
253+ } ;
254+ const expectedCompositePackageJSON = {
255+ name : 'test-service' ,
256+ version : '1.0.0' ,
257+ description : 'Packaged externals for test-service' ,
258+ private : true ,
259+ scripts : { } ,
260+ type : 'module' ,
261+ dependencies : {
262+ '@scoped/vendor' : '1.0.0' ,
263+ bluebird : '^3.4.0' ,
264+ uuid : '^5.4.1'
265+ }
266+ } ;
267+ const expectedPackageJSON = {
268+ name : 'test-service' ,
269+ version : '1.0.0' ,
270+ description : 'Packaged externals for test-service' ,
271+ private : true ,
272+ scripts : { } ,
273+ dependencies : {
274+ '@scoped/vendor' : '1.0.0' ,
275+ bluebird : '^3.4.0' ,
276+ uuid : '^5.4.1'
277+ } ,
278+ type : 'module'
279+ } ;
280+ module . configuration = new Configuration ( {
281+ webpack : {
282+ includeModules : true ,
283+ packager : 'npm' ,
284+ packagerOptions : {
285+ copyPackageSectionNames : [ 'type' ]
286+ }
287+ }
288+ } ) ;
289+
290+ module . webpackOutputPath = '/my/Service/Path/outputPath' ;
291+ fsExtraMock . pathExists . mockImplementation ( ( p , cb ) => cb ( null , true ) ) ;
292+ fsExtraMock . copy . mockImplementation ( ( from , to , cb ) => cb ( ) ) ;
293+ readFileSyncStub . mockReturnValueOnce ( originalPackageJSON ) ;
294+ readFileSyncStub . mockImplementation ( ( ) => {
295+ throw new Error ( 'Unexpected call to readFileSync' ) ;
296+ } ) ;
297+ packagerFactoryMock . get ( 'npm' ) . rebaseLockfile . mockImplementation ( ( pathToPackageRoot , lockfile ) => lockfile ) ;
298+ packagerFactoryMock . get ( 'npm' ) . getProdDependencies . mockReturnValue ( BbPromise . resolve ( { } ) ) ;
299+ packagerFactoryMock . get ( 'npm' ) . install . mockReturnValue ( BbPromise . resolve ( ) ) ;
300+ packagerFactoryMock . get ( 'npm' ) . prune . mockReturnValue ( BbPromise . resolve ( ) ) ;
301+ packagerFactoryMock . get ( 'npm' ) . runScripts . mockReturnValue ( BbPromise . resolve ( ) ) ;
302+ module . compileStats = stats ;
303+ return expect ( module . packExternalModules ( ) )
304+ . resolves . toBeUndefined ( )
305+ . then ( ( ) =>
306+ BbPromise . all ( [
307+ expect ( writeFileSyncStub ) . toHaveBeenCalledTimes ( 2 ) ,
308+ expect ( writeFileSyncStub . mock . calls [ 0 ] [ 1 ] ) . toEqual ( JSON . stringify ( expectedCompositePackageJSON , null , 2 ) ) ,
309+ expect ( writeFileSyncStub . mock . calls [ 1 ] [ 1 ] ) . toEqual ( JSON . stringify ( expectedPackageJSON , null , 2 ) )
310+ ] )
311+ ) ;
312+ } ) ;
313+
232314 it ( 'should install external modules' , ( ) => {
233315 const expectedCompositePackageJSON = {
234316 name : 'test-service' ,
0 commit comments