@lwrjs/module-bundler 0.12.0-alpha.8 → 0.12.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.
@@ -31,8 +31,9 @@ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
31
31
  var import_rollup_esm_bundler_plugin = __toModule(require("./utils/rollup-esm-bundler-plugin.cjs"));
32
32
  var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
33
33
  var import_bundle_common = __toModule(require("./utils/bundle-common.cjs"));
34
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
35
  var EsmBundlerProvider = class {
35
- constructor(options, {config, moduleRegistry}) {
36
+ constructor(_options, {config, moduleRegistry}) {
36
37
  this.name = "esm-bundle-provider";
37
38
  this.config = config;
38
39
  this.moduleRegistry = moduleRegistry;
@@ -72,11 +73,15 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
72
73
  dynamicImports
73
74
  })
74
75
  ],
76
+ external: Object.keys(external),
75
77
  makeAbsoluteExternalsRelative: "ifRelativeSource"
76
78
  });
77
79
  return bundle.generate({
78
80
  paths: (id2) => {
79
- return external[id2] || id2;
81
+ if (external[id2] && (external[id2].startsWith(import_shared_utils.PROTOCOL_HTTP) || external[id2].startsWith(import_shared_utils.PROTOCOL_HTTPS))) {
82
+ return external[id2];
83
+ }
84
+ return id2;
80
85
  },
81
86
  sourcemap: true
82
87
  });
@@ -50,6 +50,9 @@ var LwrModuleBundler = class {
50
50
  addBundleTransformers(transformers) {
51
51
  this.transformers.push(...transformers);
52
52
  }
53
+ getConfig() {
54
+ return this.bundleConfig;
55
+ }
53
56
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
54
57
  const {format, minify, debug} = runtimeEnvironment;
55
58
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${(0, import_shared_utils.getCacheKeyFromJson)({
@@ -124,6 +127,7 @@ var LwrModuleBundler = class {
124
127
  }
125
128
  getPublicApi() {
126
129
  return {
130
+ getConfig: this.getConfig.bind(this),
127
131
  getModuleBundle: this.getModuleBundle.bind(this),
128
132
  resolveModuleUri: this.resolveModuleUri.bind(this)
129
133
  };
@@ -36,20 +36,25 @@ var AMD_DEFINE = "LWR.define";
36
36
  var groupieCodeCache = new Map();
37
37
  function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
38
38
  return (moduleRef) => {
39
- if (external[moduleRef.specifier] !== void 0) {
40
- return false;
39
+ const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
40
+ if ((0, import_shared_utils.isExternalSpecifier)(moduleRef.specifier, {external})) {
41
+ moduleRef.externalSrc = external[moduleRef.specifier];
42
+ moduleRef.external = true;
43
+ if (moduleIsNotRoot) {
44
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
45
+ return false;
46
+ }
41
47
  }
42
48
  const moduleRefIsGroupie = (0, import_shared_utils.isGroupie)(moduleRef.specifier, groups);
43
49
  const rootModuleIsGroupie = (0, import_shared_utils.isGroupie)(graphSpecifier, groups);
44
- const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
45
50
  if (moduleRefIsGroupie) {
46
51
  if (moduleIsNotRoot && !rootModuleIsGroupie) {
47
- requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
52
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
48
53
  }
49
54
  return false;
50
55
  } else if (exclude?.includes(moduleRef.specifier)) {
51
56
  if (moduleIsNotRoot) {
52
- requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
57
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
53
58
  }
54
59
  return false;
55
60
  }
@@ -88,7 +93,7 @@ async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = fal
88
93
  async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, unVersionedAliases, includeId, moduleRegistry, runtimeEnvironment, runtimeParams, visitedSpecifiers) {
89
94
  const modules = [rootModule, ...moduleGraphs.graphs[0].static];
90
95
  const {moduleRecord} = await moduleRegistry.getModule((0, import_shared_utils.explodeSpecifier)(rootModule), runtimeParams);
91
- if (moduleRecord.importMeta) {
96
+ if (moduleRecord.importMeta && process.env.MRT_HMR !== "true") {
92
97
  for (const specifier of modules) {
93
98
  const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
94
99
  const imports = linkedDefinition?.linkedModuleRecord.imports || [];
@@ -121,16 +126,24 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
121
126
  return filteredModules;
122
127
  }, []).map((linkedDefinition) => {
123
128
  const id = (0, import_shared_utils.getSpecifier)(linkedDefinition);
129
+ includeId(linkedDefinition);
130
+ const isExternal = linkedDefinition.external;
131
+ const isExternalFile = linkedDefinition.externalSrc && linkedDefinition.externalSrc.startsWith(import_shared_utils.PROTOCOL_FILE);
124
132
  if (visitedSpecifiers?.has(id)) {
125
133
  return false;
126
134
  } else {
127
135
  visitedSpecifiers?.set(id, true);
128
136
  }
129
137
  if (id !== rootModule) {
130
- includedModules.push(id);
138
+ if (!isExternal) {
139
+ includedModules.push(id);
140
+ }
131
141
  } else {
132
142
  bundleGroupsIncludedModules.push(id);
133
143
  }
144
+ if (isExternalFile) {
145
+ return linkedDefinition.linkedSource;
146
+ }
134
147
  return bundle(id, moduleGraphs, minify, unVersionedAliases);
135
148
  }))).filter((x) => typeof x === "string");
136
149
  return bundles;
@@ -175,8 +188,8 @@ async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeE
175
188
  for (const rawGroupieSpecifier of groupies) {
176
189
  if (rawGroupieSpecifier !== rootModuleId.specifier) {
177
190
  const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
178
- const groupieSpecifer = groupieModuleGraph.graphs[0].specifier;
179
- const groupieBundles = await getBundleCode(groupieSpecifer, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
191
+ const groupieSpecifier = groupieModuleGraph.graphs[0].specifier;
192
+ const groupieBundles = await getBundleCode(groupieSpecifier, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
180
193
  bundles.push(...groupieBundles);
181
194
  }
182
195
  }
@@ -3,7 +3,7 @@ export default class EsmBundlerProvider implements BundleProvider {
3
3
  name: string;
4
4
  config: ProviderAppConfig;
5
5
  moduleRegistry: PublicModuleRegistry;
6
- constructor(options: {}, { config, moduleRegistry }: ProviderContext);
6
+ constructor(_options: {}, { config, moduleRegistry }: ProviderContext);
7
7
  bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
8
8
  }
9
9
  //# sourceMappingURL=esm-bundle-provider.d.ts.map
@@ -3,8 +3,9 @@ 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
7
  export default class EsmBundlerProvider {
7
- constructor(options, { config, moduleRegistry }) {
8
+ constructor(_options, { config, moduleRegistry }) {
8
9
  this.name = 'esm-bundle-provider';
9
10
  this.config = config;
10
11
  this.moduleRegistry = moduleRegistry;
@@ -43,13 +44,19 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
43
44
  dynamicImports,
44
45
  }),
45
46
  ],
47
+ external: Object.keys(external),
46
48
  makeAbsoluteExternalsRelative: 'ifRelativeSource', // Fix for breaking changes in https://github.com/rollup/rollup/pull/4021
47
49
  });
48
50
  return bundle.generate({
49
51
  paths: (id) => {
50
52
  // The fallback on id is important due to a rollup semantic issue:
51
53
  // https://github.com/rollup/rollup/issues/3831
52
- return external[id] || id;
54
+ // If external is an http:// URL use that in the ESM Module
55
+ if (external[id] &&
56
+ (external[id].startsWith(PROTOCOL_HTTP) || external[id].startsWith(PROTOCOL_HTTPS))) {
57
+ return external[id];
58
+ }
59
+ return id;
53
60
  },
54
61
  sourcemap: true,
55
62
  });
@@ -14,6 +14,7 @@ export declare class LwrModuleBundler implements ModuleBundler {
14
14
  constructor(config: LwrModuleBundlerConfig, globalConfig: NormalizedLwrGlobalConfig);
15
15
  addBundleProviders(providers: BundleProvider[]): void;
16
16
  addBundleTransformers(transformers: UriTransformPlugin[]): void;
17
+ getConfig(): BundleConfig;
17
18
  getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
18
19
  /**
19
20
  * Resolve the URI to the bundle rooted at the `moduleId`
package/build/es/index.js CHANGED
@@ -28,6 +28,9 @@ export class LwrModuleBundler {
28
28
  addBundleTransformers(transformers) {
29
29
  this.transformers.push(...transformers);
30
30
  }
31
+ getConfig() {
32
+ return this.bundleConfig;
33
+ }
31
34
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
32
35
  const { format, minify, debug } = runtimeEnvironment;
33
36
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${getCacheKeyFromJson({
@@ -121,6 +124,7 @@ export class LwrModuleBundler {
121
124
  }
122
125
  getPublicApi() {
123
126
  return {
127
+ getConfig: this.getConfig.bind(this),
124
128
  getModuleBundle: this.getModuleBundle.bind(this),
125
129
  resolveModuleUri: this.resolveModuleUri.bind(this),
126
130
  };
@@ -1,4 +1,4 @@
1
- import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, } from '@lwrjs/shared-utils';
1
+ import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, VERSION_NOT_PROVIDED, isExternalSpecifier, PROTOCOL_FILE, } 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';
@@ -8,21 +8,28 @@ const AMD_DEFINE = 'LWR.define';
8
8
  const groupieCodeCache = new Map();
9
9
  function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
10
10
  return (moduleRef) => {
11
+ const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
11
12
  // Do not bundle externals, including the loader module, which is auto bundled
12
13
  // with the shim + loader combo
13
- if (external[moduleRef.specifier] !== undefined) {
14
- // Do not include externals in the required imports but also return false to indicate it should not be in the bundle
15
- return false;
14
+ if (isExternalSpecifier(moduleRef.specifier, { external })) {
15
+ // Include externals just mark them as such
16
+ moduleRef.externalSrc = external[moduleRef.specifier];
17
+ moduleRef.external = true;
18
+ if (moduleIsNotRoot) {
19
+ // Include externals in the required imports
20
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
21
+ // return false to indicate it should not be in the bundle
22
+ return false;
23
+ }
16
24
  }
17
25
  const moduleRefIsGroupie = isGroupie(moduleRef.specifier, groups);
18
26
  const rootModuleIsGroupie = isGroupie(graphSpecifier, groups);
19
- const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
20
27
  if (moduleRefIsGroupie) {
21
28
  // If this is part of bundle group return false to indicate it should not be in the bundle
22
29
  // but add it to the requiredImports so it shows up as a static dependency of the bundle.
23
30
  // However, skip this if the requested specifier is also part of the same group.
24
31
  if (moduleIsNotRoot && !rootModuleIsGroupie) {
25
- requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
32
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
26
33
  }
27
34
  return false;
28
35
  }
@@ -30,7 +37,7 @@ function includeIdFactory(graphSpecifier, external, exclude = [], requiredImport
30
37
  // If this is a bundle exclude return false to indicate it should not be in the bundle
31
38
  // but add it to the requiredImports so it shows up as a static dependency of the bundle.
32
39
  if (moduleIsNotRoot) {
33
- requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
40
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
34
41
  }
35
42
  return false;
36
43
  }
@@ -74,7 +81,7 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
74
81
  const { moduleRecord } = await moduleRegistry.getModule(explodeSpecifier(rootModule), runtimeParams);
75
82
  // add static imports from the LinkedModuleDefinitions added during module linking
76
83
  // they're not in the ModuleGraph imports b/c those are based on raw module source
77
- if (moduleRecord.importMeta) {
84
+ if (moduleRecord.importMeta && process.env.MRT_HMR !== 'true') {
78
85
  // the only use case for this is "lwr/environment", so skip the logic when it's not needed
79
86
  for (const specifier of modules) {
80
87
  const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
@@ -115,19 +122,32 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
115
122
  }, [])
116
123
  .map((linkedDefinition) => {
117
124
  const id = getSpecifier(linkedDefinition);
125
+ // Calling includeId will set external and external source as a side effect
126
+ includeId(linkedDefinition);
127
+ const isExternal = linkedDefinition.external;
128
+ const isExternalFile = linkedDefinition.externalSrc &&
129
+ linkedDefinition.externalSrc.startsWith(PROTOCOL_FILE);
118
130
  if (visitedSpecifiers?.has(id)) {
119
131
  return false;
120
132
  }
121
133
  else {
122
134
  visitedSpecifiers?.set(id, true);
123
135
  }
136
+ // If this is the root module we do not include it in the included modules
124
137
  if (id !== rootModule) {
125
- includedModules.push(id);
138
+ // If this is an external module do not include it as included
139
+ if (!isExternal) {
140
+ includedModules.push(id);
141
+ }
126
142
  }
127
143
  else {
128
144
  // we need to still keep track of roots for bundle groups
129
145
  bundleGroupsIncludedModules.push(id);
130
146
  }
147
+ // If this is a external from a static file no need to bundle.
148
+ if (isExternalFile) {
149
+ return linkedDefinition.linkedSource;
150
+ }
131
151
  // bundle all dependencies for the linked definition and convert to AMD
132
152
  return bundle(id, moduleGraphs, minify, unVersionedAliases);
133
153
  }))).filter((x) => typeof x === 'string');
@@ -180,9 +200,9 @@ export async function amdBundler(rootModuleId, moduleRegistry, minify = false, r
180
200
  for (const rawGroupieSpecifier of groupies) {
181
201
  if (rawGroupieSpecifier !== rootModuleId.specifier) {
182
202
  const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
183
- const groupieSpecifer = groupieModuleGraph.graphs[0].specifier;
203
+ const groupieSpecifier = groupieModuleGraph.graphs[0].specifier;
184
204
  // eslint-disable-next-line no-await-in-loop
185
- const groupieBundles = await getBundleCode(groupieSpecifer, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
205
+ const groupieBundles = await getBundleCode(groupieSpecifier, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
186
206
  bundles.push(...groupieBundles);
187
207
  }
188
208
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.8",
7
+ "version": "0.12.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -47,14 +47,14 @@
47
47
  "build/**/*.d.ts"
48
48
  ],
49
49
  "dependencies": {
50
- "@lwrjs/diagnostics": "0.12.0-alpha.8",
51
- "@lwrjs/instrumentation": "0.12.0-alpha.8",
52
- "@lwrjs/shared-utils": "0.12.0-alpha.8",
50
+ "@lwrjs/diagnostics": "0.12.0",
51
+ "@lwrjs/instrumentation": "0.12.0",
52
+ "@lwrjs/shared-utils": "0.12.0",
53
53
  "@rollup/plugin-replace": "^2.4.2",
54
54
  "rollup": "^2.78.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@lwrjs/types": "0.12.0-alpha.8",
57
+ "@lwrjs/types": "0.12.0",
58
58
  "jest": "^26.6.3",
59
59
  "ts-jest": "^26.5.6"
60
60
  },
@@ -70,5 +70,5 @@
70
70
  "volta": {
71
71
  "extends": "../../../package.json"
72
72
  },
73
- "gitHead": "fa2d2189d7309adfb47f7b125616d26cb721ed6f"
73
+ "gitHead": "90f93604b26003e1e1eb85bb0d1f34f4fc9e9ff9"
74
74
  }