Commit ad4c7855 authored by Jude Gao's avatar Jude Gao

[Webpack] Transpile external TypeScript files imported by instrumentation-client in pages layer

parent 3cee3a37
...@@ -1766,6 +1766,16 @@ export default async function getBaseWebpackConfig( ...@@ -1766,6 +1766,16 @@ export default async function getBaseWebpackConfig(
}, },
] ]
: []), : []),
{
test: codeCondition.test,
exclude: codeCondition.exclude,
issuerLayer: WEBPACK_LAYERS.pagesDirBrowser,
use: [
...reactRefreshLoaders,
defaultLoaders.babel,
reactCompilerLoader,
].filter(Boolean),
},
{ {
...codeCondition, ...codeCondition,
use: [ use: [
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
'use client'
import { useEffect, useState } from 'react'
export default function Page() {
const [result, setResult] = useState<string>('')
useEffect(() => {
setResult((window as any).__INSTRUMENTATION_CLIENT_RESULT || 'not-set')
}, [])
return <p id="result">{result}</p>
}
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import fs from 'fs'
import path from 'path'
describe('instrumentation-client-external-dir', () => {
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
beforeAll(async () => {
// Create the external package directory outside the project root
// to simulate a monorepo sibling package with TypeScript files
const externalDir = path.join(next.testDir, '..', 'external-package')
await fs.promises.mkdir(externalDir, { recursive: true })
await fs.promises.writeFile(
path.join(externalDir, 'utils.ts'),
`
interface InitOptions {
debug: boolean
}
export function initClient(options: InitOptions): string {
const message: string = options.debug
? 'external-package-init-debug'
: 'external-package-init'
return message
}
`
)
await next.start()
})
it('should transpile TypeScript files imported from outside the project root in instrumentation-client', async () => {
const browser = await next.browser('/')
await retry(async () => {
const result = await browser.elementById('result').text()
expect(result).toBe('external-package-init-debug')
})
})
})
import { initClient } from '../external-package/utils'
const result = initClient({ debug: true })
;(window as any).__INSTRUMENTATION_CLIENT_RESULT = result
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
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