1
1
import { Command , flags } from '@oclif/command'
2
2
import { resolve , isAbsolute } from 'path'
3
- import { promises } from 'fs'
4
- import * as fs from 'fs'
3
+ import { promises , constants } from 'fs'
5
4
import * as tsNode from 'ts-node'
6
5
import { Config , Script } from './types'
7
6
@@ -23,7 +22,7 @@ class ScriptRunner extends Command {
23
22
async parseConfigPath ( paths : string [ ] ) {
24
23
for ( const path of paths ) {
25
24
try {
26
- await promises . access ( path , fs . constants . F_OK )
25
+ await promises . access ( path , constants . F_OK )
27
26
return path
28
27
} catch { }
29
28
}
@@ -34,7 +33,7 @@ class ScriptRunner extends Command {
34
33
let configPaths : string [ ] = [ ]
35
34
36
35
if ( ! filePath ) {
37
- configPaths = [ 'js' , 'mjs' , ' ts'] . map ( ext => resolve ( process . cwd ( ) , `scr.config.${ ext } ` ) )
36
+ configPaths = [ 'js' , 'ts' ] . map ( ext => resolve ( process . cwd ( ) , `scr.config.${ ext } ` ) )
38
37
} else {
39
38
if ( isAbsolute ( filePath ) ) {
40
39
configPaths . push ( filePath )
@@ -44,21 +43,13 @@ class ScriptRunner extends Command {
44
43
}
45
44
46
45
const configPath = await this . parseConfigPath ( configPaths )
47
- const [ , fileExt ] = configPath . match ( / .+ \. ( \w + ) $ / ) || [ ]
48
46
49
- if ( fileExt !== 'js' ) {
50
- tsNode . register ( { dir : configPath , skipProject : true , transpileOnly : true , compilerOptions : { allowJs : true } } )
51
- }
47
+ tsNode . register ( { dir : configPath , skipProject : true , transpileOnly : true , compilerOptions : { allowJs : true } } )
52
48
53
- return require ( configPath )
49
+ const configModule = require ( configPath )
50
+ return configModule . default ?? configModule
54
51
}
55
52
56
- // runTs(script: Script) {
57
- // const { module, args } = script
58
- // tsNode.register({ dir: require.resolve(module), skipProject: true, transpileOnly: true })
59
- // require(module).default(...args)
60
- // }
61
-
62
53
runTs ( script : Script ) {
63
54
const { module, args } = script
64
55
tsNode . register ( { dir : require . resolve ( module ) , skipProject : true , transpileOnly : true , compilerOptions : { allowJs : true } } )
@@ -74,8 +65,6 @@ class ScriptRunner extends Command {
74
65
runScript ( script : Script ) {
75
66
switch ( script . type ) {
76
67
case 'ts' :
77
- // this.runTs(script)
78
- // break
79
68
case 'esm' :
80
69
this . runTs ( script )
81
70
break
0 commit comments