Skip to content

Commit 5ec1fc7

Browse files
authored
A couple small fixes for Scratch.external (TurboWarp#2297)
- generate extension-dependencies.json with URLs in alphabetical order to reduce chance of merge conflict in the future - improve error tolerance for invalid extension-dependencies.json
1 parent 045593b commit 5ec1fc7

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎development/dependency-management.js‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,34 @@ const removeDependency = (url) => {
7979
*/
8080
const loadFromManifest = async () => {
8181
const text = await fsPromises.readFile(manifestPath, "utf-8");
82-
const json = JSON.parse(text);
83-
dependencies = json.dependencies;
82+
try {
83+
const json = JSON.parse(text);
84+
if (typeof json.dependencies !== "object" || !json.dependencies) {
85+
throw new Error(`.dependencies is not an object`);
86+
}
87+
dependencies = json.dependencies;
88+
} catch (e) {
89+
console.error("Failed to read dependencies - resetting to blank slate:", e);
90+
dependencies = {};
91+
}
8492
};
8593

8694
/**
8795
* @returns {Promise<void>}
8896
*/
8997
const saveToManifest = async () => {
98+
// Save with the URLs in alphabetical order instead of the newest dependency always
99+
// being at the very end.
100+
const exportedDependencies = {};
101+
for (const key of Object.keys(dependencies).sort()) {
102+
exportedDependencies[key] = dependencies[key];
103+
}
104+
90105
await fsPromises.writeFile(
91106
manifestPath,
92107
JSON.stringify(
93108
{
94-
dependencies,
109+
dependencies: exportedDependencies,
95110
},
96111
null,
97112
2

‎extension-dependencies.json‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
"sha256": "464efd192f197f1000ab60bedde235f349b8ee2967e1443cc3a29cebf42cbce2",
55
"contentType": "application/javascript; charset=utf-8"
66
},
7-
"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.22.0/dist/tf-core.min.js": {
8-
"sha256": "0924438788ff7da57b14d0f7c45a05d81611a5a4b52653da6d065e86d348757c",
9-
"contentType": "application/javascript; charset=utf-8"
10-
},
11-
"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl@4.22.0/dist/tf-backend-webgl.min.js": {
12-
"sha256": "b41fcbb4aee7721af0cc77ecfede60b44ad4ed6d5782a8392b84f774f4359a45",
13-
"contentType": "application/javascript; charset=utf-8"
14-
},
15-
"https://cdn.jsdelivr.net/npm/@turbowarp/tensorflow-models-face-detection@1.0.3-tw1/dist/face-detection.min.js": {
16-
"sha256": "3faf18f98df4270e0a945f2ad67d5ab6f43d6e625e0b3f2c3bcfcd1e6330ab57",
17-
"contentType": "application/javascript; charset=utf-8"
18-
},
197
"https://cdn.jsdelivr.net/npm/@mediapipe/face_detection@0.4.1646425229/face_detection_short.binarypb": {
208
"sha256": "771c6b632d5ba58a41d3160abfd80185a1d18081f52bcefc5baec9f3d10aa8d9",
219
"contentType": "application/octet-stream"
@@ -31,6 +19,18 @@
3119
"https://cdn.jsdelivr.net/npm/@mediapipe/face_detection@0.4.1646425229/face_detection_solution_simd_wasm_bin.wasm": {
3220
"sha256": "ed927313be5ead0002008a7bc18177ecd342c60fd75795e4611fb44e19c4745b",
3321
"contentType": "application/wasm"
22+
},
23+
"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl@4.22.0/dist/tf-backend-webgl.min.js": {
24+
"sha256": "b41fcbb4aee7721af0cc77ecfede60b44ad4ed6d5782a8392b84f774f4359a45",
25+
"contentType": "application/javascript; charset=utf-8"
26+
},
27+
"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.22.0/dist/tf-core.min.js": {
28+
"sha256": "0924438788ff7da57b14d0f7c45a05d81611a5a4b52653da6d065e86d348757c",
29+
"contentType": "application/javascript; charset=utf-8"
30+
},
31+
"https://cdn.jsdelivr.net/npm/@turbowarp/tensorflow-models-face-detection@1.0.3-tw1/dist/face-detection.min.js": {
32+
"sha256": "3faf18f98df4270e0a945f2ad67d5ab6f43d6e625e0b3f2c3bcfcd1e6330ab57",
33+
"contentType": "application/javascript; charset=utf-8"
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)