@lwrjs/npm-module-provider 0.17.2-alpha.3 → 0.17.2-alpha.30

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.
@@ -52,6 +52,22 @@ var ExternalsPlugin = function({external}) {
52
52
  }
53
53
  };
54
54
  };
55
+ function resolveExportsIteratively(entry, preferred = ["import", "module", "default", "browser"]) {
56
+ let current = entry;
57
+ while (current && typeof current === "object") {
58
+ let found = false;
59
+ for (const condition of preferred) {
60
+ if (current[condition] !== void 0) {
61
+ current = current[condition];
62
+ found = true;
63
+ break;
64
+ }
65
+ }
66
+ if (!found)
67
+ break;
68
+ }
69
+ return typeof current === "string" ? current : void 0;
70
+ }
55
71
  async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
56
72
  let res;
57
73
  try {
@@ -61,10 +77,12 @@ async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
61
77
  packageFilter: function(pkg) {
62
78
  const {exports: exports2, browser} = pkg;
63
79
  if (exports2 && exports2["."]) {
64
- const root = exports2["."];
65
- pkg.main = root?.browser?.import || root?.browser?.default || (typeof root?.browser === "string" ? root.browser : void 0) || root?.import?.browser?.default || root?.import?.default || (typeof root?.import === "string" ? root.import : void 0) || root?.default;
80
+ const resolved = resolveExportsIteratively(exports2["."]);
81
+ if (resolved) {
82
+ pkg.main = resolved;
83
+ }
66
84
  } else if (browser && typeof browser === "string") {
67
- pkg.main = pkg.browser;
85
+ pkg.main = browser;
68
86
  } else if (pkg.module) {
69
87
  pkg.main = pkg.module;
70
88
  }
@@ -28,6 +28,24 @@ const ExternalsPlugin = function ({ external }) {
28
28
  },
29
29
  };
30
30
  };
31
+ // Helper function using an iterative approach to resolve export entries.
32
+ function resolveExportsIteratively(entry, preferred = ['import', 'module', 'default', 'browser']) {
33
+ let current = entry;
34
+ // Loop until we reach a string or cannot go further.
35
+ while (current && typeof current === 'object') {
36
+ let found = false;
37
+ for (const condition of preferred) {
38
+ if (current[condition] !== undefined) {
39
+ current = current[condition];
40
+ found = true;
41
+ break;
42
+ }
43
+ }
44
+ if (!found)
45
+ break;
46
+ }
47
+ return typeof current === 'string' ? current : undefined;
48
+ }
31
49
  export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
32
50
  let res;
33
51
  try {
@@ -36,24 +54,22 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
36
54
  res = resolve.sync(specifier, {
37
55
  packageFilter: function (pkg) {
38
56
  const { exports, browser } = pkg;
57
+ // 1. Handle the "exports" field (and nested conditions)
39
58
  if (exports && exports['.']) {
40
- const root = exports['.'];
41
- pkg.main =
42
- root?.browser?.import ||
43
- root?.browser?.default ||
44
- (typeof root?.browser === 'string' ? root.browser : undefined) ||
45
- root?.import?.browser?.default ||
46
- root?.import?.default ||
47
- (typeof root?.import === 'string' ? root.import : undefined) ||
48
- root?.default;
59
+ const resolved = resolveExportsIteratively(exports['.']);
60
+ if (resolved) {
61
+ pkg.main = resolved;
62
+ }
49
63
  }
64
+ // 2. Fall back to the "browser" field (if it's a string)
50
65
  else if (browser && typeof browser === 'string') {
51
- pkg.main = pkg.browser;
66
+ pkg.main = browser;
52
67
  }
68
+ // 3. Next check the "module" field.
53
69
  else if (pkg.module) {
54
70
  pkg.main = pkg.module;
55
71
  }
56
- // grab package.json version (if set) before we go
72
+ // Grab package.json version (if set) before we go.
57
73
  if (pkg.version) {
58
74
  pkgVersion = pkg.version;
59
75
  }
@@ -62,7 +78,7 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
62
78
  });
63
79
  }
64
80
  catch (error) {
65
- // Just return undefined from resolve module not found
81
+ // Just return undefined for module not found.
66
82
  if (error.code === 'MODULE_NOT_FOUND') {
67
83
  logger.debug({
68
84
  label: 'npm-module-provider',
@@ -76,7 +92,7 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
76
92
  if (!res) {
77
93
  return undefined;
78
94
  }
79
- // ensure package version is set
95
+ // Ensure package version is set.
80
96
  if (pkgVersion === undefined) {
81
97
  throw new Error('Failed to find version in package.json');
82
98
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.3",
7
+ "version": "0.17.2-alpha.30",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -36,22 +36,22 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
39
- "@lwrjs/diagnostics": "0.17.2-alpha.3",
40
- "@lwrjs/shared-utils": "0.17.2-alpha.3",
39
+ "@lwrjs/diagnostics": "0.17.2-alpha.30",
40
+ "@lwrjs/shared-utils": "0.17.2-alpha.30",
41
41
  "esbuild": "^0.9.7",
42
42
  "resolve": "^1.22.8"
43
43
  },
44
44
  "devDependencies": {
45
- "@lwrjs/types": "0.17.2-alpha.3",
46
- "jest": "^26.6.3",
45
+ "@lwrjs/types": "0.17.2-alpha.30",
46
+ "jest": "29.7.0",
47
47
  "memfs": "^4.13.0",
48
- "ts-jest": "^26.5.6"
48
+ "ts-jest": "^29.2.6"
49
49
  },
50
50
  "engines": {
51
- "node": ">=18.0.0"
51
+ "node": ">=20.0.0"
52
52
  },
53
53
  "volta": {
54
54
  "extends": "../../../package.json"
55
55
  },
56
- "gitHead": "43757693dfca356cff105d4896a7a3cbf11ac017"
56
+ "gitHead": "818bbb13d2d4b14d128c4c4f23229c9ce7458a23"
57
57
  }