@lwrjs/shared-utils 0.9.0-alpha.15 → 0.9.0-alpha.17

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.
@@ -25,7 +25,8 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  GraphDepth: () => GraphDepth,
28
- getModuleGraphs: () => getModuleGraphs
28
+ getModuleGraphs: () => getModuleGraphs,
29
+ isBundler: () => isBundler
29
30
  });
30
31
  var import_identity = __toModule(require("./identity.cjs"));
31
32
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
@@ -74,21 +74,29 @@ function log(level, message, additionalInfo) {
74
74
  }
75
75
  }
76
76
  if (shouldLog) {
77
- let logMessage;
78
- if (additionalInfo) {
79
- logMessage = `[${level}]${gap(message)}${message}
80
- Additional Info: ${JSON.stringify(additionalInfo)}`;
81
- } else {
82
- logMessage = `[${level}]${gap(message)}${message}`;
83
- }
77
+ const logMessage = `[${level}]${gap(message)}${message}`;
78
+ const additionalMessage = additionalInfo ? `Additional Info: ${JSON.stringify(additionalInfo)}` : void 0;
84
79
  if (level == ERROR) {
85
80
  console.error("%s", logMessage);
81
+ if (additionalInfo) {
82
+ console.error("\n%s", additionalMessage);
83
+ }
86
84
  } else if (level == WARN) {
87
85
  console.warn("%s", logMessage);
86
+ if (additionalInfo) {
87
+ console.warn("\n%s", additionalMessage);
88
+ }
88
89
  } else if (level == DEBUG || level == VERBOSE) {
89
90
  console.log("%s", logMessage);
91
+ if (additionalInfo) {
92
+ console.log("\n%s", additionalMessage);
93
+ }
90
94
  } else {
91
95
  console.log(logMessage);
96
+ if (additionalInfo) {
97
+ console.log(`
98
+ ${additionalMessage}`);
99
+ }
92
100
  }
93
101
  }
94
102
  }
@@ -57,7 +57,7 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
57
57
  }
58
58
  return importMetadata;
59
59
  }
60
- async function toImportMetadata(moduleGraph, existingImportMetadata = {imports: {}, index: {}}, defRegistry, runtimeEnvironment, runtimeParams = {}) {
60
+ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams = {}) {
61
61
  const specifier = moduleGraph.graphs[0].specifier;
62
62
  const uri = moduleGraph.uriMap[specifier];
63
63
  const definition = moduleGraph.linkedDefinitions[specifier];
@@ -67,7 +67,7 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
67
67
  if (!definition) {
68
68
  throw new Error("Linked module definition was not included in the graph: " + specifier);
69
69
  }
70
- const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, defRegistry, runtimeEnvironment, runtimeParams);
70
+ const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
71
71
  let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
72
72
  const depSpecifiers = runtimeEnvironment.format === "esm" ? moduleGraph.graphs[0].dynamicRefs : moduleGraph.graphs[0].static;
73
73
  for (const depSpecifier of depSpecifiers) {
@@ -85,7 +85,7 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
85
85
  continue;
86
86
  }
87
87
  if (!importMetadata.imports[depUri]) {
88
- const depMetadata = await normalizeImportMetadata((0, import_identity.getSpecifier)(depDef), depUri, depDef, defRegistry, runtimeEnvironment, runtimeParams);
88
+ const depMetadata = await normalizeImportMetadata((0, import_identity.getSpecifier)(depDef), depUri, depDef, moduleRegistry, runtimeEnvironment, runtimeParams);
89
89
  importMetadata = mergeImportMetadata(importMetadata, depMetadata);
90
90
  }
91
91
  }
@@ -103,11 +103,11 @@ function mergeImportMetadata(existing, newMetadata) {
103
103
  }
104
104
  };
105
105
  }
106
- async function normalizeImportMetadata(specifier, uri, definition, defRegistry, moduleRuntimeEnvironment, runtimeParams) {
106
+ async function normalizeImportMetadata(specifier, uri, definition, moduleRegistry, moduleRuntimeEnvironment, runtimeParams) {
107
107
  const specifiers = normalizedIncludedModules(definition);
108
108
  const imports = {};
109
109
  imports[uri] = specifiers;
110
- const index = await createIndex(specifiers, defRegistry, moduleRuntimeEnvironment, runtimeParams);
110
+ const index = await createIndex(specifiers, moduleRegistry, moduleRuntimeEnvironment, runtimeParams);
111
111
  if (!(specifier in index)) {
112
112
  index[specifier] = uri;
113
113
  }
@@ -119,7 +119,7 @@ async function normalizeImportMetadata(specifier, uri, definition, defRegistry,
119
119
  function normalizedIncludedModules(definition) {
120
120
  return (0, import_identity.isBundleDefinition)(definition) ? [(0, import_identity.getSpecifier)(definition), ...definition.bundleRecord.includedModules] : [(0, import_identity.getSpecifier)(definition)];
121
121
  }
122
- async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeParams) {
122
+ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runtimeParams) {
123
123
  const index = {};
124
124
  const moduleRuntimeEnvironment = {...runtimeEnvironment, bundle: false};
125
125
  async function getUri(specifier) {
@@ -127,7 +127,7 @@ async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeP
127
127
  if (!moduleId.version) {
128
128
  throw new Error("Module specifier must include a version: " + specifier);
129
129
  }
130
- index[specifier] = await defRegistry.resolveModuleUri({...moduleId, version: moduleId.version}, moduleRuntimeEnvironment, runtimeParams);
130
+ index[specifier] = await moduleRegistry.resolveModuleUri({...moduleId, version: moduleId.version}, moduleRuntimeEnvironment, runtimeParams);
131
131
  }
132
132
  const promises = [];
133
133
  for (const specifier of specifiers) {
@@ -29,7 +29,7 @@ __export(exports, {
29
29
  var import_path = __toModule(require("path"));
30
30
  var import_fs_extra = __toModule(require("fs-extra"));
31
31
  var import_logger = __toModule(require("./logger.cjs"));
32
- var SITE_METADATA_PATH = "site-metadata";
32
+ var SITE_METADATA_PATH = ".metadata";
33
33
  var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
34
34
  var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
35
35
  var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
@@ -40,6 +40,9 @@ var SiteMetadataImpl = class {
40
40
  this.siteResources = this.readStaticResourceMetadata(options.rootDir);
41
41
  this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
42
42
  }
43
+ getSiteRootDir() {
44
+ return this.options.rootDir;
45
+ }
43
46
  getSiteBundles() {
44
47
  return this.siteBundles;
45
48
  }
@@ -1,9 +1,10 @@
1
- import { ModuleRegistry, RuntimeEnvironment, RuntimeParams, FlattenedModuleGraphs, GraphNode, GraphOptions, ModuleBundler } from '@lwrjs/types';
1
+ import type { ModuleRegistry, RuntimeEnvironment, RuntimeParams, FlattenedModuleGraphs, GraphNode, GraphOptions, ModuleBundler, PublicModuleRegistry, PublicModuleBundler } from '@lwrjs/types';
2
2
  export declare enum GraphDepth {
3
3
  ALL = "all",
4
4
  DIRECT = "direct",
5
5
  NONE = "none"
6
6
  }
7
+ export declare function isBundler(registry: PublicModuleRegistry | PublicModuleBundler): registry is PublicModuleBundler;
7
8
  export declare function getModuleGraphs(specifier: string, // version | un-versioned specifiers
8
9
  options: GraphOptions, moduleRegistry: ModuleRegistry, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, visited?: Map<string, GraphNode>): Promise<FlattenedModuleGraphs>;
9
10
  //# sourceMappingURL=graph.d.ts.map
package/build/es/graph.js CHANGED
@@ -8,7 +8,7 @@ export var GraphDepth;
8
8
  GraphDepth["NONE"] = "none";
9
9
  })(GraphDepth || (GraphDepth = {}));
10
10
  // type guard for ViewDef responses
11
- function isBundler(registry) {
11
+ export function isBundler(registry) {
12
12
  return registry.getModuleBundle !== undefined;
13
13
  }
14
14
  async function traverse(module, depth, flattened,
@@ -43,24 +43,33 @@ function log(level, message, additionalInfo) {
43
43
  }
44
44
  }
45
45
  if (shouldLog) {
46
- let logMessage;
47
- if (additionalInfo) {
48
- logMessage = `[${level}]${gap(message)}${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`;
49
- }
50
- else {
51
- logMessage = `[${level}]${gap(message)}${message}`;
52
- }
46
+ const logMessage = `[${level}]${gap(message)}${message}`;
47
+ const additionalMessage = additionalInfo
48
+ ? `Additional Info: ${JSON.stringify(additionalInfo)}`
49
+ : undefined;
53
50
  if (level == ERROR) {
54
51
  console.error('\x1b[31m%s\x1b[0m', logMessage); // red
52
+ if (additionalInfo) {
53
+ console.error('\n\x1b[31m%s\x1b[0m', additionalMessage); // red
54
+ }
55
55
  }
56
56
  else if (level == WARN) {
57
57
  console.warn('\x1b[33m%s\x1b[0m', logMessage); // yellow
58
+ if (additionalInfo) {
59
+ console.warn('\n\x1b[33m%s\x1b[0m', additionalMessage); // yellow
60
+ }
58
61
  }
59
62
  else if (level == DEBUG || level == VERBOSE) {
60
63
  console.log('\x1b[2m%s\x1b[0m', logMessage); // dim
64
+ if (additionalInfo) {
65
+ console.log('\n\x1b[2m%s\x1b[0m', additionalMessage); // dim
66
+ }
61
67
  }
62
68
  else {
63
69
  console.log(logMessage);
70
+ if (additionalInfo) {
71
+ console.log(`\n${additionalMessage}`);
72
+ }
64
73
  }
65
74
  }
66
75
  }
@@ -15,5 +15,5 @@ export declare function getImportMetadataMappings(moduleIds: AbstractModuleId[],
15
15
  * @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
16
16
  * @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
17
17
  */
18
- export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ImportMetadata>;
18
+ export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ImportMetadata>;
19
19
  //# sourceMappingURL=mappings.d.ts.map
@@ -53,7 +53,7 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
53
53
  * @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
54
54
  * @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
55
55
  */
56
- export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} }, defRegistry, runtimeEnvironment, runtimeParams = {}) {
56
+ export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams = {}) {
57
57
  // root module specifier
58
58
  const specifier = moduleGraph.graphs[0].specifier;
59
59
  const uri = moduleGraph.uriMap[specifier];
@@ -65,7 +65,7 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
65
65
  throw new Error('Linked module definition was not included in the graph: ' + specifier);
66
66
  }
67
67
  // Merge in the existing metadata with imports for the root specifier
68
- const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, defRegistry, runtimeEnvironment, runtimeParams);
68
+ const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
69
69
  let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
70
70
  // root module dependencies:
71
71
  // - static for AMD; dynamic dependencies require a new mapping request
@@ -91,7 +91,7 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
91
91
  }
92
92
  if (!importMetadata.imports[depUri]) {
93
93
  // eslint-disable-next-line no-await-in-loop
94
- const depMetadata = await normalizeImportMetadata(getSpecifier(depDef), depUri, depDef, defRegistry, runtimeEnvironment, runtimeParams);
94
+ const depMetadata = await normalizeImportMetadata(getSpecifier(depDef), depUri, depDef, moduleRegistry, runtimeEnvironment, runtimeParams);
95
95
  importMetadata = mergeImportMetadata(importMetadata, depMetadata);
96
96
  }
97
97
  }
@@ -110,12 +110,12 @@ function mergeImportMetadata(existing, newMetadata) {
110
110
  },
111
111
  };
112
112
  }
113
- async function normalizeImportMetadata(specifier, uri, definition, defRegistry, moduleRuntimeEnvironment, runtimeParams) {
113
+ async function normalizeImportMetadata(specifier, uri, definition, moduleRegistry, moduleRuntimeEnvironment, runtimeParams) {
114
114
  const specifiers = normalizedIncludedModules(definition);
115
115
  const imports = {};
116
116
  imports[uri] = specifiers;
117
117
  // The index info for the modules included in a bundle
118
- const index = await createIndex(specifiers, defRegistry, moduleRuntimeEnvironment, runtimeParams);
118
+ const index = await createIndex(specifiers, moduleRegistry, moduleRuntimeEnvironment, runtimeParams);
119
119
  // If root specifier was not included in createIndex add an entry where the uri is the index
120
120
  if (!(specifier in index)) {
121
121
  index[specifier] = uri;
@@ -132,7 +132,7 @@ function normalizedIncludedModules(definition) {
132
132
  ? [getSpecifier(definition), ...definition.bundleRecord.includedModules]
133
133
  : [getSpecifier(definition)];
134
134
  }
135
- async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeParams) {
135
+ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runtimeParams) {
136
136
  const index = {};
137
137
  // We need a runtime environment for modules when building the index for a bundle
138
138
  const moduleRuntimeEnvironment = { ...runtimeEnvironment, bundle: false };
@@ -141,7 +141,9 @@ async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeP
141
141
  if (!moduleId.version) {
142
142
  throw new Error('Module specifier must include a version: ' + specifier);
143
143
  }
144
- index[specifier] = await defRegistry.resolveModuleUri({ ...moduleId, version: moduleId.version }, moduleRuntimeEnvironment, runtimeParams);
144
+ // Do not use replace with the moduleBundler. Otherwize we will create a bundle from every
145
+ // root just to get the URL.
146
+ index[specifier] = await moduleRegistry.resolveModuleUri({ ...moduleId, version: moduleId.version }, moduleRuntimeEnvironment, runtimeParams);
145
147
  }
146
148
  // Queue up uri requests
147
149
  const promises = [];
@@ -9,6 +9,7 @@ export declare class SiteMetadataImpl implements SiteMetadata {
9
9
  private siteResources;
10
10
  private siteAssets;
11
11
  constructor(options: Options);
12
+ getSiteRootDir(): string;
12
13
  getSiteBundles(): SiteBundles;
13
14
  getSiteResources(): SiteResources;
14
15
  getSiteAssets(): SiteAssets;
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs-extra';
3
3
  import { logger } from './logger.js';
4
- const SITE_METADATA_PATH = 'site-metadata';
4
+ const SITE_METADATA_PATH = '.metadata';
5
5
  const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
6
6
  const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
7
7
  const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
@@ -12,6 +12,9 @@ export class SiteMetadataImpl {
12
12
  this.siteResources = this.readStaticResourceMetadata(options.rootDir);
13
13
  this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
14
14
  }
15
+ getSiteRootDir() {
16
+ return this.options.rootDir;
17
+ }
15
18
  getSiteBundles() {
16
19
  return this.siteBundles;
17
20
  }
@@ -3,7 +3,7 @@ import { join, dirname, extname } from 'path';
3
3
  import esbuildEsm from 'esbuild';
4
4
  // https://github.com/evanw/esbuild/issues/706
5
5
  // Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
6
- // https://github.com/salesforce-experience-platform/lwr/issues/1014
6
+ // https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
7
7
  let esbuild = esbuildEsm;
8
8
  if (!esbuildEsm) {
9
9
  try {
package/package.json CHANGED
@@ -4,18 +4,18 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.15",
7
+ "version": "0.9.0-alpha.17",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/salesforce/lwr.git",
11
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
12
12
  "directory": "packages/@lwrjs/shared-utils"
13
13
  },
14
14
  "scripts": {
15
15
  "build": "tsc -b"
16
16
  },
17
17
  "bugs": {
18
- "url": "https://github.com/salesforce/lwr/issues"
18
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
19
19
  },
20
20
  "type": "module",
21
21
  "types": "build/es/index.d.ts",
@@ -54,20 +54,20 @@
54
54
  "path-to-regexp": "^6.2.0",
55
55
  "slugify": "^1.4.5"
56
56
  },
57
- "optionalDependencies": {
57
+ "peerDependencies": {
58
58
  "@locker/compiler": "0.18.2",
59
59
  "chokidar": "^3.5.3",
60
60
  "esbuild": "^0.9.7",
61
61
  "rollup": "~2.45.2"
62
62
  },
63
63
  "devDependencies": {
64
- "@lwrjs/diagnostics": "0.9.0-alpha.15",
65
- "@lwrjs/types": "0.9.0-alpha.15",
64
+ "@lwrjs/diagnostics": "0.9.0-alpha.17",
65
+ "@lwrjs/types": "0.9.0-alpha.17",
66
66
  "@types/mime-types": "2.1.1",
67
67
  "@types/path-to-regexp": "^1.7.0"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=14.15.4 <19"
71
71
  },
72
- "gitHead": "f32f103d2d5e516daccce1be69f68acd7b4b86fb"
72
+ "gitHead": "447417ff091802927b25cfc1bcb01da02264f41b"
73
73
  }