Skip to content

Commit 15f6d38

Browse files
committed
[TS/JS] Entry point per namespace
1 parent c92e78a commit 15f6d38

File tree

137 files changed

+7402
-14543
lines changed

Some content is hidden

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

137 files changed

+7402
-14543
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ jobs:
3939
chmod +x flatc
4040
./flatc --version
4141
- name: flatc tests
42-
run: python3 tests/flatc/main.py
42+
run: |
43+
yarn global add esbuild
44+
python3 tests/flatc/main.py
4345
- name: upload build artifacts
4446
uses: actions/upload-artifact@v1
4547
with:
@@ -460,7 +462,9 @@ jobs:
460462
run: yarn compile
461463
- name: test
462464
working-directory: tests/ts
463-
run: python3 TypeScriptTest.py
465+
run: |
466+
yarn global add esbuild
467+
python3 TypeScriptTest.py
464468
465469
build-dart:
466470
name: Build Dart

include/flatbuffers/idl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ struct IDLOptions {
632632
bool json_nested_flatbuffers;
633633
bool json_nested_flexbuffers;
634634
bool json_nested_legacy_flatbuffers;
635-
bool ts_flat_file;
635+
bool ts_flat_files;
636+
bool ts_entry_points;
636637
bool no_leak_private_annotations;
637638

638639
// Possible options for the more general generator below.
@@ -732,7 +733,8 @@ struct IDLOptions {
732733
json_nested_flatbuffers(true),
733734
json_nested_flexbuffers(true),
734735
json_nested_legacy_flatbuffers(false),
735-
ts_flat_file(false),
736+
ts_flat_files(false),
737+
ts_entry_points(false),
736738
no_leak_private_annotations(false),
737739
mini_reflect(IDLOptions::kNone),
738740
require_explicit_ids(false),

package.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,28 @@
99
"mjs/**/*.d.ts",
1010
"ts/**/*.ts"
1111
],
12-
"main": "js/index.js",
13-
"module": "mjs/index.js",
12+
"main": "js/flatbuffers.js",
13+
"module": "mjs/flatbuffers.js",
14+
"exports": {
15+
".": {
16+
"node": {
17+
"import": "./mjs/flatbuffers.js",
18+
"require": "./js/flatbuffers.js"
19+
},
20+
"default": "./js/flatbuffers.js"
21+
},
22+
"./js/flexbuffers.js": {
23+
"default": "./js/flexbuffers.js"
24+
}
25+
},
1426
"directories": {
1527
"doc": "docs",
1628
"test": "tests"
1729
},
1830
"scripts": {
1931
"test": "npm run compile && cd tests/ts && python3 ./TypeScriptTest.py",
2032
"lint": "eslint ts",
21-
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c",
33+
"compile": "tsc && tsc -p tsconfig.mjs.json && esbuild js/flatbuffers.js --minify --global-name=flatbuffers --bundle --outfile=js/flatbuffers.min.js",
2234
"prepublishOnly": "npm install --only=dev && npm run compile"
2335
},
2436
"repository": {
@@ -40,8 +52,8 @@
4052
"@types/node": "18.7.16",
4153
"@typescript-eslint/eslint-plugin": "^5.36.2",
4254
"@typescript-eslint/parser": "^5.36.2",
55+
"esbuild": "^0.15.10",
4356
"eslint": "^8.23.1",
44-
"rollup": "^2.79.0",
4557
"typescript": "^4.8.3"
4658
}
4759
}

rollup.config.js

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

scripts/generate_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def glob(path, pattern):
263263

264264
# Generate the complete flat file TS of monster.
265265
flatc(
266-
["--ts", "--gen-all", "--ts-flat-files"],
266+
["--ts", "--gen-all"],
267267
include="include_test",
268268
schema="monster_test.fbs",
269269
prefix="ts/ts-flat-files"

src/flatc.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ const static FlatCOption options[] = {
218218
"Allow a nested_flatbuffer field to be parsed as a vector of bytes"
219219
"in JSON, which is unsafe unless checked by a verifier afterwards." },
220220
{ "", "ts-flat-files", "",
221-
"Only generated one typescript file per .fbs file." },
221+
"Generate a single typescript file per .fbs file. Implies ts_entry_points." },
222+
{ "", "ts-entry-points", "",
223+
"Generate entry point typescript per namespace. Implies gen-all." },
222224
{ "", "annotate", "SCHEMA",
223225
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
224226
{ "", "no-leak-private-annotation", "",
@@ -598,7 +600,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
598600
} else if (arg == "--json-nested-bytes") {
599601
opts.json_nested_legacy_flatbuffers = true;
600602
} else if (arg == "--ts-flat-files") {
601-
opts.ts_flat_file = true;
603+
opts.ts_flat_files = true;
604+
opts.ts_entry_points = true;
605+
opts.generate_all = true;
606+
} else if (arg == "--ts-entry-points") {
607+
opts.ts_entry_points = true;
608+
opts.generate_all = true;
602609
} else if (arg == "--no-leak-private-annotation") {
603610
opts.no_leak_private_annotations = true;
604611
} else if (arg == "--annotate") {

0 commit comments

Comments
 (0)