Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to esm #367

Merged
merged 8 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
site
.eslintrc.js
.eslintrc.cjs
build_utils
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ node_modules/
# Coverage
coverage

# Transpiled files
build/

# Optional npm cache directory
.npm

Expand Down
4 changes: 1 addition & 3 deletions build_utils/eslintrc.js → build_utils/eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.eslintrc.js
/.eslintrc.cjs
/dist
/build.mjs
1 change: 1 addition & 0 deletions packages/cli-common/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/cli-common/.eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/cli-common/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -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',
},
}
6 changes: 0 additions & 6 deletions packages/cli-common/jest.config.js

This file was deleted.

16 changes: 10 additions & 6 deletions packages/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand All @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions packages/cli-common/src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>
Expand Down Expand Up @@ -68,7 +69,7 @@ abstract class BaseCommand<T extends typeof Command=typeof Command> extends Comm
)
}

protected get preevyConfig() {
protected get preevyConfig(): PreevyConfig {
return this.config.preevyConfig
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cli-common/src/hooks/init/load-plugins.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions packages/cli-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 3 additions & 3 deletions packages/cli-common/src/lib/common-flags/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof ux.table['flags']>

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/flags.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/flags.ts
Original file line number Diff line number Diff line change
@@ -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<T> =Pick<Flag<T>, 'type' | 'default'>

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/hooks.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/log.ts
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/plugins/commands.ts
Original file line number Diff line number Diff line change
@@ -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 })))
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-common/src/lib/plugins/flags.ts
Original file line number Diff line number Diff line change
@@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-common/src/lib/plugins/hooks.ts
Original file line number Diff line number Diff line change
@@ -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[],
Expand Down
10 changes: 5 additions & 5 deletions packages/cli-common/src/lib/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 4 additions & 4 deletions packages/cli-common/src/lib/plugins/load.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-common/src/lib/plugins/model.ts
Original file line number Diff line number Diff line change
@@ -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<string, FlagProps>
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/src/lib/plugins/topics.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 8 additions & 5 deletions packages/cli-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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" },
]
Expand Down
1 change: 1 addition & 0 deletions packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../build_utils/eslintrc.cjs')
1 change: 0 additions & 1 deletion packages/cli/.eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_modules/
coverage

# Transpiled files
build/
/build/

# Optional npm cache directory
.npm
Expand Down
Loading
Loading