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: handle node: prefix #285

Merged
merged 3 commits into from
May 18, 2022
Merged

fix: handle node: prefix #285

merged 3 commits into from
May 18, 2022

Conversation

Rich-Harris
Copy link
Contributor

This appears to be enough to fix #284, but I'm not sure where a test would go

@Rich-Harris Rich-Harris requested review from ijjk and styfle as code owners May 17, 2022 15:55
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a unit fixture that uses node: imports/requires here https://github.com/vercel/nft/tree/main/test/unit would be good to ensure fs/path usage via node:fs and node:path catches the files it's reading correctly

@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #285 (085e4ae) into main (4a3725f) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 085e4ae differs from pull request most recent head 6391685. Consider uploading reports for the commit 6391685 to get more accurate results

@@            Coverage Diff             @@
##             main     #285      +/-   ##
==========================================
+ Coverage   80.43%   80.44%   +0.01%     
==========================================
  Files          13       13              
  Lines        1482     1483       +1     
  Branches      552      555       +3     
==========================================
+ Hits         1192     1193       +1     
  Misses        120      120              
  Partials      170      170              
Impacted Files Coverage Δ
src/analyze.ts 86.58% <100.00%> (ø)
src/resolve-dependency.ts 70.00% <100.00%> (+0.18%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@Rich-Harris
Copy link
Contributor Author

Looks like that didn't fix it after all 😬

@styfle styfle changed the title handle node: prefix fix: handle node: prefix May 17, 2022
@guybedford
Copy link
Contributor

@Rich-Harris let me know if I can assist with any NFT stuff anytime - it seems like the unit test just needs to be updated? The logging isn't ideal, may make sense to log the error before the warning to ensure the error can be seen at that call site in https://github.com/vercel/nft/blob/main/test/unit.test.js#L175.

@Rich-Harris
Copy link
Contributor Author

@guybedford if you are able to get this working, that would be terrific — unfortunately I'm maxed out at the moment otherwise I'd spend more time digging into it. Right now I'm just working around it:

	traced.warnings.forEach((error) => {
		// pending https://github.com/vercel/nft/issues/284
		if (error.message.startsWith('Failed to resolve dependency node:')) return;
		console.error(error);
	});

@guybedford
Copy link
Contributor

I don't have time to clone and PR right now, especially since I'm on Windows here. But I'd just suggest the following change in analyze.ts:

Line 305 change:

const m = staticModules[specifier.startsWith('node:') ? specifier.slice(5) : specifier];

line 345 change:

const staticModule = staticModules[source.startsWith('node:') ? source.slice(5) : source];

Unverified

This user has not yet uploaded their public signing key.
Co-authored-by: Guy Bedford <guybedford@gmail.com>
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ijjk ijjk added the automerge Automatically merge PR once checks pass label May 18, 2022
@kodiakhq kodiakhq bot merged commit 37830e7 into vercel:main May 18, 2022
@Rich-Harris Rich-Harris deleted the node-prefix branch May 18, 2022 02:20
import fs from 'fs';
import * as path from 'path';
import fs from 'node:fs';
import * as path from 'node:path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test be reverted so we cover both cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can revert this one since we have the separate fixtures now, updated in #287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node: prefixes cause a warning
4 participants