Skip to content

Commit

Permalink
Merge pull request #8659 from CesiumGS/node12
Browse files Browse the repository at this point in the history
Fix Cesium in Node.js 12+.
  • Loading branch information
mramato authored Mar 19, 2020
2 parents 6b2d445 + f67eb82 commit f36a25c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
}
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
20 changes: 13 additions & 7 deletions gulpfile.js → gulpfile.cjs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f36a25c

Please sign in to comment.