Skip to content

Commit 4ef8a2a

Browse files
authored
Merge branch 'master' into fs-promises-part-2
2 parents 9aae18f + 4611705 commit 4ef8a2a

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

cli/run/getConfigPath.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { readdirSync } from 'fs';
1+
import { promises as fs } from 'fs';
22
import { resolve } from 'path';
33
import { cwd } from 'process';
44
import { handleError } from '../logging';
55

66
const DEFAULT_CONFIG_BASE = 'rollup.config';
77

8-
export function getConfigPath(commandConfig: string | true): string {
8+
export async function getConfigPath(commandConfig: string | true): Promise<string> {
99
if (commandConfig === true) {
10-
return resolve(findConfigFileNameInCwd());
10+
return resolve(await findConfigFileNameInCwd());
1111
}
1212
if (commandConfig.slice(0, 5) === 'node:') {
1313
const pkgName = commandConfig.slice(5);
@@ -30,8 +30,8 @@ export function getConfigPath(commandConfig: string | true): string {
3030
return resolve(commandConfig);
3131
}
3232

33-
function findConfigFileNameInCwd(): string {
34-
const filesInWorkingDir = new Set(readdirSync(cwd()));
33+
async function findConfigFileNameInCwd(): Promise<string> {
34+
const filesInWorkingDir = new Set(await fs.readdir(cwd()));
3535
for (const extension of ['mjs', 'cjs', 'ts']) {
3636
const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
3737
if (filesInWorkingDir.has(fileName)) return fileName;

cli/run/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function getConfigs(
8989
command: any
9090
): Promise<{ options: MergedRollupOptions[]; warnings: BatchWarnings }> {
9191
if (command.config) {
92-
const configFile = getConfigPath(command.config);
92+
const configFile = await getConfigPath(command.config);
9393
const { options, warnings } = await loadAndParseConfigFile(configFile, command);
9494
return { options, warnings };
9595
}

cli/run/loadConfigFile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { realpathSync } from 'fs';
1+
import { promises as fs } from 'fs';
22
import { extname, isAbsolute } from 'path';
33
import { pathToFileURL } from 'url';
44
import * as rollup from '../../src/node-entry';
@@ -57,7 +57,7 @@ async function loadConfigFile(
5757
return getConfigList(configFileExport, commandOptions);
5858
}
5959

60-
function getDefaultFromCjs(namespace: GenericConfigObject) {
60+
function getDefaultFromCjs(namespace: GenericConfigObject): unknown {
6161
return namespace.__esModule ? namespace.default : namespace;
6262
}
6363

@@ -103,7 +103,7 @@ async function getDefaultFromTranspiledConfigFile(
103103
}
104104

105105
async function loadConfigFromBundledFile(fileName: string, bundledCode: string): Promise<unknown> {
106-
const resolvedFileName = realpathSync(fileName);
106+
const resolvedFileName = await fs.realpath(fileName);
107107
const extension = extname(resolvedFileName);
108108
const defaultLoader = require.extensions[extension];
109109
require.extensions[extension] = (module: NodeModule, requiredFileName: string) => {

cli/run/watch-cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type FSWatcher, readFileSync } from 'fs';
1+
import { promises as fs, type FSWatcher } from 'fs';
22
import process from 'process';
33
import chokidar from 'chokidar';
44
import dateTime from 'date-time';
@@ -23,7 +23,7 @@ export async function watch(command: Record<string, any>): Promise<void> {
2323
let watcher: RollupWatcher;
2424
let configWatcher: FSWatcher;
2525
let resetScreen: (heading: string) => void;
26-
const configFile = command.config ? getConfigPath(command.config) : null;
26+
const configFile = command.config ? await getConfigPath(command.config) : null;
2727

2828
onExit(close);
2929
process.on('uncaughtException', close);
@@ -41,7 +41,7 @@ export async function watch(command: Record<string, any>): Promise<void> {
4141

4242
async function reloadConfigFile() {
4343
try {
44-
const newConfigFileData = readFileSync(configFile, 'utf-8');
44+
const newConfigFileData = await fs.readFile(configFile, 'utf8');
4545
if (newConfigFileData === configFileData) {
4646
return;
4747
}

0 commit comments

Comments
 (0)