Skip to content

Commit 4741df6

Browse files
committed
Remove import.meta.url usage
import.meta.url is only at stage 3 of the standards and tools like webpack and babel do not have good support. Not all browser do either. I ran into problems just trying to update the cesium-webpack-example because of it and Edge won't even part JS code with import.meta.url in it. This PR removes import.meta.url usage and just does a little extra work so that all of our developer setups properly set CESIUM_BASE_URL. Most ES6 development setups would require setting CESIUM_BASE_URL anyway, so this doesn't change much of anything for our end users. Folks using combined versions of Cesium.js are unaffected. I also tightened up our regex for `getBaseUrlFromCesiumScript` because Cesium.js is always named Cesium.js if it is available, which wasn't the case years ago when this code was written. This should prevent accidental detection of the wrong script, for example `CesiumViewer.js` would get selected as a false positive. This type of check is only valid for non-ES6 module usage anyway, since there is no `script` tag inserter for individual ES6 modules. Fixes #8251 You can now load Cesium Viewer unbuilt in Edge (but it takes forever)
1 parent 4080bc1 commit 4741df6

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

Apps/CesiumViewer/CesiumViewer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
window.CESIUM_BASE_URL = '../../Source/';
2+
13
import {
24
Cartesian3,
35
createWorldTerrain,

Apps/Sandcastle/load-cesium-es6.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file loads the unbuilt ES6 version of Cesium
22
// into the global scope during local developmnet
3+
window.CESIUM_BASE_URL = "../../../Source/";
34
import * as Cesium from "../../Source/Cesium.js";
45
window.Cesium = Cesium;
56

Source/Core/buildModuleUrl.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import defined from './defined.js';
22
import DeveloperError from './DeveloperError.js';
3-
import FeatureDetection from './FeatureDetection.js';
43
import getAbsoluteUri from './getAbsoluteUri.js';
54
import Resource from './Resource.js';
65

76
/*global CESIUM_BASE_URL*/
87

9-
var cesiumScriptRegex = /((?:.*\/)|^)cesium[\w-]*\.js(?:\W|$)/i;
8+
var cesiumScriptRegex = /((?:.*\/)|^)Cesium\.js$/;
109
function getBaseUrlFromCesiumScript() {
1110
var scripts = document.getElementsByTagName('script');
1211
for ( var i = 0, len = scripts.length; i < len; ++i) {
@@ -47,16 +46,10 @@ import Resource from './Resource.js';
4746
baseUrlString = CESIUM_BASE_URL;
4847
} else if (typeof define === 'object' && defined(define.amd) && !define.amd.toUrlUndefined && defined(require.toUrl)) {
4948
baseUrlString = getAbsoluteUri('..', buildModuleUrl('Core/buildModuleUrl.js'));
50-
} else if (!FeatureDetection.isInternetExplorer() && /\/buildModuleUrl\.js$/.test(import.meta.url)) {
51-
baseUrlString = getAbsoluteUri('..', import.meta.url);
5249
} else {
5350
baseUrlString = getBaseUrlFromCesiumScript();
5451
}
5552

56-
if (baseUrlString === '') {
57-
baseUrlString = '.';
58-
}
59-
6053
//>>includeStart('debug', pragmas.debug);
6154
if (!defined(baseUrlString)) {
6255
throw new DeveloperError('Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.');

Specs/Core/buildModuleUrlSpec.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ describe('Core/buildModuleUrl', function() {
1818
var r = buildModuleUrl._cesiumScriptRegex;
1919

2020
expect(r.exec('Cesium.js')[1]).toEqual('');
21-
expect(r.exec('assets/foo/Cesium-b16.js')[1]).toEqual('assets/foo/');
2221
expect(r.exec('assets/foo/Cesium.js')[1]).toEqual('assets/foo/');
2322
expect(r.exec('http://example.invalid/Cesium/assets/foo/Cesium.js')[1]).toEqual('http://example.invalid/Cesium/assets/foo/');
2423

Specs/SpecRunner.html

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
document.write('<script src="../Build/Specs/spec-main.js"><\/script>');
2828
document.write('<script src="../Build/Specs/Specs.js"><\/script>');
2929
} else {
30+
window.CESIUM_BASE_URL = '../Source/';
3031
document.write('<script type="module" src="spec-main.js"><\/script>');
3132
}
3233
</script>

Specs/karma-main.js

+6
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ if (__karma__.config.args) {
1515
release = __karma__.config.args[4];
1616
}
1717

18+
if (release) {
19+
window.CESIUM_BASE_URL = 'base/Build/Cesium';
20+
} else {
21+
window.CESIUM_BASE_URL = 'base/Source';
22+
}
23+
1824
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
1925
customizeJasmine(jasmine.getEnv(), included, excluded, webglValidation, webglStub, release);

gulpfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ function buildCesiumViewer() {
13941394
var stream = mergeStream(
13951395
gulp.src('Build/Apps/CesiumViewer/CesiumViewer.js')
13961396
.pipe(gulpInsert.prepend(copyrightHeader))
1397+
.pipe(gulpReplace('../../Source', '.'))
13971398
.pipe(gulp.dest(cesiumViewerOutputDirectory)),
13981399

13991400
gulp.src('Apps/CesiumViewer/CesiumViewer.css')

0 commit comments

Comments
 (0)