-
Notifications
You must be signed in to change notification settings - Fork 965
chore(deps): upgrade rspack to v2 #10691
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
Open
GiladShoham
wants to merge
2
commits into
master
Choose a base branch
from
chore/rspack-v2-upgrade
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import os from 'os'; | ||
| import { join } from 'path'; | ||
| import { promisify } from 'util'; | ||
| import fs from 'fs-extra'; | ||
| import { expect } from 'chai'; | ||
| import { rspack } from '@rspack/core'; | ||
| import { cssParser, styleRules, fontRule } from './rspack.common'; | ||
|
|
||
| /** | ||
| * Regression coverage for the node_modules/first-party split in `styleRules()`. Rspack v2's CSS | ||
| * handler treats every `url()` as a module to read, which throws on an absolute (e.g. CDN) | ||
| * `https:` url - vendored stylesheets are exempted from `url` resolution for that reason (see | ||
| * `vendorCssParser` in rspack.common.ts). This build proves the exemption is scoped correctly: | ||
| * a first-party stylesheet's local relative url still goes through the real asset pipeline, and | ||
| * only a vendored (node_modules) stylesheet's absolute url is left untouched. | ||
| */ | ||
| describe('styleRules', () => { | ||
| let tmpDir: string; | ||
| let outDir: string; | ||
|
|
||
| before(() => { | ||
| tmpDir = fs.mkdtempSync(join(os.tmpdir(), 'bit-rspack-style-rules-')); | ||
| outDir = join(tmpDir, 'dist'); | ||
|
|
||
| fs.outputFileSync(join(tmpDir, 'src/first-party.module.scss'), `.icon { background: url('./icon.svg'); }\n`); | ||
| // padded well past rspack's default inline-asset threshold (~8KB), so this emits as a | ||
| // separate file - like a real font/image asset would - instead of an inlined data: URI. | ||
| fs.outputFileSync(join(tmpDir, 'src/icon.svg'), `<svg><!-- ${'x'.repeat(9000)} --></svg>`); | ||
| fs.outputFileSync( | ||
| join(tmpDir, 'src/entry.js'), | ||
| `import './first-party.module.scss';\nimport 'vendor-pkg/vendor.module.scss';\n` | ||
| ); | ||
| fs.outputFileSync( | ||
| join(tmpDir, 'node_modules/vendor-pkg/vendor.module.scss'), | ||
| `.brand { background: url('https://cdn.example.com/font.woff2'); }\n` | ||
| ); | ||
| }); | ||
|
|
||
| after(() => { | ||
| fs.removeSync(tmpDir); | ||
| }); | ||
|
|
||
| it('resolves a first-party relative url() through the asset pipeline while leaving a vendored absolute url() untouched', async () => { | ||
| const compiler = rspack({ | ||
| context: tmpDir, | ||
| entry: join(tmpDir, 'src/entry.js'), | ||
| mode: 'production', | ||
| output: { path: outDir, filename: 'bundle.js' }, | ||
| module: { | ||
| parser: cssParser, | ||
| rules: [...styleRules({ sourceMap: false }), fontRule()], | ||
| }, | ||
| } as any); | ||
|
|
||
| try { | ||
| const run = promisify(compiler.run.bind(compiler)); | ||
| const stats = await run(); | ||
| expect(stats?.hasErrors(), stats?.toString({ errorDetails: true })).to.be.false; | ||
|
|
||
| const assetNames = Object.keys((stats as any).compilation.assets); | ||
| const cssAssetName = assetNames.find((name) => name.endsWith('.css')); | ||
| expect(cssAssetName, `no .css asset emitted, got: ${assetNames.join(', ')}`).to.exist; | ||
| const css = fs.readFileSync(join(outDir, cssAssetName as string), 'utf8'); | ||
|
|
||
| // vendored url() is left as literal text - not resolved, not fetched. | ||
| expect(css).to.include('https://cdn.example.com/font.woff2'); | ||
|
|
||
| // first-party url() went through fontRule's asset pipeline instead of being left literal. | ||
| expect(css).to.not.include("url('./icon.svg')"); | ||
| expect(css).to.not.include('url("./icon.svg")'); | ||
| const emittedIconName = assetNames.find((name) => name.includes('static/fonts') && name.endsWith('.svg')); | ||
| expect(emittedIconName, `no emitted icon asset, got: ${assetNames.join(', ')}`).to.exist; | ||
| expect(fs.existsSync(join(outDir, emittedIconName as string))).to.be.true; | ||
| } finally { | ||
| await new Promise<void>((done) => compiler.close(() => done())); | ||
| } | ||
| }); | ||
| }); | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.