fix(core): Replace ts-node with tsx for module handling
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsrun',
|
||||
version: '1.3.1',
|
||||
version: '1.3.2',
|
||||
description: 'run typescript programs efficiently'
|
||||
}
|
||||
|
20
ts/index.ts
20
ts/index.ts
@ -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);
|
||||
};
|
||||
|
27
ts/loader.ts
27
ts/loader.ts
@ -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;
|
@ -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 };
|
||||
|
Reference in New Issue
Block a user