From 6b587b7247c8f2b0674e752348f477ccdf6ae06d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 29 Sep 2020 23:04:00 +0200 Subject: [PATCH 01/21] [core] Ship modern bundle --- .browserslistrc | 50 ++++- babel.config.js | 185 ++++++++++-------- packages/material-ui-codemod/package.json | 2 +- packages/material-ui-docs/package.json | 8 +- packages/material-ui-icons/package.json | 9 +- packages/material-ui-lab/package.json | 9 +- .../material-ui-styled-engine-sc/package.json | 9 +- .../material-ui-styled-engine/package.json | 9 +- packages/material-ui-styles/package.json | 9 +- packages/material-ui-system/package.json | 9 +- packages/material-ui-utils/package.json | 9 +- packages/material-ui/package.json | 11 +- scripts/build.js | 31 ++- scripts/copy-files.js | 11 +- scripts/sizeSnapshot/create.js | 5 + scripts/sizeSnapshot/webpack.config.js | 86 ++++---- 16 files changed, 276 insertions(+), 176 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index a437b1bf007c9e..49446da39f6530 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,6 +1,44 @@ -ie 11 -edge >= 14 -firefox >= 52 -chrome >= 49 -safari >= 10 -node 8.0 +[modern] +last 1 chrome version +last 1 edge version +last 1 firefox version +last 1 safari version +node 14 + +# snapshot of "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11" when the last major is released. +[stable] +and_chr 84 +and_ff 79 +and_qq 10.4 +and_uc 12.12 +android 81 +baidu 7.12 +chrome 83 +edge 83 +firefox 68 +ios_saf 12.0 +kaios 2.5 +op_mob 46 +opera 69 +safari 13 +samsung 11.1 + +# Default/Fallback +# Same as `stable` but with IE 11 +[production] +IE 11 +and_chr 84 +and_ff 79 +and_qq 10.4 +and_uc 12.12 +android 81 +baidu 7.12 +chrome 83 +edge 83 +firefox 68 +ios_saf 12.0 +kaios 2.5 +op_mob 46 +opera 69 +safari 13 +samsung 11.1 diff --git a/babel.config.js b/babel.config.js index 2023a104f5328f..1fda3a82b259ca 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,25 +3,6 @@ const path = require('path'); const errorCodesPath = path.resolve(__dirname, './docs/public/static/error-codes.json'); const missingError = process.env.MUI_EXTRACT_ERROR_CODES === 'true' ? 'write' : 'annotate'; -let defaultPresets; - -// We release a ES version of Material-UI. -// It's something that matches the latest official supported features of JavaScript. -// Nothing more (stage-1, etc), nothing less (require, etc). -if (process.env.BABEL_ENV === 'es') { - defaultPresets = []; -} else { - defaultPresets = [ - [ - '@babel/preset-env', - { - bugfixes: true, - modules: ['esm', 'production-umd'].includes(process.env.BABEL_ENV) ? false : 'commonjs', - }, - ], - ]; -} - const defaultAlias = { '@material-ui/core': './packages/material-ui/src', '@material-ui/docs': './packages/material-ui-docs/src', @@ -46,9 +27,23 @@ const productionPlugins = [ ], ]; -module.exports = { - presets: defaultPresets.concat(['@babel/preset-react', '@babel/preset-typescript']), - plugins: [ +module.exports = function getBabelConfig(api) { + const presets = [ + [ + '@babel/preset-env', + { + bugfixes: true, + browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV, + debug: process.env.MUI_BUILD_VERBOSE === 'true', + modules: api.env(['legacy', 'modern', 'stable', 'production-umd']) ? false : 'commonjs', + shippedProposals: api.env('modern'), + }, + ], + '@babel/preset-react', + '@babel/preset-typescript', + ]; + + const plugins = [ [ 'babel-plugin-macros', { @@ -59,77 +54,99 @@ module.exports = { }, ], 'babel-plugin-optimize-clsx', + // Need the following 3 proposals for all targets in .browserslistrc. + // With our usage the transpiled loose mode is equivalent to spec mode. ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-private-methods', { loose: true }], ['@babel/plugin-proposal-object-rest-spread', { loose: true }], // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 ['@babel/plugin-transform-runtime', { version: '^7.4.4' }], + ]; + if (api.env('legacy')) { // for IE 11 support - '@babel/plugin-transform-object-assign', - ], - ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue. - env: { - cjs: { - plugins: productionPlugins, - }, - coverage: { - plugins: [ - 'babel-plugin-istanbul', - [ - 'babel-plugin-module-resolver', - { - root: ['./'], - alias: defaultAlias, - }, + plugins.push('@babel/plugin-transform-object-assign'); + } + + return { + presets, + plugins, + ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue. + env: { + cjs: { + plugins: productionPlugins, + }, + coverage: { + plugins: [ + 'babel-plugin-istanbul', + [ + 'babel-plugin-module-resolver', + { + root: ['./'], + alias: defaultAlias, + }, + ], ], - ], - }, - development: { - plugins: [ - [ - 'babel-plugin-module-resolver', - { - alias: { - modules: './modules', + }, + development: { + plugins: [ + [ + 'babel-plugin-module-resolver', + { + alias: { + modules: './modules', + }, }, - }, + ], ], - ], - }, - esm: { - plugins: [...productionPlugins, ['@babel/plugin-transform-runtime', { useESModules: true }]], - }, - es: { - plugins: [...productionPlugins, ['@babel/plugin-transform-runtime', { useESModules: true }]], - }, - production: { - plugins: [...productionPlugins, ['@babel/plugin-transform-runtime', { useESModules: true }]], - }, - 'production-umd': { - plugins: [...productionPlugins, ['@babel/plugin-transform-runtime', { useESModules: true }]], - }, - test: { - sourceMaps: 'both', - plugins: [ - [ - 'babel-plugin-module-resolver', - { - root: ['./'], - alias: defaultAlias, - }, + }, + esm: { + plugins: [ + ...productionPlugins, + ['@babel/plugin-transform-runtime', { useESModules: true }], ], - ], - }, - benchmark: { - plugins: [ - ...productionPlugins, - [ - 'babel-plugin-module-resolver', - { - root: ['./'], - alias: defaultAlias, - }, + }, + es: { + plugins: [ + ...productionPlugins, + ['@babel/plugin-transform-runtime', { useESModules: true }], ], - ], + }, + production: { + plugins: [ + ...productionPlugins, + ['@babel/plugin-transform-runtime', { useESModules: true }], + ], + }, + 'production-umd': { + plugins: [ + ...productionPlugins, + ['@babel/plugin-transform-runtime', { useESModules: true }], + ], + }, + test: { + sourceMaps: 'both', + plugins: [ + [ + 'babel-plugin-module-resolver', + { + root: ['./'], + alias: defaultAlias, + }, + ], + ], + }, + benchmark: { + plugins: [ + ...productionPlugins, + [ + 'babel-plugin-module-resolver', + { + root: ['./'], + alias: defaultAlias, + }, + ], + ], + }, }, - }, + }; }; diff --git a/packages/material-ui-codemod/package.json b/packages/material-ui-codemod/package.json index d521efe7612b93..f58174ff2c3d92 100644 --- a/packages/material-ui-codemod/package.json +++ b/packages/material-ui-codemod/package.json @@ -14,7 +14,7 @@ "scripts": { "test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-codemod/**/*.test.js'", "prebuild": "rimraf lib", - "build": "node ../../scripts/build cjs --out-dir ./lib", + "build": "node ../../scripts/build node --out-dir ./lib", "release": "yarn build && npm publish --tag next" }, "repository": { diff --git a/packages/material-ui-docs/package.json b/packages/material-ui-docs/package.json index fdc2afa48fedfd..97774d9e8f4708 100644 --- a/packages/material-ui-docs/package.json +++ b/packages/material-ui-docs/package.json @@ -23,9 +23,11 @@ }, "homepage": "https://github.com/mui-org/material-ui/tree/next/packages/material-ui-lab", "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "echo 'Skip modern build'", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-icons/package.json b/packages/material-ui-icons/package.json index 478029df11299b..7e5a1fa3067321 100644 --- a/packages/material-ui-icons/package.json +++ b/packages/material-ui-icons/package.json @@ -23,10 +23,11 @@ }, "homepage": "https://material-ui.com/components/icons", "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:typings && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "echo 'skip es folder'", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:typings && yarn build:copy-files", + "build:legacy": "echo 'Skip legacy build'", + "build:modern": "echo 'Skip modern build'", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "build:typings": "babel-node --config-file ../../babel.config.js ./scripts/create-typings.js", "prebuild": "rimraf material-design-icons && rimraf build", diff --git a/packages/material-ui-lab/package.json b/packages/material-ui-lab/package.json index 0162a62018197b..bd9efc90243600 100644 --- a/packages/material-ui-lab/package.json +++ b/packages/material-ui-lab/package.json @@ -23,10 +23,11 @@ }, "homepage": "https://material-ui.com/components/about-the-lab", "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-styled-engine-sc/package.json b/packages/material-ui-styled-engine-sc/package.json index eeaa6af68b4255..667930e2bcadec 100644 --- a/packages/material-ui-styled-engine-sc/package.json +++ b/packages/material-ui-styled-engine-sc/package.json @@ -26,10 +26,11 @@ "url": "https://opencollective.com/material-ui" }, "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-styled-engine/package.json b/packages/material-ui-styled-engine/package.json index ceff317e2872da..f7f84fdf49c7e5 100644 --- a/packages/material-ui-styled-engine/package.json +++ b/packages/material-ui-styled-engine/package.json @@ -26,10 +26,11 @@ "url": "https://opencollective.com/material-ui" }, "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-styles/package.json b/packages/material-ui-styles/package.json index bfcd787e34452e..6462fd806adf93 100644 --- a/packages/material-ui-styles/package.json +++ b/packages/material-ui-styles/package.json @@ -26,10 +26,11 @@ "url": "https://opencollective.com/material-ui" }, "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-system/package.json b/packages/material-ui-system/package.json index d441f39a6de372..898ad3fd282b50 100644 --- a/packages/material-ui-system/package.json +++ b/packages/material-ui-system/package.json @@ -26,10 +26,11 @@ "url": "https://opencollective.com/material-ui" }, "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", diff --git a/packages/material-ui-utils/package.json b/packages/material-ui-utils/package.json index d4cb2f10858365..a47b693efc5db4 100644 --- a/packages/material-ui-utils/package.json +++ b/packages/material-ui-utils/package.json @@ -22,10 +22,11 @@ }, "homepage": "https://github.com/mui-org/material-ui/tree/next/packages/material-ui-utils", "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files && yarn build:types", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:copy-files && yarn build:types", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:copy-files": "node ../../scripts/copy-files.js", "build:types": "tsc -p tsconfig.build.json", "prebuild": "rimraf build", diff --git a/packages/material-ui/package.json b/packages/material-ui/package.json index 818f840cff4a29..aa79a1bfef2dd0 100644 --- a/packages/material-ui/package.json +++ b/packages/material-ui/package.json @@ -25,10 +25,11 @@ "url": "https://opencollective.com/material-ui" }, "scripts": { - "build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:umd && yarn build:copy-files && yarn build:types", - "build:cjs": "node ../../scripts/build cjs", - "build:esm": "node ../../scripts/build esm", - "build:es": "node ../../scripts/build es", + "build": "yarn build:legacy && yarn build:modern &&yarn build:node && yarn build:stable && yarn build:umd && yarn build:copy-files && yarn build:types", + "build:legacy": "node ../../scripts/build legacy", + "build:modern": "node ../../scripts/build modern", + "build:node": "node ../../scripts/build node", + "build:stable": "node ../../scripts/build stable", "build:umd": "cross-env BABEL_ENV=production-umd rollup -c scripts/rollup.config.js", "build:copy-files": "node ../../scripts/copy-files.js", "build:types": "tsc -p tsconfig.build.json", @@ -77,6 +78,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/scripts/build.js b/scripts/build.js index 8271e7907306a5..112de544c2acc7 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -6,12 +6,14 @@ const yargs = require('yargs'); const exec = promisify(childProcess.exec); const validBundles = [ - // legacy build using commonJS modules - 'cjs', - // modern build - 'es', // legacy build using ES6 modules - 'esm', + 'legacy', + // modern build with a rolling target using ES6 modules + 'modern', + // build for node using commonJS modules + 'node', + // build with a hardcoded target using ES6 modules + 'stable', ]; async function run(argv) { @@ -24,18 +26,19 @@ async function run(argv) { } const env = { - ...process.env, NODE_ENV: 'production', BABEL_ENV: bundle, + MUI_BUILD_VERBOSE: verbose, }; const babelConfigPath = path.resolve(__dirname, '../babel.config.js'); const srcDir = path.resolve('./src'); const outDir = path.resolve( relativeOutDir, { - cjs: '.', - esm: './esm', - es: './es', + node: './node', + modern: './modern', + stable: './', + legacy: './legacy', }[bundle], ); @@ -65,7 +68,15 @@ async function run(argv) { console.log(`running '${command}' with ${JSON.stringify(env)}`); } - return exec(command, { env }); + const { stderr, stdout } = await exec(command, { env: { ...process.env, ...env } }); + if (stderr) { + throw new Error(`'${command}' failed with \n${stderr}`); + } + + if (verbose) { + // eslint-disable-next-line no-console + console.log(stdout); + } } yargs diff --git a/scripts/copy-files.js b/scripts/copy-files.js index 108c7e3212d611..18104ef7917f50 100644 --- a/scripts/copy-files.js +++ b/scripts/copy-files.js @@ -30,7 +30,8 @@ async function createModulePackages({ from, to }) { directoryPackages.map(async (directoryPackage) => { const packageJson = { sideEffects: false, - module: path.join('../esm', directoryPackage, 'index.js'), + module: './index.js', + main: path.join('../node', directoryPackage, 'index.js'), typings: './index.d.ts', }; const packageJsonPath = path.join(to, directoryPackage, 'package.json'); @@ -68,8 +69,8 @@ async function createPackageFile() { const newPackageData = { ...packageDataOther, private: false, - main: './index.js', - module: './esm/index.js', + main: './node/index.js', + module: './index.js', typings: './index.d.ts', }; const targetPath = path.resolve(buildPath, './package.json'); @@ -95,7 +96,9 @@ async function addLicense(packageData) { await Promise.all( [ './index.js', - './esm/index.js', + './legacy/index.js', + './modern/index.js', + './node/index.js', './umd/material-ui.development.js', './umd/material-ui.production.min.js', ].map(async (file) => { diff --git a/scripts/sizeSnapshot/create.js b/scripts/sizeSnapshot/create.js index 2657bb1ba9b197..88e018e75c0768 100644 --- a/scripts/sizeSnapshot/create.js +++ b/scripts/sizeSnapshot/create.js @@ -39,6 +39,11 @@ async function getWebpackSizes() { // memory. This will sometimes crash node in azure pipelines with "heap out of memory" const webpackStats = await webpack(await createWebpackConfig(webpack)); const stats = webpackStats.toJson(); + if (stats.errors.length > 0) { + throw new Error( + `The following errors occured during bundling with webpack: \n${stats.errors.join('\n')}`, + ); + } const assets = new Map(stats.assets.map((asset) => [asset.name, asset])); diff --git a/scripts/sizeSnapshot/webpack.config.js b/scripts/sizeSnapshot/webpack.config.js index a95d9d87918595..28e88a0e403594 100644 --- a/scripts/sizeSnapshot/webpack.config.js +++ b/scripts/sizeSnapshot/webpack.config.js @@ -8,36 +8,40 @@ const glob = promisify(globCallback); const workspaceRoot = path.join(__dirname, '..', '..'); async function getSizeLimitBundles() { - const corePackagePath = path.join(workspaceRoot, 'packages/material-ui/build/esm'); - const coreComponents = (await glob(path.join(corePackagePath, '[A-Z]*'))).map((componentPath) => { - const componentName = path.basename(componentPath); - let entryName = componentName; - // adjust for legacy names - if (componentName === 'Paper') { - entryName = '@material-ui/core/Paper.esm'; - } else if (componentName === 'TextareaAutosize') { - entryName = '@material-ui/core/Textarea'; - } else if (['Popper'].indexOf(componentName) !== -1) { - entryName = `@material-ui/core/${componentName}`; - } + const corePackagePath = path.join(workspaceRoot, 'packages/material-ui/build'); + const coreComponents = (await glob(path.join(corePackagePath, '[A-Z]*/index.js'))).map( + (componentPath) => { + const componentName = path.basename(path.dirname(componentPath)); + let entryName = componentName; + // adjust for legacy names + if (componentName === 'Paper') { + entryName = '@material-ui/core/Paper.esm'; + } else if (componentName === 'TextareaAutosize') { + entryName = '@material-ui/core/Textarea'; + } else if (['Popper'].indexOf(componentName) !== -1) { + entryName = `@material-ui/core/${componentName}`; + } - return { - name: entryName, - webpack: true, - path: path.relative(workspaceRoot, componentPath), - }; - }); + return { + name: entryName, + webpack: true, + path: path.relative(workspaceRoot, path.dirname(componentPath)), + }; + }, + ); - const labPackagePath = path.join(workspaceRoot, 'packages/material-ui-lab/build/esm'); - const labComponents = (await glob(path.join(labPackagePath, '[A-Z]*'))).map((componentPath) => { - const componentName = path.basename(componentPath); + const labPackagePath = path.join(workspaceRoot, 'packages/material-ui-lab/build'); + const labComponents = (await glob(path.join(labPackagePath, '[A-Z]*/index.js'))).map( + (componentPath) => { + const componentName = path.basename(path.dirname(componentPath)); - return { - name: componentName, - webpack: true, - path: path.relative(workspaceRoot, componentPath), - }; - }); + return { + name: componentName, + webpack: true, + path: path.relative(workspaceRoot, path.dirname(componentPath)), + }; + }, + ); return [ { @@ -53,44 +57,56 @@ async function getSizeLimitBundles() { { name: '@material-ui/styles', webpack: true, - path: 'packages/material-ui-styles/build/esm/index.js', + path: 'packages/material-ui-styles/build/index.js', }, { name: '@material-ui/system', webpack: true, - path: 'packages/material-ui-system/build/esm/index.js', + path: 'packages/material-ui-system/build/index.js', }, ...coreComponents, { name: '@material-ui/core/styles/createMuiTheme', webpack: true, - path: 'packages/material-ui/build/esm/styles/createMuiTheme.js', + path: 'packages/material-ui/build/styles/createMuiTheme.js', }, { name: 'colorManipulator', webpack: true, - path: 'packages/material-ui/build/esm/styles/colorManipulator.js', + path: 'packages/material-ui/build/styles/colorManipulator.js', }, ...labComponents, { name: 'useAutocomplete', webpack: true, - path: 'packages/material-ui-lab/build/esm/useAutocomplete/index.js', + path: 'packages/material-ui-lab/build/useAutocomplete/index.js', }, { name: '@material-ui/core/useMediaQuery', webpack: true, - path: 'packages/material-ui/build/esm/useMediaQuery/index.js', + path: 'packages/material-ui/build/useMediaQuery/index.js', }, { name: '@material-ui/core/useScrollTrigger', webpack: true, - path: 'packages/material-ui/build/esm/useScrollTrigger/index.js', + path: 'packages/material-ui/build/useScrollTrigger/index.js', }, { name: '@material-ui/utils', webpack: true, - path: 'packages/material-ui-utils/build/esm/index.js', + path: 'packages/material-ui-utils/build/index.js', + }, + // TODO: Needs webpack 5 + // https://github.com/webpack/webpack/issues/10227 + // { + // name: '@material-ui/core.modern', + // webpack: true, + // path: path.join(path.relative(workspaceRoot, corePackagePath), 'modern/index.js'), + // }, + { + name: '@material-ui/core.legacy', + webpack: true, + path: path.join(path.relative(workspaceRoot, corePackagePath), 'legacy/index.js'), }, ]; } From 0e11b39b0f391adcd4f2e7ae362f14590038f476 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 30 Sep 2020 10:05:58 +0200 Subject: [PATCH 02/21] Fix `yarn extract-error-codes` --- packages/material-ui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui/package.json b/packages/material-ui/package.json index aa79a1bfef2dd0..22701201d3d46e 100644 --- a/packages/material-ui/package.json +++ b/packages/material-ui/package.json @@ -33,7 +33,7 @@ "build:umd": "cross-env BABEL_ENV=production-umd rollup -c scripts/rollup.config.js", "build:copy-files": "node ../../scripts/copy-files.js", "build:types": "tsc -p tsconfig.build.json", - "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true yarn build:esm", + "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true yarn build:modern", "prebuild": "rimraf build", "release": "yarn build && npm publish build --tag next", "test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui/**/*.test.{js,ts,tsx}' --exclude '**/node_modules/**'", From 8a75f9c3d33db42bd0b9264afc35a372a016f822 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 30 Sep 2020 10:07:42 +0200 Subject: [PATCH 03/21] Update engines --- packages/material-ui-benchmark/package.json | 2 +- packages/material-ui-codemod/package.json | 2 +- packages/material-ui-docs/package.json | 2 +- packages/material-ui-icons/package.json | 2 +- packages/material-ui-lab/package.json | 2 +- packages/material-ui-styled-engine-sc/package.json | 2 +- packages/material-ui-styled-engine/package.json | 2 +- packages/material-ui-styles/package.json | 2 +- packages/material-ui-system/package.json | 2 +- packages/material-ui-utils/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/material-ui-benchmark/package.json b/packages/material-ui-benchmark/package.json index e1fec970b36713..b5f08e4d963e83 100644 --- a/packages/material-ui-benchmark/package.json +++ b/packages/material-ui-benchmark/package.json @@ -20,7 +20,7 @@ "test": "exit 0" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" }, "license": "MIT", "dependencies": { diff --git a/packages/material-ui-codemod/package.json b/packages/material-ui-codemod/package.json index f58174ff2c3d92..fc9b125dd75cb3 100644 --- a/packages/material-ui-codemod/package.json +++ b/packages/material-ui-codemod/package.json @@ -37,6 +37,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-docs/package.json b/packages/material-ui-docs/package.json index 97774d9e8f4708..f74887e59293ef 100644 --- a/packages/material-ui-docs/package.json +++ b/packages/material-ui-docs/package.json @@ -54,6 +54,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-icons/package.json b/packages/material-ui-icons/package.json index 7e5a1fa3067321..ed6bdff68d0198 100644 --- a/packages/material-ui-icons/package.json +++ b/packages/material-ui-icons/package.json @@ -64,6 +64,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-lab/package.json b/packages/material-ui-lab/package.json index bd9efc90243600..e20507c532245a 100644 --- a/packages/material-ui-lab/package.json +++ b/packages/material-ui-lab/package.json @@ -61,6 +61,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-styled-engine-sc/package.json b/packages/material-ui-styled-engine-sc/package.json index 667930e2bcadec..518fee6ffa1434 100644 --- a/packages/material-ui-styled-engine-sc/package.json +++ b/packages/material-ui-styled-engine-sc/package.json @@ -52,6 +52,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-styled-engine/package.json b/packages/material-ui-styled-engine/package.json index f7f84fdf49c7e5..187d5ad093d505 100644 --- a/packages/material-ui-styled-engine/package.json +++ b/packages/material-ui-styled-engine/package.json @@ -55,6 +55,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-styles/package.json b/packages/material-ui-styles/package.json index 6462fd806adf93..c1fc76eef7d127 100644 --- a/packages/material-ui-styles/package.json +++ b/packages/material-ui-styles/package.json @@ -70,6 +70,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-system/package.json b/packages/material-ui-system/package.json index 898ad3fd282b50..77a92a9991f1b7 100644 --- a/packages/material-ui-system/package.json +++ b/packages/material-ui-system/package.json @@ -58,6 +58,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } diff --git a/packages/material-ui-utils/package.json b/packages/material-ui-utils/package.json index a47b693efc5db4..9e978337eb188c 100644 --- a/packages/material-ui-utils/package.json +++ b/packages/material-ui-utils/package.json @@ -56,6 +56,6 @@ "access": "public" }, "engines": { - "node": ">=8.0.0" + "node": ">=10.0.0" } } From acfead40f3800f00878d2dab0df00bc95f354e36 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 30 Sep 2020 10:28:52 +0200 Subject: [PATCH 04/21] Use esm babel helpers when using ES6 modules --- babel.config.js | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/babel.config.js b/babel.config.js index 1fda3a82b259ca..895e6fe7865ce7 100644 --- a/babel.config.js +++ b/babel.config.js @@ -28,6 +28,8 @@ const productionPlugins = [ ]; module.exports = function getBabelConfig(api) { + const useESModules = api.env(['legacy', 'modern', 'stable', 'production-umd']); + const presets = [ [ '@babel/preset-env', @@ -35,7 +37,7 @@ module.exports = function getBabelConfig(api) { bugfixes: true, browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV, debug: process.env.MUI_BUILD_VERBOSE === 'true', - modules: api.env(['legacy', 'modern', 'stable', 'production-umd']) ? false : 'commonjs', + modules: useESModules ? false : 'commonjs', shippedProposals: api.env('modern'), }, ], @@ -59,12 +61,18 @@ module.exports = function getBabelConfig(api) { ['@babel/plugin-proposal-class-properties', { loose: true }], ['@babel/plugin-proposal-private-methods', { loose: true }], ['@babel/plugin-proposal-object-rest-spread', { loose: true }], - // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 - ['@babel/plugin-transform-runtime', { version: '^7.4.4' }], + [ + '@babel/plugin-transform-runtime', + { + useESModules, + // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 + version: '^7.4.4', + }, + ], ]; - if (api.env('legacy')) { - // for IE 11 support - plugins.push('@babel/plugin-transform-object-assign'); + + if (process.env.NODE_ENV === 'production') { + plugins.push(...productionPlugins); } return { @@ -72,9 +80,6 @@ module.exports = function getBabelConfig(api) { plugins, ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue. env: { - cjs: { - plugins: productionPlugins, - }, coverage: { plugins: [ 'babel-plugin-istanbul', @@ -99,28 +104,10 @@ module.exports = function getBabelConfig(api) { ], ], }, - esm: { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - es: { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - production: { + legacy: { plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - 'production-umd': { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], + // IE 11 support + '@babel/plugin-transform-object-assign', ], }, test: { From 8994e78accbf0e1d89c95859b2d9ca6ede0c6a93 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 30 Sep 2020 11:04:11 +0200 Subject: [PATCH 05/21] Forgot op_mini --- .browserslistrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.browserslistrc b/.browserslistrc index 49446da39f6530..022f05157ab94c 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -18,6 +18,7 @@ edge 83 firefox 68 ios_saf 12.0 kaios 2.5 +op_mini all op_mob 46 opera 69 safari 13 @@ -38,6 +39,7 @@ edge 83 firefox 68 ios_saf 12.0 kaios 2.5 +op_mini all op_mob 46 opera 69 safari 13 From da4cd9bb897969f2ed7ce715fc38e95919d37576 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 30 Sep 2020 11:47:33 +0200 Subject: [PATCH 06/21] Use `stable` bundle as default --- .browserslistrc | 8 ++++---- babel.config.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 022f05157ab94c..0e2dc6b7665a81 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -5,8 +5,9 @@ last 1 firefox version last 1 safari version node 14 +# Default/Fallback # snapshot of "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11" when the last major is released. -[stable] +[production] and_chr 84 and_ff 79 and_qq 10.4 @@ -24,9 +25,8 @@ opera 69 safari 13 samsung 11.1 -# Default/Fallback -# Same as `stable` but with IE 11 -[production] +# Same as `production` but with IE 11 +[legacy] IE 11 and_chr 84 and_ff 79 diff --git a/babel.config.js b/babel.config.js index 895e6fe7865ce7..568464695e41eb 100644 --- a/babel.config.js +++ b/babel.config.js @@ -35,7 +35,9 @@ module.exports = function getBabelConfig(api) { '@babel/preset-env', { bugfixes: true, - browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV, + // Use `[production]` entry if no environment matches. + // Seems like `browserslist` doesn't support these semantics so we have to implement them here. + browserslistEnv: api.env(['modern', 'stable']) ? process.env.BABEL_ENV : 'production', debug: process.env.MUI_BUILD_VERBOSE === 'true', modules: useESModules ? false : 'commonjs', shippedProposals: api.env('modern'), From eae0e0a0735c7f423e26602f8dcc558ad04b78d7 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 1 Oct 2020 09:40:26 +0200 Subject: [PATCH 07/21] Fix issues related to assumed transpilation --- .browserslistrc | 15 +++++++++++++++ babel.config.js | 13 ++++++++++--- framer/Material-UI.framerfx/code/Avatar.tsx | 2 +- framer/Material-UI.framerfx/code/Chip.tsx | 2 +- .../code/CircularProgress.tsx | 2 +- .../Material-UI.framerfx/code/LinearProgress.tsx | 4 ++-- framer/Material-UI.framerfx/code/ListItem.tsx | 8 ++++---- framer/scripts/buildFramer.js | 2 +- .../src/elementTypeAcceptingRef.ts | 2 +- .../material-ui-utils/src/getDisplayName.test.tsx | 3 --- test/karma.conf.js | 15 +++++++++------ 11 files changed, 45 insertions(+), 23 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 0e2dc6b7665a81..02b1d38ee1d3d6 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -44,3 +44,18 @@ op_mob 46 opera 69 safari 13 samsung 11.1 + +[coverage] +node 10.0 + +[development] +node 10.0 + +[node] +node 10.0 + +[test] +node 10.0 + +[benchmark] +node 10.0 diff --git a/babel.config.js b/babel.config.js index 568464695e41eb..3c28f0fd0f72da 100644 --- a/babel.config.js +++ b/babel.config.js @@ -35,9 +35,7 @@ module.exports = function getBabelConfig(api) { '@babel/preset-env', { bugfixes: true, - // Use `[production]` entry if no environment matches. - // Seems like `browserslist` doesn't support these semantics so we have to implement them here. - browserslistEnv: api.env(['modern', 'stable']) ? process.env.BABEL_ENV : 'production', + browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV, debug: process.env.MUI_BUILD_VERBOSE === 'true', modules: useESModules ? false : 'commonjs', shippedProposals: api.env('modern'), @@ -76,6 +74,15 @@ module.exports = function getBabelConfig(api) { if (process.env.NODE_ENV === 'production') { plugins.push(...productionPlugins); } + if (process.env.NODE_ENV === 'test') { + plugins.push([ + 'babel-plugin-module-resolver', + { + alias: defaultAlias, + root: ['./'], + }, + ]); + } return { presets, diff --git a/framer/Material-UI.framerfx/code/Avatar.tsx b/framer/Material-UI.framerfx/code/Avatar.tsx index 90d9e2f54501af..fe8282d692ffd7 100644 --- a/framer/Material-UI.framerfx/code/Avatar.tsx +++ b/framer/Material-UI.framerfx/code/Avatar.tsx @@ -67,7 +67,7 @@ addPropertyControls(Avatar, { avatarImageUrl: { type: ControlType.String, title: 'Avatar Image URL', - hidden: function hidden(props) { + hidden(props) { return props.avatarImageFile !== ''; }, }, diff --git a/framer/Material-UI.framerfx/code/Chip.tsx b/framer/Material-UI.framerfx/code/Chip.tsx index 01ae95cc7ba864..271eb15aac42e6 100644 --- a/framer/Material-UI.framerfx/code/Chip.tsx +++ b/framer/Material-UI.framerfx/code/Chip.tsx @@ -102,7 +102,7 @@ addPropertyControls(Chip, { avatarImageUrl: { type: ControlType.String, title: 'Avatar Image URL', - hidden: function hidden(props) { + hidden(props) { return props.avatarImageFile !== ''; }, }, diff --git a/framer/Material-UI.framerfx/code/CircularProgress.tsx b/framer/Material-UI.framerfx/code/CircularProgress.tsx index 3f6b58e1641d49..75c311e70854db 100644 --- a/framer/Material-UI.framerfx/code/CircularProgress.tsx +++ b/framer/Material-UI.framerfx/code/CircularProgress.tsx @@ -41,7 +41,7 @@ addPropertyControls(CircularProgress, { value: { type: ControlType.Number, title: 'Value', - hidden: function hidden(props) { + hidden(props) { return props.variant === 'indeterminate'; }, }, diff --git a/framer/Material-UI.framerfx/code/LinearProgress.tsx b/framer/Material-UI.framerfx/code/LinearProgress.tsx index 4969e9852df316..1d0e7c51ffef31 100644 --- a/framer/Material-UI.framerfx/code/LinearProgress.tsx +++ b/framer/Material-UI.framerfx/code/LinearProgress.tsx @@ -36,14 +36,14 @@ addPropertyControls(LinearProgress, { value: { type: ControlType.Number, title: 'Value', - hidden: function hidden(props) { + hidden(props) { return props.variant === 'indeterminate'; }, }, valueBuffer: { type: ControlType.Number, title: 'Value buffer', - hidden: function hidden(props) { + hidden(props) { return props.variant !== 'buffer'; }, }, diff --git a/framer/Material-UI.framerfx/code/ListItem.tsx b/framer/Material-UI.framerfx/code/ListItem.tsx index d55ab6f310af6f..e1fedabe321086 100644 --- a/framer/Material-UI.framerfx/code/ListItem.tsx +++ b/framer/Material-UI.framerfx/code/ListItem.tsx @@ -186,7 +186,7 @@ addPropertyControls(ListItem, { primaryIcon: { type: ControlType.String, title: 'Primary icon', - hidden: function hidden(props) { + hidden(props) { return ( (props.primaryAction !== 'icon' && props.primaryAction !== 'avatar') || props.imageFile !== '' || @@ -197,14 +197,14 @@ addPropertyControls(ListItem, { imageFile: { type: ControlType.Image, title: 'Image File', - hidden: function hidden(props) { + hidden(props) { return props.primaryAction !== undefined && props.primaryAction !== 'avatar'; }, }, imageUrl: { type: ControlType.String, title: 'Image URL', - hidden: function hidden(props) { + hidden(props) { return ( props.imageFile !== '' || (props.primaryAction !== undefined && props.primaryAction !== 'avatar') @@ -219,7 +219,7 @@ addPropertyControls(ListItem, { secondaryIcon: { type: ControlType.String, title: 'Secondary icon', - hidden: function hidden(props) { + hidden(props) { return props.secondaryAction !== 'iconButton'; }, }, diff --git a/framer/scripts/buildFramer.js b/framer/scripts/buildFramer.js index fdceb439651151..da1685bdeeec12 100644 --- a/framer/scripts/buildFramer.js +++ b/framer/scripts/buildFramer.js @@ -176,7 +176,7 @@ ${propName}: { }${ hidden ? ` - hidden: ${hidden},` + ${hidden},` : '' }${otherValues(other)} },`; diff --git a/packages/material-ui-utils/src/elementTypeAcceptingRef.ts b/packages/material-ui-utils/src/elementTypeAcceptingRef.ts index caccb2dcee5ebc..e552f03b273f95 100644 --- a/packages/material-ui-utils/src/elementTypeAcceptingRef.ts +++ b/packages/material-ui-utils/src/elementTypeAcceptingRef.ts @@ -3,7 +3,7 @@ import chainPropTypes from './chainPropTypes'; function isClassComponent(elementType: Function) { // elementType.prototype?.isReactComponent - const { prototype } = elementType; + const { prototype = {} } = elementType; return Boolean(prototype.isReactComponent); } diff --git a/packages/material-ui-utils/src/getDisplayName.test.tsx b/packages/material-ui-utils/src/getDisplayName.test.tsx index 45dc0f600a558c..2206382968ea3c 100644 --- a/packages/material-ui-utils/src/getDisplayName.test.tsx +++ b/packages/material-ui-utils/src/getDisplayName.test.tsx @@ -75,10 +75,7 @@ describe('utils/getDisplayName.js', () => { return
; } - const SomeOtherFunction = () =>
; - expect(getFunctionName(SomeFunction)).to.equal('SomeFunction'); - expect(getFunctionName(SomeOtherFunction)).to.equal('SomeOtherFunction'); }); }); }); diff --git a/test/karma.conf.js b/test/karma.conf.js index 38e460e8b72fcd..242a359c35bf91 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -58,6 +58,9 @@ module.exports = function setKarmaConfig(config) { test: /\.(js|ts|tsx)$/, loader: 'babel-loader', exclude: /node_modules/, + options: { + envName: 'stable', + }, }, ], }, @@ -114,30 +117,30 @@ module.exports = function setKarmaConfig(config) { BrowserStack_Chrome: { base: 'BrowserStack', os: 'OS X', - os_version: 'Sierra', + os_version: 'Catalina', browser: 'chrome', - browser_version: '49.0', + browser_version: '83.0', }, BrowserStack_Firefox: { base: 'BrowserStack', os: 'Windows', os_version: '10', browser: 'firefox', - browser_version: '52.0', + browser_version: '68.0', }, BrowserStack_Safari: { base: 'BrowserStack', os: 'OS X', - os_version: 'Sierra', + os_version: 'Catalina', browser: 'safari', - browser_version: '10.1', + browser_version: '13.0', }, BrowserStack_Edge: { base: 'BrowserStack', os: 'Windows', os_version: '10', browser: 'edge', - browser_version: '14.0', + browser_version: '83.0', }, }, }; From 14bf56311050449f818969b80d8444d446ba9acb Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 1 Oct 2020 13:53:03 +0200 Subject: [PATCH 08/21] Fix stable bundle targets --- .browserslistrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 02b1d38ee1d3d6..385ad1286e0efa 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -7,7 +7,7 @@ node 14 # Default/Fallback # snapshot of "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11" when the last major is released. -[production] +[stable] and_chr 84 and_ff 79 and_qq 10.4 @@ -25,7 +25,7 @@ opera 69 safari 13 samsung 11.1 -# Same as `production` but with IE 11 +# Same as `stable` but with IE 11 [legacy] IE 11 and_chr 84 From 1e7339d610213ecc2f0c21ae69a1f005489d7478 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 1 Oct 2020 14:11:34 +0200 Subject: [PATCH 09/21] Fix failing initMatchers test --- test/utils/initMatchers.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/utils/initMatchers.test.js b/test/utils/initMatchers.test.js index 74cf9fd398674d..b9879951c224cc 100644 --- a/test/utils/initMatchers.test.js +++ b/test/utils/initMatchers.test.js @@ -44,12 +44,12 @@ describe('custom matchers', () => { 'Could not match the following console.error calls. ' + "Make sure previous actions didn't call console.error by wrapping them in expect(() => {}).not.toErrorDev(): \n\n" + ' - "expected message"\n' + - ' at Context.', + ' at Context.', // `Context.it` in node 10.x, `Context.` in later node version ); // check that the top stackframe points to this test // if this test is moved to another file the next assertion fails expect(caughtError.stack).to.match( - /- "expected message"\s+at Context\. \(.+\/initMatchers\.test\.js:\d+:\d+\)/, + /- "expected message"\s+at Context\.(|it) \(.+\/initMatchers\.test\.js:\d+:\d+\)/, ); }); From a242debdbe52587d67d726e8f655c18b75aafee7 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 1 Oct 2020 15:48:26 +0200 Subject: [PATCH 10/21] Fix grid related issues in safari --- .../src/ImageList/ImageList.test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/material-ui/src/ImageList/ImageList.test.js b/packages/material-ui/src/ImageList/ImageList.test.js index fc52e4c72e533e..1e48c189bd2398 100644 --- a/packages/material-ui/src/ImageList/ImageList.test.js +++ b/packages/material-ui/src/ImageList/ImageList.test.js @@ -189,18 +189,25 @@ describe('', () => { }); describe('prop: gap', () => { - it('should render with modified grid-template-columns style', () => { + it('should render with modified grid-template-columns style', function test() { + if (/jsdom/.test(window.navigator.userAgent)) { + this.skip(); + } + const { getByTestId } = render( {children} , ); - expect(getByTestId('test-root').style.gap).to.equal('8px'); + expect(window.getComputedStyle(getByTestId('test-root'))).to.include({ + rowGap: '8px', + columnGap: '8px', + }); }); it('should render with modified column-gap style', function test() { - if (!/jsdom/.test(window.navigator.userAgent)) { + if (/jsdom/.test(window.navigator.userAgent)) { this.skip(); } @@ -210,7 +217,10 @@ describe('', () => { , ); - expect(getByTestId('test-root').style['column-gap']).to.equal('8px'); + expect(window.getComputedStyle(getByTestId('test-root'))).to.have.property( + 'columnGap', + '8px', + ); }); }); }); From b5921974fa4966fdce19a07d5ebd514df8cd2add Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 2 Oct 2020 17:01:00 +0200 Subject: [PATCH 11/21] Proper snapshot with mobileToDesktop --- .browserslistrc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 385ad1286e0efa..a21dabe076ca6d 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -6,13 +6,13 @@ last 1 safari version node 14 # Default/Fallback -# snapshot of "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11" when the last major is released. +# `npx browserslist --mobile-to-desktop "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11"` when the last major is released. [stable] and_chr 84 and_ff 79 and_qq 10.4 and_uc 12.12 -android 81 +android 84 baidu 7.12 chrome 83 edge 83 @@ -20,7 +20,7 @@ firefox 68 ios_saf 12.0 kaios 2.5 op_mini all -op_mob 46 +op_mob 69 opera 69 safari 13 samsung 11.1 @@ -32,7 +32,7 @@ and_chr 84 and_ff 79 and_qq 10.4 and_uc 12.12 -android 81 +android 84 baidu 7.12 chrome 83 edge 83 @@ -40,7 +40,7 @@ firefox 68 ios_saf 12.0 kaios 2.5 op_mini all -op_mob 46 +op_mob 69 opera 69 safari 13 samsung 11.1 From c544f2989d95e2a08b5acc8d71ed647eeea8e73d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 2 Oct 2020 18:59:56 +0200 Subject: [PATCH 12/21] Reduce noise from chunks --- scripts/sizeSnapshot/webpack.config.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/sizeSnapshot/webpack.config.js b/scripts/sizeSnapshot/webpack.config.js index 28e88a0e403594..6e9966aebdc5b0 100644 --- a/scripts/sizeSnapshot/webpack.config.js +++ b/scripts/sizeSnapshot/webpack.config.js @@ -123,6 +123,13 @@ module.exports = async function webpackConfig() { // ideally this would be computed from the bundles peer dependencies externals: /^(react|react-dom|react\/jsx-runtime)$/, mode: 'production', + optimization: { + // Otherwise bundles with that include chunks for which we track the size separately are penalized + // e.g. without this option `@material-ui/core.legacy` would be smaller since it could concatenate all modules + // while `@material-ui/core` had to import the chunks from all the components. + // Ideally we could just disable shared chunks but I couldn't figure out how. + concatenateModules: false, + }, output: { filename: '[name].js', path: path.join(__dirname, 'build'), From 426ad90a6d3b7d9bca566a2f4ceef6a8568aaa06 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 2 Oct 2020 19:14:10 +0200 Subject: [PATCH 13/21] Update caniuse --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 187985a6c63532..67708856686abc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4745,9 +4745,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111, caniuse-lite@^1.0.30001113: - version "1.0.30001124" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001124.tgz#5d9998190258e11630d674fc50ea8e579ae0ced2" - integrity sha512-zQW8V3CdND7GHRH6rxm6s59Ww4g/qGWTheoboW9nfeMg7sUoopIfKCcNZUjwYRCOrvereh3kwDpZj4VLQ7zGtA== + version "1.0.30001142" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001142.tgz" + integrity sha512-pDPpn9ankEpBFZXyCv2I4lh1v/ju+bqb78QfKf+w9XgDAFWBwSYPswXqprRdrgQWK0wQnpIbfwRjNHO1HWqvoQ== case@1.6.3: version "1.6.3" From a5193c94fdbae43e96da2e865d3f21e85a784292 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 2 Oct 2020 19:21:18 +0200 Subject: [PATCH 14/21] Use new bundle in UMD build --- babel.config.js | 2 +- packages/material-ui/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/babel.config.js b/babel.config.js index 3c28f0fd0f72da..38363c5ec1554e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -28,7 +28,7 @@ const productionPlugins = [ ]; module.exports = function getBabelConfig(api) { - const useESModules = api.env(['legacy', 'modern', 'stable', 'production-umd']); + const useESModules = api.env(['legacy', 'modern', 'stable']); const presets = [ [ diff --git a/packages/material-ui/package.json b/packages/material-ui/package.json index 22701201d3d46e..485b50a89c265b 100644 --- a/packages/material-ui/package.json +++ b/packages/material-ui/package.json @@ -30,7 +30,7 @@ "build:modern": "node ../../scripts/build modern", "build:node": "node ../../scripts/build node", "build:stable": "node ../../scripts/build stable", - "build:umd": "cross-env BABEL_ENV=production-umd rollup -c scripts/rollup.config.js", + "build:umd": "cross-env BABEL_ENV=stable rollup -c scripts/rollup.config.js", "build:copy-files": "node ../../scripts/copy-files.js", "build:types": "tsc -p tsconfig.build.json", "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true yarn build:modern", From 2ae909abc2272732d587d46c453095b1b6fbcbae Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 5 Oct 2020 11:48:04 +0200 Subject: [PATCH 15/21] Improved docs :) --- .../supported-platforms.md | 11 ++++--- .../minimizing-bundle-size.md | 32 ++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md index 7150dc1728b3e1..7febb39b9ceba8 100644 --- a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md +++ b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md @@ -5,12 +5,13 @@ ## Browser Material-UI supports the latest, stable releases of all major browsers and platforms. -It also supports Internet Explorer 11. You don't need to provide any JavaScript polyfill as it manages unsupported browser features internally and in isolation. -| IE | Edge | Firefox | Chrome | Safari | Googlebot | -| :-- | :---- | :------ | :----- | :----- | :-------- | -| 11 | >= 14 | >= 52 | >= 49 | >= 10 | ✅ | +| Edge | Firefox | Chrome | Safari | +| :---- | :------ | :----- | :----- | +| >= 83 | >= 68 | >= 83 | >= 13 | + +If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size#legacy-bundle). Because Googlebot uses a web rendering service (WRS) to index the page content, it's critical that Material-UI supports it. [WRS regularly updates the rendering engine it uses](https://webmasters.googleblog.com/2019/05/the-new-evergreen-googlebot.html). @@ -19,7 +20,7 @@ You can expect Material-UI's components to render without major issues. ## Server Because Material-UI supports server-side rendering, it needs to support the latest, stable releases of [Node.js](https://github.com/nodejs/node). -Where possible, the [LTS versions that are in maintenance](https://github.com/nodejs/Release#lts-schedule1) are supported. We recommend using **node v10.x** or newer. However we still support **node v8.x**. The support of **node v8.x** will be stopped in Material-UI Version 5. +Where possible, the [LTS versions that are in maintenance](https://github.com/nodejs/Release#lts-schedule1) are supported. ### CSS prefixing diff --git a/docs/src/pages/guides/minimizing-bundle-size/minimizing-bundle-size.md b/docs/src/pages/guides/minimizing-bundle-size/minimizing-bundle-size.md index 7f95e93d137074..1cfa72214bd085 100644 --- a/docs/src/pages/guides/minimizing-bundle-size/minimizing-bundle-size.md +++ b/docs/src/pages/guides/minimizing-bundle-size/minimizing-bundle-size.md @@ -117,8 +117,6 @@ Pick one of the following plugins: 'babel-plugin-import', { libraryName: '@material-ui/core', - // Use "'libraryDirectory': ''," if your bundler does not support ES modules - libraryDirectory: 'esm', camel2DashComponentName: false, }, 'core', @@ -127,8 +125,6 @@ Pick one of the following plugins: 'babel-plugin-import', { libraryName: '@material-ui/icons', - // Use "'libraryDirectory': ''," if your bundler does not support ES modules - libraryDirectory: 'esm', camel2DashComponentName: false, }, 'icons', @@ -150,13 +146,11 @@ Pick one of the following plugins: 'babel-plugin-transform-imports', { '@material-ui/core': { - // Use "transform: '@material-ui/core/${member}'," if your bundler does not support ES modules - transform: '@material-ui/core/esm/${member}', + transform: '@material-ui/core/${member}', preventFullImport: true, }, '@material-ui/icons': { - // Use "transform: '@material-ui/icons/${member}'," if your bundler does not support ES modules - transform: '@material-ui/icons/esm/${member}', + transform: '@material-ui/icons/${member}', preventFullImport: true, }, }, @@ -226,18 +220,20 @@ It will perform the following diffs: +import { Button, TextField } from '@material-ui/core'; ``` -## ECMAScript +## Available bundles The package published on npm is **transpiled**, with [Babel](https://github.com/babel/babel), to take into account the [supported platforms](/getting-started/supported-platforms/). -A second version of the components is also published, which -you can find under the [`/es` folder](https://unpkg.com/@material-ui/core/es/). -All the non-official syntax is transpiled to the [ECMA-262 standard](https://www.ecma-international.org/publications/standards/Ecma-262.htm), nothing more. +⚠️ In order to minimize duplication of code in users' bundles, library authors are **strongly discouraged** to import from any of the other bundles. + +### Modern bundle + +The modern bundle can be found under the [`/modern` folder](https://unpkg.com/@material-ui/core/modern/). +It targets the latest released versions of evergreen browsers (Chrome, Firefox, Safari, Edge). This can be used to make separate bundles targeting different browsers. -Older browsers will require more JavaScript features to be transpiled, -which increases the size of the bundle. -No polyfills are included for ES2015 runtime features. IE11+ and evergreen browsers support all the -necessary features. If you need support for other browsers, consider using -[`@babel/polyfill`](https://www.npmjs.com/package/@babel/polyfill). -⚠️ In order to minimize duplication of code in users' bundles, library authors are **strongly discouraged** from using the `/es` folder. +### Legacy bundle + +If you need to support IE 11 you cannot use the default or modern bundle without transpilation. +However, you can use the legacy bundle found under the [`/legacy` folder](https://unpkg.com/@material-ui/core/legacy/). +You don't need any additional polyfills. From 4a1eef20373ee611547682beacf2c2b96cef9ec4 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 5 Oct 2020 11:53:54 +0200 Subject: [PATCH 16/21] Remove unused polyfills --- package.json | 1 - test/karma.tests.js | 3 --- test/utils/createClientRender.js | 37 ++++---------------------------- yarn.lock | 5 ----- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 4bca621606ad01..4e6f5fba0ea213 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,6 @@ "eslint-plugin-react-hooks": "^4.0.7", "expect-puppeteer": "^4.3.0", "format-util": "^1.0.5", - "formdata-polyfill": "^3.0.20", "fs-extra": "^9.0.0", "glob": "^7.1.2", "glob-gitignore": "^1.0.11", diff --git a/test/karma.tests.js b/test/karma.tests.js index da44018040f65b..554e82aa9ea4cb 100644 --- a/test/karma.tests.js +++ b/test/karma.tests.js @@ -1,6 +1,3 @@ -// https://github.com/airbnb/enzyme/issues/1792 -import 'core-js/modules/es6.array.from'; -import 'formdata-polyfill'; import './utils/init'; const integrationContext = require.context( diff --git a/test/utils/createClientRender.js b/test/utils/createClientRender.js index db68328d7b7a4e..26964c1b42e75e 100644 --- a/test/utils/createClientRender.js +++ b/test/utils/createClientRender.js @@ -5,7 +5,6 @@ import { act, buildQueries, cleanup, - createEvent, fireEvent as rtlFireEvent, queries, render as testingLibraryRender, @@ -157,10 +156,9 @@ export function createClientRender(globalOptions = {}) { }; } +const originalFireEventKeyDown = rtlFireEvent.keyDown; +const originalFireEventKeyUp = rtlFireEvent.keyUp; const fireEvent = Object.assign(rtlFireEvent, { - // polyfill event.key(Code) for chrome 49 and edge 15 (supported in Material-UI v4) - // for user-interactions react does the polyfilling but manually created - // events don't have this luxury keyDown(element, options = {}) { // `element` shouldn't be `document` but we catch this later anyway const document = element.ownerDocument || element; @@ -182,21 +180,7 @@ const fireEvent = Object.assign(rtlFireEvent, { throw error; } - const event = createEvent.keyDown(element, options); - Object.defineProperty(event, 'key', { - get() { - return options.key || ''; - }, - }); - if (options.keyCode !== undefined && event.keyCode === 0) { - Object.defineProperty(event, 'keyCode', { - get() { - return options.keyCode; - }, - }); - } - - rtlFireEvent(element, event); + originalFireEventKeyDown(element, options); }, keyUp(element, options = {}) { // `element` shouldn't be `document` but we catch this later anyway @@ -218,21 +202,8 @@ const fireEvent = Object.assign(rtlFireEvent, { .join('\n'); throw error; } - const event = createEvent.keyUp(element, options); - Object.defineProperty(event, 'key', { - get() { - return options.key || ''; - }, - }); - if (options.keyCode !== undefined && event.keyCode === 0) { - Object.defineProperty(event, 'keyCode', { - get() { - return options.keyCode; - }, - }); - } - rtlFireEvent(element, event); + originalFireEventKeyUp(element, options); }, }); diff --git a/yarn.lock b/yarn.lock index 67708856686abc..6ee91796d86bfb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7831,11 +7831,6 @@ format-util@^1.0.5: resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271" integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg== -formdata-polyfill@^3.0.20: - version "3.0.20" - resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-3.0.20.tgz#d6319db8efc5cf4bb2da27856c2b902be63be1c6" - integrity sha512-TAaxIEwTBdoH1TWndtUH1T0/GisUHwmOKcV5hjkR/iTatHBJSOHb563FP86Lra5nXo3iNdhK7HPwMl5Ihg71pg== - forwarded@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" From 1722f299daec72a492d97ae5c993a088d50aab2e Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 5 Oct 2020 13:50:43 +0200 Subject: [PATCH 17/21] Fix event targets --- .../SwipeableDrawer/SwipeableDrawer.test.js | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.test.js b/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.test.js index c8074d21b67cc8..13221c1e5687b1 100644 --- a/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.test.js +++ b/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.test.js @@ -233,15 +233,15 @@ describe('', () => { fireEvent.touchStart(swipeArea, { touches: [new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[0] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.openTouches[1] })], + fireEvent.touchMove(swipeArea, { + touches: [new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[1] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.openTouches[2] })], + fireEvent.touchMove(swipeArea, { + touches: [new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[2] })], }); - fireEvent.touchEnd(document, { + fireEvent.touchEnd(swipeArea, { changedTouches: [ - new Touch({ identifier: 0, target: document, ...params.openTouches[2] }), + new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[2] }), ], }); expect(handleOpen.callCount).to.equal(1); @@ -254,16 +254,14 @@ describe('', () => { fireEvent.touchStart(h1, { touches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[0] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.closeTouches[1] })], + fireEvent.touchMove(h1, { + touches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[1] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.closeTouches[2] })], + fireEvent.touchMove(h1, { + touches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[2] })], }); - fireEvent.touchEnd(document, { - changedTouches: [ - new Touch({ identifier: 0, target: document, ...params.closeTouches[2] }), - ], + fireEvent.touchEnd(h1, { + changedTouches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[2] })], }); expect(handleClose.callCount).to.equal(1); }); @@ -278,12 +276,12 @@ describe('', () => { fireEvent.touchStart(swipeArea, { touches: [new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[0] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.openTouches[1] })], + fireEvent.touchMove(swipeArea, { + touches: [new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[1] })], }); - fireEvent.touchEnd(document, { + fireEvent.touchEnd(swipeArea, { changedTouches: [ - new Touch({ identifier: 0, target: document, ...params.openTouches[1] }), + new Touch({ identifier: 0, target: swipeArea, ...params.openTouches[1] }), ], }); expect(handleOpen.callCount).to.equal(0); @@ -299,13 +297,11 @@ describe('', () => { fireEvent.touchStart(h1, { touches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[0] })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, ...params.closeTouches[1] })], + fireEvent.touchMove(h1, { + touches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[1] })], }); - fireEvent.touchEnd(document, { - changedTouches: [ - new Touch({ identifier: 0, target: document, ...params.closeTouches[1] }), - ], + fireEvent.touchEnd(h1, { + changedTouches: [new Touch({ identifier: 0, target: h1, ...params.closeTouches[1] })], }); expect(handleClose.callCount).to.equal(0); }); @@ -323,8 +319,8 @@ describe('', () => { const h1 = document.querySelector('h1'); expect(h1).to.not.equal(null); - fireEvent.touchEnd(document, { - changedTouches: [new Touch({ identifier: 0, target: document, ...params.edgeTouch })], + fireEvent.touchEnd(swipeArea, { + changedTouches: [new Touch({ identifier: 0, target: swipeArea, ...params.edgeTouch })], }); expect(handleOpen.callCount).to.equal(0); @@ -346,8 +342,10 @@ describe('', () => { fireEvent.touchStart(swipeArea, { touches: [new Touch({ identifier: 0, target: swipeArea, ...params.ignoreTouch })], }); - fireEvent.touchEnd(document, { - changedTouches: [new Touch({ identifier: 0, target: document, ...params.ignoreTouch })], + fireEvent.touchEnd(swipeArea, { + changedTouches: [ + new Touch({ identifier: 0, target: swipeArea, ...params.ignoreTouch }), + ], }); expect(handleOpen.callCount).to.equal(0); expect(handleClose.callCount).to.equal(0); @@ -366,15 +364,15 @@ describe('', () => { fireEvent.touchStart(h1, { touches: [new Touch({ identifier: 0, target: h1, pageX: 250, clientY: 0 })], }); - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, pageX: 180, clientY: 0 })], + fireEvent.touchMove(h1, { + touches: [new Touch({ identifier: 0, target: h1, pageX: 180, clientY: 0 })], }); container.setProps({ open: false, onClose: handleClose, }); - fireEvent.touchEnd(document, { - changedTouches: [new Touch({ identifier: 0, target: document, pageX: 10, clientY: 0 })], + fireEvent.touchEnd(h1, { + changedTouches: [new Touch({ identifier: 0, target: h1, pageX: 10, clientY: 0 })], }); expect(handleClose.callCount).to.equal(0); }); @@ -386,8 +384,8 @@ describe('', () => { }); container.unmount(); // trigger setState warning if listeners aren't cleaned. - fireEvent.touchMove(document, { - touches: [new Touch({ identifier: 0, target: document, pageX: 180, clientY: 0 })], + fireEvent.touchMove(swipeArea, { + touches: [new Touch({ identifier: 0, target: swipeArea, pageX: 180, clientY: 0 })], }); // trigger setState warning if swipe handling is not cleaned, too fireEvent.touchStart(swipeArea, { From 27172beceb848b1e3e9246e2372caf0c028562bb Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 6 Oct 2020 09:46:17 +0200 Subject: [PATCH 18/21] Add note about node 10 (later 12) --- .browserslistrc | 12 +++++++++--- .../supported-platforms/supported-platforms.md | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index a21dabe076ca6d..7be61d34643cbd 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -7,6 +7,7 @@ node 14 # Default/Fallback # `npx browserslist --mobile-to-desktop "> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11"` when the last major is released. +# #stable-snapshot [stable] and_chr 84 and_ff 79 @@ -45,17 +46,22 @@ opera 69 safari 13 samsung 11.1 -[coverage] +# snapshot of `npx browserslist "maintained node versions"` +[node] node 10.0 -[development] +# same as `node` +[coverage] node 10.0 -[node] +# same as `node` +[development] node 10.0 +# same as `node` [test] node 10.0 +# same as `node` [benchmark] node 10.0 diff --git a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md index 7febb39b9ceba8..f5f3f632f117e5 100644 --- a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md +++ b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md @@ -7,6 +7,8 @@ Material-UI supports the latest, stable releases of all major browsers and platforms. You don't need to provide any JavaScript polyfill as it manages unsupported browser features internally and in isolation. + + | Edge | Firefox | Chrome | Safari | | :---- | :------ | :----- | :----- | | >= 83 | >= 68 | >= 83 | >= 13 | @@ -19,7 +21,9 @@ You can expect Material-UI's components to render without major issues. ## Server -Because Material-UI supports server-side rendering, it needs to support the latest, stable releases of [Node.js](https://github.com/nodejs/node). + + +We support [Node.js](https://github.com/nodejs/node) starting with version 10 for server-side rendering. Where possible, the [LTS versions that are in maintenance](https://github.com/nodejs/Release#lts-schedule1) are supported. ### CSS prefixing From 11cb3e561d110da5b68ab0a55a4d01ce844e7cd2 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 6 Oct 2020 09:47:27 +0200 Subject: [PATCH 19/21] Add changelog entry --- .../pages/guides/migration-v4/migration-v4.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/src/pages/guides/migration-v4/migration-v4.md b/docs/src/pages/guides/migration-v4/migration-v4.md index 09346a618a54eb..97403e62d56d25 100644 --- a/docs/src/pages/guides/migration-v4/migration-v4.md +++ b/docs/src/pages/guides/migration-v4/migration-v4.md @@ -45,6 +45,25 @@ yarn add @material-ui/core@next ## Handling breaking changes +### Supported browsers and node versions + +The targets of the default bundle have changed. +The exact versions will be pinned on release from the browserslist query `"> 0.5%, last 2 versions, Firefox ESR, not dead, not IE 11, maintained node versions"`. + +The default bundle now supports: + + + +- Node 10 (up from 8) +- Chrome 83 (up from 49) +- Edge 83 (up from 14) +- Firefox 68 (up from 52) +- Safari 13 (up from 10) +- and more (see [.browserslistrc (`stable` entry)](https://github.com/mui-org/material-ui/blob/HEAD/.browserslistrc#L11)) + +It no longer supports IE 11. +If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size#legacy-bundle). + ### non-ref-forwarding class components Support for non-ref-forwarding class components in the `component` prop or as an immediate `children` has been dropped. If you were using `unstable_createStrictModeTheme` or didn't see any warnings related to `findDOMNode` in `React.StrictMode` then you don't need to do anything. From 840e29ef174fc46e6943e2c39b9808e85c42246a Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 6 Oct 2020 11:36:43 +0200 Subject: [PATCH 20/21] Track modern bundle --- package.json | 6 ++- scripts/sizeSnapshot/webpack.config.js | 18 +++++---- yarn.lock | 54 +++++++++++++++----------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 6ab2111340c2e5..800978c1710cf0 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,7 @@ "rollup-plugin-terser": "^7.0.0", "sinon": "^9.0.0", "size-limit": "^0.21.0", + "terser-webpack-plugin": "^4.2.2", "tslint": "5.14.0", "typescript": "^4.0.2", "unist-util-visit": "^2.0.2", @@ -154,7 +155,7 @@ "resolutions": { "**/@babel/core": "^7.10.2", "**/@babel/code-frame": "^7.10.4", - "**/@babel/parser": "7.10.5", + "**/@babel/parser": "^7.10.5", "**/@babel/plugin-proposal-class-properties": "^7.10.1", "**/@babel/plugin-proposal-object-rest-spread": "^7.10.1", "**/@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.1", @@ -170,7 +171,8 @@ "**/cross-fetch": "^3.0.5", "**/dot-prop": "^5.2.0", "**/hoist-non-react-statics": "^3.3.2", - "**/webpack": "^4.44.1" + "**/webpack": "^4.44.1", + "**/webpack/acorn": "^7.4.0" }, "nyc": { "include": [ diff --git a/scripts/sizeSnapshot/webpack.config.js b/scripts/sizeSnapshot/webpack.config.js index 6e9966aebdc5b0..be1bcfeb72faee 100644 --- a/scripts/sizeSnapshot/webpack.config.js +++ b/scripts/sizeSnapshot/webpack.config.js @@ -1,6 +1,7 @@ const globCallback = require('glob'); const path = require('path'); const CompressionPlugin = require('compression-webpack-plugin'); +const TerserPlugin = require('terser-webpack-plugin'); const { promisify } = require('util'); const glob = promisify(globCallback); @@ -96,13 +97,11 @@ async function getSizeLimitBundles() { webpack: true, path: 'packages/material-ui-utils/build/index.js', }, - // TODO: Needs webpack 5 - // https://github.com/webpack/webpack/issues/10227 - // { - // name: '@material-ui/core.modern', - // webpack: true, - // path: path.join(path.relative(workspaceRoot, corePackagePath), 'modern/index.js'), - // }, + { + name: '@material-ui/core.modern', + webpack: true, + path: path.join(path.relative(workspaceRoot, corePackagePath), 'modern/index.js'), + }, { name: '@material-ui/core.legacy', webpack: true, @@ -129,6 +128,11 @@ module.exports = async function webpackConfig() { // while `@material-ui/core` had to import the chunks from all the components. // Ideally we could just disable shared chunks but I couldn't figure out how. concatenateModules: false, + minimizer: [ + new TerserPlugin({ + test: /\.js(\?.*)?$/i, + }), + ], }, output: { filename: '[name].js', diff --git a/yarn.lock b/yarn.lock index 92e9359385c74e..a841d4f70a8a6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -354,10 +354,10 @@ resolve "^1.13.1" v8flags "^3.1.1" -"@babel/parser@7.10.5", "@babel/parser@^7.1.0", "@babel/parser@^7.1.6", "@babel/parser@^7.10.4", "@babel/parser@^7.11.5", "@babel/parser@^7.7.5": - version "7.10.5" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.10.5.tgz#e7c6bf5a7deff957cec9f04b551e2762909d826b" - integrity sha512-wfryxy4bE1UivvQKSQDU4/X6dr+i8bctjUjj8Zyt3DQy7NtPizJXT8M52nqpNKL+nq2PW8lxk4ZqLj0fD4B4hQ== +"@babel/parser@^7.1.0", "@babel/parser@^7.1.6", "@babel/parser@^7.10.4", "@babel/parser@^7.10.5", "@babel/parser@^7.11.5", "@babel/parser@^7.7.5": + version "7.11.5" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.11.5.tgz#c7ff6303df71080ec7a4f5b8c003c58f1cf51037" + integrity sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q== "@babel/plugin-proposal-async-generator-functions@^7.10.4": version "7.10.5" @@ -3309,12 +3309,7 @@ acorn@^5.7.3: resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== -acorn@^6.4.1: - version "6.4.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.1.tgz#531e58ba3f51b9dacb9a6646ca4debf5b14ca474" - integrity sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== - -acorn@^7.1.1, acorn@^7.2.0, acorn@^7.4.0: +acorn@^6.4.1, acorn@^7.1.1, acorn@^7.2.0, acorn@^7.4.0: version "7.4.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.0.tgz#e1ad486e6c54501634c6c397c5c121daa383607c" integrity sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w== @@ -9574,10 +9569,10 @@ jest-worker@24.9.0: merge-stream "^2.0.0" supports-color "^6.1.0" -jest-worker@^26.2.1: - version "26.3.0" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.3.0.tgz#7c8a97e4f4364b4f05ed8bca8ca0c24de091871f" - integrity sha512-Vmpn2F6IASefL+DVBhPzI2J9/GJUsqzomdeN+P+dK8/jKxbh8R3BtFnx3FIta7wYlPU62cpJMJQo4kuOowcMnw== +jest-worker@^26.2.1, jest-worker@^26.3.0: + version "26.5.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.5.0.tgz#87deee86dbbc5f98d9919e0dadf2c40e3152fa30" + integrity sha512-kTw66Dn4ZX7WpjZ7T/SUDgRhapFRKWmisVAF0Rv4Fu8SLFD7eLbqpLvbxVqYhSgaWa7I+bW7pHnbyfNsH6stug== dependencies: "@types/node" "*" merge-stream "^2.0.0" @@ -14897,7 +14892,7 @@ source-map-resolve@^0.5.0, source-map-resolve@^0.5.2: source-map-url "^0.4.0" urix "^0.1.0" -source-map-support@^0.5.16, source-map-support@~0.5.12: +source-map-support@^0.5.16, source-map-support@~0.5.12, source-map-support@~0.5.19: version "0.5.19" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61" integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== @@ -14915,7 +14910,7 @@ source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@0.7.3, source-map@^0.7.3: +source-map@0.7.3, source-map@^0.7.3, source-map@~0.7.2: version "0.7.3" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== @@ -15656,6 +15651,21 @@ terser-webpack-plugin@^1.4.3: webpack-sources "^1.4.0" worker-farm "^1.7.0" +terser-webpack-plugin@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-4.2.2.tgz#d86200c700053bba637913fe4310ba1bdeb5568e" + integrity sha512-3qAQpykRTD5DReLu5/cwpsg7EZFzP3Q0Hp2XUWJUw2mpq2jfgOKTZr8IZKKnNieRVVo1UauROTdhbQJZveGKtQ== + dependencies: + cacache "^15.0.5" + find-cache-dir "^3.3.1" + jest-worker "^26.3.0" + p-limit "^3.0.2" + schema-utils "^2.7.1" + serialize-javascript "^5.0.1" + source-map "^0.6.1" + terser "^5.3.2" + webpack-sources "^1.4.3" + terser@4.8.0, terser@^4.1.2, terser@^4.7.0: version "4.8.0" resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17" @@ -15665,14 +15675,14 @@ terser@4.8.0, terser@^4.1.2, terser@^4.7.0: source-map "~0.6.1" source-map-support "~0.5.12" -terser@^5.0.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.2.0.tgz#e547d0b20926b321d3e524bf9e5bc1b10ba2f360" - integrity sha512-nZ9TWhBznZdlww3borgJyfQDrxzpgd0RlRNoxR63tMVry01lIH/zKQDTTiaWRMGowydfvSHMgyiGyn6A9PSkCQ== +terser@^5.0.0, terser@^5.3.2: + version "5.3.4" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.3.4.tgz#e510e05f86e0bd87f01835c3238839193f77a60c" + integrity sha512-dxuB8KQo8Gt6OVOeLg/rxfcxdNZI/V1G6ze1czFUzPeCFWZRtvZMgSzlZZ5OYBZ4HoG607F6pFPNLekJyV+yVw== dependencies: commander "^2.20.0" - source-map "~0.6.1" - source-map-support "~0.5.12" + source-map "~0.7.2" + source-map-support "~0.5.19" test-exclude@^6.0.0: version "6.0.0" From 950bc1fe07613a1f6e88327a913f50bc9e89689d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 6 Oct 2020 13:17:54 +0200 Subject: [PATCH 21/21] Apply suggestions from code review Co-authored-by: Olivier Tassinari --- .../getting-started/supported-platforms/supported-platforms.md | 2 +- docs/src/pages/guides/migration-v4/migration-v4.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md index f5f3f632f117e5..62dd695a3b5c67 100644 --- a/docs/src/pages/getting-started/supported-platforms/supported-platforms.md +++ b/docs/src/pages/getting-started/supported-platforms/supported-platforms.md @@ -13,7 +13,7 @@ You don't need to provide any JavaScript polyfill as it manages unsupported brow | :---- | :------ | :----- | :----- | | >= 83 | >= 68 | >= 83 | >= 13 | -If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size#legacy-bundle). +If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size/#legacy-bundle). Because Googlebot uses a web rendering service (WRS) to index the page content, it's critical that Material-UI supports it. [WRS regularly updates the rendering engine it uses](https://webmasters.googleblog.com/2019/05/the-new-evergreen-googlebot.html). diff --git a/docs/src/pages/guides/migration-v4/migration-v4.md b/docs/src/pages/guides/migration-v4/migration-v4.md index a3256a5792d48c..2f55c1048b32a0 100644 --- a/docs/src/pages/guides/migration-v4/migration-v4.md +++ b/docs/src/pages/guides/migration-v4/migration-v4.md @@ -62,7 +62,7 @@ The default bundle now supports: - and more (see [.browserslistrc (`stable` entry)](https://github.com/mui-org/material-ui/blob/HEAD/.browserslistrc#L11)) It no longer supports IE 11. -If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size#legacy-bundle). +If you need to support IE 11, check out our [legacy bundle](/guides/minimizing-bundle-size/#legacy-bundle). ### non-ref-forwarding class components