Skip to content

Commit

Permalink
Improve(Pack): Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jul 6, 2023
1 parent 0f41a93 commit 445ead3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dedent": "^0.7.0",
"execa": "^7.1.1",
"pkg-types": "^1.0.1",
"pretty-bytes": "^6.1.0"
"pretty-bytes": "^6.1.0",
"pretty-hrtime": "^1.0.3"
}
}
}
8 changes: 7 additions & 1 deletion packages/pack/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import extend from '@techor/extend'
import { readFileAsJSON } from '@techor/fs'
import exploreConfig from 'explore-config'
import { execaCommand } from 'execa'
import prettyHartime from 'pretty-hrtime'
import { createShakableLibPlugin } from '../plugins/shakable-lib'

declare type BuildTask = { options?: BuildOptions, metafile?: Metafile, run: () => Promise<any> }
const pkg: PackageJson = readFileAsJSON('./package.json')
Expand Down Expand Up @@ -154,6 +156,8 @@ program.command('pack [entryPaths...]', { isDefault: true })
// buildOptions.plugins.push(createFillModuleExtPlugin(options.esmExt))
// }

// buildOptions.plugins.push(createShakableLibPlugin({ srcdir: options.srcdir }))

// Fix ERROR: Invalid option in build() call
delete buildOptions['watch']
delete buildOptions['serve']
Expand Down Expand Up @@ -352,7 +356,9 @@ program.command('pack [entryPaths...]', { isDefault: true })
}
}

const buildStartTime = process.hrtime()
await Promise.all(buildTasks.map(({ run }) => run()))
const buildEndTime = process.hrtime(buildStartTime)

console.log('')

Expand All @@ -377,7 +383,7 @@ program.command('pack [entryPaths...]', { isDefault: true })
if (options.watch) {
log`Start watching ${buildTasks.length} build tasks $t`
} else {
log.success`${buildTasks.length} build tasks $t`
log.success`${buildTasks.length} build tasks $t in ${prettyHartime(buildEndTime).replace(' ', '')}`
}
console.log('')

Expand Down
21 changes: 21 additions & 0 deletions packages/pack/src/plugins/shakable-lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Plugin } from 'esbuild'
import path from 'upath'

export const createShakableLibPlugin = ({ srcdir }: { srcdir: string }): Plugin => ({
name: 'shakable-lib-plugin',
setup(build) {
const started: any = {}
started.promise = new Promise(resolve => {
started.resolve = resolve
})
build.onStart(() => {
started.resolve(true)
})
build.onResolve({ filter: /\.(?:ts|tsx|js|jsx|mjs|mts|css)$/ }, args => {
return {
path: path.join(args.resolveDir, args.path),
external: path.normalize(args.path).startsWith(srcdir)
}
})
}
})
1 change: 1 addition & 0 deletions packages/pack/tests/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'foo'
3 changes: 2 additions & 1 deletion packages/pack/tests/standard/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './options'
export * from './dev-deps'
export * from './external'
import { foo } from '../../foo'

const a = 1236324243223423
console.log(a)
console.log(a, foo)

0 comments on commit 445ead3

Please sign in to comment.