@lwrjs/lwc-module-provider 0.9.0-alpha.8 → 0.9.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.
@@ -82,17 +82,11 @@ var LwcCompiler = class {
82
82
  experimentalDynamicComponent: {
83
83
  strictSpecifier: false
84
84
  },
85
- scopedStyles
85
+ scopedStyles,
86
+ enableScopedSlots: true
86
87
  };
87
88
  import_shared_utils.logger.debug("transformSync", {filename, transformConfig});
88
- const compilerResult = (0, import_compiler.transformSync)(source, filename, {
89
- namespace,
90
- name,
91
- experimentalDynamicComponent: {
92
- strictSpecifier: false
93
- },
94
- scopedStyles
95
- });
89
+ const compilerResult = (0, import_compiler.transformSync)(source, filename, transformConfig);
96
90
  import_shared_utils.logger.verbose("transformSync result", {compilerResult});
97
91
  return {
98
92
  code: compilerResult.code,
@@ -38,7 +38,8 @@ var LwcModuleProvider = class {
38
38
  constructor(options = {}, {
39
39
  appEmitter,
40
40
  config: {modules, rootDir, cacheDir, environment},
41
- runtimeEnvironment: {watchFiles}
41
+ runtimeEnvironment: {watchFiles},
42
+ watcherFactory
42
43
  }) {
43
44
  this.name = "lwc-module-provider";
44
45
  this.moduleSourceCache = new Map();
@@ -52,7 +53,7 @@ var LwcModuleProvider = class {
52
53
  this.emitter = appEmitter;
53
54
  this.modules = modules;
54
55
  this.rootDir = rootDir;
55
- this.watcher = watchFiles ? (0, import_utils.setUpWatcher)(this.onModuleChange.bind(this)) : void 0;
56
+ this.watcher = watchFiles && watcherFactory ? (0, import_utils.setUpWatcher)(watcherFactory, this.onModuleChange.bind(this)) : void 0;
56
57
  this.moduleFsCacheEnabled = disableCaching !== void 0 ? !disableCaching : true;
57
58
  this.interchangeableModulesEnabled = !!environment?.default;
58
59
  if (this.moduleFsCacheEnabled) {
@@ -75,13 +76,14 @@ var LwcModuleProvider = class {
75
76
  }
76
77
  async getModule(moduleId) {
77
78
  const id = (0, import_shared_utils.getSpecifier)(moduleId);
79
+ import_shared_utils.logger.debug(`[lwc-module-provider ] getModule ${id}`);
78
80
  return this.inflightGetModuleJobs.execute(id, () => {
79
81
  return this.createGetModuleJob(moduleId);
80
82
  });
81
83
  }
82
84
  async createGetModuleJob(moduleId) {
83
85
  const {watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled} = this;
84
- import_shared_utils.logger.debug("createGetModuleJob", {moduleId});
86
+ import_shared_utils.logger.debug("[lwc-module-provider ] fetch module", {moduleId, moduleFsCacheEnabled});
85
87
  const moduleEntry = await this.getModuleEntry(moduleId);
86
88
  if (!moduleEntry) {
87
89
  return;
@@ -90,10 +92,14 @@ var LwcModuleProvider = class {
90
92
  const {id, namespace, name: rawName, originalSource} = moduleSource;
91
93
  const cacheConfig = {lwcCacheDir, lwcCacheIndex};
92
94
  let compiledModule = moduleFsCacheEnabled && (0, import_cache.getCompiledModuleCacheEntry)(moduleSource, cacheConfig);
95
+ import_shared_utils.logger.debug("[lwc-module-provider ] module source ", {
96
+ moduleId,
97
+ isPreCompiled: compiledModule != void 0
98
+ });
93
99
  if (!compiledModule) {
94
100
  const [name] = rawName.split("#");
95
101
  const scopedStyles = moduleEntry.entry.endsWith(".css") && moduleEntry.specifier.endsWith("?scoped=true");
96
- import_shared_utils.logger.debug("createGetModuleJob:compile", {
102
+ import_shared_utils.logger.debug("[lwc-module-provider] compile", {
97
103
  namespace,
98
104
  name,
99
105
  filename: moduleEntry.entry,
@@ -105,7 +111,7 @@ var LwcModuleProvider = class {
105
111
  filename: moduleEntry.entry,
106
112
  scopedStyles
107
113
  });
108
- import_shared_utils.logger.verbose("createGetModuleJob:compile compiledModule", {
114
+ import_shared_utils.logger.verbose("[lwc-module-provider] createGetModuleJob:compile compiledModule", {
109
115
  namespace,
110
116
  name,
111
117
  filename: moduleEntry.entry,
@@ -152,7 +158,7 @@ var LwcModuleProvider = class {
152
158
  importer,
153
159
  version
154
160
  }) {
155
- import_shared_utils.logger.debug("getModuleEntry", {specifier, importer, version});
161
+ import_shared_utils.logger.debug(`[lwc-module-provider] getModuleEntry ${specifier}@${version}@${importer}`);
156
162
  const versionId = version || importer;
157
163
  if (versionId) {
158
164
  const cacheKey2 = getModuleEntryCacheKey(specifier, versionId);
@@ -161,7 +167,6 @@ var LwcModuleProvider = class {
161
167
  }
162
168
  }
163
169
  const cacheKey = `${specifier}@${version}@${importer}`;
164
- import_shared_utils.logger.debug("getModuleEntry:cacheKey", {cacheKey});
165
170
  return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
166
171
  return this.createModuleEntry({specifier, importer, version});
167
172
  });
@@ -171,7 +176,12 @@ var LwcModuleProvider = class {
171
176
  importer,
172
177
  version
173
178
  }) {
174
- import_shared_utils.logger.debug("createModuleEntry", {specifier, importer, rootDir: this.rootDir, version});
179
+ import_shared_utils.logger.debug("[lwc-module-provider] createModuleEntry", {
180
+ specifier,
181
+ importer,
182
+ rootDir: this.rootDir,
183
+ version
184
+ });
175
185
  const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
176
186
  const fileRelativePath = fileRelativePathRaw?.split("?")[0];
177
187
  let moduleEntry;
@@ -181,14 +191,14 @@ var LwcModuleProvider = class {
181
191
  }
182
192
  if (!moduleEntry) {
183
193
  try {
184
- import_shared_utils.logger.debug("createModuleEntry:resolveModuleSpecifier", {
194
+ import_shared_utils.logger.debug("[lwc-module-provider] createModuleEntry:resolveModuleSpecifier", {
185
195
  baseSpecifier,
186
196
  importer,
187
197
  rootDir: this.rootDir,
188
198
  modules: this.modules
189
199
  });
190
200
  const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
191
- import_shared_utils.logger.debug("createModuleEntry:registryEntry", {registryEntry});
201
+ import_shared_utils.logger.debug("[lwc-module-provider] createModuleEntry:registryEntry", {registryEntry});
192
202
  moduleEntry = {
193
203
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
194
204
  ...registryEntry
@@ -37,9 +37,18 @@ 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
39
  function resolveModuleSpecifier(specifier, importer, modules = [], packageVersionCache) {
40
- import_shared_utils.logger.debug("resolveModuleSpecifier", {specifier, importer, modules});
41
- const resolvedModule = (0, import_module_resolver.resolveModule)(specifier, importer, {modules});
42
- import_shared_utils.logger.debug("resolveModuleSpecifier:resolvedModule", {resolvedModule});
40
+ import_shared_utils.logger.debug("[lwc-module-provider] resolveModuleSpecifier", {specifier, importer, modules});
41
+ let resolvedModule;
42
+ try {
43
+ resolvedModule = (0, import_module_resolver.resolveModule)(specifier, importer, {modules});
44
+ } catch (error) {
45
+ if (import_shared_utils.logger.currentLevel == import_shared_utils.DEBUG || import_shared_utils.logger.currentLevel == import_shared_utils.VERBOSE) {
46
+ import_shared_utils.logger.debug(`[lwc-module-provider] @lwc/module-resolver/resolveModule ${specifier}`);
47
+ import_shared_utils.logger.error(error);
48
+ }
49
+ throw error;
50
+ }
51
+ import_shared_utils.logger.debug("[lwc-module-provider] resolveModuleSpecifier:resolvedModule", {resolvedModule});
43
52
  const moduleScope = resolvedModule.scope;
44
53
  let version;
45
54
  if (packageVersionCache.has(moduleScope)) {
@@ -79,8 +88,8 @@ function isImplicitLwcImport(entry, specifier) {
79
88
  }
80
89
  return true;
81
90
  }
82
- function setUpWatcher(onModuleChange) {
83
- const watcher = (0, import_shared_utils.createFileWatcher)();
91
+ function setUpWatcher(watcherFactory, onModuleChange) {
92
+ const watcher = watcherFactory.createFileWatcher();
84
93
  watcher.on("change", (0, import_shared_utils.debounce)((file) => onModuleChange(file), 500));
85
94
  watcher.on("unlink", (0, import_shared_utils.debounce)((file) => onModuleChange(file), 500));
86
95
  watcher.on("add", (file) => import_shared_utils.logger.info(`Watching: ${file}`));
@@ -1,8 +1,8 @@
1
- import type { CompilerConfig, CompilerResult } from '@lwrjs/types';
1
+ import type { CompilerResult, LwcCompilerConfig } from '@lwrjs/types';
2
2
  export interface BundleFiles {
3
3
  [filename: string]: string;
4
4
  }
5
5
  export declare class LwcCompiler {
6
- compileFile(source: string, config: CompilerConfig): Promise<CompilerResult>;
6
+ compileFile(source: string, config: LwcCompilerConfig): Promise<CompilerResult>;
7
7
  }
8
8
  //# sourceMappingURL=compiler.d.ts.map
@@ -58,16 +58,10 @@ export class LwcCompiler {
58
58
  strictSpecifier: false,
59
59
  },
60
60
  scopedStyles,
61
+ enableScopedSlots: true, // this flag turns on an additive feature and is backwards compatible
61
62
  };
62
63
  logger.debug('transformSync', { filename, transformConfig });
63
- const compilerResult = transformSync(source, filename, {
64
- namespace,
65
- name,
66
- experimentalDynamicComponent: {
67
- strictSpecifier: false,
68
- },
69
- scopedStyles,
70
- });
64
+ const compilerResult = transformSync(source, filename, transformConfig);
71
65
  logger.verbose('transformSync result', { compilerResult });
72
66
  return {
73
67
  code: compilerResult.code,
@@ -19,7 +19,7 @@ export default class LwcModuleProvider implements ModuleProvider {
19
19
  private lwcCompiler;
20
20
  private inflightGetModuleJobs;
21
21
  private inflightGetModuleEntryJobs;
22
- constructor(options: LwcModuleProviderOptions | undefined, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, }: ProviderContext);
22
+ constructor(options: LwcModuleProviderOptions | undefined, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }: ProviderContext);
23
23
  onModuleChange(fileChanged: string): Promise<void>;
24
24
  getModule(moduleId: AbstractModuleId): Promise<ModuleCompiled | undefined>;
25
25
  /**
package/build/es/index.js CHANGED
@@ -7,7 +7,7 @@ function getModuleEntryCacheKey(specifier, version) {
7
7
  return `${specifier}@${version}`;
8
8
  }
9
9
  export default class LwcModuleProvider {
10
- constructor(options = {}, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, }) {
10
+ constructor(options = {}, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, watcherFactory, }) {
11
11
  this.name = 'lwc-module-provider';
12
12
  this.moduleSourceCache = new Map();
13
13
  this.packageVersionCache = new Map();
@@ -20,7 +20,10 @@ export default class LwcModuleProvider {
20
20
  this.emitter = appEmitter;
21
21
  this.modules = modules;
22
22
  this.rootDir = rootDir;
23
- this.watcher = watchFiles ? setUpWatcher(this.onModuleChange.bind(this)) : undefined;
23
+ this.watcher =
24
+ watchFiles && watcherFactory
25
+ ? setUpWatcher(watcherFactory, this.onModuleChange.bind(this))
26
+ : undefined;
24
27
  this.moduleFsCacheEnabled = disableCaching !== undefined ? !disableCaching : true;
25
28
  this.interchangeableModulesEnabled = !!environment?.default;
26
29
  // Module Cache setup
@@ -44,6 +47,7 @@ export default class LwcModuleProvider {
44
47
  }
45
48
  async getModule(moduleId) {
46
49
  const id = getSpecifier(moduleId);
50
+ logger.debug(`[lwc-module-provider ] getModule ${id}`);
47
51
  return this.inflightGetModuleJobs.execute(id, () => {
48
52
  return this.createGetModuleJob(moduleId);
49
53
  });
@@ -55,7 +59,7 @@ export default class LwcModuleProvider {
55
59
  */
56
60
  async createGetModuleJob(moduleId) {
57
61
  const { watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled } = this;
58
- logger.debug('createGetModuleJob', { moduleId });
62
+ logger.debug('[lwc-module-provider ] fetch module', { moduleId, moduleFsCacheEnabled });
59
63
  const moduleEntry = await this.getModuleEntry(moduleId);
60
64
  if (!moduleEntry) {
61
65
  return;
@@ -64,10 +68,14 @@ export default class LwcModuleProvider {
64
68
  const { id, namespace, name: rawName, originalSource } = moduleSource;
65
69
  const cacheConfig = { lwcCacheDir, lwcCacheIndex };
66
70
  let compiledModule = moduleFsCacheEnabled && getCompiledModuleCacheEntry(moduleSource, cacheConfig);
71
+ logger.debug('[lwc-module-provider ] module source ', {
72
+ moduleId,
73
+ isPreCompiled: compiledModule != undefined,
74
+ });
67
75
  if (!compiledModule) {
68
76
  const [name] = rawName.split('#');
69
77
  const scopedStyles = moduleEntry.entry.endsWith('.css') && moduleEntry.specifier.endsWith('?scoped=true');
70
- logger.debug('createGetModuleJob:compile', {
78
+ logger.debug('[lwc-module-provider] compile', {
71
79
  namespace,
72
80
  name,
73
81
  filename: moduleEntry.entry,
@@ -80,7 +88,7 @@ export default class LwcModuleProvider {
80
88
  filename: moduleEntry.entry,
81
89
  scopedStyles,
82
90
  });
83
- logger.verbose('createGetModuleJob:compile compiledModule', {
91
+ logger.verbose('[lwc-module-provider] createGetModuleJob:compile compiledModule', {
84
92
  namespace,
85
93
  name,
86
94
  filename: moduleEntry.entry,
@@ -123,7 +131,7 @@ export default class LwcModuleProvider {
123
131
  return moduleSource;
124
132
  }
125
133
  async getModuleEntry({ specifier, importer, version, }) {
126
- logger.debug('getModuleEntry', { specifier, importer, version });
134
+ logger.debug(`[lwc-module-provider] getModuleEntry ${specifier}@${version}@${importer}`);
127
135
  // Check cache
128
136
  const versionId = version || importer;
129
137
  if (versionId) {
@@ -133,13 +141,17 @@ export default class LwcModuleProvider {
133
141
  }
134
142
  }
135
143
  const cacheKey = `${specifier}@${version}@${importer}`;
136
- logger.debug('getModuleEntry:cacheKey', { cacheKey });
137
144
  return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
138
145
  return this.createModuleEntry({ specifier, importer, version });
139
146
  });
140
147
  }
141
148
  async createModuleEntry({ specifier, importer, version, }) {
142
- logger.debug('createModuleEntry', { specifier, importer, rootDir: this.rootDir, version });
149
+ logger.debug('[lwc-module-provider] createModuleEntry', {
150
+ specifier,
151
+ importer,
152
+ rootDir: this.rootDir,
153
+ version,
154
+ });
143
155
  // Strip any filenames out of the specifier
144
156
  // eg: 'c/myApp#myApp.css' => 'c/myApp' and 'myApp.css'
145
157
  // eg: 'some/where#lib/util' => 'some/where' and 'lib/util'
@@ -154,14 +166,14 @@ export default class LwcModuleProvider {
154
166
  // Nothing from cache, let's try to resolve it first from lwc then from npm
155
167
  if (!moduleEntry) {
156
168
  try {
157
- logger.debug('createModuleEntry:resolveModuleSpecifier', {
169
+ logger.debug('[lwc-module-provider] createModuleEntry:resolveModuleSpecifier', {
158
170
  baseSpecifier,
159
171
  importer,
160
172
  rootDir: this.rootDir,
161
173
  modules: this.modules,
162
174
  });
163
175
  const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
164
- logger.debug('createModuleEntry:registryEntry', { registryEntry });
176
+ logger.debug('[lwc-module-provider] createModuleEntry:registryEntry', { registryEntry });
165
177
  moduleEntry = {
166
178
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
167
179
  ...registryEntry,
@@ -1,8 +1,8 @@
1
- import { ResolverModuleRecord, Watcher } from '@lwrjs/types';
1
+ import type { ResolverModuleRecord, Watcher, WatcherFactory } 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
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
- export declare function setUpWatcher(onModuleChange: Function): Watcher;
7
+ export declare function setUpWatcher(watcherFactory: WatcherFactory, onModuleChange: Function): Watcher;
8
8
  //# sourceMappingURL=utils.d.ts.map
package/build/es/utils.js CHANGED
@@ -1,13 +1,24 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { readFile, debounce, createFileWatcher, logger } from '@lwrjs/shared-utils';
3
+ import { readFile, debounce, logger, DEBUG, VERBOSE } from '@lwrjs/shared-utils';
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
7
  export function resolveModuleSpecifier(specifier, importer, modules = [], packageVersionCache) {
8
- logger.debug('resolveModuleSpecifier', { specifier, importer, modules });
9
- const resolvedModule = resolveModule(specifier, importer, { modules });
10
- logger.debug('resolveModuleSpecifier:resolvedModule', { resolvedModule });
8
+ logger.debug('[lwc-module-provider] resolveModuleSpecifier', { specifier, importer, modules });
9
+ let resolvedModule;
10
+ try {
11
+ resolvedModule = resolveModule(specifier, importer, { modules });
12
+ }
13
+ catch (error) {
14
+ if (logger.currentLevel == DEBUG || logger.currentLevel == VERBOSE) {
15
+ // If log level is debug or greater. Otherwise error will be swalloed and resolved by npm-resolver
16
+ logger.debug(`[lwc-module-provider] @lwc/module-resolver/resolveModule ${specifier}`);
17
+ logger.error(error);
18
+ }
19
+ throw error;
20
+ }
21
+ logger.debug('[lwc-module-provider] resolveModuleSpecifier:resolvedModule', { resolvedModule });
11
22
  const moduleScope = resolvedModule.scope;
12
23
  let version;
13
24
  if (packageVersionCache.has(moduleScope)) {
@@ -61,8 +72,8 @@ export function isImplicitLwcImport(entry, specifier) {
61
72
  }
62
73
  return true;
63
74
  }
64
- export function setUpWatcher(onModuleChange) {
65
- const watcher = createFileWatcher();
75
+ export function setUpWatcher(watcherFactory, onModuleChange) {
76
+ const watcher = watcherFactory.createFileWatcher();
66
77
  watcher.on('change', debounce((file) => onModuleChange(file), 500));
67
78
  watcher.on('unlink', debounce((file) => onModuleChange(file), 500));
68
79
  watcher.on('add', (file) => logger.info(`Watching: ${file}`));
package/package.json CHANGED
@@ -4,15 +4,15 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.8",
7
+ "version": "0.9.0",
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/fs-service"
13
13
  },
14
14
  "bugs": {
15
- "url": "https://github.com/salesforce/lwr/issues"
15
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
16
16
  },
17
17
  "type": "module",
18
18
  "types": "build/es/index.d.ts",
@@ -31,15 +31,15 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/preset-typescript": "^7.9.0",
34
- "@lwc/module-resolver": "2.17.0",
35
- "@lwrjs/shared-utils": "0.9.0-alpha.8",
34
+ "@lwc/module-resolver": "2.38.1",
35
+ "@lwrjs/shared-utils": "0.9.0",
36
36
  "es-module-lexer": "^0.3.18"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.9.0-alpha.8"
39
+ "@lwrjs/types": "0.9.0"
40
40
  },
41
41
  "engines": {
42
- "node": ">=14.15.4 <19"
42
+ "node": ">=16.0.0 <20"
43
43
  },
44
- "gitHead": "013fcee240ff2e1c23ef304e70fc39d6ef13fb8b"
44
+ "gitHead": "4e42b0dc5453f92b36b42aa8132c5bc281e616b7"
45
45
  }