Skip to content

Commit

Permalink
use esmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jan 6, 2024
1 parent 4a8091d commit a002a0e
Show file tree
Hide file tree
Showing 211 changed files with 1,329 additions and 1,105 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use esmodule
9 changes: 1 addition & 8 deletions bin/inet-js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#!/usr/bin/env node

const process = require("process")

process.on("unhandledRejection", (error) => {
console.error(error)
process.exit(1)
})

const { createCommandRunner } = require("../lib/command-line")
import { createCommandRunner } from "../lib/command-line/index.js"

createCommandRunner().run()
784 changes: 508 additions & 276 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@cicada-lang/inet-js",
"version": "0.2.11",
"repository": "github:cicada-lang/inet-js",
"type": "module",
"main": "./lib/index.js",
"files": [
"lib"
Expand All @@ -12,7 +13,7 @@
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"test:ts": "vitest --dir src --threads false --run",
"test:ts": "vitest --dir src --run",
"test:inet-parse": "test-runner test 'node ./bin/inet-js parse --no-color' 'std/**/*.i'",
"test:inet-format": "test-runner test 'node ./bin/inet-js format --no-color' 'std/**/*.i'",
"test:inet-run": "test-runner snapshot 'node ./bin/inet-js run --no-color' 'std/**/*.i' --exclude 'std/**/*.error.i'",
Expand All @@ -21,12 +22,12 @@
"format": "prettier src docs --write"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/node": "^20.10.6",
"@xieyuheng/test-runner": "^0.2.10",
"prettier": "^3.1.0",
"prettier": "^3.1.1",
"prettier-plugin-organize-imports": "^3.2.4",
"typescript": "^5.3.2",
"vitest": "^0.34.6"
"typescript": "^5.3.3",
"vitest": "^1.1.3"
},
"dependencies": {
"@cicada-lang/framework": "^0.1.6",
Expand Down
6 changes: 2 additions & 4 deletions src/app/App.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AppConfig } from "./AppConfig"
import { AppHome } from "./AppHome"
import { AppReplEventHandler } from "./AppReplEventHandler"
import { AppHome } from "./AppHome.js"
import { AppReplEventHandler } from "./AppReplEventHandler.js"

export class App {
home = new AppHome()
config = new AppConfig()
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
19 changes: 11 additions & 8 deletions src/app/AppReplEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ReplEvent, ReplEventHandler } from "@cicada-lang/framework/lib/repl"
import {
ReplEventHandler,
type ReplEvent,
} from "@cicada-lang/framework/lib/repl/index.js"
import { ParsingError } from "@cicada-lang/partech"
import fs from "fs"
import { relative } from "node:path"
import process from "process"
import { app } from "../app"
import { Fetcher } from "../fetcher/Fetcher"
import { Report } from "../lang/errors/Report"
import { execute } from "../lang/execute"
import { parseStmts } from "../lang/syntax/index"
import { Loader } from "../loader"
import { Fetcher } from "../fetcher/Fetcher.js"
import { Report } from "../lang/errors/Report.js"
import { execute } from "../lang/execute/index.js"
import { parseStmts } from "../lang/syntax/index.js"
import { Loader } from "../loader/index.js"
import { version } from "../version.js"

const fetcher = new Fetcher()

Expand Down Expand Up @@ -43,7 +46,7 @@ export class AppReplEventHandler extends ReplEventHandler {
loader = new Loader({ fetcher })

greeting(): void {
console.log(`iNet JS ${app.config.packageJson.version}`)
console.log(`iNet JS ${version}`)
}

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,3 +1,3 @@
import { App } from "./App"
import { App } from "./App.js"

export const app = new App()
6 changes: 3 additions & 3 deletions src/command-line/commands/Default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import * as Commands from "."
import { app } from "../../app/index"
import { version } from "../../version.js"
import * as Commands from "../commands/index.js"

type Args = { path?: string }
type Opts = { help?: boolean; version?: boolean }
Expand All @@ -26,7 +26,7 @@ export class Default extends Command<Args, Opts> {
}

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

Expand Down
12 changes: 6 additions & 6 deletions src/command-line/commands/Format.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ParsingError } from "@cicada-lang/partech/lib/errors"
import { ParsingError } from "@cicada-lang/partech/lib/errors/index.js"
import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import fs from "node:fs"
import { relative } from "node:path"
import process from "node:process"
import { Fetcher } from "../../fetcher"
import { Report } from "../../lang/errors/Report"
import { formatStmt } from "../../lang/stmt"
import { parseStmts } from "../../lang/syntax"
import { createURL } from "../../utils/createURL"
import { Fetcher } from "../../fetcher/index.js"
import { Report } from "../../lang/errors/Report.js"
import { formatStmt } from "../../lang/stmt/index.js"
import { parseStmts } from "../../lang/syntax/index.js"
import { createURL } from "../../utils/createURL.js"

type Args = { path: string }
type Opts = {}
Expand Down
10 changes: 5 additions & 5 deletions src/command-line/commands/Parse.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ParsingError } from "@cicada-lang/partech/lib/errors"
import { ParsingError } from "@cicada-lang/partech/lib/errors/index.js"
import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import fs from "node:fs"
import { relative } from "node:path"
import process from "node:process"
import { Fetcher } from "../../fetcher"
import { Report } from "../../lang/errors/Report"
import { parseStmts } from "../../lang/syntax"
import { createURL } from "../../utils/createURL"
import { Fetcher } from "../../fetcher/index.js"
import { Report } from "../../lang/errors/Report.js"
import { parseStmts } from "../../lang/syntax/index.js"
import { createURL } from "../../utils/createURL.js"

type Args = { path: string }
type Opts = {}
Expand Down
4 changes: 2 additions & 2 deletions src/command-line/commands/Repl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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"
import { app } from "../../app"
import { app } from "../../app/index.js"

type Args = {}

Expand Down
10 changes: 5 additions & 5 deletions src/command-line/commands/Run.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ParsingError } from "@cicada-lang/partech/lib/errors"
import { ParsingError } from "@cicada-lang/partech/lib/errors/index.js"
import { Command, CommandRunner } from "@xieyuheng/command-line"
import { ty } from "@xieyuheng/ty"
import fs from "node:fs"
import { relative } from "node:path"
import process from "node:process"
import { Fetcher } from "../../fetcher"
import { Report } from "../../lang/errors/Report"
import { Loader } from "../../loader"
import { createURL } from "../../utils/createURL"
import { Fetcher } from "../../fetcher/index.js"
import { Report } from "../../lang/errors/Report.js"
import { Loader } from "../../loader/index.js"
import { createURL } from "../../utils/createURL.js"

type Args = { path: string }
type Opts = {}
Expand Down
12 changes: 6 additions & 6 deletions src/command-line/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "@xieyuheng/command-line/lib/commands"
export * from "./Default"
export * from "./Format"
export * from "./Parse"
export * from "./Repl"
export * from "./Run"
export * from "@xieyuheng/command-line/lib/commands/index.js"
export * from "./Default.js"
export * from "./Format.js"
export * from "./Parse.js"
export * from "./Repl.js"
export * from "./Run.js"
2 changes: 1 addition & 1 deletion src/command-line/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandRunner, CommandRunners } from "@xieyuheng/command-line"
import * as Commands from "./commands"
import * as Commands from "./commands/index.js"

export function createCommandRunner(): CommandRunner {
return new CommandRunners.CommonCommandRunner({
Expand Down
2 changes: 1 addition & 1 deletion src/fetcher/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Fetcher"
export * from "./Fetcher.js"
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./fetcher"
export * from "./lang"
export * from "./loader"
export * from "./fetcher/index.js"
export * from "./lang/index.js"
export * from "./loader/index.js"
12 changes: 6 additions & 6 deletions src/lang/apply/apply.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Env } from "../env"
import { EvaluateOptions } from "../evaluate"
import { Value, formatValue } from "../value"
import { applyFunction } from "./applyFunction"
import { applyNode } from "./applyNode"
import { applyTypeCtor } from "./applyTypeCtor"
import { type Env } from "../env/index.js"
import { type EvaluateOptions } from "../evaluate/index.js"
import { formatValue, type Value } from "../value/index.js"
import { applyFunction } from "./applyFunction.js"
import { applyNode } from "./applyNode.js"
import { applyTypeCtor } from "./applyTypeCtor.js"

export function apply(
env: Env,
Expand Down
18 changes: 9 additions & 9 deletions src/lang/apply/applyFunction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { manyTimes } from "../../utils/manyTimes"
import { connectValues } from "../connect/connectValues"
import { Env } from "../env"
import { defineLocals } from "../env/defineLocals"
import { EvaluateOptions } from "../evaluate"
import { evaluateBlock } from "../evaluate/evaluateBlock"
import { addEdge } from "../net/addEdge"
import { Function, Value, formatValue } from "../value"
import { formatValues } from "../value/formatValues"
import { manyTimes } from "../../utils/manyTimes.js"
import { connectValues } from "../connect/connectValues.js"
import { defineLocals } from "../env/defineLocals.js"
import { type Env } from "../env/index.js"
import { evaluateBlock } from "../evaluate/evaluateBlock.js"
import { type EvaluateOptions } from "../evaluate/index.js"
import { addEdge } from "../net/addEdge.js"
import { formatValues } from "../value/formatValues.js"
import { formatValue, type Function, type Value } from "../value/index.js"

export function applyFunction(
env: Env,
Expand Down
22 changes: 11 additions & 11 deletions src/lang/apply/applyNode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { checkHalfEdges } from "../check/checkHalfEdges"
import { connectHalfEdges } from "../connect/connectHalfEdges"
import { Env } from "../env"
import { EvaluateOptions } from "../evaluate"
import { refreshNode } from "../freshen/refreshNode"
import { halfEdgeFromPort } from "../half-edge/halfEdgeFromPort"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node, formatNode } from "../node"
import { formatPort } from "../port/formatPort"
import { Value, formatValue } from "../value"
import { checkHalfEdges } from "../check/checkHalfEdges.js"
import { connectHalfEdges } from "../connect/connectHalfEdges.js"
import { type Env } from "../env/index.js"
import { type EvaluateOptions } from "../evaluate/index.js"
import { refreshNode } from "../freshen/refreshNode.js"
import { halfEdgeFromPort } from "../half-edge/halfEdgeFromPort.js"
import { findInputPorts } from "../net/findInputPorts.js"
import { findOutputPorts } from "../net/findOutputPorts.js"
import { formatNode, type Node } from "../node/index.js"
import { formatPort } from "../port/formatPort.js"
import { formatValue, type Value } from "../value/index.js"

export function applyNode(
env: Env,
Expand Down
12 changes: 6 additions & 6 deletions src/lang/apply/applyTypeCtor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { checkTypeTermArgs } from "../check/checkTypeTermArgs"
import { Env } from "../env"
import { EvaluateOptions } from "../evaluate"
import { formatParameters } from "../parameter"
import { TypeCtor, Value } from "../value"
import { formatValues } from "../value/formatValues"
import { checkTypeTermArgs } from "../check/checkTypeTermArgs.js"
import { type Env } from "../env/index.js"
import { type EvaluateOptions } from "../evaluate/index.js"
import { formatParameters } from "../parameter/index.js"
import { formatValues } from "../value/formatValues.js"
import { type TypeCtor, type Value } from "../value/index.js"

export function applyTypeCtor(
env: Env,
Expand Down
2 changes: 1 addition & 1 deletion src/lang/apply/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./apply"
export * from "./apply.js"
8 changes: 4 additions & 4 deletions src/lang/builtins/connect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { checkHalfEdges } from "../check/checkHalfEdges"
import { connectHalfEdges } from "../connect/connectHalfEdges"
import { PrimitiveApply } from "../definition"
import { formatValue } from "../value/formatValue"
import { checkHalfEdges } from "../check/checkHalfEdges.js"
import { connectHalfEdges } from "../connect/connectHalfEdges.js"
import { type PrimitiveApply } from "../definition/index.js"
import { formatValue } from "../value/formatValue.js"

export const apply: PrimitiveApply = (env, args, options) => {
if (args.length !== 2) {
Expand Down
4 changes: 2 additions & 2 deletions src/lang/builtins/defineBuiltinPrimitiveFunction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrimitiveApply } from "../definition"
import { Mod } from "../mod"
import { type PrimitiveApply } from "../definition/index.js"
import { type Mod } from "../mod/index.js"

export function defineBuiltinPrimitiveFunction(
mod: Mod,
Expand Down
4 changes: 2 additions & 2 deletions src/lang/builtins/defineBuiltinValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mod } from "../mod"
import { Value } from "../value"
import { type Mod } from "../mod/index.js"
import { type Value } from "../value/index.js"

export function defineBuiltinValue(mod: Mod, name: string, value: Value): void {
mod.builtins.set(name, {
Expand Down
12 changes: 6 additions & 6 deletions src/lang/builtins/defineBuiltins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Mod } from "../mod"
import * as connect from "./connect"
import { defineBuiltinPrimitiveFunction } from "./defineBuiltinPrimitiveFunction"
import { defineBuiltinValue } from "./defineBuiltinValue"
import * as inspect from "./inspect"
import * as run from "./run"
import { type Mod } from "../mod/index.js"
import * as connect from "./connect.js"
import { defineBuiltinPrimitiveFunction } from "./defineBuiltinPrimitiveFunction.js"
import { defineBuiltinValue } from "./defineBuiltinValue.js"
import * as inspect from "./inspect.js"
import * as run from "./run.js"

export function defineBuiltins(mod: Mod): void {
defineBuiltinPrimitiveFunction(mod, "connect", connect)
Expand Down
16 changes: 8 additions & 8 deletions src/lang/builtins/inspect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { indent } from "../../utils/indent"
import { PrimitiveApply } from "../definition"
import { findConnectedComponent } from "../net/findConnectedComponent"
import { findHalfEdgeEntryOrFail } from "../net/findHalfEdgeEntryOrFail"
import { findHalfEdgePortOrFail } from "../net/findHalfEdgePortOrFail"
import { formatNet } from "../net/formatNet"
import { formatPort } from "../port/formatPort"
import { formatValue } from "../value/formatValue"
import { indent } from "../../utils/indent.js"
import { type PrimitiveApply } from "../definition/index.js"
import { findConnectedComponent } from "../net/findConnectedComponent.js"
import { findHalfEdgeEntryOrFail } from "../net/findHalfEdgeEntryOrFail.js"
import { findHalfEdgePortOrFail } from "../net/findHalfEdgePortOrFail.js"
import { formatNet } from "../net/formatNet.js"
import { formatPort } from "../port/formatPort.js"
import { formatValue } from "../value/formatValue.js"

export const apply: PrimitiveApply = (env, args) => {
if (args.length !== 1) {
Expand Down
6 changes: 3 additions & 3 deletions src/lang/builtins/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrimitiveApply } from "../definition"
import { runHalfEdge } from "../run/runHalfEdge"
import { formatValue } from "../value/formatValue"
import { type PrimitiveApply } from "../definition/index.js"
import { runHalfEdge } from "../run/runHalfEdge.js"
import { formatValue } from "../value/formatValue.js"

export const apply: PrimitiveApply = (env, args) => {
if (args.length !== 1) {
Expand Down
Loading

0 comments on commit a002a0e

Please sign in to comment.