mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## Summary - add native Turbopack support for `import.meta.env.DEV`, `PROD`, `MODE`, `BASE_URL`, and `SSR` - statically analyze built-in values for dead-code elimination while exposing the complete runtime object - derive `BASE_URL` from the Next.js `basePath` and include Vite-compatible trailing-slash formatting - add TypeScript declarations, focused execution and Next.js integration coverage, and Vite migration documentation ## Verification - `cargo fmt --all -- --check` - `cargo nextest run -p turbopack-tests -E 'test(import_meta_env)'` - `pnpm build-all` - `pnpm --filter=next types` - `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-turbo test/e2e/import-meta-env/import-meta-env.test.ts` - `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-turbo test/e2e/import-meta-env/import-meta-env.test.ts` <!-- NEXT_JS_LLM -->
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { isNextDev, nextTestSetup } from 'e2e-utils'
|
|
|
|
const testFn =
|
|
process.env.IS_WEBPACK_TEST || process.env.NEXT_RSPACK
|
|
? describe.skip
|
|
: describe
|
|
|
|
testFn('import.meta.env', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('exposes built-in environment values on the server and client', async () => {
|
|
const browser = await next.browser('/docs')
|
|
const expectedMode = isNextDev ? 'development' : 'production'
|
|
|
|
expect(
|
|
JSON.parse(await browser.elementByCss('#server-env dd').text())
|
|
).toEqual({
|
|
DEV: isNextDev,
|
|
PROD: !isNextDev,
|
|
MODE: expectedMode,
|
|
BASE_URL: '/docs/',
|
|
SSR: true,
|
|
})
|
|
expect(
|
|
JSON.parse(await browser.elementByCss('#client-env dd').text())
|
|
).toEqual({
|
|
DEV: isNextDev,
|
|
PROD: !isNextDev,
|
|
MODE: expectedMode,
|
|
BASE_URL: '/docs/',
|
|
SSR: false,
|
|
})
|
|
})
|
|
|
|
it('supports static bracket access and unknown properties', async () => {
|
|
const browser = await next.browser('/docs')
|
|
const $ = await next.render$('/docs')
|
|
const expectedMode = isNextDev ? 'development' : 'production'
|
|
|
|
expect($('#server-env dd').eq(1).text()).toBe(expectedMode)
|
|
expect($('#server-env dd').eq(2).text()).toBe('undefined')
|
|
expect(
|
|
await browser.elementByCss('#client-env dd:nth-of-type(2)').text()
|
|
).toBe(expectedMode)
|
|
expect(
|
|
await browser.elementByCss('#client-env dd:nth-of-type(3)').text()
|
|
).toBe('undefined')
|
|
})
|
|
})
|