Skip to content

Commit 646a7b3

Browse files
committed
fix(projects): fix execa can't run in commonjs
1 parent 3e3c44f commit 646a7b3

File tree

9 files changed

+23
-20
lines changed

9 files changed

+23
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
}
2626
},
2727
"bin": {
28-
"soybean": "dist/index.mjs",
29-
"soy": "dist/index.mjs"
28+
"soybean": "dist/index.cjs",
29+
"soy": "dist/index.cjs"
3030
},
3131
"files": [
3232
"dist"

src/changelog/git.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,5 @@ export async function getGitCommitsAndResolvedAuthors(commits: GitCommit[], gith
253253
contributors: Array.from(map.values())
254254
};
255255
}
256+
257+
getTotalGitTags();

src/command/eslint-prettier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { execa } from 'execa';
1+
import { execCommand } from '../shared';
22

33
export async function eslintPretter() {
4-
await execa('npx', ['eslint', '.', '--fix'], {
4+
await execCommand('npx', ['eslint', '.', '--fix'], {
55
stdio: 'inherit'
66
});
77

8-
await execa('npx', ['soy', 'prettier-format'], {
8+
await execCommand('npx', ['soy', 'prettier-format'], {
99
stdio: 'inherit'
1010
});
1111
}

src/command/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execa } from 'execa';
1+
import { execCommand } from '../shared';
22

33
export function prettierFormat() {
44
const formatFiles = [
@@ -18,7 +18,7 @@ export function prettierFormat() {
1818
'!__snapshots__'
1919
];
2020

21-
execa('npx', ['prettier', '.', '--write', ...formatFiles], {
21+
execCommand('npx', ['prettier', '.', '--write', ...formatFiles], {
2222
stdio: 'inherit'
2323
});
2424
}

src/command/git-commit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import enquirer from 'enquirer';
2-
import { execa } from 'execa';
2+
import { execCommand } from '../shared';
33
import { gitCommitTypes, gitCommitScopes } from '../configs';
44

55
interface PromptObject {
@@ -31,5 +31,5 @@ export async function gitCommit() {
3131

3232
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
3333

34-
execa('git', ['commit', '-m', commitMsg], { stdio: 'inherit' });
34+
execCommand('git', ['commit', '-m', commitMsg], { stdio: 'inherit' });
3535
}

src/command/git-hooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync } from 'fs';
2-
import { execa } from 'execa';
2+
import { execCommand } from '../shared';
33
import { rimraf } from 'rimraf';
44

55
export async function initSimpleGitHooks() {
@@ -8,9 +8,9 @@ export async function initSimpleGitHooks() {
88

99
if (existHusky) {
1010
await rimraf('.husky');
11-
await execa('git', ['config', 'core.hooksPath', '.git/hooks/'], { stdio: 'inherit' });
11+
await execCommand('git', ['config', 'core.hooksPath', '.git/hooks/'], { stdio: 'inherit' });
1212
}
1313

1414
await rimraf('.git/hooks');
15-
await execa('npx', ['simple-git-hooks'], { stdio: 'inherit' });
15+
await execCommand('npx', ['simple-git-hooks'], { stdio: 'inherit' });
1616
}

src/command/lint-staged.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { execa } from 'execa';
1+
import { execCommand } from '../shared';
22

33
export function lintStaged() {
4-
execa('npx', ['lint-staged', '--config', '@soybeanjs/cli/lint-staged'], { stdio: 'inherit' });
4+
execCommand('npx', ['lint-staged', '--config', '@soybeanjs/cli/lint-staged'], { stdio: 'inherit' });
55
}

src/command/update-pkg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { execa } from 'execa';
1+
import { execCommand } from '../shared';
22

33
export async function updatePkg() {
4-
execa('npx', ['ncu', '--deep', '-u'], { stdio: 'inherit' });
4+
execCommand('npx', ['ncu', '--deep', '-u'], { stdio: 'inherit' });
55
}

src/shared/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { execa } from 'execa';
1+
import type { Options } from 'execa';
22

3-
export async function execCommand(cmd: string, args: string[]) {
4-
const res = await execa(cmd, args);
5-
return res.stdout.trim();
3+
export async function execCommand(cmd: string, args: string[], options?: Options) {
4+
const { execa } = await import('execa');
5+
const res = await execa(cmd, args, options);
6+
return res?.stdout?.trim() || '';
67
}
78

89
export function notNullish<T>(v?: T | null): v is NonNullable<T> {

0 commit comments

Comments
 (0)