3
3
``` js
4
4
{
5
5
" compilerOptions" : {
6
- // implicitly true
7
- // "allowSyntheticDefaultImports": true,
8
6
" esModuleInterop" : true ,
9
7
" moduleResolution" : " Node"
10
8
}
@@ -19,7 +17,7 @@ Depends on the test configuration, the way to consume a module are different.
19
17
20
18
In this section we describe each module and how they are consumed within this configuration.
21
19
22
- ` assert ` : ` module declaration ` with ` export = ` as in DefinitelyTyped
20
+ ## [ assert ] ( ../../README.md#assert )
23
21
24
22
``` ts
25
23
import assert from ' assert'
@@ -28,11 +26,7 @@ import * as assert from 'assert'
28
26
assert (true )
29
27
```
30
28
31
- ` assertron@7 ` : Written in TypeScript, compile to CJS.
32
- The type definition uses ` export default ` as performed by ` tsc ` .
33
- It also has a transient dependency on ` assertion-error ` which uses ` export = ` in the type definition.
34
-
35
- It also expose ` module ` field in ` package.json ` , but that should not affect the test.
29
+ ## [ assertron@7] ( ../../README.md#assertron7 )
36
30
37
31
``` ts
38
32
import assertron from ' assertron'
@@ -43,7 +37,7 @@ import * as assertron from 'assertron'
43
37
assertron .default .truthy (1 )
44
38
```
45
39
46
- ` param-case@1 ` : is a CJS with ` export = ` in the typing file. It does not use ` declare module ` .
40
+ ## [ param-case@1] ( ../../README.md#param-case1 )
47
41
48
42
``` ts
49
43
// export =
@@ -55,7 +49,7 @@ import * as paramCase from 'param-case'
55
49
paramCase .default (' hello world' )
56
50
```
57
51
58
- ` cjs ` : is a local package that expose ` main ` in CJS format. It does not contain ` module ` field.
52
+ ## [ cjs ] ( ../../README.md#cjs )
59
53
60
54
``` ts
61
55
import m from ' cjs'
@@ -66,8 +60,7 @@ import * as m from 'cjs'
66
60
m .default (1 )
67
61
```
68
62
69
- ` es-cjs ` : is a local package that expose ` main ` in CJS and ` module ` in ` ES* ` format.
70
- It should behaves identical to ` cjs ` . Adding just for reference.
63
+ ## [ es-cjs] ( ../../README.md#es-cjs )
71
64
72
65
``` ts
73
66
import m from ' es-cjs'
@@ -78,12 +71,7 @@ import * as m from 'es-cjs'
78
71
m .default (1 )
79
72
```
80
73
81
- ` esm ` : is a local package that expose ` ESM ` with ` exports ` field. It does not contain ` main ` field.
82
-
83
- It is not supported in this test configuration as ` moduleResolution ` set to ` Node16 ` or ` NodeNext ` is required.
84
-
85
- ` esm-cjs ` : is a local package that expose ` ESM ` with ` exports ` field and ` main ` in CJS format.
86
- It should behaves identical to ` cjs ` in this configuration. Adding just for reference.
74
+ ## [ esm-cjs] ( ../../README.md#esm-cjs )
87
75
88
76
``` ts
89
77
import m from ' esm-cjs'
@@ -97,7 +85,7 @@ m.default(1)
97
85
## Legends
98
86
99
87
- π’: both compile and runtime are working correctly
100
- - π‘: for compile, it means there is an error, but can be supressed (e.g. with ` skipLibCheck ` )\
88
+ - π‘: for compile, it means there is an error, but can be suppressed (e.g. with ` skipLibCheck ` )\
101
89
for runtime, it means the compile fails, but runtime is working
102
90
- π΄: both compile and runtime fails
103
91
- β: compile success, but runtime fails. Potentially a TypeScript bug.
@@ -113,12 +101,12 @@ Import Syntax:
113
101
114
102
| module | Package | Type | import: default as | import: default | import: * as |
115
103
| -------- | ---------- | --------- | ------------------ | ----------------- | ----------------- |
116
- | CommonJS | assert | π» Compile | π΄ TS1259-e | π΄ TS1259-e | π’ |
117
- | | | π Runtime | π΄ not-fn | π΄ not-fn | π’ |
118
- | | assertron | π» Compile | π‘ TS1259-t | π‘ TS1259-t | π‘ TS1259-t |
119
- | | | π Runtime | π‘ | π‘ | π‘ |
120
- | | param-case | π» Compile | π΄ TS1259-e | π΄ TS1259-e | π΄ TS2497-e TS2339 |
121
- | | | π Runtime | π΄ not-fn | π΄ not-fn | π‘ |
104
+ | CommonJS | assert | π» Compile | π’ | π’ | π’ |
105
+ | | | π Runtime | π’ | π’ | β not-fn |
106
+ | | assertron | π» Compile | π’ | π’ | π’ |
107
+ | | | π Runtime | π’ | π’ | π’ |
108
+ | | param-case | π» Compile | π’ | π’ | π΄ TS2497-e TS2339 |
109
+ | | | π Runtime | π’ | π’ | π‘ |
122
110
| | cjs | π» Compile | π’ | π’ | π’ |
123
111
| | | π Runtime | π’ | π’ | π’ |
124
112
| | es-cjs | π» Compile | π’ | π’ | π’ |
@@ -127,16 +115,16 @@ Import Syntax:
127
115
| | | π Runtime | β | β | β |
128
116
| | esm-cjs | π» Compile | π’ | π’ | π’ |
129
117
| | | π Runtime | π’ | π’ | π’ |
130
- | ES* | assert | π» Compile | π΄ TS1259-a | π΄ TS1259-a | π’ |
131
- | | | π Runtime | π‘ | π‘ | π΄ not-fn |
132
- | | assertron | π» Compile | π‘ TS1259-t | π‘ TS1259-t | π‘ TS1259-t |
133
- | | | π Runtime | π΄ not-fn | π΄ not-fn | π΄ not-fn |
134
- | | param-case | π» Compile | π΄ TS1259-a | π΄ TS1259-a | π΄ TS2497-a TS2339 |
135
- | | | π Runtime | π‘ | π‘ | π΄ not-fn |
118
+ | ES* | assert | π» Compile | π’ | π’ | π’ |
119
+ | | | π Runtime | π’ | π’ | β not-fn |
120
+ | | assertron | π» Compile | π’ | π’ | π’ |
121
+ | | | π Runtime | β not-fn | β not-fn | β not-fn |
122
+ | | param-case | π» Compile | π’ | π’ | π΄ TS2497-a TS2339 |
123
+ | | | π Runtime | π’ | π’ | π‘ |
136
124
| | cjs | π» Compile | π’ | π’ | π’ |
137
- | | | π Runtime | π’ | π’ | π’ |
125
+ | | | π Runtime | β not-fn | β not-fn | β not-fn |
138
126
| | es-cjs | π» Compile | π’ | π’ | π’ |
139
- | | | π Runtime | π’ | π’ | π’ |
127
+ | | | π Runtime | β not-fn | β not-fn | β not-fn |
140
128
| | esm | π» Compile | β | β | β |
141
129
| | | π Runtime | β | β | β |
142
130
| | esm-cjs | π» Compile | π’ | π’ | π’ |
@@ -170,6 +158,9 @@ Import Syntax:
170
158
171
159
## Conclusion
172
160
173
- - ` module: CommonJS ` is the only "barely usable" one.
174
- - Cannot support ` export = ` type definition
161
+ - ` module: CommonJS ` works on most cases.
162
+ This is expected as that is the majority case for many years.
163
+ - for ` * as assert ` case, while ` esModuleInterop ` tries to solve that problem,
164
+ and the consumer should use the other forms. The compiler passing it is a bug IMO.
165
+ - β ` module: ES* ` fails with CJS is suprising, and if the test is correct, it's disturbing.
175
166
- β ` module: Node* ` compiled to CJS incorrectly
0 commit comments