Skip to content

Commit 84e00dd

Browse files
authored
Modernize typescript (#1529)
### Changelog TypeScript packages now properly export both ESM + CJS modules. Types and constants are now exported directly from `@mcap/core`: ```typescript // Before import type { McapTypes } from "@mcap/core"; const MetadataIndex = { McapTypes }; // After import type { MetadataIndex } from "@mcap/core"; ``` Nested imports are no longer supported: ```typescript // Before import { Metadata } from "@mcap/core/src/types"; // After import type { Metadata } from "@mcap/core"; ``` ### Docs None ### Description - Upgrade TypeScript - Upgrade `@foxglove/tsconfig` and fix all issues - Replace `ts-node` with `tsx` - Maintain both esm and cjs exports for backwards compatibility - Semver minor bump all 4 public packages
1 parent c4edfde commit 84e00dd

158 files changed

Lines changed: 1270 additions & 1287 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ jobs:
233233
registry-url: https://registry.npmjs.org
234234
- run: yarn install --immutable
235235
- run: yarn dedupe --check
236-
- run: yarn prettier:check
236+
- run: yarn fmt:check
237237
- run: yarn workspace @mcap/core lint:ci
238238
- run: yarn workspace @mcap/core build
239239
- run: yarn workspace @mcap/support lint:ci

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ site/
1111
.pnp.*
1212
.yarn/*
1313
*.tgz
14-
14+
*.tsbuildinfo
1515
*.db3-shm
1616
*.db3-wal

‎package.json‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
"website"
1313
]
1414
},
15+
"type": "module",
1516
"scripts": {
16-
"prettier": "prettier --write .",
17-
"prettier:check": "prettier --check .",
17+
"fmt": "prettier --write .",
18+
"fmt:check": "prettier --check .",
1819
"docs:swift:start": "swift package --disable-sandbox preview-documentation --target MCAP",
1920
"typedoc": "yarn typescript:build && typedoc --out __docs__/typescript --options typescript/typedoc.json",
2021
"start": "yarn workspace website start",
2122
"spellcheck": "cspell --relative '**'",
23+
"tsc:all": "tsc --build --incremental --verbose $(git ls-files -- 'tsconfig*.json' '**/tsconfig*.json')",
2224
"typescript:test": "yarn jest --config typescript/jest.config.json",
2325
"typescript:build": "yarn workspace @mcap/core build && yarn workspace @mcap/support build && yarn workspace @mcap/nodejs build && yarn workspace @mcap/browser build",
2426
"typescript:clean": "yarn workspace @mcap/core build --clean && yarn workspace @mcap/support build --clean && yarn workspace @mcap/nodejs build --clean && yarn workspace @mcap/browser build --clean",
@@ -27,13 +29,12 @@
2729
},
2830
"packageManager": "yarn@4.12.0",
2931
"devDependencies": {
30-
"@types/node": "18.13.0",
32+
"@types/node": "20.19.33",
3133
"cspell": "8.0.0",
3234
"jest": "29.7.0",
3335
"prettier": "3.1.0",
3436
"ts-jest": "29.1.1",
35-
"ts-node": "10.9.1",
3637
"typedoc": "0.25.3",
37-
"typescript": "5.2.2"
38+
"typescript": "5.9.3"
3839
}
3940
}

‎tests/conformance/package.json‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{
22
"name": "@foxglove/mcap-conformance",
3-
"version": "0.0.0",
43
"private": true,
4+
"type": "module",
55
"scripts": {
6-
"build": "tsc -b tsconfig.json tsconfig.cjs.json",
7-
"lint:ci": "eslint --report-unused-disable-directives .",
8-
"lint": "eslint --report-unused-disable-directives --fix .",
9-
"generate-inputs": "ts-node --files --project tsconfig.cjs.json scripts/generate-inputs",
10-
"run-tests": "tsc -b tsconfig.json tsconfig.cjs.json && ts-node --files --project tsconfig.cjs.json scripts/run-tests"
6+
"build": "tsc -b",
7+
"lint:ci": "tsc -b && eslint --report-unused-disable-directives .",
8+
"lint": "tsc -b && eslint --report-unused-disable-directives --fix .",
9+
"generate-inputs": "tsc -b && tsx scripts/generate-inputs.ts",
10+
"run-tests": "tsc -b && tsx scripts/run-tests/index.ts"
1111
},
1212
"devDependencies": {
1313
"@foxglove/crc": "^0.0.3",
1414
"@foxglove/eslint-plugin": "1.0.1",
15-
"@foxglove/tsconfig": "1.1.0",
15+
"@foxglove/tsconfig": "3.2.0",
1616
"@mcap/core": "workspace:*",
17-
"@mcap/support": "workspace:*",
17+
"@mcap/nodejs": "workspace:*",
1818
"@types/diff": "^5.0.2",
1919
"@types/js-yaml": "^4.0.5",
20-
"@types/node": "18.13.0",
20+
"@types/lodash-es": "4.17.12",
21+
"@types/node": "20.19.33",
2122
"@typescript-eslint/eslint-plugin": "6.11.0",
2223
"@typescript-eslint/parser": "6.11.0",
2324
"colors": "1.4.0",
@@ -35,10 +36,9 @@
3536
"json-stringify-pretty-compact": "4.0.0",
3637
"kaitai-struct": "0.10.0",
3738
"kaitai-struct-compiler": "0.10.0",
38-
"lodash": "4.17.21",
39+
"lodash-es": "4.17.23",
3940
"prettier": "3.1.0",
40-
"ts-node": "10.9.1",
41-
"tsconfig-paths": "^4.1.2",
42-
"typescript": "5.2.2"
41+
"tsx": "4.21.0",
42+
"typescript": "5.9.3"
4343
}
4444
}

‎tests/conformance/scripts/generate-inputs.ts‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { crc32, crc32Init, crc32Update, crc32Final } from "@foxglove/crc";
2-
import { McapTypes, McapConstants, McapRecordBuilder, McapChunkBuilder } from "@mcap/core";
2+
import { McapRecordBuilder, McapChunkBuilder, Opcode } from "@mcap/core";
3+
import type { AttachmentIndex, ChunkIndex, MetadataIndex } from "@mcap/core";
34
import { program } from "commander";
4-
import fs from "fs/promises";
5-
import path from "path";
6-
import generateTestVariants from "variants/generateTestVariants";
5+
import fs from "node:fs/promises";
6+
import path from "node:path";
77

8-
import { collect } from "../util/collect";
9-
import listDirRecursive from "../util/listDirRecursive";
10-
import { TestDataRecord, TestFeatures } from "../variants/types";
8+
import { collect } from "../util/collect.ts";
9+
import listDirRecursive from "../util/listDirRecursive.ts";
10+
import generateTestVariants from "../variants/generateTestVariants.ts";
11+
import { TestFeatures } from "../variants/types.ts";
12+
import type { TestDataRecord, TestFeature } from "../variants/types.ts";
1113

12-
type MetadataIndex = McapTypes.MetadataIndex;
13-
type ChunkIndex = McapTypes.ChunkIndex;
14-
type AttachmentIndex = McapTypes.AttachmentIndex;
15-
16-
function generateFile(features: Set<TestFeatures>, records: TestDataRecord[]) {
14+
function generateFile(features: Set<TestFeature>, records: TestDataRecord[]) {
1715
const builder = new McapRecordBuilder({
1816
padRecords: features.has(TestFeatures.AddExtraDataToRecords),
1917
});
@@ -204,42 +202,42 @@ function generateFile(features: Set<TestFeatures>, records: TestDataRecord[]) {
204202
summaryOffsetStart = BigInt(builder.length);
205203
if (repeatedSchemasLength !== 0n) {
206204
builder.writeSummaryOffset({
207-
groupOpcode: McapConstants.Opcode.SCHEMA,
205+
groupOpcode: Opcode.SCHEMA,
208206
groupStart: repeatedSchemasStart,
209207
groupLength: repeatedSchemasLength,
210208
});
211209
}
212210
if (repeatedChannelInfosLength !== 0n) {
213211
builder.writeSummaryOffset({
214-
groupOpcode: McapConstants.Opcode.CHANNEL,
212+
groupOpcode: Opcode.CHANNEL,
215213
groupStart: repeatedChannelInfosStart,
216214
groupLength: repeatedChannelInfosLength,
217215
});
218216
}
219217
if (statisticsLength !== 0n) {
220218
builder.writeSummaryOffset({
221-
groupOpcode: McapConstants.Opcode.STATISTICS,
219+
groupOpcode: Opcode.STATISTICS,
222220
groupStart: statisticsStart,
223221
groupLength: statisticsLength,
224222
});
225223
}
226224
if (metadataIndexLength !== 0n) {
227225
builder.writeSummaryOffset({
228-
groupOpcode: McapConstants.Opcode.METADATA_INDEX,
226+
groupOpcode: Opcode.METADATA_INDEX,
229227
groupStart: metadataIndexStart,
230228
groupLength: metadataIndexLength,
231229
});
232230
}
233231
if (attachmentIndexLength !== 0n) {
234232
builder.writeSummaryOffset({
235-
groupOpcode: McapConstants.Opcode.ATTACHMENT_INDEX,
233+
groupOpcode: Opcode.ATTACHMENT_INDEX,
236234
groupStart: attachmentIndexStart,
237235
groupLength: attachmentIndexLength,
238236
});
239237
}
240238
if (chunkIndexLength !== 0n) {
241239
builder.writeSummaryOffset({
242-
groupOpcode: McapConstants.Opcode.CHUNK_INDEX,
240+
groupOpcode: Opcode.CHUNK_INDEX,
243241
groupStart: chunkIndexStart,
244242
groupLength: chunkIndexLength,
245243
});
@@ -255,7 +253,7 @@ function generateFile(features: Set<TestFeatures>, records: TestDataRecord[]) {
255253
);
256254
summaryCrc = crc32Update(summaryCrc, summaryData);
257255
const tempBuffer = new DataView(new ArrayBuffer(1 + 8 + 8 + 8));
258-
tempBuffer.setUint8(0, McapConstants.Opcode.FOOTER);
256+
tempBuffer.setUint8(0, Opcode.FOOTER);
259257
tempBuffer.setBigUint64(1, 8n + 8n + 4n, true);
260258
tempBuffer.setBigUint64(1 + 8, hasSummary ? summaryStart : 0n, true);
261259
tempBuffer.setBigUint64(1 + 8 + 8, summaryOffsetStart, true);

‎tests/conformance/scripts/run-tests/index.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import { McapStreamReader, McapTypes } from "@mcap/core";
1+
import { McapStreamReader } from "@mcap/core";
2+
import type { TypedMcapRecord } from "@mcap/core";
23
import colors from "colors";
34
import { program } from "commander";
45
import * as Diff from "diff";
5-
import fs from "fs/promises";
66
import stableStringify from "json-stable-stringify";
7-
import { chunk } from "lodash";
8-
import path from "path";
7+
import { chunk } from "lodash-es";
8+
import fs from "node:fs/promises";
9+
import path from "node:path";
910

10-
import runners from "./runners";
1111
import {
1212
IndexedReadTestRunner,
1313
StreamedReadTestRunner,
1414
WriteTestRunner,
15-
} from "./runners/TestRunner";
16-
import { toSerializableMcapRecord } from "./toSerializableMcapRecord";
17-
import {
15+
} from "./runners/TestRunner.ts";
16+
import runners from "./runners/index.ts";
17+
import { toSerializableMcapRecord } from "./toSerializableMcapRecord.ts";
18+
import type {
1819
IndexedReadTestResult,
1920
SerializableMcapRecord,
2021
StreamedReadTestResult,
2122
TestCase,
22-
} from "./types";
23-
import { splitMcapRecords } from "../../util/splitMcapRecords";
24-
import generateTestVariants from "../../variants/generateTestVariants";
23+
} from "./types.ts";
24+
import { splitMcapRecords } from "../../util/splitMcapRecords.ts";
25+
import generateTestVariants from "../../variants/generateTestVariants.ts";
2526

2627
type TestOptions = {
2728
dataDir: string;
@@ -142,7 +143,9 @@ async function runWriterTest(
142143
hadError = true;
143144
continue;
144145
}
145-
const expectedParts = splitMcapRecords(expectedOutput).map(spaceHexString).join("\n");
146+
const expectedParts = splitMcapRecords(new Uint8Array(expectedOutput))
147+
.map(spaceHexString)
148+
.join("\n");
146149
const outputParts = splitMcapRecords(output).map(spaceHexString).join("\n");
147150
if (!expectedOutput.equals(output)) {
148151
console.error(colors.red("fail "), path.basename(testCasePath));
@@ -152,7 +155,7 @@ async function runWriterTest(
152155
) as TestCase;
153156
const reader = new McapStreamReader({ validateCrcs: true });
154157
reader.append(output);
155-
const records: McapTypes.TypedMcapRecord[] = [];
158+
const records: TypedMcapRecord[] = [];
156159
for (let record; (record = reader.nextRecord()); ) {
157160
records.push(record);
158161
}

‎tests/conformance/scripts/run-tests/runners/CppIndexedReaderTestRunner.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { exec } from "child_process";
2-
import { join } from "path";
3-
import { promisify } from "util";
4-
import { TestFeatures, TestVariant } from "variants/types";
1+
import { exec } from "node:child_process";
2+
import { join } from "node:path";
3+
import { promisify } from "node:util";
54

6-
import { IndexedReadTestRunner } from "./TestRunner";
7-
import { IndexedReadTestResult } from "../types";
5+
import { IndexedReadTestRunner } from "./TestRunner.ts";
6+
import { TestFeatures } from "../../../variants/types.ts";
7+
import type { TestVariant } from "../../../variants/types.ts";
8+
import type { IndexedReadTestResult } from "../types.ts";
89

910
export default class CppIndexedReaderTestRunner extends IndexedReadTestRunner {
1011
readonly name = "cpp-indexed-reader";
1112

1213
async runReadTest(filePath: string): Promise<IndexedReadTestResult> {
1314
const { stdout } = await promisify(exec)(`./indexed-reader-conformance ${filePath}`, {
14-
cwd: join(__dirname, "../../../../../cpp/test/build/Debug/bin"),
15+
cwd: join(import.meta.dirname, "../../../../../cpp/test/build/Debug/bin"),
1516
});
1617
return JSON.parse(stdout) as IndexedReadTestResult;
1718
}

‎tests/conformance/scripts/run-tests/runners/CppStreamedReaderTestRunner.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { exec } from "child_process";
2-
import { join } from "path";
3-
import { promisify } from "util";
4-
import { TestVariant } from "variants/types";
1+
import { exec } from "node:child_process";
2+
import { join } from "node:path";
3+
import { promisify } from "node:util";
54

6-
import { StreamedReadTestRunner } from "./TestRunner";
7-
import { StreamedReadTestResult } from "../types";
5+
import { StreamedReadTestRunner } from "./TestRunner.ts";
6+
import type { TestVariant } from "../../../variants/types.ts";
7+
import type { StreamedReadTestResult } from "../types.ts";
88

99
export default class CppStreamedReaderTestRunner extends StreamedReadTestRunner {
1010
readonly name = "cpp-streamed-reader";
1111

1212
async runReadTest(filePath: string): Promise<StreamedReadTestResult> {
1313
const { stdout } = await promisify(exec)(`./streamed-reader-conformance ${filePath}`, {
14-
cwd: join(__dirname, "../../../../../cpp/test/build/Debug/bin"),
14+
cwd: join(import.meta.dirname, "../../../../../cpp/test/build/Debug/bin"),
1515
});
1616
return JSON.parse(stdout) as StreamedReadTestResult;
1717
}

‎tests/conformance/scripts/run-tests/runners/CppStreamedWriterTestRunner.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { exec } from "child_process";
2-
import { join } from "path";
3-
import { promisify } from "util";
4-
import { TestFeatures, TestVariant } from "variants/types";
1+
import { exec } from "node:child_process";
2+
import { join } from "node:path";
3+
import { promisify } from "node:util";
54

6-
import { WriteTestRunner } from "./TestRunner";
5+
import { WriteTestRunner } from "./TestRunner.ts";
6+
import { TestFeatures } from "../../../variants/types.ts";
7+
import type { TestVariant } from "../../../variants/types.ts";
78

89
export default class CppStreamedWriterTestRunner extends WriteTestRunner {
910
name = "cpp-streamed-writer";
1011

1112
async runWriteTest(filePath: string): Promise<Uint8Array> {
1213
const { stdout } = await promisify(exec)(`./streamed-writer-conformance ${filePath}`, {
13-
cwd: join(__dirname, "../../../../../cpp/test/build/Debug/bin"),
14+
cwd: join(import.meta.dirname, "../../../../../cpp/test/build/Debug/bin"),
1415
encoding: undefined,
1516
});
1617
return stdout as unknown as Uint8Array;

0 commit comments

Comments
 (0)