@lwrjs/module-registry 0.10.0-alpha.9 → 0.10.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.
@@ -81,8 +81,13 @@ var LwrModuleRegistry = class {
81
81
  }
82
82
  const {bundle, format} = runtimeEnvironment;
83
83
  if (bundle) {
84
+ let bundleId;
85
+ if (format === "amd") {
86
+ const bundleGroups = this.globalConfig?.bundleConfig?.groups;
87
+ bundleId = bundleGroups && (0, import_shared_utils.getGroupName)(moduleId.specifier, bundleGroups);
88
+ }
84
89
  return new Promise((resolve, reject) => {
85
- (0, import_signature.getBundleSignature)(moduleId, this, this.globalConfig?.bundleConfig?.exclude).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature))).catch(reject);
90
+ (0, import_signature.getBundleSignature)(moduleId, this, this.globalConfig?.bundleConfig?.exclude).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature, bundleId))).catch(reject);
86
91
  });
87
92
  } else {
88
93
  return new Promise((resolve, reject) => {
@@ -111,15 +116,7 @@ var LwrModuleRegistry = class {
111
116
  });
112
117
  }
113
118
  async createModuleDefinition(moduleId, runtimeParams) {
114
- const {locker} = this.globalConfig;
115
119
  const moduleCompiled = await this.delegateGetModuleOnProviders(moduleId, runtimeParams);
116
- if (locker.enabled && !locker.clientOnly) {
117
- const {runtimeEnvironment} = this.context;
118
- const {minify, sourceMapUrl} = runtimeEnvironment;
119
- const sourcemap = typeof sourceMapUrl === "string" || !minify;
120
- const {code: lockerizedCode} = (0, import_compiler.lockerize)(moduleCompiled, locker, sourcemap);
121
- moduleCompiled.compiledSource = lockerizedCode;
122
- }
123
120
  const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this);
124
121
  return {...moduleCompiled, moduleRecord};
125
122
  }
@@ -31,7 +31,7 @@ var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
31
31
  var import_signature = __toModule(require("../signature.cjs"));
32
32
  async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
33
33
  const {specifier, version, compiledSource, moduleRecord} = moduleDef;
34
- const {imports, dynamicImports} = moduleRecord;
34
+ const {imports, dynamicImports, importMeta} = moduleRecord;
35
35
  const codeStringBuilder = (0, import_shared_utils.createStringBuilder)(compiledSource);
36
36
  const amdLoaderModule = config?.amdLoaderModule;
37
37
  const esmLoaderModule = config?.esmLoaderModule;
@@ -115,6 +115,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
115
115
  return {...importRef, sourceSpecifier, specifier: link2, locations: linkedLocations};
116
116
  }));
117
117
  }
118
+ let loaderImportOffset = 0;
118
119
  if (dynamicImports && dynamicImports.length > 0 && (amdLoaderModule || esmLoaderModule)) {
119
120
  const {version: version2, specifier: specifier2} = amdLoaderModule || esmLoaderModule;
120
121
  const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(specifier2);
@@ -123,8 +124,10 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
123
124
  signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry, exclude);
124
125
  }
125
126
  const loaderLink = strategy({specifier: specifier2, version: version2}, runtimeEnvironment, runtimeParams, signature);
126
- codeStringBuilder.prepend(`import { load } from "${loaderLink}";
127
- `);
127
+ const loaderImport = `import { load } from "${loaderLink}";
128
+ `;
129
+ loaderImportOffset = loaderImport.length;
130
+ codeStringBuilder.prepend(loaderImport);
128
131
  linkedImports.unshift({
129
132
  name,
130
133
  namespace,
@@ -139,6 +142,32 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
139
142
  ]
140
143
  });
141
144
  }
145
+ if (importMeta && importMeta.length > 0) {
146
+ importMeta.forEach(({statement, location}) => {
147
+ if (statement === "import.meta.env.SSR") {
148
+ codeStringBuilder.overwrite(location.startColumn, location.endColumn, "isServer");
149
+ }
150
+ });
151
+ const envSpecifier = "lwr/environment";
152
+ const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(envSpecifier);
153
+ const envLink = strategy({specifier: envSpecifier, version: runtimeEnvironment.lwrVersion}, runtimeEnvironment, runtimeParams);
154
+ const envImport = `import { isServer } from "${envLink}";
155
+ `;
156
+ codeStringBuilder.prepend(envImport);
157
+ linkedImports.unshift({
158
+ name,
159
+ namespace,
160
+ sourceSpecifier: specifier,
161
+ specifier: envLink,
162
+ version,
163
+ locations: [
164
+ {
165
+ startColumn: 26 + loaderImportOffset,
166
+ endColumn: 26 + envLink.length + loaderImportOffset
167
+ }
168
+ ]
169
+ });
170
+ }
142
171
  return {
143
172
  id,
144
173
  code: codeStringBuilder.toString(),
@@ -29,15 +29,15 @@ __export(exports, {
29
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
30
  var SIGNATURE_SIGIL = "s";
31
31
  var LATEST_SIG = "latest";
32
- function linkEsm(moduleId, environment, params = {}, signature) {
32
+ function linkEsm(moduleId, environment, params = {}, signature, bundleId) {
33
33
  const {bundle, debug} = environment;
34
34
  const {specifier, version} = moduleId;
35
- const uriPrefix = (0, import_shared_utils.getModuleUriPrefix)(environment, params);
35
+ const uriPrefix = (0, import_shared_utils.getModuleUriPrefix)(environment, params, bundleId);
36
36
  const vSpecifier = (0, import_shared_utils.getSpecifier)({specifier, version: (0, import_shared_utils.normalizeVersionToUri)(version)});
37
37
  const encodedVSpecifier = encodeURIComponent(vSpecifier);
38
38
  const latestSignature = signature === void 0 || signature === LATEST_SIG;
39
39
  const sigilSignature = latestSignature ? LATEST_SIG : `${SIGNATURE_SIGIL}/${signature}`;
40
- const prettyUrl = (bundle ? "bundle_" : "") + (0, import_shared_utils.prettyModuleUriSuffix)(specifier);
40
+ const prettyUrl = (bundle ? "bundle_" : "") + (0, import_shared_utils.prettyModuleUriSuffix)(bundleId || specifier);
41
41
  const debugModifier = debug ? "?debug=true" : "";
42
42
  return `${uriPrefix}${encodedVSpecifier}/${sigilSignature}/${prettyUrl}.js${debugModifier}`;
43
43
  }
@@ -74,7 +74,11 @@ async function getModuleRecord(compiledModule, registry) {
74
74
  const dynamicImports = [];
75
75
  const {compiledMetadata: defaultCompilerMetadata, moduleEntry, version} = compiledModule;
76
76
  const compiledMetadata = defaultCompilerMetadata || {};
77
- const {imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports} = await (0, import_shared_utils.getImportMetadata)(compiledModule.compiledSource);
77
+ const {
78
+ imports: compiledModuleImports,
79
+ dynamicImports: compiledModuleDynamicImports,
80
+ importMeta
81
+ } = await (0, import_shared_utils.getImportMetadata)(compiledModule.compiledSource);
78
82
  Object.assign(compiledMetadata, {
79
83
  imports: compiledModuleImports,
80
84
  dynamicImports: compiledModuleDynamicImports
@@ -158,6 +162,7 @@ async function getModuleRecord(compiledModule, registry) {
158
162
  }
159
163
  return {
160
164
  imports,
161
- dynamicImports
165
+ dynamicImports,
166
+ importMeta
162
167
  };
163
168
  }
package/build/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
- import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, } from '@lwrjs/shared-utils';
2
+ import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, getGroupName, } from '@lwrjs/shared-utils';
3
3
  // dependencies @locker/compiler and rollup are in this package.json is to satisfy the shared-utils/compiler optional dependencies
4
- import { convertToAmd, lockerize } from '@lwrjs/shared-utils/compiler';
4
+ import { convertToAmd } from '@lwrjs/shared-utils/compiler';
5
5
  import { link } from './linker/linker.js';
6
6
  import { getModuleRecord } from './module-record.js';
7
7
  import amdLinkingStrategy from './linker/strategies/amd-strategy.js';
@@ -60,9 +60,15 @@ export class LwrModuleRegistry {
60
60
  // Else compute the URL from source
61
61
  const { bundle, format } = runtimeEnvironment;
62
62
  if (bundle) {
63
+ let bundleId;
64
+ if (format === 'amd') {
65
+ // bundling groups is only supported in AMD for now
66
+ const bundleGroups = this.globalConfig?.bundleConfig?.groups;
67
+ bundleId = bundleGroups && getGroupName(moduleId.specifier, bundleGroups);
68
+ }
63
69
  return new Promise((resolve, reject) => {
64
70
  getBundleSignature(moduleId, this, this.globalConfig?.bundleConfig?.exclude)
65
- .then((bundleSignature) => resolve(esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, bundleSignature)))
71
+ .then((bundleSignature) => resolve(esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, bundleSignature, bundleId)))
66
72
  .catch(reject);
67
73
  });
68
74
  // For individual files we return a module URL
@@ -101,18 +107,7 @@ export class LwrModuleRegistry {
101
107
  });
102
108
  }
103
109
  async createModuleDefinition(moduleId, runtimeParams) {
104
- const { locker } = this.globalConfig;
105
110
  const moduleCompiled = await this.delegateGetModuleOnProviders(moduleId, runtimeParams); // provider source + hash
106
- /** Locker before collecting dep module records so locker imports are processed normally */
107
- if (locker.enabled && !locker.clientOnly) {
108
- const { runtimeEnvironment } = this.context;
109
- // Locker should generate inline source maps in non-minified modes
110
- // in addition to being explicitly enabled.
111
- const { minify, sourceMapUrl } = runtimeEnvironment;
112
- const sourcemap = typeof sourceMapUrl === 'string' || !minify;
113
- const { code: lockerizedCode } = lockerize(moduleCompiled, locker, sourcemap);
114
- moduleCompiled.compiledSource = lockerizedCode;
115
- }
116
111
  const moduleRecord = await getModuleRecord(moduleCompiled, this);
117
112
  return { ...moduleCompiled, moduleRecord };
118
113
  }
@@ -1,5 +1,5 @@
1
- import { ModuleRecord, ModuleEntry, ModuleDefinition, RuntimeEnvironment, Specifier, RuntimeParams, InterchangeableModuleMap } from '@lwrjs/types';
2
- import { LwrModuleRegistry } from '../index.js';
1
+ import type { ModuleRecord, ModuleEntry, ModuleDefinition, RuntimeEnvironment, Specifier, RuntimeParams, InterchangeableModuleMap } from '@lwrjs/types';
2
+ import type { LwrModuleRegistry } from '../index.js';
3
3
  export interface LinkingStrategy {
4
4
  (moduleId: {
5
5
  specifier: Specifier;
@@ -9,7 +9,7 @@ import { getBundleSignature } from '../signature.js';
9
9
  */
10
10
  export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
11
11
  const { specifier, version, compiledSource, moduleRecord } = moduleDef;
12
- const { imports, dynamicImports } = moduleRecord;
12
+ const { imports, dynamicImports, importMeta } = moduleRecord;
13
13
  const codeStringBuilder = createStringBuilder(compiledSource);
14
14
  const amdLoaderModule = config?.amdLoaderModule;
15
15
  const esmLoaderModule = config?.esmLoaderModule;
@@ -112,6 +112,7 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
112
112
  }));
113
113
  }
114
114
  // (optionally) add loader module import link if necessary
115
+ let loaderImportOffset = 0;
115
116
  if (dynamicImports && dynamicImports.length > 0 && (amdLoaderModule || esmLoaderModule)) {
116
117
  // mutate ModuleEntry to ImportModuleRecord
117
118
  const { version, specifier } = amdLoaderModule || esmLoaderModule;
@@ -123,7 +124,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
123
124
  }
124
125
  const loaderLink = strategy({ specifier, version }, runtimeEnvironment, runtimeParams, signature);
125
126
  // import {load} from 'loader/loader'
126
- codeStringBuilder.prepend(`import { load } from "${loaderLink}";\n`);
127
+ const loaderImport = `import { load } from "${loaderLink}";\n`;
128
+ loaderImportOffset = loaderImport.length;
129
+ codeStringBuilder.prepend(loaderImport);
127
130
  linkedImports.unshift({
128
131
  name,
129
132
  namespace,
@@ -138,6 +141,34 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
138
141
  ],
139
142
  });
140
143
  }
144
+ // replace "import.meta.env.SSR" statements with the "isServer" boolean from "lwr/environment"
145
+ if (importMeta && importMeta.length > 0) {
146
+ // Replace each "import.meta.env.SSR" statement with "isServer"
147
+ importMeta.forEach(({ statement, location }) => {
148
+ if (statement === 'import.meta.env.SSR') {
149
+ codeStringBuilder.overwrite(location.startColumn, location.endColumn, 'isServer');
150
+ }
151
+ });
152
+ // Add import { isServer } from 'lwr/environment'
153
+ const envSpecifier = 'lwr/environment';
154
+ const { namespace, name } = explodeSpecifier(envSpecifier);
155
+ const envLink = strategy({ specifier: envSpecifier, version: runtimeEnvironment.lwrVersion }, runtimeEnvironment, runtimeParams);
156
+ const envImport = `import { isServer } from "${envLink}";\n`;
157
+ codeStringBuilder.prepend(envImport);
158
+ linkedImports.unshift({
159
+ name,
160
+ namespace,
161
+ sourceSpecifier: specifier,
162
+ specifier: envLink,
163
+ version,
164
+ locations: [
165
+ {
166
+ startColumn: 26 + loaderImportOffset,
167
+ endColumn: 26 + envLink.length + loaderImportOffset,
168
+ },
169
+ ],
170
+ });
171
+ }
141
172
  return {
142
173
  id,
143
174
  code: codeStringBuilder.toString(),
@@ -1,4 +1,4 @@
1
- import { Specifier } from '@lwrjs/types';
1
+ import type { Specifier } from '@lwrjs/types';
2
2
  export default function amdLinkingStrategy(moduleId: {
3
3
  specifier: Specifier;
4
4
  version: string;
@@ -1,6 +1,6 @@
1
- import { RuntimeEnvironment, RuntimeParams, Specifier } from '@lwrjs/types';
1
+ import type { RuntimeEnvironment, RuntimeParams, Specifier } from '@lwrjs/types';
2
2
  export default function linkEsm(moduleId: {
3
3
  specifier: Specifier;
4
4
  version: string;
5
- }, environment: RuntimeEnvironment, params?: RuntimeParams, signature?: string): string;
5
+ }, environment: RuntimeEnvironment, params?: RuntimeParams, signature?: string, bundleId?: string): string;
6
6
  //# sourceMappingURL=esm-strategy.d.ts.map
@@ -1,15 +1,15 @@
1
1
  import { getModuleUriPrefix, getSpecifier, normalizeVersionToUri, prettyModuleUriSuffix, } from '@lwrjs/shared-utils';
2
2
  const SIGNATURE_SIGIL = 's';
3
3
  const LATEST_SIG = 'latest';
4
- export default function linkEsm(moduleId, environment, params = {}, signature) {
4
+ export default function linkEsm(moduleId, environment, params = {}, signature, bundleId) {
5
5
  const { bundle, debug } = environment;
6
6
  const { specifier, version } = moduleId;
7
- const uriPrefix = getModuleUriPrefix(environment, params);
7
+ const uriPrefix = getModuleUriPrefix(environment, params, bundleId);
8
8
  const vSpecifier = getSpecifier({ specifier, version: normalizeVersionToUri(version) });
9
9
  const encodedVSpecifier = encodeURIComponent(vSpecifier);
10
10
  const latestSignature = signature === undefined || signature === LATEST_SIG;
11
11
  const sigilSignature = latestSignature ? LATEST_SIG : `${SIGNATURE_SIGIL}/${signature}`;
12
- const prettyUrl = (bundle ? 'bundle_' : '') + prettyModuleUriSuffix(specifier);
12
+ const prettyUrl = (bundle ? 'bundle_' : '') + prettyModuleUriSuffix(bundleId || specifier);
13
13
  const debugModifier = debug ? '?debug=true' : '';
14
14
  return `${uriPrefix}${encodedVSpecifier}/${sigilSignature}/${prettyUrl}.js${debugModifier}`;
15
15
  }
@@ -57,7 +57,7 @@ export async function getModuleRecord(compiledModule, registry) {
57
57
  const { compiledMetadata: defaultCompilerMetadata, moduleEntry, version } = compiledModule;
58
58
  const compiledMetadata = defaultCompilerMetadata || {};
59
59
  // Get imports metadata and merge with rest of compiledModule metadata
60
- const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports } = await getImportMetadata(compiledModule.compiledSource);
60
+ const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports, importMeta, } = await getImportMetadata(compiledModule.compiledSource);
61
61
  Object.assign(compiledMetadata, {
62
62
  imports: compiledModuleImports,
63
63
  dynamicImports: compiledModuleDynamicImports,
@@ -153,6 +153,7 @@ export async function getModuleRecord(compiledModule, registry) {
153
153
  return {
154
154
  imports,
155
155
  dynamicImports,
156
+ importMeta,
156
157
  };
157
158
  }
158
159
  //# sourceMappingURL=module-record.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.10.0-alpha.9",
7
+ "version": "0.10.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,18 +30,15 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@locker/compiler": "0.19.0",
34
- "@lwrjs/diagnostics": "0.10.0-alpha.9",
35
- "@lwrjs/shared-utils": "0.10.0-alpha.9",
36
- "es-module-lexer": "^0.3.18",
33
+ "@lwrjs/diagnostics": "0.10.0",
34
+ "@lwrjs/shared-utils": "0.10.0",
37
35
  "rollup": "^2.78.0"
38
36
  },
39
37
  "devDependencies": {
40
- "@lwrjs/types": "0.10.0-alpha.9",
41
- "@types/es-module-lexer": "^0.3.0"
38
+ "@lwrjs/types": "0.10.0"
42
39
  },
43
40
  "engines": {
44
- "node": ">=16.0.0 <20"
41
+ "node": ">=16.0.0"
45
42
  },
46
- "gitHead": "6da48f5164ac881396055096a6c1e3d0f8d981aa"
43
+ "gitHead": "e6deaeef3db8aa079acefed508897eca19b3218a"
47
44
  }