@lwrjs/lwc-module-provider 0.8.0-alpha.3 → 0.8.0-alpha.6
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.
- package/build/cjs/compiler.cjs +23 -2
- package/build/cjs/index.cjs +31 -2
- package/build/cjs/utils.cjs +2 -0
- package/build/es/compiler.d.ts +1 -1
- package/build/es/compiler.js +24 -2
- package/build/es/index.js +34 -3
- package/build/es/utils.js +3 -1
- package/package.json +4 -4
package/build/cjs/compiler.cjs
CHANGED
|
@@ -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
|
|
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,
|
package/build/cjs/index.cjs
CHANGED
|
@@ -74,10 +74,13 @@ var LwcModuleProvider = class {
|
|
|
74
74
|
}
|
|
75
75
|
async getModule(moduleId) {
|
|
76
76
|
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
77
|
-
return this.inflightGetModuleJobs.execute(id, () =>
|
|
77
|
+
return this.inflightGetModuleJobs.execute(id, () => {
|
|
78
|
+
return this.createGetModuleJob(moduleId);
|
|
79
|
+
});
|
|
78
80
|
}
|
|
79
81
|
async createGetModuleJob(moduleId) {
|
|
80
82
|
const {watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled} = this;
|
|
83
|
+
import_shared_utils.logger.debug("createGetModuleJob", {moduleId});
|
|
81
84
|
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
82
85
|
if (!moduleEntry) {
|
|
83
86
|
return;
|
|
@@ -89,12 +92,24 @@ var LwcModuleProvider = class {
|
|
|
89
92
|
if (!compiledModule) {
|
|
90
93
|
const [name] = rawName.split("#");
|
|
91
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
|
+
});
|
|
92
101
|
compiledModule = await this.lwcCompiler.compileFile(originalSource, {
|
|
93
102
|
namespace,
|
|
94
103
|
name,
|
|
95
104
|
filename: moduleEntry.entry,
|
|
96
105
|
scopedStyles
|
|
97
106
|
});
|
|
107
|
+
import_shared_utils.logger.verbose("createGetModuleJob:compile compiledModule", {
|
|
108
|
+
namespace,
|
|
109
|
+
name,
|
|
110
|
+
filename: moduleEntry.entry,
|
|
111
|
+
scopedStyles
|
|
112
|
+
});
|
|
98
113
|
if (moduleFsCacheEnabled) {
|
|
99
114
|
(0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
|
|
100
115
|
}
|
|
@@ -136,6 +151,7 @@ var LwcModuleProvider = class {
|
|
|
136
151
|
importer,
|
|
137
152
|
version
|
|
138
153
|
}) {
|
|
154
|
+
import_shared_utils.logger.debug("getModuleEntry", {specifier, importer, version});
|
|
139
155
|
const versionId = version || importer;
|
|
140
156
|
if (versionId) {
|
|
141
157
|
const cacheKey2 = getModuleEntryCacheKey(specifier, versionId);
|
|
@@ -144,13 +160,17 @@ var LwcModuleProvider = class {
|
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
162
|
const cacheKey = `${specifier}@${version}@${importer}`;
|
|
147
|
-
|
|
163
|
+
import_shared_utils.logger.debug("getModuleEntry:cacheKey", {cacheKey});
|
|
164
|
+
return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
|
|
165
|
+
return this.createModuleEntry({specifier, importer, version});
|
|
166
|
+
});
|
|
148
167
|
}
|
|
149
168
|
async createModuleEntry({
|
|
150
169
|
specifier,
|
|
151
170
|
importer,
|
|
152
171
|
version
|
|
153
172
|
}) {
|
|
173
|
+
import_shared_utils.logger.debug("createModuleEntry", {specifier, importer, rootDir: this.rootDir, version});
|
|
154
174
|
const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
|
|
155
175
|
const fileRelativePath = fileRelativePathRaw?.split("?")[0];
|
|
156
176
|
let moduleEntry;
|
|
@@ -160,7 +180,14 @@ var LwcModuleProvider = class {
|
|
|
160
180
|
}
|
|
161
181
|
if (!moduleEntry) {
|
|
162
182
|
try {
|
|
183
|
+
import_shared_utils.logger.debug("createModuleEntry:resolveModuleSpecifier", {
|
|
184
|
+
baseSpecifier,
|
|
185
|
+
importer,
|
|
186
|
+
rootDir: this.rootDir,
|
|
187
|
+
modules: this.modules
|
|
188
|
+
});
|
|
163
189
|
const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules);
|
|
190
|
+
import_shared_utils.logger.debug("createModuleEntry:registryEntry", {registryEntry});
|
|
164
191
|
moduleEntry = {
|
|
165
192
|
id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
|
|
166
193
|
...registryEntry
|
|
@@ -174,6 +201,8 @@ var LwcModuleProvider = class {
|
|
|
174
201
|
} catch (e) {
|
|
175
202
|
if (e.code !== "NO_LWC_MODULE_FOUND") {
|
|
176
203
|
throw e;
|
|
204
|
+
} else {
|
|
205
|
+
import_shared_utils.logger.verbose(`LWC provider could not find the module ${specifier}`);
|
|
177
206
|
}
|
|
178
207
|
}
|
|
179
208
|
}
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -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};
|
package/build/es/compiler.d.ts
CHANGED
package/build/es/compiler.js
CHANGED
|
@@ -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
|
|
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';
|
|
@@ -43,7 +43,9 @@ export default class LwcModuleProvider {
|
|
|
43
43
|
}
|
|
44
44
|
async getModule(moduleId) {
|
|
45
45
|
const id = getSpecifier(moduleId);
|
|
46
|
-
return this.inflightGetModuleJobs.execute(id, () =>
|
|
46
|
+
return this.inflightGetModuleJobs.execute(id, () => {
|
|
47
|
+
return this.createGetModuleJob(moduleId);
|
|
48
|
+
});
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Create a new Job to fetch a module by id so we are not duplicating effort when multiple requests come in
|
|
@@ -52,6 +54,7 @@ export default class LwcModuleProvider {
|
|
|
52
54
|
*/
|
|
53
55
|
async createGetModuleJob(moduleId) {
|
|
54
56
|
const { watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled } = this;
|
|
57
|
+
logger.debug('createGetModuleJob', { moduleId });
|
|
55
58
|
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
56
59
|
if (!moduleEntry) {
|
|
57
60
|
return;
|
|
@@ -63,6 +66,12 @@ export default class LwcModuleProvider {
|
|
|
63
66
|
if (!compiledModule) {
|
|
64
67
|
const [name] = rawName.split('#');
|
|
65
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
|
+
});
|
|
66
75
|
// We need to convert anything (html, css, javascript) into a canonical ES6 module
|
|
67
76
|
compiledModule = await this.lwcCompiler.compileFile(originalSource, {
|
|
68
77
|
namespace,
|
|
@@ -70,6 +79,12 @@ export default class LwcModuleProvider {
|
|
|
70
79
|
filename: moduleEntry.entry,
|
|
71
80
|
scopedStyles,
|
|
72
81
|
});
|
|
82
|
+
logger.verbose('createGetModuleJob:compile compiledModule', {
|
|
83
|
+
namespace,
|
|
84
|
+
name,
|
|
85
|
+
filename: moduleEntry.entry,
|
|
86
|
+
scopedStyles,
|
|
87
|
+
});
|
|
73
88
|
if (moduleFsCacheEnabled) {
|
|
74
89
|
addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
|
|
75
90
|
}
|
|
@@ -107,6 +122,7 @@ export default class LwcModuleProvider {
|
|
|
107
122
|
return moduleSource;
|
|
108
123
|
}
|
|
109
124
|
async getModuleEntry({ specifier, importer, version, }) {
|
|
125
|
+
logger.debug('getModuleEntry', { specifier, importer, version });
|
|
110
126
|
// Check cache
|
|
111
127
|
const versionId = version || importer;
|
|
112
128
|
if (versionId) {
|
|
@@ -116,9 +132,13 @@ export default class LwcModuleProvider {
|
|
|
116
132
|
}
|
|
117
133
|
}
|
|
118
134
|
const cacheKey = `${specifier}@${version}@${importer}`;
|
|
119
|
-
|
|
135
|
+
logger.debug('getModuleEntry:cacheKey', { cacheKey });
|
|
136
|
+
return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
|
|
137
|
+
return this.createModuleEntry({ specifier, importer, version });
|
|
138
|
+
});
|
|
120
139
|
}
|
|
121
140
|
async createModuleEntry({ specifier, importer, version, }) {
|
|
141
|
+
logger.debug('createModuleEntry', { specifier, importer, rootDir: this.rootDir, version });
|
|
122
142
|
// Strip any filenames out of the specifier
|
|
123
143
|
// eg: 'c/myApp#myApp.css' => 'c/myApp' and 'myApp.css'
|
|
124
144
|
// eg: 'some/where#lib/util' => 'some/where' and 'lib/util'
|
|
@@ -133,7 +153,14 @@ export default class LwcModuleProvider {
|
|
|
133
153
|
// Nothing from cache, let's try to resolve it first from lwc then from npm
|
|
134
154
|
if (!moduleEntry) {
|
|
135
155
|
try {
|
|
156
|
+
logger.debug('createModuleEntry:resolveModuleSpecifier', {
|
|
157
|
+
baseSpecifier,
|
|
158
|
+
importer,
|
|
159
|
+
rootDir: this.rootDir,
|
|
160
|
+
modules: this.modules,
|
|
161
|
+
});
|
|
136
162
|
const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules);
|
|
163
|
+
logger.debug('createModuleEntry:registryEntry', { registryEntry });
|
|
137
164
|
moduleEntry = {
|
|
138
165
|
id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version),
|
|
139
166
|
...registryEntry,
|
|
@@ -150,6 +177,10 @@ export default class LwcModuleProvider {
|
|
|
150
177
|
if (e.code !== 'NO_LWC_MODULE_FOUND') {
|
|
151
178
|
throw e;
|
|
152
179
|
}
|
|
180
|
+
else {
|
|
181
|
+
// in verbose log the lwc provider miss
|
|
182
|
+
logger.verbose(`LWC provider could not find the module ${specifier}`);
|
|
183
|
+
}
|
|
153
184
|
}
|
|
154
185
|
}
|
|
155
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.
|
|
7
|
+
"version": "0.8.0-alpha.6",
|
|
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.
|
|
35
|
+
"@lwrjs/shared-utils": "0.8.0-alpha.6",
|
|
36
36
|
"es-module-lexer": "^0.3.18"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.8.0-alpha.
|
|
39
|
+
"@lwrjs/types": "0.8.0-alpha.6"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=14.15.4 <19"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "cf34943d7df7b570d1183836868462c10a6a136c"
|
|
45
45
|
}
|