Skip to content

Commit

Permalink
Move typescript package into subdirectory (#170)
Browse files Browse the repository at this point in the history
### Changelog
None

### Docs
None

### Description
Migrate `@foxglove/schemas` typescript package into `typescript`
directory. This prepares for other typescript packages to live in this
repo.

Also restrict to only necessary files included in the npm package.
  • Loading branch information
amacneil authored Feb 6, 2025
1 parent 7cd2bd1 commit ee094ad
Show file tree
Hide file tree
Showing 85 changed files with 176 additions and 71 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ jobs:

- run: yarn install --immutable
- run: yarn lint:ci
- run: yarn typecheck

# must run this first because it copies the jsonschema directory
- run: yarn workspace @foxglove/schemas build

# typecheck remaining files in the repo
- run: yarn build

- run: yarn test
- run: yarn update-generated-files

- name: Ensure generated files are up to date
run: |
yarn update-generated-files
git add --all
changes=$(git status --porcelain)
if [ -n "$changes" ]; then
Expand All @@ -97,7 +103,7 @@ jobs:

- name: Publish to NPM
if: startsWith(github.ref, 'refs/tags/typescript/v')
run: yarn publish --access public
run: yarn npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
.catkin_tools
.DS_Store
.idea/
.mypy_cache/
.pytest_cache/
.yarn/
.idea/
*.py[cod]
*.so
/python/**/dist/
*.tsbuildinfo
/python/*/dist/
/python/foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/*.bfbs
/python/foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/*.py
/python/foxglove-schemas-protobuf/foxglove_schemas_protobuf/*.py
/python/foxglove-schemas-protobuf/foxglove_schemas_protobuf/*.pyi
/python/foxglove-sdk/python/foxglove/_protobuf/
/target/
/typescript/*/dist/
/typescript/schemas/src/jsonschema/
node_modules/
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import foxglove from "@foxglove/eslint-plugin";
import globals from "globals";
import tseslint from "typescript-eslint";

export default tseslint.config(
{
ignores: ["**/dist"],
},
...foxglove.configs.base,
{
files: ["**/*.js"],
languageOptions: {
globals: {
...globals.node,
},
},
},
...foxglove.configs.typescript.map((config) => ({
...config,
files: ["**/*.ts"],
Expand Down
3 changes: 0 additions & 3 deletions jsonschema/index.ts

This file was deleted.

32 changes: 8 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
{
"name": "@foxglove/schemas",
"version": "1.6.6",
"description": "Foxglove-defined message schemas for ROS, Protobuf, FlatBuffers, OMG IDL, and JSON",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/foxglove/schemas.git"
},
"author": {
"name": "Foxglove Technologies Inc",
"email": "[email protected]"
},
"engines": {
"node": ">=16"
},
"name": "foxglove-sdk",
"private": true,
"packageManager": "[email protected]",
"main": "schemas/typescript/index.js",
"typings": "schemas/typescript/index.d.ts",
"workspaces": [
"typescript/*"
],
"scripts": {
"prepack": "yarn update-generated-files && tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
"build": "tsc -b",
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --report-unused-disable-directives --fix .",
"test": "jest",
"update-generated-files": "yarn test --updateSnapshot && ts-node --files --project tsconfig.json ./scripts/updateGeneratedFiles.ts --out-dir schemas --ros-out-dir ros_foxglove_msgs"
"update-generated-files": "ts-node --files --project tsconfig.json ./scripts/updateGeneratedFiles.ts --out-dir schemas --ros-out-dir ros_foxglove_msgs && yarn test --updateSnapshot"
},
"devDependencies": {
"@foxglove/eslint-plugin": "2.0.0",
Expand All @@ -43,6 +30,7 @@
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.11.0",
"eslint-plugin-prettier": "5.2.3",
"globals": "^15.14.0",
"jest": "29.7.0",
"prettier": "^3.4.2",
"prettier-plugin-toml": "^2.0.1",
Expand All @@ -51,9 +39,5 @@
"ts-jest": "29.2.5",
"ts-node": "^10.9.2",
"typescript": "5.7.3"
},
"dependencies": {
"@foxglove/rosmsg-msgs-common": "^3.0.0",
"tslib": "^2.8.1"
}
}
30 changes: 20 additions & 10 deletions scripts/updateGeneratedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ import fs from "fs/promises";
import path from "path";
import { rimraf } from "rimraf";

import { generateRosMsg, generateRosMsgDefinition } from "../internal";
import { exportTypeScriptSchemas } from "../internal/exportTypeScriptSchemas";
import { generateRosMsg, generateRosMsgDefinition } from "../typescript/schemas/src/internal";
import { exportTypeScriptSchemas } from "../typescript/schemas/src/internal/exportTypeScriptSchemas";
import {
BYTE_VECTOR_FB,
DURATION_FB,
TIME_FB,
generateFlatbuffers,
} from "../internal/generateFlatbufferSchema";
import { generateJsonSchema } from "../internal/generateJsonSchema";
import { generateMarkdown } from "../internal/generateMarkdown";
import { DURATION_IDL, TIME_IDL, generateOmgIdl } from "../internal/generateOmgIdl";
import { generateProto } from "../internal/generateProto";
import { foxgloveEnumSchemas, foxgloveMessageSchemas } from "../internal/schemas";
} from "../typescript/schemas/src/internal/generateFlatbufferSchema";
import { generateJsonSchema } from "../typescript/schemas/src/internal/generateJsonSchema";
import { generateMarkdown } from "../typescript/schemas/src/internal/generateMarkdown";
import {
DURATION_IDL,
TIME_IDL,
generateOmgIdl,
} from "../typescript/schemas/src/internal/generateOmgIdl";
import { generateProto } from "../typescript/schemas/src/internal/generateProto";
import {
foxgloveEnumSchemas,
foxgloveMessageSchemas,
} from "../typescript/schemas/src/internal/schemas";

async function logProgress(message: string, body: () => Promise<void>) {
process.stderr.write(`${message}... `);
Expand Down Expand Up @@ -101,10 +108,13 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string }
});

await logProgress("Generating TypeScript definitions", async () => {
await fs.mkdir(path.join(outDir, "typescript"), { recursive: true });
const typesDir = path.join(outDir, "../typescript/schemas/src/types");
await rimraf(typesDir);
await fs.mkdir(typesDir, { recursive: true });

const schemas = exportTypeScriptSchemas();
for (const [name, source] of schemas.entries()) {
await fs.writeFile(path.join(outDir, "typescript", `${name}.ts`), source);
await fs.writeFile(path.join(typesDir, `${name}.ts`), source);
}
});

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compilerOptions": {
"rootDir": ".",
"module": "commonjs",
"lib": ["es2020", "dom"]
"lib": ["es2020"],
"noEmit": true
}
}
18 changes: 18 additions & 0 deletions typescript/schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @foxglove/schemas

This package contains TypeScript type definitions and JSON Schemas for the Foxglove schemas.

## Installation

```bash
npm install @foxglove/schemas
```

## Usage

For a list of available schemas, see https://docs.foxglove.dev/docs/visualization/message-schemas/introduction

```ts
import type { CompressedImage } from '@foxglove/schemas';
import { CompressedImage } from '@foxglove/schemas/jsonschema';
```
1 change: 1 addition & 0 deletions typescript/schemas/internal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/internal/index";
2 changes: 2 additions & 0 deletions typescript/schemas/internal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// allows importing @foxglove/schemas/internal
module.exports = require("./dist/internal/index.js");
1 change: 1 addition & 0 deletions typescript/schemas/jsonschema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/jsonschema/index";
2 changes: 2 additions & 0 deletions typescript/schemas/jsonschema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// allows importing @foxglove/schemas/jsonschema
module.exports = require("./dist/jsonschema/index.js");
39 changes: 39 additions & 0 deletions typescript/schemas/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@foxglove/schemas",
"version": "1.6.6",
"description": "Foxglove-defined message schemas for ROS, Protobuf, FlatBuffers, OMG IDL, and JSON",
"license": "MIT",
"author": {
"name": "Foxglove",
"email": "[email protected]",
"url": "https://foxglove.dev/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/foxglove/foxglove-sdk.git",
"directory": "typescript/schemas"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"internal.d.ts",
"internal.js",
"jsonschema.d.ts",
"jsonschema.js"
],
"packageManager": "[email protected]",
"scripts": {
"build": "cp -R ../../schemas/jsonschema ./src/jsonschema && tsc -b",
"clean": "git clean -Xdf",
"prepack": "yarn clean && yarn build"
},
"dependencies": {
"tslib": "^2"
},
"devDependencies": {
"@foxglove/rosmsg-msgs-common": "^3.0.0",
"rimraf": "^6.0.1",
"typescript": "5.7.3"
}
}
1 change: 1 addition & 0 deletions typescript/schemas/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./types/index";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("generateTypeScript", () => {
});

it("generates parseable .ts files", async () => {
await expect(import("../schemas/typescript")).resolves.not.toThrow();
await expect(import("../types")).resolves.not.toThrow();
});

it("can include TypedArray types", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions typescript/schemas/src/jsonschema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file only exists to ensure the jsonschema directory was copied.
// If you get an build error you need to run `yarn build` first.
export * from "./jsonschema/index";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions typescript/schemas/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@foxglove/tsconfig/base",
"include": ["./**/*"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"module": "commonjs",
"lib": ["es2020"],
"noEmit": false
}
}
71 changes: 44 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -691,36 +691,13 @@ __metadata:
languageName: node
linkType: hard

"@foxglove/schemas@workspace:.":
"@foxglove/schemas@workspace:typescript/schemas":
version: 0.0.0-use.local
resolution: "@foxglove/schemas@workspace:."
resolution: "@foxglove/schemas@workspace:typescript/schemas"
dependencies:
"@foxglove/eslint-plugin": "npm:2.0.0"
"@foxglove/omgidl-parser": "npm:^0.2.0"
"@foxglove/rosmsg": "npm:^4.0.0"
"@foxglove/rosmsg-msgs-common": "npm:^3.0.0"
"@foxglove/tsconfig": "npm:2.0.0"
"@types/jest": "npm:29.5.14"
"@types/node": "npm:22.13.0"
"@typescript-eslint/eslint-plugin": "npm:8.22.0"
"@typescript-eslint/parser": "npm:8.22.0"
ajv: "npm:^8.12.0"
commander: "npm:^10.0.0"
eslint: "npm:9.19.0"
eslint-config-prettier: "npm:10.0.1"
eslint-plugin-es: "npm:4.1.0"
eslint-plugin-filenames: "npm:1.3.2"
eslint-plugin-import: "npm:2.31.0"
eslint-plugin-jest: "npm:28.11.0"
eslint-plugin-prettier: "npm:5.2.3"
jest: "npm:29.7.0"
prettier: "npm:^3.4.2"
prettier-plugin-toml: "npm:^2.0.1"
protobufjs: "npm:^7.2.2"
rimraf: "npm:^6.0.1"
ts-jest: "npm:29.2.5"
ts-node: "npm:^10.9.2"
tslib: "npm:^2.8.1"
tslib: "npm:^2"
typescript: "npm:5.7.3"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -3428,6 +3405,39 @@ __metadata:
languageName: node
linkType: hard

"foxglove-sdk@workspace:.":
version: 0.0.0-use.local
resolution: "foxglove-sdk@workspace:."
dependencies:
"@foxglove/eslint-plugin": "npm:2.0.0"
"@foxglove/omgidl-parser": "npm:^0.2.0"
"@foxglove/rosmsg": "npm:^4.0.0"
"@foxglove/tsconfig": "npm:2.0.0"
"@types/jest": "npm:29.5.14"
"@types/node": "npm:22.13.0"
"@typescript-eslint/eslint-plugin": "npm:8.22.0"
"@typescript-eslint/parser": "npm:8.22.0"
ajv: "npm:^8.12.0"
commander: "npm:^10.0.0"
eslint: "npm:9.19.0"
eslint-config-prettier: "npm:10.0.1"
eslint-plugin-es: "npm:4.1.0"
eslint-plugin-filenames: "npm:1.3.2"
eslint-plugin-import: "npm:2.31.0"
eslint-plugin-jest: "npm:28.11.0"
eslint-plugin-prettier: "npm:5.2.3"
globals: "npm:^15.14.0"
jest: "npm:29.7.0"
prettier: "npm:^3.4.2"
prettier-plugin-toml: "npm:^2.0.1"
protobufjs: "npm:^7.2.2"
rimraf: "npm:^6.0.1"
ts-jest: "npm:29.2.5"
ts-node: "npm:^10.9.2"
typescript: "npm:5.7.3"
languageName: unknown
linkType: soft

"fs-minipass@npm:^3.0.0":
version: 3.0.3
resolution: "fs-minipass@npm:3.0.3"
Expand Down Expand Up @@ -3687,6 +3697,13 @@ __metadata:
languageName: node
linkType: hard

"globals@npm:^15.14.0":
version: 15.14.0
resolution: "globals@npm:15.14.0"
checksum: 10c0/039deb8648bd373b7940c15df9f96ab7508fe92b31bbd39cbd1c1a740bd26db12457aa3e5d211553b234f30e9b1db2fee3683012f543a01a6942c9062857facb
languageName: node
linkType: hard

"globalthis@npm:^1.0.3":
version: 1.0.3
resolution: "globalthis@npm:1.0.3"
Expand Down Expand Up @@ -6941,7 +6958,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.6.2, tslib@npm:^2.8.1":
"tslib@npm:^2.6.2":
version: 2.8.1
resolution: "tslib@npm:2.8.1"
checksum: 10c0/9c4759110a19c53f992d9aae23aac5ced636e99887b51b9e61def52611732872ff7668757d4e4c61f19691e36f4da981cd9485e869b4a7408d689f6bf1f14e62
Expand Down

0 comments on commit ee094ad

Please sign in to comment.