Skip to content

fix: filter should not stabilize args.specifier - #3972

Merged
IWANABETHATGUY merged 2 commits into
mainfrom
03-27-fix_filter_should_not_stabilize_args.specifier
Mar 27, 2025
Merged

IWANABETHATGUY merged 2 commits into
mainfrom
03-27-fix_filter_should_not_stabilize_args.specifier

Conversation

@IWANABETHATGUY

@IWANABETHATGUY IWANABETHATGUY commented Mar 27, 2025 •

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@netlify

netlify Bot commented Mar 27, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit c889b3f
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/67e500e5607f410008221968
😎 Deploy Preview https://deploy-preview-3972--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions

github-actions Bot commented Mar 27, 2025 •

Copy link
Copy Markdown
Contributor

Benchmarks Rust

  • target: main(acbb339)
  • pr: 03-27-fix_filter_should_not_stabilize_args.specifier(c889b3f)
group                                                               pr                                     target
-----                                                               --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol                     1.03     77.9±6.69ms        ? ?/sec    1.00     75.3±2.08ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify              1.00     96.4±2.23ms        ? ?/sec    1.01     97.1±4.15ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-minify-sourcemap    1.00    109.0±2.13ms        ? ?/sec    1.00    108.5±1.54ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap           1.00     83.2±1.72ms        ? ?/sec    1.02     85.2±2.18ms        ? ?/sec
bundle/bundle@rome-ts                                               1.00    122.8±1.45ms        ? ?/sec    1.00    122.9±2.63ms        ? ?/sec
bundle/bundle@rome-ts-minify                                        1.01    204.8±6.15ms        ? ?/sec    1.00    202.7±5.15ms        ? ?/sec
bundle/bundle@rome-ts-minify-sourcemap                              1.04   252.0±10.27ms        ? ?/sec    1.00    243.4±4.49ms        ? ?/sec
bundle/bundle@rome-ts-sourcemap                                     1.01    135.7±1.60ms        ? ?/sec    1.00    134.1±1.40ms        ? ?/sec
bundle/bundle@threejs                                               1.04     43.5±3.31ms        ? ?/sec    1.00     41.9±1.43ms        ? ?/sec
bundle/bundle@threejs-minify                                        1.01     88.2±2.53ms        ? ?/sec    1.00     87.3±1.14ms        ? ?/sec
bundle/bundle@threejs-minify-sourcemap                              1.00    103.1±2.23ms        ? ?/sec    1.00    103.1±2.79ms        ? ?/sec
bundle/bundle@threejs-sourcemap                                     1.01     48.7±0.81ms        ? ?/sec    1.00     48.2±0.51ms        ? ?/sec
bundle/bundle@threejs10x                                            1.00    433.4±8.07ms        ? ?/sec    1.00    433.3±8.59ms        ? ?/sec
bundle/bundle@threejs10x-minify                                     1.00   1071.3±9.20ms        ? ?/sec    1.00   1070.7±5.46ms        ? ?/sec
bundle/bundle@threejs10x-minify-sourcemap                           1.01   1253.0±9.03ms        ? ?/sec    1.00   1245.7±6.80ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                                  1.00    501.3±5.29ms        ? ?/sec    1.00    500.5±4.90ms        ? ?/sec
remapping/remapping                                                 1.00     26.7±0.38ms        ? ?/sec    1.02     27.3±0.50ms        ? ?/sec
remapping/render-chunk-remapping                                    1.01     71.6±5.85ms        ? ?/sec    1.00     70.6±5.15ms        ? ?/sec
scan/scan@rome-ts                                                   1.00     96.2±1.35ms        ? ?/sec    1.00     96.7±1.67ms        ? ?/sec
scan/scan@threejs                                                   1.01     32.6±0.77ms        ? ?/sec    1.00     32.4±0.36ms        ? ?/sec
scan/scan@threejs10x                                                1.00    318.6±3.89ms        ? ?/sec    1.00    319.8±4.17ms        ? ?/sec

@IWANABETHATGUY
IWANABETHATGUY force-pushed the 03-27-fix_filter_should_not_stabilize_args.specifier branch from 2c20a45 to d555693 Compare March 27, 2025 05:38
@IWANABETHATGUY
IWANABETHATGUY force-pushed the 03-27-fix_filter_should_not_stabilize_args.specifier branch from d555693 to 53f5dc8 Compare March 27, 2025 05:45
@IWANABETHATGUY
IWANABETHATGUY force-pushed the 03-27-fix_filter_should_not_stabilize_args.specifier branch from 53f5dc8 to 365ad09 Compare March 27, 2025 05:52
@IWANABETHATGUY
IWANABETHATGUY marked this pull request as ready for review March 27, 2025 05:53
@IWANABETHATGUY
IWANABETHATGUY requested a review from hi-ogawa March 27, 2025 05:53

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Porting get_matcher_string would break a following pattern, so I'm not sure if aligning with createFilter is necessary.

{
  name: 'repro',
  resolveId: {
    filter: {
      id: 'virtual:foo'
    },
    handler(...args) {
      console.log("[resolveId]", args)
      return '\0virtual:foo'
    }
  },
  load: {
    filter: {
      id: '\0virtual:foo'
    },
    handler(...args) {
      console.log("[load]", args)
      return `console.log("ok")`;
    }
  },
}

I didn't know createFilter is aware of cwd and, from what I've seen, I think people normally don't rely on that and explicitly uses ** for string pattern instead, so breaking that away from createFilter might be fine in practice. Any thoughts? @sapphi-red

@IWANABETHATGUY

Copy link
Copy Markdown
Member Author

b

Maybe we should also handle any string prefix with virtual: specially?

@IWANABETHATGUY

Copy link
Copy Markdown
Member Author

In this case we recommended user to use regexp instead

@IWANABETHATGUY
IWANABETHATGUY force-pushed the 03-27-fix_filter_should_not_stabilize_args.specifier branch from 365ad09 to c2ecda4 Compare March 27, 2025 06:40
@IWANABETHATGUY

Copy link
Copy Markdown
Member Author

Porting get_matcher_string would break a following pattern, so I'm not sure if aligning with createFilter is necessary.

{
  name: 'repro',
  resolveId: {
    filter: {
      id: 'virtual:foo'
    },
    handler(...args) {
      console.log("[resolveId]", args)
      return '\0virtual:foo'
    }
  },
  load: {
    filter: {
      id: '\0virtual:foo'
    },
    handler(...args) {
      console.log("[load]", args)
      return `console.log("ok")`;
    }
  },
}

I didn't know createFilter is aware of cwd and, from what I've seen, I think people normally don't rely on that and explicitly uses ** for string pattern instead, so breaking that away from createFilter might be fine in practice. Any thoughts? @sapphi-red

Another reason I prefer to align with rollup is user may have less mental burden when migrating from rollup to rolldown

@hi-ogawa

hi-ogawa commented Mar 27, 2025 •

Copy link
Copy Markdown
Collaborator

Maybe we should also handle any string prefix with virtual: specially?

Virtual module naming is not restricted to virtual:, just like Vite internally uses vite/modulepreload-polyfill.

Another reason I prefer to align with rollup is user may have less mental burden when migrating from rollup to rolldown

I understand both ways. I'm also wondering which is less mental burden for users, either 1. exactly same as createFilter but not being able to use intuitive-looking { filter: { id: "virtual:xxx" } } (and need to use exact regex like vitejs/rolldown-vite#89 or less accurate **/virtual:xxx ) or, 2. not exactly same as createFilter but allows filter: { id: "virtual:xxx" }.

@sapphi-red

Copy link
Copy Markdown
Member

@sapphi-red

Copy link
Copy Markdown
Member

I wonder if which is more common, matching a virtual module or filtering under process.cwd. Maybe matching a virtual module is more common? Vite has a concept of root which is different from process.cwd and probably won't work well together with it.

@sapphi-red

Copy link
Copy Markdown
Member

Probably depends on how the filter is used. If the value is passed from the user, aligning with createFilter is useful I guess: https://github.com/search?q=path%3Arollup.config.js+%2Finclude%3A%2F&type=code&p=1

@sapphi-red

sapphi-red commented Mar 27, 2025 •

Copy link
Copy Markdown
Member

My personal conclusion is: I prefer this PR, maybe good to add a @rolldown/pluginutils package (or add to @rollup/pluginutils) that exposes the following functions:

export const extactRegExp = str => new RegExp(`^${RegExp.escape(str)}$`)
export const prefixRegExp = str => new RegExp(`^${RegExp.escape(str)}`)
export const suffixRegExp = str => new RegExp(`${RegExp.escape(str)}$`)

@graphite-app

graphite-app Bot commented Mar 27, 2025

Copy link
Copy Markdown
Contributor

Merge activity

  • Mar 27, 3:29 AM EDT: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm good with this too as intended behavior is clear now 👍

@IWANABETHATGUY
IWANABETHATGUY added this pull request to the merge queue Mar 27, 2025
Merged via the queue into main with commit 85c4bdd Mar 27, 2025
@IWANABETHATGUY
IWANABETHATGUY deleted the 03-27-fix_filter_should_not_stabilize_args.specifier branch March 27, 2025 08:25
IWANABETHATGUY added a commit that referenced this pull request Oct 26, 2026
A relative glob like `filter: { id: 'src/**' }` matches nothing when
`cwd` contains glob characters or is relative. The default `cwd` is
`process.cwd()`, so running Rolldown from such a folder is enough.

```diff
 cwd:  /w/my[app]
 glob: src/**
-/w/my[app]/src/**     # [app] is a character class, so /w/my[app]/src/main.js doesn't match
+/w/my\[app\]/src/**   # cwd is escaped first
```

`get_matcher_string` now does what Rollup's `getMatcherString` does.
#3972 ported it without these two steps:

```diff
 get_matcher_string(glob, cwd)
   if glob starts with ** or is absolute
     return glob
+  if cwd is relative, make it absolute
+  escape \ * ? [ ] { } ! in cwd
   join glob onto cwd, resolving . and ..
```

Every relative glob filter goes through it:

```text
get_matcher_string
├── hook filters (id, importerId)
├── watch.include / watch.exclude
└── include/exclude of the native Vite plugins (transform, dynamic-import-vars)
```

Repro:
https://github.com/onmax/repros/tree/repro/rolldown-cwd-glob/rolldown-cwd-glob

An empty `cwd` still keeps the glob relative, because `test_filter`
relies on it. I haven't tested on Windows, so a `ci: windows` run would
help.

---------

Co-authored-by: IWANABETHATGUY <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: hook filter (both rolldown and vite) not working same as createFilter util

3 participants