Skip to content

Commit

Permalink
Don't send sdk version in the dev build (internal-1924)
Browse files Browse the repository at this point in the history
* Don't send sdk version in dev build
  • Loading branch information
stepankuzmin authored and mourner committed Nov 12, 2024
1 parent 51ef9ad commit ba756d0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion build/rollup_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import minifyStyleSpec from './rollup_plugin_minify_style_spec.js';
// Common set of plugins/transformations shared across different rollup
// builds (main mapboxgl bundle, style-spec package, benchmarks bundle)

export const plugins = ({minified, production, test, bench, keepClassNames}) => [
export const plugins = ({mode, minified, production, test, bench, keepClassNames}) => [
minifyStyleSpec(),
esbuild({
// We target `esnext` and disable minification so esbuild
// doesn't transform the code, which we'll minify later with the terser
target: 'esnext',
minify: false,
sourceMap: true,
define: {
'import.meta.env': JSON.stringify({mode}),
},
}),
json({
exclude: 'src/style-spec/reference/v8.json'
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const config = (input, file, format) => ({
banner
},
treeshake: true,
plugins: plugins({minified: true, production: true, keepClassNames: true, test: false, bench: false})
plugins: plugins({minified: true, production: true, keepClassNames: true, test: false, bench: false, mode: 'production'})
});

export default [
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default ({watch}) => {
},
preset: "recommended"
} : false,
plugins: plugins({minified, production, bench, test: false, keepClassNames: false})
plugins: plugins({minified, production, bench, test: false, keepClassNames: false, mode: BUILD})
}, {
// Next, bundle together the three "chunks" produced in the previous pass
// into a single, final bundle. See rollup/bundle_prelude.js and
Expand Down
6 changes: 6 additions & 0 deletions src/types/import-meta.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface ImportMeta {
env: {
mode?: 'dev' | 'production' | 'bench';
[key: string]: unknown;
};
}
5 changes: 4 additions & 1 deletion src/util/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {RequestParameters, ResourceType as ResourceTypeEnum} from './ajax';
import type {Cancelable} from '../types/cancelable';
import type {TileJSON} from '../types/tilejson';
import type {Map as MapboxMap} from "../ui/map";
import '../types/import-meta.d';

export type ResourceType = keyof typeof ResourceTypeEnum;
export type RequestTransformFunction = (url: string, resourceTypeEnum?: ResourceType) => RequestParameters;
Expand Down Expand Up @@ -76,7 +77,9 @@ export class RequestManager {
normalizeStyleURL(url: string, accessToken?: string): string {
if (!isMapboxURL(url)) return url;
const urlObject = parseUrl(url);
urlObject.params.push(`sdk=js-${sdkVersion}`);
if (import.meta.env.mode !== 'dev') {
urlObject.params.push(`sdk=js-${sdkVersion}`);
}
urlObject.path = `/styles/v1${urlObject.path}`;
return this._makeAPIURL(urlObject, this._customAccessToken || accessToken);
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"./test/usvg/**/*",
"./test/util/**/*",
"./vitest.config.*",
"./rollup.config.*",
"./rollup.config.*"
],
"exclude": [
"./dist",
Expand Down

0 comments on commit ba756d0

Please sign in to comment.