@lexibase/rdx-core 3.6.0 → 3.6.1
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/dist/check/index.js +49 -9
- package/package.json +1 -1
package/dist/check/index.js
CHANGED
|
@@ -155,34 +155,65 @@ function checkDocumentation(project, options = {}) {
|
|
|
155
155
|
message: value.message ?? String(error)
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
const publicRoot = path.resolve(project.rootDir, "public");
|
|
159
|
+
const publicDirectories = /* @__PURE__ */ new Map();
|
|
160
|
+
function findPublicFile(pathname) {
|
|
159
161
|
if (pathname.includes("\\") || pathname.includes("\0"))
|
|
160
162
|
throw new Error("Use a valid URL with forward slashes.");
|
|
161
|
-
const publicRoot = path.resolve(project.rootDir, "public");
|
|
162
163
|
const asset = path.resolve(publicRoot, `.${pathname}`);
|
|
163
164
|
const relative = path.relative(publicRoot, asset);
|
|
164
165
|
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
165
166
|
throw new Error("The destination escapes public/.");
|
|
166
|
-
let exists = false;
|
|
167
167
|
try {
|
|
168
|
-
|
|
168
|
+
const segments = [];
|
|
169
|
+
let directory = publicRoot;
|
|
170
|
+
for (const segment of relative.split(path.sep)) {
|
|
171
|
+
let entries = publicDirectories.get(directory);
|
|
172
|
+
if (!entries) {
|
|
173
|
+
entries = new Set(fs.readdirSync(directory));
|
|
174
|
+
publicDirectories.set(directory, entries);
|
|
175
|
+
}
|
|
176
|
+
let name = segment;
|
|
177
|
+
if (!entries.has(segment)) {
|
|
178
|
+
const folded = segment.toLowerCase();
|
|
179
|
+
const matches = [...entries].filter(
|
|
180
|
+
(entry) => entry.toLowerCase() === folded
|
|
181
|
+
);
|
|
182
|
+
if (matches.length !== 1) return;
|
|
183
|
+
name = matches[0];
|
|
184
|
+
}
|
|
185
|
+
segments.push(name);
|
|
186
|
+
directory = path.join(directory, name);
|
|
187
|
+
}
|
|
188
|
+
if (fs.statSync(directory).isFile())
|
|
189
|
+
return {
|
|
190
|
+
correctedPath: segments.join(path.sep) === relative ? void 0 : `/${segments.map(encodeURIComponent).join("/")}`
|
|
191
|
+
};
|
|
169
192
|
} catch {
|
|
170
193
|
}
|
|
171
|
-
return exists;
|
|
172
194
|
}
|
|
195
|
+
const caseMismatch = "The path must match the capitalization on disk in public/.";
|
|
173
196
|
const logo = project.config.navbar?.logo;
|
|
174
197
|
if (typeof logo === "string") {
|
|
198
|
+
let suggestion;
|
|
175
199
|
try {
|
|
176
|
-
const
|
|
177
|
-
|
|
200
|
+
const url = new URL(logo, origin);
|
|
201
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
202
|
+
const asset = findPublicFile(pathname);
|
|
203
|
+
if (!asset)
|
|
178
204
|
throw new Error(`Local file "${pathname}" does not exist in public/.`);
|
|
205
|
+
if (asset.correctedPath) {
|
|
206
|
+
suggestion = `${asset.correctedPath}${url.search}${url.hash}`;
|
|
207
|
+
throw new Error(caseMismatch);
|
|
208
|
+
}
|
|
179
209
|
} catch (error) {
|
|
180
210
|
diagnostics.push({
|
|
181
211
|
file: "rdx.config.ts",
|
|
182
212
|
line: 1,
|
|
183
213
|
column: 1,
|
|
184
214
|
code: "asset",
|
|
185
|
-
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}
|
|
215
|
+
message: `navbar.logo "${logo}": ${error instanceof Error ? error.message : String(error)}`,
|
|
216
|
+
...suggestion ? { suggestion } : {}
|
|
186
217
|
});
|
|
187
218
|
}
|
|
188
219
|
}
|
|
@@ -449,7 +480,16 @@ function checkDocumentation(project, options = {}) {
|
|
|
449
480
|
}
|
|
450
481
|
if (!reference.image && roots.has(pathname)) continue;
|
|
451
482
|
code = reference.image || !/^\/(?:[^/]+\/)?docs(?:\/|$)/.test(pathname) ? "asset" : "page";
|
|
452
|
-
|
|
483
|
+
const asset = findPublicFile(pathname);
|
|
484
|
+
if (asset?.correctedPath) {
|
|
485
|
+
code = "asset";
|
|
486
|
+
const absolute = /^(?:https?:|\/\/)/i.test(reference.href);
|
|
487
|
+
const basePath = project.config.basePath;
|
|
488
|
+
const prefix = absolute && basePath && url.pathname.startsWith(`${basePath}/`) ? basePath : "";
|
|
489
|
+
suggestion = `${absolute ? url.origin : ""}${prefix}${asset.correctedPath}${url.search}${url.hash}`;
|
|
490
|
+
throw new Error(caseMismatch);
|
|
491
|
+
}
|
|
492
|
+
if (!asset) {
|
|
453
493
|
if (code === "page") {
|
|
454
494
|
const edition = redirectSources.filter(({ root }) => pathname.startsWith(`${key(root)}/`)).sort((a, b) => b.root.length - a.root.length)[0];
|
|
455
495
|
const match = edition && closestMatch(
|