Skip to content
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

Node.js Tracking bug #2082

Closed
1 of 3 tasks
NeilFraser opened this issue Oct 16, 2018 · 12 comments
Closed
1 of 3 tasks

Node.js Tracking bug #2082

NeilFraser opened this issue Oct 16, 2018 · 12 comments
Assignees
Labels
component: devtools help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added

Comments

@NeilFraser
Copy link
Contributor

NeilFraser commented Oct 16, 2018

Meta bug for tracking issues with running Blockly under Node.js.

Known issues:

  • Blockly.utils.xml.createElement & Blockly.utils.xml.createTextNode
  • Blockly.utils.xml.domToText
  • Blockly.utils.xml.textToDomDocument

The initial goal is to be able to load a set of blocks from XML onto a headless workspace, and generate code.

@AnmAtAnm
Copy link
Contributor

AnmAtAnm commented Oct 16, 2018

Are you testing these with the Node package created via npm install (and indirectly gulp build)? I just want to make sure we are all working with the same jsdom setup and version.

@NeilFraser
Copy link
Contributor Author

I'm not testing this or owning this effort. Rachel made me file something here so that I could annotate the TODOs in Blockly.Xml.utils that point out the code there fails due to the use of global objects not present in Node (such as document). :)

@kesavkolla
Copy link

Is there any work being done to make the blockly to be imported into Node.js environment? Our usecase is to use blockly in NodeJS and generate the code from blockly XML file.

@RoboErikG RoboErikG added component: devtools issue: feature request Describes a new feature and why it should be added labels Nov 28, 2018
@rachel-fenichel
Copy link
Collaborator

@riknoll Before the holidays I said I'd ping you about remaining steps for Blockly to work under Node. Here's the tracking bug. It looks like the number of remaining globals is fairly small. @AnmAtAnm may have more comments on whether anything else needs to be done.

@rachel-fenichel rachel-fenichel added the help wanted External contributions actively solicited label Jan 28, 2019
@staylornc
Copy link

@rachel-fenichel, is there an update on this issue? We would love to use Blockly within the adaptive learning environments we are creating in Unity, getting this to work would be a huge help to us. Thanks. :-)

@amber-cd
Copy link
Contributor

I would also like to ask for an update on this, for the reason that we've actually been using Blockly on Nodejs for some time by doing overrides of the blockToDom and domToVariables to use childNodes instead of children and commenting out container.appendChild(Blockly.Xml.cloneShadow_(shadow)); in blockToDom. I wouldn't be averse to trying to integrate our Nodejs-only overrides into something that will just behave fine both in the supported browsers and in Nodejs, but all we really do is load saved XML up into non-SVG workspaces in order to regenerate their JavaScript. What all else is known to be an issue when running in Nodejs? Is there a good comprehensive replication of the issues available somewhere? (Of note is that we use xmldom in order to make this work, and I'm not sure if that would be acceptable in the final product either.)

@rachel-fenichel
Copy link
Collaborator

@amber-cd We don't have anyone actively working on it right now. Our eng team is focusing on rendering and keyboard navigation.

I would be open to a PR that gets this working for headless mode (your use case), even if it doesn't fix everything.

I know that our gulpfile has a snippet of code to use JSDOM instead of DOMParser in Blockly.Xml.utils.textToDomDocument; I think we need to do something similar for the other functions mentioned above.

The other problem I'm aware of is that we have a lot of references to document.

@DaveWelling
Copy link

For those that need a solution sooner, check out this repository: https://github.com/mo4islona/node-blockly
My company has been using it to create Blockly transformations in Node for a while. The package author seems to do a good job of keeping it up to date.
The downside is that it has a dependency on the xmlshim npm package for XML parsing -- which creates problems involving native code compilation. Unfortunately, I don't know if there is a better alternative for XML parsing in Node. I actually looked around in the hopes of recommending something for the repository owner - but no luck.

@samelhusseini
Copy link
Contributor

Hey @DaveWelling. We have also since tackled this issue. You can read more about the release here: https://groups.google.com/forum/#!topic/blockly/HZuw6KZWqYY

We are officially publishing our releases to NPM, wrapping each of our compressed files in a UMD module. We chose UMD to support both AMD and CommonJS ecosystems.

This should work out the box for Node, you can find it on NPM here:
https://www.npmjs.com/package/blockly

and there's a sample for using it with Node here:
https://github.com/google/blockly-samples/tree/master/blockly-node

@samelhusseini samelhusseini self-assigned this Aug 28, 2019
@RoboErikG
Copy link
Contributor

@samelhusseini can this bug be closed or is there more work to do?

@samelhusseini
Copy link
Contributor

Yes, we still need an XML serializer polyfill for Blockly.utils.xml.domToText.
I think we can use jsdom for that.
Blockly.utils.xml.createElement and Blockly.utils.xml.createTextNode are taken care of by using jsdom to polyfill a document element.
If jsdom doesn't do it, we should consider just relying on https://www.npmjs.com/package/dom-parser and https://www.npmjs.com/package/xmlserializer for dom parsing and xml serialization.

@samelhusseini
Copy link
Contributor

I think this can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: devtools help wanted External contributions actively solicited issue: feature request Describes a new feature and why it should be added
Projects
None yet
Development

No branches or pull requests

9 participants