Skip to content

Commit

Permalink
fix: support imports with nested enums
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `capnpc-js` is being retired in favor of compiling
directly to js from `capnpc-ts` instead. This makes the one compiler
serve both purposes; js-only users who are annoyed by the extra d.ts
files may simply delete them. This was done to work around bugs in
source-map-support that prevent importing capnp.js files when a
capnp.ts file is also present.
  • Loading branch information
jdiaz5513 committed Aug 19, 2021
1 parent 6e89b75 commit 64778e0
Show file tree
Hide file tree
Showing 63 changed files with 355 additions and 64,437 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
with:
check-latest: true
node-version: ${{ matrix.node-version }}
- name: Install capnproto
run: sudo apt-get install capnproto libcapnp-dev
- name: Install dependencies
run: |
npm i -g npm@latest
Expand Down
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"DEBUG": "capnp:*",
"NODE_ENV": "development"
},
"outFiles": [
"${workspaceRoot}/packages/*/lib-test/**/*"
],
"name": "Debug (Test)",
"preLaunchTask": "build",
"program": "${file}",
Expand Down
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"build/Release": true,
"coverage": true,
"packages/*/bin/**/*.d.ts": true,
"packages/*/bin/**/*.js": true,
"packages/*/src/**/*.d.ts": true,
"packages/*/src/**/*.js": true,
"packages/*/test/**/*.d.ts": true,
Expand All @@ -46,7 +45,6 @@
"**/lib": true,
"**/lib-test": true,
"packages/*/bin/**/*.d.ts": true,
"packages/*/bin/**/*.js": true,
"packages/*/src/**/*.d.ts": true,
"packages/*/src/**/*.js": true,
"packages/*/test/**/*.d.ts": true,
Expand Down
59 changes: 31 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SHELL := bash
CAPNP_BIN := capnp
TAP_FLAGS ?= -j8 --no-coverage --ts -Rterse -c
TAP_TS := 1
TSC_FLAGS ?= --incremental
TSC_FLAGS ?=
STANDARD_FLAGS ?= --dry-run

##############
Expand All @@ -33,63 +33,67 @@ npm := $(shell which npm)
# vars

capnp_ts := packages/capnp-ts
capnpc_js := packages/capnpc-js
capnpc_ts := packages/capnpc-ts
js_examples := packages/js_examples

capnp_deps := $(shell find packages/capnp-ts/src -name '*.ts' -not -name '*.d.ts' -print)
capnp_deps := $(capnp_deps) $(shell find packages/capnpc-ts/src -name '*.ts' -not -name '*.d.ts' -print)

specs_in := $(shell find packages -name '*.spec.ts' -print)
specs_out := $(patsubst %.ts,%.js,$(specs_in))
capnp_in := $(shell find packages -name '*.capnp' -print)
capnp_out := $(patsubst %.capnp,%.capnp.ts,$(capnp_in))

###############
# build targets

%.capnp.ts: build
%.capnp.ts: %.capnp
@echo [capnpc] compiling $<...
$(capnpc) -o./$(capnpc_ts)/bin/capnpc-ts.js -I $(capnp_ts)/src/std $<
capnp_out := $(patsubst %.capnp,%.capnp.js,$(capnp_in))

################
# build commands

%.capnp.js: $(capnp_deps)
%.capnp.js: %.capnp
$(capnpc) -o./$(capnpc_ts)/bin/capnpc-ts.js -I $(capnp_ts)/src/std $<

.PHONY: benchmark
benchmark: build
benchmark:
@echo [tap] running benchmarks...
@echo
@echo =============================
$(node) $(capnp_ts)/benchmark/index.js
@echo

.PHONY: build-prelude
build-prelude:
$(tsc) -p tsconfig.prelude.json

.PHONY: build-src
build-src: build-prelude
$(tsc) -p tsconfig.src.json

.PHONY: build-capnp
build-capnp: build-src
build-capnp: $(capnp_out)

.PHONY: build-test
build-test: build-capnp
$(tsc) -p tsconfig.test.json

.PHONY: build
build: $(capnp_out)
@echo [tsc] compiling...
$(tsc) -p packages/capnp-ts/tsconfig.json
$(tsc) -p packages/capnp-ts-test/tsconfig.json
$(tsc) -p packages/capnpc-ts/tsconfig.json
$(tsc) -p packages/capnpc-js/tsconfig.json
build: build-test

.PHONY: clean
clean:
find packages -name "*.d.ts" | xargs -r rm
find packages -name "*.js" -not -path "*/bin/*" | xargs -r rm
find packages -name "*.map" | xargs -r rm
find packages -name "*.tsbuildinfo" | xargs -r rm
@find packages -name "*.d.ts" -not -path "*/node_modules/*" | xargs -r rm
@find packages -name "*.js" -not -path "*/bin/*" -not -path "*/node_modules/*" | xargs -r rm
@find packages -name "*.map" -not -path "*/node_modules/*" | xargs -r rm
@find packages -name "*.tsbuildinfo" -not -path "*/node_modules/*" | xargs -r rm
@rm -f $(capnp_out)

.PHONY: test
test: build
@echo [tap] running tests...
@$(tap) $(specs_out)

.PHONY: coverage
coverage: build
@echo [tap] generating coverage report...
@$(tap) --coverage $(specs_in)

.PHONY: lint
lint: build
@echo [eslint] running lint checkers...
$(eslint) . --ext .ts

.PHONY: release
Expand All @@ -99,5 +103,4 @@ release: build
.PHONY: publish
publish:
$(npm) publish -w capnp-ts
$(npm) publish -w capnpc-js
$(npm) publish -w capnpc-ts
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ To read a message, do something like the following:
```typescript
import * as capnp from "capnp-ts";

import { MyStruct } from "./myschema.capnp";
import { MyStruct } from "./myschema.capnp.js";

export function loadMessage(buffer: ArrayBuffer): MyStruct {
const message = new capnp.Message(buffer);
Expand Down
Loading

0 comments on commit 64778e0

Please sign in to comment.