From e633b0db83fd20412e04e172ed3b5ede4b11740c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Fri, 8 Sep 2023 20:43:05 +0200 Subject: [PATCH] fix(build): transpile source code properly against target envs (#3132) --- .browserslistrc | 19 +++++ babel.config.js | 65 +++++++--------- package-lock.json | 178 +------------------------------------------ package.json | 7 +- scripts/overrides.js | 61 --------------- 5 files changed, 48 insertions(+), 282 deletions(-) delete mode 100644 scripts/overrides.js diff --git a/.browserslistrc b/.browserslistrc index a0f90650f..221dff56a 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,4 +1,23 @@ +[isomorphic-production] > 1% last 2 versions Firefox ESR not dead +node 12.20.0 + +[isomorphic-development] +last 1 Chrome versions +last 1 FireFox versions +last 1 Safari versions +node 20 + +[browser-production] +> 1% +last 2 versions +Firefox ESR +not dead + +[browser-development] +last 1 Chrome versions +last 1 FireFox versions +last 1 Safari versions diff --git a/babel.config.js b/babel.config.js index d66867e85..313da32c4 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,60 +1,44 @@ -/** - * This is override for https://github.com/lodash/babel-plugin-lodash/issues/259. - * babel-plugin-lodash is using deprecated babel API, which causes generation of many - * console.trace calls. - */ - -const consoleTrace = console.trace.bind(console); -console.trace = (message, ...optionalParams) => { - if ( - typeof message === 'string' && - message.startsWith('`isModuleDeclaration` has been deprecated') - ) { - return undefined; // noop - } - - return consoleTrace(message, ...optionalParams); -}; - module.exports = { env: { commonjs: { + browserslistEnv: 'isomorphic-production', presets: [ [ '@babel/preset-env', { debug: false, modules: 'commonjs', - corejs: { version: 3 }, + loose: true, useBuiltIns: false, - targets: { - node: '12.20.0', - }, forceAllTransforms: false, - ignoreBrowserslistConfig: true, + ignoreBrowserslistConfig: false, }, ], ], plugins: [ [ - '@babel/plugin-transform-modules-commonjs', + '@babel/plugin-transform-runtime', { - loose: true, + corejs: { version: 3, proposals: false }, + absoluteRuntime: false, + helpers: true, + regenerator: false, + version: '^7.22.15', }, ], - '@babel/proposal-class-properties', - '@babel/proposal-object-rest-spread', ], }, es: { + browserslistEnv: 'isomorphic-production', presets: [ [ '@babel/preset-env', { debug: false, modules: false, - corejs: { version: 3 }, useBuiltIns: false, + forceAllTransforms: false, + ignoreBrowserslistConfig: false, }, ], ], @@ -62,25 +46,28 @@ module.exports = { [ '@babel/plugin-transform-runtime', { + corejs: { version: 3, proposals: false }, absoluteRuntime: false, - corejs: 3, - version: '^7.11.2', + helpers: true, + regenerator: false, + useESModules: true, + version: '^7.22.15', }, ], - '@babel/proposal-class-properties', - '@babel/proposal-object-rest-spread', - 'lodash', ], }, browser: { + browserslistEnv: 'browser-production', sourceType: 'unambiguous', // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940 presets: [ [ '@babel/preset-env', { debug: false, - corejs: { version: 3 }, + modules: 'auto', useBuiltIns: false, + forceAllTransforms: false, + ignoreBrowserslistConfig: false, }, ], ], @@ -88,13 +75,13 @@ module.exports = { [ '@babel/plugin-transform-runtime', { - corejs: 3, - version: '^7.11.2', + corejs: { version: 3, proposals: false }, + absoluteRuntime: false, + helpers: true, + regenerator: false, + version: '^7.22.15', }, ], - '@babel/proposal-class-properties', - '@babel/proposal-object-rest-spread', - 'lodash', ], }, }, diff --git a/package-lock.json b/package-lock.json index 0fc2c35f1..f38c0a235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.20.1", "license": "Apache-2.0", "dependencies": { - "@babel/runtime-corejs3": "^7.20.13", + "@babel/runtime-corejs3": "^7.22.15", "@swagger-api/apidom-core": ">=0.76.2 <1.0.0", "@swagger-api/apidom-json-pointer": ">=0.76.2 <1.0.0", "@swagger-api/apidom-ns-openapi-3-1": ">=0.76.2 <1.0.0", @@ -30,8 +30,6 @@ "devDependencies": { "@babel/cli": "^7.21.0", "@babel/core": "^7.21.0", - "@babel/plugin-proposal-class-properties": "^7.18.6", - "@babel/plugin-proposal-object-rest-spread": "^7.20.7", "@babel/plugin-transform-runtime": "^7.21.0", "@babel/preset-env": "^7.20.2", "@babel/register": "^7.21.0", @@ -39,7 +37,6 @@ "@commitlint/config-conventional": "^17.0.0", "abort-controller": "^3.0.0", "babel-loader": "=9.1.3", - "babel-plugin-lodash": "=3.3.4", "cross-env": "=7.0.3", "eslint": "^8.42.0", "eslint-config-airbnb-base": "^15.0.0", @@ -623,41 +620,6 @@ "@babel/core": "^7.13.0" } }, - "node_modules/@babel/plugin-proposal-class-properties": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz", - "integrity": "sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==", - "dev": true, - "dependencies": { - "@babel/helper-create-class-features-plugin": "^7.18.6", - "@babel/helper-plugin-utils": "^7.18.6" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-proposal-object-rest-spread": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.7.tgz", - "integrity": "sha512-d2S98yCiLxDVmBmE8UjGcfPvNEUbA1U5q5WxaWFUGRzJSVAZqm5W6MbPct0jxnegUZ0niLeNX+IOzEs7wYg9Dg==", - "dev": true, - "dependencies": { - "@babel/compat-data": "^7.20.5", - "@babel/helper-compilation-targets": "^7.20.7", - "@babel/helper-plugin-utils": "^7.20.2", - "@babel/plugin-syntax-object-rest-spread": "^7.8.3", - "@babel/plugin-transform-parameters": "^7.20.7" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-proposal-private-property-in-object": { "version": "7.21.0-placeholder-for-preset-env.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", @@ -4918,61 +4880,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/babel-plugin-lodash": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz", - "integrity": "sha512-yDZLjK7TCkWl1gpBeBGmuaDIFhZKmkoL+Cu2MUUjv5VxUZx/z7tBGBCBcQs5RI1Bkz5LLmNdjx7paOyQtMovyg==", - "dev": true, - "dependencies": { - "@babel/helper-module-imports": "^7.0.0-beta.49", - "@babel/types": "^7.0.0-beta.49", - "glob": "^7.1.1", - "lodash": "^4.17.10", - "require-package-name": "^2.0.1" - } - }, - "node_modules/babel-plugin-lodash/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/babel-plugin-lodash/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/babel-plugin-lodash/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/babel-plugin-polyfill-corejs2": { "version": "0.4.5", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.5.tgz", @@ -13282,12 +13189,6 @@ "node": ">=0.10.0" } }, - "node_modules/require-package-name": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/require-package-name/-/require-package-name-2.0.1.tgz", - "integrity": "sha512-uuoJ1hU/k6M0779t3VMVIYpb2VMJk05cehCaABFhXaibcbvfgR8wKiozLjVFSzJPmQMRqIcO0HMyTFqfV09V6Q==", - "dev": true - }, "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", @@ -16100,29 +16001,6 @@ "@babel/plugin-transform-optional-chaining": "^7.22.15" } }, - "@babel/plugin-proposal-class-properties": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz", - "integrity": "sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==", - "dev": true, - "requires": { - "@babel/helper-create-class-features-plugin": "^7.18.6", - "@babel/helper-plugin-utils": "^7.18.6" - } - }, - "@babel/plugin-proposal-object-rest-spread": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.7.tgz", - "integrity": "sha512-d2S98yCiLxDVmBmE8UjGcfPvNEUbA1U5q5WxaWFUGRzJSVAZqm5W6MbPct0jxnegUZ0niLeNX+IOzEs7wYg9Dg==", - "dev": true, - "requires": { - "@babel/compat-data": "^7.20.5", - "@babel/helper-compilation-targets": "^7.20.7", - "@babel/helper-plugin-utils": "^7.20.2", - "@babel/plugin-syntax-object-rest-spread": "^7.8.3", - "@babel/plugin-transform-parameters": "^7.20.7" - } - }, "@babel/plugin-proposal-private-property-in-object": { "version": "7.21.0-placeholder-for-preset-env.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", @@ -19354,54 +19232,6 @@ "@types/babel__traverse": "^7.0.6" } }, - "babel-plugin-lodash": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz", - "integrity": "sha512-yDZLjK7TCkWl1gpBeBGmuaDIFhZKmkoL+Cu2MUUjv5VxUZx/z7tBGBCBcQs5RI1Bkz5LLmNdjx7paOyQtMovyg==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.0.0-beta.49", - "@babel/types": "^7.0.0-beta.49", - "glob": "^7.1.1", - "lodash": "^4.17.10", - "require-package-name": "^2.0.1" - }, - "dependencies": { - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - } - } - }, "babel-plugin-polyfill-corejs2": { "version": "0.4.5", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.5.tgz", @@ -25473,12 +25303,6 @@ "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true }, - "require-package-name": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/require-package-name/-/require-package-name-2.0.1.tgz", - "integrity": "sha512-uuoJ1hU/k6M0779t3VMVIYpb2VMJk05cehCaABFhXaibcbvfgR8wKiozLjVFSzJPmQMRqIcO0HMyTFqfV09V6Q==", - "dev": true - }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", diff --git a/package.json b/package.json index f5de3a07d..2a25dde15 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "scripts": { "analyze:umd:browser": "source-map-explorer 'dist/swagger-client.browser.min.js'", - "prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build && node ./scripts/overrides.js", + "prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build", "build": "run-s build:umd:browser build:commonjs build:es", "build:umd:browser": "cross-env BABEL_ENV=browser webpack --progress --config config/webpack/browser.config.babel.js", "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", @@ -71,8 +71,6 @@ "devDependencies": { "@babel/cli": "^7.21.0", "@babel/core": "^7.21.0", - "@babel/plugin-proposal-class-properties": "^7.18.6", - "@babel/plugin-proposal-object-rest-spread": "^7.20.7", "@babel/plugin-transform-runtime": "^7.21.0", "@babel/preset-env": "^7.20.2", "@babel/register": "^7.21.0", @@ -80,7 +78,6 @@ "@commitlint/config-conventional": "^17.0.0", "abort-controller": "^3.0.0", "babel-loader": "=9.1.3", - "babel-plugin-lodash": "=3.3.4", "cross-env": "=7.0.3", "eslint": "^8.42.0", "eslint-config-airbnb-base": "^15.0.0", @@ -113,7 +110,7 @@ "xmock": "=0.3.0" }, "dependencies": { - "@babel/runtime-corejs3": "^7.20.13", + "@babel/runtime-corejs3": "^7.22.15", "@swagger-api/apidom-core": ">=0.76.2 <1.0.0", "@swagger-api/apidom-json-pointer": ">=0.76.2 <1.0.0", "@swagger-api/apidom-ns-openapi-3-1": ">=0.76.2 <1.0.0", diff --git a/scripts/overrides.js b/scripts/overrides.js deleted file mode 100644 index 6f251d392..000000000 --- a/scripts/overrides.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * This script uses package.json `overrides` field and remove all - * unnecessary dependencies of ApiDOM from npm bundling. - * The mechanism is fully idempotent. - * - * Dependencies are removed when using following override notation: - * - * ``` - * "overrides": { - * "dep": { - * ".": "dep-override" - * } - * } - * ``` - * - * Dependencies are overridden when using following override notation: - * - * ``` - * "overrides": { - * "dep": "dep-override" - * } - * ``` - */ -const fs = require('node:fs'); -const path = require('node:path'); - -const rootPckgJSON = require(path.join(__dirname, '..', 'package.json')); // eslint-disable-line import/no-dynamic-require -const { overrides: rootOverrides } = rootPckgJSON; -const swaggerApiOverrides = Object.fromEntries( - Object.entries(rootOverrides).filter(([pckgName]) => pckgName.startsWith('@swagger-api')) -); - -const readPckg = (pckgName) => { - const pckgPath = path.join(__dirname, '..', 'node_modules', pckgName, 'package.json'); - - return JSON.parse(fs.readFileSync(pckgPath, { encoding: 'utf-8' })); -}; - -const writePckg = (pckgName, pckgJSON) => { - const pckgPath = path.join(__dirname, '..', 'node_modules', pckgName, 'package.json'); - - return fs.writeFileSync(pckgPath, JSON.stringify(pckgJSON, null, 2)); -}; - -const removeDeps = (pckgName, overrides) => { - const pckgJSON = readPckg(pckgName); - - Object.entries(overrides).forEach(([dep, override]) => { - if (typeof override === 'object') { - delete pckgJSON?.dependencies[dep]; - } else { - pckgJSON.dependencies[dep] = override; - } - }); - - return writePckg(pckgName, pckgJSON); -}; - -Object.entries(swaggerApiOverrides).forEach(([pckgName]) => { - removeDeps(pckgName, swaggerApiOverrides[pckgName]); -});