/
index.html
246 lines (181 loc) · 6.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<h1>Resolve</h1>
<h2>Utf8-bom import</h2>
<p class="utf8-bom">fail</p>
<h2>Deep import</h2>
<p>Should show [2,4]:<span class="pre deep-import">fail</span></p>
<h2>Entry resolving with exports field</h2>
<p class="exports-entry">fail</p>
<h2>Deep import with exports field</h2>
<p class="exports-deep">fail</p>
<h2>Deep import with query with exports field</h2>
<p class="exports-deep-query">fail</p>
<h2>Deep import with exports field + exposed directory</h2>
<p class="exports-deep-exposed-dir">fail</p>
<h2>Deep import with exports field + mapped directory</h2>
<p class="exports-deep-mapped-dir">fail</p>
<h2>Exports field env priority</h2>
<p class="exports-env">fail</p>
<h2>Resolve /index.*</h2>
<p class="index">fail</p>
<h2>Resolve dir and file of the same name (should prioritize file)</h2>
<p class="dir-vs-file">fail</p>
<h2>Resolve to non-duplicated file extension</h2>
<p class="exact-extension">fail</p>
<h2>Don't add extensions to directory names</h2>
<p class="dir-with-ext">fail</p>
<h2>
A ts module can import another ts module using its corresponding js file name
</h2>
<p class="ts-extension">fail</p>
<h2>
A ts module can import another tsx module using its corresponding jsx file
name
</h2>
<p class="jsx-extension">fail</p>
<h2>
A ts module can import another tsx module using its corresponding js file name
</h2>
<p class="tsx-extension">fail</p>
<h2>Resolve file name containing dot</h2>
<p class="dot">fail</p>
<h2>Browser Field</h2>
<p class="browser">fail</p>
<h2>
Resolve to the `browser` field instead of `module` when the importer is a
`require` call
</h2>
<p class="require-pkg-with-browser-and-module-field">fail</p>
<h2>
Resolve to the `main` field instead of `module` when the importer is a
`require` call
</h2>
<p class="require-pkg-with-esm-entries">fail</p>
<h2>CSS Entry</h2>
<p class="css"></p>
<h2>Monorepo linked dep</h2>
<p class="monorepo"></p>
<h2>Plugin resolved virtual file</h2>
<p class="virtual"></p>
<h2>Plugin resolved custom virtual file</h2>
<p class="custom-virtual"></p>
<h2>Inline package</h2>
<p class="inline-pkg"></p>
<h2>resolve.extensions</h2>
<p class="custom-ext"></p>
<h2>resolve.mainFields</h2>
<p class="custom-main-fields"></p>
<h2>resolve.conditions</h2>
<p class="custom-condition"></p>
<h2>resolve package that contains # in path</h2>
<p class="path-contains-sharp-symbol"></p>
<script type="module">
function text(selector, text) {
document.querySelector(selector).textContent = text
}
// import from a utf-8 bom file
import { msg as bomMsg } from './utf8-bom/main.js'
text('.utf8-bom', bomMsg)
// deep import
import slicedToArray from '@babel/runtime/helpers/esm/slicedToArray'
const iterable = (function* () {
yield 2
yield 4
yield 6
yield 8
})()
text('.deep-import', JSON.stringify(slicedToArray(iterable, 2)))
// exports field
import { msg } from 'resolve-exports-path'
text('.exports-entry', msg)
// deep import w/ exports
import { msg as deepMsg } from 'resolve-exports-path/deep.js'
text('.exports-deep', deepMsg)
// deep import w/ exports w/ query
import deepPath from 'resolve-exports-path/deep.json?url'
text('.exports-deep-query', deepPath)
// deep import w/ exposed dir
import { msg as exposedDirMsg } from 'resolve-exports-path/dir/dir'
text('.exports-deep-exposed-dir', exposedDirMsg)
// deep import w/ mapped dir
import { msg as mappedDirMsg } from 'resolve-exports-path/dir-mapped/dir'
text('.exports-deep-mapped-dir', mappedDirMsg)
import { msg as exportsEnvMsg } from 'resolve-exports-env'
text('.exports-env', exportsEnvMsg)
// implicit index resolving
import { foo } from './util'
text('.index', foo())
// implicit dir index vs. file
import { file } from './dir'
text('.dir-vs-file', file)
// // exact extension vs. duplicated (.js.js)
import { file as exactExtMsg } from './exact-extension/file.js'
text('.exact-extension', exactExtMsg)
// don't add extensions to dir name (./dir-with-ext.js/index.js)
import { file as dirWithExtMsg } from './dir-with-ext'
text('.dir-with-ext', dirWithExtMsg)
import { msg as tsExtensionMsg } from './ts-extension'
text('.ts-extension', tsExtensionMsg)
import { msgJsx as tsJsxExtensionMsg } from './ts-extension'
text('.jsx-extension', tsJsxExtensionMsg)
import { msgTsx as tsTsxExtensionMsg } from './ts-extension'
text('.tsx-extension', tsTsxExtensionMsg)
// filename with dot
import { bar } from './util/bar.util'
text('.dot', bar())
// browser field
import main from 'resolve-browser-field'
import a from 'resolve-browser-field/no-ext'
import b from 'resolve-browser-field/no-ext.js' // no substitution
import c from 'resolve-browser-field/ext'
import d from 'resolve-browser-field/ext.js'
import e from 'resolve-browser-field/ext-index/index.js'
import f from 'resolve-browser-field/ext-index'
import g from 'resolve-browser-field/no-ext-index/index.js' // no substitution
import h from 'resolve-browser-field/no-ext?query'
import { ra, rb, rc, rd, re, rf, rg } from 'resolve-browser-field/relative'
const success = [main, a, c, d, e, f, h, ra, rc, rd, re, rf]
const noSuccess = [b, g, rb, rg]
if (
[...success, ...noSuccess].filter((text) => text.includes('[success]'))
.length === success.length
) {
text('.browser', main)
}
import { msg as requireBrowserMsg } from 'require-pkg-with-browser-and-module-field'
text('.require-pkg-with-browser-and-module-field', requireBrowserMsg)
import { msg as requireMainMsg } from 'require-pkg-with-esm-entries'
text('.require-pkg-with-esm-entries', requireMainMsg)
import { msg as customExtMsg } from './custom-ext'
text('.custom-ext', customExtMsg)
import { msg as customMainMsg } from 'resolve-custom-main-field'
text('.custom-main-fields', customMainMsg)
import { msg as customConditionMsg } from 'resolve-custom-condition'
text('.custom-condition', customConditionMsg)
// should be ok to import a file marked with browser: false
import 'resolve-browser-field/not-browser'
import 'resolve-browser-field/multiple.dot.path'
// css entry
import css from 'normalize.css'
if (typeof css === 'string') {
text('.css', '[success] resolve package with css entry file')
}
// monorepo linked dep w/ upper directory import
import { msg as linkedMsg } from 'resolve-linked'
text('.monorepo', linkedMsg)
import { msg as virtualMsg } from '@virtual-file'
text('.virtual', virtualMsg)
import { msg as customVirtualMsg } from '@custom-virtual-file'
text('.custom-virtual', customVirtualMsg)
import { msg as inlineMsg } from './inline-package'
text('.inline-pkg', inlineMsg)
import es5Ext from 'es5-ext'
text('.path-contains-sharp-symbol', '[success]')
</script>
<style>
.pre {
display: block;
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
</style>