Skip to content

Commit

Permalink
Export TS types from main; move generation exports under internal (f…
Browse files Browse the repository at this point in the history
…oxglove#63)

**Public-Facing Changes**
Moved TypeScript types and enums to the main `@foxglove/schemas` entry
point; moved raw schema structures and generation functions to
`@foxglove/schemas/internal` entry point. Added
`@foxglove/schemas/jsonschema` entry point for JSON Schema.

Removed ESM outputs because without full package.json `"exports"`
support, importing from `@foxglove/schemas/internal` can only point to
one place, not intelligently one of `dist/cjs` or `dist/esm`. This
required removing the tsconfig `outDir`, so output files are placed
alongside source files.

The import syntax is now:
```ts
import { CompressedImage } from "@foxglove/schemas";  // TS type or enum
import { CompressedImage } from "@foxglove/schemas/jsonschema"; // json schema as POJO
import { foxgloveMessageSchemas } from "@foxglove/schemas/internal"; // internal representation of all schemas
```

**Description**
Resolves foxglove#41
  • Loading branch information
jtbandes authored Sep 20, 2022
1 parent 0de3bd0 commit 1192685
Show file tree
Hide file tree
Showing 23 changed files with 4,797 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ These schemas can be used in [MCAP](https://github.com/foxglove/mcap) files or [

## Development

The schema definitions are in [src/schemas.ts](src/schemas.ts).
The schema definitions are in [internal/schemas.ts](internal/schemas.ts).

After editing the schemas, re-generate the language-specific definitions by running `yarn update-generated-files`.

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/generateMarkdown.ts → internal/generateMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function generateMarkdown(
See [Foxglove Schemas documentation](https://foxglove.dev/docs/studio/messages).
All schemas are generated from [schemas.ts](/src/schemas.ts).`,
All schemas are generated from [schemas.ts](/internal/schemas.ts).`,

"## Contents",

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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"testMatch": ["<rootDir>/src/**/*.test.ts"],
"testMatch": ["<rootDir>/**/*.test.ts"],
"transform": {
"^.+\\.ts$": [
"ts-jest",
Expand Down
3 changes: 3 additions & 0 deletions jsonschema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists to allow packages to import via `import { Foo } from "@foxglove/schemas/jsonschema"`.

export * from "../schemas/jsonschema";
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
"name": "Foxglove Technologies",
"email": "[email protected]"
},
"module": "dist/esm/src/index.js",
"main": "dist/cjs/src/index.js",
"typings": "dist/esm/src/index.d.ts",
"engines": {
"node": ">=16"
},
"main": "schemas/typescript/index.js",
"typings": "schemas/typescript/index.d.ts",
"scripts": {
"prepack": "tsc -b tsconfig.json tsconfig.cjs.json && yarn update-generated-files",
"prepack": "yarn update-generated-files && tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --report-unused-disable-directives --fix .",
"test": "jest",
"update-generated-files": "ts-node --files --project tsconfig.cjs.json scripts/updateGeneratedFiles --out-dir schemas --ros-out-dir ros_foxglove_msgs"
"update-generated-files": "ts-node --files --project tsconfig.json scripts/updateGeneratedFiles --out-dir schemas --ros-out-dir ros_foxglove_msgs"
},
"devDependencies": {
"@foxglove/eslint-plugin": "0.20.0",
Expand Down
2 changes: 1 addition & 1 deletion schemas/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1192685

Please sign in to comment.