Skip to content

Commit

Permalink
Preserve overrides from root package
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lpsinger committed Feb 22, 2022
1 parent 22c17b9 commit 1e41c26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/actions/autoinstall/get-root-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let { existsSync, readFileSync } = require('fs')
let { join } = require('path')

// Get params from root project that should be preserved in hydrated package.json
module.exports = function getRootParams ({ inv }) {
let root = inv._project.cwd
let packageJson = join(root, 'package.json')

let package = existsSync(packageJson) && JSON.parse(readFileSync(packageJson)) || {}

let result = {}
if (package.overrides)
result.overrides = package.overrides

return result
}
4 changes: 3 additions & 1 deletion src/actions/autoinstall/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let { existsSync, renameSync, writeFileSync } = require('fs')
let { join } = require('path')
let getRootDeps = require('./get-root-deps')
let getRootParams = require('./get-root-params')
let getSharedDeps = require('./get-shared-deps')
let getLambdaDeps = require('./get-lambda-deps')

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

0 comments on commit 1e41c26

Please sign in to comment.