Skip to content

Commit bf1ff32

Browse files
authored
fix: config path problem on windows (#4501)
* add test * fix
1 parent 931a199 commit bf1ff32

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

cli/run/loadConfigFile.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { promises as fs } from 'fs';
21
import { extname, isAbsolute } from 'path';
32
import { version } from 'process';
43
import { pathToFileURL } from 'url';
@@ -103,8 +102,8 @@ async function getDefaultFromTranspiledConfigFile(
103102
return loadConfigFromBundledFile(fileName, code);
104103
}
105104

106-
async function loadConfigFromBundledFile(fileName: string, bundledCode: string): Promise<unknown> {
107-
const resolvedFileName = await fs.realpath(fileName);
105+
function loadConfigFromBundledFile(fileName: string, bundledCode: string): unknown {
106+
const resolvedFileName = require.resolve(fileName);
108107
const extension = extname(resolvedFileName);
109108
const defaultLoader = require.extensions[extension];
110109
require.extensions[extension] = (module: NodeModule, requiredFileName: string) => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function toggleCase(s) {
2+
return s == s.toLowerCase() ? s.toUpperCase() : s.toLowerCase();
3+
}
4+
5+
module.exports = {
6+
onlyWindows: true,
7+
description: "can load ES6 config with cwd that doesn't match realpath",
8+
command: 'rollup -c',
9+
cwd: __dirname.replace(/^[A-Z]:\\/i, toggleCase),
10+
execute: true
11+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert.equal( ANSWER, 42 );
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import replace from '@rollup/plugin-replace';
2+
3+
export default {
4+
input: 'main.js',
5+
output: {
6+
format: 'cjs'
7+
},
8+
plugins: [replace({ preventAssignment: true, ANSWER: 42 })]
9+
};

0 commit comments

Comments
 (0)