From 2ed1e1889fea8c3732dea3619c6a9b41427484e0 Mon Sep 17 00:00:00 2001 From: Emmett Lalish Date: Tue, 11 Jul 2023 17:10:09 -0700 Subject: [PATCH] fix postinstall --- scripts/postinstall.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 1504dea66c..036b4df38b 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -3,7 +3,8 @@ const THREE_REGEX = /three@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/gm; let NEW_THREE_VERSION; const THREE_PACKAGE_REGEX = /"three": ".*"/g; fs.readFile('package.json', {encoding: 'utf8'}, (err, data) => { - NEW_THREE_VERSION = `three@${THREE_PACKAGE_REGEX.exec(data)[0].split(' ')[1].replaceAll('"', '')}`; + NEW_THREE_VERSION = `three@${ + THREE_PACKAGE_REGEX.exec(data)[0].split(' ')[1].replaceAll('"', '')}`; console.log(NEW_THREE_VERSION); }); @@ -14,9 +15,15 @@ function updateThreeVersion(filePath) { return; } const OLD_THREE_VERSION = THREE_REGEX.exec(data)[0]; + if (!OLD_THREE_VERSION || !NEW_THREE_VERSION) { + console.error( + 'Tried to replace ', OLD_THREE_VERSION, ' with ', NEW_THREE_VERSION); + return; + } data = data.replaceAll(OLD_THREE_VERSION, NEW_THREE_VERSION); fs.writeFile(filePath, data, {encoding: 'utf8'}, (err) => { - if (err) console.log(err); + if (err) + console.log(err); }); }); }