@ckeditor/ckeditor5-dev-manual-server 56.2.0 → 56.3.0

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/index.js CHANGED
@@ -107,7 +107,6 @@ function matchFiles(patterns, workspaceRoot) {
107
107
  * For licensing, see LICENSE.md.
108
108
  */
109
109
  const PROCESSED_MANUAL_TEST_EXTENSIONS = new Set([
110
- ".css",
111
110
  ".html",
112
111
  ".js",
113
112
  ".md",
@@ -206,8 +205,8 @@ function loadRenderedInstructions(entry, workspaceRoot) {
206
205
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
207
206
  * For licensing, see LICENSE.md.
208
207
  */
209
- function createManualShellHtml({ entry, html, shellScriptPublicPath, shellTemplateFilePath, workspaceRoot }) {
210
- const shellDocument = parse(readFileSync(shellTemplateFilePath, "utf8"));
208
+ function createManualShellHtml({ catalogPublicPath = "/", entry, html, shellScriptPublicPath, shellTemplateFilePath, workspaceRoot }) {
209
+ const shellDocument = parse(readFileSync(shellTemplateFilePath, "utf8").replace("href=\"/\" title=\"Back to test index\"", `href="${catalogPublicPath}" title="Back to test index"`));
211
210
  const shellHead = getRequiredElementByTagName$1(shellDocument, "head");
212
211
  const shellBody = getRequiredElementByTagName$1(shellDocument, "body");
213
212
  const shellTitle = getRequiredElementByTagName$1(shellHead, "title");
@@ -283,8 +282,12 @@ function isManualTestScriptNode(node, testScriptFileName) {
283
282
  if (node.tagName != "script") return false;
284
283
  const source = getAttribute(node, "src");
285
284
  if (!source) return false;
285
+ if (isExternalScriptSource$1(source)) return false;
286
286
  return getScriptModuleName(posix.basename(source.split("?")[0].split("#")[0])) == getScriptModuleName(testScriptFileName);
287
287
  }
288
+ function isExternalScriptSource$1(source) {
289
+ return source.startsWith("http://") || source.startsWith("https://") || source.startsWith("//");
290
+ }
288
291
  function getScriptModuleName(fileName) {
289
292
  return fileName.replace(/\.[jt]s$/, "");
290
293
  }
@@ -311,6 +314,7 @@ const MANUAL_SHELL_TEMPLATE_FILE_PATH = resolve(MANUAL_THEME_ROOT, "shell.html")
311
314
  const MANUAL_SHELL_SCRIPT_FILE_PATH = resolve(MANUAL_THEME_ROOT, "shell.ts");
312
315
  function manualTestsPlugin(manualTestPatterns) {
313
316
  let workspaceRoot = process.cwd();
317
+ let base = "/";
314
318
  const manualPagePatterns = manualTestPatterns.map(toManualPagePattern);
315
319
  const manualPagesCache = cacheValue(() => collectManualPages(manualPagePatterns, workspaceRoot));
316
320
  const manualStaticAssetsCache = cacheValue(() => collectManualStaticAssets(manualTestPatterns, workspaceRoot));
@@ -324,13 +328,15 @@ function manualTestsPlugin(manualTestPatterns) {
324
328
  return getManualPages().get(toPublicSpecifier(relative(workspaceRoot, filePath)));
325
329
  };
326
330
  const getManualCatalogPublicPath = () => toPublicFilePath(MANUAL_CATALOG_FILE_PATH, workspaceRoot);
331
+ const getManualCatalogBuildInputFilePath = () => resolve(workspaceRoot, "index.html");
327
332
  const getManualCatalogScriptPublicPath = () => toPublicFilePath(MANUAL_CATALOG_SCRIPT_FILE_PATH, workspaceRoot);
328
333
  const getManualShellScriptPublicPath = () => toPublicFilePath(MANUAL_SHELL_SCRIPT_FILE_PATH, workspaceRoot);
329
- const getManualBuildInputs = () => [MANUAL_CATALOG_FILE_PATH, ...[...getManualPages().values()].map((entry) => resolve(workspaceRoot, entry.htmlFilePath.slice(1)))];
334
+ const getManualCatalogClientPath = (entry) => toBaseCatalogPath(base, entry.htmlFilePath);
335
+ const getManualBuildInputs = () => [getManualCatalogBuildInputFilePath(), ...[...getManualPages().values()].map((entry) => resolve(workspaceRoot, entry.htmlFilePath.slice(1)))];
330
336
  const resolvedVirtualModuleId = `\0${MANUAL_ENTRIES_VIRTUAL_ID}`;
331
337
  const getClientEntries = () => [...getManualPages().values()].map((entry) => ({
332
338
  displayName: entry.displayName,
333
- href: entry.htmlFilePath,
339
+ href: toBasePublicPath(entry.htmlFilePath, base),
334
340
  packageName: entry.packageName,
335
341
  slug: entry.slug
336
342
  }));
@@ -342,23 +348,23 @@ function manualTestsPlugin(manualTestPatterns) {
342
348
  },
343
349
  configResolved(config) {
344
350
  workspaceRoot = config.root;
351
+ base = config.base || "/";
345
352
  invalidateManualFileCaches();
346
353
  config.build.rolldownOptions.input = getManualBuildInputs();
347
354
  },
348
355
  configureServer(server) {
349
356
  const { memoryFiles } = server.environments.client;
350
357
  useManualTestMiddlewares(server, getManualCatalogPublicPath, getManualStaticAssets);
351
- useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, () => workspaceRoot);
352
- },
353
- configurePreviewServer(server) {
354
- useManualCatalogMiddleware(server, getManualCatalogPublicPath);
358
+ useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getManualCatalogClientPath, () => workspaceRoot);
355
359
  },
356
360
  resolveId(source) {
357
361
  if (source == MANUAL_ENTRIES_VIRTUAL_ID) return resolvedVirtualModuleId;
362
+ if (isManualCatalogBuildInputSpecifier(source, getManualCatalogBuildInputFilePath(), workspaceRoot)) return getManualCatalogBuildInputFilePath();
358
363
  return null;
359
364
  },
360
365
  load(id) {
361
366
  if (id == resolvedVirtualModuleId) return `export const manualTestEntries = ${getManualEntriesJson()};`;
367
+ if (toPosixPath(id) == toPosixPath(getManualCatalogBuildInputFilePath())) return readFileSync(MANUAL_CATALOG_FILE_PATH, "utf8");
362
368
  return null;
363
369
  },
364
370
  generateBundle() {
@@ -371,10 +377,11 @@ function manualTestsPlugin(manualTestPatterns) {
371
377
  transformIndexHtml: {
372
378
  order: "pre",
373
379
  handler(html, context) {
374
- if (toPosixPath(context.filename) == toPosixPath(MANUAL_CATALOG_FILE_PATH)) return html.replace("./catalog.ts", getManualCatalogScriptPublicPath());
380
+ if (isManualCatalogHtmlFile(context.filename, getManualCatalogBuildInputFilePath())) return html.replace("./catalog.ts", getManualCatalogScriptPublicPath());
375
381
  const entry = getManualPageEntryForFile(context.filename);
376
382
  if (!entry) return;
377
383
  return createManualShellHtml({
384
+ catalogPublicPath: getManualCatalogClientPath(entry),
378
385
  entry,
379
386
  html,
380
387
  shellScriptPublicPath: getManualShellScriptPublicPath(),
@@ -395,7 +402,7 @@ function useManualCatalogMiddleware(server, getManualCatalogPublicPath) {
395
402
  next();
396
403
  });
397
404
  }
398
- function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getWorkspaceRoot) {
405
+ function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getManualCatalogClientPath, getWorkspaceRoot) {
399
406
  if (!memoryFiles) return;
400
407
  const getBundledFile = memoryFiles.get.bind(memoryFiles);
401
408
  memoryFiles.get = (filePath) => {
@@ -406,6 +413,7 @@ function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShe
406
413
  const shellScriptPublicPath = getManualShellScriptPublicPath();
407
414
  const bundledHtml = getFileSource(file);
408
415
  return { source: mergeBundledAssetTags(createManualShellHtml({
416
+ catalogPublicPath: getManualCatalogClientPath(entry),
409
417
  entry,
410
418
  html: readFileSync(resolve(workspaceRoot, stripLeadingSlash(entry.htmlFilePath)), "utf8"),
411
419
  shellScriptPublicPath,
@@ -421,6 +429,21 @@ function toManualPagePattern(pattern) {
421
429
  if (/\.(?:html|js|md|ts|\{[^}]*\})$/.test(pattern)) return pattern;
422
430
  return `${pattern}.{html,js,md,ts}`;
423
431
  }
432
+ function isManualCatalogHtmlFile(filePath, catalogBuildInputFilePath) {
433
+ const normalizedFilePath = toPosixPath(filePath);
434
+ return normalizedFilePath == toPosixPath(MANUAL_CATALOG_FILE_PATH) || normalizedFilePath == toPosixPath(catalogBuildInputFilePath);
435
+ }
436
+ function isManualCatalogBuildInputSpecifier(source, catalogBuildInputFilePath, workspaceRoot) {
437
+ return toPosixPath(resolve(workspaceRoot, source)) == toPosixPath(catalogBuildInputFilePath);
438
+ }
439
+ function toBasePublicPath(publicPath, base) {
440
+ if (base == "" || base == "./") return `.${publicPath}`;
441
+ return `${base.replace(/\/$/, "")}${publicPath}`;
442
+ }
443
+ function toBaseCatalogPath(base, entryHtmlFilePath) {
444
+ if (base == "" || base == "./") return posix.relative(posix.dirname(stripLeadingSlash(entryHtmlFilePath)), "index.html");
445
+ return base;
446
+ }
424
447
  function mergeBundledAssetTags(sourceHtml, bundledHtml, entry, shellScriptPublicPath) {
425
448
  const sourceDocument = parse(sourceHtml);
426
449
  const bundledDocument = parse(bundledHtml);
@@ -439,8 +462,12 @@ function isSourceTestScript(node, testScriptFileName) {
439
462
  if (!isElementNode(node) || node.tagName != "script") return false;
440
463
  const source = getAttribute(node, "src");
441
464
  if (!source) return false;
465
+ if (isExternalScriptSource(source)) return false;
442
466
  return posix.basename(source) == testScriptFileName;
443
467
  }
468
+ function isExternalScriptSource(source) {
469
+ return source.startsWith("http://") || source.startsWith("https://") || source.startsWith("//");
470
+ }
444
471
  function isSourceShellScript(node, shellScriptPublicPath) {
445
472
  return isElementNode(node) && node.tagName == "script" && getAttribute(node, "src") == shellScriptPublicPath;
446
473
  }
@@ -4,10 +4,11 @@
4
4
  */
5
5
  import type { ManualPageEntry } from "./types.js";
6
6
  export interface CreateManualShellHtmlOptions {
7
+ catalogPublicPath?: string;
7
8
  entry: ManualPageEntry;
8
9
  html: string;
9
10
  shellScriptPublicPath: string;
10
11
  shellTemplateFilePath: string;
11
12
  workspaceRoot: string;
12
13
  }
13
- export declare function createManualShellHtml({ entry, html, shellScriptPublicPath, shellTemplateFilePath, workspaceRoot }: CreateManualShellHtmlOptions): string;
14
+ export declare function createManualShellHtml({ catalogPublicPath, entry, html, shellScriptPublicPath, shellTemplateFilePath, workspaceRoot }: CreateManualShellHtmlOptions): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-dev-manual-server",
3
- "version": "56.2.0",
3
+ "version": "56.3.0",
4
4
  "description": "Used to extend Vite to create a manual test server for CKEditor 5.",
5
5
  "keywords": [],
6
6
  "author": "CKSource (http://cksource.com/)",