Skip to content

Commit

Permalink
chore: update deps and configs
Browse files Browse the repository at this point in the history
- Remove TypeScript config `noImplicitAny` and `noImplicitTHis`.
  They are both enabled under `strict` in TSC >=5.0

- Remove `noUnusedLocals`: this should be checked by a linter.

- Enable skipLibCheck (recommended by TSC)

- Remove stripInternal (no use)

- Add tsconfig and rome $schema for auto-completion in IDE

- Remove `npx` in scripts: it incurs a 30% slowdown.

- Specify `--target` for _ESbuild_.
  _ESbuild_ >= 0.18.0 no longer relies on `tsconfig`'s `target` option.

- Enable all Rome rules and make sure that generated code will pass
  all rules.

- Disable Rome `json` formatting
  • Loading branch information
Conaclos committed Jun 11, 2023
1 parent 43bf24a commit c668da5
Show file tree
Hide file tree
Showing 38 changed files with 341 additions and 341 deletions.
540 changes: 270 additions & 270 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@
},
"devDependencies": {
"@bare-ts/lib": "~0.3.0",
"@types/node": "~14.18.0",
"esbuild": "0.17.5",
"oletus": "3.3.0",
"rome": "11.0.0-nightly.fab5440",
"typescript": "5.0.0-beta",
"@types/node": "~14.18.49",
"esbuild": "0.18",
"oletus": "4.0.0",
"rome": "12.1.3",
"typescript": "5.1.3",
"validate-commit-message": "3.2.0"
},
"dependencies": {
"commander": "10.0.0"
"commander": "10.0.1"
},
"peerDependencies": {
"@bare-ts/lib": "~0.3.0"
Expand Down
12 changes: 10 additions & 2 deletions rome.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{
"$schema": "./node_modules/rome/configuration_schema.json",
"formatter": {
"indentStyle": "space",
"indentSize": 4
"indentSize": 4,
"ignore": ["*.json", "./tsconfig-base.json"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
"all": true,
"nursery": {
"useLiteralKeys": "off"
}
}
},
"javascript": {
"formatter": {
"quoteProperties": "preserve",
"semicolons": "asNeeded"
}
},
"organizeImports": {
"enabled": true
}
}
14 changes: 9 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#!/bin/sh
set -eu

# https://node.green/#ES2020
# https://kangax.github.io/compat-table/es2016plus
TARGET=es2020

# build .d.ts
npx tsc --build src
tsc --build src/

cp -f dist/index.d.ts dist/index.d.cts

# build ESM
npx esbuild src/index.ts src/*/*.ts --outdir=dist --log-level=warning
esbuild src/index.ts src/*/*.ts --target=$TARGET --outdir=dist --log-level=warning

# build CommonJS (fallback)
npx esbuild src/index.ts --bundle --platform=node > dist/index.cjs
esbuild src/index.ts --bundle --target=$TARGET --platform=node > dist/index.cjs

# build cli (bin)
npx esbuild src/cli.ts --define:VERSION=\""$npm_package_version"\" > dist/cli.js
esbuild src/cli.ts --target=$TARGET --define:VERSION=\""$npm_package_version"\" > dist/cli.js

# build standalone cli program
npx esbuild dist/cli.js --bundle --minify --keep-names --platform=node > dist/bare
esbuild dist/cli.js --bundle --target=$TARGET --minify --keep-names --platform=node > dist/bare
2 changes: 1 addition & 1 deletion scripts/generate-tests-corpus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { Config, configure, transform, parse } from "@bare-ts/tools"
import { Config, configure, parse, transform } from "@bare-ts/tools"
import * as fs from "node:fs"
import * as path from "node:path"

Expand Down
11 changes: 5 additions & 6 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh
set -eu

npm run build
. scripts/build.sh

# unit tests
npx oletus dist/*/*.test.js tests-corpus/*.test.js tests-corpus/*/*/*.test.js
oletus dist/*/*.test.js tests-corpus/*.test.js tests-corpus/*/*/*.test.js

# lint
npx rome ci src scripts
npx rome check tests-corpus
rome ci src scripts
rome check tests-corpus

# type check
npx tsc --build src/tsconfig-*.json tests-corpus
tsc --build src/tsconfig-test.json tests-corpus/
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! Copyright (c) 2022 Victorien Elvinger
//! Licensed under the MIT License (https://mit-license.org/)

import { Config, transform } from "./index.js"
import { Argument, Option, program } from "commander"
import * as fs from "node:fs"
import * as process from "node:process"
import { Config, transform } from "./index.js"

// WARNING: This constant MUST be defined at build time.
declare const VERSION: string
Expand Down
13 changes: 7 additions & 6 deletions src/generator/js-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export function generate(schema: ast.Ast, config: Config): string {
}
}
let head = ""
if (/\bassert\(/.test(body)) {
head += 'import assert from "assert"\n'
}
if (/bare\./.test(body)) {
head += // Are values imported?
g.config.generator !== "ts" ||
Expand All @@ -85,8 +82,11 @@ export function generate(schema: ast.Ast, config: Config): string {
? 'import * as bare from "@bare-ts/lib"\n'
: 'import type * as bare from "@bare-ts/lib"\n'
}
if (/\bassert\(/.test(body)) {
head += 'import assert from "node:assert"\n'
}
if (/ext\./.test(body)) {
head += 'import * as ext from "./ext.js"\n'
head += '\nimport * as ext from "./ext.js"\n'
}
if (
hasEncodeDecode &&
Expand Down Expand Up @@ -918,9 +918,10 @@ function genBaseFlatUnionWriter(g: Gen, union: ast.UnionType): string {
const type = union.types[i]
if (type.tag === "void") {
defaultCase = `
default:
default: {
bare.${tagWriter}(bc, ${tagVal})
break`
break
}`
} else {
const valWriting = genWriting(g, type, "$x")
switchBody += `
Expand Down
2 changes: 1 addition & 1 deletion src/parser/bare-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//! Licensed under the MIT License (https://mit-license.org/)

import * as ast from "../ast/bare-ast.js"
import type { Config } from "../core/config.js"
import { CompilerError, type Location } from "../core/compiler-error.js"
import type { Config } from "../core/config.js"
import { Lex } from "./bare-lex.js"

export function parse(content: string, config: Config): ast.Ast {
Expand Down
8 changes: 0 additions & 8 deletions src/tsconfig-node.json

This file was deleted.

3 changes: 1 addition & 2 deletions src/tsconfig-test.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"moduleResolution": "node",
"types": ["node"]
},
"include": ["./**/*.test.ts"],
"include": ["./cli.ts", "./**/*.test.ts"],
"references": [{ "path": "." }]
}
1 change: 0 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

"composite": true
},
"include": ["./**/*.ts"],
"exclude": ["./cli.ts", "./**/*.spec.ts", "./**/*.test.ts"]
}
3 changes: 0 additions & 3 deletions tests-corpus/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"moduleResolution": "node",
"paths": { "@bare-ts/tools": ["../src/index.js"] },
"types": ["node"]
},
"include": ["./**/*.js", "./**/*.ts"],
"references": [{ "path": "../src/" }]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
2 changes: 1 addition & 1 deletion tests-corpus/valid-bare-schema/data-fixed/out.gen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
2 changes: 1 addition & 1 deletion tests-corpus/valid-bare-schema/data-fixed/out.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
1 change: 1 addition & 0 deletions tests-corpus/valid-bare-schema/imported-config/out.gen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as bare from "@bare-ts/lib"

import * as ext from "./ext.js"

export function readMessage(bc) {
Expand Down
1 change: 1 addition & 0 deletions tests-corpus/valid-bare-schema/imported-config/out.gen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as bare from "@bare-ts/lib"

import * as ext from "./ext.js"

export type u8 = number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
2 changes: 1 addition & 1 deletion tests-corpus/valid-bare-schema/list-fixed/out.gen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
2 changes: 1 addition & 1 deletion tests-corpus/valid-bare-schema/list-fixed/out.gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

function read0(bc) {
const offset = bc.offset
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

function read0(bc: bare.ByteCursor):
| { readonly tag: "Alias", readonly val: Alias }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
3 changes: 2 additions & 1 deletion tests-corpus/valid-bare-schema/union-flat-typeof/out.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export function writeTypeOfUnion(bc, x) {
bare.writeString(bc, x)
break
}
default:
default: {
bare.writeU8(bc, 3)
break
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests-corpus/valid-bare-schema/union-flat-typeof/out.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export function writeTypeOfUnion(bc: bare.ByteCursor, x: TypeOfUnion): void {
bare.writeString(bc, x)
break
}
default:
default: {
bare.writeU8(bc, 3)
break
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert"
import * as bare from "@bare-ts/lib"
import assert from "node:assert"

const config = /* @__PURE__ */ bare.Config({})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//! Licensed under the MIT License (https://mit-license.org/)

import { default as test } from "oletus"
import { decodePerson, encodePerson, Department } from "./out.gen.js"

import { Department, decodePerson, encodePerson } from "./out.gen.js"

test("x-readme-example", (t) => {
const payload1 = encodePerson({
Expand Down
3 changes: 2 additions & 1 deletion tests-corpus/valid-bare-schema/x-readme-example/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//! Licensed under the MIT License (https://mit-license.org/)

import { default as test } from "oletus"
import { decodeContacts, encodeContacts, Gender } from "./out.gen.js"

import { Gender, decodeContacts, encodeContacts } from "./out.gen.js"

test("x-readme-example", (t) => {
const payload = encodeContacts([
Expand Down
Loading

0 comments on commit c668da5

Please sign in to comment.