@lwrjs/lwc-module-provider 0.5.11 → 0.6.0-alpha.12
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 +1 -1
- package/build/cjs/index.cjs +18 -0
- package/build/es/cache.js +1 -1
- package/build/es/index.d.ts +9 -0
- package/build/es/index.js +20 -1
- package/package.json +6 -6
package/build/cjs/cache.cjs
CHANGED
|
@@ -36,7 +36,7 @@ var import_fs = __toModule(require("fs"));
|
|
|
36
36
|
var DEFAULT_COMPILED_DIR = "lwc_compiled_modules";
|
|
37
37
|
var DEFAULT_CACHE_FOLDER = "cache";
|
|
38
38
|
var DEFAULT_CACHE_INDEX = `compiled.json`;
|
|
39
|
-
var NORMALIZE_PATH_REGEX = /[
|
|
39
|
+
var NORMALIZE_PATH_REGEX = /[@\/#\.\?<>\\:\*\|"]/gm;
|
|
40
40
|
function setupModuleCache(cacheDir) {
|
|
41
41
|
const lwcCacheDir = import_path.default.join(cacheDir, `${DEFAULT_COMPILED_DIR}`);
|
|
42
42
|
const lwcCacheIndexPath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_INDEX);
|
package/build/cjs/index.cjs
CHANGED
|
@@ -45,6 +45,8 @@ var LwcModuleProvider = class {
|
|
|
45
45
|
this.watchedModuleContextMap = new Map();
|
|
46
46
|
this.moduleEntryVersionCache = new Map();
|
|
47
47
|
this.lwcCompiler = new import_compiler.LwcCompiler();
|
|
48
|
+
this.inflightGetModuleJobs = new import_shared_utils.InflightTasks();
|
|
49
|
+
this.inflightGetModuleEntryJobs = new import_shared_utils.InflightTasks();
|
|
48
50
|
const {disableCaching} = options;
|
|
49
51
|
this.emitter = appEmitter;
|
|
50
52
|
this.modules = modules;
|
|
@@ -71,6 +73,12 @@ var LwcModuleProvider = class {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
async getModule(moduleId) {
|
|
76
|
+
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
77
|
+
return this.inflightGetModuleJobs.execute(id, () => {
|
|
78
|
+
return this.createGetModuleJob(moduleId);
|
|
79
|
+
}, this);
|
|
80
|
+
}
|
|
81
|
+
async createGetModuleJob(moduleId) {
|
|
74
82
|
const {watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled} = this;
|
|
75
83
|
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
76
84
|
if (!moduleEntry) {
|
|
@@ -135,6 +143,16 @@ var LwcModuleProvider = class {
|
|
|
135
143
|
return this.moduleEntryVersionCache.get(cacheKey2);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
146
|
+
const cacheKey = `${specifier}@${version}@${importer}`;
|
|
147
|
+
return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
|
|
148
|
+
return this.createModuleEntry({specifier, importer, version});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async createModuleEntry({
|
|
152
|
+
specifier,
|
|
153
|
+
importer,
|
|
154
|
+
version
|
|
155
|
+
}) {
|
|
138
156
|
const [baseSpecifier, fileRelativePathRaw] = specifier.split("#");
|
|
139
157
|
const fileRelativePath = fileRelativePathRaw?.split("?")[0];
|
|
140
158
|
let moduleEntry;
|
package/build/es/cache.js
CHANGED
|
@@ -4,7 +4,7 @@ export const DEFAULT_COMPILED_DIR = 'lwc_compiled_modules';
|
|
|
4
4
|
export const DEFAULT_CACHE_FOLDER = 'cache';
|
|
5
5
|
export const DEFAULT_CACHE_INDEX = `compiled.json`;
|
|
6
6
|
// eslint-disable-next-line no-useless-escape
|
|
7
|
-
const NORMALIZE_PATH_REGEX = /[
|
|
7
|
+
const NORMALIZE_PATH_REGEX = /[@\/#\.\?<>\\:\*\|"]/gm;
|
|
8
8
|
/**
|
|
9
9
|
* The module cache allow us to recover modules compiled across server restart
|
|
10
10
|
* We store an index file and the compiler modules individually
|
package/build/es/index.d.ts
CHANGED
|
@@ -16,11 +16,20 @@ export default class LwcModuleProvider implements ModuleProvider {
|
|
|
16
16
|
private watchedModuleContextMap;
|
|
17
17
|
private moduleEntryVersionCache;
|
|
18
18
|
private lwcCompiler;
|
|
19
|
+
private inflightGetModuleJobs;
|
|
20
|
+
private inflightGetModuleEntryJobs;
|
|
19
21
|
constructor(options: LwcModuleProviderOptions | undefined, { appEmitter, config: { modules, rootDir, cacheDir, environment }, runtimeEnvironment: { watchFiles }, }: ProviderContext);
|
|
20
22
|
onModuleChange(fileChanged: string): Promise<void>;
|
|
21
23
|
getModule(moduleId: AbstractModuleId): Promise<ModuleCompiled | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new Job to fetch a module by id so we are not duplicating effort when multiple requests come in
|
|
26
|
+
* @param moduleId Id of module in question
|
|
27
|
+
* @returns Compiled Module
|
|
28
|
+
*/
|
|
29
|
+
createGetModuleJob(moduleId: AbstractModuleId): Promise<ModuleCompiled | undefined>;
|
|
22
30
|
getModuleSource({ name, namespace, specifier }: AbstractModuleId, moduleEntry: FsModuleEntry): Promise<ModuleSource>;
|
|
23
31
|
getModuleEntry({ specifier, importer, version, }: AbstractModuleId): Promise<FsModuleEntry | undefined>;
|
|
32
|
+
createModuleEntry({ specifier, importer, version, }: AbstractModuleId): Promise<FsModuleEntry | undefined>;
|
|
24
33
|
}
|
|
25
34
|
export {};
|
|
26
35
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, join } from 'path';
|
|
2
|
-
import { explodeSpecifier, hashContent, readFile, resolveFileExtension, resolveCustomLWCMetadata, } from '@lwrjs/shared-utils';
|
|
2
|
+
import { explodeSpecifier, getSpecifier, hashContent, InflightTasks, 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';
|
|
@@ -13,6 +13,8 @@ export default class LwcModuleProvider {
|
|
|
13
13
|
this.watchedModuleContextMap = new Map();
|
|
14
14
|
this.moduleEntryVersionCache = new Map();
|
|
15
15
|
this.lwcCompiler = new LwcCompiler();
|
|
16
|
+
this.inflightGetModuleJobs = new InflightTasks();
|
|
17
|
+
this.inflightGetModuleEntryJobs = new InflightTasks();
|
|
16
18
|
const { disableCaching } = options;
|
|
17
19
|
this.emitter = appEmitter;
|
|
18
20
|
this.modules = modules;
|
|
@@ -40,6 +42,17 @@ export default class LwcModuleProvider {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
async getModule(moduleId) {
|
|
45
|
+
const id = getSpecifier(moduleId);
|
|
46
|
+
return this.inflightGetModuleJobs.execute(id, () => {
|
|
47
|
+
return this.createGetModuleJob(moduleId);
|
|
48
|
+
}, this);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a new Job to fetch a module by id so we are not duplicating effort when multiple requests come in
|
|
52
|
+
* @param moduleId Id of module in question
|
|
53
|
+
* @returns Compiled Module
|
|
54
|
+
*/
|
|
55
|
+
async createGetModuleJob(moduleId) {
|
|
43
56
|
const { watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled } = this;
|
|
44
57
|
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
45
58
|
if (!moduleEntry) {
|
|
@@ -102,6 +115,12 @@ export default class LwcModuleProvider {
|
|
|
102
115
|
return this.moduleEntryVersionCache.get(cacheKey);
|
|
103
116
|
}
|
|
104
117
|
}
|
|
118
|
+
const cacheKey = `${specifier}@${version}@${importer}`;
|
|
119
|
+
return this.inflightGetModuleEntryJobs.execute(cacheKey, async () => {
|
|
120
|
+
return this.createModuleEntry({ specifier, importer, version });
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async createModuleEntry({ specifier, importer, version, }) {
|
|
105
124
|
// Strip any filenames out of the specifier
|
|
106
125
|
// eg: 'c/myApp#myApp.css' => 'c/myApp' and 'myApp.css'
|
|
107
126
|
// eg: 'some/where#lib/util' => 'some/where' and 'lib/util'
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.12",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/preset-typescript": "^7.9.0",
|
|
34
|
-
"@lwc/module-resolver": "2.
|
|
35
|
-
"@lwrjs/shared-utils": "0.
|
|
34
|
+
"@lwc/module-resolver": "2.5.8",
|
|
35
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.12",
|
|
36
36
|
"es-module-lexer": "^0.3.18"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.
|
|
39
|
+
"@lwrjs/types": "0.6.0-alpha.12"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=14.15.4 <17"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "876b56ca4f98f3299303f2193c0dec8f46a69b84"
|
|
45
45
|
}
|