From bf1ff32b3c963baf1f81f92b1cc089c26e73b29c Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 19 May 2022 07:38:16 +0300 Subject: [PATCH 1/2] fix: config path problem on windows (#4501) * add test * fix --- cli/run/loadConfigFile.ts | 5 ++--- .../config-cwd-case-insensitive-es6/_config.js | 11 +++++++++++ .../samples/config-cwd-case-insensitive-es6/main.js | 1 + .../config-cwd-case-insensitive-es6/rollup.config.js | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/cli/samples/config-cwd-case-insensitive-es6/_config.js create mode 100644 test/cli/samples/config-cwd-case-insensitive-es6/main.js create mode 100644 test/cli/samples/config-cwd-case-insensitive-es6/rollup.config.js diff --git a/cli/run/loadConfigFile.ts b/cli/run/loadConfigFile.ts index 946d2d4752b..1d407162e7a 100644 --- a/cli/run/loadConfigFile.ts +++ b/cli/run/loadConfigFile.ts @@ -1,4 +1,3 @@ -import { promises as fs } from 'fs'; import { extname, isAbsolute } from 'path'; import { version } from 'process'; import { pathToFileURL } from 'url'; @@ -103,8 +102,8 @@ async function getDefaultFromTranspiledConfigFile( return loadConfigFromBundledFile(fileName, code); } -async function loadConfigFromBundledFile(fileName: string, bundledCode: string): Promise { - const resolvedFileName = await fs.realpath(fileName); +function loadConfigFromBundledFile(fileName: string, bundledCode: string): unknown { + const resolvedFileName = require.resolve(fileName); const extension = extname(resolvedFileName); const defaultLoader = require.extensions[extension]; require.extensions[extension] = (module: NodeModule, requiredFileName: string) => { diff --git a/test/cli/samples/config-cwd-case-insensitive-es6/_config.js b/test/cli/samples/config-cwd-case-insensitive-es6/_config.js new file mode 100644 index 00000000000..8fc7b6c5aa9 --- /dev/null +++ b/test/cli/samples/config-cwd-case-insensitive-es6/_config.js @@ -0,0 +1,11 @@ +function toggleCase(s) { + return s == s.toLowerCase() ? s.toUpperCase() : s.toLowerCase(); +} + +module.exports = { + onlyWindows: true, + description: "can load ES6 config with cwd that doesn't match realpath", + command: 'rollup -c', + cwd: __dirname.replace(/^[A-Z]:\\/i, toggleCase), + execute: true +}; diff --git a/test/cli/samples/config-cwd-case-insensitive-es6/main.js b/test/cli/samples/config-cwd-case-insensitive-es6/main.js new file mode 100644 index 00000000000..df16c1b06b9 --- /dev/null +++ b/test/cli/samples/config-cwd-case-insensitive-es6/main.js @@ -0,0 +1 @@ +assert.equal( ANSWER, 42 ); diff --git a/test/cli/samples/config-cwd-case-insensitive-es6/rollup.config.js b/test/cli/samples/config-cwd-case-insensitive-es6/rollup.config.js new file mode 100644 index 00000000000..dee04a33fb1 --- /dev/null +++ b/test/cli/samples/config-cwd-case-insensitive-es6/rollup.config.js @@ -0,0 +1,9 @@ +import replace from '@rollup/plugin-replace'; + +export default { + input: 'main.js', + output: { + format: 'cjs' + }, + plugins: [replace({ preventAssignment: true, ANSWER: 42 })] +}; From 0537d932c38d9e441c38812c89869a385789bf90 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 19 May 2022 06:45:01 +0200 Subject: [PATCH 2/2] Avoid maximum listeners exceeded warning (#4502) --- src/utils/hookActions.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/hookActions.ts b/src/utils/hookActions.ts index 69269bbb27f..01608209f55 100644 --- a/src/utils/hookActions.ts +++ b/src/utils/hookActions.ts @@ -1,3 +1,4 @@ +import { EventEmitter } from 'events'; import process from 'process'; import { HookAction, PluginDriver } from './PluginDriver'; @@ -19,6 +20,13 @@ function formatAction([pluginName, hookName, args]: HookAction): string { return action; } +// We do not directly listen on process to avoid max listeners warnings for +// complicated build processes +const beforeExitEvent = 'beforeExit'; +const beforeExitEmitter = new EventEmitter(); +beforeExitEmitter.setMaxListeners(0); +process.on(beforeExitEvent, () => beforeExitEmitter.emit(beforeExitEvent)); + export async function catchUnfinishedHookActions( pluginDriver: PluginDriver, callback: () => Promise @@ -34,10 +42,10 @@ export async function catchUnfinishedHookActions( ) ); }; - process.once('beforeExit', handleEmptyEventLoop); + beforeExitEmitter.once(beforeExitEvent, handleEmptyEventLoop); }); const result = await Promise.race([callback(), emptyEventLoopPromise]); - process.off('beforeExit', handleEmptyEventLoop!); + beforeExitEmitter.off(beforeExitEvent, handleEmptyEventLoop!); return result; }