Skip to content

Commit

Permalink
Merge branch 'master' into gh-4490-dynamic-imports-shared-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 19, 2022
2 parents 2ad6f67 + 0537d93 commit de2d2dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
5 changes: 2 additions & 3 deletions 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';
Expand Down Expand Up @@ -103,8 +102,8 @@ async function getDefaultFromTranspiledConfigFile(
return loadConfigFromBundledFile(fileName, code);
}

async function loadConfigFromBundledFile(fileName: string, bundledCode: string): Promise<unknown> {
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) => {
Expand Down
12 changes: 10 additions & 2 deletions src/utils/hookActions.ts
@@ -1,3 +1,4 @@
import { EventEmitter } from 'events';
import process from 'process';
import { HookAction, PluginDriver } from './PluginDriver';

Expand All @@ -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<T>(
pluginDriver: PluginDriver,
callback: () => Promise<T>
Expand All @@ -34,10 +42,10 @@ export async function catchUnfinishedHookActions<T>(
)
);
};
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;
}
11 changes: 11 additions & 0 deletions 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
};
1 change: 1 addition & 0 deletions test/cli/samples/config-cwd-case-insensitive-es6/main.js
@@ -0,0 +1 @@
assert.equal( ANSWER, 42 );
@@ -0,0 +1,9 @@
import replace from '@rollup/plugin-replace';

export default {
input: 'main.js',
output: {
format: 'cjs'
},
plugins: [replace({ preventAssignment: true, ANSWER: 42 })]
};

0 comments on commit de2d2dc

Please sign in to comment.