@lwrjs/lwc-module-provider 0.12.0-alpha.2 → 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.
- package/build/cjs/cache.cjs +40 -23
- package/build/cjs/index.cjs +30 -23
- package/build/cjs/utils.cjs +1 -1
- package/build/es/cache.d.ts +1 -1
- package/build/es/cache.js +37 -17
- package/build/es/index.d.ts +3 -2
- package/build/es/index.js +29 -22
- package/build/es/utils.js +1 -1
- package/package.json +7 -6
package/build/cjs/cache.cjs
CHANGED
|
@@ -32,7 +32,8 @@ __export(exports, {
|
|
|
32
32
|
setupModuleCache: () => setupModuleCache
|
|
33
33
|
});
|
|
34
34
|
var import_path = __toModule(require("path"));
|
|
35
|
-
var
|
|
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
|
-
|
|
44
|
-
if (!
|
|
45
|
-
|
|
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
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 &&
|
|
105
|
+
if (ownHash === cacheEntry.ownHash && import_fs_extra.default.existsSync(cacheModulePath) && import_fs_extra.default.existsSync(cacheMetaPath)) {
|
|
89
106
|
return {
|
|
90
|
-
code:
|
|
91
|
-
metadata: JSON.parse(
|
|
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
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ function getModuleEntryCacheKey(specifier, version) {
|
|
|
38
38
|
var LwcModuleProvider = class {
|
|
39
39
|
constructor(options = {}, {
|
|
40
40
|
appEmitter,
|
|
41
|
-
config: {
|
|
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,10 +101,7 @@ 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("#");
|
|
@@ -136,7 +133,7 @@ var LwcModuleProvider = class {
|
|
|
136
133
|
}
|
|
137
134
|
});
|
|
138
135
|
if (moduleFsCacheEnabled) {
|
|
139
|
-
(0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
|
|
136
|
+
await (0, import_cache.addCompiledModuleCacheEntry)(moduleSource, compiledModule, cacheConfig);
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
if (watcher && !watchedModuleContextMap.has(moduleEntry.entry)) {
|
|
@@ -180,15 +177,12 @@ var LwcModuleProvider = class {
|
|
|
180
177
|
label: `${this.name}`,
|
|
181
178
|
message: `getModuleEntry ${specifier}@${version}@${importer}`
|
|
182
179
|
});
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
if (this.moduleEntryVersionCache.has(cacheKey2)) {
|
|
187
|
-
return this.moduleEntryVersionCache.get(cacheKey2);
|
|
188
|
-
}
|
|
180
|
+
const moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
|
|
181
|
+
if (moduleEntry) {
|
|
182
|
+
return moduleEntry;
|
|
189
183
|
}
|
|
190
|
-
const
|
|
191
|
-
return this.inflightGetModuleEntryJobs.execute(
|
|
184
|
+
const jobKey = `${specifier}@${version}@${importer}`;
|
|
185
|
+
return this.inflightGetModuleEntryJobs.execute(jobKey, async () => {
|
|
192
186
|
return this.createModuleEntry({specifier, importer, version});
|
|
193
187
|
});
|
|
194
188
|
}
|
|
@@ -210,9 +204,8 @@ var LwcModuleProvider = class {
|
|
|
210
204
|
const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
|
|
211
205
|
const fileRelativePath = fileRelativePathRaw?.split("?")[0];
|
|
212
206
|
let moduleEntry;
|
|
213
|
-
if (fileRelativePath
|
|
214
|
-
|
|
215
|
-
moduleEntry = this.moduleEntryVersionCache.get(cacheKey2);
|
|
207
|
+
if (fileRelativePath) {
|
|
208
|
+
moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
|
|
216
209
|
}
|
|
217
210
|
if (!moduleEntry) {
|
|
218
211
|
try {
|
|
@@ -222,8 +215,7 @@ var LwcModuleProvider = class {
|
|
|
222
215
|
additionalInfo: {
|
|
223
216
|
baseSpecifier,
|
|
224
217
|
importer,
|
|
225
|
-
rootDir: this.rootDir
|
|
226
|
-
modules: this.modules
|
|
218
|
+
rootDir: this.rootDir
|
|
227
219
|
}
|
|
228
220
|
});
|
|
229
221
|
const registryEntry = (0, import_utils.resolveModuleSpecifier)(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
|
|
@@ -268,11 +260,26 @@ var LwcModuleProvider = class {
|
|
|
268
260
|
const cacheKey = getModuleEntryCacheKey(specifier, moduleEntry.version);
|
|
269
261
|
const finalModuleEntry = {...moduleEntry, id: cacheKey};
|
|
270
262
|
this.moduleEntryVersionCache.set(cacheKey, finalModuleEntry);
|
|
271
|
-
if (!version
|
|
272
|
-
const importerCacheKey = getModuleEntryCacheKey(specifier, importer);
|
|
273
|
-
this.
|
|
263
|
+
if (!version) {
|
|
264
|
+
const importerCacheKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
|
|
265
|
+
this.importerMappingCache.set(importerCacheKey, cacheKey);
|
|
274
266
|
}
|
|
275
267
|
return finalModuleEntry;
|
|
276
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
|
+
}
|
|
277
284
|
};
|
|
278
285
|
var src_default = LwcModuleProvider;
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -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
|
|
44
|
+
additionalInfo: {specifier, importer}
|
|
45
45
|
});
|
|
46
46
|
let resolvedModule;
|
|
47
47
|
try {
|
package/build/es/cache.d.ts
CHANGED
|
@@ -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):
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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}`;
|
package/build/es/index.d.ts
CHANGED
|
@@ -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: {
|
|
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: {
|
|
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,10 +77,7 @@ 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('#');
|
|
@@ -113,7 +110,7 @@ export default class LwcModuleProvider {
|
|
|
113
110
|
},
|
|
114
111
|
});
|
|
115
112
|
if (moduleFsCacheEnabled) {
|
|
116
|
-
addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
|
|
113
|
+
await addCompiledModuleCacheEntry(moduleSource, compiledModule, cacheConfig);
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
if (watcher && !watchedModuleContextMap.has(moduleEntry.entry)) {
|
|
@@ -154,15 +151,12 @@ export default class LwcModuleProvider {
|
|
|
154
151
|
message: `getModuleEntry ${specifier}@${version}@${importer}`,
|
|
155
152
|
});
|
|
156
153
|
// Check cache
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
if (this.moduleEntryVersionCache.has(cacheKey)) {
|
|
161
|
-
return this.moduleEntryVersionCache.get(cacheKey);
|
|
162
|
-
}
|
|
154
|
+
const moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
|
|
155
|
+
if (moduleEntry) {
|
|
156
|
+
return moduleEntry;
|
|
163
157
|
}
|
|
164
|
-
const
|
|
165
|
-
return this.inflightGetModuleEntryJobs.execute(
|
|
158
|
+
const jobKey = `${specifier}@${version}@${importer}`;
|
|
159
|
+
return this.inflightGetModuleEntryJobs.execute(jobKey, async () => {
|
|
166
160
|
return this.createModuleEntry({ specifier, importer, version });
|
|
167
161
|
});
|
|
168
162
|
}
|
|
@@ -184,9 +178,8 @@ export default class LwcModuleProvider {
|
|
|
184
178
|
const fileRelativePath = fileRelativePathRaw?.split('?')[0]; // Remove queryString as LWC uses it for scope style
|
|
185
179
|
let moduleEntry;
|
|
186
180
|
// If this is a relative import, check the cache for the base specifier first
|
|
187
|
-
if (fileRelativePath
|
|
188
|
-
|
|
189
|
-
moduleEntry = this.moduleEntryVersionCache.get(cacheKey);
|
|
181
|
+
if (fileRelativePath) {
|
|
182
|
+
moduleEntry = this.getCachedModuleEntry(specifier, version, importer);
|
|
190
183
|
}
|
|
191
184
|
// Nothing from cache, let's try to resolve it first from lwc then from npm
|
|
192
185
|
if (!moduleEntry) {
|
|
@@ -198,7 +191,6 @@ export default class LwcModuleProvider {
|
|
|
198
191
|
baseSpecifier,
|
|
199
192
|
importer,
|
|
200
193
|
rootDir: this.rootDir,
|
|
201
|
-
modules: this.modules,
|
|
202
194
|
},
|
|
203
195
|
});
|
|
204
196
|
const registryEntry = resolveModuleSpecifier(baseSpecifier, importer || this.rootDir, this.modules, this.packageVersionCache);
|
|
@@ -250,13 +242,28 @@ export default class LwcModuleProvider {
|
|
|
250
242
|
const cacheKey = getModuleEntryCacheKey(specifier, moduleEntry.version);
|
|
251
243
|
const finalModuleEntry = { ...moduleEntry, id: cacheKey };
|
|
252
244
|
this.moduleEntryVersionCache.set(cacheKey, finalModuleEntry);
|
|
253
|
-
if (!version
|
|
245
|
+
if (!version) {
|
|
254
246
|
// if this module is being resolved via importer rather than version,
|
|
255
247
|
// then use the importer as part of the cache key to avoid future cache misses
|
|
256
|
-
const importerCacheKey = getModuleEntryCacheKey(specifier, importer);
|
|
257
|
-
this.
|
|
248
|
+
const importerCacheKey = getModuleEntryCacheKey(specifier, importer || this.rootDir);
|
|
249
|
+
this.importerMappingCache.set(importerCacheKey, cacheKey);
|
|
258
250
|
}
|
|
259
251
|
return finalModuleEntry;
|
|
260
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
|
+
}
|
|
261
268
|
}
|
|
262
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
|
|
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.
|
|
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.
|
|
35
|
-
"@lwrjs/fs-watch": "0.12.0-alpha.
|
|
36
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
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.
|
|
40
|
+
"@lwrjs/types": "0.12.0-alpha.3",
|
|
40
41
|
"typescript": "^4.9.5"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"engines": {
|
|
47
48
|
"node": ">=18.0.0"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "48f97b40cbacce6cd6a6faee9206a465832c6774"
|
|
50
51
|
}
|