Skip to content

Commit f36a25c

Browse files
authored
Merge pull request #8659 from CesiumGS/node12
Fix Cesium in Node.js 12+.
2 parents 6b2d445 + f67eb82 commit f36a25c

8 files changed

+34
-16
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"overrides": [
1010
{
1111
"files": [
12-
"index.js",
12+
"index.cjs",
1313
"server.cjs",
1414
"gulpfile.js",
1515
"Source/Workers/transferTypedArrayTest.js"

.gulp.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"flags": {
3+
"gulpfile": "gulpfile.cjs"
4+
}
5+
}

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ script:
2626

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

3232
- npm --silent run cloc

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ Change Log
66
##### Additions :tada:
77

88
* 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)
9+
* The `CesiumUnminified` build now includes sourcemaps.
910

1011
##### Fixes :wrench:
1112

13+
* 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.
1214
* Interacting with the Cesium canvas will now blur the previously focused element. This prevents unintended modification of input elements when interacting with the globe.
1315
* `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)
1416
* Fixed ground atmosphere rendering when using a samller ellipsoid. [#8683](https://github.com/CesiumGS/cesium/issues/8683)

Tools/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

gulpfile.js gulpfile.cjs

+13-7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ function rollupWarning(message) {
115115
console.log(message);
116116
}
117117

118+
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'), "utf8");
119+
118120
function createWorkers() {
119121
rimraf.sync('Build/createWorkers');
120122

@@ -150,6 +152,9 @@ function createWorkers() {
150152

151153
gulp.task('build', function() {
152154
mkdirp.sync('Build');
155+
fs.writeFileSync('Build/package.json', JSON.stringify({
156+
type: 'commonjs'
157+
}), "utf8");
153158
glslToJavaScript(minifyShaders, 'Build/minifyShaders.state');
154159
createCesiumJs();
155160
createSpecList();
@@ -341,7 +346,7 @@ gulp.task('makeZipFile', gulp.series('release', function() {
341346
'Specs/**',
342347
'ThirdParty/**',
343348
'favicon.ico',
344-
'gulpfile.js',
349+
'gulpfile.cjs',
345350
'server.cjs',
346351
'package.json',
347352
'LICENSE.md',
@@ -457,7 +462,7 @@ function deployCesium(bucketName, uploadDirectory, cacheControl, done) {
457462
'ThirdParty/**',
458463
'*.md',
459464
'favicon.ico',
460-
'gulpfile.js',
465+
'gulpfile.cjs',
461466
'index.html',
462467
'package.json',
463468
'server.cjs',
@@ -997,7 +1002,9 @@ function combineCesium(debug, optimizer, combineOutput) {
9971002
return bundle.write({
9981003
format: 'umd',
9991004
name: 'Cesium',
1000-
file: path.join(combineOutput, 'Cesium.js')
1005+
file: path.join(combineOutput, 'Cesium.js'),
1006+
sourcemap: debug,
1007+
banner: copyrightHeader
10011008
});
10021009
});
10031010
}
@@ -1047,7 +1054,9 @@ function combineWorkers(debug, optimizer, combineOutput) {
10471054
}).then(function(bundle) {
10481055
return bundle.write({
10491056
dir: path.join(combineOutput, 'Workers'),
1050-
format: 'amd'
1057+
format: 'amd',
1058+
sourcemap: debug,
1059+
banner: copyrightHeader
10511060
});
10521061
});
10531062
});
@@ -1073,7 +1082,6 @@ function combineJavaScript(options) {
10731082
var removePragmas = options.removePragmas;
10741083

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

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

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

10921099
promises.push(streamToPromise(stream));
@@ -1391,7 +1398,6 @@ function buildCesiumViewer() {
13911398
);
13921399

13931400
promise = promise.then(function() {
1394-
var copyrightHeader = fs.readFileSync(path.join('Source', 'copyrightHeader.js'));
13951401
var stream = mergeStream(
13961402
gulp.src('Build/Apps/CesiumViewer/CesiumViewer.js')
13971403
.pipe(gulpInsert.prepend(copyrightHeader))

index.js index.cjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ if (process.env.NODE_ENV === 'production') {
88
module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium'));
99
return;
1010
}
11-
module.exports = require('esm')(module)('./Source/Cesium.js');
11+
12+
module.exports = require(path.join(__dirname, 'Build/CesiumUnminified/Cesium'));

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
"url": "https://github.com/CesiumGS/cesium/issues",
3030
"email": "cesium-dev@googlegroups.com"
3131
},
32-
"main": "index.js",
33-
"module": "Source/Cesium.js",
34-
"type": "module",
35-
"dependencies": {
36-
"esm": "^3.2.25"
32+
"main": "index.cjs",
33+
"module": "./Source/Cesium.js",
34+
"exports": {
35+
"require": "./index.cjs",
36+
"import": "./Source/Cesium.js"
3737
},
38+
"type": "module",
3839
"devDependencies": {
3940
"aws-sdk": "^2.531.0",
4041
"bluebird": "^3.4.6",

0 commit comments

Comments
 (0)