Skip to content

Commit 787e597

Browse files
committed
fix
1 parent d04fdb1 commit 787e597

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// biome-ignore lint/suspicious/noTsIgnore: we can't use ts-expect-error because states are dynamic
22
// @ts-ignore
3-
import * as moonscratch from '../../_build/js/debug/build/moonscratch.js'
3+
import * as moonscratch from '../../_build/js/release/build/moonscratch.js'
44

55
export { moonscratch }

packages/moonscratch/vite.config.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,57 @@
1+
import { existsSync } from 'node:fs'
2+
import { dirname, resolve } from 'node:path'
13
import { defineConfig } from 'vite-plus'
24

5+
const RELEASE_IMPORTER_PATH = '../../_build/js/release/build/moonscratch.js'
6+
const RELEASE_BINDING_PATH = '../../_build/js/release/build/moonscratch.js'
7+
const DEBUG_BINDING_PATH = '../../_build/js/debug/build/moonscratch.js'
8+
const DEBUG_BUILD_PATH = './_build/js/debug/build/moonscratch.js'
9+
10+
const toAbsolutePath = (
11+
importer: string | null | undefined,
12+
importPath: string,
13+
) => {
14+
const baseDir = importer ? dirname(importer) : process.cwd()
15+
const normalizedCandidate = importPath.replace(/^\.\.\/\.\.\//, './')
16+
const candidates = [
17+
resolve(baseDir, importPath),
18+
resolve(process.cwd(), importPath),
19+
resolve(process.cwd(), normalizedCandidate),
20+
]
21+
for (const candidate of candidates) {
22+
if (existsSync(candidate)) {
23+
return candidate
24+
}
25+
}
26+
return undefined
27+
}
28+
29+
const resolveBindingPath = (importer: string | null | undefined) => {
30+
const releasePath = toAbsolutePath(importer, RELEASE_IMPORTER_PATH)
31+
if (releasePath) {
32+
return releasePath
33+
}
34+
if (existsSync(resolve(process.cwd(), DEBUG_BUILD_PATH))) {
35+
return resolve(process.cwd(), DEBUG_BUILD_PATH)
36+
}
37+
const debugPath = toAbsolutePath(importer, DEBUG_BINDING_PATH)
38+
return debugPath
39+
}
40+
341
export default defineConfig({
442
pack: {
543
entry: 'js/index.ts',
644
dts: true,
45+
plugins: [
46+
{
47+
name: 'mbt-binding',
48+
resolveId(id, importer) {
49+
if (id === RELEASE_BINDING_PATH) {
50+
return resolveBindingPath(importer)
51+
}
52+
},
53+
},
54+
],
755
},
856
test: {
957
include: ['./js/**/*.test.ts'],

0 commit comments

Comments
 (0)