Skip to content

Commit 8c217dc

Browse files
committed
Added better handling for the case when patch is for older version of the NPM package and the file/folder for a given chunk does not exist any more.
1 parent d276c9a commit 8c217dc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,15 @@ function loadFile(info, callback)
373373
}
374374
*/
375375
const oldName = path.join(curDir, 'node_modules', pathNormalize(info.index));
376-
if(!fs.existsSync(oldName)) fs.writeFileSync(oldName, '');
377-
// read the original file
378-
fs.readFile(oldName, 'utf8', callback);
376+
if(fs.existsSync(oldName))
377+
{
378+
// read the original file
379+
fs.readFile(oldName, 'utf8', callback);
380+
}
381+
else
382+
{
383+
callback(null, ''); // old file does not exist - i.e. it is empty
384+
}
379385
}
380386

381387
function pathNormalize(pathName)
@@ -440,6 +446,16 @@ function waitForResults()
440446
else
441447
{
442448
chunk.success = false;
449+
const oldName = path.join(curDir, 'node_modules', pathNormalize(chunk.chunkInfo.index));
450+
if(!fs.existsSync(oldName))
451+
{
452+
const folder = path.dirname(oldName);
453+
if (!fs.existsSync(folder))
454+
{
455+
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');
456+
return;
457+
}
458+
}
443459
echo(startColor('yellowBright') + 'WARNING: ' + stopColor() + 'Chunk failed - ' + startColor('redBright') + ' either already applied or for different version' + stopColor());
444460
}
445461
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "custompatch",
3-
"version": "1.0.26",
3+
"version": "1.0.27",
44
"description": "Tool for patching buggy NPM packages instead of forking them",
55
"author": "IVO GELOV",
66
"private": false,

0 commit comments

Comments
 (0)