Skip to content

Commit

Permalink
Fix(CLI): TypeError: e is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jul 9, 2023
1 parent 81ad672 commit 81b79e0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"dependencies": {
"@techor/extend": "",
"@techor/fs": "",
"@techor/log": "",
"@techor/glob": "",
"@techor/log": "",
"@techor/one-liner": "",
"cross-import": "",
"esbuild": "^0.18.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/pack/src/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { explorePathsSync } from '@techor/glob'

declare type BuildTask = { options?: BuildOptions, metafile?: Metafile, run: () => Promise<any> }

export default async function action(specifiedEntries: string[], options: any = {}) {
module.exports = async function action(specifiedEntries: string[], options: any = {}) {
// if (!specifiedEntries.length) {
// specifiedEntries = [path.join(options.srcdir, '**/*.{js,ts,jsx,tsx,mjs,mts,css}')]
// }
Expand Down
4 changes: 2 additions & 2 deletions packages/techor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "techor",
"scripts": {
"build": "esbuild src/bin/index.ts --bundle --outfile=dist/bin/index.bundle.js --format=cjs --minify --platform=node --external:@techor/fs --external:@techor/log --external:commander --external:@techor/version --external:@techor/pack",
"build": "esbuild src/bin/index.ts --bundle --outfile=dist/bin/index.bundle.js --format=cjs --target=esnext --platform=node --external:@techor/fs --external:@techor/log --external:commander --external:@techor/version --external:@techor/pack",
"dev": "npm run build -- --watch",
"type-check": "tsc --noEmit",
"lint": "eslint src"
Expand Down Expand Up @@ -55,6 +55,6 @@
"dependencies": {
"@techor/fs": "",
"@techor/log": "",
"commander": "^10.0.0"
"commander": "^11.0.0"
}
}
22 changes: 12 additions & 10 deletions packages/techor/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/usr/bin/env node

import { program } from 'commander'
import { Command } from 'commander'
import { readJSONFileSync } from '@techor/fs'
import log from '@techor/log'
import path from 'path'

const { version, name, description } = readJSONFileSync('./package.json')
const { version, name, description } = readJSONFileSync(path.resolve(__dirname, '../../package.json'))
const program = new Command()

program
.name(name)
.description(description)
.version(version || '0.0.0')

program.command('pack [entryPaths...]')
.option('-f, --format [formats...]', 'The output format for the generated JavaScript files `iife`, `cjs`, `esm`', ['cjs', 'esm'])
Expand All @@ -29,8 +36,7 @@ program.command('pack [entryPaths...]')
.option('--no-clean', 'OFF: Clean up the previous output directory before the build starts')
.action(async function (args, options) {
try {
// @ts-expect-error dynamic import action
const action = (await import('@techor/pack/actions/main')).default
const action = require('@techor/pack/actions/main')
await action(args, options)
} catch (error) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
Expand All @@ -50,8 +56,7 @@ program.command('version <version>')
.option('--no-public', 'Off: Bump public project version')
.action(async function (args, options) {
try {
// @ts-expect-error dynamic import action
const action = (await import('@techor/version/actions/main')).default
const action = require('@techor/version/actions/main')
await action(args, options)
} catch (error) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
Expand All @@ -62,7 +67,4 @@ program.command('version <version>')
}
})

program.parse(process.argv)
program.name(name)
program.description(description)
program.version(version)
program.parse()
2 changes: 1 addition & 1 deletion packages/version/src/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'
import log, { paint } from '@techor/log'
import { readJSONFileSync, writeFileSync } from '@techor/fs'

export default function action(version: string, options) {
module.exports = function action(version: string, options) {
const pkg = readJSONFileSync(path.resolve('./package.json'))
if (!options.workspaces) {
options.workspaces = pkg.workspaces
Expand Down

0 comments on commit 81b79e0

Please sign in to comment.