File tree 4 files changed +51
-1
lines changed
4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 4
4
npm-debug.log
5
5
.idea
6
6
* .iml
7
+ dist
Original file line number Diff line number Diff line change 3
3
- 8
4
4
- 10
5
5
- 12
6
+ - 14
6
7
cache :
7
8
directories :
8
9
- wrk/bin
@@ -13,6 +14,7 @@ before_script:
13
14
- export PATH=$PATH:$PWD/wrk/bin/
14
15
script :
15
16
- npm run lint
17
+ - npm run prepack
16
18
- npm run test-cov
17
19
- npm run bench
18
20
after_script :
Original file line number Diff line number Diff line change 3
3
"version" : " 2.12.1" ,
4
4
"description" : " Koa web app framework" ,
5
5
"main" : " lib/application.js" ,
6
+ "exports" : {
7
+ "." : {
8
+ "require" : " ./lib/application.js" ,
9
+ "import" : " ./dist/koa.mjs"
10
+ },
11
+ "./" : " ./"
12
+ },
6
13
"scripts" : {
7
14
"test" : " egg-bin test test" ,
8
15
"test-cov" : " egg-bin cov test" ,
9
16
"lint" : " eslint benchmarks lib test" ,
10
17
"bench" : " make -C benchmarks" ,
11
- "authors" : " git log --format='%aN <%aE>' | sort -u > AUTHORS"
18
+ "authors" : " git log --format='%aN <%aE>' | sort -u > AUTHORS" ,
19
+ "build" : " gen-esm-wrapper . ./dist/koa.mjs" ,
20
+ "prepack" : " npm run build"
12
21
},
13
22
"repository" : " koajs/koa" ,
14
23
"keywords" : [
55
64
"eslint-plugin-node" : " ^10.0.0" ,
56
65
"eslint-plugin-promise" : " ^4.2.1" ,
57
66
"eslint-plugin-standard" : " ^4.0.1" ,
67
+ "gen-esm-wrapper" : " ^1.0.6" ,
58
68
"mm" : " ^2.5.0" ,
59
69
"supertest" : " ^3.1.0"
60
70
},
61
71
"engines" : {
62
72
"node" : " ^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4"
63
73
},
64
74
"files" : [
75
+ " dist" ,
65
76
" lib"
66
77
]
67
78
}
Original file line number Diff line number Diff line change
1
+ const assert = require ( 'assert' ) ;
2
+
3
+ let importESM = ( ) => { } ;
4
+
5
+ describe ( 'Load with esm' , ( ) => {
6
+ before ( function ( ) {
7
+ // ESM support is flagged on v12.x.
8
+ const majorVersion = + process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ;
9
+ if ( majorVersion < 12 ) {
10
+ this . skip ( ) ;
11
+ } else {
12
+ // eslint-disable-next-line no-eval
13
+ importESM = eval ( '(specifier) => import(specifier)' ) ;
14
+ }
15
+ } ) ;
16
+
17
+ it ( 'should default export koa' , async ( ) => {
18
+ const exported = await importESM ( 'koa' ) ;
19
+ const required = require ( '../' ) ;
20
+ assert . strictEqual ( exported . default , required ) ;
21
+ } ) ;
22
+
23
+ it ( 'should match exports own property names' , async ( ) => {
24
+ const exported = new Set ( Object . getOwnPropertyNames ( await importESM ( 'koa' ) ) ) ;
25
+ const required = new Set ( Object . getOwnPropertyNames ( require ( '../' ) ) ) ;
26
+
27
+ // Remove constructor properties + default export.
28
+ for ( const k of [ 'prototype' , 'length' , 'name' ] ) {
29
+ required . delete ( k ) ;
30
+ }
31
+ exported . delete ( 'default' ) ;
32
+
33
+ assert . strictEqual ( exported . size , required . size ) ;
34
+ assert . strictEqual ( [ ...exported ] . every ( property => required . has ( property ) ) , true ) ;
35
+ } ) ;
36
+ } ) ;
You can’t perform that action at this time.
0 commit comments