Skip to content

Commit

Permalink
Use async readFile in getRollupDefaultPlugin (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaksmet authored and lukastaegert committed Jul 2, 2019
1 parent 20b434d commit b02296a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion browser/fs.ts
Expand Up @@ -4,6 +4,6 @@ const nope = (method: string) => (..._args: any[]): any => {

export const lstatSync = nope('lstatSync');
export const readdirSync = nope('readdirSync');
export const readFileSync = nope('readFileSync');
export const readFile = nope('readFile');
export const realpathSync = nope('realpathSync');
export const writeFile = nope('writeFile');
4 changes: 2 additions & 2 deletions src/utils/defaultPlugin.ts
@@ -1,14 +1,14 @@
import { Plugin, ResolveIdHook } from '../rollup/types';
import { error } from './error';
import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs';
import { lstatSync, readdirSync, readFile, realpathSync } from './fs';
import { basename, dirname, isAbsolute, resolve } from './path';

export function getRollupDefaultPlugin(preserveSymlinks: boolean): Plugin {
return {
name: 'Rollup Core',
resolveId: createResolveId(preserveSymlinks) as ResolveIdHook,
load(id) {
return readFileSync(id, 'utf-8');
return readFile(id);
},
resolveFileUrl({ relativePath, format }) {
return relativeUrlMechanisms[format](relativePath);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/fs.ts
Expand Up @@ -3,6 +3,11 @@ import { dirname } from './path';

export * from 'fs';

export const readFile = (file: string) =>
new Promise<string>((fulfil, reject) =>
fs.readFile(file, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents)))
);

function mkdirpath(path: string) {
const dir = dirname(path);
try {
Expand Down

0 comments on commit b02296a

Please sign in to comment.