Skip to content

Commit dbc372a

Browse files
authored
Merge pull request #46 from STRd6/types
Types; convert to civet
2 parents 448cf78 + a179594 commit dbc372a

Some content is hidden

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

67 files changed

+1976
-4674
lines changed

.github/workflows/build.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99

10-
- uses: actions/checkout@v1
10+
- uses: actions/checkout@v4
1111

12-
- name: Setup Node.js 16.x
13-
uses: actions/setup-node@v2
12+
- name: Setup Node.js 20.x
13+
uses: actions/setup-node@v4
1414
with:
1515
cache: yarn
16-
node-version: 16.x
16+
node-version: 20.x
1717

1818
- name: Install and Test
1919
run: |
2020
yarn
21+
yarn build
2122
yarn test
2223
2324
- name: Coveralls

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist/
66
gh-pages/
77
node_modules/
88
test/samples/*.js
9+
test/fixtures/out/

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"phil294.coffeesense",
4+
"DanielX.hera"
5+
]
6+
}

NOTES.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
TypeScript
2+
==========
3+
4+
esbuild is a real stickler with extensions so it is necessary to require "parser.hera".
5+
TypeScript then needs a parser.hera.d.ts to work with CoffeeSense. Alternatively
6+
an esbuild resolver plugin could be used.
7+
8+
So far the clean way of handling it is to declare all the types in `./types/`
9+
and import then `export = SomeType` in the individual .d.ts files adjacent
10+
to the sources.
11+
12+
Building with `tsc` is not necessary if we're only using CoffeeScript sources
13+
since `./types/main.d.ts` is pointed to by the `type` field in `package.json`.
14+
If there are other TypeScript sources then `tsc` will need to be involved in the
15+
build process.
16+
17+
`export =` vs `export default`
18+
---
19+
20+
`export = Something` is necessary for `Something = require('...')` to get picked
21+
up properly. `export default Something` works with `{default:Something} = require...`
22+
23+
`export =` cannot be used with `export {something}`.
24+
25+
Since all the modern tools are moving in the direction of ES6 import/export it
26+
may simplify integration with some tools to also move in that direction.
27+
28+
Ambient Declarations
29+
---
30+
31+
A typescript file that exports will ignore ambient `declare` statements. In
32+
order to have ambient they must all be `declare`.
33+
34+
Ambient declarations also cannot import other types but a work around is to use
35+
`declare global` and put vars inside there. See [./types/ambient.d.ts](./types/ambient.d.ts)
36+
37+
Namespaces as types
38+
---
39+
40+
Cannot use namespace 'Observable' as type.
41+
42+
use `typeof Observable`
43+
44+
TypeDoc
45+
-------
46+
47+
TypeDoc seems to work pretty good by default when using `.ts` files with ES6
48+
style exports.
49+
50+
TypeDoc and other more modern tools strongly prefer ES6 module imports/exports.
51+
`.d.ts` files prefer it (there is no way to both `export =` and also have named
52+
exports even if those exports are just types).
53+
54+
JSDoc
55+
---
56+
57+
JS written with JSDoc type annotations and compiled with `tsc -d --allowJs` will
58+
output type declarations.
59+
60+
CoffeeSense + TypeScript
61+
---
62+
63+
VSCode Intellisense is the primary documentation target. That means that the
64+
docs should be optimized for how things appear in the IDE. 2nd target is a
65+
standalone website generated by TypeDoc or some other tool. Still need to test
66+
TypeDoc with a .coffee -> .js -> .d.ts -> TypeDoc pipeline and see how it goes.
67+
68+
Need to set `checkJs` to true or add `#@ts-check` to enable type checking in
69+
CoffeeSense.
70+
71+
It is possible to alias a bunch of imported types at the top to make using
72+
comments for inline types easier inside the file.
73+
74+
```coffee
75+
###*
76+
@typedef {import("../types/types").Element} El
77+
@typedef {import("../types/types").Context} Context
78+
@typedef {import("../types/types").JadeletAttribute} JadeletAttribute
79+
@typedef {import("../types/types").JadeletAST} JadeletAST
80+
###
81+
```

TODO.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TODO
2+
====
3+
4+
- [ ] Explore Custom elements
5+
- [ ] Optionally pass `document` when rendering?
6+
- [x] Explore adding TypeScript typings
7+
- [x] declare "jadelet/esbuild-plugin" module
8+
- [x] Figure out secrets of CoffeeSense and workspace setup
9+
- [x] Publishing types
10+
- [x] esbuild plugin
11+
- [x] Use esbuild for publishing
12+
- [x] main
13+
- [x] cli
14+
- [x] browser
15+
- [x] Update to @danielx/observable
16+
- [x] Update register
17+
- [x] Update to hera 0.7.3-pre.3

build/build.civet

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
esbuild from esbuild
2+
civetPlugin from @danielx/civet/esbuild
3+
heraPlugin from @danielx/hera/esbuild-plugin
4+
5+
esbuild.build
6+
entryPoints: ['source/index.civet']
7+
format: 'esm'
8+
tsconfig: "./tsconfig.json"
9+
bundle: true
10+
sourcemap: true
11+
outdir: 'dist/'
12+
outExtension:
13+
".js": ".mjs"
14+
plugins: [
15+
civetPlugin
16+
ts: "civet"
17+
emitDeclaration: true
18+
heraPlugin
19+
module: true
20+
]
21+
.catch ->
22+
process.exit 1
23+
24+
esbuild.build
25+
entryPoints: ['source/index.civet']
26+
format: 'cjs'
27+
tsconfig: "./tsconfig.json"
28+
bundle: true
29+
sourcemap: true
30+
outdir: 'dist/'
31+
plugins: [
32+
civetPlugin
33+
ts: "civet"
34+
heraPlugin
35+
module: true
36+
]
37+
.catch ->
38+
process.exit 1
39+
40+
esbuild.build({
41+
entryPoints: ['source/cli.civet']
42+
platform: 'node'
43+
format: 'cjs'
44+
outfile: 'dist/cli.js'
45+
plugins: [
46+
civetPlugin
47+
ts: "civet"
48+
]
49+
}).catch -> process.exit 1

build/build.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/bash
2+
3+
set -eoux pipefail
4+
shopt -s globstar
5+
6+
rm -rf dist
7+
8+
# build
9+
civet build/build.civet
10+
11+
# adjust .d.ts files
12+
for f in dist/**/*.civet.d.ts; do
13+
# replace all .civet imports with .js
14+
sed -i 's/\.civet"/.js"/g' "$f"
15+
mv "$f" "${f%.civet.d.ts}.d.ts"
16+
done
17+
18+
# cli
19+
sed -i 's/\.civet"/.js"/g' dist/cli.js
20+
BIN="dist/jadelet"
21+
echo "#!/usr/bin/env node" | cat - dist/cli.js > "$BIN"
22+
chmod +x "$BIN"
23+
rm dist/cli.js

build/plugin-test.civet

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
esbuild from esbuild
2+
jadeletPlugin from ../esbuild-plugin.js
3+
path from path
4+
5+
root := path.resolve()
6+
7+
esbuild.build
8+
entryPoints: ['test/fixtures/esbuild.js']
9+
globalName: "Bundle"
10+
bundle: true
11+
sourcemap: true
12+
external: ["jadelet"]
13+
platform: 'browser'
14+
outfile: 'test/fixtures/out/build.js'
15+
plugins: [
16+
jadeletPlugin
17+
runtime: `require(${JSON.stringify(root)})`
18+
]
19+
.catch -> process.exit 1

0 commit comments

Comments
 (0)