From 34ef996197443dcd2b51987731537314d9831a57 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 7 Apr 2023 22:16:14 -0400 Subject: [PATCH] fix(cli): terminate `watch` mode via esbuild - https://esbuild.github.io/api/#watch Signed-off-by: Lexus Drumgold --- package.json | 1 + src/cli/index.ts | 14 ++++++++-- .../__snapshots__/plugin.integration.snap | 27 ++++++++++++++----- yarn.lock | 8 ++++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e6e2b621..e4eb88f7 100644 --- a/package.json +++ b/package.json @@ -169,6 +169,7 @@ "jsonc-eslint-parser": "2.2.0", "lint-staged": "13.2.0", "memfs": "3.5.0", + "mri": "1.2.0", "nest-commander": "3.6.1", "nest-commander-testing": "3.1.0", "node-notifier": "10.0.1", diff --git a/src/cli/index.ts b/src/cli/index.ts index 44d8a7a1..431ee73a 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -5,6 +5,7 @@ * @module mkbuild/cli */ +import mri from 'mri' import { CommandFactory } from 'nest-commander' import AppModule from './app.module' import { CLI_NAME } from './constants' @@ -26,6 +27,15 @@ async function main(): Promise { })) } -// run application and exit +// run application void (await main()) -process.exit() + +// check if watch mode is enabled +const { watch } = mri<{ watch: boolean }>(process.argv.slice(2), { + alias: { watch: 'w' }, + boolean: ['watch'], + default: { write: false } +}) + +// exit if watch mode is not enabled +!watch && process.exit() diff --git a/src/plugins/fully-specified/__snapshots__/plugin.integration.snap b/src/plugins/fully-specified/__snapshots__/plugin.integration.snap index f088216a..3a9d887c 100644 --- a/src/plugins/fully-specified/__snapshots__/plugin.integration.snap +++ b/src/plugins/fully-specified/__snapshots__/plugin.integration.snap @@ -2,10 +2,25 @@ exports[`integration:plugins/fully-specified > esbuild > should fill specifiers in output files 1`] = ` [ + { + "assertion": "", + "code": "import mri from \\"mri\\"", + "end": 41, + "imports": [ + "mri", + ], + "kind": "import", + "specifier": "mri", + "specifier_kind": "bare", + "specifier_syntax": "static", + "start": 20, + "syntax": "default", + "type": false, + }, { "assertion": "", "code": "import { CommandFactory } from \\"nest-commander\\"", - "end": 67, + "end": 90, "imports": [ "CommandFactory", ], @@ -13,14 +28,14 @@ exports[`integration:plugins/fully-specified > esbuild > should fill specifiers "specifier": "nest-commander", "specifier_kind": "bare", "specifier_syntax": "static", - "start": 20, + "start": 43, "syntax": "named", "type": false, }, { "assertion": "", "code": "import AppModule from \\"./app.module.mjs\\"", - "end": 109, + "end": 132, "imports": [ "AppModule", ], @@ -28,14 +43,14 @@ exports[`integration:plugins/fully-specified > esbuild > should fill specifiers "specifier": "./app.module.mjs", "specifier_kind": "relative", "specifier_syntax": "static", - "start": 69, + "start": 92, "syntax": "default", "type": false, }, { "assertion": "", "code": "import { CLI_NAME } from \\"./constants.mjs\\"", - "end": 153, + "end": 176, "imports": [ "CLI_NAME", ], @@ -43,7 +58,7 @@ exports[`integration:plugins/fully-specified > esbuild > should fill specifiers "specifier": "./constants.mjs", "specifier_kind": "relative", "specifier_syntax": "static", - "start": 111, + "start": 134, "syntax": "named", "type": false, }, diff --git a/yarn.lock b/yarn.lock index 7baa344e..d3cf3b8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1192,6 +1192,7 @@ __metadata: lint-staged: "npm:13.2.0" memfs: "npm:3.5.0" merge-anything: "npm:5.1.4" + mri: "npm:1.2.0" nest-commander: "npm:3.6.1" nest-commander-testing: "npm:3.1.0" node-notifier: "npm:10.0.1" @@ -6753,6 +6754,13 @@ __metadata: languageName: node linkType: hard +"mri@npm:1.2.0": + version: 1.2.0 + resolution: "mri@npm:1.2.0" + checksum: f459cd82edbe77b6296cc59a5005c351cd52f6a6d733539ae91f6dbc61a23c6e558bf9dea2703212b2caf1b0803852f357325612ba848795686577432740bd49 + languageName: node + linkType: hard + "mrmime@npm:^1.0.0": version: 1.0.1 resolution: "mrmime@npm:1.0.1"