@lwrjs/npm-module-provider 0.6.0-alpha.7 → 0.6.0

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.
@@ -28,7 +28,6 @@ __export(exports, {
28
28
  resolveNpmModuleSpecifierBlock: () => resolveNpmModuleSpecifierBlock
29
29
  });
30
30
  var import_path = __toModule(require("path"));
31
- var import_fs = __toModule(require("fs"));
32
31
  var import_resolve = __toModule(require("resolve"));
33
32
  var import_esbuild = __toModule(require("esbuild"));
34
33
  var import_node_modules_polyfill = __toModule(require("@esbuild-plugins/node-modules-polyfill"));
@@ -39,10 +38,6 @@ if (!import_esbuild.default) {
39
38
  } catch {
40
39
  }
41
40
  }
42
- function getPkgVersion(specifier) {
43
- const pkgPath = import_resolve.default.sync((0, import_path.join)(specifier, "/package.json"));
44
- return JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf-8")).version;
45
- }
46
41
  var NodePolyfillsPlugin = import_node_modules_polyfill.default.default || import_node_modules_polyfill.default;
47
42
  var ExternalsPlugin = function({external}) {
48
43
  return {
@@ -58,6 +53,7 @@ var ExternalsPlugin = function({external}) {
58
53
  };
59
54
  async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
60
55
  try {
56
+ let pkgVersion;
61
57
  const res = import_resolve.default.sync(specifier, {
62
58
  packageFilter: function(pkg) {
63
59
  const {exports: exports2, browser} = pkg;
@@ -69,12 +65,15 @@ async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
69
65
  } else if (pkg.module) {
70
66
  pkg.main = pkg.module;
71
67
  }
68
+ pkgVersion = pkg.version;
72
69
  return pkg;
73
70
  }
74
71
  });
72
+ if (pkgVersion === void 0) {
73
+ throw new Error("Failed to find version in package.json");
74
+ }
75
75
  const outfile = (0, import_path.join)(dest, specifier, "_bundle.js");
76
- const version = getPkgVersion(specifier);
77
- const cacheKey = `${specifier}@${version}`;
76
+ const cacheKey = `${specifier}@${pkgVersion}`;
78
77
  await esbuild.build({
79
78
  entryPoints: [res],
80
79
  format: "esm",
@@ -92,7 +91,7 @@ async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
92
91
  id: cacheKey,
93
92
  entry: outfile,
94
93
  specifier,
95
- version
94
+ version: pkgVersion
96
95
  };
97
96
  } catch (err) {
98
97
  console.log("[ERROR]resolveNpmModules(esbuild): ", {specifier, dest});
@@ -1,5 +1,4 @@
1
1
  import { join } from 'path';
2
- import { readFileSync } from 'fs';
3
2
  import resolve from 'resolve';
4
3
  import esbuildEsm from 'esbuild';
5
4
  import NodeModulesPolyfills from '@esbuild-plugins/node-modules-polyfill';
@@ -14,10 +13,6 @@ if (!esbuildEsm) {
14
13
  /* this is to support mjs/cjs dual impl */
15
14
  }
16
15
  }
17
- function getPkgVersion(specifier) {
18
- const pkgPath = resolve.sync(join(specifier, '/package.json'));
19
- return JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
20
- }
21
16
  const NodePolyfillsPlugin = NodeModulesPolyfills.default || NodeModulesPolyfills;
22
17
  const ExternalsPlugin = function ({ external }) {
23
18
  return {
@@ -33,6 +28,7 @@ const ExternalsPlugin = function ({ external }) {
33
28
  };
34
29
  export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
35
30
  try {
31
+ let pkgVersion;
36
32
  const res = resolve.sync(specifier, {
37
33
  packageFilter: function (pkg) {
38
34
  const { exports, browser } = pkg;
@@ -46,12 +42,17 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
46
42
  else if (pkg.module) {
47
43
  pkg.main = pkg.module;
48
44
  }
45
+ // grab package.json version before we go
46
+ pkgVersion = pkg.version;
49
47
  return pkg;
50
48
  },
51
49
  });
50
+ // ensure package version is set
51
+ if (pkgVersion === undefined) {
52
+ throw new Error('Failed to find version in package.json');
53
+ }
52
54
  const outfile = join(dest, specifier, '_bundle.js');
53
- const version = getPkgVersion(specifier);
54
- const cacheKey = `${specifier}@${version}`;
55
+ const cacheKey = `${specifier}@${pkgVersion}`;
55
56
  await esbuild.build({
56
57
  entryPoints: [res],
57
58
  format: 'esm',
@@ -69,7 +70,7 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
69
70
  id: cacheKey,
70
71
  entry: outfile,
71
72
  specifier,
72
- version,
73
+ version: pkgVersion,
73
74
  };
74
75
  }
75
76
  catch (err) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.7",
7
+ "version": "0.6.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -31,16 +31,16 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@esbuild-plugins/node-modules-polyfill": "^0.0.2",
34
- "@lwrjs/shared-utils": "0.6.0-alpha.7",
34
+ "@lwrjs/shared-utils": "0.6.0",
35
35
  "esbuild": "^0.9.7",
36
36
  "esinstall": "^1.0.5",
37
37
  "resolve": "^1.19.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.6.0-alpha.7"
40
+ "@lwrjs/types": "0.6.0"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=14.15.4 <17"
44
44
  },
45
- "gitHead": "dc066450384dc1e27064b46ddd5f24543758a414"
45
+ "gitHead": "31769655f0155ad7e54cf37bccdf72d0baaf44ab"
46
46
  }