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

Partial XHR polyfull for Node.js #6463

Merged
merged 9 commits into from
Apr 18, 2018
Merged

Partial XHR polyfull for Node.js #6463

merged 9 commits into from
Apr 18, 2018

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Apr 18, 2018

This is a continuation of #6454 with some minor cleanup and additions.

@cesium-concierge
Copy link

Signed CLA is on file.

@mramato, thanks for the pull request! Maintainers, we have a signed CLA from @mramato, so you can review this at any time.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@mramato mramato mentioned this pull request Apr 18, 2018
@mramato mramato merged commit 570b6f6 into master Apr 18, 2018
@mramato mramato deleted the node-xhr-polyfill branch April 18, 2018 16:24
@mramato
Copy link
Contributor Author

mramato commented Apr 18, 2018

CC @jimmyangel this will be in the May 1st release.

var isNodeJsResult;
function isNodeJs() {
if (!defined(isNodeJsResult)) {
isNodeJsResult = typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]'; // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the eslint-disable-line for? Can we do eslint-disable-line some-eslint-rule instead of disabling everything for this line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind I guess haha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process is only a global in node and this is browser code so we need to ignore it. I couldn't figure out how to just allow a global for one line.

@hpinkos
Copy link
Contributor

hpinkos commented Apr 18, 2018

@mramato are you going to add @jimmyangel to CONTRIBUTORS.md?

@jimmyangel
Copy link
Contributor

Hi @hpinkos @mramato, I can work on a couple of tests but could you please tell me where to plug them in so that they executed under nodejs (as opposed to a browser)?

@mramato
Copy link
Contributor Author

mramato commented Apr 18, 2018

Hi @hpinkos @mramato, I can work on a couple of tests but could you please tell me where to plug them in so that they executed under nodejs (as opposed to a browser)?

Thanks for the offer, but we actually don't have any Node unit tests at this time, so there's no where for you to put them. We want to have them eventually, but the plan is to figure out how to leverage our existing tests in node rather than have a separate set of node-specific tests.

@mramato
Copy link
Contributor Author

mramato commented Apr 18, 2018

@mramato are you going to add @jimmyangel to CONTRIBUTORS.md?

Sorry, I thought he was already in there but didn't check, I'll add him

@jimmyangel
Copy link
Contributor

Thanks for the offer, but we actually don't have any Node unit tests at this time, so there's no where for you to put them. We want to have them eventually, but the plan is to figure out how to leverage our existing tests in node rather than have a separate set of node-specific tests.

Ok. FYI, I have created a package that uses sampleTerrain in node as a utility (and library) to add elevation to arbitrary GeoJSON data. It includes a few Jasmine tests that end up exercising the XHR functionality here. You could potential reuse, or simply add a command line invocation with a couple of test files. Just let me know if I can help.

@jimmyangel
Copy link
Contributor

jimmyangel commented Jan 21, 2020

Hi @mramato,

It looks like the ability to use xhr from node.js broke in Cesium at some point :(. I tried to use Cesium.sampleTerrain from node.js, and I am seeing this:

TypeError: nodeRequire is not a function
    at loadWithHttpRequest (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1892:19)
    at Object._34e‍.r.Resource._Implementations.loadWithXhr (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1945:13)
    at Request.request.requestFunction (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1298:49)
    at startRequest (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/RequestScheduler.js:195:17)
    at Function._34e‍.r.RequestScheduler.request (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/RequestScheduler.js:338:20)
    at Resource._34e‍.r.Resource._makeRequest (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1307:40)
    at Resource._34e‍.r.Resource.fetch (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1414:21)
    at Resource._34e‍.r.Resource.fetchJson (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/Resource.js:1091:28)
    at Function._34e‍.r.IonResource.fromAssetId (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/IonResource.js:98:33)
    at Proxy.createWorldTerrain (/Users/morin_ricardo/Projects/sampleterrain/node_modules/cesium/Source/Core/createWorldTerrain.js:37:30)

Looks like global.require is undefined in Resource.js. At some point it seems like it got messed up. Would this be something you guys could easily fix?

I propose replacing line 1905

var nodeRequire = global.require; // eslint-disable-line

with

var nodeRequire = global.require ? global.require : require; // eslint-disable-line

Does that work for you?

Thank you,

Ricardo

@mramato
Copy link
Contributor Author

mramato commented Jan 21, 2020

@jimmyangel Can you please write up a fresh issue for us to take a look at this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants