@lwrjs/lwc-module-provider 0.8.0-alpha.0 → 0.8.0-alpha.10

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.
@@ -29,6 +29,7 @@ __export(exports, {
29
29
  var import_core = __toModule(require("@babel/core"));
30
30
  var import_compiler = __toModule(require("@lwc/compiler"));
31
31
  var import_utils = __toModule(require("./utils.cjs"));
32
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
33
  var DEFAULT_BABEL_CONFIG = {
33
34
  babelrc: false,
34
35
  configFile: false,
@@ -48,12 +49,22 @@ var LwcCompiler = class {
48
49
  };
49
50
  }
50
51
  if (filename.endsWith("ts")) {
51
- const result = (0, import_core.transformSync)(source, {
52
+ const babelConfig = {
52
53
  ...DEFAULT_BABEL_CONFIG,
53
54
  presets: [["@babel/preset-typescript", {onlyRemoveTypeImports: false}]],
54
55
  filename
55
- });
56
+ };
57
+ import_shared_utils.logger.debug("babelTransform", {babelConfig});
58
+ let result;
59
+ try {
60
+ result = (0, import_core.transformSync)(source, babelConfig);
61
+ } catch (error) {
62
+ import_shared_utils.logger.debug("babelTransform error", error);
63
+ throw error;
64
+ }
65
+ import_shared_utils.logger.verbose("babelTransform result", {result});
56
66
  if (!result || !result.code) {
67
+ import_shared_utils.logger.debug("babelTransform invalid result", {result});
57
68
  throw new Error(`Error TS compiling ${filename}`);
58
69
  }
59
70
  source = result.code;
@@ -65,6 +76,15 @@ var LwcCompiler = class {
65
76
  metadata: {}
66
77
  };
67
78
  }
79
+ const transformConfig = {
80
+ namespace,
81
+ name,
82
+ experimentalDynamicComponent: {
83
+ strictSpecifier: false
84
+ },
85
+ scopedStyles
86
+ };
87
+ import_shared_utils.logger.debug("transformSync", {filename, transformConfig});
68
88
  const compilerResult = (0, import_compiler.transformSync)(source, filename, {
69
89
  namespace,
70
90
  name,
@@ -73,6 +93,7 @@ var LwcCompiler = class {
73
93
  },
74
94
  scopedStyles
75
95
  });
96
+ import_shared_utils.logger.verbose("transformSync result", {compilerResult});
76
97
  return {
77
98
  code: compilerResult.code,
78
99
  map: null,
@@ -76,10 +76,11 @@ var LwcModuleProvider = class {
76
76
  const id = (0, import_shared_utils.getSpecifier)(moduleId);
77
77
  return this.inflightGetModuleJobs.execute(id, () => {
78
78
  return this.createGetModuleJob(moduleId);
79
- }, this);
79
+ });
80
80
  }
81
81
  async createGetModuleJob(moduleId) {
82
82
  const {watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled} = this;
83
+ import_shared_utils.logger.debug("createGetModuleJob", {moduleId});
83
84
  const moduleEntry = await this.getModuleEntry(moduleId);
84
85
  if (!moduleEntry) {
85
86
  return;
@@ -91,12 +92,24 @@ var LwcModuleProvider = class {
91
92
  if (!compiledModule) {
92
93
  const [name] = rawName.split("#");
93
94
  const scopedStyles = moduleEntry.entry.endsWith(".css") && moduleEntry.specifier.endsWith("?scoped=true");
95
+ import_shared_utils.logger.debug("createGetModuleJob:compile", {
96
+ namespace,
97
+ name,
98
+ filename: moduleEntry.entry,
99
+ scopedStyles
100
+ });
94
101
  compiledModule = await this.lwcCompiler.compileFile(originalSource, {
95
102
  namespace,
96
103
  name,
97
104
  filename: moduleEntry.entry,
98
105
  scopedStyles
99
106
  });
107
+ import_shared_utils.logger.verbose("createGetModuleJob:compile compiledModule", {
108
+ namespace,
109
+ name,
110
+ filename: moduleEntry.entry,
111
+ scopedStyles
112
+ });
100
113
  if (moduleFsCacheEnabled) {
101
114
  (0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
102
115
  }
@@ -138,6 +151,7 @@ var LwcModuleProvider = class {
138
151
  importer,
139
152
  version
140
153
  }) {
154
+ import_shared_utils.logger.debug("getModuleEntry", {specifier, importer, version});
141
155
  const versionId = version || importer;
142
156
  if (versionId) {
143
157
  const cacheKey2 = getModuleEntryCacheKey(specifier, versionId);
@@ -146,6 +160,7 @@ var LwcModuleProvider = class {
146
160
  }
147
161
  }
148
162
  const cacheKey = `${specifier}@${version}@${importer}`;
163
+ import_shared_utils.logger.debug("getModuleEntry:cacheKey", {cacheKey});
149
164
  return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
150
165
  return this.createModuleEntry({specifier, importer, version});
151
166
  });
@@ -155,6 +170,7 @@ var LwcModuleProvider = class {
155
170
  importer,
156
171
  version
157
172
  }) {
173
+ import_shared_utils.logger.debug("createModuleEntry", {specifier, importer, rootDir: this.rootDir, version});
158
174
  const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
159
175
  const fileRelativePath = fileRelativePathRaw?.split("?")[0];
160
176
  let moduleEntry;
@@ -164,7 +180,14 @@ var LwcModuleProvider = class {
164
180
  }
165
181
  if (!moduleEntry) {
166
182
  try {
183
+ import_shared_utils.logger.debug("createModuleEntry:resolveModuleSpecifier", {
184
+ baseSpecifier,
185
+ importer,
186
+ rootDir: this.rootDir,
187
+ modules: this.modules
188
+ });
167
189
  const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules);
190
+ import_shared_utils.logger.debug("createModuleEntry:registryEntry", {registryEntry});
168
191
  moduleEntry = {
169
192
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
170
193
  ...registryEntry
@@ -178,6 +201,8 @@ var LwcModuleProvider = class {
178
201
  } catch (e) {
179
202
  if (e.code !== "NO_LWC_MODULE_FOUND") {
180
203
  throw e;
204
+ } else {
205
+ import_shared_utils.logger.verbose(`LWC provider could not find the module ${specifier}`);
181
206
  }
182
207
  }
183
208
  }
@@ -37,7 +37,9 @@ 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 = []) {
40
+ import_shared_utils.logger.debug("resolveModuleSpecifier", {specifier, importer, modules});
40
41
  const resolvedModule = (0, import_module_resolver.resolveModule)(specifier, importer, {modules});
42
+ import_shared_utils.logger.debug("resolveModuleSpecifier:resolvedModule", {resolvedModule});
41
43
  const json = (0, import_shared_utils.readFile)(import_path.default.join(resolvedModule.scope, "package.json"));
42
44
  const version = JSON.parse(json).version;
43
45
  return {...resolvedModule, version};
@@ -1,4 +1,4 @@
1
- import { CompilerConfig, CompilerResult } from '@lwrjs/types';
1
+ import type { CompilerConfig, CompilerResult } from '@lwrjs/types';
2
2
  export interface BundleFiles {
3
3
  [filename: string]: string;
4
4
  }
@@ -1,6 +1,7 @@
1
1
  import { transformSync as babelTransform } from '@babel/core';
2
2
  import { transformSync } from '@lwc/compiler';
3
3
  import { EXPLICIT_CONSTANT } from './utils.js';
4
+ import { logger } from '@lwrjs/shared-utils';
4
5
  const DEFAULT_BABEL_CONFIG = {
5
6
  babelrc: false,
6
7
  configFile: false,
@@ -21,12 +22,23 @@ export class LwcCompiler {
21
22
  };
22
23
  }
23
24
  if (filename.endsWith('ts')) {
24
- const result = babelTransform(source, {
25
+ const babelConfig = {
25
26
  ...DEFAULT_BABEL_CONFIG,
26
27
  presets: [['@babel/preset-typescript', { onlyRemoveTypeImports: false }]],
27
28
  filename,
28
- });
29
+ };
30
+ logger.debug('babelTransform', { babelConfig });
31
+ let result;
32
+ try {
33
+ result = babelTransform(source, babelConfig);
34
+ }
35
+ catch (error) {
36
+ logger.debug('babelTransform error', error);
37
+ throw error;
38
+ }
39
+ logger.verbose('babelTransform result', { result });
29
40
  if (!result || !result.code) {
41
+ logger.debug('babelTransform invalid result', { result });
30
42
  throw new Error(`Error TS compiling ${filename}`);
31
43
  }
32
44
  source = result.code;
@@ -39,6 +51,15 @@ export class LwcCompiler {
39
51
  metadata: {},
40
52
  };
41
53
  }
54
+ const transformConfig = {
55
+ namespace,
56
+ name,
57
+ experimentalDynamicComponent: {
58
+ strictSpecifier: false,
59
+ },
60
+ scopedStyles,
61
+ };
62
+ logger.debug('transformSync', { filename, transformConfig });
42
63
  const compilerResult = transformSync(source, filename, {
43
64
  namespace,
44
65
  name,
@@ -47,6 +68,7 @@ export class LwcCompiler {
47
68
  },
48
69
  scopedStyles,
49
70
  });
71
+ logger.verbose('transformSync result', { compilerResult });
50
72
  return {
51
73
  code: compilerResult.code,
52
74
  map: null,
package/build/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { dirname, join } from 'path';
2
- import { explodeSpecifier, getSpecifier, hashContent, InflightTasks, readFile, resolveFileExtension, resolveCustomLWCMetadata, } from '@lwrjs/shared-utils';
2
+ import { explodeSpecifier, getSpecifier, hashContent, InflightTasks, logger, readFile, resolveFileExtension, resolveCustomLWCMetadata, } from '@lwrjs/shared-utils';
3
3
  import { DEFAULT_IMPLICIT_DEP, isImplicitLwcImport, resolveModuleSpecifier, setUpWatcher } from './utils.js';
4
4
  import { addCompiledModuleCacheEntry, getCompiledModuleCacheEntry, setupModuleCache, } from './cache.js';
5
5
  import { LwcCompiler } from './compiler.js';
@@ -45,7 +45,7 @@ export default class LwcModuleProvider {
45
45
  const id = getSpecifier(moduleId);
46
46
  return this.inflightGetModuleJobs.execute(id, () => {
47
47
  return this.createGetModuleJob(moduleId);
48
- }, this);
48
+ });
49
49
  }
50
50
  /**
51
51
  * Create a new Job to fetch a module by id so we are not duplicating effort when multiple requests come in
@@ -54,6 +54,7 @@ export default class LwcModuleProvider {
54
54
  */
55
55
  async createGetModuleJob(moduleId) {
56
56
  const { watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled } = this;
57
+ logger.debug('createGetModuleJob', { moduleId });
57
58
  const moduleEntry = await this.getModuleEntry(moduleId);
58
59
  if (!moduleEntry) {
59
60
  return;
@@ -65,6 +66,12 @@ export default class LwcModuleProvider {
65
66
  if (!compiledModule) {
66
67
  const [name] = rawName.split('#');
67
68
  const scopedStyles = moduleEntry.entry.endsWith('.css') && moduleEntry.specifier.endsWith('?scoped=true');
69
+ logger.debug('createGetModuleJob:compile', {
70
+ namespace,
71
+ name,
72
+ filename: moduleEntry.entry,
73
+ scopedStyles,
74
+ });
68
75
  // We need to convert anything (html, css, javascript) into a canonical ES6 module
69
76
  compiledModule = await this.lwcCompiler.compileFile(originalSource, {
70
77
  namespace,
@@ -72,6 +79,12 @@ export default class LwcModuleProvider {
72
79
  filename: moduleEntry.entry,
73
80
  scopedStyles,
74
81
  });
82
+ logger.verbose('createGetModuleJob:compile compiledModule', {
83
+ namespace,
84
+ name,
85
+ filename: moduleEntry.entry,
86
+ scopedStyles,
87
+ });
75
88
  if (moduleFsCacheEnabled) {
76
89
  addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
77
90
  }
@@ -109,6 +122,7 @@ export default class LwcModuleProvider {
109
122
  return moduleSource;
110
123
  }
111
124
  async getModuleEntry({ specifier, importer, version, }) {
125
+ logger.debug('getModuleEntry', { specifier, importer, version });
112
126
  // Check cache
113
127
  const versionId = version || importer;
114
128
  if (versionId) {
@@ -118,11 +132,13 @@ export default class LwcModuleProvider {
118
132
  }
119
133
  }
120
134
  const cacheKey = `${specifier}@${version}@${importer}`;
135
+ logger.debug('getModuleEntry:cacheKey', { cacheKey });
121
136
  return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
122
137
  return this.createModuleEntry({ specifier, importer, version });
123
138
  });
124
139
  }
125
140
  async createModuleEntry({ specifier, importer, version, }) {
141
+ logger.debug('createModuleEntry', { specifier, importer, rootDir: this.rootDir, version });
126
142
  // Strip any filenames out of the specifier
127
143
  // eg: 'c/myApp#myApp.css' => 'c/myApp' and 'myApp.css'
128
144
  // eg: 'some/where#lib/util' => 'some/where' and 'lib/util'
@@ -137,7 +153,14 @@ export default class LwcModuleProvider {
137
153
  // Nothing from cache, let's try to resolve it first from lwc then from npm
138
154
  if (!moduleEntry) {
139
155
  try {
156
+ logger.debug('createModuleEntry:resolveModuleSpecifier', {
157
+ baseSpecifier,
158
+ importer,
159
+ rootDir: this.rootDir,
160
+ modules: this.modules,
161
+ });
140
162
  const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules);
163
+ logger.debug('createModuleEntry:registryEntry', { registryEntry });
141
164
  moduleEntry = {
142
165
  id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
143
166
  ...registryEntry,
@@ -154,6 +177,10 @@ export default class LwcModuleProvider {
154
177
  if (e.code !== 'NO_LWC_MODULE_FOUND') {
155
178
  throw e;
156
179
  }
180
+ else {
181
+ // in verbose log the lwc provider miss
182
+ logger.verbose(`LWC provider could not find the module ${specifier}`);
183
+ }
157
184
  }
158
185
  }
159
186
  if (!moduleEntry) {
package/build/es/utils.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { readFile, debounce, createFileWatcher } from '@lwrjs/shared-utils';
3
+ import { readFile, debounce, createFileWatcher, logger } 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 = []) {
8
+ logger.debug('resolveModuleSpecifier', { specifier, importer, modules });
8
9
  const resolvedModule = resolveModule(specifier, importer, { modules });
10
+ logger.debug('resolveModuleSpecifier:resolvedModule', { resolvedModule });
9
11
  const json = readFile(path.join(resolvedModule.scope, 'package.json'));
10
12
  const version = JSON.parse(json).version;
11
13
  return { ...resolvedModule, version };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.0",
7
+ "version": "0.8.0-alpha.10",
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-alpha.0",
35
+ "@lwrjs/shared-utils": "0.8.0-alpha.10",
36
36
  "es-module-lexer": "^0.3.18"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.8.0-alpha.0"
39
+ "@lwrjs/types": "0.8.0-alpha.10"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14.15.4 <19"
43
43
  },
44
- "gitHead": "2e1f60ed13f9f8079f1333af9b614cd24715f3ad"
44
+ "gitHead": "55922351f484d77784d86ef7b03ebe788fa3e12c"
45
45
  }