Skip to content

Commit

Permalink
Fixing typescript setup
Browse files Browse the repository at this point in the history
Modeling after turborepo's repo. Hoping to fix typecheck issues in github action pipeline
  • Loading branch information
kyleect committed Sep 16, 2023
1 parent 3f0e096 commit 2d73aac
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 138 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:

- name: Verify
run: npm run verify

- name: Build TS Project
run: npm run build:ts

- name: Build
run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion apps/cidlang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"tsup": "tsup",
"dev": "npm run build -- --watch --onSuccess \"npm run start\"",
"build-src": "rm -rf dist/lib && tsup src/cidlang.ts -d dist/lib --minify --shims --format cjs --treeshake recommended --no-splitting",
"build-src": "tsup",
"start": "node dist/cidlang.js",
"build-bins": "npx pkg dist/lib/cidlang.js --out-path=dist/bins",
"format": "npx prettier --write .",
Expand Down
8 changes: 5 additions & 3 deletions apps/cidlang/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"references": [{"path": "../../packages/lib"}]
}
"extends": "cid-tsconfig/library.json",
"compilerOptions": {
"rootDir": "."
}
}
14 changes: 14 additions & 0 deletions apps/cidlang/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig, Options } from "tsup";

export default defineConfig((options: Options) => ({
entry: ["src/cidlang.ts"],
format: ["cjs"],
outDir: "dist/lib",
dts: true,
clean: true,
minify: true,
shims: true,
treeshake: "recommended",
splitting: false,
...options,
}));
2 changes: 1 addition & 1 deletion apps/cidrepl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"tsup": "tsup",
"dev": "npm run build -- --watch --onSuccess \"npm run start\"",
"build-src": "rm -rf dist/lib && tsup src/cidrepl.ts -d dist/lib --minify --shims --format cjs --treeshake recommended --no-splitting",
"build-src": "tsup",
"build-bins": "npx pkg dist/lib/cidrepl.js --out-path=dist/bins",
"format": "npx prettier --write .",
"lint": "npx eslint .",
Expand Down
8 changes: 5 additions & 3 deletions apps/cidrepl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"references": [{"path": "../../packages/lib"}]
}
"extends": "cid-tsconfig/library.json",
"compilerOptions": {
"rootDir": "."
}
}
14 changes: 14 additions & 0 deletions apps/cidrepl/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig, Options } from "tsup";

export default defineConfig((options: Options) => ({
entry: ["src/cidrepl.ts"],
format: ["cjs"],
outDir: "dist/lib",
dts: true,
clean: true,
minify: true,
shims: true,
treeshake: "recommended",
splitting: false,
...options,
}));
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "cidlang-monorepo",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*",
"apps/*"
],
"scripts": {
"verify": "npx turbo test lint typecheck",
"build": "npx turbo build",
"build:ts": "tsc -b tsconfig.project.json",
"cli": "apps/cidlang/dist/lib/cidlang.js",
"repl": "apps/cidrepl/dist/lib/cidrepl.js",
"spec": "npm run cli -- spec/test.scm",
Expand Down
5 changes: 3 additions & 2 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"tsup": "tsup",
"dev": "npm run build -- --watch --onSuccess \"npm run start\"",
"build": "rm -rf dist && tsup src/index.ts -d dist --minify --shims --dts --sourcemap --format esm,cjs --keep-names --treeshake recommended --no-splitting",
"build": "tsup",
"test": "vitest run",
"test:watch": "vitest",
"coverage": "npm test -- --coverage",
Expand All @@ -34,6 +34,7 @@
"turbo": "^1.10.13",
"typedoc": "^0.25.1",
"typescript": "^4.9.5",
"vitest": "^0.34.4"
"vitest": "^0.34.4",
"cid-tsconfig": "*"
}
}
4 changes: 2 additions & 2 deletions packages/lib/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export class Cell {

const valuesReversed = [...values].reverse();

let cell: Cell;
let cell: ListExpression = NullExpression;

if (values.length === 0) {
return NullExpression;
return cell;
}

if (values.length === 1) {
Expand Down
8 changes: 2 additions & 6 deletions packages/lib/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ import {

export class Environment {
constructor(
private values?: Map<string, unknown>,
private values: Map<string, unknown> = new Map(),
private enclosing?: Environment
) {
if (typeof this.values === "undefined" || this.values === null) {
this.values = new Map();
}
}
) {}

// Sets the variable value in the
// environment where it was defined
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe("Expression", () => {
});

it("should return that empty arrays are not pair expressions", () => {
const value = [];
const value: unknown[] = [];

expect(isPairExpression(value)).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ describe("Interpreter", () => {
});

describe("display", () => {
let originalConsoleLog;
let originalConsoleLog: typeof console.log;

beforeEach(() => {
originalConsoleLog = console.log;
Expand Down
9 changes: 5 additions & 4 deletions packages/lib/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Interpreter {
* @returns Result of program's last interpreted expression
*/
public interpretProgram(program: Program): Expression {
let result: Expression;
let result: Expression = NullExpression;

if (!isProgram(program)) {
throw new CIDLangRuntimeError(
Expand Down Expand Up @@ -116,7 +116,7 @@ export class Interpreter {
const value = this.#interpret(expr, env);

env.set(name, value);
return;
return value;
}

if (op === Sym.Set) {
Expand All @@ -136,7 +136,7 @@ export class Interpreter {
const value = this.#interpret(expr, env);

env.set(name, value);
return;
return value;
}

throw new CIDLangRuntimeError(
Expand Down Expand Up @@ -191,13 +191,14 @@ export class Interpreter {
let result: Expression;

if (args.length === 0) {
return Cell.list();
return NullExpression;
}

for (const arg of args) {
result = this.#interpret(arg as Expression, env);
}

// @ts-expect-error WIP
return result;
}

Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class TokenParser implements Parser {
this.#advance();
}

// @ts-expect-error WIP
return expression;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Token } from "./token";

function getRandomArbitrary(min, max) {
function getRandomArbitrary(min: number, max: number) {
return Math.random() * (max - min) + min;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"extends": "cid-tsconfig/library.json",
"compilerOptions": {
"types": ["vitest/globals"]
"types": ["vitest/globals"],
"rootDir": "."
}
}
15 changes: 15 additions & 0 deletions packages/lib/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig, Options } from "tsup";

export default defineConfig((options: Options) => ({
entry: ["src/index.ts"],
format: ["cjs", "esm"],
outDir: "dist",
dts: true,
clean: true,
minify: true,
sourcemap: true,
keepNames: true,
treeshake: "recommended",
splitting: false,
...options,
}));
20 changes: 20 additions & 0 deletions packages/tsconfig/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"exclude": ["node_modules", "dist"]
}
12 changes: 12 additions & 0 deletions packages/tsconfig/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./base.json",
"display": "TS Library",
"compilerOptions": {
"lib": ["ES2019"],
"target": "ES2019",
"skipLibCheck": true,
"resolveJsonModule": true,
"outDir": "dist",
"allowJs": false
}
}
5 changes: 5 additions & 0 deletions packages/tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "cid-tsconfig",
"version": "0.0.0",
"private": true
}
Loading

0 comments on commit 2d73aac

Please sign in to comment.