{{ message }}
fix: unescape webpack/rspack paths in load and transform#592
Open
fix: unescape webpack/rspack paths in load and transform#592
Conversation
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
test/fixtures/hash-path/unplugin.js (1)
40-43: Optionally add explicit token-not-found guards for clearer test failures.Right now
overwrite(...)relies on implicit failure behavior when tokens are missing. A direct guard would make fixture failures more diagnosable.♻️ Suggested small robustness tweak
const s = new MagicString(code) const index = code.indexOf('msg#hash') + if (index === -1) + throw new Error(`load expected token "msg#hash" in ${JSON.stringify(id)}`) s.overwrite(index, index + 'msg#hash'.length, 'msg -> through the load hook -> __unplugin__#hash') return s.toString() @@ const s = new MagicString(code) const index = code.indexOf('__unplugin__') + if (index === -1) + throw new Error(`transform expected token "__unplugin__" in ${JSON.stringify(id)}`) s.overwrite(index, index + '__unplugin__'.length, 'transform') return {Also applies to: 57-60
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/fixtures/hash-path/unplugin.js` around lines 40 - 43, The test fixture silently assumes the token exists before calling s.overwrite; add explicit guards that check the result of code.indexOf('msg#hash') (and similarly the other occurrence around lines 57-60) and throw a clear error if indexOf returns -1 so failures show a descriptive message; locate the token search using code.indexOf('msg#hash') and the mutation via s.overwrite(...) (and the paired s.toString() return) and validate the index before calling s.overwrite to produce a meaningful test-failure message when the token is missing.test/fixtures/hash-path/__test__/build.test.ts (1)
10-38: Optional: collapse repeated bundler assertions into a table-driven loop.Current tests are solid; this is just a maintainability cleanup to reduce duplication and ease future fixture additions.
♻️ Proposed refactor
describe('hash-path hooks', () => { - it('vite', async () => { - const content = await fs.readFile(r('vite/main.js.mjs'), 'utf-8') - expect(content).toContain(expected) - }) - - it('rollup', async () => { - const content = await fs.readFile(r('rollup/main.js'), 'utf-8') - expect(content).toContain(expected) - }) - - it('webpack', async () => { - const content = await fs.readFile(r('webpack/main.js'), 'utf-8') - expect(content).toContain(expected) - }) - - it('esbuild', async () => { - const content = await fs.readFile(r('esbuild/main.js'), 'utf-8') - expect(content).toContain(expected) - }) - - it('rspack', async () => { - const content = await fs.readFile(r('rspack/main.js'), 'utf-8') - expect(content).toContain(expected) - }) - - it('farm', async () => { - const content = await fs.readFile(r('farm/main.js'), 'utf-8') - expect(content).toContain(expected) - }) + const cases: Array<[string, string]> = [ + ['vite', 'vite/main.js.mjs'], + ['rollup', 'rollup/main.js'], + ['webpack', 'webpack/main.js'], + ['esbuild', 'esbuild/main.js'], + ['rspack', 'rspack/main.js'], + ['farm', 'farm/main.js'], + ] + + for (const [name, file] of cases) { + it(name, async () => { + const content = await fs.readFile(r(file), 'utf-8') + expect(content).toContain(expected) + }) + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/fixtures/hash-path/__test__/build.test.ts` around lines 10 - 38, Tests repeat the same assertion for multiple bundlers; refactor by replacing the repeated it(...) blocks with a table-driven loop: create an array of bundler names (e.g., ['vite','rollup','webpack','esbuild','rspack','farm']), iterate over it and for each name call it(bundleName, async () => { const content = await fs.readFile(r(`${bundleName}/main.js${bundleName === 'vite' ? '.mjs' : ''}`), 'utf-8'); expect(content).toContain(expected); }); use the existing r helper, fs.readFile, and expected variable so behavior is unchanged but duplication is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/fixtures/hash-path/__test__/build.test.ts`:
- Around line 10-38: Tests repeat the same assertion for multiple bundlers;
refactor by replacing the repeated it(...) blocks with a table-driven loop:
create an array of bundler names (e.g.,
['vite','rollup','webpack','esbuild','rspack','farm']), iterate over it and for
each name call it(bundleName, async () => { const content = await
fs.readFile(r(`${bundleName}/main.js${bundleName === 'vite' ? '.mjs' : ''}`),
'utf-8'); expect(content).toContain(expected); }); use the existing r helper,
fs.readFile, and expected variable so behavior is unchanged but duplication is
removed.
In `@test/fixtures/hash-path/unplugin.js`:
- Around line 40-43: The test fixture silently assumes the token exists before
calling s.overwrite; add explicit guards that check the result of
code.indexOf('msg#hash') (and similarly the other occurrence around lines 57-60)
and throw a clear error if indexOf returns -1 so failures show a descriptive
message; locate the token search using code.indexOf('msg#hash') and the mutation
via s.overwrite(...) (and the paired s.toString() return) and validate the index
before calling s.overwrite to produce a meaningful test-failure message when the
token is missing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4df8609d-b47d-49b1-b362-eb9c98c3ae02
📒 Files selected for processing (17)
src/rspack/loaders/load.tssrc/rspack/loaders/transform.tssrc/utils/webpack-like.tssrc/webpack/loaders/load.tssrc/webpack/loaders/transform.tstest/fixtures/hash-path/__test__/build.test.tstest/fixtures/hash-path/bun.config.jstest/fixtures/hash-path/esbuild.config.jstest/fixtures/hash-path/farm.config.jstest/fixtures/hash-path/rollup.config.jstest/fixtures/hash-path/rspack.config.jstest/fixtures/hash-path/src/main.jstest/fixtures/hash-path/src/msg#hash.jstest/fixtures/hash-path/unplugin.jstest/fixtures/hash-path/vite.config.jstest/fixtures/hash-path/webpack.config.jstest/fixtures/load/unplugin.js
Member
|
Tests are failing, would you also check them? Thanks |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Resolves #591 by unescaping paths before passing into load and transform.
I'm open to better / less redundant ways to test. I wanted to test that all hooks unescape (or never escape), on all platforms.
Summary by CodeRabbit
Bug Fixes
Tests