diff --git a/.changeset/red-islands-drop.md b/.changeset/red-islands-drop.md new file mode 100644 index 000000000..39d3319e8 --- /dev/null +++ b/.changeset/red-islands-drop.md @@ -0,0 +1,5 @@ +--- +"modular-scripts": patch +--- + +Bump @rollup/plugin-commonjs from 21.1.0 to 22.0.0 diff --git a/packages/modular-scripts/package.json b/packages/modular-scripts/package.json index 4fe84a74c..15e1d8a6f 100644 --- a/packages/modular-scripts/package.json +++ b/packages/modular-scripts/package.json @@ -24,7 +24,7 @@ "dependencies": { "@babel/code-frame": "7.16.7", "@rollup/plugin-babel": "5.3.1", - "@rollup/plugin-commonjs": "21.1.0", + "@rollup/plugin-commonjs": "22.0.0", "@rollup/plugin-json": "4.1.0", "@rollup/plugin-node-resolve": "13.2.1", "@svgr/core": "6.1.2", diff --git a/packages/modular-scripts/src/__tests__/__snapshots__/build.test.ts.snap b/packages/modular-scripts/src/__tests__/__snapshots__/build.test.ts.snap index b39931576..66a86d943 100644 --- a/packages/modular-scripts/src/__tests__/__snapshots__/build.test.ts.snap +++ b/packages/modular-scripts/src/__tests__/__snapshots__/build.test.ts.snap @@ -1,13 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`WHEN building with preserve modules SHOULD create the correct index.js 1`] = ` +"export { default } from './index2.js'; +//# sourceMappingURL=index.js.map +" +`; + +exports[`WHEN building with preserve modules SHOULD create the correct index2.js 1`] = ` "async function runInAsync() { const { runAsync } = await import('./runAsync.js'); return runAsync(); } export { runInAsync as default }; -//# sourceMappingURL=index.js.map +//# sourceMappingURL=index2.js.map " `; diff --git a/packages/modular-scripts/src/__tests__/__snapshots__/index.test.ts.snap b/packages/modular-scripts/src/__tests__/__snapshots__/index.test.ts.snap index 07a61c8d3..0c691163f 100644 --- a/packages/modular-scripts/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/modular-scripts/src/__tests__/__snapshots__/index.test.ts.snap @@ -1,8 +1,41 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`modular-scripts WHEN building a view THEN outputs the correct output cjs index2.js map file 1`] = ` +Object { + "file": "index2.js", + "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AACe,SAAS,UAAU,GAAG;AACrC,EAAE,uBAAuBA,gBAAK,CAAC,aAAa,CAAC,KAAK,EAAE;AACpD,IAAI,aAAa,EAAE,WAAW;AAC9B,GAAG,EAAE,wBAAwB,CAAC,CAAC;AAC/B;;;;", + "names": Array [ + "React", + ], + "sources": Array [ + "../src/index.tsx", + ], + "sourcesContent": Array [ + "import * as React from 'react'; + +export default function SampleView(): JSX.Element { + return
this is a modular view
+}", + ], + "version": 3, +} +`; + exports[`modular-scripts WHEN building a view THEN outputs the correct output cjs file 1`] = ` "'use strict'; +var index = require('./index2.js'); + + + +module.exports = index; +//# sourceMappingURL=index.js.map +" +`; + +exports[`modular-scripts WHEN building a view THEN outputs the correct output cjs index2.js file 1`] = ` +"'use strict'; + var React = require('react'); function _interopNamespace(e) { @@ -32,27 +65,17 @@ function SampleView() { } module.exports = SampleView; -//# sourceMappingURL=index.js.map +//# sourceMappingURL=index2.js.map " `; exports[`modular-scripts WHEN building a view THEN outputs the correct output cjs map file 1`] = ` Object { "file": "index.js", - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AACe,SAAS,UAAU,GAAG;AACrC,EAAE,uBAAuBA,gBAAK,CAAC,aAAa,CAAC,KAAK,EAAE;AACpD,IAAI,aAAa,EAAE,WAAW;AAC9B,GAAG,EAAE,wBAAwB,CAAC,CAAC;AAC/B;;;;", - "names": Array [ - "React", - ], - "sources": Array [ - "../src/index.tsx", - ], - "sourcesContent": Array [ - "import * as React from 'react'; - -export default function SampleView(): JSX.Element { - return
this is a modular view
-}", - ], + "mappings": ";;;;;;", + "names": Array [], + "sources": Array [], + "sourcesContent": Array [], "version": 3, } `; diff --git a/packages/modular-scripts/src/__tests__/build.test.ts b/packages/modular-scripts/src/__tests__/build.test.ts index f49918c53..2e262795c 100644 --- a/packages/modular-scripts/src/__tests__/build.test.ts +++ b/packages/modular-scripts/src/__tests__/build.test.ts @@ -52,13 +52,17 @@ describe('WHEN building with preserve modules', () => { .toMatchInlineSnapshot(` "sample-async-package ├─ dist-cjs - │ ├─ index.js #y5z0kw - │ ├─ index.js.map #1gofapj + │ ├─ index.js #p1m6x9 + │ ├─ index.js.map #16jes1h + │ ├─ index2.js #1gdggtn + │ ├─ index2.js.map #r11rcb │ ├─ runAsync.js #kr3qrh │ └─ runAsync.js.map #19q2dqp ├─ dist-es - │ ├─ index.js #7arwpf - │ ├─ index.js.map #p3aqj2 + │ ├─ index.js #tcl83f + │ ├─ index.js.map #yz1h1d + │ ├─ index2.js #67jtpf + │ ├─ index2.js.map #1pcnly9 │ ├─ runAsync.js #1tt0e7o │ └─ runAsync.js.map #1tlnsv0 ├─ dist-types @@ -84,6 +88,22 @@ describe('WHEN building with preserve modules', () => { ).toMatchSnapshot(); }); + it('SHOULD create the correct index2.js', () => { + expect( + String( + fs.readFileSync( + path.join( + getModularRoot(), + 'dist', + packageName, + 'dist-es', + 'index2.js', + ), + ), + ), + ).toMatchSnapshot(); + }); + it('SHOULD create the correct runAsync.js', () => { expect( String( @@ -149,11 +169,15 @@ describe('WHEN building packages with private cross-package dependencies', () => .toMatchInlineSnapshot(` "sample-depending-package ├─ dist-cjs - │ ├─ index.js #1gj4b9h - │ └─ index.js.map #1v4zj6b + │ ├─ index.js #1m9v9ya + │ ├─ index.js.map #79ot9r + │ ├─ index2.js #q6vf2j + │ └─ index2.js.map #10q3jzt ├─ dist-es - │ ├─ index.js #xezjee - │ └─ index.js.map #isxuu + │ ├─ index.js #3qxwo1 + │ ├─ index.js.map #yz1h1d + │ ├─ index2.js #14be4lv + │ └─ index2.js.map #jfjxet ├─ dist-types │ └─ index.d.ts #6hjmh9 └─ package.json" diff --git a/packages/modular-scripts/src/__tests__/index.test.ts b/packages/modular-scripts/src/__tests__/index.test.ts index 450c89a7c..ca7b2b846 100644 --- a/packages/modular-scripts/src/__tests__/index.test.ts +++ b/packages/modular-scripts/src/__tests__/index.test.ts @@ -259,16 +259,50 @@ describe('modular-scripts', () => { ).toMatchSnapshot(); }); + it('THEN outputs the correct output cjs index2.js file', () => { + expect( + String( + fs.readFileSync( + path.join( + modularRoot, + 'dist', + 'sample-view', + 'dist-cjs', + 'index2.js', + ), + ), + ), + ).toMatchSnapshot(); + }); + + it('THEN outputs the correct output cjs index2.js map file', () => { + expect( + fs.readJsonSync( + path.join( + modularRoot, + 'dist', + 'sample-view', + 'dist-cjs', + 'index2.js.map', + ), + ), + ).toMatchSnapshot(); + }); + it('THEN outputs the correct directory structure', () => { expect(tree(path.join(modularRoot, 'dist', 'sample-view'))) .toMatchInlineSnapshot(` "sample-view ├─ dist-cjs - │ ├─ index.js #a7k6ic - │ └─ index.js.map #1m4qim9 + │ ├─ index.js #p1m6x9 + │ ├─ index.js.map #16jes1h + │ ├─ index2.js #dbk75e + │ └─ index2.js.map #11cwgsp ├─ dist-es - │ ├─ index.js #1ymmv5l - │ └─ index.js.map #11lg0ox + │ ├─ index.js #tcl83f + │ ├─ index.js.map #yz1h1d + │ ├─ index2.js #urz4k4 + │ └─ index2.js.map #1w4fdrj ├─ dist-types │ └─ index.d.ts #1vloh7q └─ package.json" @@ -347,11 +381,15 @@ describe('modular-scripts', () => { .toMatchInlineSnapshot(` "sample-package ├─ dist-cjs - │ ├─ index.js #rq9uxe - │ └─ index.js.map #19satcx + │ ├─ index.js #p1m6x9 + │ ├─ index.js.map #16jes1h + │ ├─ index2.js #6y6kyx + │ └─ index2.js.map #10ij9v ├─ dist-es - │ ├─ index.js #3bszhr - │ └─ index.js.map #1m2nocl + │ ├─ index.js #tcl83f + │ ├─ index.js.map #yz1h1d + │ ├─ index2.js #hx36fq + │ └─ index2.js.map #bbrfkq ├─ dist-types │ └─ index.d.ts #f68aj └─ package.json" diff --git a/yarn.lock b/yarn.lock index d772ba63e..4ff51c294 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2061,10 +2061,10 @@ "@babel/helper-module-imports" "^7.10.4" "@rollup/pluginutils" "^3.1.0" -"@rollup/plugin-commonjs@21.1.0": - version "21.1.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-21.1.0.tgz#45576d7b47609af2db87f55a6d4b46e44fc3a553" - integrity sha512-6ZtHx3VHIp2ReNNDxHjuUml6ur+WcQ28N1yHgCQwsbNkQg2suhxGMDQGJOn/KuDxKtd1xuZP5xSTwBA4GQ8hbA== +"@rollup/plugin-commonjs@22.0.0": + version "22.0.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.0.tgz#f4d87016e2fbf187a593ab9f46626fe05b59e8bd" + integrity sha512-Ktvf2j+bAO+30awhbYoCaXpBcyPmJbaEUYClQns/+6SNCYFURbvBiNbWgHITEsIgDDWCDUclWRKEuf8cwZCFoQ== dependencies: "@rollup/pluginutils" "^3.1.0" commondir "^1.0.1"