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

Emit warning if require will not comply with specification #3681

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Apr 8, 2024

What?

Add warning on require invocations that do not follow the specification.

Depends on #3680

Why?

As this isn't how it works we would like to fix it.

Also happens to be hard to keep it working once we move to ESM.

part of #3534

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

@mstoykov mstoykov added this to the v0.51.0 milestone Apr 8, 2024
@mstoykov mstoykov requested a review from a team as a code owner April 8, 2024 15:19
@mstoykov mstoykov requested review from oleiade and codebien and removed request for a team April 8, 2024 15:19
@mstoykov mstoykov added the breaking change for PRs that need to be mentioned in the breaking changes section of the release notes label Apr 8, 2024
@mstoykov mstoykov self-assigned this Apr 8, 2024
js/modules/require_impl.go Outdated Show resolved Hide resolved
@codebien
Copy link
Contributor

codebien commented Apr 10, 2024

@mstoykov do you intend to open the pull request dropping the support directly now? It would be useful to be sure we are not going to forget to act on this.

@mstoykov
Copy link
Contributor Author

Finally managed to finish it in #3694

codebien
codebien previously approved these changes Apr 19, 2024
oleiade
oleiade previously approved these changes Apr 19, 2024
var parent string
var buf [2]goja.StackFrame
frames := rt.CaptureCallStack(2, buf[:0])
parent = frames[1].SrcName()
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 always safe? Is there any change to get frames with only one or no items at all?🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In all of the experiments I have ran in the last 4 months or so (this particular code is very old) I have had 1 panic when I called it when there was nothing running on the runtime.

As I would argue that is very much the wrong way to use it ... I am particularly certain it makes sense to capture this it seems.

Base automatically changed from lockModules to master April 22, 2024 07:11
@mstoykov mstoykov dismissed stale reviews from oleiade and codebien April 22, 2024 07:11

The base branch was changed.

@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2024

Codecov Report

Attention: Patch coverage is 57.89474% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 73.28%. Comparing base (edd2d15) to head (85d4b1e).

❗ Current head 85d4b1e differs from pull request most recent head 79d8dab. Consider uploading reports for the commit 79d8dab to get more accurate results

Files Patch % Lines
js/modules/require_impl.go 56.86% 16 Missing and 6 partials ⚠️
js/modules/resolution.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3681      +/-   ##
==========================================
+ Coverage   73.26%   73.28%   +0.02%     
==========================================
  Files         276      278       +2     
  Lines       20333    20386      +53     
==========================================
+ Hits        14897    14940      +43     
- Misses       4486     4496      +10     
  Partials      950      950              
Flag Coverage Δ
macos 73.19% <57.89%> (?)
ubuntu 73.22% <57.89%> (-0.05%) ⬇️
windows 73.12% <57.89%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

Generally, it looks good to me.

One thing that could be improved is to migrate from the terms "correct" and "wrong" words.

Maybe instead, the wrong use of CommonJS specification is non-compliant? I know that's longer, but I'm trying to think from the user perspective how they understand what's the issue faster. WDYT?

@mstoykov mstoykov merged commit 0e48fa2 into master Apr 22, 2024
22 checks passed
@mstoykov mstoykov deleted the requireWarning branch April 22, 2024 12:28
@mstoykov
Copy link
Contributor Author

@olegbespalov I used to call it "compliant" earlier .. but then I had to explain to what it is "compliant" and it becomes longer and longer.

Arguably the linked issue is the much better place to find why this is happening and what needs to be done.

Also as I explain in the issue - you are really unlikely to hit this issue at all. If you just use ESM syntax - babel transpile it correctly. If not ... you literally need to be doing dynamic import require which AFAIK nobody is doing.

So I expect this will have practically 0 comments. But we will see 🤞

@mstoykov mstoykov mentioned this pull request Jun 27, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change for PRs that need to be mentioned in the breaking changes section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants