Skip to content

Commit a1187a7

Browse files
committed
Remove behaviour forcing types to be first in exports
1 parent e3f2370 commit a1187a7

4 files changed

Lines changed: 10 additions & 158 deletions

File tree

index.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,27 +390,21 @@ const sortScripts = onObject((scripts, packageJson) => {
390390
})
391391

392392
/*
393-
- Move `types` and versioned type condition to top
394393
- Move `default` condition to bottom
395394
*/
396395
const sortConditions = (conditions) => {
397-
const {
398-
typesConditions = [],
399-
defaultConditions = [],
400-
restConditions = [],
401-
} = objectGroupBy(conditions, (condition) => {
402-
if (condition === 'types' || condition.startsWith('types@')) {
403-
return 'typesConditions'
404-
}
405-
406-
if (condition === 'default') {
407-
return 'defaultConditions'
408-
}
396+
const { defaultConditions = [], restConditions = [] } = objectGroupBy(
397+
conditions,
398+
(condition) => {
399+
if (condition === 'default') {
400+
return 'defaultConditions'
401+
}
409402

410-
return 'restConditions'
411-
})
403+
return 'restConditions'
404+
},
405+
)
412406

413-
return [...typesConditions, ...restConditions, ...defaultConditions]
407+
return [...restConditions, ...defaultConditions]
414408
}
415409

416410
const sortExports = onObject((exports) => {

tests/exports.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,6 @@ import { macro } from './_helpers.js'
44
for (const deep of [false, true]) {
55
const titleSuffix = deep ? `(deep)` : ''
66

7-
{
8-
const exports = {
9-
unknown: './unknown.unknown',
10-
'./path-not-really-makes-no-sense': {},
11-
types: './types.d.ts',
12-
'types@<=1': './v1/types.d.ts',
13-
}
14-
15-
test(`'types' condition should be first${titleSuffix}`, macro.sortObject, {
16-
path: 'exports',
17-
expect: 'snapshot',
18-
value: deep ? { './deep': exports } : exports,
19-
})
20-
}
21-
22-
{
23-
const exports = {
24-
unknown: './unknown.unknown',
25-
'./path-not-really-makes-no-sense': {},
26-
'types@<=1': './v1/types.d.ts',
27-
types: './types.d.ts',
28-
}
29-
30-
test(
31-
`'types' condition should be first${titleSuffix} 2`,
32-
macro.sortObject,
33-
{
34-
path: 'exports',
35-
expect: 'snapshot',
36-
value: deep ? { './deep': exports } : exports,
37-
},
38-
)
39-
}
40-
417
{
428
const exports = {
439
unknown: './unknown.unknown',

tests/snapshots/exports.js.md

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,6 @@ The actual snapshot is saved in `exports.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7-
## 'types' condition should be first
8-
9-
> Should sort `exports` as object.
10-
11-
{
12-
input: `{␊
13-
"exports": {␊
14-
"unknown": "./unknown.unknown",␊
15-
"./path-not-really-makes-no-sense": {},␊
16-
"types": "./types.d.ts",␊
17-
"types@<=1": "./v1/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-
"types@<=1": "./v1/types.d.ts",␊
26-
"unknown": "./unknown.unknown"␊
27-
}␊
28-
}`,
29-
pretty: true,
30-
}
31-
32-
## 'types' condition should be first 2
33-
34-
> Should sort `exports` as object.
35-
36-
{
37-
input: `{␊
38-
"exports": {␊
39-
"unknown": "./unknown.unknown",␊
40-
"./path-not-really-makes-no-sense": {},␊
41-
"types@<=1": "./v1/types.d.ts",␊
42-
"types": "./types.d.ts"␊
43-
}␊
44-
}`,
45-
options: undefined,
46-
output: `{␊
47-
"exports": {␊
48-
"./path-not-really-makes-no-sense": {},␊
49-
"types@<=1": "./v1/types.d.ts",␊
50-
"types": "./types.d.ts",␊
51-
"unknown": "./unknown.unknown"␊
52-
}␊
53-
}`,
54-
pretty: true,
55-
}
56-
577
## 'default' condition should be last
588

599
> Should sort `exports` as object.
@@ -77,64 +27,6 @@ Generated by [AVA](https://avajs.dev).
7727
pretty: true,
7828
}
7929

80-
## 'types' condition should be first(deep)
81-
82-
> Should sort `exports` as object.
83-
84-
{
85-
input: `{␊
86-
"exports": {␊
87-
"./deep": {␊
88-
"unknown": "./unknown.unknown",␊
89-
"./path-not-really-makes-no-sense": {},␊
90-
"types": "./types.d.ts",␊
91-
"types@<=1": "./v1/types.d.ts"␊
92-
}␊
93-
}␊
94-
}`,
95-
options: undefined,
96-
output: `{␊
97-
"exports": {␊
98-
"./deep": {␊
99-
"./path-not-really-makes-no-sense": {},␊
100-
"types": "./types.d.ts",␊
101-
"types@<=1": "./v1/types.d.ts",␊
102-
"unknown": "./unknown.unknown"␊
103-
}␊
104-
}␊
105-
}`,
106-
pretty: true,
107-
}
108-
109-
## 'types' condition should be first(deep) 2
110-
111-
> Should sort `exports` as object.
112-
113-
{
114-
input: `{␊
115-
"exports": {␊
116-
"./deep": {␊
117-
"unknown": "./unknown.unknown",␊
118-
"./path-not-really-makes-no-sense": {},␊
119-
"types@<=1": "./v1/types.d.ts",␊
120-
"types": "./types.d.ts"␊
121-
}␊
122-
}␊
123-
}`,
124-
options: undefined,
125-
output: `{␊
126-
"exports": {␊
127-
"./deep": {␊
128-
"./path-not-really-makes-no-sense": {},␊
129-
"types@<=1": "./v1/types.d.ts",␊
130-
"types": "./types.d.ts",␊
131-
"unknown": "./unknown.unknown"␊
132-
}␊
133-
}␊
134-
}`,
135-
pretty: true,
136-
}
137-
13830
## 'default' condition should be last(deep)
13931

14032
> Should sort `exports` as object.

tests/snapshots/exports.js.snap

-156 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)