Skip to content

Commit

Permalink
fix: resolve asbolute path to jiti for pnpm support (#58)
Browse files Browse the repository at this point in the history
* fix: resolve asbolute path to jiti for pnpm support

* Delete stub.ts
  • Loading branch information
antfu authored Apr 8, 2022
1 parent eb7da84 commit 81d6da7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}')`)

This comment has been minimized.

Copy link
@pi0

pi0 Apr 12, 2022

Member

FYI this doesn't work for windows. We need to use file URLs

image

This comment has been minimized.

Copy link
@pi0

pi0 Apr 12, 2022

Member

(sorry comment was for .mjs :D )

}
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

0 comments on commit 81d6da7

Please sign in to comment.