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

Fix Cesium in Node.js 12+. #8659

Merged
merged 11 commits into from Mar 19, 2020
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -9,7 +9,7 @@
"overrides": [
{
"files": [
"index.js",
"index.cjs",
"server.cjs",
"gulpfile.js",
"Source/Workers/transferTypedArrayTest.js"
Expand Down
5 changes: 5 additions & 0 deletions .gulp.json
@@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
}
}
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -26,7 +26,7 @@ script:

# Various Node.js smoke-screen tests
- node -e "const Cesium = require('./');"
- NODE_ENV=development node index.js
- NODE_ENV=production node index.js
- NODE_ENV=development node index.cjs
- NODE_ENV=production node index.cjs

- npm --silent run cloc
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -6,9 +6,11 @@ Change Log
##### Additions :tada:

* Added basic underground rendering support. When the camera is underground the globe will be rendered as a solid surface and underground entities will not be culled. [#8572](https://github.com/AnalyticalGraphicsInc/cesium/pull/8572)
* The `CesiumUnminified` build now includes sourcemaps.

##### Fixes :wrench:

* Cesium can now be used in Node.JS 12 and later, with or without `--experimental-modules`. It can still be used in earlier versions as well.
* Interacting with the Cesium canvas will now blur the previously focused element. This prevents unintended modification of input elements when interacting with the globe.
* `TileMapServiceImageryProvider` will now force `minimumLevel` to 0 if the `tilemapresource.xml` metadata request fails and the `rectangle` is too large for the given detail level [#8448](https://github.com/AnalyticalGraphicsInc/cesium/pull/8448)
* Fixed ground atmosphere rendering when using a samller ellipsoid. [#8683](https://github.com/CesiumGS/cesium/issues/8683)
Expand Down
3 changes: 3 additions & 0 deletions Tools/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
20 changes: 13 additions & 7 deletions gulpfile.js → gulpfile.cjs
Expand Up @@ -115,6 +115,8 @@ function rollupWarning(message) {
console.log(message);
}

var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'), "utf8");

function createWorkers() {
rimraf.sync('Build/createWorkers');

Expand Down Expand Up @@ -150,6 +152,9 @@ function createWorkers() {

gulp.task('build', function() {
mkdirp.sync('Build');
fs.writeFileSync('Build/package.json', JSON.stringify({
type: 'commonjs'
}), "utf8");
glslToJavaScript(minifyShaders, 'Build/minifyShaders.state');
createCesiumJs();
createSpecList();
Expand Down Expand Up @@ -341,7 +346,7 @@ gulp.task('makeZipFile', gulp.series('release', function() {
'Specs/**',
'ThirdParty/**',
'favicon.ico',
'gulpfile.js',
'gulpfile.cjs',
'server.cjs',
'package.json',
'LICENSE.md',
Expand Down Expand Up @@ -457,7 +462,7 @@ function deployCesium(bucketName, uploadDirectory, cacheControl, done) {
'ThirdParty/**',
'*.md',
'favicon.ico',
'gulpfile.js',
'gulpfile.cjs',
'index.html',
'package.json',
'server.cjs',
Expand Down Expand Up @@ -997,7 +1002,9 @@ function combineCesium(debug, optimizer, combineOutput) {
return bundle.write({
format: 'umd',
name: 'Cesium',
file: path.join(combineOutput, 'Cesium.js')
file: path.join(combineOutput, 'Cesium.js'),
sourcemap: debug,
banner: copyrightHeader
});
});
}
Expand Down Expand Up @@ -1047,7 +1054,9 @@ function combineWorkers(debug, optimizer, combineOutput) {
}).then(function(bundle) {
return bundle.write({
dir: path.join(combineOutput, 'Workers'),
format: 'amd'
format: 'amd',
sourcemap: debug,
banner: copyrightHeader
});
});
});
Expand All @@ -1073,7 +1082,6 @@ function combineJavaScript(options) {
var removePragmas = options.removePragmas;

var combineOutput = path.join('Build', 'combineOutput', optimizer);
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'));

var promise = Promise.join(
combineCesium(!removePragmas, optimizer, combineOutput),
Expand All @@ -1086,7 +1094,6 @@ function combineJavaScript(options) {

//copy to build folder with copyright header added at the top
var stream = gulp.src([combineOutput + '/**'])
.pipe(gulpInsert.prepend(copyrightHeader))
.pipe(gulp.dest(outputDirectory));

promises.push(streamToPromise(stream));
Expand Down Expand Up @@ -1391,7 +1398,6 @@ function buildCesiumViewer() {
);

promise = promise.then(function() {
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'));
var stream = mergeStream(
gulp.src('Build/Apps/CesiumViewer/CesiumViewer.js')
.pipe(gulpInsert.prepend(copyrightHeader))
Expand Down
3 changes: 2 additions & 1 deletion index.js → index.cjs
Expand Up @@ -8,4 +8,5 @@ if (process.env.NODE_ENV === 'production') {
module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium'));
return;
}
module.exports = require('esm')(module)('./Source/Cesium.js');

module.exports = require(path.join(__dirname, 'Build/CesiumUnminified/Cesium'));
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -29,12 +29,13 @@
"url": "https://github.com/CesiumGS/cesium/issues",
"email": "cesium-dev@googlegroups.com"
},
"main": "index.js",
"module": "Source/Cesium.js",
"type": "module",
"dependencies": {
"esm": "^3.2.25"
"main": "index.cjs",
"module": "./Source/Cesium.js",
"exports": {
"require": "./index.cjs",
"import": "./Source/Cesium.js"
},
"type": "module",
"devDependencies": {
"aws-sdk": "^2.531.0",
"bluebird": "^3.4.6",
Expand Down