Skip to content

Commit

Permalink
[TS/JS] Entry point per namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharrtell committed Oct 5, 2022
1 parent c92e78a commit 15f6d38
Show file tree
Hide file tree
Showing 137 changed files with 7,402 additions and 14,543 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -39,7 +39,9 @@ jobs:
chmod +x flatc
./flatc --version
- name: flatc tests
run: python3 tests/flatc/main.py
run: |
yarn global add esbuild
python3 tests/flatc/main.py
- name: upload build artifacts
uses: actions/upload-artifact@v1
with:
Expand Down Expand Up @@ -460,7 +462,9 @@ jobs:
run: yarn compile
- name: test
working-directory: tests/ts
run: python3 TypeScriptTest.py
run: |
yarn global add esbuild
python3 TypeScriptTest.py
build-dart:
name: Build Dart
Expand Down
6 changes: 4 additions & 2 deletions include/flatbuffers/idl.h
Expand Up @@ -632,7 +632,8 @@ struct IDLOptions {
bool json_nested_flatbuffers;
bool json_nested_flexbuffers;
bool json_nested_legacy_flatbuffers;
bool ts_flat_file;
bool ts_flat_files;
bool ts_entry_points;
bool no_leak_private_annotations;

// Possible options for the more general generator below.
Expand Down Expand Up @@ -732,7 +733,8 @@ struct IDLOptions {
json_nested_flatbuffers(true),
json_nested_flexbuffers(true),
json_nested_legacy_flatbuffers(false),
ts_flat_file(false),
ts_flat_files(false),
ts_entry_points(false),
no_leak_private_annotations(false),
mini_reflect(IDLOptions::kNone),
require_explicit_ids(false),
Expand Down
20 changes: 16 additions & 4 deletions package.json
Expand Up @@ -9,16 +9,28 @@
"mjs/**/*.d.ts",
"ts/**/*.ts"
],
"main": "js/index.js",
"module": "mjs/index.js",
"main": "js/flatbuffers.js",
"module": "mjs/flatbuffers.js",
"exports": {
".": {
"node": {
"import": "./mjs/flatbuffers.js",
"require": "./js/flatbuffers.js"
},
"default": "./js/flatbuffers.js"
},
"./js/flexbuffers.js": {
"default": "./js/flexbuffers.js"
}
},
"directories": {
"doc": "docs",
"test": "tests"
},
"scripts": {
"test": "npm run compile && cd tests/ts && python3 ./TypeScriptTest.py",
"lint": "eslint ts",
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c",
"compile": "tsc && tsc -p tsconfig.mjs.json && esbuild js/flatbuffers.js --minify --global-name=flatbuffers --bundle --outfile=js/flatbuffers.min.js",
"prepublishOnly": "npm install --only=dev && npm run compile"
},
"repository": {
Expand All @@ -40,8 +52,8 @@
"@types/node": "18.7.16",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"esbuild": "^0.15.10",
"eslint": "^8.23.1",
"rollup": "^2.79.0",
"typescript": "^4.8.3"
}
}
8 changes: 0 additions & 8 deletions rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/generate_code.py
Expand Up @@ -263,7 +263,7 @@ def glob(path, pattern):

# Generate the complete flat file TS of monster.
flatc(
["--ts", "--gen-all", "--ts-flat-files"],
["--ts", "--gen-all"],
include="include_test",
schema="monster_test.fbs",
prefix="ts/ts-flat-files"
Expand Down
11 changes: 9 additions & 2 deletions src/flatc.cpp
Expand Up @@ -218,7 +218,9 @@ const static FlatCOption options[] = {
"Allow a nested_flatbuffer field to be parsed as a vector of bytes"
"in JSON, which is unsafe unless checked by a verifier afterwards." },
{ "", "ts-flat-files", "",
"Only generated one typescript file per .fbs file." },
"Generate a single typescript file per .fbs file. Implies ts_entry_points." },
{ "", "ts-entry-points", "",
"Generate entry point typescript per namespace. Implies gen-all." },
{ "", "annotate", "SCHEMA",
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
{ "", "no-leak-private-annotation", "",
Expand Down Expand Up @@ -598,7 +600,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
} else if (arg == "--json-nested-bytes") {
opts.json_nested_legacy_flatbuffers = true;
} else if (arg == "--ts-flat-files") {
opts.ts_flat_file = true;
opts.ts_flat_files = true;
opts.ts_entry_points = true;
opts.generate_all = true;
} else if (arg == "--ts-entry-points") {
opts.ts_entry_points = true;
opts.generate_all = true;
} else if (arg == "--no-leak-private-annotation") {
opts.no_leak_private_annotations = true;
} else if (arg == "--annotate") {
Expand Down

0 comments on commit 15f6d38

Please sign in to comment.