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: improve compatibility with restricted-export modules #3205

Merged
merged 18 commits into from
Dec 7, 2021

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Nov 25, 2021

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().

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') then findUp

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.

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()`.
@rix0rrr rix0rrr requested a review from a team November 25, 2021 15:47
@rix0rrr rix0rrr self-assigned this Nov 25, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 25, 2021
@rix0rrr rix0rrr changed the title fix(jsii-reflect): improve compatibility with restricted-export modules fix: improve compatibility with restricted-export modules Nov 25, 2021
packages/jsii-pacmak/lib/util.ts Show resolved Hide resolved
packages/jsii-pacmak/lib/util.ts Outdated Show resolved Hide resolved
packages/jsii-reflect/lib/type-system.ts Show resolved Hide resolved
/**
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
*/
export async function findDependencyDirectory(
Copy link
Contributor

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...

Copy link
Contributor Author

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

packages/jsii/lib/project-info.ts Show resolved Hide resolved
Co-authored-by: Romain Marcadier <rmuller@amazon.lu>
@RomainMuller RomainMuller added the pr/do-not-merge This PR should not be merged at this time. label Dec 6, 2021
Copy link
Contributor

@RomainMuller RomainMuller left a 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).

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Dec 7, 2021

#3236

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Dec 7, 2021
@rix0rrr rix0rrr merged commit 31a7172 into main Dec 7, 2021
@rix0rrr rix0rrr deleted the huijbers/no-reflect-require branch December 7, 2021 08:57
rix0rrr added a commit that referenced this pull request Dec 9, 2021
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.
rix0rrr added a commit that referenced this pull request Dec 9, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants