@ckeditor/ckeditor5-dev-manual-server 57.2.0 → 57.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.
Files changed (2) hide show
  1. package/dist/index.js +35 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createReadStream, globSync, readFileSync, realpathSync, statSync } from "node:fs";
1
+ import { createReadStream, existsSync, globSync, readFileSync, realpathSync, statSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { basename, extname, isAbsolute, posix, relative, resolve } from "node:path";
4
4
  //#region src/utils.ts
@@ -61,8 +61,8 @@ function stripLeadingSlash(value) {
61
61
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
62
62
  * For licensing, see LICENSE.md.
63
63
  */
64
- const MANUAL_TESTS_DIRECTORY = "tests/manual/";
65
- const MANUAL_TEST_SUFFIX$1 = ".manual.html";
64
+ const MANUAL_TESTS_DIRECTORY$1 = "tests/manual/";
65
+ const MANUAL_TEST_SUFFIX$2 = ".manual.html";
66
66
  /**
67
67
  * Discovers manual test pages. A manual test is a single full HTML document named
68
68
  * `<slug>.manual.html` located under a package's `tests/manual/` directory. Plain `.html`
@@ -75,10 +75,10 @@ function collectManualPages(patterns, workspaceRoot) {
75
75
  return new Map(manualPages);
76
76
  }
77
77
  function matchManualPageFiles(patterns, workspaceRoot) {
78
- return patterns.map((pattern) => `${pattern.replace(/\/+$/, "")}/${MANUAL_TESTS_DIRECTORY}**/*${MANUAL_TEST_SUFFIX$1}`).flatMap((pattern) => globSync(pattern, { cwd: workspaceRoot }).map((match) => toPosixPath(match)));
78
+ return patterns.map((pattern) => `${pattern.replace(/\/+$/, "")}/${MANUAL_TESTS_DIRECTORY$1}**/*${MANUAL_TEST_SUFFIX$2}`).flatMap((pattern) => globSync(pattern, { cwd: workspaceRoot }).map((match) => toPosixPath(match)));
79
79
  }
80
80
  function toManualPageEntry(relativeFilePath, workspaceRoot) {
81
- const directoryStartIndex = relativeFilePath.startsWith(MANUAL_TESTS_DIRECTORY) ? 0 : relativeFilePath.indexOf(`/${MANUAL_TESTS_DIRECTORY}`) + 1;
81
+ const directoryStartIndex = relativeFilePath.startsWith(MANUAL_TESTS_DIRECTORY$1) ? 0 : relativeFilePath.indexOf(`/${MANUAL_TESTS_DIRECTORY$1}`) + 1;
82
82
  const packagePath = relativeFilePath.slice(0, Math.max(directoryStartIndex - 1, 0));
83
83
  const slugPath = relativeFilePath.slice(directoryStartIndex + 13);
84
84
  return {
@@ -94,6 +94,9 @@ function toManualPageEntry(relativeFilePath, workspaceRoot) {
94
94
  * For licensing, see LICENSE.md.
95
95
  */
96
96
  const MANUAL_HEADER_ELEMENT = "ck-manual-header";
97
+ const MANUAL_TEST_SUFFIX$1 = ".manual.html";
98
+ const MANUAL_TESTS_DIRECTORY = "/tests/manual/";
99
+ const THEME_ENTRY_FILE_PATH = "theme/index.css";
97
100
  const MANUAL_ENTRIES_VIRTUAL_ID = "virtual:ckeditor5-manual-entries";
98
101
  const MANUAL_THEME_ROOT = realpathSync(fileURLToPath(import.meta.resolve("@ckeditor/ckeditor5-dev-manual-server/theme")));
99
102
  const MANUAL_CATALOG_FILE_PATH = resolve(MANUAL_THEME_ROOT, "catalog.html");
@@ -109,6 +112,18 @@ function manualTestsPlugin(options) {
109
112
  const getManualPageEntryForFile = (filePath) => {
110
113
  return getManualPages().get(toPublicSpecifier(relative(workspaceRoot, filePath)));
111
114
  };
115
+ const getManualPageEntryForScriptSpecifier = (scriptSpecifier) => {
116
+ const htmlSpecifier = scriptSpecifier.replace(/\.(?:js|ts)$/, MANUAL_TEST_SUFFIX$1);
117
+ return htmlSpecifier == scriptSpecifier ? void 0 : getManualPages().get(htmlSpecifier);
118
+ };
119
+ const packageThemeEntryCache = /* @__PURE__ */ new Map();
120
+ const hasPackageThemeEntry = (packageRootSpecifier) => {
121
+ if (!packageThemeEntryCache.has(packageRootSpecifier)) {
122
+ const themeEntryFilePath = resolve(workspaceRoot, stripLeadingSlash(packageRootSpecifier), THEME_ENTRY_FILE_PATH);
123
+ packageThemeEntryCache.set(packageRootSpecifier, existsSync(themeEntryFilePath));
124
+ }
125
+ return packageThemeEntryCache.get(packageRootSpecifier);
126
+ };
112
127
  const getManualCatalogBuildInputFilePath = () => resolve(workspaceRoot, "index.html");
113
128
  const getManualCatalogPublicPath = () => toPublicFilePath(getManualCatalogBuildInputFilePath(), workspaceRoot);
114
129
  const getManualCatalogScriptPublicPath = () => toPublicFilePath(MANUAL_CATALOG_SCRIPT_FILE_PATH, workspaceRoot);
@@ -131,6 +146,7 @@ function manualTestsPlugin(options) {
131
146
  workspaceRoot = config.root;
132
147
  base = config.base || "/";
133
148
  manualPagesCache.invalidate();
149
+ packageThemeEntryCache.clear();
134
150
  config.build.rolldownOptions.input = getManualBuildInputs();
135
151
  },
136
152
  configureServer(server) {
@@ -151,6 +167,20 @@ function manualTestsPlugin(options) {
151
167
  if (toPosixPath(id) == toPosixPath(getManualCatalogBuildInputFilePath())) return readFileSync(MANUAL_CATALOG_FILE_PATH, "utf8");
152
168
  return null;
153
169
  },
170
+ transform: {
171
+ order: "pre",
172
+ handler(code, id) {
173
+ const scriptSpecifier = toPublicSpecifier(relative(workspaceRoot, id.split("?")[0]));
174
+ const entry = getManualPageEntryForScriptSpecifier(scriptSpecifier);
175
+ if (!entry) return;
176
+ const packageRootSpecifier = entry.htmlFilePath.slice(0, entry.htmlFilePath.indexOf(MANUAL_TESTS_DIRECTORY));
177
+ if (!hasPackageThemeEntry(packageRootSpecifier)) return;
178
+ return {
179
+ code: `${code}\nimport '${posix.relative(posix.dirname(scriptSpecifier), `${packageRootSpecifier}/${THEME_ENTRY_FILE_PATH}`)}';\n`,
180
+ map: null
181
+ };
182
+ }
183
+ },
154
184
  transformIndexHtml: {
155
185
  order: "pre",
156
186
  handler(html, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-dev-manual-server",
3
- "version": "57.2.0",
3
+ "version": "57.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/)",