Skip to content

Commit e0fc6ce

Browse files
authored
copy over blockly 12 overrides and patch script from pxt-core (#6166)
1 parent 7e5221d commit e0fc6ce

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,19 @@
4747
"dependencies": {
4848
"pxt-common-packages": "12.3.29",
4949
"pxt-core": "11.4.16"
50+
},
51+
"overrides": {
52+
"@blockly/field-colour": {
53+
"blockly": "^12.0.0-beta.4"
54+
},
55+
"@blockly/plugin-workspace-search": {
56+
"blockly": "^12.0.0-beta.4"
57+
},
58+
"@blockly/keyboard-navigation": {
59+
"blockly": "^12.0.0-beta.4"
60+
}
61+
},
62+
"scripts": {
63+
"postinstall": "node ./scripts/patchBlocklyFieldColour.js"
5064
}
51-
}
65+
}

scripts/patchBlocklyFieldColour.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This script patches Blockly's FieldColour plugin which has a typing
2+
// error with the Blockly 12 beta. Presumably this plugin will receive
3+
// an update when Blockly 12 is officially released and at that time
4+
// this script can be removed.
5+
6+
const fs = require("fs");
7+
const path = require("path");
8+
9+
if (!fs.existsSync(path.resolve("./node_modules/@blockly/field-colour/package.json"))) {
10+
return;
11+
}
12+
13+
const packageJson = JSON.parse(fs.readFileSync(path.resolve("./node_modules/@blockly/field-colour/package.json"), "utf8"));
14+
15+
if (packageJson.version !== "5.0.12") {
16+
throw new Error("patchBlocklyFieldColour was written for @blockly/field-colour version 5.0.12. If the version has been updated, update or remove this script!");
17+
}
18+
19+
20+
function patchFile(filepath) {
21+
const contents = fs.readFileSync(filepath, "utf8");
22+
23+
const patched = contents.replace(
24+
"protected isFullBlockField(): boolean",
25+
"public isFullBlockField(): boolean"
26+
);
27+
28+
fs.writeFileSync(filepath, patched, "utf8");
29+
}
30+
31+
patchFile(path.resolve(__dirname, "..", "./node_modules/@blockly/field-colour/dist/field_colour.d.ts"));
32+
patchFile(path.resolve(__dirname, "..", "./node_modules/@blockly/field-colour/src/field_colour.ts"));
33+
34+
console.log("Patched @blockly/field-colour")

0 commit comments

Comments
 (0)