Skip to content

Commit b02296a

Browse files
kaksmetlukastaegert
authored andcommitted
Use async readFile in getRollupDefaultPlugin (#2965)
1 parent 20b434d commit b02296a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

browser/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ const nope = (method: string) => (..._args: any[]): any => {
44

55
export const lstatSync = nope('lstatSync');
66
export const readdirSync = nope('readdirSync');
7-
export const readFileSync = nope('readFileSync');
7+
export const readFile = nope('readFile');
88
export const realpathSync = nope('realpathSync');
99
export const writeFile = nope('writeFile');

src/utils/defaultPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Plugin, ResolveIdHook } from '../rollup/types';
22
import { error } from './error';
3-
import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs';
3+
import { lstatSync, readdirSync, readFile, realpathSync } from './fs';
44
import { basename, dirname, isAbsolute, resolve } from './path';
55

66
export function getRollupDefaultPlugin(preserveSymlinks: boolean): Plugin {
77
return {
88
name: 'Rollup Core',
99
resolveId: createResolveId(preserveSymlinks) as ResolveIdHook,
1010
load(id) {
11-
return readFileSync(id, 'utf-8');
11+
return readFile(id);
1212
},
1313
resolveFileUrl({ relativePath, format }) {
1414
return relativeUrlMechanisms[format](relativePath);

src/utils/fs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { dirname } from './path';
33

44
export * from 'fs';
55

6+
export const readFile = (file: string) =>
7+
new Promise<string>((fulfil, reject) =>
8+
fs.readFile(file, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents)))
9+
);
10+
611
function mkdirpath(path: string) {
712
const dir = dirname(path);
813
try {

0 commit comments

Comments
 (0)