Skip to content

Commit 81d6da7

Browse files
authoredApr 8, 2022
fix: resolve asbolute path to jiti for pnpm support (#58)
* fix: resolve asbolute path to jiti for pnpm support * Delete stub.ts
1 parent eb7da84 commit 81d6da7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"build": "pnpm unbuild",
1717
"dev": "pnpm unbuild test/fixture",
1818
"lint": "eslint --ext .ts,.js .",
19-
"prepack": "pnpm build",
19+
"prepack": "pnpm unbuild",
2020
"release": "pnpm test && standard-version && git push --follow-tags && npm publish",
21-
"stub": "pnpm build --stub",
21+
"stub": "pnpm unbuild -- --stub",
2222
"test": "mocha -r jiti/register ./test/*.test.*",
2323
"unbuild": "jiti ./src/cli"
2424
},

‎src/builder/rollup.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dts from 'rollup-plugin-dts'
1010
import replace from '@rollup/plugin-replace'
1111
import { relative, resolve, dirname } from 'pathe'
1212
import consola from 'consola'
13+
import { resolvePath } from 'mlly'
1314
import { getpkg, tryResolve } from '../utils'
1415
import type { BuildContext } from '../types'
1516
import { JSONPlugin } from './plugins/json'
@@ -22,6 +23,8 @@ const esbuild = _esbuild.default || _esbuild
2223

2324
export async function rollupBuild (ctx: BuildContext) {
2425
if (ctx.options.stub) {
26+
const jitiPath = await resolvePath('jiti', { url: import.meta.url })
27+
2528
for (const entry of ctx.options.entries.filter(entry => entry.builder === 'rollup')) {
2629
const output = resolve(ctx.options.rootDir, ctx.options.outDir, entry.name!)
2730

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

3235
await mkdir(dirname(output), { recursive: true })
3336
if (ctx.options.rollup.emitCJS) {
34-
await writeFile(output + '.cjs', `${shebang}module.exports = require('jiti')(null, { interopDefault: true })('${entry.input}')`)
37+
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true })('${entry.input}')`)
Has conversations. Original line has conversations.
3538
}
36-
await writeFile(output + '.mjs', `${shebang}import jiti from 'jiti';\nexport default jiti(null, { interopDefault: true })('${entry.input}');`)
39+
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(jitiPath)};\nexport default jiti(null, { interopDefault: true })('${entry.input}');`)
3740
await writeFile(output + '.d.ts', `export * from '${entry.input}';\nexport { default } from '${entry.input}';`)
3841

3942
if (shebang) {

0 commit comments

Comments
 (0)
Please sign in to comment.