Skip to content

Commit

Permalink
Added better handling for the case when patch is for older version of…
Browse files Browse the repository at this point in the history
… the NPM package and the file/folder for a given chunk does not exist any more.
  • Loading branch information
tmcdos committed Apr 21, 2024
1 parent d276c9a commit 8c217dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,15 @@ function loadFile(info, callback)
}
*/
const oldName = path.join(curDir, 'node_modules', pathNormalize(info.index));
if(!fs.existsSync(oldName)) fs.writeFileSync(oldName, '');
// read the original file
fs.readFile(oldName, 'utf8', callback);
if(fs.existsSync(oldName))
{
// read the original file
fs.readFile(oldName, 'utf8', callback);
}
else
{
callback(null, ''); // old file does not exist - i.e. it is empty
}
}

function pathNormalize(pathName)
Expand Down Expand Up @@ -440,6 +446,16 @@ function waitForResults()
else
{
chunk.success = false;
const oldName = path.join(curDir, 'node_modules', pathNormalize(chunk.chunkInfo.index));
if(!fs.existsSync(oldName))
{
const folder = path.dirname(oldName);
if (!fs.existsSync(folder))
{
echo(startColor('yellowBright') + 'WARNING: Folder ' + stopColor() + startColor('redBright') + path.dirname(pathNormalize(chunk.chunkInfo.index)) + stopColor() + startColor('yellowBright') + ' does not exist - the patch is probably for older version');
return;
}
}
echo(startColor('yellowBright') + 'WARNING: ' + stopColor() + 'Chunk failed - ' + startColor('redBright') + ' either already applied or for different version' + stopColor());
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custompatch",
"version": "1.0.26",
"version": "1.0.27",
"description": "Tool for patching buggy NPM packages instead of forking them",
"author": "IVO GELOV",
"private": false,
Expand Down

0 comments on commit 8c217dc

Please sign in to comment.