Skip to content

Commit 32acdc0

Browse files
authored
Turbopack: absolute requests in webpack loader (#84575)
Recent sass-loader versions use this heavily: `this.getResolver()(..., "/Users/foo/..../bar.scss")`
1 parent adb2829 commit 32acdc0

File tree

14 files changed

+111
-10
lines changed

14 files changed

+111
-10
lines changed

test/e2e/app-dir/webpack-loader-binary/webpack-loader-binary.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { nextTestSetup } from 'e2e-utils'
22

33
describe('webpack-loader-ts-transform', () => {
4-
const { next } = nextTestSetup({
4+
const { next, skipped } = nextTestSetup({
55
files: __dirname,
66
skipDeployment: true,
77
})
88

9+
if (skipped) return
10+
911
it('should allow passing binary assets to and from a Webpack loader', async () => {
1012
const $ = await next.render$('/')
1113
expect($('#text').text()).toBe('Got a buffer of 18 bytes')

test/e2e/app-dir/webpack-loader-conditions/webpack-loader-conditions.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { nextTestSetup } from 'e2e-utils'
44
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
55
'webpack-loader-conditions',
66
() => {
7-
const { next } = nextTestSetup({
7+
const { next, skipped } = nextTestSetup({
88
files: __dirname,
99
skipDeployment: true,
1010
})
1111

12+
if (skipped) return
13+
1214
it('should render correctly on server site', async () => {
1315
const res = await next.fetch('/')
1416
const html = (await res.text()).replaceAll(/<!-- -->/g, '')

test/e2e/app-dir/webpack-loader-fs/webpack-loader-fs.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { nextTestSetup } from 'e2e-utils'
22

33
describe('webpack-loader-fs', () => {
4-
const { next } = nextTestSetup({
4+
const { next, skipped } = nextTestSetup({
55
files: __dirname,
66
skipDeployment: true,
77
})
88

9+
if (skipped) return
10+
911
it('should allow reading the input FS', async () => {
1012
const $ = await next.render$('/')
1113
expect($('#test').text()).toBe(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'wrong'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Root({ children }: { children: React.ReactNode }) {
2+
return (
3+
<html>
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import absolute from './file.test-file?absolute=data1'
2+
import relative from './file.test-file?relative=data2'
3+
4+
export default function Page() {
5+
return (
6+
<div>
7+
<p id="absolute">{absolute}</p>
8+
<p id="relative">{relative}</p>
9+
</div>
10+
)
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'abc'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'xyz'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {
5+
turbopack: {
6+
rules: {
7+
'*.test-file.ts': [require.resolve('./test-file-loader.js')],
8+
},
9+
},
10+
webpack(config) {
11+
config.module.rules.push({
12+
test: /\.test-file\.ts/,
13+
use: require.resolve('./test-file-loader.js'),
14+
})
15+
return config
16+
},
17+
}
18+
19+
module.exports = nextConfig
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
module.exports = async function () {
5+
let params = new URLSearchParams(this.resourceQuery.slice(1))
6+
let file
7+
if (params.has('absolute')) {
8+
file = path.join(__dirname, params.get('absolute'))
9+
} else if (params.has('relative')) {
10+
file = './' + params.get('relative')
11+
} else {
12+
this.callback(null, "throw new Error('no file specified')")
13+
return
14+
}
15+
16+
const resolve = this.getResolve({})
17+
const result = await resolve(__dirname, file)
18+
this.addDependency(result)
19+
20+
return fs.readFileSync(result, 'utf8')
21+
}

0 commit comments

Comments
 (0)