From 430e28a023b8fcf2de767e30dc1afef390381467 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Sun, 3 Mar 2024 14:50:48 -0500 Subject: [PATCH] export bin as .mjs --- bin/{cli.ts => cli.mts} | 8 ++++++-- index.ts | 6 +++--- package.json | 16 ++++------------ src/getModuleHash.ts | 2 +- src/parseFilename.ts | 2 +- tsconfig.json | 9 ++++----- version.ts | 1 + 7 files changed, 20 insertions(+), 24 deletions(-) rename bin/{cli.ts => cli.mts} (71%) create mode 100644 version.ts diff --git a/bin/cli.ts b/bin/cli.mts similarity index 71% rename from bin/cli.ts rename to bin/cli.mts index 62b28d1..8855269 100644 --- a/bin/cli.ts +++ b/bin/cli.mts @@ -3,16 +3,20 @@ import { Option } from "commander"; import { commander } from "substreams-sink"; import { action } from "../index.js"; -import pkg from "../package.json" assert { type: "json" }; +import { version } from "../version.js"; export interface CSVRunOptions extends commander.RunOptions { schema: string; filename?: string; } +const name = "substreams-sink-csv"; +const description = "Substreams Sink CSV"; +const pkg = {name, version, description}; + // Run Webhook Sink const program = commander.program(pkg); -const command = commander.addRunOptions(program, pkg, {metrics: false, http: false}); +const command = commander.addRunOptions(program, {metrics: false, http: false}); command.addOption(new Option("--filename ", "CSV filename (default: '--.csv')").env("FILENAME")); command.addOption(new Option("--schema ", "SQL Table Schema for CSV").default("schema.sql").env("SCHEMA")); command.action(action); diff --git a/index.ts b/index.ts index 76a540b..9ccf887 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,8 @@ import fs from "fs"; import path from "path"; -import pkg from "./package.json" assert { type: "json" }; +import { version } from './version.js' import { setup, fileCursor } from "substreams-sink"; -import { CSVRunOptions } from "./bin/cli.js" +import { CSVRunOptions } from "./bin/cli.mjs" import { EntityChanges, getValuesInEntityChange } from "@substreams/sink-entity-changes/zod" import logUpdate from "log-update"; import { getModuleHash, isRemotePath } from "./src/getModuleHash.js"; @@ -11,7 +11,7 @@ import { parseClock } from "./src/parseClock.js"; import { parseSchema } from "./src/parseSchema.js"; export async function action(options: CSVRunOptions ) { - console.log(`[substreams-sink-csv] v${pkg.version}`); + console.log(`[substreams-sink-csv] v${version}`); // handle file system manifest // can be removed when issue resolved diff --git a/package.json b/package.json index 7fa83d5..5f48fc2 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,8 @@ "name": "substreams-sink-csv", "description": "Substreams Sink CSV", "type": "module", - "main": "dist/index.js", - "types": "dist/index.d.ts", "bin": { - "substreams-sink-csv": "dist/bin/cli.js" + "substreams-sink-csv": "dist/bin/cli.mjs" }, "author": { "name": "Denis", @@ -14,19 +12,13 @@ }, "files": [ "index.ts", + "version.ts", "dist", + "bin", "src" ], - "sideEffects": false, - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "default": "./dist/index.js" - } - }, "scripts": { - "start": "tsc && node ./dist/bin/cli.js", + "start": "tsc && node ./dist/bin/cli.mjs", "test": "bun test", "posttest": "tsc --noEmit", "prepublishOnly": "tsc" diff --git a/src/getModuleHash.ts b/src/getModuleHash.ts index 92207ea..342fc99 100644 --- a/src/getModuleHash.ts +++ b/src/getModuleHash.ts @@ -1,5 +1,5 @@ import { readPackage } from "@substreams/manifest"; -import { CSVRunOptions } from "../bin/cli.js"; +import { CSVRunOptions } from "../bin/cli.mjs"; import { createModuleHashHex } from "@substreams/core"; export function isRemotePath(path: string): boolean { diff --git a/src/parseFilename.ts b/src/parseFilename.ts index 00366fe..360f5c3 100644 --- a/src/parseFilename.ts +++ b/src/parseFilename.ts @@ -1,6 +1,6 @@ import path from "path"; import fs from "fs"; -import { CSVRunOptions } from "../bin/cli.js"; +import { CSVRunOptions } from "../bin/cli.mjs"; export function parseFilename(moduleHash: string, options: CSVRunOptions) { // user provided filename diff --git a/tsconfig.json b/tsconfig.json index ebe2583..01de923 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,8 @@ -{ + { "compilerOptions": { "target": "ESNext", "module": "NodeNext", "moduleResolution": "NodeNext", - "resolveJsonModule": true, "declaration": true, "declarationMap": true, "sourceMap": true, @@ -13,11 +12,11 @@ "strictNullChecks": true, "alwaysStrict": true, "skipLibCheck": true, - "types": ["bun-types"] + "types": ["@types/bun"] }, "include": [ "index-csv.ts", "src", - "bin/cli.ts" + "bin/cli.mts" ] -} \ No newline at end of file + } diff --git a/version.ts b/version.ts new file mode 100644 index 0000000..98dfbc9 --- /dev/null +++ b/version.ts @@ -0,0 +1 @@ +export const version = "0.2.9"; \ No newline at end of file