Skip to content

Commit

Permalink
path separator fix for HomeAssistant
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbutenaers committed Oct 25, 2022
1 parent d85f5b6 commit 8122816
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 8 additions & 3 deletions blockly.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
"blockly-contrib/npm/blockly/msg/en.js", // Fills the Blockly.Msg with english translations
"blockly-contrib/npm/blockly/blocks_compressed.js",
"blockly-contrib/npm/blockly/javascript_compressed.js",
"blockly-contrib/npm/@blockly%2Fplugin-workspace-search/dist/index.js",
"blockly-contrib/npm/@blockly%2Fzoom-to-fit/dist/index.js",
"blockly-contrib/npm/@blockly%2Fworkspace-backpack/dist/index.js"
// When the npm package name contains a path separator (e.g. @blockly/plugin-workspace-search) then the frontend will
// need to replace that separator by the string "___SEPARATOR___". Otherwise the NGinx webserver installed together
// with HomeAssistant will cause the Express.js routes to be messed up.
// See https://github.com/bartbutenaers/node-red-contrib-blockly/issues/101
"blockly-contrib/npm/@blockly___SEPARATOR___plugin-workspace-search/dist/index.js",
"blockly-contrib/npm/@blockly___SEPARATOR___zoom-to-fit/dist/index.js",
"blockly-contrib/npm/@blockly___SEPARATOR___workspace-backpack/dist/index.js",
"blockly-contrib/npm/@blockly___SEPARATOR___workspace-backpack/dist/index.js"
]
});

Expand Down
6 changes: 6 additions & 0 deletions blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ module.exports = function(RED) {
// Make all the static NPM modules resources from this node public available
RED.httpAdmin.get('/blockly-contrib/npm/:package/*', function(req, res) {
var requestedFilePath;

// When the npm package name contains a path separator (e.g. @blockly/plugin-workspace-search) then the frontend will
// have replaced that separator by the string "___SEPARATOR___". So we need to replace "___SEPARATOR___" here again by
// the path separator (which depends on the OS this node is running on).
// See https://github.com/bartbutenaers/node-red-contrib-blockly/issues/101
req.params.package = req.params.package.replace("___SEPARATOR___", path.sep);

// Try to get the npm package path from the cache
var npmPackagePath = blocklyNpmPaths.get(req.params.package);
Expand Down
8 changes: 5 additions & 3 deletions blockly_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
name: "Date/time",
files: [
// Inside this category we use a datepicker plugin, which is available as a separate NPM package.
// Note that this NPM package name (blockly/field-date) contains a slash, which needs to be replaced
// by %2f (which represents a slash character inside the NPM package name element of the url).
"blockly-contrib/npm/@blockly%2Ffield-date/dist/date_compressed.js",
// When the npm package name contains a path separator (e.g. @blockly/field-date) then the frontend will
// need to replace that separator by the string "___SEPARATOR___". Otherwise the NGinx webserver installed together
// with HomeAssistant will cause the Express.js routes to be messed up.
// See https://github.com/bartbutenaers/node-red-contrib-blockly/issues/101
"blockly-contrib/npm/@blockly___SEPARATOR___field-date/dist/date_compressed.js",
"blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/dateTimeBlocksCodeGen.js",
"blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/dateTimeBlocksDefs.js",
"blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/toolbox.xml",
Expand Down

0 comments on commit 8122816

Please sign in to comment.