Skip to content

Commit

Permalink
fix(rollup): escape stub import paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 10, 2022
1 parent 7b774e1 commit 63a3c11
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/builder/rollup.ts
Expand Up @@ -38,7 +38,7 @@ export async function rollupBuild (ctx: BuildContext) {

// CJS Stub
if (ctx.options.rollup.emitCJS) {
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true, esmResolve: true })('${resolvedEntry}')`)
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true, esmResolve: true })(${JSON.stringify(resolvedEntry)})`)
}

// MJS Stub
Expand All @@ -49,10 +49,10 @@ export async function rollupBuild (ctx: BuildContext) {
warn(ctx, `Cannot analyze ${resolvedEntry} for exports:` + err)
return []
})
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(pathToFileURL(jitiPath).href)};\nconst _module = jiti(null, { interopDefault: true, esmResolve: true })('${resolvedEntry}');\n\nexport default _module;\n\n${namedExports.map(name => `export const ${name} = _module.${name};`).join('\n')}`)
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(pathToFileURL(jitiPath).href)};\nconst _module = jiti(null, { interopDefault: true, esmResolve: true })(${JSON.stringify(resolvedEntry)});\n\nexport default _module;\n\n${namedExports.map(name => `export const ${name} = _module.${name};`).join('\n')}`)

// DTS Stub
await writeFile(output + '.d.ts', `export * from '${entry.input}';\nexport { default } from '${resolvedEntry}';`)
await writeFile(output + '.d.ts', `export * from ${JSON.stringify(entry.input)};\nexport { default } from ${JSON.stringify(resolvedEntry)};`)

if (shebang) {
await makeExecutable(output + '.cjs')
Expand Down

0 comments on commit 63a3c11

Please sign in to comment.