Skip to content

Commit

Permalink
fix postinstall (#4359)
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Jul 12, 2023
1 parent 415c4aa commit b81a0f2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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);
});
});
}
Expand Down

0 comments on commit b81a0f2

Please sign in to comment.