-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed loading .ts config file (
npm i amaro
)
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
## Changelog | ||
|
||
* 2.8.2 | ||
- fixed loading .ts config file (`npm i amaro`) | ||
|
||
* 2.8.1 | ||
- fixed onData issue (#141) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
const EC = require('eight-colors'); | ||
|
||
const extensionsRegex = /\.ts$|\.mts$|\.cts$/; | ||
|
||
async function load(url, context, nextLoad) { | ||
|
||
if (extensionsRegex.test(url) && !url.includes('/node_modules/')) { | ||
|
||
const { transformSync } = await import('amaro').catch((e) => { | ||
// console.log(e.message || e); | ||
EC.logRed('The "amaro" module is required for loading ".ts" file, please run "npm i amaro"'); | ||
}); | ||
|
||
// Use format 'module' so it returns the source as-is, without stripping the types. | ||
// Format 'commonjs' would not return the source for historical reasons. | ||
const { source } = await nextLoad(url, { | ||
... context, | ||
format: 'module' | ||
}); | ||
if (source === null) { | ||
throw new Error('Source code cannot be null or undefined'); | ||
} | ||
const { code } = transformSync(source.toString(), { | ||
mode: 'strip-only' | ||
}); | ||
return { | ||
format: 'module', | ||
source: code | ||
}; | ||
} | ||
return nextLoad(url, context); | ||
} | ||
|
||
module.exports = { | ||
load | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters