Skip to content

Commit

Permalink
fix types generation on node 18 because of --loader bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Feb 1, 2025
1 parent d4b50ad commit cfc9b48
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions unframer/src/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,27 +904,35 @@ export async function extractPropControlsUnsafe(
const code = `import("${fileUrl}").then(x => { console.log("${delimiter}"); console.log(${propCode}) })`

const TIMEOUT = 5 * 1000
const UNFRAMER_MAP_PACKAGES = JSON.stringify({
const UNFRAMER_MAP_PACKAGES = {
unframer: url.pathToFileURL(require.resolve('../esm/index.js')).href,
react: url.pathToFileURL(require.resolve('react')).href,
'react-dom': url.pathToFileURL(require.resolve('react-dom')).href,
'react/jsx-runtime': url.pathToFileURL(
require.resolve('react/jsx-runtime'),
).href,
})
}
let loaderOption = `--loader ${url.pathToFileURL(
require.resolve('../dist/unframer-loader.js'),
)}`
try {
require.resolve('unframer/package.json')

UNFRAMER_MAP_PACKAGES.unframer = ''
} catch {}
let stdout = await new Promise<string>((res, rej) => {
const cmd = `"${
nodePath
}" --no-warnings --input-type=module --loader ${url.pathToFileURL(
require.resolve('../dist/unframer-loader.js'),
)} -e ${JSON.stringify(code)}`
}" --no-warnings --input-type=module ${loaderOption} -e ${JSON.stringify(code)}`

let childProcess = exec(
cmd,
{
env: {
// ...process.env,
UNFRAMER_MAP_PACKAGES,
UNFRAMER_MAP_PACKAGES: JSON.stringify(
UNFRAMER_MAP_PACKAGES,
),
},
},
(err, stdout, stderr) => {
Expand Down

0 comments on commit cfc9b48

Please sign in to comment.