Skip to content

Commit b81a0f2

Browse files
authored
fix postinstall (#4359)
1 parent 415c4aa commit b81a0f2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/postinstall.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const THREE_REGEX = /three@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/gm;
33
let NEW_THREE_VERSION;
44
const THREE_PACKAGE_REGEX = /"three": ".*"/g;
55
fs.readFile('package.json', {encoding: 'utf8'}, (err, data) => {
6-
NEW_THREE_VERSION = `three@${THREE_PACKAGE_REGEX.exec(data)[0].split(' ')[1].replaceAll('"', '')}`;
6+
NEW_THREE_VERSION = `three@${
7+
THREE_PACKAGE_REGEX.exec(data)[0].split(' ')[1].replaceAll('"', '')}`;
78
console.log(NEW_THREE_VERSION);
89
});
910

@@ -14,9 +15,15 @@ function updateThreeVersion(filePath) {
1415
return;
1516
}
1617
const OLD_THREE_VERSION = THREE_REGEX.exec(data)[0];
18+
if (!OLD_THREE_VERSION || !NEW_THREE_VERSION) {
19+
console.error(
20+
'Tried to replace ', OLD_THREE_VERSION, ' with ', NEW_THREE_VERSION);
21+
return;
22+
}
1723
data = data.replaceAll(OLD_THREE_VERSION, NEW_THREE_VERSION);
1824
fs.writeFile(filePath, data, {encoding: 'utf8'}, (err) => {
19-
if (err) console.log(err);
25+
if (err)
26+
console.log(err);
2027
});
2128
});
2229
}

0 commit comments

Comments
 (0)