@lwrjs/module-bundler 0.13.0-alpha.2 → 0.13.0-alpha.20

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,6 +28,7 @@ __export(exports, {
28
28
  });
29
29
  var import_amd_common = __toModule(require("./utils/amd-common.cjs"));
30
30
  var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
31
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
32
  var AmdBundlerProvider = class {
32
33
  constructor(options, {config, moduleRegistry}) {
33
34
  this.name = "amd-bundle-provider";
@@ -49,6 +50,7 @@ var AmdBundlerProvider = class {
49
50
  } else {
50
51
  bundle.code = await (0, import_esbuild_utils.parseJavascript)(bundle.code, {envMode});
51
52
  }
53
+ bundle.integrity = (0, import_shared_utils.createIntegrityHash)(bundle.code);
52
54
  return bundle;
53
55
  }
54
56
  }
@@ -27,6 +27,7 @@ __export(exports, {
27
27
  default: () => amd_runtime_bundle_provider_default
28
28
  });
29
29
  var import_amd_common = __toModule(require("./utils/amd-common.cjs"));
30
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
31
  var AmdBundlerProvider = class {
31
32
  constructor(options, {config, moduleRegistry}) {
32
33
  this.name = "amd-runtime-bundle-provider";
@@ -38,7 +39,11 @@ var AmdBundlerProvider = class {
38
39
  const {moduleRegistry, config} = this;
39
40
  const {minify, debug} = runtimeEnvironment;
40
41
  const minified = minify && !debug;
41
- return await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, minified, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
42
+ const bundle = await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, minified, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
43
+ if (bundle) {
44
+ bundle.integrity = (0, import_shared_utils.createIntegrityHash)(bundle.code);
45
+ }
46
+ return bundle;
42
47
  }
43
48
  }
44
49
  };
@@ -105,6 +105,7 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
105
105
  code,
106
106
  config: {external, exclude},
107
107
  map: bundleMap,
108
+ integrity: (0, import_shared_utils.createIntegrityHash)(code),
108
109
  bundleRecord: {
109
110
  imports: Array.from(requiredImports.values()),
110
111
  dynamicImports: Array.from(dynamicImports.values()),
@@ -93,7 +93,7 @@ async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = fal
93
93
  async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, unVersionedAliases, includeId, moduleRegistry, runtimeEnvironment, runtimeParams, visitedSpecifiers) {
94
94
  const modules = [rootModule, ...moduleGraphs.graphs[0].static];
95
95
  const {moduleRecord} = await moduleRegistry.getModule((0, import_shared_utils.explodeSpecifier)(rootModule), runtimeParams);
96
- if (moduleRecord.importMeta && process.env.MRT_HMR !== "true") {
96
+ if (moduleRecord.importMeta && !(0, import_shared_utils.isLocalDev)()) {
97
97
  for (const specifier of modules) {
98
98
  const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
99
99
  const imports = linkedDefinition?.linkedModuleRecord.imports || [];
@@ -116,7 +116,12 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
116
116
  }
117
117
  linkedDefinition.linkedModuleRecord.dynamicImports?.forEach((dynamicImport) => {
118
118
  if (dynamicImport.moduleNameType !== "unresolved") {
119
- dynamicImports.set(`${dynamicImport.specifier}_${dynamicImport.version}`, dynamicImport);
119
+ const moduleId = (0, import_shared_utils.explodeSpecifier)(dynamicImport.specifier);
120
+ const importReference = {
121
+ ...dynamicImport,
122
+ specifier: moduleId.specifier
123
+ };
124
+ dynamicImports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
120
125
  }
121
126
  });
122
127
  if (specifier.includes("#")) {
@@ -167,7 +172,8 @@ async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeE
167
172
  };
168
173
  return (0, import_shared_utils.getModuleGraphs)(graphSpecifier, graphOptions, moduleRegistry, moduleRegistry, runtimeEnvironment, runtimeParams);
169
174
  };
170
- const moduleGraphs = await getModuleGraphsWrapper(rootModuleId.specifier);
175
+ const versionedSpecifier = (0, import_shared_utils.getSpecifier)(rootModuleId);
176
+ const moduleGraphs = await getModuleGraphsWrapper(versionedSpecifier);
171
177
  const rootModule = moduleGraphs.graphs[0];
172
178
  const groupModuleGraphsMap = new Map();
173
179
  if (!cachedGroupieCode && groupies && groupies.length) {
@@ -29,10 +29,6 @@ __export(exports, {
29
29
  });
30
30
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
31
  var import_esbuild = __toModule(require("esbuild"));
32
- var import_features = __toModule(require("@lwc/features"));
33
- var lwcFeatureFlags = "default" in import_features.default ? import_features.default.default : import_features.default;
34
- var lwcFeatureFlagDefinitions = Object.fromEntries(Object.keys(lwcFeatureFlags).map((feature) => [`lwcRuntimeFlags.${feature}`, "false"]));
35
- delete lwcFeatureFlagDefinitions["lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE"];
36
32
  var esbuild = import_esbuild.default;
37
33
  if (!import_esbuild.default) {
38
34
  try {
@@ -46,8 +42,7 @@ async function minifyJavascript(source) {
46
42
  loader: "js",
47
43
  minify: true,
48
44
  define: {
49
- "process.env.NODE_ENV": JSON.stringify("production"),
50
- ...lwcFeatureFlagDefinitions
45
+ "process.env.NODE_ENV": JSON.stringify("production")
51
46
  }
52
47
  });
53
48
  return code;
@@ -64,8 +59,7 @@ async function parseJavascript(source, options) {
64
59
  loader: "js",
65
60
  minify: false,
66
61
  define: {
67
- "process.env.NODE_ENV": JSON.stringify(options.envMode),
68
- ...lwcFeatureFlagDefinitions
62
+ "process.env.NODE_ENV": JSON.stringify(options.envMode)
69
63
  }
70
64
  });
71
65
  return code;
@@ -1,5 +1,6 @@
1
1
  import { amdBundler } from './utils/amd-common.js';
2
2
  import { minifyJavascript, parseJavascript } from './utils/esbuild-utils.js';
3
+ import { createIntegrityHash } from '@lwrjs/shared-utils';
3
4
  export default class AmdBundlerProvider {
4
5
  constructor(options, { config, moduleRegistry }) {
5
6
  this.name = 'amd-bundle-provider';
@@ -20,6 +21,7 @@ export default class AmdBundlerProvider {
20
21
  else {
21
22
  bundle.code = await parseJavascript(bundle.code, { envMode });
22
23
  }
24
+ bundle.integrity = createIntegrityHash(bundle.code);
23
25
  return bundle;
24
26
  }
25
27
  }
@@ -1,4 +1,5 @@
1
1
  import { amdBundler } from './utils/amd-common.js';
2
+ import { createIntegrityHash } from '@lwrjs/shared-utils';
2
3
  export default class AmdBundlerProvider {
3
4
  constructor(options, { config, moduleRegistry }) {
4
5
  this.name = 'amd-runtime-bundle-provider';
@@ -10,8 +11,12 @@ export default class AmdBundlerProvider {
10
11
  const { moduleRegistry, config } = this;
11
12
  const { minify, debug } = runtimeEnvironment;
12
13
  const minified = minify && !debug;
13
- return await amdBundler(moduleId, moduleRegistry, minified, // will minify using rollup/terser if true - MRT runtime friendly
14
+ const bundle = await amdBundler(moduleId, moduleRegistry, minified, // will minify using rollup/terser if true - MRT runtime friendly
14
15
  runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
16
+ if (bundle) {
17
+ bundle.integrity = createIntegrityHash(bundle.code);
18
+ }
19
+ return bundle;
15
20
  }
16
21
  }
17
22
  }
@@ -3,7 +3,7 @@ import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
3
3
  import { bundleDefinitions } from './utils/rollup-esm-bundler-plugin.js';
4
4
  import { minifyJavascript } from './utils/esbuild-utils.js';
5
5
  import { overrideBundleConfig } from './utils/bundle-common.js';
6
- import { PROTOCOL_HTTP, PROTOCOL_HTTPS } from '@lwrjs/shared-utils';
6
+ import { PROTOCOL_HTTP, PROTOCOL_HTTPS, createIntegrityHash } from '@lwrjs/shared-utils';
7
7
  export default class EsmBundlerProvider {
8
8
  constructor(_options, { config, moduleRegistry }) {
9
9
  this.name = 'esm-bundle-provider';
@@ -79,6 +79,7 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
79
79
  code,
80
80
  config: { external, exclude },
81
81
  map: bundleMap,
82
+ integrity: createIntegrityHash(code),
82
83
  bundleRecord: {
83
84
  imports: Array.from(requiredImports.values()),
84
85
  dynamicImports: Array.from(dynamicImports.values()),
@@ -1,4 +1,4 @@
1
- import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, VERSION_NOT_PROVIDED, isExternalSpecifier, PROTOCOL_FILE, } from '@lwrjs/shared-utils';
1
+ import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, VERSION_NOT_PROVIDED, isExternalSpecifier, PROTOCOL_FILE, isLocalDev, } from '@lwrjs/shared-utils';
2
2
  import { rollup } from 'rollup';
3
3
  import replace from '@rollup/plugin-replace';
4
4
  import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
@@ -81,7 +81,7 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
81
81
  const { moduleRecord } = await moduleRegistry.getModule(explodeSpecifier(rootModule), runtimeParams);
82
82
  // add static imports from the LinkedModuleDefinitions added during module linking
83
83
  // they're not in the ModuleGraph imports b/c those are based on raw module source
84
- if (moduleRecord.importMeta && process.env.MRT_HMR !== 'true') {
84
+ if (moduleRecord.importMeta && !isLocalDev()) {
85
85
  // the only use case for this is "lwr/environment", so skip the logic when it's not needed
86
86
  for (const specifier of modules) {
87
87
  const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
@@ -109,7 +109,13 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
109
109
  // add any dynamic imports from each of the linked definitions in the module graph
110
110
  linkedDefinition.linkedModuleRecord.dynamicImports?.forEach((dynamicImport) => {
111
111
  if (dynamicImport.moduleNameType !== 'unresolved') {
112
- dynamicImports.set(`${dynamicImport.specifier}_${dynamicImport.version}`, dynamicImport);
112
+ // Linked specifiers add a version to them We do not want this in the bundle record specifier
113
+ const moduleId = explodeSpecifier(dynamicImport.specifier);
114
+ const importReference = {
115
+ ...dynamicImport,
116
+ specifier: moduleId.specifier,
117
+ };
118
+ dynamicImports.set(getSpecifier(importReference), importReference);
113
119
  }
114
120
  });
115
121
  // skip relative dependencies
@@ -175,7 +181,8 @@ export async function amdBundler(rootModuleId, moduleRegistry, minify = false, r
175
181
  };
176
182
  return getModuleGraphs(graphSpecifier, graphOptions, moduleRegistry, moduleRegistry, runtimeEnvironment, runtimeParams);
177
183
  };
178
- const moduleGraphs = await getModuleGraphsWrapper(rootModuleId.specifier);
184
+ const versionedSpecifier = getSpecifier(rootModuleId);
185
+ const moduleGraphs = await getModuleGraphsWrapper(versionedSpecifier);
179
186
  const rootModule = moduleGraphs.graphs[0];
180
187
  // we also need to get moduleGraphs for any group members this module belongs to
181
188
  const groupModuleGraphsMap = new Map();
@@ -1,12 +1,5 @@
1
1
  import { logger } from '@lwrjs/diagnostics';
2
2
  import esbuildEsm from 'esbuild';
3
- import features from '@lwc/features';
4
- // In certain envs, this default import is not compiled correctly
5
- const lwcFeatureFlags = 'default' in features ? features.default : features;
6
- // Set every LWC feature flag to false, so that the unused code can be tree-shaken
7
- const lwcFeatureFlagDefinitions = Object.fromEntries(Object.keys(lwcFeatureFlags).map((feature) => [`lwcRuntimeFlags.${feature}`, 'false']));
8
- // We cannot set mixed mode to false across the app; it varies by route.
9
- delete lwcFeatureFlagDefinitions['lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE'];
10
3
  // https://github.com/evanw/esbuild/issues/706
11
4
  // Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
12
5
  // https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
@@ -31,7 +24,6 @@ export async function minifyJavascript(source) {
31
24
  // Remove assertions by tree shaking the computed expression
32
25
  define: {
33
26
  'process.env.NODE_ENV': JSON.stringify('production'),
34
- ...lwcFeatureFlagDefinitions,
35
27
  },
36
28
  });
37
29
  return code;
@@ -55,7 +47,6 @@ export async function parseJavascript(source, options) {
55
47
  // Remove assertions by tree shaking the computed expression
56
48
  define: {
57
49
  'process.env.NODE_ENV': JSON.stringify(options.envMode),
58
- ...lwcFeatureFlagDefinitions,
59
50
  },
60
51
  });
61
52
  return code;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.0-alpha.2",
7
+ "version": "0.13.0-alpha.20",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -47,28 +47,25 @@
47
47
  "build/**/*.d.ts"
48
48
  ],
49
49
  "dependencies": {
50
- "@lwrjs/diagnostics": "0.13.0-alpha.2",
51
- "@lwrjs/instrumentation": "0.13.0-alpha.2",
52
- "@lwrjs/shared-utils": "0.13.0-alpha.2",
53
- "@rollup/plugin-replace": "^2.4.2",
50
+ "@lwrjs/diagnostics": "0.13.0-alpha.20",
51
+ "@lwrjs/instrumentation": "0.13.0-alpha.20",
52
+ "@lwrjs/shared-utils": "0.13.0-alpha.20",
53
+ "@rollup/plugin-replace": "^5.0.7",
54
54
  "rollup": "^2.78.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@lwrjs/types": "0.13.0-alpha.2",
57
+ "@lwrjs/types": "0.13.0-alpha.20",
58
58
  "jest": "^26.6.3",
59
59
  "ts-jest": "^26.5.6"
60
60
  },
61
61
  "optionalDependencies": {
62
62
  "esbuild": "^0.9.7"
63
63
  },
64
- "peerDependencies": {
65
- "@lwc/features": ">= 2.x"
66
- },
67
64
  "engines": {
68
65
  "node": ">=18.0.0"
69
66
  },
70
67
  "volta": {
71
68
  "extends": "../../../package.json"
72
69
  },
73
- "gitHead": "3ae1051ef1eb282f9c1fb54f6aab44ab5ba48480"
70
+ "gitHead": "2165594f2871f4f20a4083394e4372e67d1fa1b5"
74
71
  }