Skip to content

Commit db915e5

Browse files
authored
refactor: use tinyexec instead of cross-spawn (#23583)
1 parent bbc8812 commit db915e5

5 files changed

Lines changed: 39 additions & 108 deletions

File tree

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@types/babel__core": "^7.20.5",
4848
"@types/babel__preset-env": "^7.10.0",
4949
"@types/convert-source-map": "^2.0.3",
50-
"@types/cross-spawn": "^6.0.6",
5150
"@types/etag": "^1.8.4",
5251
"@types/less": "^3.0.8",
5352
"@types/node": "^24.13.6",

‎packages/vite/LICENSE.md‎

Lines changed: 29 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -674,35 +674,6 @@ Repository: https://github.com/expressjs/cors
674674
675675
---------------------------------------
676676

677-
## cross-spawn
678-
License: MIT
679-
By: André Cruz
680-
Repository: https://github.com/moxystudio/node-cross-spawn
681-
682-
> The MIT License (MIT)
683-
>
684-
> Copyright (c) 2018 Made With MOXY Lda <hello@moxy.studio>
685-
>
686-
> Permission is hereby granted, free of charge, to any person obtaining a copy
687-
> of this software and associated documentation files (the "Software"), to deal
688-
> in the Software without restriction, including without limitation the rights
689-
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
690-
> copies of the Software, and to permit persons to whom the Software is
691-
> furnished to do so, subject to the following conditions:
692-
>
693-
> The above copyright notice and this permission notice shall be included in
694-
> all copies or substantial portions of the Software.
695-
>
696-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
697-
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
698-
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
699-
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
700-
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
701-
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
702-
> THE SOFTWARE.
703-
704-
---------------------------------------
705-
706677
## cssesc
707678
License: MIT
708679
By: Mathias Bynens
@@ -1226,29 +1197,6 @@ Repository: https://github.com/Rich-Harris/is-reference
12261197

12271198
---------------------------------------
12281199

1229-
## isexe, which
1230-
License: ISC
1231-
By: Isaac Z. Schlueter
1232-
Repositories: https://github.com/isaacs/isexe, https://github.com/isaacs/node-which
1233-
1234-
> The ISC License
1235-
>
1236-
> Copyright (c) Isaac Z. Schlueter and Contributors
1237-
>
1238-
> Permission to use, copy, modify, and/or distribute this software for any
1239-
> purpose with or without fee is hereby granted, provided that the above
1240-
> copyright notice and this permission notice appear in all copies.
1241-
>
1242-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1243-
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1244-
> MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1245-
> ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1246-
> WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1247-
> ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1248-
> IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1249-
1250-
---------------------------------------
1251-
12521200
## js-tokens
12531201
License: MIT
12541202
By: Simon Lydell
@@ -1669,23 +1617,6 @@ Repository: https://github.com/pillarjs/parseurl
16691617
16701618
---------------------------------------
16711619

1672-
## path-key, shebang-regex
1673-
License: MIT
1674-
By: Sindre Sorhus
1675-
Repositories: https://github.com/sindresorhus/path-key, https://github.com/sindresorhus/shebang-regex
1676-
1677-
> MIT License
1678-
>
1679-
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
1680-
>
1681-
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1682-
>
1683-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1684-
>
1685-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1686-
1687-
---------------------------------------
1688-
16891620
## periscopic
16901621
License: MIT
16911622
Repository: https://github.com/Rich-Harris/periscopic
@@ -1996,23 +1927,6 @@ Repositories: https://github.com/lukeed/resolve.exports, https://github.com/luke
19961927
19971928
---------------------------------------
19981929

1999-
## shebang-command
2000-
License: MIT
2001-
By: Kevin Mårtensson
2002-
Repository: https://github.com/kevva/shebang-command
2003-
2004-
> MIT License
2005-
>
2006-
> Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com> (github.com/kevva)
2007-
>
2008-
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2009-
>
2010-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2011-
>
2012-
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2013-
2014-
---------------------------------------
2015-
20161930
## shell-quote
20171931
License: MIT
20181932
By: James Halliday
@@ -2118,6 +2032,35 @@ Repository: https://github.com/antfu/strip-literal
21182032
21192033
---------------------------------------
21202034

2035+
## tinyexec
2036+
License: MIT
2037+
By: James Garbutt
2038+
Repository: https://github.com/tinylibs/tinyexec
2039+
2040+
> MIT License
2041+
>
2042+
> Copyright (c) 2024 Tinylibs
2043+
>
2044+
> Permission is hereby granted, free of charge, to any person obtaining a copy
2045+
> of this software and associated documentation files (the "Software"), to deal
2046+
> in the Software without restriction, including without limitation the rights
2047+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2048+
> copies of the Software, and to permit persons to whom the Software is
2049+
> furnished to do so, subject to the following conditions:
2050+
>
2051+
> The above copyright notice and this permission notice shall be included in all
2052+
> copies or substantial portions of the Software.
2053+
>
2054+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2055+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2056+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2057+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2058+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2059+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2060+
> SOFTWARE.
2061+
2062+
---------------------------------------
2063+
21212064
## to-regex-range
21222065
License: MIT
21232066
By: Jon Schlinkert, Rouven Weßling

‎packages/vite/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"connect": "^3.7.0",
9797
"convert-source-map": "^2.0.0",
9898
"cors": "^2.8.6",
99-
"cross-spawn": "^7.0.6",
10099
"dotenv-expand": "^13.0.0",
101100
"es-module-lexer": "^2.3.2",
102101
"esbuild": "^0.28.2",
@@ -130,6 +129,7 @@
130129
"sirv": "^3.0.2",
131130
"strip-literal": "^4.0.0",
132131
"terser": "^5.51.2",
132+
"tinyexec": "^1.3.1",
133133
"ufo": "^1.6.4",
134134
"ws": "^8.21.3"
135135
},

‎packages/vite/src/node/server/openBrowser.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import { exec } from 'node:child_process'
1212
import type { ExecOptions } from 'node:child_process'
1313
import { join } from 'node:path'
14-
import spawn from 'cross-spawn'
1514
import open from 'open'
1615
import type { Options } from 'open'
1716
import colors from 'picocolors'
17+
import { x } from 'tinyexec'
1818
import { VITE_PACKAGE_DIR } from '../constants'
1919
import type { Logger } from '../logger'
2020

@@ -41,16 +41,15 @@ export function openBrowser(
4141

4242
function executeNodeScript(scriptPath: string, url: string, logger: Logger) {
4343
const extraArgs = process.argv.slice(2)
44-
const child = spawn(process.execPath, [scriptPath, ...extraArgs, url], {
45-
stdio: 'inherit',
46-
})
47-
child.on('close', (code) => {
48-
if (code !== 0) {
44+
x(process.execPath, [scriptPath, ...extraArgs, url], {
45+
nodeOptions: { stdio: 'inherit' },
46+
}).then(({ exitCode }) => {
47+
if (exitCode !== 0) {
4948
logger.error(
5049
colors.red(
5150
`\nThe script specified as BROWSER environment variable failed.\n\n${colors.cyan(
5251
scriptPath,
53-
)} exited with code ${code}.`,
52+
)} exited with code ${exitCode}.`,
5453
),
5554
{ error: null },
5655
)

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)