fix(core): Replace ts-node with tsx for module handling

This commit is contained in:
2024-10-27 19:45:57 +01:00
parent c2e406964d
commit bec80e6862
7 changed files with 293 additions and 163 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tsrun',
version: '1.3.1',
version: '1.3.2',
description: 'run typescript programs efficiently'
}

View File

@ -22,21 +22,7 @@ export const runCli = async (pathArg?: string) => {
// thus when pathArg is specifed -> we only splice 2
pathArg ? process.argv.splice(0, 2) : process.argv.splice(0, 3); // this ensures transparent arguments for the child process
// lets setup things for execution
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
});
const tsNodeLoaderPath = plugins.path.join(__dirname, 'loader.js');
// note: -> reduce on emtpy array does not work
// thus check needed before reducing the argv array
smartshellInstance.exec(
`node --loader ${tsNodeLoaderPath} ${absolutePathToTsFile} ${
process.argv.length > 0
? process.argv.reduce((prevArg, currentArg) => {
return prevArg + ' ' + currentArg;
})
: ''
}`,
);
const tsx = await import('tsx/esm/api');
const unregister = tsx.register();
await import(absolutePathToTsFile);
};

View File

@ -1,27 +0,0 @@
import * as paths from './paths.js';
import * as plugins from './plugins.js';
import type { CompilerOptions } from 'typescript';
const defaultTsNodeOptions: plugins.tsNode.CreateOptions = {
compilerOptions: {
lib: ['dom'],
target: <any>'es2022', // Script Target should be a string -> 2 is for ES2015
experimentalDecorators: true,
useDefineForClassFields: false,
esModuleInterop: true,
strictNullChecks: false,
moduleResolution: <any>'nodenext',
module: <any>'nodenext',
verbatimModuleSyntax: true,
paths: plugins.smartfile.fs.toObjectSync(plugins.path.join(paths.cwd, 'tsconfig.json'))
?.compilerOptions?.paths,
} as CompilerOptions,
esm: true,
skipIgnore: true,
transpileOnly: true,
};
console.log(`tsrun is using the following options: ${JSON.stringify(defaultTsNodeOptions, null, 2)}`);
export const { resolve, load, getFormat, transformSource } = plugins.tsNode.createEsmHooks(
plugins.tsNode.register(defaultTsNodeOptions),
) as any;

View File

@ -10,7 +10,6 @@ import * as smartshell from '@push.rocks/smartshell';
export { smartfile, smartshell };
// third party scope
import * as tsNode from 'ts-node';
import { tsImport } from 'tsx/esm/api';
export { tsNode };
export { tsImport };