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

module: use kNodeModulesRE to detect node_modules #55243

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

joyeecheung
Copy link
Member

This is faster and more consistent with other places using the regular expression to detect node_modules.

This is faster and more consistent with other places using the
regular expression to detect node_modules.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 2, 2024
@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Oct 2, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 2, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.39%. Comparing base (d24c731) to head (676184d).
Report is 365 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55243      +/-   ##
==========================================
- Coverage   88.39%   88.39%   -0.01%     
==========================================
  Files         652      652              
  Lines      186568   186563       -5     
  Branches    36047    36043       -4     
==========================================
- Hits       164924   164916       -8     
+ Misses      14915    14912       -3     
- Partials     6729     6735       +6     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 97.42% <100.00%> (ø)
lib/internal/modules/esm/load.js 92.24% <100.00%> (ø)
lib/internal/modules/helpers.js 99.01% <ø> (-0.02%) ⬇️
lib/internal/util.js 96.87% <100.00%> (+0.01%) ⬆️

... and 25 files with indirect coverage changes

---- 🚨 Try these New Features:

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

Can you share some benchmarks?

@anonrig anonrig added the needs-benchmark-ci PR that need a benchmark CI run. label Oct 3, 2024
@joyeecheung
Copy link
Member Author

Personally I am not a fan of adding microbenchmarks of internals into the benchmark suite, so I'll just share some local benchmark results:

const path = require('path');
const fs = require('fs');

const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/;

function isUnderNodeModules(filename) {
  return filename && kNodeModulesRE.exec(filename) !== null;
}

function isUnderNodeModulesByPath(filename) {
  const resolvedPath = path.resolve(filename);
  const normalizedPath = path.normalize(resolvedPath);
  const splitPath = normalizedPath.split(path.sep);
  return splitPath.includes('node_modules');
}

const check = process.env.TYPE === 'PATH' ? isUnderNodeModulesByPath : isUnderNodeModules;
const files = fs.globSync('**/*.js');
const results = [];

console.time(files.length);
for (let i = 0; i < files.length; ++i) {
  results.push(check(files[i]));
}
console.timeEnd(results.length);
❯ NODE_NO_WARNINGS=1 TYPE=REGEXP out/Release/node bench.js
23559: 4.73ms
❯ NODE_NO_WARNINGS=1 TYPE=PATH out/Release/node bench.js
23559: 34.513ms

@joyeecheung joyeecheung removed the needs-benchmark-ci PR that need a benchmark CI run. label Oct 3, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@marco-ippolito marco-ippolito left a comment

Choose a reason for hiding this comment

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

LGTM I remember I created that function as a workaround, thanks for handling it properly

@joyeecheung joyeecheung added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 4, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 4, 2024
@nodejs-github-bot nodejs-github-bot merged commit bdd590b into nodejs:main Oct 4, 2024
80 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in bdd590b

@joyeecheung joyeecheung mentioned this pull request Oct 7, 2024
8 tasks
joyeecheung added a commit to joyeecheung/node that referenced this pull request Oct 7, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
joyeecheung added a commit to joyeecheung/node that referenced this pull request Oct 8, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
joyeecheung added a commit to joyeecheung/node that referenced this pull request Oct 9, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
@aduh95 aduh95 added the backport-open-v20.x Indicate that the PR has an open backport label Oct 9, 2024
aduh95 pushed a commit to joyeecheung/node that referenced this pull request Oct 11, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Backport-PR-URL: nodejs#55217
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Refs: nodejs#52697
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
joyeecheung added a commit to joyeecheung/node that referenced this pull request Nov 7, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Backport-PR-URL: nodejs#55217
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Refs: nodejs#52697
joyeecheung added a commit to joyeecheung/node that referenced this pull request Nov 12, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Backport-PR-URL: nodejs#55217
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Refs: nodejs#52697
joyeecheung added a commit to joyeecheung/node that referenced this pull request Nov 12, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Backport-PR-URL: nodejs#55217
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Refs: nodejs#52697
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
joyeecheung added a commit to joyeecheung/node that referenced this pull request Nov 23, 2024
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
Backport-PR-URL: nodejs#55217
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Refs: nodejs#52697
@ruyadorno ruyadorno added the backport-open-v22.x Indicate that the PR has an open backport label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-open-v20.x Indicate that the PR has an open backport backport-open-v22.x Indicate that the PR has an open backport esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants