diff --git a/.eslintignore b/.eslintignore index b1d80557..0aec16d9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ site -.eslintrc.js +.eslintrc.cjs build_utils \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8bee4e9f..45a22c69 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,6 @@ node_modules/ # Coverage coverage -# Transpiled files -build/ - # Optional npm cache directory .npm diff --git a/build_utils/eslintrc.js b/build_utils/eslintrc.cjs similarity index 98% rename from build_utils/eslintrc.js rename to build_utils/eslintrc.cjs index dacc41fe..26d254e4 100644 --- a/build_utils/eslintrc.js +++ b/build_utils/eslintrc.cjs @@ -40,6 +40,7 @@ module.exports = { 'single', { avoidEscape: true, allowTemplateLiterals: false }, ], + 'import/extensions': 'off', 'dot-location': 'warn', 'no-trailing-spaces': 'warn', 'no-multi-spaces': 'warn', @@ -101,9 +102,6 @@ module.exports = { } ], 'jest/valid-describe': ['off'], - 'import/extensions': ['error', 'never', { - 'json': 'always', - }], 'no-restricted-imports': ['error', { patterns: ['**/dist/**', 'src/*'] }], // copied from https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js#L334 // removed rule about generators/iterators since es2019 natively supports them diff --git a/package.json b/package.json index 60e7c9a4..dddbaa60 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ ], "devDependencies": { "husky": "^8.0.0", + "jest": "29.7.0", "lerna": "^6.6.2", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "patch-package": "^8.0.0", "postinstall-postinstall": "^2.1.0", "syncpack": "^9.8.4", - "typescript": "^5.2.2" + "typescript": "^5.3.3" }, "resolutions": { "**/@oclif/core": "livecycle/oclif-core-patched-for-preevy#v3.12.0-preevy-patch-10" diff --git a/packages/cli-common/.eslintignore b/packages/cli-common/.eslintignore index 4a74d128..33bffeaa 100644 --- a/packages/cli-common/.eslintignore +++ b/packages/cli-common/.eslintignore @@ -1,3 +1,3 @@ -/.eslintrc.js +/.eslintrc.cjs /dist /build.mjs \ No newline at end of file diff --git a/packages/cli-common/.eslintrc.cjs b/packages/cli-common/.eslintrc.cjs new file mode 100644 index 00000000..1a4bf217 --- /dev/null +++ b/packages/cli-common/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('../../build_utils/eslintrc.cjs') \ No newline at end of file diff --git a/packages/cli-common/.eslintrc.js b/packages/cli-common/.eslintrc.js deleted file mode 100644 index de29daef..00000000 --- a/packages/cli-common/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('../../build_utils/eslintrc.js') \ No newline at end of file diff --git a/packages/cli-common/jest.config.cjs b/packages/cli-common/jest.config.cjs new file mode 100644 index 00000000..d69d187d --- /dev/null +++ b/packages/cli-common/jest.config.cjs @@ -0,0 +1,20 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest/presets/default-esm', + testEnvironment: 'node', + testMatch: ['!dist/', '**/*.test.ts'], + extensionsToTreatAsEsm: ['.ts'], + transform: { + // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest` + // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest` + '^.+\\.tsx?$': [ + 'ts-jest', + { + useESM: true, + }, + ], + }, + moduleNameMapper: { + '^(\\.{1,2}/.+)\\.js$': '$1', + }, +} diff --git a/packages/cli-common/jest.config.js b/packages/cli-common/jest.config.js deleted file mode 100644 index 22c3f9f6..00000000 --- a/packages/cli-common/jest.config.js +++ /dev/null @@ -1,6 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} */ -module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - testMatch: ['!dist/', '**/*.test.ts'], -} diff --git a/packages/cli-common/package.json b/packages/cli-common/package.json index 529909eb..bcbfd29b 100644 --- a/packages/cli-common/package.json +++ b/packages/cli-common/package.json @@ -2,7 +2,11 @@ "name": "@preevy/cli-common", "version": "0.0.58", "description": "Common library for the Preevy CLI and plugins", + "type": "module", "main": "dist/index.js", + "exports": { + ".": "./dist/index.js" + }, "files": [ "dist" ], @@ -12,14 +16,14 @@ "@preevy/core": "0.0.58", "chalk": "^4.1.2", "iter-tools-es": "^7.5.3", - "lodash": "^4.17.21" + "lodash-es": "^4.17.21" }, "devDependencies": { "@jest/globals": "29.7.0", - "@types/lodash": "^4.14.192", + "@types/lodash-es": "^4.17.12", "@types/node": "18", - "@typescript-eslint/eslint-plugin": "6.10.0", - "@typescript-eslint/parser": "6.10.0", + "@typescript-eslint/eslint-plugin": "6.14.0", + "@typescript-eslint/parser": "6.14.0", "eslint": "^8.36.0", "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.27.5", @@ -30,11 +34,11 @@ "lint-staged": "^15.2.0", "shx": "^0.3.3", "tslib": "^2.5.0", - "typescript": "^5.2.2" + "typescript": "^5.3.3" }, "scripts": { "lint": "eslint . --ext .ts,.tsx --cache", - "test": "yarn jest", + "test": "yarn node --experimental-vm-modules ../../node_modules/.bin/jest", "clean": "shx rm -rf dist tsconfig.tsbuildinfo", "build": "tsc -b", "prepack": "yarn clean && yarn build", diff --git a/packages/cli-common/src/commands/base-command.ts b/packages/cli-common/src/commands/base-command.ts index 20b3244b..29e05f0d 100644 --- a/packages/cli-common/src/commands/base-command.ts +++ b/packages/cli-common/src/commands/base-command.ts @@ -3,9 +3,10 @@ import { LogLevel, Logger, logLevels, ComposeModel, ProcessError, telemetryEmitter, } from '@preevy/core' import { asyncReduce } from 'iter-tools-es' -import { ParsingToken } from '@oclif/core/lib/interfaces/parser' -import { commandLogger } from '../lib/log' -import { composeFlags, pluginFlags } from '../lib/common-flags' +import { ParsingToken } from '@oclif/core/lib/interfaces/parser.js' +import { commandLogger } from '../lib/log.js' +import { composeFlags, pluginFlags } from '../lib/common-flags/index.js' +import { PreevyConfig } from '../../../core/src/config.js' // eslint-disable-next-line no-use-before-define export type Flags = Interfaces.InferredFlags @@ -68,7 +69,7 @@ abstract class BaseCommand extends Comm ) } - protected get preevyConfig() { + protected get preevyConfig(): PreevyConfig { return this.config.preevyConfig } diff --git a/packages/cli-common/src/hooks/init/load-plugins.ts b/packages/cli-common/src/hooks/init/load-plugins.ts index 9588793e..632585ae 100644 --- a/packages/cli-common/src/hooks/init/load-plugins.ts +++ b/packages/cli-common/src/hooks/init/load-plugins.ts @@ -1,10 +1,10 @@ import { Hook as OclifHook, Command, Flags } from '@oclif/core' -import { Parser } from '@oclif/core/lib/parser/parse' +import { Parser } from '@oclif/core/lib/parser/parse.js' import { BooleanFlag, Config, Topic } from '@oclif/core/lib/interfaces' import { localComposeClient, ComposeModel, resolveComposeFiles, withSpinner, NoComposeFilesError } from '@preevy/core' -import { cloneDeep } from 'lodash' -import { composeFlags, pluginFlags } from '../../lib/common-flags' -import { addPluginFlags, loadPlugins, hooksFromPlugins, addPluginCommands } from '../../lib/plugins' +import { cloneDeep } from 'lodash-es' +import { composeFlags, pluginFlags } from '../../lib/common-flags/index.js' +import { addPluginFlags, loadPlugins, hooksFromPlugins, addPluginCommands } from '../../lib/plugins/index.js' type InternalConfig = Config & { loadCommands: (plugin: { commands: Command.Loadable[]; topics: Topic[] }) => void diff --git a/packages/cli-common/src/index.ts b/packages/cli-common/src/index.ts index 5eceef1d..4f483d91 100644 --- a/packages/cli-common/src/index.ts +++ b/packages/cli-common/src/index.ts @@ -1,10 +1,10 @@ -export * from './lib/plugins/model' -export * as text from './lib/text' -export { HookName, HookFunc, HooksListeners, Hooks } from './lib/hooks' -export { PluginContext, PluginInitContext } from './lib/plugins/context' +export * from './lib/plugins/model.js' +export * as text from './lib/text.js' +export { HookName, HookFunc, HooksListeners, Hooks } from './lib/hooks.js' +export { PluginContext, PluginInitContext } from './lib/plugins/context.js' export { composeFlags, pluginFlags, envIdFlags, tunnelServerFlags, urlFlags, buildFlags, tableFlags, parseBuildFlags, -} from './lib/common-flags' -export { formatFlagsToArgs, parseFlags, ParsedFlags } from './lib/flags' -export { initHook } from './hooks/init/load-plugins' -export { default as BaseCommand } from './commands/base-command' +} from './lib/common-flags/index.js' +export { formatFlagsToArgs, parseFlags, ParsedFlags } from './lib/flags.js' +export { initHook } from './hooks/init/load-plugins.js' +export { default as BaseCommand } from './commands/base-command.js' diff --git a/packages/cli-common/src/lib/common-flags/index.ts b/packages/cli-common/src/lib/common-flags/index.ts index 57d1e9f4..028ca108 100644 --- a/packages/cli-common/src/lib/common-flags/index.ts +++ b/packages/cli-common/src/lib/common-flags/index.ts @@ -1,9 +1,9 @@ import { Flags, ux } from '@oclif/core' -import { mapValues } from 'lodash' +import { mapValues } from 'lodash-es' import { EOL } from 'os' -import { DEFAULT_PLUGINS } from '../plugins/default-plugins' +import { DEFAULT_PLUGINS } from '../plugins/default-plugins.js' -export * from './build-flags' +export * from './build-flags.js' export const tableFlags = mapValues(ux.table.flags(), f => ({ ...f, helpGroup: 'OUTPUT' })) as ReturnType diff --git a/packages/cli-common/src/lib/flags.test.ts b/packages/cli-common/src/lib/flags.test.ts index 28dafa97..5902fd8d 100644 --- a/packages/cli-common/src/lib/flags.test.ts +++ b/packages/cli-common/src/lib/flags.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from '@jest/globals' -import { formatFlagsToArgs } from './flags' +import { formatFlagsToArgs } from './flags.js' describe('formatFlagsToArgs', () => { describe('when given accepted characters', () => { diff --git a/packages/cli-common/src/lib/flags.ts b/packages/cli-common/src/lib/flags.ts index 10c1f6a9..d07024c1 100644 --- a/packages/cli-common/src/lib/flags.ts +++ b/packages/cli-common/src/lib/flags.ts @@ -1,5 +1,5 @@ import { Flag } from '@oclif/core/lib/interfaces' -import { Parser } from '@oclif/core/lib/parser/parse' +import { Parser } from '@oclif/core/lib/parser/parse.js' type FlagSpec =Pick, 'type' | 'default'> diff --git a/packages/cli-common/src/lib/hooks.ts b/packages/cli-common/src/lib/hooks.ts index 07f7ca31..5d038500 100644 --- a/packages/cli-common/src/lib/hooks.ts +++ b/packages/cli-common/src/lib/hooks.ts @@ -1,5 +1,5 @@ import { ComposeModel, FlatTunnel } from '@preevy/core' -import { PluginContext } from './plugins/context' +import { PluginContext } from './plugins/context.js' export type Hooks = { filterUrls: { diff --git a/packages/cli-common/src/lib/log.ts b/packages/cli-common/src/lib/log.ts index d4965e00..318a856f 100644 --- a/packages/cli-common/src/lib/log.ts +++ b/packages/cli-common/src/lib/log.ts @@ -1,6 +1,6 @@ import { Command } from '@oclif/core' import { Logger, LogLevel, logLevels, nullLogFunc } from '@preevy/core' -import { mapValues } from 'lodash' +import { mapValues } from 'lodash-es' export const commandLogger = ( command: { logLevel: LogLevel }, diff --git a/packages/cli-common/src/lib/plugins/commands.ts b/packages/cli-common/src/lib/plugins/commands.ts index 4bf48c0f..d4e4598a 100644 --- a/packages/cli-common/src/lib/plugins/commands.ts +++ b/packages/cli-common/src/lib/plugins/commands.ts @@ -1,5 +1,5 @@ import { Command } from '@oclif/core' -import { LoadedPlugin } from './load' +import { LoadedPlugin } from './load.js' const pluginCommands = (loadedPlugins: LoadedPlugin[]) => loadedPlugins .flatMap(p => (p.initResults.commands ?? []).map(c => ({ command: c, pluginConfig: p.config }))) diff --git a/packages/cli-common/src/lib/plugins/flags.ts b/packages/cli-common/src/lib/plugins/flags.ts index ac7db1e5..02990cbc 100644 --- a/packages/cli-common/src/lib/plugins/flags.ts +++ b/packages/cli-common/src/lib/plugins/flags.ts @@ -1,7 +1,7 @@ import { Command } from '@oclif/core' -import { groupBy } from 'lodash' -import { CommandFlags } from './model' -import { LoadedPlugin } from './load' +import { groupBy } from 'lodash-es' +import { CommandFlags } from './model.js' +import { LoadedPlugin } from './load.js' const addFlags = ( commands: Command.Loadable[], diff --git a/packages/cli-common/src/lib/plugins/hooks.ts b/packages/cli-common/src/lib/plugins/hooks.ts index 358b3b8e..181f5c64 100644 --- a/packages/cli-common/src/lib/plugins/hooks.ts +++ b/packages/cli-common/src/lib/plugins/hooks.ts @@ -1,5 +1,5 @@ -import { HookFunc, HookName, hookNames } from '../hooks' -import { InitResults } from './model' +import { HookFunc, HookName, hookNames } from '../hooks.js' +import { InitResults } from './model.js' export const hooksFromPlugins = ( initResults: InitResults[], diff --git a/packages/cli-common/src/lib/plugins/index.ts b/packages/cli-common/src/lib/plugins/index.ts index f61b2634..33dfbb28 100644 --- a/packages/cli-common/src/lib/plugins/index.ts +++ b/packages/cli-common/src/lib/plugins/index.ts @@ -1,5 +1,5 @@ -export { loadPlugins } from './load' -export { addPluginFlags } from './flags' -export { addPluginCommands } from './commands' -export { hooksFromPlugins } from './hooks' -export { DEFAULT_PLUGINS } from './default-plugins' +export { loadPlugins } from './load.js' +export { addPluginFlags } from './flags.js' +export { addPluginCommands } from './commands.js' +export { hooksFromPlugins } from './hooks.js' +export { DEFAULT_PLUGINS } from './default-plugins.js' diff --git a/packages/cli-common/src/lib/plugins/load.ts b/packages/cli-common/src/lib/plugins/load.ts index 8ca14dae..9705d218 100644 --- a/packages/cli-common/src/lib/plugins/load.ts +++ b/packages/cli-common/src/lib/plugins/load.ts @@ -1,11 +1,11 @@ import { Config } from '@oclif/core' import { InferredFlags } from '@oclif/core/lib/interfaces' import { config as coreConfig } from '@preevy/core' -import { InitResults, PluginModule } from './model' -import { PluginInitContext } from './context' +import { InitResults, PluginModule } from './model.js' +import { PluginInitContext } from './context.js' import PreevyPluginConfig = coreConfig.PreevyPluginConfig -import { pluginFlags } from '../common-flags' -import { DEFAULT_PLUGINS } from './default-plugins' +import { pluginFlags } from '../common-flags/index.js' +import { DEFAULT_PLUGINS } from './default-plugins.js' export type LoadedPlugin = { initResults: InitResults diff --git a/packages/cli-common/src/lib/plugins/model.ts b/packages/cli-common/src/lib/plugins/model.ts index 05167ede..89253e72 100644 --- a/packages/cli-common/src/lib/plugins/model.ts +++ b/packages/cli-common/src/lib/plugins/model.ts @@ -1,9 +1,9 @@ -import { FlagProps } from '@oclif/core/lib/interfaces/parser' +import { FlagProps } from '@oclif/core/lib/interfaces/parser.js' import { Topic } from '@oclif/core/lib/interfaces' import { Command } from '@oclif/core' import { ComposeModel, config as coreConfig } from '@preevy/core' -import { PluginInitContext } from './context' -import { HookFuncs, HooksListeners } from '../hooks' +import { PluginInitContext } from './context.js' +import { HookFuncs, HooksListeners } from '../hooks.js' import PreevyConfig = coreConfig.PreevyConfig export type Flags = Record @@ -23,7 +23,7 @@ export type PluginModule = { preevyPlugin: Plugin } -declare module '@oclif/core/lib/config/config' { +declare module '@oclif/core/lib/config/config.js' { export interface Config { composeFiles: string[] initialUserModel: ComposeModel | Error diff --git a/packages/cli-common/src/lib/plugins/topics.ts b/packages/cli-common/src/lib/plugins/topics.ts index c099b247..63381f8e 100644 --- a/packages/cli-common/src/lib/plugins/topics.ts +++ b/packages/cli-common/src/lib/plugins/topics.ts @@ -1,5 +1,5 @@ import { Topic } from '@oclif/core/lib/interfaces' -import { LoadedPlugin } from './load' +import { LoadedPlugin } from './load.js' export const addPluginCommands = (topics: Topic[], loadedPlugins: LoadedPlugin[]) => [ ...topics, diff --git a/packages/cli-common/tsconfig.json b/packages/cli-common/tsconfig.json index 7b87897e..30af1313 100644 --- a/packages/cli-common/tsconfig.json +++ b/packages/cli-common/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "lib": ["ES2022"], - "module": "CommonJS", - "target": "ES2019", - "moduleResolution": "node", + "module": "Node16", + "target": "ES2020", + "moduleResolution": "Node16", + "lib": ["es2022", "ESNext.Disposable"], "strict": true, "esModuleInterop": true, "skipLibCheck": true, @@ -24,8 +24,11 @@ "baseUrl": ".", "rootDir": "src", }, + "ts-node": { + "esm": true + }, "include": ["**/*"], - "exclude": ["jest.config.js", "dist", "lint-staged.config.cjs"], + "exclude": ["jest.config.cjs", "dist", "lint-staged.config.cjs"], "references": [ { "path": "../core" }, ] diff --git a/packages/cli/.eslintrc.cjs b/packages/cli/.eslintrc.cjs new file mode 100644 index 00000000..652c451c --- /dev/null +++ b/packages/cli/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('../../build_utils/eslintrc.cjs') diff --git a/packages/cli/.eslintrc.js b/packages/cli/.eslintrc.js deleted file mode 100644 index 25256f88..00000000 --- a/packages/cli/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('../../build_utils/eslintrc.js') diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore index 64a06d27..0e2ac517 100644 --- a/packages/cli/.gitignore +++ b/packages/cli/.gitignore @@ -11,7 +11,7 @@ node_modules/ coverage # Transpiled files -build/ +/build/ # Optional npm cache directory .npm diff --git a/packages/cli/README.md b/packages/cli/README.md index c3880a6d..8d5473e1 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -11,6 +11,7 @@ Preevy is a CLI tool for easily creating preview environments for your Docker Co * [Usage](#usage) * [Commands](#commands) +* [Command Topics](#command-topics) # Usage @@ -28,1015 +29,19 @@ USAGE # Commands -* [`preevy down`](#preevy-down) -* [`preevy help [COMMANDS]`](#preevy-help-commands) -* [`preevy init [PROFILE-ALIAS]`](#preevy-init-profile-alias) -* [`preevy login`](#preevy-login) -* [`preevy logs [SERVICES]`](#preevy-logs-services) -* [`preevy ls`](#preevy-ls) -* [`preevy profile config update`](#preevy-profile-config-update) -* [`preevy profile config view`](#preevy-profile-config-view) -* [`preevy profile cp`](#preevy-profile-cp) -* [`preevy profile create NAME URL`](#preevy-profile-create-name-url) -* [`preevy profile current`](#preevy-profile-current) -* [`preevy profile import LOCATION`](#preevy-profile-import-location) -* [`preevy profile key [TYPE]`](#preevy-profile-key-type) -* [`preevy profile link`](#preevy-profile-link) -* [`preevy profile ls`](#preevy-profile-ls) -* [`preevy profile rm NAME`](#preevy-profile-rm-name) -* [`preevy profile use NAME`](#preevy-profile-use-name) -* [`preevy purge`](#preevy-purge) -* [`preevy ssh ENVID`](#preevy-ssh-envid) -* [`preevy up [SERVICE]`](#preevy-up-service) -* [`preevy urls [SERVICE] [PORT]`](#preevy-urls-service-port) -* [`preevy version`](#preevy-version) +# Command Topics + +* [`preevy down`](docs/down.md) - Delete preview environments +* [`preevy help`](docs/help.md) - Display help for preevy. +* [`preevy init`](docs/init.md) - Initialize or import a new profile +* [`preevy login`](docs/login.md) - Login to the Livecycle SaaS +* [`preevy logs`](docs/logs.md) - Show logs for an existing environment +* [`preevy ls`](docs/ls.md) - List preview environments +* [`preevy profile`](docs/profile.md) - View and update profile configuration +* [`preevy purge`](docs/purge.md) - Delete all cloud provider machines, and potentially other resources +* [`preevy ssh`](docs/ssh.md) - Execute a command or start an interactive shell inside an environment +* [`preevy up`](docs/up.md) - Bring up a preview environment +* [`preevy urls`](docs/urls.md) - Show urls for an existing environment +* [`preevy version`](docs/version.md) - Show Preevy version -## `preevy down` - -Delete preview environments - -``` -USAGE - $ preevy down [--json] [-D] [-f ] [--system-compose-file ] [-p ] [--enable-plugin - ] [--disable-plugin ] [--profile ] [-d lightsail|gce|azure|kube-pod] [--lightsail-region - ] [--gce-project-id ] [--gce-zone ] [--azure-region ] [--azure-subscription-id ] - [--kube-pod-namespace ] [--kube-pod-kubeconfig ] [--kube-pod-context ] [--kube-pod-template - ] [--id ] [--force] [--wait] [--github-token ] [--github-repo ] [--github-pull-request - ] [--github-pr-comment-template-file ] [--github-add-build-cache] [--github-pr-comment-enabled - auto|no|always] - -FLAGS - -d, --driver=