Skip to content

Commit

Permalink
feat: add support for Node.js >= 12.20.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
char0n committed Jan 25, 2023
1 parent 47b3f0a commit a79b7f6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 35 additions & 0 deletions scripts/overrides.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit a79b7f6

Please sign in to comment.