@lwrjs/lwc-module-provider 0.8.0 → 0.8.2

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.
@@ -42,6 +42,7 @@ var LwcModuleProvider = class {
42
42
  }) {
43
43
  this.name = "lwc-module-provider";
44
44
  this.moduleSourceCache = new Map();
45
+ this.packageVersionCache = new Map();
45
46
  this.watchedModuleContextMap = new Map();
46
47
  this.moduleEntryVersionCache = new Map();
47
48
  this.lwcCompiler = new import_compiler.LwcCompiler();
@@ -186,7 +187,7 @@ var LwcModuleProvider = class {
186
187
  rootDir: this.rootDir,
187
188
  modules: this.modules
188
189
  });
189
- const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules);
190
+ const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
190
191
  import_shared_utils.logger.debug("createModuleEntry:registryEntry", {registryEntry});
191
192
  moduleEntry = {
192
193
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
@@ -36,12 +36,19 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
36
36
  var import_module_resolver = __toModule(require("@lwc/module-resolver"));
37
37
  var EXPLICIT_CONSTANT = "/* _implicit_dependency_ */";
38
38
  var DEFAULT_IMPLICIT_DEP = `${EXPLICIT_CONSTANT} export default void 0`;
39
- function resolveModuleSpecifier(specifier, importer, modules = []) {
39
+ function resolveModuleSpecifier(specifier, importer, modules = [], packageVersionCache) {
40
40
  import_shared_utils.logger.debug("resolveModuleSpecifier", {specifier, importer, modules});
41
41
  const resolvedModule = (0, import_module_resolver.resolveModule)(specifier, importer, {modules});
42
42
  import_shared_utils.logger.debug("resolveModuleSpecifier:resolvedModule", {resolvedModule});
43
- const json = (0, import_shared_utils.readFile)(import_path.default.join(resolvedModule.scope, "package.json"));
44
- const version = JSON.parse(json).version;
43
+ const moduleScope = resolvedModule.scope;
44
+ let version;
45
+ if (packageVersionCache.has(moduleScope)) {
46
+ version = packageVersionCache.get(moduleScope);
47
+ } else {
48
+ const json = (0, import_shared_utils.readFile)(import_path.default.join(moduleScope, "package.json"));
49
+ version = JSON.parse(json).version;
50
+ packageVersionCache.set(moduleScope, version);
51
+ }
45
52
  return {...resolvedModule, version};
46
53
  }
47
54
  function isImplicitLwcImport(entry, specifier) {
@@ -10,6 +10,7 @@ export default class LwcModuleProvider implements ModuleProvider {
10
10
  private lwcCacheDir?;
11
11
  private lwcCacheIndex?;
12
12
  private moduleSourceCache;
13
+ private packageVersionCache;
13
14
  private modules;
14
15
  private emitter;
15
16
  private watcher?;
package/build/es/index.js CHANGED
@@ -10,6 +10,7 @@ export default class LwcModuleProvider {
10
10
  constructor(options = {}, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, }) {
11
11
  this.name = 'lwc-module-provider';
12
12
  this.moduleSourceCache = new Map();
13
+ this.packageVersionCache = new Map();
13
14
  this.watchedModuleContextMap = new Map();
14
15
  this.moduleEntryVersionCache = new Map();
15
16
  this.lwcCompiler = new LwcCompiler();
@@ -159,7 +160,7 @@ export default class LwcModuleProvider {
159
160
  rootDir: this.rootDir,
160
161
  modules: this.modules,
161
162
  });
162
- const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules);
163
+ const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
163
164
  logger.debug('createModuleEntry:registryEntry', { registryEntry });
164
165
  moduleEntry = {
165
166
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
@@ -2,7 +2,7 @@ import { ResolverModuleRecord, Watcher } from '@lwrjs/types';
2
2
  import { RegistryEntry } from '@lwc/module-resolver';
3
3
  export declare const EXPLICIT_CONSTANT = "/* _implicit_dependency_ */";
4
4
  export declare const DEFAULT_IMPLICIT_DEP: string;
5
- export declare function resolveModuleSpecifier(specifier: string, importer: string, modules?: ResolverModuleRecord[]): Required<RegistryEntry>;
5
+ export declare function resolveModuleSpecifier(specifier: string, importer: string, modules: ResolverModuleRecord[] | undefined, packageVersionCache: Map<string, string>): Required<RegistryEntry>;
6
6
  export declare function isImplicitLwcImport(entry: string, specifier: string): boolean;
7
7
  export declare function setUpWatcher(onModuleChange: Function): Watcher;
8
8
  //# sourceMappingURL=utils.d.ts.map
package/build/es/utils.js CHANGED
@@ -4,12 +4,20 @@ import { readFile, debounce, createFileWatcher, logger } from '@lwrjs/shared-uti
4
4
  import { resolveModule } from '@lwc/module-resolver';
5
5
  export const EXPLICIT_CONSTANT = '/* _implicit_dependency_ */';
6
6
  export const DEFAULT_IMPLICIT_DEP = `${EXPLICIT_CONSTANT} export default void 0`;
7
- export function resolveModuleSpecifier(specifier, importer, modules = []) {
7
+ export function resolveModuleSpecifier(specifier, importer, modules = [], packageVersionCache) {
8
8
  logger.debug('resolveModuleSpecifier', { specifier, importer, modules });
9
9
  const resolvedModule = resolveModule(specifier, importer, { modules });
10
10
  logger.debug('resolveModuleSpecifier:resolvedModule', { resolvedModule });
11
- const json = readFile(path.join(resolvedModule.scope, 'package.json'));
12
- const version = JSON.parse(json).version;
11
+ const moduleScope = resolvedModule.scope;
12
+ let version;
13
+ if (packageVersionCache.has(moduleScope)) {
14
+ version = packageVersionCache.get(moduleScope);
15
+ }
16
+ else {
17
+ const json = readFile(path.join(moduleScope, 'package.json'));
18
+ version = JSON.parse(json).version;
19
+ packageVersionCache.set(moduleScope, version);
20
+ }
13
21
  return { ...resolvedModule, version };
14
22
  }
15
23
  // An implicit import is dependency that the LWC includes automatically to "auto-magically" bind JS, HTML and CSS
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0",
7
+ "version": "0.8.2",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -32,14 +32,14 @@
32
32
  "dependencies": {
33
33
  "@babel/preset-typescript": "^7.9.0",
34
34
  "@lwc/module-resolver": "2.17.0",
35
- "@lwrjs/shared-utils": "0.8.0",
35
+ "@lwrjs/shared-utils": "0.8.2",
36
36
  "es-module-lexer": "^0.3.18"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.8.0"
39
+ "@lwrjs/types": "0.8.2"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14.15.4 <19"
43
43
  },
44
- "gitHead": "6db460e470fb149ca282aaa293ad4f0be03ae4e8"
44
+ "gitHead": "82ba0843aee466db97ddc253cd28401d0e6ed8fc"
45
45
  }