Skip to content

Commit 106af5a

Browse files
committed
chore: Drop promisified.fs, use fs.promises everywhere in the codebase
1 parent 0236b25 commit 106af5a

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/dependency.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs');
12
const path = require('path');
23
const packlist = require('npm-packlist');
34
const tar = require('tar');
@@ -8,12 +9,12 @@ const { validate_path, promisified, default_ignore_rules, definitely_posix } = r
89
/**
910
*
1011
* @param relative_package_path {string}
11-
* @returns {Promise<{package_json_path: string, package_path: string, package_json_filename: string, package_json_content: *}>}
12+
* @returns {{package_json_path: string, package_path: string, package_json_filename: string, package_json_content: *}}
1213
*/
13-
async function get_package_details(relative_package_path) {
14+
function get_package_details(relative_package_path) {
1415
const package_path = path.resolve(relative_package_path);
1516

16-
if (!await promisified.fs.exists(package_path)) {
17+
if (!fs.existsSync(package_path)) {
1718
throw new Error(`Module '${relative_package_path}' was not found in '${path.resolve()}'.`);
1819
}
1920

@@ -42,11 +43,11 @@ async function get_ignore_file_rules(relative_package_path) {
4243

4344
try {
4445
// try to read .npmignore
45-
ignorefile = await promisified.fs.readFile(npmignorePath, 'utf-8');
46+
ignorefile = await fs.promises.readFile(npmignorePath, 'utf-8');
4647
} catch (e) {
4748
// .npmignore not found, try to read .gitignore
4849
try {
49-
ignorefile = await promisified.fs.readFile(gitignorePath, 'utf-8');
50+
ignorefile = await fs.promises.readFile(gitignorePath, 'utf-8');
5051
} catch (e) {
5152
// No ignore file found
5253
return [];
@@ -133,7 +134,7 @@ async function create_tarball({ name: local_dependency_name, version: local_depe
133134
throw new Error(`Could not pack module '${local_dependency_path}'`);
134135
}
135136

136-
if (!await promisified.fs.exists(tarball_path)) {
137+
if (!fs.existsSync(tarball_path)) {
137138
throw new Error(`Could not locate the created tarball '${tarball_name}' in '${temp_path}'.`);
138139
}
139140

@@ -179,7 +180,7 @@ async function install_tarball(tarball_name, { temp_path, cwd, manager = 'pnpm'
179180
async function delete_tarball(tarball_name, { temp_path }) {
180181
// console.log('delete_tarball', tarball_name);
181182
const tarball_path = path.resolve(temp_path, tarball_name);
182-
await promisified.fs.unlink(tarball_path);
183+
await fs.promises.unlink(tarball_path);
183184
}
184185

185186
module.exports = {

src/helpers.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ const pify = require('pify');
44
const rimraf = require('rimraf');
55

66
const promisified = {
7-
fs: {
8-
...pify(fs),
9-
exists: pify(fs.exists, { errorFirst: false }),
10-
},
117
rimraf: pify(rimraf),
128
};
139

@@ -96,8 +92,8 @@ function color_log(msg, color) {
9692
* @param path {string}
9793
*/
9894
async function validate_path(path) {
99-
if (!await promisified.fs.exists(path)) {
100-
await promisified.fs.mkdir(path, { recursive: true });
95+
if (!fs.existsSync(path)) {
96+
await fs.promises.mkdir(path, { recursive: true });
10197
}
10298
}
10399

@@ -136,7 +132,7 @@ async function copy_file_or_directory(source_path, destination_path) {
136132
const is_directory = stats.isDirectory();
137133

138134
if (is_directory) {
139-
return promisified.fs.mkdir(destination_path);
135+
return fs.promises.mkdir(destination_path);
140136
}
141137

142138
// console.log('COPY', source_path, 'to', destination_path);
@@ -150,7 +146,7 @@ async function copy_file_or_directory(source_path, destination_path) {
150146
* @returns {Promise<null|*>}
151147
*/
152148
async function detect_newline_at_eof(path) {
153-
const fileContents = await promisified.fs.readFile(path, 'utf-8');
149+
const fileContents = await fs.promises.readFile(path, 'utf-8');
154150

155151
const matches = fileContents.match(/\r?\n$/);
156152

src/project.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs');
12
const path = require('path');
23
const chokidar = require('chokidar');
34
const execSh = require('exec-sh').promise;
@@ -37,7 +38,7 @@ async function save_package_json(content, { cwd }) {
3738

3839
const newline_char = await detect_newline_at_eof(package_json_path);
3940

40-
promisified.fs.writeFile(package_json_path, JSON.stringify(content, null, 2) + newline_char);
41+
await fs.promises.writeFile(package_json_path, JSON.stringify(content, null, 2) + newline_char);
4142
}
4243

4344
/**
@@ -148,7 +149,7 @@ async function collect_dependencies_files(packed_dependencies, { cwd, modules_pa
148149
throw new Error('No data received to install the dependencies.');
149150
}
150151

151-
if (!await promisified.fs.exists(modules_path)) {
152+
if (!fs.existsSync(modules_path)) {
152153
throw new Error(`Could not find the modules directory. Tried: '${modules_path}'`);
153154
}
154155

@@ -157,7 +158,7 @@ async function collect_dependencies_files(packed_dependencies, { cwd, modules_pa
157158
const local_package_path = definitely_posix(path.resolve(cwd, local_dependency_path)); // source
158159
const installed_package_path = definitely_posix(path.resolve(modules_path, local_dependency_name)); // target
159160

160-
if (!await promisified.fs.exists(installed_package_path)) {
161+
if (!fs.existsSync(installed_package_path)) {
161162
throw new Error(`Could not find the installed package '${local_dependency_name}' in '${installed_package_path}'`);
162163
}
163164

0 commit comments

Comments
 (0)