@ckeditor/ckeditor5-dev-manual-server 56.2.1 → 56.4.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.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * For licensing, see LICENSE.md.
4
4
  */
5
5
  export { manualTestsPlugin } from "./manual-test-plugin/plugin.js";
6
- export type { ManualData } from "./manual-test-plugin/plugin.js";
6
+ export type { ManualData, ManualTestsPluginOptions } from "./manual-test-plugin/plugin.js";
7
7
  export { refreshPlugin } from "./refresh-plugin/plugin.js";
8
8
  export { rawHtmlPlugin } from "./raw-plugin/plugin.js";
9
9
  export { stringifyValues } from "./utils.js";
package/dist/index.js CHANGED
@@ -205,8 +205,8 @@ function loadRenderedInstructions(entry, workspaceRoot) {
205
205
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
206
206
  * For licensing, see LICENSE.md.
207
207
  */
208
- function createManualShellHtml({ entry, html, shellScriptPublicPath, shellTemplateFilePath, workspaceRoot }) {
209
- 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"`));
210
210
  const shellHead = getRequiredElementByTagName$1(shellDocument, "head");
211
211
  const shellBody = getRequiredElementByTagName$1(shellDocument, "body");
212
212
  const shellTitle = getRequiredElementByTagName$1(shellHead, "title");
@@ -312,12 +312,15 @@ const MANUAL_CATALOG_FILE_PATH = resolve(MANUAL_THEME_ROOT, "catalog.html");
312
312
  const MANUAL_CATALOG_SCRIPT_FILE_PATH = resolve(MANUAL_THEME_ROOT, "catalog.ts");
313
313
  const MANUAL_SHELL_TEMPLATE_FILE_PATH = resolve(MANUAL_THEME_ROOT, "shell.html");
314
314
  const MANUAL_SHELL_SCRIPT_FILE_PATH = resolve(MANUAL_THEME_ROOT, "shell.ts");
315
- function manualTestsPlugin(manualTestPatterns) {
315
+ function manualTestsPlugin(options) {
316
316
  let workspaceRoot = process.cwd();
317
+ let base = "/";
318
+ const manualTestPatterns = options.paths;
317
319
  const manualPagePatterns = manualTestPatterns.map(toManualPagePattern);
318
- const manualPagesCache = cacheValue(() => collectManualPages(manualPagePatterns, workspaceRoot));
319
- const manualStaticAssetsCache = cacheValue(() => collectManualStaticAssets(manualTestPatterns, workspaceRoot));
320
+ const includePackageNames = (options.include || []).filter(Boolean);
321
+ const manualPagesCache = cacheValue(() => filterManualPages(collectManualPages(manualPagePatterns, workspaceRoot), includePackageNames));
320
322
  const getManualPages = manualPagesCache.get;
323
+ const manualStaticAssetsCache = cacheValue(() => collectManualStaticAssets(getManualStaticAssetPatterns(getManualPages(), manualTestPatterns, includePackageNames), workspaceRoot));
321
324
  const getManualStaticAssets = manualStaticAssetsCache.get;
322
325
  const invalidateManualFileCaches = () => {
323
326
  manualPagesCache.invalidate();
@@ -326,14 +329,16 @@ function manualTestsPlugin(manualTestPatterns) {
326
329
  const getManualPageEntryForFile = (filePath) => {
327
330
  return getManualPages().get(toPublicSpecifier(relative(workspaceRoot, filePath)));
328
331
  };
329
- const getManualCatalogPublicPath = () => toPublicFilePath(MANUAL_CATALOG_FILE_PATH, workspaceRoot);
332
+ const getManualCatalogBuildInputFilePath = () => resolve(workspaceRoot, "index.html");
333
+ const getManualCatalogPublicPath = () => toPublicFilePath(getManualCatalogBuildInputFilePath(), workspaceRoot);
330
334
  const getManualCatalogScriptPublicPath = () => toPublicFilePath(MANUAL_CATALOG_SCRIPT_FILE_PATH, workspaceRoot);
331
335
  const getManualShellScriptPublicPath = () => toPublicFilePath(MANUAL_SHELL_SCRIPT_FILE_PATH, workspaceRoot);
332
- const getManualBuildInputs = () => [MANUAL_CATALOG_FILE_PATH, ...[...getManualPages().values()].map((entry) => resolve(workspaceRoot, entry.htmlFilePath.slice(1)))];
336
+ const getManualCatalogClientPath = (entry) => toBaseCatalogPath(base, entry.htmlFilePath);
337
+ const getManualBuildInputs = () => [getManualCatalogBuildInputFilePath(), ...[...getManualPages().values()].map((entry) => resolve(workspaceRoot, entry.htmlFilePath.slice(1)))];
333
338
  const resolvedVirtualModuleId = `\0${MANUAL_ENTRIES_VIRTUAL_ID}`;
334
339
  const getClientEntries = () => [...getManualPages().values()].map((entry) => ({
335
340
  displayName: entry.displayName,
336
- href: entry.htmlFilePath,
341
+ href: toBasePublicPath(entry.htmlFilePath, base),
337
342
  packageName: entry.packageName,
338
343
  slug: entry.slug
339
344
  }));
@@ -345,23 +350,23 @@ function manualTestsPlugin(manualTestPatterns) {
345
350
  },
346
351
  configResolved(config) {
347
352
  workspaceRoot = config.root;
353
+ base = config.base || "/";
348
354
  invalidateManualFileCaches();
349
355
  config.build.rolldownOptions.input = getManualBuildInputs();
350
356
  },
351
357
  configureServer(server) {
352
358
  const { memoryFiles } = server.environments.client;
353
359
  useManualTestMiddlewares(server, getManualCatalogPublicPath, getManualStaticAssets);
354
- useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, () => workspaceRoot);
355
- },
356
- configurePreviewServer(server) {
357
- useManualCatalogMiddleware(server, getManualCatalogPublicPath);
360
+ useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getManualCatalogClientPath, () => workspaceRoot);
358
361
  },
359
362
  resolveId(source) {
360
363
  if (source == MANUAL_ENTRIES_VIRTUAL_ID) return resolvedVirtualModuleId;
364
+ if (isManualCatalogBuildInputSpecifier(source, getManualCatalogBuildInputFilePath(), workspaceRoot)) return getManualCatalogBuildInputFilePath();
361
365
  return null;
362
366
  },
363
367
  load(id) {
364
368
  if (id == resolvedVirtualModuleId) return `export const manualTestEntries = ${getManualEntriesJson()};`;
369
+ if (toPosixPath(id) == toPosixPath(getManualCatalogBuildInputFilePath())) return readFileSync(MANUAL_CATALOG_FILE_PATH, "utf8");
365
370
  return null;
366
371
  },
367
372
  generateBundle() {
@@ -374,10 +379,11 @@ function manualTestsPlugin(manualTestPatterns) {
374
379
  transformIndexHtml: {
375
380
  order: "pre",
376
381
  handler(html, context) {
377
- if (toPosixPath(context.filename) == toPosixPath(MANUAL_CATALOG_FILE_PATH)) return html.replace("./catalog.ts", getManualCatalogScriptPublicPath());
382
+ if (isManualCatalogHtmlFile(context.filename, getManualCatalogBuildInputFilePath())) return html.replace("./catalog.ts", getManualCatalogScriptPublicPath());
378
383
  const entry = getManualPageEntryForFile(context.filename);
379
384
  if (!entry) return;
380
385
  return createManualShellHtml({
386
+ catalogPublicPath: getManualCatalogClientPath(entry),
381
387
  entry,
382
388
  html,
383
389
  shellScriptPublicPath: getManualShellScriptPublicPath(),
@@ -398,7 +404,7 @@ function useManualCatalogMiddleware(server, getManualCatalogPublicPath) {
398
404
  next();
399
405
  });
400
406
  }
401
- function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getWorkspaceRoot) {
407
+ function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShellScriptPublicPath, getManualCatalogClientPath, getWorkspaceRoot) {
402
408
  if (!memoryFiles) return;
403
409
  const getBundledFile = memoryFiles.get.bind(memoryFiles);
404
410
  memoryFiles.get = (filePath) => {
@@ -409,6 +415,7 @@ function useBundledDevManualHtmlSource(memoryFiles, getManualPages, getManualShe
409
415
  const shellScriptPublicPath = getManualShellScriptPublicPath();
410
416
  const bundledHtml = getFileSource(file);
411
417
  return { source: mergeBundledAssetTags(createManualShellHtml({
418
+ catalogPublicPath: getManualCatalogClientPath(entry),
412
419
  entry,
413
420
  html: readFileSync(resolve(workspaceRoot, stripLeadingSlash(entry.htmlFilePath)), "utf8"),
414
421
  shellScriptPublicPath,
@@ -424,6 +431,38 @@ function toManualPagePattern(pattern) {
424
431
  if (/\.(?:html|js|md|ts|\{[^}]*\})$/.test(pattern)) return pattern;
425
432
  return `${pattern}.{html,js,md,ts}`;
426
433
  }
434
+ function filterManualPages(manualPages, includePackageNames) {
435
+ if (includePackageNames.length == 0) return manualPages;
436
+ const normalizedIncludePackageNames = new Set(includePackageNames.map(normalizePackageName));
437
+ return new Map([...manualPages].filter(([, entry]) => normalizedIncludePackageNames.has(normalizePackageName(entry.packageName))));
438
+ }
439
+ function normalizePackageName(packageName) {
440
+ return packageName.replace(/^ckeditor5-/, "");
441
+ }
442
+ function getManualStaticAssetPatterns(manualPages, manualTestPatterns, includePackageNames) {
443
+ if (includePackageNames.length == 0) return manualTestPatterns;
444
+ return [...new Set([...manualPages.values()].map(getManualTestRootDirectory))].map((manualTestRootDirectory) => `${manualTestRootDirectory}/**/*`);
445
+ }
446
+ function getManualTestRootDirectory(entry) {
447
+ const htmlFilePath = stripLeadingSlash(entry.htmlFilePath);
448
+ const manualDirectoryIndex = htmlFilePath.indexOf("/tests/manual/");
449
+ return htmlFilePath.slice(0, manualDirectoryIndex + 14 - 1);
450
+ }
451
+ function isManualCatalogHtmlFile(filePath, catalogBuildInputFilePath) {
452
+ const normalizedFilePath = toPosixPath(filePath);
453
+ return normalizedFilePath == toPosixPath(MANUAL_CATALOG_FILE_PATH) || normalizedFilePath == toPosixPath(catalogBuildInputFilePath);
454
+ }
455
+ function isManualCatalogBuildInputSpecifier(source, catalogBuildInputFilePath, workspaceRoot) {
456
+ return toPosixPath(resolve(workspaceRoot, source)) == toPosixPath(catalogBuildInputFilePath);
457
+ }
458
+ function toBasePublicPath(publicPath, base) {
459
+ if (base == "" || base == "./") return `.${publicPath}`;
460
+ return `${base.replace(/\/$/, "")}${publicPath}`;
461
+ }
462
+ function toBaseCatalogPath(base, entryHtmlFilePath) {
463
+ if (base == "" || base == "./") return posix.relative(posix.dirname(stripLeadingSlash(entryHtmlFilePath)), "index.html");
464
+ return base;
465
+ }
427
466
  function mergeBundledAssetTags(sourceHtml, bundledHtml, entry, shellScriptPublicPath) {
428
467
  const sourceDocument = parse(sourceHtml);
429
468
  const bundledDocument = parse(bundledHtml);
@@ -4,4 +4,8 @@
4
4
  */
5
5
  import type { Plugin } from "vite";
6
6
  export type { ManualData } from "./types.js";
7
- export declare function manualTestsPlugin(manualTestPatterns: Array<string>): Plugin;
7
+ export interface ManualTestsPluginOptions {
8
+ paths: Array<string>;
9
+ include?: Array<string>;
10
+ }
11
+ export declare function manualTestsPlugin(options: ManualTestsPluginOptions): Plugin;
@@ -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.1",
3
+ "version": "56.4.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/)",