Skip to content

Commit 365b2a8

Browse files
authored
Remove CJS build (#449)
### Changelog Breaking changes: * Package is ESM-only ### Docs None ### Description Split from #448 - Upgrade `@foxglove/tsconfig`, replace some TS-specific syntax features, add file extensions on all imports - Add `"type": "module"`, remove `tsconfig.cjs.json`
1 parent 074624d commit 365b2a8

17 files changed

+165
-363
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ updates:
2222
patterns:
2323
- "storybook"
2424
- "@storybook/*"
25+
- "eslint-plugin-storybook"
2526
jest:
2627
patterns:
2728
- "jest"
2829
- "jest-*"
29-
- "babel-jest"
3030
- "@types/jest"
31+
- "@swc/*"
3132
webpack:
3233
patterns:
3334
- "webpack"
3435
- "webpack-cli"
3536
- "webpack-dev-server"
36-
babel:
37-
patterns:
38-
- "@babel/*"

babel.config.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import foxglove from "@foxglove/eslint-plugin";
2+
import { defineConfig } from "eslint/config";
23
import storybook from "eslint-plugin-storybook";
34
import globals from "globals";
4-
import tseslint from "typescript-eslint";
55

6-
// avoid a type error when using eslint's builtin defineConfig()
7-
// eslint-disable-next-line @typescript-eslint/no-deprecated
8-
export default tseslint.config(
6+
export default defineConfig(
97
{
108
ignores: ["**/dist", "!.storybook"],
119
},
@@ -34,9 +32,11 @@ export default tseslint.config(
3432
},
3533
{
3634
rules: {
35+
"@typescript-eslint/consistent-type-imports": ["error", { disallowTypeAnnotations: false }],
3736
"@typescript-eslint/no-unsafe-assignment": "off",
3837
"@typescript-eslint/no-unsafe-member-access": "off",
3938
"@foxglove/prefer-hash-private": "off",
39+
"import/extensions": ["error", "ignorePackages", { checkTypeImports: true }],
4040
},
4141
},
4242
{

jest.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Config } from "jest";
2+
3+
export default {
4+
testMatch: ["<rootDir>/src/**/*.test.ts"],
5+
setupFiles: ["jest-canvas-mock"],
6+
transform: {
7+
"^.+\\.(t|j)sx?$": "@swc/jest",
8+
},
9+
transformIgnorePatterns: [],
10+
} satisfies Config;

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
"email": "contact@foxglove.dev",
1313
"url": "https://foxglove.dev/"
1414
},
15-
"module": "dist/esm/index.js",
16-
"main": "dist/cjs/index.js",
15+
"type": "module",
16+
"exports": {
17+
".": "./dist/index.js"
18+
},
1719
"files": [
1820
"dist",
1921
"src"
2022
],
2123
"scripts": {
2224
"clean": "rimraf dist *.tsbuildinfo",
23-
"prepack": "tsc -b tsconfig.build.json tsconfig.cjs.json",
24-
"build": "tsc -b tsconfig.build.json tsconfig.cjs.json",
25+
"prepack": "tsc -b tsconfig.build.json",
26+
"build": "tsc -b tsconfig.build.json",
2527
"lint": "eslint --fix .",
2628
"lint:ci": "eslint .",
27-
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
29+
"test": "jest",
2830
"typecheck": "tsc -b --noEmit tsconfig.json",
2931
"storybook": "storybook dev -p 6006",
3032
"build-storybook": "storybook build"
@@ -37,13 +39,15 @@
3739
},
3840
"devDependencies": {
3941
"@foxglove/eslint-plugin": "2.1.0",
40-
"@foxglove/tsconfig": "2.0.0",
42+
"@foxglove/tsconfig": "3.2.0",
4143
"@storybook/addon-webpack5-compiler-swc": "4.0.2",
4244
"@storybook/react-webpack5": "10.1.11",
45+
"@swc/core": "^1.15.11",
46+
"@swc/jest": "^0.2.39",
4347
"@types/jest": "30.0.0",
4448
"@types/node": "25.0.3",
4549
"@types/react": "19.2.2",
46-
"@types/three": "0.181.0",
50+
"@types/three": "0.182.0",
4751
"eslint": "9.39.1",
4852
"eslint-plugin-storybook": "10.1.4",
4953
"globals": "16.5.0",
@@ -55,8 +59,7 @@
5559
"react-dom": "19.2.0",
5660
"rimraf": "6.1.2",
5761
"storybook": "10.1.11",
58-
"three": "0.181.2",
59-
"ts-jest": "29.4.5",
62+
"three": "0.182.0",
6063
"typescript": "5.9.3"
6164
},
6265
"packageManager": "yarn@4.12.0"

src/FontManager.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useRef, type ReactElement } from "react";
22

3-
import { AtlasData, FontManager } from "./FontManager";
3+
import type { AtlasData } from "./FontManager.ts";
4+
import { FontManager } from "./FontManager.ts";
45

56
export default {
67
title: "FontManager",

src/FontManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jest-environment jsdom */
22

3-
import { FontManager } from "./FontManager";
3+
import { FontManager } from "./FontManager.ts";
44

55
describe("FontManager", () => {
66
it("emits error events", () => {

src/FontManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import TinySDF from "@mapbox/tiny-sdf";
2-
import { EventDispatcher } from "three";
2+
import * as THREE from "three";
33

44
export type CharInfo = {
55
atlasX: number;
@@ -50,7 +50,7 @@ type EventMap = {
5050
* Manages the creation of a Signed Distance Field (SDF) font atlas, and performs text layout to
5151
* generate attributes for rendering text using the atlas.
5252
*/
53-
export class FontManager extends EventDispatcher<EventMap> {
53+
export class FontManager extends THREE.EventDispatcher<EventMap> {
5454
private alphabet = "";
5555
readonly atlasData: AtlasData = {
5656
data: new Uint8ClampedArray(1024 * 1024),
@@ -64,8 +64,11 @@ export class FontManager extends EventDispatcher<EventMap> {
6464
#tinysdf: TinySDF;
6565
#lastCharPosition = { x: 0, y: 0, rowHeight: 0 };
6666

67-
constructor(public readonly options: FontManagerOptions = {}) {
67+
public readonly options: FontManagerOptions;
68+
69+
constructor(options: FontManagerOptions = {}) {
6870
super();
71+
this.options = options;
6972

7073
this.options.fontSize = this.options.fontSize ?? 48;
7174
this.#buffer = Math.ceil(this.options.fontSize / 16);

src/LabelPool.stories.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Meta, StoryObj } from "@storybook/react-webpack5";
1+
import type { Meta, StoryObj } from "@storybook/react-webpack5";
22
import { useEffect, useRef, useState, type ReactElement } from "react";
33
import * as THREE from "three";
44
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
55

6-
import { Label, LabelPool } from "./LabelPool";
6+
import type { Label } from "./LabelPool.ts";
7+
import { LabelPool } from "./LabelPool.ts";
78

89
const meta: Meta<typeof BasicTemplate> = {
910
title: "LabelPool",
@@ -41,6 +42,9 @@ const meta: Meta<typeof BasicTemplate> = {
4142
};
4243
export default meta;
4344

45+
type StorySceneOptions = {
46+
logDepthBuffer: boolean;
47+
};
4448
class StoryScene {
4549
labelPool = new LabelPool();
4650

@@ -54,7 +58,10 @@ class StoryScene {
5458

5559
bgCube?: THREE.Mesh;
5660

57-
constructor(private options: { logDepthBuffer: boolean }) {
61+
private options: StorySceneOptions;
62+
63+
constructor(options: StorySceneOptions) {
64+
this.options = options;
5865
this.perspectiveCamera.position.set(4, 4, 4);
5966
this.scene.background = new THREE.Color(0xf0f0f0);
6067
this.scene.add(new THREE.AxesHelper(5));

0 commit comments

Comments
 (0)