Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Correctly search for loaded modules in node 12 #2612

Merged
merged 3 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/@aws-cdk/cdk/lib/node-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import process = require('process');

// process.versions.node is like "12.3.1"
const [strMajor, strMinor, strPatch, ] = process.versions.node.split('.');

/**
* The major version of the node runtime.
*/
export const major = Number(strMajor);

/**
* The minor version of the node runtime.
*/
export const minor = Number(strMinor);

/**
* The revision of the node runtime.
*/
export const patch = Number(strPatch);
7 changes: 6 additions & 1 deletion packages/@aws-cdk/cdk/lib/runtime-info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cxapi = require('@aws-cdk/cx-api');
import { major as nodeMajorVersion } from './node-version';

/**
* Returns a list of loaded modules and their versions.
Expand Down Expand Up @@ -55,7 +56,11 @@ function findNpmPackage(fileName: string): { name: string, version: string, priv
const paths = mod.paths.map(stripNodeModules);

try {
const packagePath = require.resolve('package.json', { paths });
const packagePath = require.resolve(
// Resolution behavior changed in node 12.0.0 - https://github.com/nodejs/node/issues/27583
nodeMajorVersion >= 12 ? './package.json' : 'package.json',
{ paths }
);
return require(packagePath);
} catch (e) {
return undefined;
Expand Down
73 changes: 40 additions & 33 deletions packages/@aws-cdk/cdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/lodash": "^4.14.123",
"@types/lodash": "^4.14.130",
"cdk-build-tools": "^0.31.0",
"cfn2ts": "^0.31.0",
"fast-check": "^1.14.0",
Expand Down