@lwrjs/shared-utils 0.7.0-alpha.5 → 0.7.0-alpha.8

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.
@@ -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;
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];
@@ -43,13 +43,14 @@ __export(exports, {
43
43
  getMappingUriPrefix: () => getMappingUriPrefix,
44
44
  getModuleIdentity: () => getModuleIdentity,
45
45
  getModuleUriPrefix: () => getModuleUriPrefix,
46
+ getPropFromAttrName: () => getPropFromAttrName,
46
47
  getResourceIdentity: () => getResourceIdentity,
47
48
  getSpecifier: () => getSpecifier,
48
49
  getVersionedModuleId: () => getVersionedModuleId,
49
50
  getVersionedSpecifier: () => getVersionedSpecifier,
50
51
  isBundleDefinition: () => isBundleDefinition,
51
52
  isExternalUrl: () => isExternalUrl,
52
- kebabcaseToCamelcase: () => kebabcaseToCamelcase,
53
+ kebabCaseToModuleSpecifer: () => kebabCaseToModuleSpecifer,
53
54
  moduleSpecifierToKebabCase: () => moduleSpecifierToKebabCase,
54
55
  normalizeVersionFromUri: () => normalizeVersionFromUri,
55
56
  normalizeVersionToUri: () => normalizeVersionToUri,
@@ -159,7 +160,7 @@ function parsePackageSpecifier(specifier) {
159
160
  subResource: matched[2] || ""
160
161
  };
161
162
  }
162
- function kebabcaseToCamelcase(name) {
163
+ function kebabCaseToModuleSpecifer(name) {
163
164
  const newName = [];
164
165
  let nsFound = false;
165
166
  let upper = false;
@@ -186,6 +187,9 @@ function slugify(name) {
186
187
  lower: true
187
188
  });
188
189
  }
190
+ function getPropFromAttrName(propName) {
191
+ return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
192
+ }
189
193
  function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
190
194
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
191
195
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
@@ -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
+ });
@@ -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,23 @@ 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
+ props: attrs.length
43
+ ? attrs.reduce((obj, { name, value }) => {
44
+ obj[getPropFromAttrName(name)] = value;
45
+ return obj;
46
+ }, {})
47
+ : undefined,
48
+ };
36
49
  openElements.add(tagName);
37
50
  if (ceRefStack.length) {
38
51
  // nested CE
@@ -127,13 +127,13 @@ interface PackageIdentity {
127
127
  */
128
128
  export declare function parsePackageSpecifier(specifier: string): PackageIdentity;
129
129
  /**
130
- * Turn a string from kebab case to camel case
130
+ * Turn a string from kebab case to "specifier case": namespace/camelCaseName
131
131
  * @param name A string in kebab case
132
132
  * @example - 'name-of-something' => 'name/ofSomething'
133
133
  */
134
- export declare function kebabcaseToCamelcase(name: string): string;
134
+ export declare function kebabCaseToModuleSpecifer(name: string): string;
135
135
  /**
136
- * Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions
136
+ * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
137
137
  * @param specifier
138
138
  * @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
139
139
  */
@@ -144,6 +144,12 @@ export declare function moduleSpecifierToKebabCase(specifier: string): string;
144
144
  * @example - 'This IS a sentence' => 'this-is-a-sentence'
145
145
  */
146
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;
147
153
  /**
148
154
  * Create a module URI prefix, stopping where the specifier would be (at "mi/")
149
155
  * @param param0 - URI props from the Runtime Environment
@@ -190,11 +190,11 @@ export function parsePackageSpecifier(specifier) {
190
190
  };
191
191
  }
192
192
  /**
193
- * Turn a string from kebab case to camel case
193
+ * Turn a string from kebab case to "specifier case": namespace/camelCaseName
194
194
  * @param name A string in kebab case
195
195
  * @example - 'name-of-something' => 'name/ofSomething'
196
196
  */
197
- export function kebabcaseToCamelcase(name) {
197
+ export function kebabCaseToModuleSpecifer(name) {
198
198
  const newName = [];
199
199
  let nsFound = false;
200
200
  let upper = false;
@@ -216,7 +216,7 @@ export function kebabcaseToCamelcase(name) {
216
216
  return newName.join('');
217
217
  }
218
218
  /**
219
- * Clone of lwr/init, reverse of kebabcaseToCamelcase, strips off versions
219
+ * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
220
220
  * @param specifier
221
221
  * @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
222
222
  */
@@ -236,6 +236,14 @@ export function slugify(name) {
236
236
  lower: true,
237
237
  });
238
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
+ }
239
247
  /**
240
248
  * Create a module URI prefix, stopping where the specifier would be (at "mi/")
241
249
  * @param param0 - URI props from the Runtime Environment
@@ -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
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.5",
7
+ "version": "0.7.0-alpha.8",
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.5",
47
- "@lwrjs/types": "0.7.0-alpha.5",
47
+ "@lwrjs/diagnostics": "0.7.0-alpha.8",
48
+ "@lwrjs/types": "0.7.0-alpha.8",
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": "4be785ee5e0da8fbbf29bf18993bbd77febf5a2c"
55
+ "gitHead": "fbe1daed908cf07eaf9fc8821f2ba2947f5d919f"
55
56
  }