Skip to content

Commit

Permalink
fix: config path problem on windows (#4501)
Browse files Browse the repository at this point in the history
* add test

* fix
  • Loading branch information
pos777 committed May 19, 2022
1 parent 931a199 commit bf1ff32
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 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
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 bf1ff32

Please sign in to comment.