From a79b7f6c88850bbbd78b37bb6b4820789cb5bee3 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Wed, 25 Jan 2023 09:47:40 +0100 Subject: [PATCH] feat: add support for Node.js >= 12.20.0 As older npm versions doesn't support new package.json override field, we're simulating it for older npm versions before the npm package publish phase. --- package.json | 2 +- scripts/overrides.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 scripts/overrides.js diff --git a/package.json b/package.json index aef49a39c..2631d7697 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "deps_check_dir": ".deps_check" }, "scripts": { - "prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build", + "prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build && node ./scripts/overrides.js", "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", diff --git a/scripts/overrides.js b/scripts/overrides.js new file mode 100644 index 000000000..56d0c8da0 --- /dev/null +++ b/scripts/overrides.js @@ -0,0 +1,35 @@ +/** + * This script simulates `overrides` package.json field + * in older npm versions that doesn't support it. + * + * Older versions of npm match the package overrides by name and version, + * instead of just name (this is how new `override` package.json field works). + */ +/* eslint-disable import/no-dynamic-require */ + +const fs = require('fs'); +const path = require('path'); + +const rootPckg = require(path.join(__dirname, '..', 'package.json')); +const apidomReferencePckgPath = path.join( + __dirname, + '..', + 'node_modules', + '@swagger-api', + 'apidom-reference', + 'package.json' +); +const apidomReferencePckg = require(apidomReferencePckgPath); + +const { + overrides: { '@swagger-api/apidom-reference': overrides }, +} = rootPckg; +const overridesList = Object.keys(overrides).filter((key) => key.startsWith('@swagger-api/')); + +overridesList.forEach((override) => { + if (Object.hasOwn(apidomReferencePckg.dependencies, override)) { + apidomReferencePckg.dependencies[override] = '=0.0.1'; + } +}); + +fs.writeFileSync(apidomReferencePckgPath, JSON.stringify(apidomReferencePckg, null, 2));