Skip to content

Commit

Permalink
build: self hoist (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Dec 3, 2023
1 parent 35fa09c commit d91b882
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
"name": "bunchee",
"version": "3.9.2",
"description": "zero config bundler for js/ts/jsx libraries",
"bin": {
"bunchee": "./dist/cli.js"
},
"bin": "./dist/bin/cli.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"test": "jest --env node",
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
"clean": "rm -rf ./dist",
"typecheck": "tsc --noEmit",
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/cli.js && pnpm test",
"build:cli": "tsx ./src/cli.ts ./src/cli.ts --runtime node -f cjs -o ./dist/cli.js",
"build:main": "tsx ./src/cli.ts ./src/index.ts --runtime node -f cjs",
"build": "pnpm build:main && pnpm build:cli",
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test",
"build": "tsx ./src/bin/index.ts --runtime node",
"format": "prettier --write .",
"prepare": "husky install"
},
Expand Down
10 changes: 5 additions & 5 deletions src/cli.ts → src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

import type { CliArgs, BundleConfig } from './types'
import type { CliArgs, BundleConfig } from '../types'

import path from 'path'
import arg from 'arg'
import { exit, formatDuration, getPackageMeta, hasPackageJson } from './utils'
import { logger } from './logger'
import { version } from '../package.json'
import { exit, formatDuration, getPackageMeta, hasPackageJson } from '../utils'
import { logger } from '../logger'
import { version } from '../../package.json'

const helpMessage = `
Usage: bunchee [options]
Expand Down Expand Up @@ -138,7 +138,7 @@ async function run(args: CliArgs) {
}

const entry = source ? path.resolve(cwd, source) : ''
const bundle: typeof import('./index').bundle = require('./index').bundle
const bundle: typeof import('../index').bundle = require('../index').bundle

let timeStart = Date.now()
let timeEnd
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('cli', () => {

const ps = fork(
`${require.resolve('tsx/cli')}`,
[__dirname + '/../src/cli.ts'].concat(args),
[__dirname + '/../src/bin/index.ts'].concat(args),
{
stdio: 'pipe',
env,
Expand Down
4 changes: 2 additions & 2 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ async function runBundle(
args_: string[],
): Promise<{ code: number | null; stdout: string; stderr: string }> {
const assetPath = process.env.POST_BUILD
? '/../dist/cli.js'
: '/../src/cli.ts'
? '/../dist/bin/cli.js'
: '/../src/bin/index.ts'

const args = (args_ || []).concat(['--cwd', dir])
const ps = fork(
Expand Down

0 comments on commit d91b882

Please sign in to comment.