Skip to content

Commit cfc9b48

Browse files
committed
fix types generation on node 18 because of --loader bugs
1 parent d4b50ad commit cfc9b48

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

unframer/src/exporter.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,27 +904,35 @@ export async function extractPropControlsUnsafe(
904904
const code = `import("${fileUrl}").then(x => { console.log("${delimiter}"); console.log(${propCode}) })`
905905

906906
const TIMEOUT = 5 * 1000
907-
const UNFRAMER_MAP_PACKAGES = JSON.stringify({
907+
const UNFRAMER_MAP_PACKAGES = {
908908
unframer: url.pathToFileURL(require.resolve('../esm/index.js')).href,
909909
react: url.pathToFileURL(require.resolve('react')).href,
910910
'react-dom': url.pathToFileURL(require.resolve('react-dom')).href,
911911
'react/jsx-runtime': url.pathToFileURL(
912912
require.resolve('react/jsx-runtime'),
913913
).href,
914-
})
914+
}
915+
let loaderOption = `--loader ${url.pathToFileURL(
916+
require.resolve('../dist/unframer-loader.js'),
917+
)}`
918+
try {
919+
require.resolve('unframer/package.json')
920+
921+
UNFRAMER_MAP_PACKAGES.unframer = ''
922+
} catch {}
915923
let stdout = await new Promise<string>((res, rej) => {
916924
const cmd = `"${
917925
nodePath
918-
}" --no-warnings --input-type=module --loader ${url.pathToFileURL(
919-
require.resolve('../dist/unframer-loader.js'),
920-
)} -e ${JSON.stringify(code)}`
926+
}" --no-warnings --input-type=module ${loaderOption} -e ${JSON.stringify(code)}`
921927

922928
let childProcess = exec(
923929
cmd,
924930
{
925931
env: {
926932
// ...process.env,
927-
UNFRAMER_MAP_PACKAGES,
933+
UNFRAMER_MAP_PACKAGES: JSON.stringify(
934+
UNFRAMER_MAP_PACKAGES,
935+
),
928936
},
929937
},
930938
(err, stdout, stderr) => {

0 commit comments

Comments
 (0)