Unverified Commit 56e5acc0 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

webpack: fix swcPlugins with relative paths (#92770)

Webpack didn't correctly load relative paths for `swcPlugins`.

https://github.com/vercel/next.js/pull/92579 will add a test
parent 6413e523
......@@ -142,6 +142,7 @@ export default function nextJest(options: { dir?: string } = {}) {
isEsmProject,
pagesDir,
imageConfig,
configDir: options.dir,
}
return {
......
......@@ -43,6 +43,7 @@ export interface JestTransformerConfig extends TransformerConfig {
jsConfig: any
resolvedBaseUrl?: ResolvedBaseUrl
pagesDir?: string
configDir?: string
serverComponents?: boolean
isEsmProject: boolean
modularizeImports?: NextConfig['modularizeImports']
......@@ -90,6 +91,7 @@ const createTransformer: TransformerCreator<
jestConfig.testEnvironment === 'node' ||
jestConfig.testEnvironment.includes('jest-environment-node'),
filename,
configDir: inputOptions?.configDir,
jsConfig: inputOptions?.jsConfig,
resolvedBaseUrl: inputOptions?.resolvedBaseUrl,
pagesDir: inputOptions?.pagesDir,
......
......@@ -60,6 +60,7 @@ function getBaseSWCOptions({
hasReactRefresh,
globalWindow,
esm,
configDir,
modularizeImports,
swcPlugins,
compilerOptions,
......@@ -83,6 +84,7 @@ function getBaseSWCOptions({
hasReactRefresh: boolean
globalWindow: boolean
esm: boolean
configDir?: string
modularizeImports?: NextConfig['modularizeImports']
compilerOptions: NextConfig['compiler']
swcPlugins: ExperimentalConfig['swcPlugins']
......@@ -115,7 +117,10 @@ function getBaseSWCOptions({
)
const plugins = (swcPlugins ?? [])
.filter(Array.isArray)
.map(([name, options]: any) => [require.resolve(name), options])
.map(([name, options]: any) => [
require.resolve(name, configDir ? { paths: [configDir] } : undefined),
options,
])
return {
jsc: {
......@@ -311,6 +316,7 @@ export function getJestSWCOptions({
filename,
esm,
modularizeImports,
configDir,
swcPlugins,
compilerOptions,
jsConfig,
......@@ -322,6 +328,7 @@ export function getJestSWCOptions({
isServer: boolean
filename: string
esm: boolean
configDir?: string
modularizeImports?: NextConfig['modularizeImports']
swcPlugins: ExperimentalConfig['swcPlugins']
compilerOptions: NextConfig['compiler']
......@@ -337,6 +344,7 @@ export function getJestSWCOptions({
jest: true,
development: false,
hasReactRefresh: false,
configDir,
globalWindow: !isServer,
modularizeImports,
swcPlugins,
......@@ -393,6 +401,8 @@ export function getLoaderSWCOptions({
isPageFile,
isCacheComponents,
hasReactRefresh,
// The folder containing the next.config.js, used for resolving relative config paths.
configDir,
modularizeImports,
optimizeServerReact,
optimizePackageImports,
......@@ -420,6 +430,7 @@ export function getLoaderSWCOptions({
appDir?: string
isPageFile: boolean
hasReactRefresh: boolean
configDir: string
optimizeServerReact?: boolean
modularizeImports: NextConfig['modularizeImports']
isCacheComponents?: boolean
......@@ -448,6 +459,7 @@ export function getLoaderSWCOptions({
development,
globalWindow: !isServer,
hasReactRefresh,
configDir,
modularizeImports,
swcPlugins,
compilerOptions,
......
......@@ -152,6 +152,7 @@ async function loaderTransform(
!!nextConfig.experimental?.allowDevelopmentBuild,
isCacheComponents: nextConfig.cacheComponents,
hasReactRefresh,
configDir: rootDir,
modularizeImports: nextConfig?.modularizeImports,
optimizePackageImports: nextConfig?.experimental?.optimizePackageImports,
swcPlugins: nextConfig?.experimental?.swcPlugins,
......
......@@ -19,6 +19,7 @@ describe('swcEnvOptions', () => {
serverReferenceHashSalt: 'test-salt',
bundleLayer: undefined,
cacheHandlers: undefined,
configDir: '/',
}
it('should not include extra env options when swcEnvOptions is not set', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment