Skip to content

Commit

Permalink
use "type": "module" in package.json
Browse files Browse the repository at this point in the history
- remove "node-watch"
  • Loading branch information
xieyuheng committed Sep 24, 2024
1 parent 5302b84 commit 8549d87
Show file tree
Hide file tree
Showing 345 changed files with 1,217 additions and 1,266 deletions.
4 changes: 0 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use "type": "module" in package.json

move std/ and tests/ to docs/

`cic run --watch` should not watch even first run meets error

`Stmts.Test` -- `test { ... }` and `test <description> { ... }`

- move snapshot tests to `test:cic`
Expand Down
10 changes: 1 addition & 9 deletions bin/cic.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#!/usr/bin/env -S node --no-warnings

const process = require("process")

process.on("unhandledRejection", (error) => {
console.error(error)
process.exit(1)
})
import { createCommandRunner } from "../lib/command-line/index.js"

Error.stackTraceLimit = Infinity

const { createCommandRunner } = require("../lib/command-line")

createCommandRunner().run()
1 change: 0 additions & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@cicada-lang/cicada",
"version": "0.8.24",
"repository": "github:cicada-lang/cicada",
"type": "module",
"main": "./lib/index.js",
"files": [
"lib"
Expand Down Expand Up @@ -29,7 +30,6 @@
"commonmark": "^0.31.2",
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21",
"node-watch": "^0.7.4",
"picocolors": "^1.1.0",
"readdirp": "^4.0.1"
},
Expand Down
8 changes: 3 additions & 5 deletions src/app/App.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as Loggers from "@cicada-lang/framework/lib/loggers"
import { AppConfig } from "./AppConfig"
import { AppHome } from "./AppHome"
import { AppReplEventHandler } from "./AppReplEventHandler"
import * as Loggers from "@cicada-lang/framework/lib/loggers/index.js"
import { AppHome } from "./AppHome.js"
import { AppReplEventHandler } from "./AppReplEventHandler.js"

export class App {
logger = new Loggers.PrettyLogger()
config = new AppConfig()
home = new AppHome()
replEventHandler = new AppReplEventHandler()
}
9 changes: 0 additions & 9 deletions src/app/AppConfig.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/AppHome.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocalFileStore } from "@cicada-lang/framework/lib/file-stores/LocalFileStore"
import { LocalFileStore } from "@cicada-lang/framework/lib/file-stores/LocalFileStore.js"
import os from "os"
import Path from "path"
import process from "process"
Expand Down
15 changes: 9 additions & 6 deletions src/app/AppReplEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ReplEvent, ReplEventHandler } from "@cicada-lang/framework/lib/repl"
import {
type ReplEvent,
ReplEventHandler,
} from "@cicada-lang/framework/lib/repl/index.js"
import fs from "fs"
import process from "process"
import * as Errors from "../lang/errors"
import { parseStmts } from "../lang/syntax"
import { Loader } from "../loader"
import { colors } from "../utils/colors"
import * as Errors from "../lang/errors/index.js"
import { parseStmts } from "../lang/syntax/index.js"
import { Loader } from "../loader/index.js"
import { colors } from "../utils/colors.js"

export class AppReplEventHandler extends ReplEventHandler {
pathname = process.cwd() + "/repl"
Expand All @@ -23,7 +26,7 @@ export class AppReplEventHandler extends ReplEventHandler {
}

greeting(): void {
console.log(`Welcome to cicada ${app.config.pkg.version}`)
console.log(`Welcome to cicada`)
}

async handle(event: ReplEvent): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App } from "./App"
import { App } from "./App.js"

declare global {
var app: App
Expand Down
35 changes: 2 additions & 33 deletions src/command-line/Runner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import process from "node:process"
import fs from "fs"
import watcher from "node-watch"
import * as Errors from "../lang/errors"
import { Loader } from "../loader"
import * as Errors from "../lang/errors/index.js"
import { Loader } from "../loader/index.js"

export class Runner {
loader = new Loader()
Expand Down Expand Up @@ -42,34 +41,4 @@ export class Runner {
return { error }
}
}

async watch(main: URL): Promise<void> {
const tracked = [main, ...this.loader.loaded]
app.logger.info({ msg: `Watching for changes.`, tracked })

for (const url of tracked) {
if (main.protocol !== "file:") continue

watcher(url.pathname, async (event, _filename) => {
if (event === "remove") {
this.loader.delete(url)
if (url.href === main.href) {
app.logger.info({ tag: event, msg: url.pathname })
app.logger.info({ msg: "The main file is removed." })
} else {
const { error } = await this.run(main)
if (error) app.logger.error({ tag: event, msg: url.pathname })
else app.logger.info({ tag: event, msg: url.pathname })
}
}

if (event === "update") {
this.loader.delete(url)
const { error } = await this.run(main)
if (error) app.logger.error({ tag: event, msg: url.pathname })
else app.logger.info({ tag: event, msg: url.pathname })
}
})
}
}
}
9 changes: 2 additions & 7 deletions src/command-line/commands/Default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import * as Commands from "."
import * as Commands from "./index.js"

type Args = { file?: string }
type Opts = { help?: boolean; version?: boolean }
Expand All @@ -11,7 +11,7 @@ export class Default extends Command<Args, Opts> {
description = "Open REPL or run an file"

args = { file: ty.optional(ty.string()) }
opts = { help: ty.optional(ty.boolean()), version: ty.optional(ty.boolean()) }
opts = { help: ty.optional(ty.boolean()) }
alias = { help: ["h"], version: ["v"] }

async execute(argv: Args & Opts, runner: CommandRunner): Promise<void> {
Expand All @@ -21,11 +21,6 @@ export class Default extends Command<Args, Opts> {
return
}

if (argv["version"]) {
console.log(app.config.pkg.version)
return
}

const file = argv["file"]

if (file === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/command-line/commands/Repl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReadlineRepl } from "@cicada-lang/framework/lib/repls/readline-repl"
import { ReadlineRepl } from "@cicada-lang/framework/lib/repls/readline-repl/index.js"
import { Command, CommandRunner } from "@xieyuheng/command-line"
import Path from "path"

Expand Down
13 changes: 4 additions & 9 deletions src/command-line/commands/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import fs from "fs"
import Path from "path"
import { Runner } from "../Runner"
import { Runner } from "../Runner.js"

type Args = { file: string }
type Opts = { watch?: boolean }
Expand Down Expand Up @@ -43,14 +43,9 @@ export class Run extends Command<Args, Opts> {
async execute(argv: Args & Opts): Promise<void> {
const url = createURL(argv["file"])

if (argv["watch"]) {
await this.runner.run(url)
await this.runner.watch(url)
} else {
const { error } = await this.runner.run(url)
if (error) {
process.exit(1)
}
const { error } = await this.runner.run(url)
if (error) {
process.exit(1)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/command-line/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "@xieyuheng/command-line/lib/commands"
export * from "./Default"
export * from "./Repl"
export * from "./Run"
export * from "@xieyuheng/command-line/lib/commands/index.js"
export * from "./Default.js"
export * from "./Repl.js"
export * from "./Run.js"
7 changes: 4 additions & 3 deletions src/command-line/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommandRunner, CommandRunners } from "@xieyuheng/command-line"
import "../app"
import * as Commands from "./commands"
import { CommandRunner } from "@xieyuheng/command-line/lib/command-runner/index.js"
import * as CommandRunners from "@xieyuheng/command-line/lib/command-runners/index.js"
import "../app/index.js"
import * as Commands from "./commands/index.js"

export function createCommandRunner(): CommandRunner {
return new CommandRunners.CommonCommandRunner({
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * as Errors from "./lang/errors"
export * from "./lang/mod"
export * from "./loader"
export * as Errors from "./lang/errors/index.js"
export * from "./lang/mod/index.js"
export * from "./loader/index.js"
12 changes: 6 additions & 6 deletions src/lang/actions/doAp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { closureApply } from "../closure"
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import { TypedValue } from "../value"
import { closureApply } from "../closure/index.js"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"
import { TypedValue } from "../value/index.js"

export function doAp(target: Value, arg: Value): Value {
return tryAp(target, arg) || neutralizeAp(target, arg)
Expand Down
12 changes: 6 additions & 6 deletions src/lang/actions/doApImplicit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { closureApply } from "../closure"
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import { TypedValue } from "../value"
import { closureApply } from "../closure/index.js"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"
import { TypedValue } from "../value/index.js"

export function doApImplicit(target: Value, arg: Value): Value {
return tryApImplicit(target, arg) || neutralizeApImplicit(target, arg)
Expand Down
8 changes: 4 additions & 4 deletions src/lang/actions/doCar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"

export function doCar(target: Value): Value {
return tryCar(target) || neutralizeCar(target)
Expand Down
12 changes: 6 additions & 6 deletions src/lang/actions/doCdr.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { closureApply } from "../closure"
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import { doCar } from "./doCar"
import { closureApply } from "../closure/index.js"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"
import { doCar } from "./doCar.js"

export function doCdr(target: Value): Value {
return tryCdr(target) || neutralizeCdr(target)
Expand Down
8 changes: 4 additions & 4 deletions src/lang/actions/doDot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"

export function doDot(target: Value, name: string): Value {
return tryDot(target, name) || neutralizeDot(target, name)
Expand Down
14 changes: 7 additions & 7 deletions src/lang/actions/doReplace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Actions from "../actions"
import { ClosureNative } from "../closure"
import * as Errors from "../errors"
import * as Neutrals from "../neutral"
import type { Value } from "../value"
import * as Values from "../value"
import { TypedValue } from "../value"
import * as Actions from "../actions/index.js"
import { ClosureNative } from "../closure/index.js"
import * as Errors from "../errors/index.js"
import * as Neutrals from "../neutral/index.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"
import { TypedValue } from "../value/index.js"

export function doReplace(target: Value, motive: Value, base: Value): Value {
return (
Expand Down
12 changes: 6 additions & 6 deletions src/lang/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./doAp"
export * from "./doApImplicit"
export * from "./doCar"
export * from "./doCdr"
export * from "./doDot"
export * from "./doReplace"
export * from "./doAp.js"
export * from "./doApImplicit.js"
export * from "./doCar.js"
export * from "./doCdr.js"
export * from "./doDot.js"
export * from "./doReplace.js"
40 changes: 20 additions & 20 deletions src/lang/check/check.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { indent } from "../../utils/indent"
import { checkByInfer, checkProperties } from "../check"
import { closureApply } from "../closure"
import type { Core } from "../core"
import * as Cores from "../core"
import type { Ctx } from "../ctx"
import { CtxCons, ctxNames, ctxToEnv } from "../ctx"
import * as Errors from "../errors"
import { evaluate } from "../evaluate"
import type { Exp } from "../exp"
import * as Exps from "../exp"
import { infer } from "../infer"
import { insertDuringCheck } from "../insert"
import type { Mod } from "../mod"
import * as Neutrals from "../neutral"
import { solutionNames } from "../solution"
import { freshen } from "../utils/freshen"
import type { Value } from "../value"
import * as Values from "../value"
import { formatType } from "../value"
import { indent } from "../../utils/indent.js"
import { checkByInfer, checkProperties } from "../check/index.js"
import { closureApply } from "../closure/index.js"
import type { Core } from "../core/index.js"
import * as Cores from "../core/index.js"
import type { Ctx } from "../ctx/index.js"
import { CtxCons, ctxNames, ctxToEnv } from "../ctx/index.js"
import * as Errors from "../errors/index.js"
import { evaluate } from "../evaluate/index.js"
import type { Exp } from "../exp/index.js"
import * as Exps from "../exp/index.js"
import { infer } from "../infer/index.js"
import { insertDuringCheck } from "../insert/index.js"
import type { Mod } from "../mod/index.js"
import * as Neutrals from "../neutral/index.js"
import { solutionNames } from "../solution/index.js"
import { freshen } from "../utils/freshen.js"
import type { Value } from "../value/index.js"
import * as Values from "../value/index.js"
import { formatType } from "../value/index.js"

export function check(mod: Mod, ctx: Ctx, exp: Exp, type: Value): Core {
switch (exp["@kind"]) {
Expand Down
Loading

0 comments on commit 8549d87

Please sign in to comment.