@lwrjs/shared-utils 0.7.0-alpha.0 → 0.7.0-alpha.11

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.
package/build/cjs/env.cjs CHANGED
@@ -8,10 +8,10 @@ var __export = (target, all) => {
8
8
  // packages/@lwrjs/shared-utils/src/env.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
- getExperimentalFeatures: () => getExperimentalFeatures
11
+ getFeatureFlags: () => getFeatureFlags
12
12
  });
13
- function getExperimentalFeatures() {
13
+ function getFeatureFlags() {
14
14
  return {
15
- ENABLE_FINGERPRINTS: process.env.ENABLE_FINGERPRINTS !== void 0 && process.env.ENABLE_FINGERPRINTS === "true" ? true : false
15
+ LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER === "true" ? true : false
16
16
  };
17
17
  }
@@ -28,6 +28,7 @@ __export(exports, {
28
28
  getModuleGraphs: () => getModuleGraphs
29
29
  });
30
30
  var import_identity = __toModule(require("./identity.cjs"));
31
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
32
  var import_import_metadata = __toModule(require("./import-metadata.cjs"));
32
33
  var GraphDepth;
33
34
  (function(GraphDepth2) {
@@ -110,7 +111,9 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
110
111
  };
111
112
  const moduleDef = isBundler(defRegistry) ? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams) : await defRegistry.getModule(versionedModuleId, runtimeParams);
112
113
  if (!moduleDef) {
113
- throw new Error("Missing module Definition");
114
+ throw (0, import_diagnostics.createSingleDiagnosticError)({
115
+ description: import_diagnostics.descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier)
116
+ }, import_diagnostics.LwrUnresolvableError);
114
117
  }
115
118
  const flattened = [];
116
119
  await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
@@ -26,6 +26,7 @@ __markAsModule(exports);
26
26
  __export(exports, {
27
27
  extractMetadataFromHtml: () => extractMetadataFromHtml
28
28
  });
29
+ var import_identity = __toModule(require("./identity.cjs"));
29
30
  var import_parse5_sax_parser = __toModule(require("parse5-sax-parser"));
30
31
  var import_stream = __toModule(require("stream"));
31
32
  function parseAssetLocation(htmlSource, tagName, attrLocation) {
@@ -52,11 +53,19 @@ async function extractMetadataFromHtml(htmlSource) {
52
53
  const ceRefStack = [];
53
54
  parser.on("startTag", ({
54
55
  tagName,
56
+ attrs,
55
57
  sourceCodeLocation
56
58
  }) => {
57
59
  if (tagName.includes("-") && !openElements.has(tagName)) {
58
60
  const {startOffset, endOffset} = sourceCodeLocation;
59
- const ceRef = {tagName, location: {startOffset, endOffset}};
61
+ const ceRef = {
62
+ tagName,
63
+ location: {startOffset, endOffset},
64
+ props: attrs.length ? attrs.reduce((obj, {name, value}) => {
65
+ obj[(0, import_identity.getPropFromAttrName)(name)] = value === "" ? "true" : value;
66
+ return obj;
67
+ }, {}) : void 0
68
+ };
60
69
  openElements.add(tagName);
61
70
  if (ceRefStack.length) {
62
71
  const last = ceRefStack[ceRefStack.length - 1];
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  ASSETS_CACHE_DIR: () => ASSETS_CACHE_DIR,
28
+ BUNDLE_SIGIL: () => BUNDLE_SIGIL,
28
29
  DEFAULT_LOCKER_TRUSTED_CMP: () => DEFAULT_LOCKER_TRUSTED_CMP,
29
30
  DEFAULT_LWR_BOOTSTRAP_CONFIG: () => DEFAULT_LWR_BOOTSTRAP_CONFIG,
30
31
  DEFAULT_LWR_LOCKER_CONFIG: () => DEFAULT_LWR_LOCKER_CONFIG,
@@ -42,13 +43,14 @@ __export(exports, {
42
43
  getMappingUriPrefix: () => getMappingUriPrefix,
43
44
  getModuleIdentity: () => getModuleIdentity,
44
45
  getModuleUriPrefix: () => getModuleUriPrefix,
46
+ getPropFromAttrName: () => getPropFromAttrName,
45
47
  getResourceIdentity: () => getResourceIdentity,
46
48
  getSpecifier: () => getSpecifier,
47
49
  getVersionedModuleId: () => getVersionedModuleId,
48
50
  getVersionedSpecifier: () => getVersionedSpecifier,
49
51
  isBundleDefinition: () => isBundleDefinition,
50
52
  isExternalUrl: () => isExternalUrl,
51
- kebabcaseToCamelcase: () => kebabcaseToCamelcase,
53
+ kebabCaseToModuleSpecifer: () => kebabCaseToModuleSpecifer,
52
54
  moduleSpecifierToKebabCase: () => moduleSpecifierToKebabCase,
53
55
  normalizeVersionFromUri: () => normalizeVersionFromUri,
54
56
  normalizeVersionToUri: () => normalizeVersionToUri,
@@ -61,6 +63,7 @@ var import_fast_json_stable_stringify = __toModule(require("fast-json-stable-str
61
63
  var VERSION_SIGIL = "/v/";
62
64
  var LOCALE_SIGIL = "l";
63
65
  var ENVIRONMENT_SIGIL = "e";
66
+ var BUNDLE_SIGIL = "bi";
64
67
  var LATEST_SIGNATURE = "latest";
65
68
  var DEFAULT_TITLE = "LWR App";
66
69
  var IMMUTABLE_ASSET_PREFIX = "/_immutable/";
@@ -157,7 +160,7 @@ function parsePackageSpecifier(specifier) {
157
160
  subResource: matched[2] || ""
158
161
  };
159
162
  }
160
- function kebabcaseToCamelcase(name) {
163
+ function kebabCaseToModuleSpecifer(name) {
161
164
  const newName = [];
162
165
  let nsFound = false;
163
166
  let upper = false;
@@ -184,18 +187,23 @@ function slugify(name) {
184
187
  lower: true
185
188
  });
186
189
  }
190
+ function getPropFromAttrName(propName) {
191
+ return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
192
+ }
187
193
  function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
188
194
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
189
195
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
190
196
  if (bundle) {
191
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/bi/0/module/mi/`;
197
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
192
198
  } else {
193
199
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
194
200
  }
195
201
  }
196
- function getMappingUriPrefix({apiVersion, format, compat, basePath}, {locale} = {}) {
202
+ function getMappingUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
197
203
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
198
- return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
204
+ const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
205
+ const bundlePart = bundle ? `/${BUNDLE_SIGIL}/0` : "";
206
+ return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}${environmentPart}${bundlePart}/mp/`;
199
207
  }
200
208
  var REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
201
209
  function isExternalUrl(url) {
@@ -214,7 +222,10 @@ function getModuleIdentity(req) {
214
222
  }
215
223
  function getMappingIdentity(req) {
216
224
  const {specifiers} = req.params;
217
- const moduleIds = explodeSpecifiers(specifiers);
225
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
226
+ ...obj,
227
+ importer: req.query.importer
228
+ }));
218
229
  return {
219
230
  moduleIds
220
231
  };
@@ -33,3 +33,4 @@ __exportStar(exports, __toModule(require("./graph.cjs")));
33
33
  __exportStar(exports, __toModule(require("./mappings.cjs")));
34
34
  __exportStar(exports, __toModule(require("./urls.cjs")));
35
35
  __exportStar(exports, __toModule(require("./env.cjs")));
36
+ __exportStar(exports, __toModule(require("./logger.cjs")));
@@ -0,0 +1,36 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/shared-utils/src/logger.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ logger: () => logger
28
+ });
29
+ var import_winston = __toModule(require("winston"));
30
+ var LOG_LEVEL = process.env.LOG_LEVEL || "info";
31
+ console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
32
+ var logger = import_winston.default.createLogger({
33
+ level: LOG_LEVEL,
34
+ format: import_winston.default.format.json(),
35
+ transports: [new import_winston.default.transports.Console()]
36
+ });
@@ -36,7 +36,8 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
36
36
  index: {}
37
37
  };
38
38
  for (const moduleId of moduleIds) {
39
- const specifier = (0, import_identity.getSpecifier)(moduleId);
39
+ const requestedSpecifier = (0, import_identity.getSpecifier)(moduleId);
40
+ const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
40
41
  if (!visitedCache.has(specifier)) {
41
42
  const depth = {
42
43
  static: runtimeEnvironment.format === "esm" ? import_graph.GraphDepth.NONE : import_graph.GraphDepth.ALL,
@@ -45,6 +46,14 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
45
46
  const moduleGraph = await (0, import_graph.getModuleGraphs)(specifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
46
47
  importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
47
48
  }
49
+ if (requestedSpecifier !== specifier) {
50
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${moduleId.importer}`;
51
+ const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
52
+ if (!specifiersArray) {
53
+ throw new Error("Could not find: " + specifier + " in " + JSON.stringify(importMetadata.imports));
54
+ }
55
+ specifiersArray.push(requestedSpecifierPlusImporter);
56
+ }
48
57
  }
49
58
  return importMetadata;
50
59
  }
@@ -127,3 +136,12 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
127
136
  await Promise.all(promises);
128
137
  return index;
129
138
  }
139
+ async function getVersionedSpecifier(moduleId, moduleRegistry) {
140
+ if (!moduleId.importer || moduleId.version) {
141
+ return (0, import_identity.getSpecifier)(moduleId);
142
+ }
143
+ const versionedModuleEntry = await moduleRegistry.getModuleEntry({
144
+ ...moduleId
145
+ });
146
+ return (0, import_identity.getSpecifier)(versionedModuleEntry);
147
+ }
package/build/es/env.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { ExperimentalFeatures } from '@lwrjs/types';
2
- export declare function getExperimentalFeatures(): ExperimentalFeatures;
1
+ import { FeatureFlags } from '@lwrjs/types';
2
+ export declare function getFeatureFlags(): FeatureFlags;
3
3
  //# sourceMappingURL=env.d.ts.map
package/build/es/env.js CHANGED
@@ -1,9 +1,7 @@
1
- export function getExperimentalFeatures() {
1
+ export function getFeatureFlags() {
2
2
  return {
3
- // DEFAULT ENABLE_FINGERPRINTS = false;
4
- ENABLE_FINGERPRINTS: process.env.ENABLE_FINGERPRINTS !== undefined && process.env.ENABLE_FINGERPRINTS === 'true'
5
- ? true
6
- : false,
3
+ // DEFAULT LEGACY_LOADER = false;
4
+ LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER === 'true' ? true : false,
7
5
  };
8
6
  }
9
7
  //# sourceMappingURL=env.js.map
package/build/es/graph.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getSpecifier, getVersionedModuleId, isBundleDefinition } from './identity.js';
2
+ import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
3
  import { ModuleNameType } from './import-metadata.js';
3
4
  export var GraphDepth;
4
5
  (function (GraphDepth) {
@@ -116,7 +117,9 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
116
117
  ? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams)
117
118
  : await defRegistry.getModule(versionedModuleId, runtimeParams);
118
119
  if (!moduleDef) {
119
- throw new Error('Missing module Definition');
120
+ throw createSingleDiagnosticError({
121
+ description: descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier),
122
+ }, LwrUnresolvableError);
120
123
  }
121
124
  const flattened = [];
122
125
  await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
@@ -1,3 +1,4 @@
1
+ import { getPropFromAttrName } from './identity.js';
1
2
  import SAXParser from 'parse5-sax-parser';
2
3
  import { Readable } from 'stream';
3
4
  function parseAssetLocation(htmlSource, tagName, attrLocation) {
@@ -28,11 +29,24 @@ export async function extractMetadataFromHtml(htmlSource) {
28
29
  const assetReferences = [];
29
30
  const parser = new SAXParser({ sourceCodeLocationInfo: true }); // TODO: Would we need this in the future?
30
31
  const ceRefStack = [];
31
- parser.on('startTag', ({ tagName, sourceCodeLocation, }) => {
32
+ parser.on('startTag', ({ tagName, attrs, // attributes are passed into SSR
33
+ sourceCodeLocation, }) => {
32
34
  // custom elements
33
35
  if (tagName.includes('-') && !openElements.has(tagName)) {
34
36
  const { startOffset, endOffset } = sourceCodeLocation;
35
- const ceRef = { tagName, location: { startOffset, endOffset } };
37
+ const ceRef = {
38
+ tagName,
39
+ location: { startOffset, endOffset },
40
+ // transform attributes [{ name: 'some-attr', value: 'the value' }] into properties { someAttr: 'the value' }
41
+ // leave props as undefined if there are no attributes
42
+ // set boolean attribute values to "true", or lwc will see them as falsy
43
+ props: attrs.length
44
+ ? attrs.reduce((obj, { name, value }) => {
45
+ obj[getPropFromAttrName(name)] = value === '' ? 'true' : value;
46
+ return obj;
47
+ }, {})
48
+ : undefined,
49
+ };
36
50
  openElements.add(tagName);
37
51
  if (ceRefStack.length) {
38
52
  // nested CE
@@ -3,6 +3,7 @@ import { AbstractModuleId, AssetIdentity, BundleDefinition, MappingIdentity, Mid
3
3
  export declare const VERSION_SIGIL = "/v/";
4
4
  export declare const LOCALE_SIGIL = "l";
5
5
  export declare const ENVIRONMENT_SIGIL = "e";
6
+ export declare const BUNDLE_SIGIL = "bi";
6
7
  export declare const LATEST_SIGNATURE = "latest";
7
8
  export declare const DEFAULT_TITLE = "LWR App";
8
9
  export declare const IMMUTABLE_ASSET_PREFIX = "/_immutable/";
@@ -126,13 +127,13 @@ interface PackageIdentity {
126
127
  */
127
128
  export declare function parsePackageSpecifier(specifier: string): PackageIdentity;
128
129
  /**
129
- * Turn a string from kebab case to camel case
130
+ * Turn a string from kebab case to "specifier case": namespace/camelCaseName
130
131
  * @param name A string in kebab case
131
132
  * @example - 'name-of-something' => 'name/ofSomething'
132
133
  */
133
- export declare function kebabcaseToCamelcase(name: string): string;
134
+ export declare function kebabCaseToModuleSpecifer(name: string): string;
134
135
  /**
135
- * Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions
136
+ * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
136
137
  * @param specifier
137
138
  * @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
138
139
  */
@@ -143,6 +144,12 @@ export declare function moduleSpecifierToKebabCase(specifier: string): string;
143
144
  * @example - 'This IS a sentence' => 'this-is-a-sentence'
144
145
  */
145
146
  export declare function slugify(name: string): string;
147
+ /**
148
+ * Turn an html attribute into a LWC property, eg: 'best-property-ever' => 'bestPropertyEver'
149
+ * @param propName - a string in kebab case (lowercase)
150
+ * @returns - a string in camel case
151
+ */
152
+ export declare function getPropFromAttrName(propName: string): string;
146
153
  /**
147
154
  * Create a module URI prefix, stopping where the specifier would be (at "mi/")
148
155
  * @param param0 - URI props from the Runtime Environment
@@ -154,7 +161,7 @@ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat,
154
161
  * @param param0 - URI props from the Runtime Environment
155
162
  * @param param1 - URI props from the Runtime Params
156
163
  */
157
- export declare function getMappingUriPrefix({ apiVersion, format, compat, basePath }: RuntimeEnvironment, { locale }?: RuntimeParams): string;
164
+ export declare function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
158
165
  export { getCacheKeyFromJson };
159
166
  export declare function isExternalUrl(url: string): boolean;
160
167
  export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
@@ -3,6 +3,7 @@ import getCacheKeyFromJson from 'fast-json-stable-stringify';
3
3
  export const VERSION_SIGIL = '/v/';
4
4
  export const LOCALE_SIGIL = 'l';
5
5
  export const ENVIRONMENT_SIGIL = 'e';
6
+ export const BUNDLE_SIGIL = 'bi';
6
7
  export const LATEST_SIGNATURE = 'latest';
7
8
  export const DEFAULT_TITLE = 'LWR App';
8
9
  export const IMMUTABLE_ASSET_PREFIX = '/_immutable/';
@@ -189,11 +190,11 @@ export function parsePackageSpecifier(specifier) {
189
190
  };
190
191
  }
191
192
  /**
192
- * Turn a string from kebab case to camel case
193
+ * Turn a string from kebab case to "specifier case": namespace/camelCaseName
193
194
  * @param name A string in kebab case
194
195
  * @example - 'name-of-something' => 'name/ofSomething'
195
196
  */
196
- export function kebabcaseToCamelcase(name) {
197
+ export function kebabCaseToModuleSpecifer(name) {
197
198
  const newName = [];
198
199
  let nsFound = false;
199
200
  let upper = false;
@@ -215,7 +216,7 @@ export function kebabcaseToCamelcase(name) {
215
216
  return newName.join('');
216
217
  }
217
218
  /**
218
- * Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions
219
+ * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
219
220
  * @param specifier
220
221
  * @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
221
222
  */
@@ -235,6 +236,14 @@ export function slugify(name) {
235
236
  lower: true,
236
237
  });
237
238
  }
239
+ /**
240
+ * Turn an html attribute into a LWC property, eg: 'best-property-ever' => 'bestPropertyEver'
241
+ * @param propName - a string in kebab case (lowercase)
242
+ * @returns - a string in camel case
243
+ */
244
+ export function getPropFromAttrName(propName) {
245
+ return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
246
+ }
238
247
  /**
239
248
  * Create a module URI prefix, stopping where the specifier would be (at "mi/")
240
249
  * @param param0 - URI props from the Runtime Environment
@@ -244,7 +253,7 @@ export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePat
244
253
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
245
254
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
246
255
  if (bundle) {
247
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/bi/0/module/mi/`;
256
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
248
257
  }
249
258
  else {
250
259
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
@@ -255,9 +264,11 @@ export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePat
255
264
  * @param param0 - URI props from the Runtime Environment
256
265
  * @param param1 - URI props from the Runtime Params
257
266
  */
258
- export function getMappingUriPrefix({ apiVersion, format, compat, basePath }, { locale } = {}) {
267
+ export function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}) {
259
268
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
260
- return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
269
+ const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
270
+ const bundlePart = bundle ? `/${BUNDLE_SIGIL}/0` : '';
271
+ return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}${environmentPart}${bundlePart}/mp/`;
261
272
  }
262
273
  export { getCacheKeyFromJson };
263
274
  const REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
@@ -278,7 +289,10 @@ export function getModuleIdentity(req) {
278
289
  }
279
290
  export function getMappingIdentity(req) {
280
291
  const { specifiers } = req.params;
281
- const moduleIds = explodeSpecifiers(specifiers);
292
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
293
+ ...obj,
294
+ importer: req.query.importer,
295
+ }));
282
296
  return {
283
297
  moduleIds,
284
298
  };
@@ -12,4 +12,5 @@ export * from './graph.js';
12
12
  export * from './mappings.js';
13
13
  export * from './urls.js';
14
14
  export * from './env.js';
15
+ export * from './logger.js';
15
16
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -12,4 +12,5 @@ export * from './graph.js';
12
12
  export * from './mappings.js';
13
13
  export * from './urls.js';
14
14
  export * from './env.js';
15
+ export * from './logger.js';
15
16
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import winston from 'winston';
2
+ export declare const logger: winston.Logger;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,9 @@
1
+ import winston from 'winston';
2
+ const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
3
+ console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
4
+ export const logger = winston.createLogger({
5
+ level: LOG_LEVEL,
6
+ format: winston.format.json(),
7
+ transports: [new winston.transports.Console()],
8
+ });
9
+ //# sourceMappingURL=logger.js.map
@@ -10,7 +10,9 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
10
10
  index: {},
11
11
  };
12
12
  for (const moduleId of moduleIds) {
13
- const specifier = getSpecifier(moduleId);
13
+ const requestedSpecifier = getSpecifier(moduleId);
14
+ // eslint-disable-next-line no-await-in-loop
15
+ const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
14
16
  // Check if we have already visited
15
17
  if (!visitedCache.has(specifier)) {
16
18
  // Traversal of the Module Graph is done to get all the URLs for discoverable dependencies.
@@ -27,6 +29,15 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
27
29
  // eslint-disable-next-line no-await-in-loop
28
30
  importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
29
31
  }
32
+ // If the requested specifier is not the same as the versioned specifier, include the requested specifier's importer.
33
+ if (requestedSpecifier !== specifier) {
34
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${moduleId.importer}`;
35
+ const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
36
+ if (!specifiersArray) {
37
+ throw new Error('Could not find: ' + specifier + ' in ' + JSON.stringify(importMetadata.imports));
38
+ }
39
+ specifiersArray.push(requestedSpecifierPlusImporter);
40
+ }
30
41
  }
31
42
  return importMetadata;
32
43
  }
@@ -141,4 +152,13 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
141
152
  await Promise.all(promises);
142
153
  return index;
143
154
  }
155
+ async function getVersionedSpecifier(moduleId, moduleRegistry) {
156
+ if (!moduleId.importer || moduleId.version) {
157
+ return getSpecifier(moduleId);
158
+ }
159
+ const versionedModuleEntry = await moduleRegistry.getModuleEntry({
160
+ ...moduleId,
161
+ });
162
+ return getSpecifier(versionedModuleEntry);
163
+ }
144
164
  //# sourceMappingURL=mappings.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.0",
7
+ "version": "0.7.0-alpha.11",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -40,16 +40,17 @@
40
40
  "magic-string": "^0.25.7",
41
41
  "mime-types": "^2.1.33",
42
42
  "parse5-sax-parser": "^6.0.1",
43
- "slugify": "^1.4.5"
43
+ "slugify": "^1.4.5",
44
+ "winston": "^3.7.2"
44
45
  },
45
46
  "devDependencies": {
46
- "@lwrjs/diagnostics": "0.7.0-alpha.0",
47
- "@lwrjs/types": "0.7.0-alpha.0",
47
+ "@lwrjs/diagnostics": "0.7.0-alpha.11",
48
+ "@lwrjs/types": "0.7.0-alpha.11",
48
49
  "@types/mime-types": "2.1.1",
49
50
  "@types/path-to-regexp": "^1.7.0"
50
51
  },
51
52
  "engines": {
52
53
  "node": ">=14.15.4 <17"
53
54
  },
54
- "gitHead": "4ed70d0bb9fd53feb629468b558b882adade0967"
55
+ "gitHead": "0b272d15905ec7b949974e8c5ba668a98eaa7e2d"
55
56
  }