@lwrjs/lwc-module-provider 0.12.0-alpha.3 → 0.12.0-alpha.30
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/utils.cjs +23 -5
- package/build/es/utils.js +29 -5
- package/package.json +8 -8
package/build/cjs/utils.cjs
CHANGED
|
@@ -61,17 +61,35 @@ function resolveModuleSpecifier(specifier, importer, modules = [], packageVersio
|
|
|
61
61
|
message: "resolveModuleSpecifier:resolvedModule",
|
|
62
62
|
additionalInfo: {resolvedModule}
|
|
63
63
|
});
|
|
64
|
-
const
|
|
64
|
+
const moduleEntry = resolvedModule.entry;
|
|
65
65
|
let version;
|
|
66
|
-
if (packageVersionCache.has(
|
|
67
|
-
version = packageVersionCache.get(
|
|
66
|
+
if (packageVersionCache.has(moduleEntry)) {
|
|
67
|
+
version = packageVersionCache.get(moduleEntry);
|
|
68
68
|
} else {
|
|
69
|
-
const
|
|
69
|
+
const packageJsonPath = findClosestPackageJsonPath(moduleEntry) ?? import_path.default.join(resolvedModule.scope, "package.json");
|
|
70
|
+
const json = (0, import_shared_utils.readFile)(packageJsonPath);
|
|
70
71
|
version = JSON.parse(json).version;
|
|
71
|
-
packageVersionCache.set(
|
|
72
|
+
packageVersionCache.set(moduleEntry, version);
|
|
72
73
|
}
|
|
73
74
|
return {...resolvedModule, version};
|
|
74
75
|
}
|
|
76
|
+
function findClosestPackageJsonPath(filepath) {
|
|
77
|
+
let curDir = import_path.default.dirname(filepath);
|
|
78
|
+
while (true) {
|
|
79
|
+
const possiblePath = import_path.default.join(curDir, "package.json");
|
|
80
|
+
const stats = import_fs.default.statSync(possiblePath, {throwIfNoEntry: false});
|
|
81
|
+
if (stats?.isFile()) {
|
|
82
|
+
return possiblePath;
|
|
83
|
+
} else {
|
|
84
|
+
const curParentDir = import_path.default.dirname(curDir);
|
|
85
|
+
if (curDir !== curParentDir) {
|
|
86
|
+
curDir = curParentDir;
|
|
87
|
+
} else {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
75
93
|
function isImplicitLwcImport(entry, specifier) {
|
|
76
94
|
const [, fileRelativePathQs] = specifier.split("#");
|
|
77
95
|
const fileRelativePath = fileRelativePathQs?.split("?")[0];
|
package/build/es/utils.js
CHANGED
|
@@ -31,18 +31,42 @@ export function resolveModuleSpecifier(specifier, importer, modules = [], packag
|
|
|
31
31
|
message: 'resolveModuleSpecifier:resolvedModule',
|
|
32
32
|
additionalInfo: { resolvedModule },
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const moduleEntry = resolvedModule.entry;
|
|
35
35
|
let version;
|
|
36
|
-
if (packageVersionCache.has(
|
|
37
|
-
version = packageVersionCache.get(
|
|
36
|
+
if (packageVersionCache.has(moduleEntry)) {
|
|
37
|
+
version = packageVersionCache.get(moduleEntry);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
|
|
40
|
+
// Find the closest package.json file from the module entry. If none exists (possible with dir or alias module
|
|
41
|
+
// records), fall back to using the "scope" from which the module is being imported.
|
|
42
|
+
const packageJsonPath = findClosestPackageJsonPath(moduleEntry) ?? path.join(resolvedModule.scope, 'package.json');
|
|
43
|
+
const json = readFile(packageJsonPath);
|
|
41
44
|
version = JSON.parse(json).version;
|
|
42
|
-
packageVersionCache.set(
|
|
45
|
+
packageVersionCache.set(moduleEntry, version);
|
|
43
46
|
}
|
|
44
47
|
return { ...resolvedModule, version };
|
|
45
48
|
}
|
|
49
|
+
// Search upwards until a package.json file is found.
|
|
50
|
+
function findClosestPackageJsonPath(filepath) {
|
|
51
|
+
let curDir = path.dirname(filepath);
|
|
52
|
+
// eslint-disable-next-line no-constant-condition
|
|
53
|
+
while (true) {
|
|
54
|
+
const possiblePath = path.join(curDir, 'package.json');
|
|
55
|
+
const stats = fs.statSync(possiblePath, { throwIfNoEntry: false });
|
|
56
|
+
if (stats?.isFile()) {
|
|
57
|
+
return possiblePath;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const curParentDir = path.dirname(curDir);
|
|
61
|
+
if (curDir !== curParentDir) {
|
|
62
|
+
curDir = curParentDir;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
46
70
|
// An implicit import is dependency that the LWC includes automatically to "auto-magically" bind JS, HTML and CSS
|
|
47
71
|
// Sometimes this file might not exist, in which case we need to provide a default
|
|
48
72
|
export function isImplicitLwcImport(entry, specifier) {
|
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.30",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@babel/preset-typescript": "^7.
|
|
34
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
35
|
-
"@lwrjs/fs-watch": "0.12.0-alpha.
|
|
36
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
37
|
-
"fs-extra": "^11.
|
|
33
|
+
"@babel/preset-typescript": "^7.24.1",
|
|
34
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.30",
|
|
35
|
+
"@lwrjs/fs-watch": "0.12.0-alpha.30",
|
|
36
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.30",
|
|
37
|
+
"fs-extra": "^11.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
40
|
+
"@lwrjs/types": "0.12.0-alpha.30",
|
|
41
41
|
"typescript": "^4.9.5"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18.0.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5273cb7ece90a3a28645cb1dfde9d315548605db"
|
|
51
51
|
}
|