Skip to content

Commit 96ba604

Browse files
committed
feat: sort exports field
1 parent 43ee7e7 commit 96ba604

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed

tests/exports.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import test from 'ava'
2+
import { macro } from './_helpers.js'
3+
4+
for (const deep of [false, true]) {
5+
const titleSuffix = deep ? `(deep)` : ''
6+
7+
{
8+
const exports = {
9+
unknown: './unknown.unknown',
10+
'./path-not-really-makes-no-sense': {},
11+
import: './import.mjs',
12+
types: './types.d.ts',
13+
}
14+
15+
test(`'types' condition should be first${titleSuffix}`, macro.sortObject, {
16+
expect: 'snapshot',
17+
value: deep ? { exports: { './deep': exports } } : { exports },
18+
})
19+
}
20+
21+
{
22+
const exports = {
23+
unknown: './unknown.unknown',
24+
'./path-not-really-makes-no-sense': {},
25+
default: './types.d.ts',
26+
import: './import.mjs',
27+
}
28+
29+
test(`'default' condition should be last${titleSuffix}`, macro.sortObject, {
30+
expect: 'snapshot',
31+
value: deep ? { exports: { './deep': exports } } : { exports },
32+
})
33+
}
34+
35+
{
36+
const exports = {
37+
unknown: './unknown.unknown',
38+
require: './require.cjs',
39+
'./path-not-really-makes-no-sense': {},
40+
'module-sync': './module-sync.mjs',
41+
}
42+
43+
test(
44+
`'module-sync' condition should before 'require'${titleSuffix}`,
45+
macro.sortObject,
46+
{
47+
expect: 'snapshot',
48+
value: deep ? { exports: { './deep': exports } } : { exports },
49+
},
50+
)
51+
}
52+
}

tests/snapshots/exports.js.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Snapshot report for `tests/exports.js`
2+
3+
The actual snapshot is saved in `exports.js.snap`.
4+
5+
Generated by [AVA](https://avajs.dev).
6+
7+
## 'types' condition should be first
8+
9+
> Should sort `undefined` as object.
10+
11+
{
12+
input: `{␊
13+
"exports": {␊
14+
"unknown": "./unknown.unknown",␊
15+
"./path-not-really-makes-no-sense": {},␊
16+
"import": "./import.mjs",␊
17+
"types": "./types.d.ts"␊
18+
}␊
19+
}`,
20+
options: undefined,
21+
output: `{␊
22+
"exports": {␊
23+
"./path-not-really-makes-no-sense": {},␊
24+
"types": "./types.d.ts",␊
25+
"unknown": "./unknown.unknown",␊
26+
"import": "./import.mjs"␊
27+
}␊
28+
}`,
29+
pretty: true,
30+
}
31+
32+
## 'default' condition should be last
33+
34+
> Should sort `undefined` as object.
35+
36+
{
37+
input: `{␊
38+
"exports": {␊
39+
"unknown": "./unknown.unknown",␊
40+
"./path-not-really-makes-no-sense": {},␊
41+
"default": "./types.d.ts",␊
42+
"import": "./import.mjs"␊
43+
}␊
44+
}`,
45+
options: undefined,
46+
output: `{␊
47+
"exports": {␊
48+
"./path-not-really-makes-no-sense": {},␊
49+
"unknown": "./unknown.unknown",␊
50+
"import": "./import.mjs",␊
51+
"default": "./types.d.ts"␊
52+
}␊
53+
}`,
54+
pretty: true,
55+
}
56+
57+
## 'module-sync' condition should before 'require'
58+
59+
> Should sort `undefined` as object.
60+
61+
{
62+
input: `{␊
63+
"exports": {␊
64+
"unknown": "./unknown.unknown",␊
65+
"require": "./require.cjs",␊
66+
"./path-not-really-makes-no-sense": {},␊
67+
"module-sync": "./module-sync.mjs"␊
68+
}␊
69+
}`,
70+
options: undefined,
71+
output: `{␊
72+
"exports": {␊
73+
"./path-not-really-makes-no-sense": {},␊
74+
"unknown": "./unknown.unknown",␊
75+
"require": "./require.cjs",␊
76+
"module-sync": "./module-sync.mjs"␊
77+
}␊
78+
}`,
79+
pretty: true,
80+
}
81+
82+
## 'types' condition should be first(deep)
83+
84+
> Should sort `undefined` as object.
85+
86+
{
87+
input: `{␊
88+
"exports": {␊
89+
"./deep": {␊
90+
"unknown": "./unknown.unknown",␊
91+
"./path-not-really-makes-no-sense": {},␊
92+
"import": "./import.mjs",␊
93+
"types": "./types.d.ts"␊
94+
}␊
95+
}␊
96+
}`,
97+
options: undefined,
98+
output: `{␊
99+
"exports": {␊
100+
"./deep": {␊
101+
"./path-not-really-makes-no-sense": {},␊
102+
"types": "./types.d.ts",␊
103+
"unknown": "./unknown.unknown",␊
104+
"import": "./import.mjs"␊
105+
}␊
106+
}␊
107+
}`,
108+
pretty: true,
109+
}
110+
111+
## 'default' condition should be last(deep)
112+
113+
> Should sort `undefined` as object.
114+
115+
{
116+
input: `{␊
117+
"exports": {␊
118+
"./deep": {␊
119+
"unknown": "./unknown.unknown",␊
120+
"./path-not-really-makes-no-sense": {},␊
121+
"default": "./types.d.ts",␊
122+
"import": "./import.mjs"␊
123+
}␊
124+
}␊
125+
}`,
126+
options: undefined,
127+
output: `{␊
128+
"exports": {␊
129+
"./deep": {␊
130+
"./path-not-really-makes-no-sense": {},␊
131+
"unknown": "./unknown.unknown",␊
132+
"import": "./import.mjs",␊
133+
"default": "./types.d.ts"␊
134+
}␊
135+
}␊
136+
}`,
137+
pretty: true,
138+
}
139+
140+
## 'module-sync' condition should before 'require'(deep)
141+
142+
> Should sort `undefined` as object.
143+
144+
{
145+
input: `{␊
146+
"exports": {␊
147+
"./deep": {␊
148+
"unknown": "./unknown.unknown",␊
149+
"require": "./require.cjs",␊
150+
"./path-not-really-makes-no-sense": {},␊
151+
"module-sync": "./module-sync.mjs"␊
152+
}␊
153+
}␊
154+
}`,
155+
options: undefined,
156+
output: `{␊
157+
"exports": {␊
158+
"./deep": {␊
159+
"./path-not-really-makes-no-sense": {},␊
160+
"unknown": "./unknown.unknown",␊
161+
"require": "./require.cjs",␊
162+
"module-sync": "./module-sync.mjs"␊
163+
}␊
164+
}␊
165+
}`,
166+
pretty: true,
167+
}

tests/snapshots/exports.js.snap

681 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)