Skip to content

Commit 73b90ca

Browse files
committed
fix: use cross-spawn for better windows support
closes #12
1 parent 5fb0d2d commit 73b90ca

File tree

4 files changed

+75
-21
lines changed

4 files changed

+75
-21
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@babel/preset-typescript": "^7.8.3",
3636
"chalk": "^3.0.0",
3737
"cosmiconfig": "^6.0.0",
38+
"cross-spawn": "^7.0.1",
3839
"dedent": "^0.7.0",
3940
"del": "^5.1.0",
4041
"ejs": "^3.0.1",
@@ -56,6 +57,7 @@
5657
"@release-it/conventional-changelog": "^1.1.0",
5758
"@types/babel__core": "^7.1.3",
5859
"@types/chalk": "^2.2.0",
60+
"@types/cross-spawn": "^6.0.1",
5961
"@types/dedent": "^0.7.0",
6062
"@types/del": "^4.0.0",
6163
"@types/ejs": "^3.0.0",

src/create.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import child_process from 'child_process';
21
import path from 'path';
32
import fs from 'fs-extra';
43
import ejs from 'ejs';
54
import dedent from 'dedent';
65
import chalk from 'chalk';
76
import inquirer from 'inquirer';
87
import yargs from 'yargs';
8+
import spawn from 'cross-spawn';
99
import validateNpmPackage from 'validate-npm-package-name';
1010
import githubUsername from 'github-username';
1111
import pack from '../package.json';
@@ -29,14 +29,14 @@ export default async function create(argv: yargs.Arguments<any>) {
2929
let name, email;
3030

3131
try {
32-
name = child_process
33-
.execSync('git config --get user.name')
34-
.toString()
32+
name = spawn
33+
.sync('git', ['config', '--get', 'user.name'])
34+
.stdout.toString()
3535
.trim();
3636

37-
email = child_process
38-
.execSync('git config --get user.email')
39-
.toString()
37+
email = spawn
38+
.sync('git', ['config', '--get', 'user.email'])
39+
.stdout.toString()
4040
.trim();
4141
} catch (e) {
4242
// Ignore error
@@ -178,7 +178,7 @@ export default async function create(argv: yargs.Arguments<any>) {
178178
await copyDir(TEMPLATE, folder);
179179

180180
try {
181-
await child_process.execSync(
181+
await spawn.sync(
182182
'git init && git add . && git commit -m "chore: initial commit"',
183183
{ cwd: folder }
184184
);

src/targets/typescript.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from 'chalk';
22
import path from 'path';
3-
import child_process from 'child_process';
43
import fs from 'fs-extra';
4+
import spawn from 'cross-spawn';
55
import del from 'del';
66
import JSON5 from 'json5';
77
import { platform } from 'os';
@@ -83,22 +83,34 @@ export default async function build({
8383
(platform() === 'win32' ? '.cmd' : '');
8484

8585
if (!(await fs.pathExists(tsc))) {
86-
tsc = child_process
87-
.execSync('which tsc')
88-
.toString('utf-8')
86+
tsc = spawn
87+
.sync('which', ['tsc'])
88+
.stdout.toString()
8989
.trim();
90+
91+
report.warn(
92+
`Using a global version of ${chalk.blue(
93+
'tsc'
94+
)}. Consider adding ${chalk.blue('typescript')} to your ${chalk.blue(
95+
'devDependencies'
96+
)} instead.`
97+
);
9098
}
9199

92100
if (await fs.pathExists(tsc)) {
93-
child_process.execFileSync(tsc, [
94-
'--pretty',
95-
'--declaration',
96-
'--emitDeclarationOnly',
97-
'--project',
98-
project,
99-
'--outDir',
100-
output,
101-
]);
101+
spawn.sync(
102+
tsc,
103+
[
104+
'--pretty',
105+
'--declaration',
106+
'--emitDeclarationOnly',
107+
'--project',
108+
project,
109+
'--outDir',
110+
output,
111+
],
112+
{ stdio: 'inherit' }
113+
);
102114

103115
await del([
104116
path.join(output, project.replace(/\.json$/, '.tsbuildinfo')),

yarn.lock

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,13 @@
12541254
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
12551255
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
12561256

1257+
"@types/cross-spawn@^6.0.1":
1258+
version "6.0.1"
1259+
resolved "https://registry.yarnpkg.com/@types/cross-spawn/-/cross-spawn-6.0.1.tgz#60fa0c87046347c17d9735e5289e72b804ca9b63"
1260+
integrity sha512-MtN1pDYdI6D6QFDzy39Q+6c9rl2o/xN7aWGe6oZuzqq5N6+YuwFsWiEAv3dNzvzN9YzU+itpN8lBzFpphQKLAw==
1261+
dependencies:
1262+
"@types/node" "*"
1263+
12571264
"@types/dedent@^0.7.0":
12581265
version "0.7.0"
12591266
resolved "http://localhost:4873/@types%2fdedent/-/dedent-0.7.0.tgz#155f339ca404e6dd90b9ce46a3f78fd69ca9b050"
@@ -2359,6 +2366,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
23592366
shebang-command "^1.2.0"
23602367
which "^1.2.9"
23612368

2369+
cross-spawn@^7.0.1:
2370+
version "7.0.1"
2371+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
2372+
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
2373+
dependencies:
2374+
path-key "^3.1.0"
2375+
shebang-command "^2.0.0"
2376+
which "^2.0.1"
2377+
23622378
crypto-random-string@^1.0.0:
23632379
version "1.0.0"
23642380
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
@@ -5056,6 +5072,11 @@ path-key@^2.0.0, path-key@^2.0.1:
50565072
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
50575073
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
50585074

5075+
path-key@^3.1.0:
5076+
version "3.1.1"
5077+
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
5078+
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
5079+
50595080
path-parse@^1.0.6:
50605081
version "1.0.6"
50615082
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
@@ -5734,11 +5755,23 @@ shebang-command@^1.2.0:
57345755
dependencies:
57355756
shebang-regex "^1.0.0"
57365757

5758+
shebang-command@^2.0.0:
5759+
version "2.0.0"
5760+
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
5761+
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
5762+
dependencies:
5763+
shebang-regex "^3.0.0"
5764+
57375765
shebang-regex@^1.0.0:
57385766
version "1.0.0"
57395767
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
57405768
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
57415769

5770+
shebang-regex@^3.0.0:
5771+
version "3.0.0"
5772+
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
5773+
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
5774+
57425775
57435776
version "0.8.3"
57445777
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"
@@ -6388,6 +6421,13 @@ which@^1.2.9:
63886421
dependencies:
63896422
isexe "^2.0.0"
63906423

6424+
which@^2.0.1:
6425+
version "2.0.2"
6426+
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
6427+
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
6428+
dependencies:
6429+
isexe "^2.0.0"
6430+
63916431
wide-align@^1.1.0:
63926432
version "1.1.3"
63936433
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"

0 commit comments

Comments
 (0)