From bca35e0cce138833070df197bcb28d284cd7f05f Mon Sep 17 00:00:00 2001 From: ryan-the-crayon <157742211+ryan-the-crayon@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:43:21 -0500 Subject: [PATCH] Transition to rollup to support exports (#106) * Use .js for imports * WIP * WIP * Finish transitioning to esm * Disable experimental commands * Bring back bootstrap --- package.json | 3 ++- src/FileData.ts | 10 ++++++++-- src/SimpleFileData.ts | 2 +- src/cliPref.ts | 2 +- src/createClient.ts | 6 +++--- src/index.ts | 24 ++++++++++++------------ src/subcommands/bootstrap.ts | 2 +- src/subcommands/create.ts | 4 ++-- src/subcommands/dev.ts | 17 +++++++++-------- src/subcommands/get.ts | 12 ++++++------ src/subcommands/importCmd.ts | 4 ++-- src/subcommands/list.ts | 8 ++++---- src/subcommands/load.ts | 14 +++++++------- src/subcommands/log.ts | 4 ++-- src/subcommands/push.ts | 6 +++--- src/subcommands/server.ts | 4 ++-- src/subcommands/status.ts | 8 ++++---- src/subcommands/unload.ts | 4 ++-- tsconfig.json | 3 ++- 19 files changed, 73 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 46c4e90..d1a26fd 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "bin": "dist/index.js", + "type": "module", "scripts": { "build": "tsc", "watch": "tsc -w", @@ -15,10 +16,10 @@ "license": "Apache-2.0", "dependencies": { "@lmstudio/lms-common": "^0.6.1", + "@lmstudio/lms-es-plugin-runner": "^0.0.1", "@lmstudio/lms-isomorphic": "^0.3.2", "@lmstudio/lms-lmstudio": "^0.0.13", "@lmstudio/sdk": "^0.2.0", - "@lmstudio/lms-es-plugin-runner": "^0.0.1", "boxen": "^5.1.2", "chalk": "^4.1.2", "cmd-ts": "^0.13.0", diff --git a/src/FileData.ts b/src/FileData.ts index 6678294..1b274ae 100644 --- a/src/FileData.ts +++ b/src/FileData.ts @@ -1,5 +1,11 @@ -import { Signal, type Setter, type SimpleLogger } from "@lmstudio/lms-common"; -import { isAvailable, type StripNotAvailable } from "@lmstudio/lms-common/dist/LazySignal"; +import { + isAvailable, + Signal, + type Setter, + type SimpleLogger, + type StripNotAvailable, +} from "@lmstudio/lms-common"; + import { existsSync, writeFileSync } from "fs"; import { mkdir, readFile, watch } from "fs/promises"; import path from "path"; diff --git a/src/SimpleFileData.ts b/src/SimpleFileData.ts index ee1b5d3..cf871da 100644 --- a/src/SimpleFileData.ts +++ b/src/SimpleFileData.ts @@ -1,6 +1,6 @@ import { type SimpleLogger } from "@lmstudio/lms-common"; import { type ZodSchema } from "zod"; -import { FileData } from "./FileData"; +import { FileData } from "./FileData.js"; export class SimpleFileData extends FileData { public constructor( diff --git a/src/cliPref.ts b/src/cliPref.ts index ab5d865..84cec31 100644 --- a/src/cliPref.ts +++ b/src/cliPref.ts @@ -2,7 +2,7 @@ import { SimpleLogger } from "@lmstudio/lms-common"; import os from "os"; import path from "path"; import { z } from "zod"; -import { SimpleFileData } from "./SimpleFileData"; +import { SimpleFileData } from "./SimpleFileData.js"; export async function getCliPref(logger?: SimpleLogger) { const cliPrefSchema = z.object({ diff --git a/src/createClient.ts b/src/createClient.ts index 08d371c..6624263 100644 --- a/src/createClient.ts +++ b/src/createClient.ts @@ -6,9 +6,9 @@ import { option, optional, string } from "cmd-ts"; import { readFile } from "fs/promises"; import { homedir } from "os"; import path from "path"; -import { type LogLevelArgs } from "./logLevel"; -import { checkHttpServer } from "./subcommands/server"; -import { refinedNumber } from "./types/refinedNumber"; +import { type LogLevelArgs } from "./logLevel.js"; +import { checkHttpServer } from "./subcommands/server.js"; +import { refinedNumber } from "./types/refinedNumber.js"; interface AppInstallLocation { path: string; diff --git a/src/index.ts b/src/index.ts index 4660e99..0bb95e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ import { run, subcommands } from "cmd-ts"; -import { bootstrap } from "./subcommands/bootstrap"; -import { create } from "./subcommands/create"; -import { get } from "./subcommands/get"; -import { importCmd } from "./subcommands/importCmd"; -import { ls, ps } from "./subcommands/list"; -import { load } from "./subcommands/load"; -import { log } from "./subcommands/log"; -import { server } from "./subcommands/server"; -import { status } from "./subcommands/status"; -import { unload } from "./subcommands/unload"; -import { printVersion, version } from "./subcommands/version"; +import { bootstrap } from "./subcommands/bootstrap.js"; +import { create } from "./subcommands/create.js"; +import { get } from "./subcommands/get.js"; +import { importCmd } from "./subcommands/importCmd.js"; +import { ls, ps } from "./subcommands/list.js"; +import { load } from "./subcommands/load.js"; +import { log } from "./subcommands/log.js"; +import { server } from "./subcommands/server.js"; +import { status } from "./subcommands/status.js"; +import { unload } from "./subcommands/unload.js"; +import { printVersion, version } from "./subcommands/version.js"; if (process.argv.length === 2) { printVersion(); @@ -32,8 +32,8 @@ const cli = subcommands({ // dev, // push, import: importCmd, - version, bootstrap, + version, }, }); diff --git a/src/subcommands/bootstrap.ts b/src/subcommands/bootstrap.ts index 32b54ed..c2f9fec 100644 --- a/src/subcommands/bootstrap.ts +++ b/src/subcommands/bootstrap.ts @@ -1,4 +1,4 @@ -import { installCli } from "@lmstudio/lms-lmstudio/dist/installCli"; +import { installCli } from "@lmstudio/lms-lmstudio/install-cli"; import { command } from "cmd-ts"; import { platform } from "os"; diff --git a/src/subcommands/create.ts b/src/subcommands/create.ts index 641fdd4..8dcf8fc 100644 --- a/src/subcommands/create.ts +++ b/src/subcommands/create.ts @@ -15,8 +15,8 @@ import { join } from "path"; import * as tar from "tar"; import util from "util"; import { z } from "zod"; -import { createLogger, logLevelArgs } from "../logLevel"; -import { ProgressBar } from "../ProgressBar"; +import { createLogger, logLevelArgs } from "../logLevel.js"; +import { ProgressBar } from "../ProgressBar.js"; const execAsync = util.promisify(exec); const illegalPathChars = ["/", "\\", ":", "*", "?", '"', "<", ">", "|"]; diff --git a/src/subcommands/dev.ts b/src/subcommands/dev.ts index d867fa6..ea3f303 100644 --- a/src/subcommands/dev.ts +++ b/src/subcommands/dev.ts @@ -1,6 +1,7 @@ import { SimpleLogger, text, Validator } from "@lmstudio/lms-common"; -import { EsPluginRunnerWatcher, UtilBinary } from "@lmstudio/lms-es-plugin-runner"; -import { pluginManifestSchema } from "@lmstudio/lms-shared-types/dist/PluginManifest"; +import { EsPluginRunnerWatcher } from "@lmstudio/lms-es-plugin-runner/runner-watcher"; +import { UtilBinary } from "@lmstudio/lms-es-plugin-runner/util-binary"; +import { pluginManifestSchema } from "@lmstudio/lms-shared-types"; import { type LMStudioClient, type PluginManifest, @@ -11,12 +12,12 @@ import { boolean, command, flag } from "cmd-ts"; import { cp, mkdir, readFile } from "fs/promises"; import { join } from "path"; import { cwd } from "process"; -import { askQuestion } from "../confirm"; -import { createClient, createClientArgs } from "../createClient"; -import { exists } from "../exists"; -import { findProjectFolderOrExit } from "../findProjectFolder"; -import { pluginsFolderPath } from "../lmstudioPaths"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { askQuestion } from "../confirm.js"; +import { createClient, createClientArgs } from "../createClient.js"; +import { exists } from "../exists.js"; +import { findProjectFolderOrExit } from "../findProjectFolder.js"; +import { pluginsFolderPath } from "../lmstudioPaths.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; type PluginProcessStatus = "stopped" | "starting" | "running" | "restarting"; diff --git a/src/subcommands/get.ts b/src/subcommands/get.ts index 2d0a911..730526d 100644 --- a/src/subcommands/get.ts +++ b/src/subcommands/get.ts @@ -5,12 +5,12 @@ import { type ModelSearchResultDownloadOption, type ModelSearchResultEntry } fro import chalk from "chalk"; import { boolean, command, flag, option, optional, positional, string } from "cmd-ts"; import inquirer from "inquirer"; -import { askQuestion } from "../confirm"; -import { createClient, createClientArgs } from "../createClient"; -import { formatSizeBytes1000 } from "../formatSizeBytes1000"; -import { createLogger, logLevelArgs } from "../logLevel"; -import { ProgressBar } from "../ProgressBar"; -import { refinedNumber } from "../types/refinedNumber"; +import { askQuestion } from "../confirm.js"; +import { createClient, createClientArgs } from "../createClient.js"; +import { formatSizeBytes1000 } from "../formatSizeBytes1000.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; +import { ProgressBar } from "../ProgressBar.js"; +import { refinedNumber } from "../types/refinedNumber.js"; function formatRemainingTime(timeSeconds: number) { const seconds = timeSeconds % 60; diff --git a/src/subcommands/importCmd.ts b/src/subcommands/importCmd.ts index 2c78878..7269f60 100644 --- a/src/subcommands/importCmd.ts +++ b/src/subcommands/importCmd.ts @@ -16,8 +16,8 @@ import inquirerPrompt from "inquirer-autocomplete-prompt"; import { homedir } from "os"; import { basename, dirname, join } from "path"; import { z } from "zod"; -import { getCliPref } from "../cliPref"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { getCliPref } from "../cliPref.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; const userRepoType: Type = { async from(str) { diff --git a/src/subcommands/list.ts b/src/subcommands/list.ts index 7a83918..28b1ec0 100644 --- a/src/subcommands/list.ts +++ b/src/subcommands/list.ts @@ -3,10 +3,10 @@ import { type DownloadedModel } from "@lmstudio/sdk"; import chalk from "chalk"; import { command, flag } from "cmd-ts"; import columnify from "columnify"; -import { architectureInfoLookup } from "../architectureStylizations"; -import { createClient, createClientArgs } from "../createClient"; -import { formatSizeBytes1000, formatSizeBytesWithColor1000 } from "../formatSizeBytes1000"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { architectureInfoLookup } from "../architectureStylizations.js"; +import { createClient, createClientArgs } from "../createClient.js"; +import { formatSizeBytes1000, formatSizeBytesWithColor1000 } from "../formatSizeBytes1000.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; function loadedCheckBoxed(count: number) { if (count === 0) { diff --git a/src/subcommands/load.ts b/src/subcommands/load.ts index f749895..886dd48 100644 --- a/src/subcommands/load.ts +++ b/src/subcommands/load.ts @@ -10,13 +10,13 @@ import { boolean, command, flag, option, optional, positional, string, type Type import fuzzy from "fuzzy"; import inquirer from "inquirer"; import inquirerPrompt from "inquirer-autocomplete-prompt"; -import { getCliPref } from "../cliPref"; -import { createClient, createClientArgs } from "../createClient"; -import { formatElapsedTime } from "../formatElapsedTime"; -import { formatSizeBytes1000 } from "../formatSizeBytes1000"; -import { createLogger, logLevelArgs } from "../logLevel"; -import { ProgressBar } from "../ProgressBar"; -import { refinedNumber } from "../types/refinedNumber"; +import { getCliPref } from "../cliPref.js"; +import { createClient, createClientArgs } from "../createClient.js"; +import { formatElapsedTime } from "../formatElapsedTime.js"; +import { formatSizeBytes1000 } from "../formatSizeBytes1000.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; +import { ProgressBar } from "../ProgressBar.js"; +import { refinedNumber } from "../types/refinedNumber.js"; const gpuOptionType: Type = { async from(str) { diff --git a/src/subcommands/log.ts b/src/subcommands/log.ts index aa236ba..509090a 100644 --- a/src/subcommands/log.ts +++ b/src/subcommands/log.ts @@ -1,8 +1,8 @@ import { type DiagnosticsLogEventData } from "@lmstudio/lms-shared-types"; import chalk from "chalk"; import { command, flag, subcommands } from "cmd-ts"; -import { createClient, createClientArgs } from "../createClient"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { createClient, createClientArgs } from "../createClient.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; const stream = command({ name: "stream", diff --git a/src/subcommands/push.ts b/src/subcommands/push.ts index 84210fe..dbacd74 100644 --- a/src/subcommands/push.ts +++ b/src/subcommands/push.ts @@ -1,8 +1,8 @@ import { command } from "cmd-ts"; import { cwd } from "process"; -import { createClient, createClientArgs } from "../createClient"; -import { findProjectFolderOrExit } from "../findProjectFolder"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { createClient, createClientArgs } from "../createClient.js"; +import { findProjectFolderOrExit } from "../findProjectFolder.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; export const push = command({ name: "push", diff --git a/src/subcommands/server.ts b/src/subcommands/server.ts index c3f5ff7..134c2ac 100644 --- a/src/subcommands/server.ts +++ b/src/subcommands/server.ts @@ -3,8 +3,8 @@ import { command, flag, number, option, optional, subcommands } from "cmd-ts"; import { mkdir, readFile, writeFile } from "fs/promises"; import os from "os"; import path from "path"; -import { wakeUpService } from "../createClient"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { wakeUpService } from "../createClient.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; type HttpServerCtl = | { diff --git a/src/subcommands/status.ts b/src/subcommands/status.ts index 9e651ba..331b098 100644 --- a/src/subcommands/status.ts +++ b/src/subcommands/status.ts @@ -2,10 +2,10 @@ import { text } from "@lmstudio/lms-common"; import boxen from "boxen"; import chalk from "chalk"; import { command } from "cmd-ts"; -import { createClient, createClientArgs } from "../createClient"; -import { formatSizeBytesWithColor1000 } from "../formatSizeBytes1000"; -import { createLogger, logLevelArgs } from "../logLevel"; -import { checkHttpServer, getServerConfig } from "./server"; +import { createClient, createClientArgs } from "../createClient.js"; +import { formatSizeBytesWithColor1000 } from "../formatSizeBytes1000.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; +import { checkHttpServer, getServerConfig } from "./server.js"; export const status = command({ name: "status", diff --git a/src/subcommands/unload.ts b/src/subcommands/unload.ts index 0bba79f..b8331e7 100644 --- a/src/subcommands/unload.ts +++ b/src/subcommands/unload.ts @@ -5,8 +5,8 @@ import { boolean, command, flag, optional, positional, string } from "cmd-ts"; import fuzzy from "fuzzy"; import inquirer from "inquirer"; import inquirerPrompt from "inquirer-autocomplete-prompt"; -import { createClient, createClientArgs } from "../createClient"; -import { createLogger, logLevelArgs } from "../logLevel"; +import { createClient, createClientArgs } from "../createClient.js"; +import { createLogger, logLevelArgs } from "../logLevel.js"; export const unload = command({ name: "unload", diff --git a/tsconfig.json b/tsconfig.json index a89aec1..715919a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,9 @@ "rootDir": "src", "outDir": "dist", "strict": true, - "module": "CommonJS", "target": "ES2021", + "module": "nodenext", + "moduleResolution": "nodenext", "declaration": true, "incremental": true, "noImplicitOverride": true,