Skip to content

Commit

Permalink
feat: add verbose message env
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed May 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b7c7016 commit eef08a3
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-clocks-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperse/ts-node-paths": patch
---

add `verbose` message env
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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+)

31 changes: 20 additions & 11 deletions src/path-alias.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit eef08a3

Please sign in to comment.