bare-module-traverse 2.5.7 → 2.5.9

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.
Files changed (2) hide show
  1. package/index.js +35 -30
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -897,9 +897,7 @@ function moduleType(url, attributes, info, opts = {}) {
897
897
 
898
898
  const match = url.pathname.match(/\.[a-z]+$/)
899
899
 
900
- if (match === null) return defaultType
901
-
902
- let [extension] = match
900
+ let extension = match === null ? '.js' : match[0]
903
901
 
904
902
  if (aliases !== null && extension in aliases) extension = aliases[extension]
905
903
 
@@ -1176,34 +1174,12 @@ function compressImportsMapEntry(resolved) {
1176
1174
  return compressArtifactImportsMapEntry(resolved)
1177
1175
  }
1178
1176
 
1179
- let entries = []
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)
1177
+ return compressConditions(resolved)
1203
1178
  }
1204
1179
 
1205
1180
  // Only the condition an addon or asset was resolved for tells it apart from a
1206
- // module, so those conditions must survive compression.
1181
+ // module, so those conditions must survive compression. Below them, nothing
1182
+ // more needs telling apart.
1207
1183
  const artifactConditions = ['addon', 'asset']
1208
1184
 
1209
1185
  function compressArtifactImportsMapEntry(resolved) {
@@ -1212,7 +1188,7 @@ function compressArtifactImportsMapEntry(resolved) {
1212
1188
 
1213
1189
  for (const [condition, entry] of Object.entries(resolved)) {
1214
1190
  if (artifactConditions.includes(condition)) {
1215
- artifacts[condition] = compressImportsMapEntry(entry)
1191
+ artifacts[condition] = compressConditions(entry)
1216
1192
  } else {
1217
1193
  rest[condition] = entry
1218
1194
  }
@@ -1222,7 +1198,7 @@ function compressArtifactImportsMapEntry(resolved) {
1222
1198
 
1223
1199
  if (conditions.length === 0) return artifacts
1224
1200
 
1225
- let compressed = compressImportsMapEntry(rest)
1201
+ let compressed = compressConditions(rest)
1226
1202
 
1227
1203
  if (typeof compressed === 'string') {
1228
1204
  compressed = { [conditions.length === 1 ? conditions[0] : 'default']: compressed }
@@ -1238,6 +1214,35 @@ function compressArtifactImportsMapEntry(resolved) {
1238
1214
  return entry
1239
1215
  }
1240
1216
 
1217
+ function compressConditions(resolved) {
1218
+ if (typeof resolved === 'string') return resolved
1219
+
1220
+ let entries = []
1221
+ let primary = null
1222
+
1223
+ for (const entry of Object.entries(resolved)) {
1224
+ entry[1] = compressConditions(entry[1])
1225
+
1226
+ entries.push(entry)
1227
+
1228
+ if (entry[0] === 'default') primary = entry[1]
1229
+ }
1230
+
1231
+ if (entries.length === 0) return resolved
1232
+
1233
+ const [, first] = entries[0]
1234
+
1235
+ if (entries.every(([, resolved]) => resolved === first)) return first
1236
+
1237
+ entries = entries.filter(
1238
+ ([condition, resolved]) => condition === 'default' || resolved !== primary
1239
+ )
1240
+
1241
+ if (entries.length === 1) return entries[0][1]
1242
+
1243
+ return Object.fromEntries(entries)
1244
+ }
1245
+
1241
1246
  function mixinImports(target, imports, url) {
1242
1247
  if (typeof imports === 'object' && imports !== null && 'imports' in imports) {
1243
1248
  imports = imports.imports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "2.5.7",
3
+ "version": "2.5.9",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {