Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve asbolute path to jiti for pnpm support #58

Merged
merged 2 commits into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -16,9 +16,9 @@
"build": "pnpm unbuild",
"dev": "pnpm unbuild test/fixture",
"lint": "eslint --ext .ts,.js .",
"prepack": "pnpm build",
"prepack": "pnpm unbuild",
"release": "pnpm test && standard-version && git push --follow-tags && npm publish",
"stub": "pnpm build --stub",
"stub": "pnpm unbuild -- --stub",
"test": "mocha -r jiti/register ./test/*.test.*",
"unbuild": "jiti ./src/cli"
},
Expand Down
7 changes: 5 additions & 2 deletions src/builder/rollup.ts
Expand Up @@ -10,6 +10,7 @@ import dts from 'rollup-plugin-dts'
import replace from '@rollup/plugin-replace'
import { relative, resolve, dirname } from 'pathe'
import consola from 'consola'
import { resolvePath } from 'mlly'
import { getpkg, tryResolve } from '../utils'
import type { BuildContext } from '../types'
import { JSONPlugin } from './plugins/json'
Expand All @@ -22,6 +23,8 @@ const esbuild = _esbuild.default || _esbuild

export async function rollupBuild (ctx: BuildContext) {
if (ctx.options.stub) {
const jitiPath = await resolvePath('jiti', { url: import.meta.url })

for (const entry of ctx.options.entries.filter(entry => entry.builder === 'rollup')) {
const output = resolve(ctx.options.rootDir, ctx.options.outDir, entry.name!)

Expand All @@ -31,9 +34,9 @@ export async function rollupBuild (ctx: BuildContext) {

await mkdir(dirname(output), { recursive: true })
if (ctx.options.rollup.emitCJS) {
await writeFile(output + '.cjs', `${shebang}module.exports = require('jiti')(null, { interopDefault: true })('${entry.input}')`)
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true })('${entry.input}')`)
}
await writeFile(output + '.mjs', `${shebang}import jiti from 'jiti';\nexport default jiti(null, { interopDefault: true })('${entry.input}');`)
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(jitiPath)};\nexport default jiti(null, { interopDefault: true })('${entry.input}');`)
await writeFile(output + '.d.ts', `export * from '${entry.input}';\nexport { default } from '${entry.input}';`)

if (shebang) {
Expand Down