File tree Expand file tree Collapse file tree 7 files changed +16
-2
lines changed Expand file tree Collapse file tree 7 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 4
4
import _ from '../index.js' ;
5
5
// note: not usable by `deno`;
6
6
// ...`deno` is unable to load (the CJS module) '../index.js' via import => `'../index.js' does not provide an export named 'default'`
7
+ import { adapter } from '../platform-adapters/node.js' ;
8
+
9
+ // re-define `meta.mainFilename` adapter for ESM scripts
10
+ // HACK: `process._eval` is undocumented; used here as evidence of `node -e ...` differentiating between immediate eval vs file-bound scripts
11
+ // eslint-disable-next-line functional/immutable-data
12
+ adapter . meta . mainFilename = typeof process . _eval === 'undefined' ? process . argv [ 1 ] : '' ;
7
13
8
14
const default_ = _ ;
9
15
export default default_ ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ type moduleInternals_ = typeof module_ & {
8
8
} ;
9
9
10
10
test ( 'api' , ( t ) => {
11
- const api = [ 'home' , 'temp' ] ;
11
+ const api = [ 'home' , 'temp' , 'main' ] ;
12
12
13
13
t . is ( typeof module_ , 'function' ) ;
14
14
t . deepEqual ( Object . keys ( module_ ) . sort ( ) , api . sort ( ) ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export type OSPaths = {
9
9
( ) : OSPaths ;
10
10
readonly home : ( ) => string | undefined ;
11
11
readonly temp : ( ) => string ;
12
+ readonly main : ( ) => string ;
12
13
} ;
13
14
14
15
const { env } = process ;
@@ -85,6 +86,8 @@ class _OSPaths {
85
86
OSPaths . home = extension . home ;
86
87
OSPaths . temp = extension . temp ;
87
88
89
+ OSPaths . main = ( ) => adapter . meta . mainFilename ;
90
+
88
91
return OSPaths ;
89
92
}
90
93
}
Original file line number Diff line number Diff line change 2
2
export namespace Platform {
3
3
export type Adapter = {
4
4
readonly env : { readonly get : ( _ : string ) => string | undefined } ;
5
+ readonly meta : { readonly mainFilename : string } ;
5
6
readonly os : { readonly homedir ?: ( ) => string ; readonly tmpdir ?: ( ) => string } ;
6
7
readonly path : {
7
8
readonly join : ( ..._ : readonly string [ ] ) => string ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export const adapter: Platform.Adapter = {
15
15
env : { get : Deno . env . get } ,
16
16
// Deno (as of v1.6) has no built-in implementation for homedir() or tmpdir()
17
17
os : { } , // * module is tolerant of missing homedir()/tmpdir() functions
18
+ meta : { mainFilename : Deno . mainModule } ,
18
19
path,
19
20
process : { platform : Deno . build . os } ,
20
21
} ;
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ export const adapter: Platform.Adapter = {
9
9
return process . env [ s ] ;
10
10
} ,
11
11
} ,
12
+ meta : {
13
+ mainFilename : process . mainModule ?. filename || '' ,
14
+ } ,
12
15
os,
13
16
path,
14
17
process,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const settledSupportForESMs =
26
26
// Integration tests
27
27
28
28
test ( 'api' , ( t ) => {
29
- const api = [ 'home' , 'temp' ] ;
29
+ const api = [ 'home' , 'temp' , 'main' ] ;
30
30
31
31
t . is ( typeof module_ , 'function' ) ;
32
32
t . deepEqual ( Object . keys ( module_ ) . sort ( ) , api . sort ( ) ) ;
You can’t perform that action at this time.
0 commit comments