Skip to content

Commit

Permalink
Merge branch 'fix-windows-enoent'
Browse files Browse the repository at this point in the history
  • Loading branch information
bencergazda committed Nov 29, 2021
2 parents be1f3bf + 106af5a commit ddf84b1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 47 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"cosmiconfig": "^7.0.0",
"exec-sh": "^0.4.0",
"find-cache-dir": "^3.3.1",
"fs-extra": "^10.0.0",
"lodash": "^4.17.21",
"npm-packlist": "^3.0.0",
"pify": "^5.0.0",
Expand Down
27 changes: 3 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/dependency.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const path = require('path');
const packlist = require('npm-packlist');
const tar = require('tar');
Expand All @@ -8,12 +9,12 @@ const { validate_path, promisified, default_ignore_rules, definitely_posix } = r
/**
*
* @param relative_package_path {string}
* @returns {Promise<{package_json_path: string, package_path: string, package_json_filename: string, package_json_content: *}>}
* @returns {{package_json_path: string, package_path: string, package_json_filename: string, package_json_content: *}}
*/
async function get_package_details(relative_package_path) {
function get_package_details(relative_package_path) {
const package_path = path.resolve(relative_package_path);

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

Expand Down Expand Up @@ -42,11 +43,11 @@ async function get_ignore_file_rules(relative_package_path) {

try {
// try to read .npmignore
ignorefile = await promisified.fs.readFile(npmignorePath, 'utf-8');
ignorefile = await fs.promises.readFile(npmignorePath, 'utf-8');
} catch (e) {
// .npmignore not found, try to read .gitignore
try {
ignorefile = await promisified.fs.readFile(gitignorePath, 'utf-8');
ignorefile = await fs.promises.readFile(gitignorePath, 'utf-8');
} catch (e) {
// No ignore file found
return [];
Expand Down Expand Up @@ -133,7 +134,7 @@ async function create_tarball({ name: local_dependency_name, version: local_depe
throw new Error(`Could not pack module '${local_dependency_path}'`);
}

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

Expand Down Expand Up @@ -179,7 +180,7 @@ async function install_tarball(tarball_name, { temp_path, cwd, manager = 'pnpm'
async function delete_tarball(tarball_name, { temp_path }) {
// console.log('delete_tarball', tarball_name);
const tarball_path = path.resolve(temp_path, tarball_name);
await promisified.fs.unlink(tarball_path);
await fs.promises.unlink(tarball_path);
}

module.exports = {
Expand Down
18 changes: 6 additions & 12 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
const pify = require('pify');
const rimraf = require('rimraf');

const promisified = {
fs: {
...pify(fs),
exists: pify(fs.exists, { errorFirst: false }),
},
fse: pify(fse),
rimraf: pify(rimraf),
};

Expand Down Expand Up @@ -98,8 +92,8 @@ function color_log(msg, color) {
* @param path {string}
*/
async function validate_path(path) {
if (!await promisified.fs.exists(path)) {
await promisified.fs.mkdir(path, { recursive: true });
if (!fs.existsSync(path)) {
await fs.promises.mkdir(path, { recursive: true });
}
}

Expand All @@ -110,7 +104,7 @@ async function validate_path(path) {
*/
async function get_file_stats(file_path) {
try {
return await promisified.fse.lstat(file_path);
return await fs.promises.lstat(file_path);
} catch (e) {
return null;
}
Expand Down Expand Up @@ -138,12 +132,12 @@ async function copy_file_or_directory(source_path, destination_path) {
const is_directory = stats.isDirectory();

if (is_directory) {
return promisified.fs.mkdir(destination_path);
return fs.promises.mkdir(destination_path);
}

// console.log('COPY', source_path, 'to', destination_path);

return promisified.fse.copy(source_path, destination_path);
return fs.promises.copyFile(source_path, destination_path);
}

/**
Expand All @@ -152,7 +146,7 @@ async function copy_file_or_directory(source_path, destination_path) {
* @returns {Promise<null|*>}
*/
async function detect_newline_at_eof(path) {
const fileContents = await promisified.fs.readFile(path, 'utf-8');
const fileContents = await fs.promises.readFile(path, 'utf-8');

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

Expand Down
7 changes: 4 additions & 3 deletions src/project.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const path = require('path');
const chokidar = require('chokidar');
const execSh = require('exec-sh').promise;
Expand Down Expand Up @@ -37,7 +38,7 @@ async function save_package_json(content, { cwd }) {

const newline_char = await detect_newline_at_eof(package_json_path);

promisified.fs.writeFile(package_json_path, JSON.stringify(content, null, 2) + newline_char);
await fs.promises.writeFile(package_json_path, JSON.stringify(content, null, 2) + newline_char);
}

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

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

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

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

Expand Down

0 comments on commit ddf84b1

Please sign in to comment.