@lwrjs/lwc-module-provider 0.12.0-alpha.1 → 0.12.0-alpha.3

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.
@@ -32,7 +32,8 @@ __export(exports, {
32
32
  setupModuleCache: () => setupModuleCache
33
33
  });
34
34
  var import_path = __toModule(require("path"));
35
- var import_fs = __toModule(require("fs"));
35
+ var import_fs_extra = __toModule(require("fs-extra"));
36
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
36
37
  var DEFAULT_COMPILED_DIR = "lwc_compiled_modules";
37
38
  var DEFAULT_CACHE_FOLDER = "cache";
38
39
  var DEFAULT_CACHE_INDEX = `compiled.json`;
@@ -40,42 +41,58 @@ var NORMALIZE_PATH_REGEX = /[@\/#\.\?<>\\:\*\|"]/gm;
40
41
  function setupModuleCache(cacheDir) {
41
42
  const lwcCacheDir = import_path.default.join(cacheDir, `${DEFAULT_COMPILED_DIR}`);
42
43
  const lwcCacheIndexPath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_INDEX);
43
- import_fs.default.mkdirSync(`${lwcCacheDir}/${DEFAULT_CACHE_FOLDER}`, {recursive: true});
44
- if (!import_fs.default.existsSync(lwcCacheIndexPath)) {
45
- import_fs.default.writeFileSync(lwcCacheIndexPath, "[]");
44
+ import_fs_extra.default.mkdirSync(`${lwcCacheDir}/${DEFAULT_CACHE_FOLDER}`, {recursive: true});
45
+ if (!import_fs_extra.default.existsSync(lwcCacheIndexPath)) {
46
+ import_fs_extra.default.writeFileSync(lwcCacheIndexPath, "[]");
46
47
  return {lwcCacheDir, lwcCacheIndex: new Map()};
47
48
  } else {
48
- const rawIndex = import_fs.default.readFileSync(lwcCacheIndexPath, "utf-8");
49
- try {
50
- const cacheIndexJson = JSON.parse(rawIndex);
51
- return {lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson)};
52
- } catch (err) {
53
- const newErr = new Error("Invalid LWC Index: " + rawIndex);
54
- if (err.stack) {
55
- newErr.stack += "\nCaused by: " + err.stack;
56
- }
57
- throw newErr;
58
- }
49
+ const cacheIndexJson = import_fs_extra.default.readJSONSync(lwcCacheIndexPath, "utf-8");
50
+ return {lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson)};
59
51
  }
60
52
  }
61
- function addCompiledModuleCacheEntry(moduleSource, compilerResult, {lwcCacheIndex, lwcCacheDir}) {
53
+ var IndexPersister = class {
54
+ async persist({lwcCacheIndex, lwcCacheDir}) {
55
+ if (this.updateTimer) {
56
+ clearTimeout(this.updateTimer);
57
+ }
58
+ this.lwcCacheIndex = lwcCacheIndex;
59
+ this.lwcCacheDir = lwcCacheDir;
60
+ this.updateTimer = setTimeout(() => {
61
+ this.persistData();
62
+ this.lwcCacheIndex = void 0;
63
+ this.lwcCacheDir = void 0;
64
+ this.updateTimer = void 0;
65
+ }, 1e3);
66
+ }
67
+ persistData() {
68
+ const lwcCacheIndexPath = import_path.default.join(this.lwcCacheDir, DEFAULT_CACHE_INDEX);
69
+ import_fs_extra.default.writeJSONSync(lwcCacheIndexPath, [...this.lwcCacheIndex]);
70
+ import_diagnostics.logger.debug("lwc-module-provider", `LWC Index Updated`);
71
+ }
72
+ };
73
+ var INDEX_PERSISTER = new IndexPersister();
74
+ var moduleCount = 0;
75
+ async function addCompiledModuleCacheEntry(moduleSource, compilerResult, {lwcCacheIndex, lwcCacheDir}) {
62
76
  const {specifier, version, ownHash} = moduleSource;
63
- const lwcCacheIndexPath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_INDEX);
64
77
  const cacheKey = `${specifier}@${version}`;
78
+ if (++moduleCount % 1e3 === 0) {
79
+ import_diagnostics.logger.debug({label: `lwc-module-provider`, message: `Compiled Modules >${moduleCount}`});
80
+ }
65
81
  const normalizedSpecifier = specifier.replace(NORMALIZE_PATH_REGEX, "_");
66
82
  const normalizedVersion = version.replace(NORMALIZE_PATH_REGEX, "_");
67
83
  const moduleFileName = `${normalizedSpecifier}_${normalizedVersion}.js`;
68
84
  const cachedModulePath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_FOLDER, moduleFileName);
69
- import_fs.default.writeFileSync(cachedModulePath, compilerResult.code);
85
+ const writeModulePromise = import_fs_extra.default.writeFile(cachedModulePath, compilerResult.code);
70
86
  const moduleMetaFileName = `${normalizedSpecifier}_${normalizedVersion}.meta.json`;
71
87
  const cachedMetaPath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_FOLDER, moduleMetaFileName);
72
- import_fs.default.writeFileSync(cachedMetaPath, JSON.stringify(compilerResult.metadata, null, " "));
88
+ const writeMetadataPromise = import_fs_extra.default.writeJSON(cachedMetaPath, compilerResult.metadata);
73
89
  lwcCacheIndex.set(cacheKey, {
74
90
  ownHash,
75
91
  module: `./${DEFAULT_CACHE_FOLDER}/${moduleFileName}`,
76
92
  moduleMeta: `./${DEFAULT_CACHE_FOLDER}/${moduleMetaFileName}`
77
93
  });
78
- import_fs.default.writeFileSync(lwcCacheIndexPath, JSON.stringify([...lwcCacheIndex], null, " "));
94
+ const writeMetadata = INDEX_PERSISTER.persist({lwcCacheIndex, lwcCacheDir});
95
+ return Promise.all([writeModulePromise, writeMetadataPromise, writeMetadata]);
79
96
  }
80
97
  function getCompiledModuleCacheEntry({specifier, version, ownHash}, {lwcCacheIndex, lwcCacheDir}) {
81
98
  const cacheKey = `${specifier}@${version}`;
@@ -85,10 +102,10 @@ function getCompiledModuleCacheEntry({specifier, version, ownHash}, {lwcCacheInd
85
102
  }
86
103
  const cacheModulePath = import_path.default.join(lwcCacheDir, cacheEntry.module);
87
104
  const cacheMetaPath = import_path.default.join(lwcCacheDir, cacheEntry.moduleMeta);
88
- if (ownHash === cacheEntry.ownHash && import_fs.default.existsSync(cacheModulePath) && import_fs.default.existsSync(cacheMetaPath)) {
105
+ if (ownHash === cacheEntry.ownHash && import_fs_extra.default.existsSync(cacheModulePath) && import_fs_extra.default.existsSync(cacheMetaPath)) {
89
106
  return {
90
- code: import_fs.default.readFileSync(cacheModulePath, "utf-8"),
91
- metadata: JSON.parse(import_fs.default.readFileSync(cacheMetaPath, "utf-8"))
107
+ code: import_fs_extra.default.readFileSync(cacheModulePath, "utf-8"),
108
+ metadata: JSON.parse(import_fs_extra.default.readFileSync(cacheMetaPath, "utf-8"))
92
109
  };
93
110
  }
94
111
  }
@@ -38,7 +38,7 @@ function getModuleEntryCacheKey(specifier, version) {
38
38
  var LwcModuleProvider = class {
39
39
  constructor(options = {}, {
40
40
  appEmitter,
41
- config: {locker, modules, rootDir, cacheDir, environment},
41
+ config: {modules, rootDir, cacheDir, environment},
42
42
  runtimeEnvironment: {watchFiles},
43
43
  watcherFactory
44
44
  }) {
@@ -47,12 +47,12 @@ var LwcModuleProvider = class {
47
47
  this.packageVersionCache = new Map();
48
48
  this.watchedModuleContextMap = new Map();
49
49
  this.moduleEntryVersionCache = new Map();
50
+ this.importerMappingCache = new Map();
50
51
  this.lwcCompiler = new import_compiler.LwcCompiler();
51
52
  this.inflightGetModuleJobs = new import_shared_utils.InflightTasks();
52
53
  this.inflightGetModuleEntryJobs = new import_shared_utils.InflightTasks();
53
54
  const {disableCaching} = options;
54
55
  this.emitter = appEmitter;
55
- this.locker = locker;
56
56
  this.modules = modules;
57
57
  this.rootDir = rootDir;
58
58
  this.watcher = watchFiles && watcherFactory ? (0, import_utils.setUpWatcher)(watcherFactory, this.onModuleChange.bind(this)) : void 0;
@@ -101,14 +101,10 @@ var LwcModuleProvider = class {
101
101
  import_diagnostics.logger.debug({
102
102
  label: `${this.name}`,
103
103
  message: "module source",
104
- additionalInfo: {
105
- moduleId,
106
- isPreCompiled: compiledModule != void 0
107
- }
104
+ additionalInfo: {moduleId, isPreCompiled: compiledModule != void 0}
108
105
  });
109
106
  if (!compiledModule) {
110
107
  const [name] = rawName.split("#");
111
- const enableLightningWebSecurityTransforms = !!this.locker?.enabled && !this.locker?.clientOnly;
112
108
  const scopedStyles = moduleEntry.entry.endsWith(".css") && moduleEntry.specifier.endsWith("?scoped=true");
113
109
  import_diagnostics.logger.debug({
114
110
  label: `${this.name}`,
@@ -124,7 +120,6 @@ var LwcModuleProvider = class {
124
120
  namespace,
125
121
  name,
126
122
  filename: moduleEntry.entry,
127
- enableLightningWebSecurityTransforms,
128
123
  scopedStyles
129
124
  });
130
125
  import_diagnostics.logger.verbose({
@@ -138,7 +133,7 @@ var LwcModuleProvider = class {
138
133
  }
139
134
  });
140
135
  if (moduleFsCacheEnabled) {
141
- (0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
136
+ await (0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
142
137
  }
143
138
  }
144
139
  if (watcher && !watchedModuleContextMap.has(moduleEntry.entry)) {
@@ -182,15 +177,12 @@ var LwcModuleProvider = class {
182
177
  label: `${this.name}`,
183
178
  message: `getModuleEntry ${specifier}@${version}@${importer}`
184
179
  });
185
- const versionId = version || importer;
186
- if (versionId) {
187
- const cacheKey2 = getModuleEntryCacheKey(specifier, versionId);
188
- if (this.moduleEntryVersionCache.has(cacheKey2)) {
189
- return this.moduleEntryVersionCache.get(cacheKey2);
190
- }
180
+ const moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
181
+ if (moduleEntry) {
182
+ return moduleEntry;
191
183
  }
192
- const cacheKey = `${specifier}@${version}@${importer}`;
193
- return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
184
+ const jobKey = `${specifier}@${version}@${importer}`;
185
+ return this.inflightGetModuleEntryJobs.execute(jobKey, async () => {
194
186
  return this.createModuleEntry({specifier, importer, version});
195
187
  });
196
188
  }
@@ -212,9 +204,8 @@ var LwcModuleProvider = class {
212
204
  const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
213
205
  const fileRelativePath = fileRelativePathRaw?.split("?")[0];
214
206
  let moduleEntry;
215
- if (fileRelativePath && version) {
216
- const cacheKey2 = getModuleEntryCacheKey(specifier, version);
217
- moduleEntry = this.moduleEntryVersionCache.get(cacheKey2);
207
+ if (fileRelativePath) {
208
+ moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
218
209
  }
219
210
  if (!moduleEntry) {
220
211
  try {
@@ -224,8 +215,7 @@ var LwcModuleProvider = class {
224
215
  additionalInfo: {
225
216
  baseSpecifier,
226
217
  importer,
227
- rootDir: this.rootDir,
228
- modules: this.modules
218
+ rootDir: this.rootDir
229
219
  }
230
220
  });
231
221
  const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
@@ -270,11 +260,26 @@ var LwcModuleProvider = class {
270
260
  const cacheKey = getModuleEntryCacheKey(specifier, moduleEntry.version);
271
261
  const finalModuleEntry = {...moduleEntry, id: cacheKey};
272
262
  this.moduleEntryVersionCache.set(cacheKey, finalModuleEntry);
273
- if (!version && importer) {
274
- const importerCacheKey = getModuleEntryCacheKey(specifier, importer);
275
- this.moduleEntryVersionCache.set(importerCacheKey, finalModuleEntry);
263
+ if (!version) {
264
+ const importerCacheKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
265
+ this.importerMappingCache.set(importerCacheKey, cacheKey);
276
266
  }
277
267
  return finalModuleEntry;
278
268
  }
269
+ getCachedModuleEntry(specifier, version, importer) {
270
+ let moduleEntry;
271
+ if (version) {
272
+ const cacheKey = getModuleEntryCacheKey(specifier, version);
273
+ moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
274
+ }
275
+ if (!moduleEntry) {
276
+ const importerKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
277
+ const cacheKey = this.importerMappingCache.get(importerKey);
278
+ if (cacheKey) {
279
+ moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
280
+ }
281
+ }
282
+ return moduleEntry;
283
+ }
279
284
  };
280
285
  var src_default = LwcModuleProvider;
@@ -41,7 +41,7 @@ function resolveModuleSpecifier(specifier, importer, modules = [], packageVersio
41
41
  import_diagnostics.logger.debug({
42
42
  label: `lwc-module-provider`,
43
43
  message: "resolveModuleSpecifier",
44
- additionalInfo: {specifier, importer, modules}
44
+ additionalInfo: {specifier, importer}
45
45
  });
46
46
  let resolvedModule;
47
47
  try {
@@ -16,6 +16,6 @@ export interface ModuleCacheContext {
16
16
  * We store an index file and the compiler modules individually
17
17
  */
18
18
  export declare function setupModuleCache(cacheDir: string): ModuleCacheContext;
19
- export declare function addCompiledModuleCacheEntry(moduleSource: ModuleSource, compilerResult: CompilerResult, { lwcCacheIndex, lwcCacheDir }: ModuleCacheContext): void;
19
+ export declare function addCompiledModuleCacheEntry(moduleSource: ModuleSource, compilerResult: CompilerResult, { lwcCacheIndex, lwcCacheDir }: ModuleCacheContext): Promise<any>;
20
20
  export declare function getCompiledModuleCacheEntry({ specifier, version, ownHash }: ModuleSource, { lwcCacheIndex, lwcCacheDir }: ModuleCacheContext): CompilerResult | undefined;
21
21
  //# sourceMappingURL=cache.d.ts.map
package/build/es/cache.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import path from 'path';
2
- import fs from 'fs';
2
+ import fs from 'fs-extra';
3
+ import { logger } from '@lwrjs/diagnostics';
3
4
  export const DEFAULT_COMPILED_DIR = 'lwc_compiled_modules';
4
5
  export const DEFAULT_CACHE_FOLDER = 'cache';
5
6
  export const DEFAULT_CACHE_INDEX = `compiled.json`;
@@ -18,35 +19,52 @@ export function setupModuleCache(cacheDir) {
18
19
  return { lwcCacheDir, lwcCacheIndex: new Map() };
19
20
  }
20
21
  else {
21
- const rawIndex = fs.readFileSync(lwcCacheIndexPath, 'utf-8');
22
- try {
23
- const cacheIndexJson = JSON.parse(rawIndex);
24
- return { lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson) };
25
- }
26
- catch (err) {
27
- const newErr = new Error('Invalid LWC Index: ' + rawIndex);
28
- if (err.stack) {
29
- newErr.stack += '\nCaused by: ' + err.stack;
30
- }
31
- throw newErr;
22
+ const cacheIndexJson = fs.readJSONSync(lwcCacheIndexPath, 'utf-8');
23
+ return { lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson) };
24
+ }
25
+ }
26
+ class IndexPersister {
27
+ async persist({ lwcCacheIndex, lwcCacheDir }) {
28
+ // Clear previous timer
29
+ if (this.updateTimer) {
30
+ clearTimeout(this.updateTimer);
32
31
  }
32
+ this.lwcCacheIndex = lwcCacheIndex;
33
+ this.lwcCacheDir = lwcCacheDir;
34
+ // Set a new timer for 1 second
35
+ this.updateTimer = setTimeout(() => {
36
+ this.persistData();
37
+ this.lwcCacheIndex = undefined;
38
+ this.lwcCacheDir = undefined;
39
+ this.updateTimer = undefined;
40
+ }, 1000);
41
+ }
42
+ persistData() {
43
+ // Write data to disk
44
+ const lwcCacheIndexPath = path.join(this.lwcCacheDir, DEFAULT_CACHE_INDEX);
45
+ fs.writeJSONSync(lwcCacheIndexPath, [...this.lwcCacheIndex]);
46
+ logger.debug('lwc-module-provider', `LWC Index Updated`);
33
47
  }
34
48
  }
35
- export function addCompiledModuleCacheEntry(moduleSource, compilerResult, { lwcCacheIndex, lwcCacheDir }) {
49
+ const INDEX_PERSISTER = new IndexPersister();
50
+ let moduleCount = 0;
51
+ export async function addCompiledModuleCacheEntry(moduleSource, compilerResult, { lwcCacheIndex, lwcCacheDir }) {
36
52
  const { specifier, version, ownHash } = moduleSource;
37
- const lwcCacheIndexPath = path.join(lwcCacheDir, DEFAULT_CACHE_INDEX);
38
53
  const cacheKey = `${specifier}@${version}`;
54
+ if (++moduleCount % 1000 === 0) {
55
+ logger.debug({ label: `lwc-module-provider`, message: `Compiled Modules >${moduleCount}` });
56
+ }
39
57
  // Normalize name for fs storage
40
58
  const normalizedSpecifier = specifier.replace(NORMALIZE_PATH_REGEX, '_');
41
59
  const normalizedVersion = version.replace(NORMALIZE_PATH_REGEX, '_');
42
60
  // Store module cached file
43
61
  const moduleFileName = `${normalizedSpecifier}_${normalizedVersion}.js`;
44
62
  const cachedModulePath = path.join(lwcCacheDir, DEFAULT_CACHE_FOLDER, moduleFileName);
45
- fs.writeFileSync(cachedModulePath, compilerResult.code);
63
+ const writeModulePromise = fs.writeFile(cachedModulePath, compilerResult.code);
46
64
  // Store module metadata
47
65
  const moduleMetaFileName = `${normalizedSpecifier}_${normalizedVersion}.meta.json`;
48
66
  const cachedMetaPath = path.join(lwcCacheDir, DEFAULT_CACHE_FOLDER, moduleMetaFileName);
49
- fs.writeFileSync(cachedMetaPath, JSON.stringify(compilerResult.metadata, null, ' '));
67
+ const writeMetadataPromise = fs.writeJSON(cachedMetaPath, compilerResult.metadata);
50
68
  // WIP: Store sourcemaps
51
69
  // Set new cache key in memory and persistent storage
52
70
  lwcCacheIndex.set(cacheKey, {
@@ -54,7 +72,9 @@ export function addCompiledModuleCacheEntry(moduleSource, compilerResult, { lwcC
54
72
  module: `./${DEFAULT_CACHE_FOLDER}/${moduleFileName}`,
55
73
  moduleMeta: `./${DEFAULT_CACHE_FOLDER}/${moduleMetaFileName}`,
56
74
  });
57
- fs.writeFileSync(lwcCacheIndexPath, JSON.stringify([...lwcCacheIndex], null, ' '));
75
+ // Will persist the index after 1 second of inactivity
76
+ const writeMetadata = INDEX_PERSISTER.persist({ lwcCacheIndex, lwcCacheDir });
77
+ return Promise.all([writeModulePromise, writeMetadataPromise, writeMetadata]);
58
78
  }
59
79
  export function getCompiledModuleCacheEntry({ specifier, version, ownHash }, { lwcCacheIndex, lwcCacheDir }) {
60
80
  const cacheKey = `${specifier}@${version}`;
@@ -7,7 +7,6 @@ export default class LwcModuleProvider implements ModuleProvider {
7
7
  private rootDir;
8
8
  private moduleFsCacheEnabled;
9
9
  private interchangeableModulesEnabled;
10
- private locker;
11
10
  private lwcCacheDir?;
12
11
  private lwcCacheIndex?;
13
12
  private moduleSourceCache;
@@ -17,10 +16,11 @@ export default class LwcModuleProvider implements ModuleProvider {
17
16
  private watcher?;
18
17
  private watchedModuleContextMap;
19
18
  private moduleEntryVersionCache;
19
+ private importerMappingCache;
20
20
  private lwcCompiler;
21
21
  private inflightGetModuleJobs;
22
22
  private inflightGetModuleEntryJobs;
23
- constructor(options: LwcModuleProviderOptions | undefined, { appEmitter, config: { locker, modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }: ProviderContext);
23
+ constructor(options: LwcModuleProviderOptions | undefined, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }: ProviderContext);
24
24
  onModuleChange(fileChanged: string): Promise<void>;
25
25
  getModule(moduleId: AbstractModuleId): Promise<ModuleCompiled | undefined>;
26
26
  /**
@@ -32,5 +32,6 @@ export default class LwcModuleProvider implements ModuleProvider {
32
32
  getModuleSource({ name, namespace, specifier }: AbstractModuleId, moduleEntry: ModuleEntry): Promise<ModuleSource>;
33
33
  getModuleEntry({ specifier, importer, version, }: AbstractModuleId): Promise<ModuleEntry | undefined>;
34
34
  createModuleEntry({ specifier, importer, version, }: AbstractModuleId): Promise<ModuleEntry | undefined>;
35
+ private getCachedModuleEntry;
35
36
  }
36
37
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -8,18 +8,18 @@ function getModuleEntryCacheKey(specifier, version) {
8
8
  return `${specifier}@${version}`;
9
9
  }
10
10
  export default class LwcModuleProvider {
11
- constructor(options = {}, { appEmitter, config: { locker, modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }) {
11
+ constructor(options = {}, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }) {
12
12
  this.name = 'lwc-module-provider';
13
13
  this.moduleSourceCache = new Map();
14
14
  this.packageVersionCache = new Map();
15
15
  this.watchedModuleContextMap = new Map();
16
16
  this.moduleEntryVersionCache = new Map();
17
+ this.importerMappingCache = new Map();
17
18
  this.lwcCompiler = new LwcCompiler();
18
19
  this.inflightGetModuleJobs = new InflightTasks();
19
20
  this.inflightGetModuleEntryJobs = new InflightTasks();
20
21
  const { disableCaching } = options;
21
22
  this.emitter = appEmitter;
22
- this.locker = locker;
23
23
  this.modules = modules;
24
24
  this.rootDir = rootDir;
25
25
  this.watcher =
@@ -77,14 +77,10 @@ export default class LwcModuleProvider {
77
77
  logger.debug({
78
78
  label: `${this.name}`,
79
79
  message: 'module source',
80
- additionalInfo: {
81
- moduleId,
82
- isPreCompiled: compiledModule != undefined,
83
- },
80
+ additionalInfo: { moduleId, isPreCompiled: compiledModule != undefined },
84
81
  });
85
82
  if (!compiledModule) {
86
83
  const [name] = rawName.split('#');
87
- const enableLightningWebSecurityTransforms = !!this.locker?.enabled && !this.locker?.clientOnly;
88
84
  const scopedStyles = moduleEntry.entry.endsWith('.css') && moduleEntry.specifier.endsWith('?scoped=true');
89
85
  logger.debug({
90
86
  label: `${this.name}`,
@@ -101,7 +97,6 @@ export default class LwcModuleProvider {
101
97
  namespace,
102
98
  name,
103
99
  filename: moduleEntry.entry,
104
- enableLightningWebSecurityTransforms,
105
100
  scopedStyles,
106
101
  });
107
102
  logger.verbose({
@@ -115,7 +110,7 @@ export default class LwcModuleProvider {
115
110
  },
116
111
  });
117
112
  if (moduleFsCacheEnabled) {
118
- addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
113
+ await addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
119
114
  }
120
115
  }
121
116
  if (watcher && !watchedModuleContextMap.has(moduleEntry.entry)) {
@@ -156,15 +151,12 @@ export default class LwcModuleProvider {
156
151
  message: `getModuleEntry ${specifier}@${version}@${importer}`,
157
152
  });
158
153
  // Check cache
159
- const versionId = version || importer;
160
- if (versionId) {
161
- const cacheKey = getModuleEntryCacheKey(specifier, versionId);
162
- if (this.moduleEntryVersionCache.has(cacheKey)) {
163
- return this.moduleEntryVersionCache.get(cacheKey);
164
- }
154
+ const moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
155
+ if (moduleEntry) {
156
+ return moduleEntry;
165
157
  }
166
- const cacheKey = `${specifier}@${version}@${importer}`;
167
- return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
158
+ const jobKey = `${specifier}@${version}@${importer}`;
159
+ return this.inflightGetModuleEntryJobs.execute(jobKey, async () => {
168
160
  return this.createModuleEntry({ specifier, importer, version });
169
161
  });
170
162
  }
@@ -186,9 +178,8 @@ export default class LwcModuleProvider {
186
178
  const fileRelativePath = fileRelativePathRaw?.split('?')[0]; // Remove queryString as LWC uses it for scope style
187
179
  let moduleEntry;
188
180
  // If this is a relative import, check the cache for the base specifier first
189
- if (fileRelativePath && version) {
190
- const cacheKey = getModuleEntryCacheKey(specifier, version);
191
- moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
181
+ if (fileRelativePath) {
182
+ moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
192
183
  }
193
184
  // Nothing from cache, let's try to resolve it first from lwc then from npm
194
185
  if (!moduleEntry) {
@@ -200,7 +191,6 @@ export default class LwcModuleProvider {
200
191
  baseSpecifier,
201
192
  importer,
202
193
  rootDir: this.rootDir,
203
- modules: this.modules,
204
194
  },
205
195
  });
206
196
  const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
@@ -252,13 +242,28 @@ export default class LwcModuleProvider {
252
242
  const cacheKey = getModuleEntryCacheKey(specifier, moduleEntry.version);
253
243
  const finalModuleEntry = { ...moduleEntry, id: cacheKey };
254
244
  this.moduleEntryVersionCache.set(cacheKey, finalModuleEntry);
255
- if (!version && importer) {
245
+ if (!version) {
256
246
  // if this module is being resolved via importer rather than version,
257
247
  // then use the importer as part of the cache key to avoid future cache misses
258
- const importerCacheKey = getModuleEntryCacheKey(specifier, importer);
259
- this.moduleEntryVersionCache.set(importerCacheKey, finalModuleEntry);
248
+ const importerCacheKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
249
+ this.importerMappingCache.set(importerCacheKey, cacheKey);
260
250
  }
261
251
  return finalModuleEntry;
262
252
  }
253
+ getCachedModuleEntry(specifier, version, importer) {
254
+ let moduleEntry;
255
+ if (version) {
256
+ const cacheKey = getModuleEntryCacheKey(specifier, version);
257
+ moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
258
+ }
259
+ if (!moduleEntry) {
260
+ const importerKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
261
+ const cacheKey = this.importerMappingCache.get(importerKey);
262
+ if (cacheKey) {
263
+ moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
264
+ }
265
+ }
266
+ return moduleEntry;
267
+ }
263
268
  }
264
269
  //# sourceMappingURL=index.js.map
package/build/es/utils.js CHANGED
@@ -9,7 +9,7 @@ export function resolveModuleSpecifier(specifier, importer, modules = [], packag
9
9
  logger.debug({
10
10
  label: `lwc-module-provider`,
11
11
  message: 'resolveModuleSpecifier',
12
- additionalInfo: { specifier, importer, modules },
12
+ additionalInfo: { specifier, importer },
13
13
  });
14
14
  let resolvedModule;
15
15
  try {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.1",
7
+ "version": "0.12.0-alpha.3",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -31,12 +31,13 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/preset-typescript": "^7.23.3",
34
- "@lwrjs/diagnostics": "0.12.0-alpha.1",
35
- "@lwrjs/fs-watch": "0.12.0-alpha.1",
36
- "@lwrjs/shared-utils": "0.12.0-alpha.1"
34
+ "@lwrjs/diagnostics": "0.12.0-alpha.3",
35
+ "@lwrjs/fs-watch": "0.12.0-alpha.3",
36
+ "@lwrjs/shared-utils": "0.12.0-alpha.3",
37
+ "fs-extra": "^11.1.1"
37
38
  },
38
39
  "devDependencies": {
39
- "@lwrjs/types": "0.12.0-alpha.1",
40
+ "@lwrjs/types": "0.12.0-alpha.3",
40
41
  "typescript": "^4.9.5"
41
42
  },
42
43
  "peerDependencies": {
@@ -44,7 +45,7 @@
44
45
  "@lwc/module-resolver": ">= 2.x"
45
46
  },
46
47
  "engines": {
47
- "node": ">=16.0.0"
48
+ "node": ">=18.0.0"
48
49
  },
49
- "gitHead": "138cc3716e923d0367e8279aaf2d6be21e74f440"
50
+ "gitHead": "48f97b40cbacce6cd6a6faee9206a465832c6774"
50
51
  }