Skip to content

Commit e2ad114

Browse files
committed
Preserve overrides from root package
NPM 8.3.0 introduced the `overrides` key in package.json, which allows you to customize the dependencies of any (or all) of your project's dependencies. hydrate should respect the root project's overrides.
1 parent 22c17b9 commit e2ad114

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let { existsSync, readFileSync } = require('fs')
2+
let { join } = require('path')
3+
4+
// Get params from root project that should be preserved in hydrated package.json
5+
module.exports = function getRootParams ({ inv }) {
6+
let root = inv._project.cwd
7+
let packageJson = join(root, 'package.json')
8+
9+
let package = existsSync(packageJson) && JSON.parse(readFileSync(packageJson)) || {}
10+
11+
let result = {}
12+
if (package.overrides)
13+
result.overrides = package.overrides
14+
15+
return result
16+
}

src/actions/autoinstall/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let { existsSync, renameSync, writeFileSync } = require('fs')
22
let { join } = require('path')
33
let getRootDeps = require('./get-root-deps')
4+
let getRootParams = require('./get-root-params')
45
let getSharedDeps = require('./get-shared-deps')
56
let getLambdaDeps = require('./get-lambda-deps')
67

@@ -73,7 +74,8 @@ module.exports = function autoinstaller (params) {
7374
dir,
7475
file: 'package.json',
7576
remove: [ 'package.json', 'package-lock.json' ], // Identify files for later removal
76-
data: JSON.stringify(lambdaPackage, null, 2)
77+
data: JSON.stringify(lambdaPackage, null, 2),
78+
...getRootParams()
7779
}
7880
// Autoinstall can be called on a directory that contains a package.json with `"type": "module"` (and no dependencies)
7981
// If we find such a case, kindly move the existing package.json aside until autoinstall ops are complete

0 commit comments

Comments
 (0)