@lwrjs/lwc-module-provider 0.24.2 → 0.24.4
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 +37 -28
- package/build/cjs/compiler.cjs +41 -30
- package/build/cjs/index.cjs +82 -59
- package/build/cjs/utils.cjs +39 -27
- package/package.json +6 -6
package/build/cjs/cache.cjs
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
10
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
16
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
17
|
+
return to;
|
|
22
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
28
|
|
|
24
29
|
// packages/@lwrjs/lwc-module-provider/src/cache.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
30
|
+
var cache_exports = {};
|
|
31
|
+
__export(cache_exports, {
|
|
27
32
|
DEFAULT_CACHE_FOLDER: () => DEFAULT_CACHE_FOLDER,
|
|
28
33
|
DEFAULT_CACHE_INDEX: () => DEFAULT_CACHE_INDEX,
|
|
29
34
|
DEFAULT_COMPILED_DIR: () => DEFAULT_COMPILED_DIR,
|
|
@@ -31,10 +36,11 @@ __export(exports, {
|
|
|
31
36
|
getCompiledModuleCacheEntry: () => getCompiledModuleCacheEntry,
|
|
32
37
|
setupModuleCache: () => setupModuleCache
|
|
33
38
|
});
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
39
|
+
module.exports = __toCommonJS(cache_exports);
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
42
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
43
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
38
44
|
var DEFAULT_COMPILED_DIR = "lwc_compiled_modules";
|
|
39
45
|
var DEFAULT_CACHE_FOLDER = "cache";
|
|
40
46
|
var DEFAULT_CACHE_INDEX = `compiled.json`;
|
|
@@ -42,17 +48,20 @@ var NORMALIZE_PATH_REGEX = /[@\/#\.\?<>\\:\*\|"]/gm;
|
|
|
42
48
|
function setupModuleCache(cacheDir) {
|
|
43
49
|
const lwcCacheDir = (0, import_shared_utils.toForwardSlash)(import_path.default.join(cacheDir, DEFAULT_COMPILED_DIR));
|
|
44
50
|
const lwcCacheIndexPath = import_path.default.join(lwcCacheDir, DEFAULT_CACHE_INDEX);
|
|
45
|
-
import_fs_extra.default.mkdirSync(`${lwcCacheDir}/${DEFAULT_CACHE_FOLDER}`, {recursive: true});
|
|
51
|
+
import_fs_extra.default.mkdirSync(`${lwcCacheDir}/${DEFAULT_CACHE_FOLDER}`, { recursive: true });
|
|
46
52
|
if (!import_fs_extra.default.existsSync(lwcCacheIndexPath)) {
|
|
47
53
|
import_fs_extra.default.writeFileSync(lwcCacheIndexPath, "[]");
|
|
48
|
-
return {lwcCacheDir, lwcCacheIndex: new Map()};
|
|
54
|
+
return { lwcCacheDir, lwcCacheIndex: /* @__PURE__ */ new Map() };
|
|
49
55
|
} else {
|
|
50
56
|
const cacheIndexJson = import_fs_extra.default.readJSONSync(lwcCacheIndexPath, "utf-8");
|
|
51
|
-
return {lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson)};
|
|
57
|
+
return { lwcCacheDir, lwcCacheIndex: new Map(cacheIndexJson) };
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
var IndexPersister = class {
|
|
55
|
-
|
|
61
|
+
lwcCacheDir;
|
|
62
|
+
lwcCacheIndex;
|
|
63
|
+
updateTimer;
|
|
64
|
+
async persist({ lwcCacheIndex, lwcCacheDir }) {
|
|
56
65
|
if (this.updateTimer) {
|
|
57
66
|
clearTimeout(this.updateTimer);
|
|
58
67
|
}
|
|
@@ -79,11 +88,11 @@ function getCacheKey(specifier, version, targetSSR) {
|
|
|
79
88
|
return `${specifier}@${version}|${getEnvVariant(targetSSR)}`;
|
|
80
89
|
}
|
|
81
90
|
var moduleCount = 0;
|
|
82
|
-
async function addCompiledModuleCacheEntry(moduleSource, compilerResult, targetSSR, {lwcCacheIndex, lwcCacheDir}) {
|
|
83
|
-
const {specifier, version, ownHash} = moduleSource;
|
|
91
|
+
async function addCompiledModuleCacheEntry(moduleSource, compilerResult, targetSSR, { lwcCacheIndex, lwcCacheDir }) {
|
|
92
|
+
const { specifier, version, ownHash } = moduleSource;
|
|
84
93
|
const cacheKey = getCacheKey(specifier, version, targetSSR);
|
|
85
94
|
if (++moduleCount % 1e3 === 0) {
|
|
86
|
-
import_diagnostics.logger.debug({label: `lwc-module-provider`, message: `Compiled Modules >${moduleCount}`});
|
|
95
|
+
import_diagnostics.logger.debug({ label: `lwc-module-provider`, message: `Compiled Modules >${moduleCount}` });
|
|
87
96
|
}
|
|
88
97
|
const normalizedSpecifier = specifier.replace(NORMALIZE_PATH_REGEX, "_");
|
|
89
98
|
const normalizedVersion = version.replace(NORMALIZE_PATH_REGEX, "_");
|
|
@@ -99,10 +108,10 @@ async function addCompiledModuleCacheEntry(moduleSource, compilerResult, targetS
|
|
|
99
108
|
module: `./${DEFAULT_CACHE_FOLDER}/${moduleFileName}`,
|
|
100
109
|
moduleMeta: `./${DEFAULT_CACHE_FOLDER}/${moduleMetaFileName}`
|
|
101
110
|
});
|
|
102
|
-
const writeMetadata = INDEX_PERSISTER.persist({lwcCacheIndex, lwcCacheDir});
|
|
111
|
+
const writeMetadata = INDEX_PERSISTER.persist({ lwcCacheIndex, lwcCacheDir });
|
|
103
112
|
return Promise.all([writeModulePromise, writeMetadataPromise, writeMetadata]);
|
|
104
113
|
}
|
|
105
|
-
function getCompiledModuleCacheEntry({specifier, version, ownHash}, targetSSR, {lwcCacheIndex, lwcCacheDir}) {
|
|
114
|
+
function getCompiledModuleCacheEntry({ specifier, version, ownHash }, targetSSR, { lwcCacheIndex, lwcCacheDir }) {
|
|
106
115
|
const cacheKey = getCacheKey(specifier, version, targetSSR);
|
|
107
116
|
const cacheEntry = lwcCacheIndex.get(cacheKey);
|
|
108
117
|
if (!cacheEntry) {
|
package/build/cjs/compiler.cjs
CHANGED
|
@@ -1,56 +1,66 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
10
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
16
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
17
|
+
return to;
|
|
22
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
28
|
|
|
24
29
|
// packages/@lwrjs/lwc-module-provider/src/compiler.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
30
|
+
var compiler_exports = {};
|
|
31
|
+
__export(compiler_exports, {
|
|
27
32
|
LwcCompiler: () => LwcCompiler
|
|
28
33
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
35
|
+
var import_core = require("@babel/core");
|
|
36
|
+
var lwcCompilerCjs = __toESM(require("@lwc/compiler/dist/index.cjs"));
|
|
37
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
38
|
+
var import_utils = require("./utils.cjs");
|
|
39
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
34
40
|
var DEFAULT_BABEL_CONFIG = {
|
|
35
41
|
babelrc: false,
|
|
36
42
|
configFile: false,
|
|
37
43
|
sourceMaps: true,
|
|
38
44
|
parserOpts: {
|
|
39
|
-
plugins: [["decorators", {decoratorsBeforeExport: true}]]
|
|
45
|
+
plugins: [["decorators", { decoratorsBeforeExport: true }]]
|
|
40
46
|
}
|
|
41
47
|
};
|
|
42
48
|
function skipCompilation(namespace, theName) {
|
|
43
|
-
if (!namespace && theName === "lwc" ||
|
|
49
|
+
if (!namespace && theName === "lwc" || // LWC framework
|
|
50
|
+
namespace === "@lwc" || // other LWC framework packages
|
|
51
|
+
namespace === "lwr" && theName === "hmr") {
|
|
44
52
|
return true;
|
|
45
53
|
}
|
|
46
54
|
return false;
|
|
47
55
|
}
|
|
48
56
|
var LwcCompiler = class {
|
|
57
|
+
compiler;
|
|
49
58
|
constructor(compiler) {
|
|
50
59
|
this.compiler = compiler;
|
|
51
60
|
}
|
|
61
|
+
// compileFile takes a html, css, typescript, etc, and transforms it to a es6 module
|
|
52
62
|
async compileFile(source, config, targetSSR = false) {
|
|
53
|
-
const {enableLightningWebSecurityTransforms, filename, name, namespace, scopedStyles} = config;
|
|
63
|
+
const { enableLightningWebSecurityTransforms, filename, name, namespace, scopedStyles } = config;
|
|
54
64
|
if (source.startsWith(import_utils.EXPLICIT_CONSTANT)) {
|
|
55
65
|
return {
|
|
56
66
|
code: source,
|
|
@@ -61,13 +71,13 @@ var LwcCompiler = class {
|
|
|
61
71
|
if (filename.endsWith("ts")) {
|
|
62
72
|
const babelConfig = {
|
|
63
73
|
...DEFAULT_BABEL_CONFIG,
|
|
64
|
-
presets: [["@babel/preset-typescript", {onlyRemoveTypeImports: false}]],
|
|
74
|
+
presets: [["@babel/preset-typescript", { onlyRemoveTypeImports: false }]],
|
|
65
75
|
filename
|
|
66
76
|
};
|
|
67
77
|
import_diagnostics.logger.debug({
|
|
68
78
|
label: "LwcCompiler",
|
|
69
79
|
message: "babelTransform",
|
|
70
|
-
additionalInfo: {babelConfig}
|
|
80
|
+
additionalInfo: { babelConfig }
|
|
71
81
|
});
|
|
72
82
|
let result;
|
|
73
83
|
try {
|
|
@@ -83,13 +93,13 @@ var LwcCompiler = class {
|
|
|
83
93
|
import_diagnostics.logger.verbose({
|
|
84
94
|
label: "LwcCompiler",
|
|
85
95
|
message: "babelTransform result",
|
|
86
|
-
additionalInfo: {result}
|
|
96
|
+
additionalInfo: { result }
|
|
87
97
|
});
|
|
88
98
|
if (!result || !result.code) {
|
|
89
99
|
import_diagnostics.logger.debug({
|
|
90
100
|
label: "LwcCompiler",
|
|
91
101
|
message: "babelTransform invalid result",
|
|
92
|
-
additionalInfo: {result}
|
|
102
|
+
additionalInfo: { result }
|
|
93
103
|
});
|
|
94
104
|
throw new Error(`Error TS compiling ${filename}`);
|
|
95
105
|
}
|
|
@@ -105,14 +115,15 @@ var LwcCompiler = class {
|
|
|
105
115
|
const transformConfig = {
|
|
106
116
|
namespace: namespace || "",
|
|
107
117
|
name,
|
|
108
|
-
experimentalDynamicComponent: {strictSpecifier: false},
|
|
109
|
-
dynamicImports: {strictSpecifier: false},
|
|
118
|
+
experimentalDynamicComponent: { strictSpecifier: false },
|
|
119
|
+
dynamicImports: { strictSpecifier: false },
|
|
110
120
|
scopedStyles,
|
|
111
121
|
enableDynamicComponents: true,
|
|
112
122
|
enableLightningWebSecurityTransforms,
|
|
113
123
|
enablePrivateMethods: true,
|
|
114
124
|
enableSyntheticElementInternals: true,
|
|
115
125
|
enableScopedSlots: true,
|
|
126
|
+
// this flag turns on an additive feature and is backwards compatible
|
|
116
127
|
targetSSR: (0, import_shared_utils.getFeatureFlags)().SSR_COMPILER_ENABLED && targetSSR,
|
|
117
128
|
enableLwcOn: true
|
|
118
129
|
};
|
|
@@ -130,7 +141,7 @@ var LwcCompiler = class {
|
|
|
130
141
|
import_diagnostics.logger.verbose({
|
|
131
142
|
label: "LwcCompiler",
|
|
132
143
|
message: "transformSync result",
|
|
133
|
-
additionalInfo: {compilerResult}
|
|
144
|
+
additionalInfo: { compilerResult }
|
|
134
145
|
});
|
|
135
146
|
return {
|
|
136
147
|
code: compilerResult.code,
|
package/build/cjs/index.cjs
CHANGED
|
@@ -1,56 +1,64 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
8
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
14
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
15
|
+
return to;
|
|
22
16
|
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
18
|
|
|
24
19
|
// packages/@lwrjs/lwc-module-provider/src/index.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
27
|
-
default: () =>
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
default: () => LwcModuleProvider
|
|
28
23
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
27
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
28
|
+
var import_utils = require("./utils.cjs");
|
|
29
|
+
var import_cache = require("./cache.cjs");
|
|
30
|
+
var import_compiler = require("./compiler.cjs");
|
|
35
31
|
function getModuleEntryCacheKey(specifier, version, targetSSR) {
|
|
36
32
|
return `${specifier}@${version}|${targetSSR ? "server" : "client"}`;
|
|
37
33
|
}
|
|
38
34
|
var LwcModuleProvider = class {
|
|
35
|
+
name = "lwc-module-provider";
|
|
36
|
+
rootDir;
|
|
37
|
+
moduleFsCacheEnabled;
|
|
38
|
+
interchangeableModulesEnabled;
|
|
39
|
+
lwcCacheDir;
|
|
40
|
+
lwcCacheIndex;
|
|
41
|
+
moduleSourceCache = /* @__PURE__ */ new Map();
|
|
42
|
+
// key = filepath
|
|
43
|
+
packageVersionCache = /* @__PURE__ */ new Map();
|
|
44
|
+
modules;
|
|
45
|
+
emitter;
|
|
46
|
+
watcher;
|
|
47
|
+
watchedModuleContextMap = /* @__PURE__ */ new Map();
|
|
48
|
+
// key = filepath
|
|
49
|
+
moduleEntryVersionCache = /* @__PURE__ */ new Map();
|
|
50
|
+
// key = moduleEntry.id
|
|
51
|
+
importerMappingCache = /* @__PURE__ */ new Map();
|
|
52
|
+
lwcCompiler;
|
|
53
|
+
inflightGetModuleJobs = new import_shared_utils.InflightTasks();
|
|
54
|
+
inflightGetModuleEntryJobs = new import_shared_utils.InflightTasks();
|
|
39
55
|
constructor(options = {}, {
|
|
40
56
|
appEmitter,
|
|
41
|
-
config: {modules, rootDir, cacheDir, environment},
|
|
42
|
-
runtimeEnvironment: {watchFiles},
|
|
57
|
+
config: { modules, rootDir, cacheDir, environment },
|
|
58
|
+
runtimeEnvironment: { watchFiles },
|
|
43
59
|
watcherFactory
|
|
44
60
|
}) {
|
|
45
|
-
|
|
46
|
-
this.moduleSourceCache = new Map();
|
|
47
|
-
this.packageVersionCache = new Map();
|
|
48
|
-
this.watchedModuleContextMap = new Map();
|
|
49
|
-
this.moduleEntryVersionCache = new Map();
|
|
50
|
-
this.importerMappingCache = new Map();
|
|
51
|
-
this.inflightGetModuleJobs = new import_shared_utils.InflightTasks();
|
|
52
|
-
this.inflightGetModuleEntryJobs = new import_shared_utils.InflightTasks();
|
|
53
|
-
const {disableCaching} = options;
|
|
61
|
+
const { disableCaching } = options;
|
|
54
62
|
this.emitter = appEmitter;
|
|
55
63
|
this.modules = modules;
|
|
56
64
|
this.rootDir = rootDir;
|
|
@@ -59,7 +67,7 @@ var LwcModuleProvider = class {
|
|
|
59
67
|
this.interchangeableModulesEnabled = !!environment?.default;
|
|
60
68
|
this.lwcCompiler = new import_compiler.LwcCompiler(options.lwcCompiler);
|
|
61
69
|
if (this.moduleFsCacheEnabled) {
|
|
62
|
-
const {lwcCacheDir, lwcCacheIndex} = (0, import_cache.setupModuleCache)(cacheDir);
|
|
70
|
+
const { lwcCacheDir, lwcCacheIndex } = (0, import_cache.setupModuleCache)(cacheDir);
|
|
63
71
|
this.lwcCacheDir = lwcCacheDir;
|
|
64
72
|
this.lwcCacheIndex = lwcCacheIndex;
|
|
65
73
|
}
|
|
@@ -73,7 +81,7 @@ var LwcModuleProvider = class {
|
|
|
73
81
|
const hasClient = this.moduleEntryVersionCache.get(moduleEntry.id.replace("|server", "|client"));
|
|
74
82
|
const hasServer = this.moduleEntryVersionCache.get(moduleEntry.id.replace("|client", "|server"));
|
|
75
83
|
const recompiledClientModule = hasClient && await this.getModule(moduleEntry);
|
|
76
|
-
const recompiledServerModule = hasServer && await this.getModule(moduleEntry, {ssr: true});
|
|
84
|
+
const recompiledServerModule = hasServer && await this.getModule(moduleEntry, { ssr: true });
|
|
77
85
|
if (recompiledClientModule) {
|
|
78
86
|
this.emitter.notifyModuleSourceChanged(recompiledClientModule);
|
|
79
87
|
}
|
|
@@ -87,31 +95,36 @@ var LwcModuleProvider = class {
|
|
|
87
95
|
}
|
|
88
96
|
async getModule(moduleId, runtimeParams = {}) {
|
|
89
97
|
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
90
|
-
import_diagnostics.logger.debug({label: this.name, message: `getModule ${id}`});
|
|
98
|
+
import_diagnostics.logger.debug({ label: this.name, message: `getModule ${id}` });
|
|
91
99
|
return this.inflightGetModuleJobs.execute(id, () => {
|
|
92
100
|
return this.createGetModuleJob(moduleId, runtimeParams);
|
|
93
101
|
});
|
|
94
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a new Job to fetch a module by id so we are not duplicating effort when multiple requests come in
|
|
105
|
+
* @param moduleId Id of module in question
|
|
106
|
+
* @returns Compiled Module
|
|
107
|
+
*/
|
|
95
108
|
async createGetModuleJob(moduleId, runtimeParams) {
|
|
96
|
-
const {watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled} = this;
|
|
109
|
+
const { watcher, watchedModuleContextMap, lwcCacheDir, lwcCacheIndex, moduleFsCacheEnabled } = this;
|
|
97
110
|
import_diagnostics.logger.debug({
|
|
98
111
|
label: this.name,
|
|
99
112
|
message: "fetch module",
|
|
100
|
-
additionalInfo: {moduleId, moduleFsCacheEnabled}
|
|
113
|
+
additionalInfo: { moduleId, moduleFsCacheEnabled }
|
|
101
114
|
});
|
|
102
115
|
const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
|
|
103
116
|
if (!moduleEntry) {
|
|
104
117
|
return;
|
|
105
118
|
}
|
|
106
119
|
const moduleSource = await this.getModuleSource(moduleId, moduleEntry);
|
|
107
|
-
const {namespace, name: rawName, originalSource} = moduleSource;
|
|
120
|
+
const { namespace, name: rawName, originalSource } = moduleSource;
|
|
108
121
|
const targetSSR = !!runtimeParams.ssr;
|
|
109
|
-
const cacheConfig = {lwcCacheDir, lwcCacheIndex};
|
|
122
|
+
const cacheConfig = { lwcCacheDir, lwcCacheIndex };
|
|
110
123
|
let compiledModule = moduleFsCacheEnabled && (0, import_cache.getCompiledModuleCacheEntry)(moduleSource, targetSSR, cacheConfig);
|
|
111
124
|
import_diagnostics.logger.debug({
|
|
112
125
|
label: this.name,
|
|
113
126
|
message: "module source",
|
|
114
|
-
additionalInfo: {moduleId, isPreCompiled: compiledModule != void 0}
|
|
127
|
+
additionalInfo: { moduleId, isPreCompiled: compiledModule != void 0 }
|
|
115
128
|
});
|
|
116
129
|
if (!compiledModule) {
|
|
117
130
|
const [name] = rawName.split("#");
|
|
@@ -127,12 +140,16 @@ var LwcModuleProvider = class {
|
|
|
127
140
|
targetSSR
|
|
128
141
|
}
|
|
129
142
|
});
|
|
130
|
-
compiledModule = await this.lwcCompiler.compileFile(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
143
|
+
compiledModule = await this.lwcCompiler.compileFile(
|
|
144
|
+
originalSource,
|
|
145
|
+
{
|
|
146
|
+
namespace,
|
|
147
|
+
name,
|
|
148
|
+
filename: moduleEntry.entry,
|
|
149
|
+
scopedStyles
|
|
150
|
+
},
|
|
151
|
+
targetSSR
|
|
152
|
+
);
|
|
136
153
|
import_diagnostics.logger.verbose({
|
|
137
154
|
label: this.name,
|
|
138
155
|
message: "createGetModuleJob:compile compiledModule",
|
|
@@ -158,8 +175,8 @@ var LwcModuleProvider = class {
|
|
|
158
175
|
compiledMetadata: compiledModule.metadata
|
|
159
176
|
};
|
|
160
177
|
}
|
|
161
|
-
async getModuleSource({name, namespace, specifier}, moduleEntry) {
|
|
162
|
-
const {entry, version, id} = moduleEntry;
|
|
178
|
+
async getModuleSource({ name, namespace, specifier }, moduleEntry) {
|
|
179
|
+
const { entry, version, id } = moduleEntry;
|
|
163
180
|
name = name || (0, import_shared_utils.explodeSpecifier)(specifier).name;
|
|
164
181
|
let originalSource, ownHash;
|
|
165
182
|
if (this.moduleSourceCache.has(entry)) {
|
|
@@ -170,7 +187,7 @@ var LwcModuleProvider = class {
|
|
|
170
187
|
const implicitLwc = (0, import_utils.isImplicitLwcImport)(entry, specifier);
|
|
171
188
|
originalSource = implicitLwc ? import_utils.DEFAULT_IMPLICIT_DEP : (0, import_shared_utils.readFile)(entry);
|
|
172
189
|
ownHash = (0, import_shared_utils.hashContent)(originalSource);
|
|
173
|
-
this.moduleSourceCache.set(entry, {originalSource, ownHash});
|
|
190
|
+
this.moduleSourceCache.set(entry, { originalSource, ownHash });
|
|
174
191
|
}
|
|
175
192
|
return {
|
|
176
193
|
id,
|
|
@@ -183,7 +200,7 @@ var LwcModuleProvider = class {
|
|
|
183
200
|
originalSource
|
|
184
201
|
};
|
|
185
202
|
}
|
|
186
|
-
async getModuleEntry({specifier, importer, version}, runtimeParams = {}) {
|
|
203
|
+
async getModuleEntry({ specifier, importer, version }, runtimeParams = {}) {
|
|
187
204
|
const targetSSR = !!runtimeParams.ssr;
|
|
188
205
|
const jobKey = `${specifier}@${version}@${importer}|${targetSSR ? "server" : "client"}`;
|
|
189
206
|
import_diagnostics.logger.debug({
|
|
@@ -195,10 +212,10 @@ var LwcModuleProvider = class {
|
|
|
195
212
|
return moduleEntry;
|
|
196
213
|
}
|
|
197
214
|
return this.inflightGetModuleEntryJobs.execute(jobKey, async () => {
|
|
198
|
-
return this.createModuleEntry({specifier, importer, version}, runtimeParams);
|
|
215
|
+
return this.createModuleEntry({ specifier, importer, version }, runtimeParams);
|
|
199
216
|
});
|
|
200
217
|
}
|
|
201
|
-
async createModuleEntry({specifier, importer, version}, runtimeParams) {
|
|
218
|
+
async createModuleEntry({ specifier, importer, version }, runtimeParams) {
|
|
202
219
|
const targetSSR = !!runtimeParams.ssr;
|
|
203
220
|
import_diagnostics.logger.debug({
|
|
204
221
|
label: `${this.name}`,
|
|
@@ -228,11 +245,17 @@ var LwcModuleProvider = class {
|
|
|
228
245
|
rootDir: this.rootDir
|
|
229
246
|
}
|
|
230
247
|
});
|
|
231
|
-
const registryEntry = (0, import_utils.resolveModuleSpecifier)(
|
|
248
|
+
const registryEntry = (0, import_utils.resolveModuleSpecifier)(
|
|
249
|
+
baseSpecifier,
|
|
250
|
+
this.rootDir,
|
|
251
|
+
this.modules,
|
|
252
|
+
this.packageVersionCache,
|
|
253
|
+
importer
|
|
254
|
+
);
|
|
232
255
|
import_diagnostics.logger.debug({
|
|
233
256
|
label: `${this.name}`,
|
|
234
257
|
message: "createModuleEntry:registryEntry",
|
|
235
|
-
additionalInfo: {registryEntry}
|
|
258
|
+
additionalInfo: { registryEntry }
|
|
236
259
|
});
|
|
237
260
|
moduleEntry = {
|
|
238
261
|
id: getModuleEntryCacheKey(registryEntry.specifier, registryEntry.version, targetSSR),
|
|
@@ -264,11 +287,12 @@ var LwcModuleProvider = class {
|
|
|
264
287
|
moduleEntry = {
|
|
265
288
|
...moduleEntry,
|
|
266
289
|
entry: (0, import_shared_utils.resolveFileExtension)(filePath),
|
|
290
|
+
// TODO: LWC implicit/explicit html hack
|
|
267
291
|
specifier
|
|
268
292
|
};
|
|
269
293
|
}
|
|
270
294
|
const cacheKey = getModuleEntryCacheKey(specifier, moduleEntry.version, targetSSR);
|
|
271
|
-
const finalModuleEntry = {...moduleEntry, id: cacheKey};
|
|
295
|
+
const finalModuleEntry = { ...moduleEntry, id: cacheKey };
|
|
272
296
|
this.moduleEntryVersionCache.set(cacheKey, finalModuleEntry);
|
|
273
297
|
if (!version) {
|
|
274
298
|
const importerCacheKey = getModuleEntryCacheKey(specifier, importer || this.rootDir, targetSSR);
|
|
@@ -292,4 +316,3 @@ var LwcModuleProvider = class {
|
|
|
292
316
|
return moduleEntry;
|
|
293
317
|
}
|
|
294
318
|
};
|
|
295
|
-
var src_default = LwcModuleProvider;
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
10
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
16
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
17
|
+
return to;
|
|
22
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
28
|
|
|
24
29
|
// packages/@lwrjs/lwc-module-provider/src/utils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
27
32
|
DEFAULT_IMPLICIT_DEP: () => DEFAULT_IMPLICIT_DEP,
|
|
28
33
|
EXPLICIT_CONSTANT: () => EXPLICIT_CONSTANT,
|
|
29
34
|
isImplicitLwcImport: () => isImplicitLwcImport,
|
|
30
35
|
resolveModuleSpecifier: () => resolveModuleSpecifier,
|
|
31
36
|
setUpWatcher: () => setUpWatcher
|
|
32
37
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
+
module.exports = __toCommonJS(utils_exports);
|
|
39
|
+
var import_fs = __toESM(require("fs"));
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
42
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
43
|
+
var import_dist = require("@lwc/module-resolver/dist/index.cjs");
|
|
38
44
|
var EXPLICIT_CONSTANT = "/* _implicit_dependency_ */";
|
|
39
45
|
var DEFAULT_IMPLICIT_DEP = `${EXPLICIT_CONSTANT} export default void 0`;
|
|
40
46
|
function resolveModuleSpecifier(specifier, rootDir, modules = [], packageVersionCache, importer) {
|
|
41
47
|
import_diagnostics.logger.debug({
|
|
42
48
|
label: `lwc-module-provider`,
|
|
43
49
|
message: "resolveModuleSpecifier",
|
|
44
|
-
additionalInfo: {specifier, importer}
|
|
50
|
+
additionalInfo: { specifier, importer }
|
|
45
51
|
});
|
|
46
52
|
let resolvedModule;
|
|
47
53
|
try {
|
|
@@ -62,7 +68,7 @@ function resolveModuleSpecifier(specifier, rootDir, modules = [], packageVersion
|
|
|
62
68
|
import_diagnostics.logger.debug({
|
|
63
69
|
label: `lwc-module-provider`,
|
|
64
70
|
message: "resolveModuleSpecifier:resolvedModule",
|
|
65
|
-
additionalInfo: {resolvedModule}
|
|
71
|
+
additionalInfo: { resolvedModule }
|
|
66
72
|
});
|
|
67
73
|
const moduleEntry = resolvedModule.entry;
|
|
68
74
|
let version;
|
|
@@ -74,13 +80,13 @@ function resolveModuleSpecifier(specifier, rootDir, modules = [], packageVersion
|
|
|
74
80
|
version = JSON.parse(json).version;
|
|
75
81
|
packageVersionCache.set(moduleEntry, version);
|
|
76
82
|
}
|
|
77
|
-
return {...resolvedModule, version};
|
|
83
|
+
return { ...resolvedModule, version };
|
|
78
84
|
}
|
|
79
85
|
function findClosestPackageJsonPath(filepath) {
|
|
80
86
|
let curDir = import_path.default.dirname(filepath);
|
|
81
87
|
while (true) {
|
|
82
88
|
const possiblePath = import_path.default.join(curDir, "package.json");
|
|
83
|
-
const stats = import_fs.default.statSync(possiblePath, {throwIfNoEntry: false});
|
|
89
|
+
const stats = import_fs.default.statSync(possiblePath, { throwIfNoEntry: false });
|
|
84
90
|
if (stats?.isFile()) {
|
|
85
91
|
return possiblePath;
|
|
86
92
|
} else {
|
|
@@ -123,8 +129,14 @@ function isImplicitLwcImport(entry, specifier) {
|
|
|
123
129
|
}
|
|
124
130
|
function setUpWatcher(watcherFactory, onModuleChange) {
|
|
125
131
|
const watcher = watcherFactory.createFileWatcher();
|
|
126
|
-
watcher.on(
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
watcher.on(
|
|
133
|
+
"change",
|
|
134
|
+
(0, import_shared_utils.debounce)((file) => onModuleChange(file), 500)
|
|
135
|
+
);
|
|
136
|
+
watcher.on(
|
|
137
|
+
"unlink",
|
|
138
|
+
(0, import_shared_utils.debounce)((file) => onModuleChange(file), 500)
|
|
139
|
+
);
|
|
140
|
+
watcher.on("add", (file) => import_diagnostics.logger.info({ label: `lwc-module-provider`, message: `Watching: ${file}` }));
|
|
129
141
|
return watcher;
|
|
130
142
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.24.
|
|
7
|
+
"version": "0.24.4",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/core": "^7.29.7",
|
|
37
37
|
"@babel/preset-typescript": "^7.28.5",
|
|
38
|
-
"@lwrjs/diagnostics": "0.24.
|
|
39
|
-
"@lwrjs/fs-watch": "0.24.
|
|
40
|
-
"@lwrjs/shared-utils": "0.24.
|
|
38
|
+
"@lwrjs/diagnostics": "0.24.4",
|
|
39
|
+
"@lwrjs/fs-watch": "0.24.4",
|
|
40
|
+
"@lwrjs/shared-utils": "0.24.4",
|
|
41
41
|
"fs-extra": "^11.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@lwrjs/types": "0.24.
|
|
44
|
+
"@lwrjs/types": "0.24.4",
|
|
45
45
|
"memfs": "^4.13.0",
|
|
46
46
|
"typescript": "5.0.4"
|
|
47
47
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"volta": {
|
|
56
56
|
"extends": "../../../package.json"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "63feabb6eea1340e80a82146cc1c24bfc4f2d518"
|
|
59
59
|
}
|