From eef08a3bed0631d2117d7dd9d2820eb5ffdad635 Mon Sep 17 00:00:00 2001 From: tianyingchun Date: Wed, 29 May 2024 09:59:11 +0800 Subject: [PATCH] feat: add `verbose` message env --- .changeset/good-clocks-drive.md | 5 +++++ README.md | 4 +++- src/path-alias.ts | 31 ++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 .changeset/good-clocks-drive.md diff --git a/.changeset/good-clocks-drive.md b/.changeset/good-clocks-drive.md new file mode 100644 index 0000000..ea321d2 --- /dev/null +++ b/.changeset/good-clocks-drive.md @@ -0,0 +1,5 @@ +--- +"@hyperse/ts-node-paths": patch +--- + +add `verbose` message env diff --git a/README.md b/README.md index d990d4c..d4ecf93 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,11 @@ runTsScript( ); ``` +Enable `verbose` status messages by Environment: `HYPERSE_TS_NODE_PATHS_VERBOSE` + The fields listed in the example of above are all required in order to the correct working of the package. -### ...with **ESM** `type:module` projects +### with **ESM** `type:module` projects - scripts (node 20+) diff --git a/src/path-alias.ts b/src/path-alias.ts index 8207c5f..3ca3982 100644 --- a/src/path-alias.ts +++ b/src/path-alias.ts @@ -23,19 +23,26 @@ class PathAlias { (process as any)[HYPERSE_TS_NODE_PATHS] = true; // Get options - const tsconfig = new Tsconfig(path ?? process.env.TS_NODE_PATHS_PROJECT); + const tsconfig = new Tsconfig(path ?? process.env['TS_NODE_PATHS_PROJECT']); this.#opts = tsconfig.getOptions(); // Check if the path is on source this.#isTsNode = false; } + get verbose(): boolean { + const verbose = process.env['HYPERSE_TS_NODE_PATHS_VERBOSE']; + return verbose?.toLowerCase() === 'true'; + } + showInConsole(): void { - console.log('------------------------------------'); - console.log('@hyperse/ts-node-paths'); - console.log(`> type : 'ESM'};`); - console.log('Preparing to execute...'); - console.log('------------------------------------'); + if (this.verbose) { + console.log('------------------------------------'); + console.log('@hyperse/ts-node-paths'); + console.log(`> type : 'ESM'};`); + console.log('Preparing to execute...'); + console.log('------------------------------------'); + } } checkTsNode(url: string): boolean; @@ -63,11 +70,13 @@ class PathAlias { } if (this.#isTsNode && !found) { - console.log('------------------------------------'); - console.log('> Source file found!'); - console.log(' Using "ts-node/esm"...'); - console.log('------------------------------------'); - (process as any)[HYPERSE_TS_NODE] = true; + if (this.verbose) { + console.log('------------------------------------'); + console.log('> Source file found!'); + console.log(' Using "ts-node/esm"...'); + console.log('------------------------------------'); + (process as any)[HYPERSE_TS_NODE] = true; + } } return this.#isTsNode;