-
Notifications
You must be signed in to change notification settings - Fork 245
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: improve compatibility with restricted-export modules #3205
Conversation
Modules can decide they don't export `package.json`, and our methods of using `require.resolve('the-package/package.json')` to find the package will fail. Instead, resolve the main entry point and search upward for `package.json`, bypassing `require()`.
… into huijbers/no-reflect-require
/** | ||
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory | ||
*/ | ||
export async function findDependencyDirectory( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this implementation a copy of the one in jsii-pacmak
? I wouldn't mind a @jsii/utils
package...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeeeeaaa -- hhh... I don't disagree, but I didn't want to make too many changes at once
Co-authored-by: Romain Marcadier <rmuller@amazon.lu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved granted you add notes in the duplicated code that it is... duplicated, and create an issue to refactor in a follow-up PR (I don't expect you'll implement that PR right away, though).
… into huijbers/no-reflect-require
Fixes for some cases that were introduced in #3205, that cropped up during a full CDK build: - Some `@types/xxx` modules use an `exports` field, changing the error we get when trying (and failing) to import it. - `punycode` is both an NPM dependency and a built-in. The built-in takes precedence and changes the return value of `require.resolve()` to something unexpected.
Fixes for some cases that were introduced in #3205, that cropped up during a full CDK build: - Some `@types/xxx` modules use an `exports` field, changing the error we get when trying (and failing) to import it. - `punycode` is both an NPM dependency and a built-in. The built-in takes precedence and changes the return value of `require.resolve()` to something unexpected.
Modules can decide they don't export
package.json
, and our methodsof using
require.resolve('the-package/package.json')
to find thepackage will fail.
Instead, resolve the main entry point and search upward for
package.json
, bypassingrequire()
.We have been doing all of:
require('the-package/package.json')
require.resolve('the-package/.jsii')
require.resolve('the-package/tsconfig.json')
Replace all these with a
require.resolve('the-package')
thenfindUp
Relates to aws/aws-cdk#17707
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.