Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/next-plugin/package.json": "Patch"
},
"note": "Resolve WASM from the plugin's physical install location in Bun isolated installs",
"date": "2026-08-30T03:43:34.977Z"
}
63 changes: 62 additions & 1 deletion packages/next-plugin/src/__tests__/wasm.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import {
mkdirSync,
mkdtempSync,
rmSync,
symlinkSync,
writeFileSync,
} from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

import * as wasm from '@devup-ui/wasm'
import * as webpackPlugin from '@devup-ui/webpack-plugin'
import { afterEach, describe, expect, it } from 'bun:test'
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'bun:test'

import {
loadWasm,
loadWebpackPlugin,
requireFromPlugin,
requireWasm,
setWasmForTesting,
setWebpackPluginForTesting,
} from '../wasm'

const originalCwd = process.cwd()
let tempRoots: string[] = []

beforeAll(() => {
tempRoots = []
})

afterEach(() => {
process.chdir(originalCwd)
setWasmForTesting(undefined)
setWebpackPluginForTesting(undefined)
})

afterAll(() => {
for (const root of tempRoots) rmSync(root, { recursive: true, force: true })
})

describe('WASM selection', () => {
it('uses an injected namespace in tests', () => {
setWasmForTesting(wasm)
Expand All @@ -27,6 +50,44 @@ describe('WASM selection', () => {
expect(typeof loadWasm(true).codeExtract).toBe('function')
})

it('resolves dependencies from a Bun-style isolated install', () => {
const root = mkdtempSync(join(tmpdir(), 'devup-ui-next-isolated-'))
tempRoots.push(root)
const isolatedNodeModules = join(
root,
'node_modules/.bun/next-plugin/node_modules',
)
const pluginDir = join(isolatedNodeModules, '@devup-ui/next-plugin')
const wasmDir = join(isolatedNodeModules, '@devup-ui/wasm')
const rootScope = join(root, 'node_modules/@devup-ui')
mkdirSync(pluginDir, { recursive: true })
mkdirSync(wasmDir, { recursive: true })
mkdirSync(rootScope, { recursive: true })
writeFileSync(
join(pluginDir, 'package.json'),
JSON.stringify({ name: '@devup-ui/next-plugin' }),
)
writeFileSync(
join(wasmDir, 'package.json'),
JSON.stringify({ name: '@devup-ui/wasm', main: 'index.cjs' }),
)
writeFileSync(
join(wasmDir, 'index.cjs'),
'module.exports = { isolated: true }',
)
symlinkSync(
pluginDir,
join(rootScope, 'next-plugin'),
process.platform === 'win32' ? 'junction' : 'dir',
)

process.chdir(root)

expect(requireFromPlugin<{ isolated: boolean }>('@devup-ui/wasm')).toEqual({
isolated: true,
})
})

it.each(['MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'])(
'falls back to the full package when the lite export fails with %s',
(code) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/next-plugin/src/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'node:fs'
import { existsSync, realpathSync } from 'node:fs'
import { createRequire } from 'node:module'
import { join } from 'node:path'

Expand All @@ -11,7 +11,8 @@ let fullWasm: DevupWasm | undefined
let liteWasm: DevupWasm | undefined
let webpackPlugin: DevupWebpackPlugin | undefined

function requireFromPlugin<T>(specifier: string): T {
/** @internal Resolve dependencies from the plugin's physical install location. */
export function requireFromPlugin<T>(specifier: string): T {
const installedPackage = join(
process.cwd(),
'node_modules/@devup-ui/next-plugin/package.json',
Expand All @@ -25,7 +26,7 @@ function requireFromPlugin<T>(specifier: string): T {
: existsSync(workspacePackage)
? workspacePackage
: join(process.cwd(), 'package.json')
return createRequire(requireBase)(specifier) as T
return createRequire(realpathSync(requireBase))(specifier) as T
}

type WasmLoader = (specifier: string) => DevupWasm
Expand Down
Loading