From a0c32921a5b84c810ba2177d27e42b3657cf9b82 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Tue, 22 Feb 2022 15:02:01 -0500 Subject: [PATCH] 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. --- src/actions/autoinstall/get-root-params.js | 16 ++++++++++++++++ src/actions/autoinstall/index.js | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/actions/autoinstall/get-root-params.js diff --git a/src/actions/autoinstall/get-root-params.js b/src/actions/autoinstall/get-root-params.js new file mode 100644 index 0000000..53a2b1d --- /dev/null +++ b/src/actions/autoinstall/get-root-params.js @@ -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 +} diff --git a/src/actions/autoinstall/index.js b/src/actions/autoinstall/index.js index 68aa748..9821afe 100644 --- a/src/actions/autoinstall/index.js +++ b/src/actions/autoinstall/index.js @@ -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') @@ -68,12 +69,13 @@ module.exports = function autoinstaller (params) { _parsed: files.sort(), description: `This file was generated by Architect, and placed in node_modules to aid in debugging; if you found file in your function directory, you can safely remove it (and package-lock.json)`, dependencies, + ...getRootParams(inventory) } let 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), } // 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