Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): Switch from microbundle to vite lib mode #60

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -84,6 +84,7 @@
"microbundle": "^0.15.1",
"prettier": "^3.4.2",
"rimraf": "^3.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"semver": "^7.6.3",
"typescript": "~5.3.3",
"vite": "^5.2.10",
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
}
}
27 changes: 27 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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,
sourcemap: true,
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 @@ -1478,6 +1478,7 @@ __metadata:
microbundle: "npm:^0.15.1"
prettier: "npm:^3.4.2"
rimraf: "npm:^3.0.2"
rollup-plugin-typescript2: "npm:^0.36.0"
semver: "npm:^7.6.3"
typescript: "npm:~5.3.3"
vite: "npm:^5.2.10"
Expand Down Expand Up @@ -8175,6 +8176,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