(tokens) add the support for Typescript config file

Add the support to load cunningham.ts local config file based on ts-node.
Those files will be loaded as CommonJS to preserve to coherence regarding
the way the cunningham bin is ran by node.
This commit is contained in:
Nathan Vasse
2023-01-04 15:49:37 +01:00
committed by NathanVss
parent 56da7dde48
commit 2457a93ebf
3 changed files with 9 additions and 9 deletions

View File

@@ -26,7 +26,13 @@ const getLocalConfig = async () => {
return config.default;
};
/**
* Register ts-node to load typescript config files with import. ( In fact, with `require` after transpiling ).
*/
const registerTypescriptLoader = () => {
// Specifying to load all .ts files as CJS is really important, otherwise ts-node will try to load them as ESM in
// projects where cunningham is used as a dependency where package.json contains "type": "module".
// So, by doing this we tell ts-node "Load all .ts files as CJS, even if they are in a project with ESM".
register({
moduleTypes: {
"**/*.ts": "cjs",

View File

@@ -11,15 +11,6 @@ jest.mock("../Paths", () => ({
workPath: () => __dirname,
}));
jest.mock("../cunningham.dist.js", () => ({
theme: {
colors: {
primary: "#055FD2",
secondary: "#DA0000",
},
},
}));
const runBin = async (args: string) => {
const exec = util.promisify(child_process.exec);
const promise = exec(