Skip to content

Commit

Permalink
Change our js/ts/npm build to get types in downstream projects #78
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsexton committed Jan 29, 2024
2 parents 1b054d9 + 6d11adc commit 72d4022
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 78 deletions.
3 changes: 2 additions & 1 deletion prelude/ts/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
},
"dependencies": {
"ws": "^8.12.0"
}
},
"type": "module"
}
4 changes: 2 additions & 2 deletions prelude/ts/src/sk_browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { float, int, Environment, Wrk, Shared } from "#std/sk_types";
import { MemFS, MemSys } from "#std/sk_mem_utils";
import type { float, int, Environment, Wrk, Shared } from "./sk_types.js";
import { MemFS, MemSys } from "./sk_mem_utils.js";

class WrkImpl implements Wrk {
worker: Worker;
Expand Down
3 changes: 2 additions & 1 deletion prelude/ts/src/sk_mem_utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { int, FileSystem, Options, System } from "#std/sk_types";
import type { int, FileSystem, System } from "./sk_types.js";
import { Options } from "./sk_types.js";

class File {
contents: string;
Expand Down
4 changes: 2 additions & 2 deletions prelude/ts/src/sk_node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { float, int, Environment, Wrk, Shared } from "#std/sk_types";
import { MemFS, MemSys } from "#std/sk_mem_utils";
import type { float, int, Environment, Wrk, Shared } from "./sk_types.js";
import { MemFS, MemSys } from "./sk_mem_utils.js";

import * as fs from "fs";
import * as util from "util";
Expand Down
6 changes: 3 additions & 3 deletions prelude/ts/src/sk_posix.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
import type {
int,
ptr,
Environment,
Links,
ToWasmManager,
Utils,
FileSystem,
Options,
} from "#std/sk_types";
} from "./sk_types.js";
import { Options } from "./sk_types.js";

interface ToWasm {
SKIP_check_if_file_exists: (skPath: ptr) => boolean;
Expand Down
7 changes: 3 additions & 4 deletions prelude/ts/src/sk_runtime.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
import type {
int,
float,
ptr,
Links,
Utils,
ToWasmManager,
Environment,
Stream,
Options,
} from "#std/sk_types";
} from "./sk_types.js";
import { Stream } from "./sk_types.js";

interface Env extends Environment {
window: () => Window | null;
Expand Down
2 changes: 1 addition & 1 deletion prelude/ts/src/sk_worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { int, Wrk } from "#std/sk_types";
import type { int, Wrk } from "./sk_types.js";

interface Payload {}

Expand Down
4 changes: 2 additions & 2 deletions skdate/ts/src/sk_date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
int,
ptr,
Environment,
Expand All @@ -7,7 +7,7 @@ import {
Utils,
FileSystem,
Options,
} from "#std/sk_types";
} from "#std/sk_types.js";

interface ToWasm {
SKIP_localetimezone: (year: int, month: int, day: int) => int;
Expand Down
32 changes: 14 additions & 18 deletions sknpm/src/main.sk
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ fun manage(
"dependencies" => JSON.Object(
pckDependencies.map((_, v) -> JSON.String(v)),
),
"type" => JSON.String("module"),
],
);

Expand Down Expand Up @@ -697,7 +698,7 @@ fun manage(
if (bc.env.verbose) {
print_string(">> Copy types declaration files.");
};
declFiles.each(f -> copyToDir(f, distDir, ".mjs"));
declFiles.each(f -> copyToDir(f, distDir));
srcDir = Path.join(npmDir, "src");
checkDir(srcDir);
if (bc.env.verbose) {
Expand All @@ -707,7 +708,7 @@ fun manage(
tsDir,
f -> f.endsWith(".ts"),
_f -> false,
).each(f -> copyToDir(f, srcDir, ""));
).each(f -> copyToDir(f, srcDir));
if (bc.env.verbose) {
print_string(">> Manage license and package files.");
};
Expand Down Expand Up @@ -789,12 +790,12 @@ fun tsConfig(deps: Vector<String>): String {
"baseUrl" => JSON.String("."),
"paths" => JSON.Object(unsafe_chill_trust_me(paths)),
"strictNullChecks" => JSON.Bool(true),
"module" => JSON.String("ESNext"),
"module" => JSON.String("node16"),
"sourceMap" => JSON.Bool(true),
"declaration" => JSON.Bool(true),
"declarationMap" => JSON.Bool(true),
"incremental" => JSON.Bool(true),
"moduleResolution" => JSON.String("Node"),
"verbatimModuleSyntax" => JSON.Bool(true),
],
),
],
Expand Down Expand Up @@ -824,25 +825,23 @@ fun tsc(tsDir: String, link: ?(String, String), verbose: Bool): void {
Skargo.run(Array["tsc", "--project", tsconfig], verbose);
}

fun copyToDir(tsFile: String, dir: String, ext: String = ".ts"): void {
fun copyToDir(tsFile: String, dir: String): void {
contents = FileSystem.readTextFile(tsFile);
target = Path.join(dir, Path.basename(tsFile));
lines = contents.split("\n").map(line -> {
if (line.startsWith("import ") || line.startsWith("export {")) {
if (
line.startsWith("import ") ||
line.startsWith("export {") ||
line.startsWith("export type {")
) {
elements = line.split(" from ");
if (elements.size() == 2) {
imported = elements[1].split("\"");
if (imported.size() == 3) {
elems = imported[1].split("/");
size = elems.size();
if (size > 1 && elems[0].startsWith("#")) {
!elems = elems.mapWithIndex((idx, v) ->
if (idx == 0) "." else if (idx == size - 1) {
`${v}${ext}`
} else {
v
}
);
!elems = elems.mapWithIndex((idx, v) -> if (idx == 0) "." else v);
!line = `${elements[0]} from "${elems.join("/")}"`
}
}
Expand Down Expand Up @@ -909,6 +908,7 @@ fun copyAndConvertImport(
optCategory: ?String = None();
lines = contents.split("\n").map(line -> {
if (line.startsWith("import ") || line.startsWith("export {")) {
!line = line.replace(".js", ".mjs");
elements = line.split(" from ");
if (elements.size() == 2) {
imported = elements[1].split("\"");
Expand All @@ -917,11 +917,7 @@ fun copyAndConvertImport(
size = elems.size();
if (size > 1 && elems[0].startsWith("#")) {
!elems = elems.mapWithIndex((idx, v) ->
if (idx == 0) "." else if (idx == size - 1) {
`${v}.mjs`
} else {
v
}
if (idx == 0) "." else v
);
!line = `${elements[0]} from "${elems.join("/")}"`
}
Expand Down
3 changes: 2 additions & 1 deletion sql/ts/src/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"devDependencies": {
"@types/node": "^20.10.7"
}
},
"type": "module"
}
2 changes: 1 addition & 1 deletion sql/ts/src/skdb-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseArgs } from "util";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { createSkdb } from "#skdb/skdb";
import { createSkdb } from "./skdb.js";
import { webcrypto } from "crypto";
import * as readline from "readline/promises";
import * as process from "process";
Expand Down
14 changes: 7 additions & 7 deletions sql/ts/src/skdb.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { run, loadEnv, isNode } from "#std/sk_types";
import { SKDB, SKDBSync, SKDBShared } from "#skdb/skdb_types";
import { SKDBWorker } from "#skdb/skdb_wdatabase";
export { SKDB, RemoteSKDB } from "#skdb/skdb_types";
export { SKDBTable as SKDBTable } from "#skdb/skdb_util";
export { Creds, MuxedSocket } from "#skdb/skdb_orchestration";
export { Environment } from "#std/sk_types";
import { run, loadEnv, isNode } from "#std/sk_types.js";
import type { SKDB, SKDBSync, SKDBShared } from "./skdb_types.js";
import { SKDBWorker } from "./skdb_wdatabase.js";
export { SKDBTable as SKDBTable } from "./skdb_util.js";
export type { SKDB, RemoteSKDB } from "./skdb_types.js";
export type { Creds, MuxedSocket } from "./skdb_orchestration.js";
export type { Environment } from "#std/sk_types.js";

var wasm64 = "skdb";
// sknpm searches for the modules line verbatim
Expand Down
12 changes: 6 additions & 6 deletions sql/ts/src/skdb_database.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Environment, FileSystem } from "#std/sk_types";
import {
import type { Environment, FileSystem } from "#std/sk_types.js";
import type {
SKDBMechanism,
SKDB,
RemoteSKDB,
SKDBHandle,
Params,
SKDBSync,
MirrorDefn,
} from "#skdb/skdb_types";
import { SKDBTable } from "#skdb/skdb_util";
import { SKDBGroupImpl } from "#skdb/skdb_group";
import { connect } from "#skdb/skdb_orchestration";
} from "./skdb_types.js";
import { SKDBTable } from "./skdb_util.js";
import { SKDBGroupImpl } from "./skdb_group.js";
import { connect } from "./skdb_orchestration.js";

class SKDBMechanismImpl implements SKDBMechanism {
writeCsv: (payload: string, source: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb_group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SKDB, SKDBGroup } from "#skdb/skdb_types";
import type { SKDB, SKDBGroup } from "./skdb_types.js";

export class SKDBGroupImpl implements SKDBGroup {
skdb: SKDB;
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb_nodeworker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onDbWorkerMessage } from "#skdb/skdb_wmessage";
import { onDbWorkerMessage } from "./skdb_wmessage.js";
import { parentPort } from "worker_threads";

var post = (message: any) => {
Expand Down
8 changes: 4 additions & 4 deletions sql/ts/src/skdb_orchestration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Environment } from "#std/sk_types";
import {
import type { Environment } from "#std/sk_types.js";
import type {
SKDBMechanism,
RemoteSKDB,
Params,
MirrorDefn,
} from "#skdb/skdb_types";
import { SKDBTable } from "#skdb/skdb_util";
} from "./skdb_types.js";
import { SKDBTable } from "./skdb_util.js";

const npmVersion = "";

Expand Down
15 changes: 7 additions & 8 deletions sql/ts/src/skdb_skdb.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
import type {
int,
ptr,
Environment,
Links,
ToWasmManager,
Utils,
Shared,
} from "#std/sk_types";
import {
} from "#std/sk_types.js";
import type {
PagedMemory,
Page,
Storage,
SKDB,
SKDBHandle,
Params,
SKDBSync,
} from "#skdb/skdb_types";
import { ExternalFuns, SKDBTable } from "#skdb/skdb_util";
import { IDBStorage } from "#skdb/skdb_storage";
import { SKDBImpl, SKDBSyncImpl } from "#skdb/skdb_database";
} from "./skdb_types.js";
import { ExternalFuns, SKDBTable } from "./skdb_util.js";
import { IDBStorage } from "./skdb_storage.js";
import { SKDBImpl, SKDBSyncImpl } from "./skdb_database.js";

interface Exported {
sk_pop_dirty_page: () => number;
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb_storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Storage, PagedMemory } from "#skdb/skdb_types";
import type { Storage, PagedMemory } from "./skdb_types.js";

function makeSKDBStore(
dbName: string,
Expand Down
4 changes: 2 additions & 2 deletions sql/ts/src/skdb_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Shared } from "#std/sk_types";
import { SKDBTable } from "#skdb/skdb_util";
import type { Shared } from "#std/sk_types.js";
import { SKDBTable } from "./skdb_util.js";

export interface SKDBHandle {
runner: (fn: () => string) => SKDBTable;
Expand Down
12 changes: 6 additions & 6 deletions sql/ts/src/skdb_wdatabase.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Wrk } from "#std/sk_types";
import { PromiseWorker, Function, Caller } from "#std/sk_worker";
import {
import type { Wrk } from "#std/sk_types.js";
import { PromiseWorker, Function, Caller } from "#std/sk_worker.js";
import type {
SKDB,
ProtoResponseCreds,
Params,
RemoteSKDB,
MirrorDefn,
} from "#skdb/skdb_types";
import { SKDBTable } from "#skdb/skdb_util";
import { SKDBGroupImpl } from "#skdb/skdb_group";
} from "./skdb_types.js";
import { SKDBTable } from "./skdb_util.js";
import { SKDBGroupImpl } from "./skdb_group.js";

class WrappedRemote implements RemoteSKDB {
private worker: PromiseWorker;
Expand Down
6 changes: 4 additions & 2 deletions sql/ts/src/skdb_wmessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Creator, onWorkerMessage } from "#std/sk_worker";
import { createSkdb, SKDB } from "#skdb/skdb";
import { onWorkerMessage } from "#std/sk_worker.js";
import type { Creator } from "#std/sk_worker.js";
import type { SKDB } from "./skdb.js";
import { createSkdb } from "./skdb.js";

class DbCreator implements Creator<SKDB> {
getName() {
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb_worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onDbWorkerMessage } from "#skdb/skdb_wmessage";
import { onDbWorkerMessage } from "./skdb_wmessage.js";

var post = (message: any) => {
postMessage(message);
Expand Down
10 changes: 7 additions & 3 deletions sql/ts/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"outDir": "../dist/src",
"baseUrl": ".",
"paths": {
"#std/*": ["../../../prelude/ts/src/*"],
"#skdb/*": ["./*"]
"#std/*": ["../../../prelude/ts/src/*"]
},
"strictNullChecks": true,
"module": "ESNext",
"module": "node16",
"strict": true,
"verbatimModuleSyntax": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"moduleResolution": "Node",
"incremental": true,
"noEmit": true
Expand Down

0 comments on commit 72d4022

Please sign in to comment.