Skip to content

Commit

Permalink
chore(build): Switch from microbundle to vite lib mode
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Jan 7, 2025
1 parent efebb5c commit f7cd88e
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 26 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
".": {
"types": "./build/index.d.ts",
"require": "./build/api-client.cjs",
"default": "./build/api-client.modern.js"
"default": "./build/api-client.js"
}
},
"browserslist": [
Expand All @@ -29,8 +29,8 @@
"node >= 18"
],
"scripts": {
"build": "microbundle --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
"build:watch": "microbundle watch --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
"build": "vite build",
"build:watch": "vite build --watch",
"dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
"test": "vitest run --typecheck",
"test:watch": "vitest watch --typecheck",
Expand Down Expand Up @@ -92,6 +92,7 @@
"react-dom": "^18.3.1",
"react-map-gl": "^7.1.7",
"rimraf": "^3.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"semver": "^7.6.3",
"svelte": "^4.2.17",
"typescript": "~5.3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/api/carto-api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {MapType} from '../types';
import type {MapType} from '../types';

export type APIRequestType =
| 'Map data'
Expand Down
2 changes: 1 addition & 1 deletion src/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {MapType} from '../types.js';
import type {MapType} from '../types.js';

export type V3Endpoint = 'maps' | 'stats' | 'sql';

Expand Down
4 changes: 2 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

export {
CartoAPIError,
APIErrorContext,
APIRequestType,
type APIErrorContext,
type APIRequestType,
} from './carto-api-error.js';
// Internal, but required for fetchMap().
export {buildPublicMapUrl, buildStatsUrl} from './endpoints.js';
Expand Down
6 changes: 0 additions & 6 deletions src/constants-internal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* Current version of @carto/api-client.
* @internal
*/
export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;

/** @internal */
export const V3_MINOR_VERSION = '3.4';

Expand Down
8 changes: 0 additions & 8 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
/**
* Injected by microbundle, with:
* ```
* --define __CARTO_API_CLIENT_VERSION=$npm_package_version
* ```
*/
declare const __CARTO_API_CLIENT_VERSION: string;

/** Defined by @deck.gl/core. */
declare const deck: {VERSION: string | undefined} | undefined;
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export * from './widget-sources/index.js';
export * from './types.js';

export {
APIErrorContext,
APIRequestType,
type APIErrorContext,
type APIRequestType,
CartoAPIError,
QueryOptions,
type QueryOptions,
buildPublicMapUrl, // Internal, but required for fetchMap().
buildStatsUrl, // Internal, but required for fetchMap().
query,
Expand Down
1 change: 0 additions & 1 deletion src/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
QueryParameters,
SpatialFilter,
} from '../types.js';
import {$TODO} from '../types-internal.js';
import {assert, isPureObject} from '../utils.js';
import {ModelRequestOptions, makeCall} from './common.js';
import {ApiVersion} from '../constants.js';
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lib": ["es2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"jsx": "react",
"strict": true
"strict": true,
"isolatedModules": true
}
}
26 changes: 26 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {resolve} from 'path';
import {PluginOption, defineConfig} from 'vite';
import {readFile} from 'node:fs/promises';
import typescript from 'rollup-plugin-typescript2';

const pkg = JSON.parse(await readFile('./package.json', 'utf-8'));

// NOTE: 'isolatedModules' must be enabled in tsconfig.json,
// see https://github.com/vitejs/vite/discussions/16680.
export default defineConfig({
plugins: [{...typescript(), enforce: 'pre'} as PluginOption],
build: {
outDir: 'build',
target: 'esnext',
minify: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
fileName: 'api-client',
formats: ['es', 'cjs'],
},
rollupOptions: {
// Externalize deps that shouldn't be bundled.
external: Object.keys(pkg.dependencies),
},
},
});
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ __metadata:
react-dom: "npm:^18.3.1"
react-map-gl: "npm:^7.1.7"
rimraf: "npm:^3.0.2"
rollup-plugin-typescript2: "npm:^0.36.0"
semver: "npm:^7.6.3"
svelte: "npm:^4.2.17"
typescript: "npm:~5.3.3"
Expand Down Expand Up @@ -8573,6 +8574,22 @@ __metadata:
languageName: node
linkType: hard

"rollup-plugin-typescript2@npm:^0.36.0":
version: 0.36.0
resolution: "rollup-plugin-typescript2@npm:0.36.0"
dependencies:
"@rollup/pluginutils": "npm:^4.1.2"
find-cache-dir: "npm:^3.3.2"
fs-extra: "npm:^10.0.0"
semver: "npm:^7.5.4"
tslib: "npm:^2.6.2"
peerDependencies:
rollup: ">=1.26.3"
typescript: ">=2.4.0"
checksum: 10c0/3c8d17cd852ded36eaad2759caf170f90e091d8f86ff7b016d1823bc8b507b8f689156bcccda348fc88471681dc79cc9eb13ddb09a4dfcf0d07ac9a249e2d79b
languageName: node
linkType: hard

"rollup-plugin-visualizer@npm:^5.6.0":
version: 5.12.0
resolution: "rollup-plugin-visualizer@npm:5.12.0"
Expand Down

0 comments on commit f7cd88e

Please sign in to comment.