Skip to content

Commit

Permalink
refactor(cli)!: reimplement with nest-commander
Browse files Browse the repository at this point in the history
- https://github.com/jmcdo29/nest-commander
- removes support for node14 so `assert { type: json }` can be used

Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Apr 4, 2023
1 parent 56965d5 commit 9bc1543
Show file tree
Hide file tree
Showing 66 changed files with 4,455 additions and 625 deletions.
14 changes: 7 additions & 7 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
---
codecov:
notify:
after_n_builds: 4
after_n_builds: 3
wait_for_ci: true
require_ci_to_pass: true

comment:
after_n_builds: 4
after_n_builds: 3
behavior: default
layout: header,diff,flags,components,tree,footer
require_base: false
Expand All @@ -24,6 +24,10 @@ component_management:
- type: project
target: 100%
individual_components:
- component_id: cli
name: cli
paths:
- src/cli/**/*.ts
- component_id: config
name: config
paths:
Expand Down Expand Up @@ -100,10 +104,6 @@ flags:
carryforward: false
paths:
- src/
node14:
carryforward: false
paths:
- src/

github_checks:
annotations: true
Expand All @@ -112,13 +112,13 @@ ignore:
- '**/__mocks__/**'
- '**/__tests__/**'
- '**/index.ts'
- src/cli.ts
- src/interfaces/
- src/plugins/**/options.ts
- src/types/

profiling:
critical_files_paths:
- src/cli/**/*.ts
- src/config/*.ts
- src/internal/create-context.ts
- src/make.ts
1 change: 1 addition & 0 deletions .dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ lintstagedrc
memfs
mkbuild
mlly
nestjs
nocheck
npmrc
nvmrc
Expand Down
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const config = {
overrides: [
...require('./.eslintrc.base.cjs').overrides,
{
files: ['loader.mjs'],
files: ['config/changelog.config.ts'],
rules: {
'@typescript-eslint/no-use-before-define': 0
'@typescript-eslint/require-await': 0
}
}
],
Expand Down
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ updates:
prefix: build
include: scope
directory: /
ignore:
- dependency-name: nest-commander
labels:
- scope:dependencies
- type:build
Expand Down
4 changes: 3 additions & 1 deletion .github/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ branches:
- context: gitguardian
- context: lint
- context: spelling
- context: test (14)
- context: test (16)
- context: test (18)
- context: test (19)
Expand Down Expand Up @@ -217,10 +216,13 @@ repository:
topics:
- bundle
- bundler
- cli
- dts
- esbuild
- file-to-file
- jsx
- nest-commander
- nestjs-commander
- react
- transpile
- transpiler
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ jobs:
- 19
- 18
- 16
- 14
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
],
"breadcrumbs.enabled": true,
"cSpell.enabled": true,
"coverage-gutters.coverageBaseDir": "coverage",
"coverage-gutters.coverageReportFileName": "lcov.info",
"coverage-gutters.showGutterCoverage": true,
"coverage-gutters.showLineCoverage": false,
"coverage-gutters.showRulerCoverage": false,
"debug.showBreakpointsInOverviewRuler": true,
"diffEditor.ignoreTrimWhitespace": false,
"diffEditor.renderSideBySide": false,
Expand Down
6 changes: 6 additions & 0 deletions __tests__/serve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cleanUrls": true,
"directoryListing": true,
"public": "../coverage/lcov-report",
"trailingSlash": true
}
2 changes: 1 addition & 1 deletion __tests__/ts/v4/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"declaration": true,
"noEmitOnError": true,
"skipLibCheck": false,
"target": "es2020"
"target": "es2022"
},
"exclude": ["**/__mocks__", "**/__tests__"],
"extends": "./tsconfig.json",
Expand Down
3 changes: 2 additions & 1 deletion __tests__/ts/v4/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"forceConsistentCasingInFileNames": true,
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"lib": ["dom", "es2020"],
"lib": ["dom", "es2022"],
"module": "esnext",
"moduleResolution": "node",
"newLine": "lf",
Expand All @@ -30,6 +30,7 @@
"outDir": "../../../dist",
"paths": {
"#fixtures/*": ["__fixtures__/*"],
"#pkg": ["package.json"],
"#src": ["src/index"],
"#src/*": ["src/*"],
"#tests/*": ["__tests__/*"]
Expand Down
52 changes: 52 additions & 0 deletions __tests__/utils/create-testing-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file Test Utilities - createTestingCommand
* @module tests/utils/createTestingCommand
*/

import AppModule from '#src/cli/app.module'
import { CLI_NAME } from '#src/cli/constants'
import { Module } from '@nestjs/common'
import type { TestingModule } from '@nestjs/testing'
import { CommandRunnerModule } from 'nest-commander'
import {
CommandTestFactory,
type CommandModuleMetadata
} from 'nest-commander-testing'

/**
* Creates a CLI command testing module.
*
* @see https://nest-commander.jaymcdoniel.dev/testing/factory
*
* @async
*
* @param {Omit<CommandModuleMetadata, 'imports'>} metadata - Module metadata
* @return {Promise<TestingModule>} CLI command testing module
*/
const createTestingCommand = async (
metadata: Omit<CommandModuleMetadata, 'imports'>
): Promise<TestingModule> => {
/**
* Test CLI application module.
*
* @class
*/
@Module(metadata)
class TestAppModule {}

return CommandTestFactory.createTestingCommand({
imports: [
CommandRunnerModule.forModule(undefined, {
cliName: CLI_NAME,
enablePositionalOptions: true,
errorHandler: AppModule.errorHandler,
pluginsAvailable: false,
serviceErrorHandler: AppModule.serviceErrorHandler,
usePlugins: false
}),
TestAppModule
]
}).compile()
}

export default createTestingCommand
20 changes: 16 additions & 4 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { defineBuildConfig, type Config } from '#src'
import pkg from './package.json' assert { type: 'json' }
import tsconfig from './tsconfig.build.json' assert { type: 'json' }

/**
* Build configuration options.
Expand All @@ -13,19 +14,30 @@ import pkg from './package.json' assert { type: 'json' }
*/
const config: Config = defineBuildConfig({
entries: [
{ ignore: ['cli.ts'] },
{ ignore: ['cli/**'] },
{
bundle: true,
external: ['node-fetch'],
external: [
'@nestjs/microservices',
'@nestjs/platform-express',
'@nestjs/websockets/socket-module',
'cache-manager',
'class-transformer',
'node-fetch'
],
keepNames: true,
minify: true,
name: 'cli',
platform: 'node',
source: 'src/cli.ts'
source: 'src/cli/index.ts'
}
],
sourcemap: true,
sourcesContent: false,
target: 'node' + pkg.engines.node.replace(/^\D+/, ''),
target: [
pkg.engines.node.replace(/^\D+/, 'node'),
tsconfig.compilerOptions.target
],
tsconfig: 'tsconfig.build.json'
})

Expand Down
Loading

0 comments on commit 9bc1543

Please sign in to comment.