bare-module-traverse 2.5.7 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +34 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1176,34 +1176,12 @@ function compressImportsMapEntry(resolved) {
|
|
|
1176
1176
|
return compressArtifactImportsMapEntry(resolved)
|
|
1177
1177
|
}
|
|
1178
1178
|
|
|
1179
|
-
|
|
1180
|
-
let primary = null
|
|
1181
|
-
|
|
1182
|
-
for (const entry of Object.entries(resolved)) {
|
|
1183
|
-
entry[1] = compressImportsMapEntry(entry[1])
|
|
1184
|
-
|
|
1185
|
-
entries.push(entry)
|
|
1186
|
-
|
|
1187
|
-
if (entry[0] === 'default') primary = entry[1]
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
if (entries.length === 0) return resolved
|
|
1191
|
-
|
|
1192
|
-
const [, first] = entries[0]
|
|
1193
|
-
|
|
1194
|
-
if (entries.every(([, resolved]) => resolved === first)) return first
|
|
1195
|
-
|
|
1196
|
-
entries = entries.filter(
|
|
1197
|
-
([condition, resolved]) => condition === 'default' || resolved !== primary
|
|
1198
|
-
)
|
|
1199
|
-
|
|
1200
|
-
if (entries.length === 1) return entries[0][1]
|
|
1201
|
-
|
|
1202
|
-
return Object.fromEntries(entries)
|
|
1179
|
+
return compressConditions(resolved)
|
|
1203
1180
|
}
|
|
1204
1181
|
|
|
1205
1182
|
// Only the condition an addon or asset was resolved for tells it apart from a
|
|
1206
|
-
// module, so those conditions must survive compression.
|
|
1183
|
+
// module, so those conditions must survive compression. Below them, nothing
|
|
1184
|
+
// more needs telling apart.
|
|
1207
1185
|
const artifactConditions = ['addon', 'asset']
|
|
1208
1186
|
|
|
1209
1187
|
function compressArtifactImportsMapEntry(resolved) {
|
|
@@ -1212,7 +1190,7 @@ function compressArtifactImportsMapEntry(resolved) {
|
|
|
1212
1190
|
|
|
1213
1191
|
for (const [condition, entry] of Object.entries(resolved)) {
|
|
1214
1192
|
if (artifactConditions.includes(condition)) {
|
|
1215
|
-
artifacts[condition] =
|
|
1193
|
+
artifacts[condition] = compressConditions(entry)
|
|
1216
1194
|
} else {
|
|
1217
1195
|
rest[condition] = entry
|
|
1218
1196
|
}
|
|
@@ -1222,7 +1200,7 @@ function compressArtifactImportsMapEntry(resolved) {
|
|
|
1222
1200
|
|
|
1223
1201
|
if (conditions.length === 0) return artifacts
|
|
1224
1202
|
|
|
1225
|
-
let compressed =
|
|
1203
|
+
let compressed = compressConditions(rest)
|
|
1226
1204
|
|
|
1227
1205
|
if (typeof compressed === 'string') {
|
|
1228
1206
|
compressed = { [conditions.length === 1 ? conditions[0] : 'default']: compressed }
|
|
@@ -1238,6 +1216,35 @@ function compressArtifactImportsMapEntry(resolved) {
|
|
|
1238
1216
|
return entry
|
|
1239
1217
|
}
|
|
1240
1218
|
|
|
1219
|
+
function compressConditions(resolved) {
|
|
1220
|
+
if (typeof resolved === 'string') return resolved
|
|
1221
|
+
|
|
1222
|
+
let entries = []
|
|
1223
|
+
let primary = null
|
|
1224
|
+
|
|
1225
|
+
for (const entry of Object.entries(resolved)) {
|
|
1226
|
+
entry[1] = compressConditions(entry[1])
|
|
1227
|
+
|
|
1228
|
+
entries.push(entry)
|
|
1229
|
+
|
|
1230
|
+
if (entry[0] === 'default') primary = entry[1]
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
if (entries.length === 0) return resolved
|
|
1234
|
+
|
|
1235
|
+
const [, first] = entries[0]
|
|
1236
|
+
|
|
1237
|
+
if (entries.every(([, resolved]) => resolved === first)) return first
|
|
1238
|
+
|
|
1239
|
+
entries = entries.filter(
|
|
1240
|
+
([condition, resolved]) => condition === 'default' || resolved !== primary
|
|
1241
|
+
)
|
|
1242
|
+
|
|
1243
|
+
if (entries.length === 1) return entries[0][1]
|
|
1244
|
+
|
|
1245
|
+
return Object.fromEntries(entries)
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1241
1248
|
function mixinImports(target, imports, url) {
|
|
1242
1249
|
if (typeof imports === 'object' && imports !== null && 'imports' in imports) {
|
|
1243
1250
|
imports = imports.imports
|