From 63a3c1163fa7bdd26cfbd9ea0cc06acf27919d3c Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 10 Aug 2022 16:07:55 +0200 Subject: [PATCH] fix(rollup): escape stub import paths --- src/builder/rollup.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builder/rollup.ts b/src/builder/rollup.ts index 23f69c7..6b8723f 100644 --- a/src/builder/rollup.ts +++ b/src/builder/rollup.ts @@ -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 @@ -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')