-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headless xml -> Javascript in Node.js: Many Problems #2603
Comments
One thing I tried was this:
So I'm defining DOMParser, Element and document in the Blockly namespace. Wherever Element is used I changed it with Blockly.Element. The same with DOMParser. These only appear once so thats easy. document appears a lot of times so I didn't do it. It seems to me that in the headless case the use of document should just be avoided. |
The solution above only works for node.js. To make it work for the browser Any idea where would be a good place to do this? |
Hi Karel, Just a quick note to say that we are actively working on this. One PR that is in flight is #2606 which removes some 50 document.createElement calls. I'm told that @alschmiedt has also made some changes over the past couple of days that help too. The Blockly team will be out for the next few days due to a holiday that's being celebrated over here in the colonies, but we'll be back on Monday. |
@NeilFraser I made a fix myself that might be interesting for you guys to look it basically implements the solution I proposed above. https://github.com/kbruneel/blockly I can make a pull request if you want it. |
Error 2 should be fixed by #2605 |
@kbruneel If you've got the time feel free to make a PR. This is something we'd need to find some time to look at more closely before merging (in other words, it may be a while before we reviewed it), but having a PR up will at least give us something to point folks at as an example. |
We also already have a tracking bug for getting Node working in #2082 |
Problem statement
I'm trying to translate Blockly xml into javascript using Node.js and running into many problems. I made a very small test that shows these problems: https://github.com/kbruneel/blockly-test
Each of the problems has its own tag: https://github.com/kbruneel/blockly-test/tags
Element is not defined in the node.js environment.
This is easy to solve by just calling Blockly.setTheme(), but it seems to me that in the headless case this should not be required.
document is not defined in the node.js environment.
As you can see I managed to hack a solution for each of the problems, but these are not good solutions, e.g. The solution uses global variables and in that way mess up my test suite.
I tried changing Blockly myself, but I'm not familiar with Closure and also quickly ran into more problems when trying to use the uncompressed version in the gulp build process for blockly_node_javascript_en.js.
I'm willing to help out with these problems, but I will need some help.
Expected Behavior
It should translate the xml to javascript.
Actual Behavior
It errors.
Steps to Reproduce
git clone https://github.com/kbruneel/blockly-test.git
git checkout tags/1_element_is_not_defined
npm i
node test.js
git checkout tags/2_need_to_use_Blockly_setTheme
npm i
node test.js
git checkout tags/3_document_is_not_defined
npm i
node test.js
git checkout tags/4_now_it_works
npm i
node test.js
Stack Traces
Operating System and Browser
Additional Information
The text was updated successfully, but these errors were encountered: