@lwrjs/module-registry 0.8.0-alpha.2 → 0.8.0-alpha.5

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.
@@ -118,7 +118,14 @@ var LwrModuleRegistry = class {
118
118
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
119
119
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
120
120
  const id = moduleEntry.id;
121
- const {format, compat, debug, minify, bundle} = runtimeEnvironment;
121
+ const {
122
+ format,
123
+ compat,
124
+ debug,
125
+ minify,
126
+ bundle,
127
+ env: {NODE_ENV: envMode}
128
+ } = runtimeEnvironment;
122
129
  const locale = runtimeParams?.["locale"];
123
130
  const environment = runtimeParams?.["environment"];
124
131
  const {
@@ -144,6 +151,18 @@ var LwrModuleRegistry = class {
144
151
  }
145
152
  const moduleDef = await this.getModule(moduleId, runtimeParams);
146
153
  const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
154
+ if (format === "amd" && !bundle) {
155
+ moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
156
+ id: moduleLinked.id
157
+ })).code;
158
+ }
159
+ const minified = !!minify && !debug;
160
+ if (minified && !bundle) {
161
+ moduleLinked.linkedSource = (await this.context.compiler.minifyJavascript(moduleLinked.linkedSource)).code;
162
+ moduleLinked.linkedConfig.minified = true;
163
+ } else {
164
+ moduleLinked.linkedSource = (await this.context.compiler.parseJavascript(moduleLinked.linkedSource, {envMode})).code;
165
+ }
147
166
  if (cacheDisabled === false) {
148
167
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
149
168
  linkedMap.set((0, import_shared_utils.getCacheKeyFromJson)({
@@ -161,42 +180,24 @@ var LwrModuleRegistry = class {
161
180
  return moduleLinked;
162
181
  }
163
182
  async createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams) {
164
- const {
165
- format,
166
- minify,
167
- debug,
168
- env: {NODE_ENV: envMode}
169
- } = runtimeEnvironment;
170
- const minified = !!minify && !debug;
183
+ const {format} = runtimeEnvironment;
171
184
  const {amdLoader, esmLoader} = this.globalConfig;
172
185
  if (format === "amd") {
173
186
  const loaderModuleEntry = await this.getModuleEntry({specifier: amdLoader}, runtimeParams);
174
187
  const {
175
188
  id,
176
- code: linkedES6,
189
+ code: linkedSource,
177
190
  linkedModuleRecord
178
191
  } = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, {
179
192
  amdLoaderModule: loaderModuleEntry
180
193
  }, this.interchangeableModules);
181
- const {code: amdSource} = await this.context.compiler.convertToAmd(linkedES6, {
182
- id
183
- });
184
- let linkedAmdSource = amdSource;
185
- if (minified) {
186
- const {code: minifiedCode} = await this.context.compiler.minifyJavascript(amdSource);
187
- linkedAmdSource = minifiedCode;
188
- } else {
189
- const {code: minifiedCode} = await this.context.compiler.parseJavascript(amdSource, {
190
- envMode
191
- });
192
- linkedAmdSource = minifiedCode;
193
- }
194
194
  linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== import_shared_utils.ModuleNameType.unresolved);
195
195
  return {
196
196
  ...moduleDef,
197
- linkedSource: linkedAmdSource,
197
+ id,
198
+ linkedSource,
198
199
  linkedConfig: {
199
- minified
200
+ minified: false
200
201
  },
201
202
  linkedModuleRecord,
202
203
  runtimeEnvironment
@@ -207,26 +208,21 @@ var LwrModuleRegistry = class {
207
208
  if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
208
209
  loaderModuleEntry = await this.getModuleEntry({specifier: esmLoader}, runtimeParams);
209
210
  }
210
- const {code: esmLinkedSource, linkedModuleRecord} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
211
+ const {
212
+ id,
213
+ code: linkedSource,
214
+ linkedModuleRecord
215
+ } = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
211
216
  esmLoaderModule: loaderModuleEntry
212
217
  }, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
213
- let transformedEsmCode = esmLinkedSource;
214
- if (minified) {
215
- const {code: minifiedEsm} = await this.context.compiler.minifyJavascript(transformedEsmCode);
216
- transformedEsmCode = minifiedEsm;
217
- } else {
218
- const {code: parsedEsm} = await this.context.compiler.parseJavascript(transformedEsmCode, {
219
- envMode
220
- });
221
- transformedEsmCode = parsedEsm;
222
- }
223
218
  linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== import_shared_utils.ModuleNameType.unresolved);
224
219
  return {
225
220
  ...moduleDef,
221
+ id,
222
+ linkedSource,
226
223
  linkedConfig: {
227
- minified
224
+ minified: false
228
225
  },
229
- linkedSource: transformedEsmCode,
230
226
  linkedModuleRecord,
231
227
  runtimeEnvironment,
232
228
  runtimeParams
package/build/es/index.js CHANGED
@@ -108,7 +108,7 @@ export class LwrModuleRegistry {
108
108
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
109
109
  const id = moduleEntry.id;
110
110
  // cache key pivots from the runtimeEnvironment
111
- const { format, compat, debug, minify, bundle } = runtimeEnvironment;
111
+ const { format, compat, debug, minify, bundle, env: { NODE_ENV: envMode }, } = runtimeEnvironment;
112
112
  const locale = runtimeParams?.['locale'];
113
113
  const environment = runtimeParams?.['environment'];
114
114
  const { locker: { enabled: lockerEnabled }, } = this.globalConfig;
@@ -132,6 +132,22 @@ export class LwrModuleRegistry {
132
132
  }
133
133
  const moduleDef = await this.getModule(moduleId, runtimeParams);
134
134
  const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
135
+ // the bundler will convert the linked source to AMD when bundling is enabled
136
+ if (format === 'amd' && !bundle) {
137
+ // convert the linkedSource to the transport AMD format
138
+ moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
139
+ id: moduleLinked.id,
140
+ })).code;
141
+ }
142
+ const minified = !!minify && !debug;
143
+ // the bundler will minify when bundling is enabled
144
+ if (minified && !bundle) {
145
+ moduleLinked.linkedSource = (await this.context.compiler.minifyJavascript(moduleLinked.linkedSource)).code;
146
+ moduleLinked.linkedConfig.minified = true;
147
+ }
148
+ else {
149
+ moduleLinked.linkedSource = (await this.context.compiler.parseJavascript(moduleLinked.linkedSource, { envMode })).code;
150
+ }
135
151
  // Add to cache
136
152
  if (cacheDisabled === false) {
137
153
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
@@ -150,39 +166,24 @@ export class LwrModuleRegistry {
150
166
  return moduleLinked;
151
167
  }
152
168
  async createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams) {
153
- const { format, minify, debug, env: { NODE_ENV: envMode }, } = runtimeEnvironment;
154
- const minified = !!minify && !debug;
169
+ const { format } = runtimeEnvironment;
155
170
  const { amdLoader, esmLoader } = this.globalConfig;
156
171
  // TODO: compat transformation based on runtimeEnvironment.compat
157
172
  if (format === 'amd') {
158
173
  // Resolve the loader entry
159
174
  const loaderModuleEntry = await this.getModuleEntry({ specifier: amdLoader }, runtimeParams);
160
175
  // transforms compiledModule into linkedModule (which means the imports may have changed)
161
- const { id, code: linkedES6, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, {
176
+ const { id, code: linkedSource, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, {
162
177
  amdLoaderModule: loaderModuleEntry,
163
178
  }, this.interchangeableModules);
164
- // convert the linkedSource to the transport AMD format.
165
- const { code: amdSource } = await this.context.compiler.convertToAmd(linkedES6, {
166
- id,
167
- });
168
- let linkedAmdSource = amdSource;
169
- if (minified) {
170
- const { code: minifiedCode } = await this.context.compiler.minifyJavascript(amdSource);
171
- linkedAmdSource = minifiedCode;
172
- }
173
- else {
174
- const { code: minifiedCode } = await this.context.compiler.parseJavascript(amdSource, {
175
- envMode,
176
- });
177
- linkedAmdSource = minifiedCode;
178
- }
179
179
  // Filter out variable dynamic imports
180
180
  linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
181
181
  return {
182
182
  ...moduleDef,
183
- linkedSource: linkedAmdSource,
183
+ id,
184
+ linkedSource,
184
185
  linkedConfig: {
185
- minified,
186
+ minified: false,
186
187
  },
187
188
  linkedModuleRecord,
188
189
  runtimeEnvironment,
@@ -197,28 +198,18 @@ export class LwrModuleRegistry {
197
198
  // AND this is not the ESM loader itself (it uses a variable dynamic import we DO NOT want to link)
198
199
  loaderModuleEntry = await this.getModuleEntry({ specifier: esmLoader }, runtimeParams);
199
200
  }
200
- const { code: esmLinkedSource, linkedModuleRecord } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
201
+ const { id, code: linkedSource, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
201
202
  esmLoaderModule: loaderModuleEntry,
202
203
  }, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
203
- let transformedEsmCode = esmLinkedSource;
204
- if (minified) {
205
- const { code: minifiedEsm } = await this.context.compiler.minifyJavascript(transformedEsmCode);
206
- transformedEsmCode = minifiedEsm;
207
- }
208
- else {
209
- const { code: parsedEsm } = await this.context.compiler.parseJavascript(transformedEsmCode, {
210
- envMode,
211
- });
212
- transformedEsmCode = parsedEsm;
213
- }
214
204
  // Filter out variable dynamic imports
215
205
  linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
216
206
  return {
217
207
  ...moduleDef,
208
+ id,
209
+ linkedSource,
218
210
  linkedConfig: {
219
- minified,
211
+ minified: false,
220
212
  },
221
- linkedSource: transformedEsmCode,
222
213
  linkedModuleRecord,
223
214
  runtimeEnvironment,
224
215
  runtimeParams,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.2",
7
+ "version": "0.8.0-alpha.5",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,18 +30,18 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/diagnostics": "0.8.0-alpha.2",
34
- "@lwrjs/shared-utils": "0.8.0-alpha.2",
33
+ "@lwrjs/diagnostics": "0.8.0-alpha.5",
34
+ "@lwrjs/shared-utils": "0.8.0-alpha.5",
35
35
  "es-module-lexer": "^0.3.18",
36
36
  "ws": "^7.2.5"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.8.0-alpha.2",
39
+ "@lwrjs/types": "0.8.0-alpha.5",
40
40
  "@types/es-module-lexer": "^0.3.0",
41
41
  "@types/ws": "^7.2.4"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=14.15.4 <19"
45
45
  },
46
- "gitHead": "44bee038acb30418870678d886e3ded4a6afecf0"
46
+ "gitHead": "bc2eed0c7a5a5f9ecbbd335bf896e6d6c5076c19"
47
47
  }