Skip to content

Commit bc1a2f3

Browse files
committed
Back to a synchronous factory. Fixes #37.
1 parent 6423e23 commit bc1a2f3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

source/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const isString = (str: unknown): str is string =>
127127
* A Rollup/Vite plugin that automatically declares NodeJS built-in modules,
128128
* and optionally npm dependencies, as 'external'.
129129
*/
130-
async function nodeExternals(options: ExternalsOptions = {}): Promise<Plugin> {
130+
function nodeExternals(options: ExternalsOptions = {}): Plugin {
131131

132132
const config: Config = { ...defaults, ...options }
133133

@@ -138,7 +138,12 @@ async function nodeExternals(options: ExternalsOptions = {}): Promise<Plugin> {
138138
isExcluded = (id: string) => exclude.length > 0 && exclude.some(rx => rx.test(id))
139139

140140
// Determine the root of the git repository, if any.
141-
const gitRepository = await new Promise<string | null>(resolve => {
141+
//
142+
// Note: it looks like Vite doesn't support async plugin factories
143+
// (see https://github.com/Septh/rollup-plugin-node-externals/issues/37
144+
// and https://github.com/vitejs/vite/issues/20717), so we don't await
145+
// the result here but rather inside the buildStart hook.
146+
const gitTopLevel = new Promise<string | null>(resolve => {
142147
cp.execFile('git', [ 'rev-parse', '--show-toplevel' ], (error, stdout) => {
143148
return resolve(error ? null : path.normalize(stdout.trim()))
144149
})
@@ -184,7 +189,7 @@ async function nodeExternals(options: ExternalsOptions = {}): Promise<Plugin> {
184189
packagePaths.push(name)
185190

186191
// Break early if we are at the root of a git repo.
187-
if (current === gitRepository)
192+
if (current === await gitTopLevel)
188193
break
189194

190195
// Break early is there is a known workspace root file.

0 commit comments

Comments
 (0)