@backstage/plugin-techdocs-node 1.15.4 → 1.15.6
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/CHANGELOG.md +12 -0
- package/dist/stages/generate/helpers.cjs.js +1 -0
- package/dist/stages/generate/helpers.cjs.js.map +1 -1
- package/dist/stages/generate/mkdocsPatchers.cjs.js +168 -25
- package/dist/stages/generate/mkdocsPatchers.cjs.js.map +1 -1
- package/dist/stages/generate/techdocs.cjs.js +9 -2
- package/dist/stages/generate/techdocs.cjs.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage/plugin-techdocs-node
|
|
2
2
|
|
|
3
|
+
## 1.15.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f18e9ab: Improved handling of mapping-style Markdown extension configuration.
|
|
8
|
+
|
|
9
|
+
## 1.15.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 28aa82a: **BREAKING**: TechDocs generation now removes MkDocs plugins outside the built-in allowlist and logs a warning before continuing the build. To retain additional plugins, review and add them to `techdocs.generator.mkdocs.dangerouslyAllowAdditionalPlugins`, or supply them through `dangerouslyAllowAdditionalPlugins` when creating the generator directly. Plugins configured through `defaultPlugins` are also permitted. Generation stops if the MkDocs configuration cannot be read, parsed, or updated.
|
|
14
|
+
|
|
3
15
|
## 1.15.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -342,6 +342,7 @@ exports.ALLOWED_MKDOCS_KEYS = ALLOWED_MKDOCS_KEYS;
|
|
|
342
342
|
exports.ALLOWED_THEME_KEYS = ALLOWED_THEME_KEYS;
|
|
343
343
|
exports.DANGEROUS_EXTENSION_CONFIG_KEYS = DANGEROUS_EXTENSION_CONFIG_KEYS;
|
|
344
344
|
exports.MKDOCS_SCHEMA = MKDOCS_SCHEMA;
|
|
345
|
+
exports.UnknownTag = UnknownTag;
|
|
345
346
|
exports.createOrUpdateMetadata = createOrUpdateMetadata;
|
|
346
347
|
exports.generateMkdocsYml = generateMkdocsYml;
|
|
347
348
|
exports.getGeneratorKey = getGeneratorKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs.js","sources":["../../../src/stages/generate/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isChildPath, LoggerService } from '@backstage/backend-plugin-api';\nimport { Entity } from '@backstage/catalog-model';\nimport { ForwardedError, NotAllowedError, toError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { SpawnOptionsWithoutStdio, spawn } from 'node:child_process';\nimport fs from 'fs-extra';\nimport gitUrlParse from 'git-url-parse';\nimport yaml, { DEFAULT_SCHEMA, Type } from 'js-yaml';\nimport path, { resolve as resolvePath } from 'node:path';\nimport { PassThrough, Writable } from 'node:stream';\nimport { ParsedLocationAnnotation } from '../../helpers';\nimport { DefaultMkdocsContent, SupportedGeneratorKey } from './types';\nimport { getFileTreeRecursively } from '../publish/helpers';\n\n// TODO: Implement proper support for more generators.\nexport function getGeneratorKey(entity: Entity): SupportedGeneratorKey {\n if (!entity) {\n throw new Error('No entity provided');\n }\n\n return 'techdocs';\n}\n\nexport type RunCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options: SpawnOptionsWithoutStdio;\n /** stream to capture stdout and stderr output */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n */\nexport const runCommand = async ({\n command,\n args,\n options,\n logStream = new PassThrough(),\n}: RunCommandOptions) => {\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, options);\n\n process.stdout.on('data', stream => {\n logStream.write(stream);\n });\n\n process.stderr.on('data', stream => {\n logStream.write(stream);\n });\n\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(`Command ${command} failed, exit code: ${code}`);\n }\n return resolve();\n });\n });\n};\n\n/**\n * Return the source url for MkDocs based on the backstage.io/techdocs-ref annotation.\n * Depending on the type of target, it can either return a repo_url, an edit_uri, both, or none.\n *\n * @param parsedLocationAnnotation - Object with location url and type\n * @param scmIntegrations - the scmIntegration to do url transformations\n * @param docsFolder - the configured docs folder in the mkdocs.yml (defaults to 'docs')\n * @returns the settings for the mkdocs.yml\n */\nexport const getRepoUrlFromLocationAnnotation = (\n parsedLocationAnnotation: ParsedLocationAnnotation,\n scmIntegrations: ScmIntegrationRegistry,\n docsFolder: string = 'docs',\n): { repo_url?: string; edit_uri?: string } => {\n const { type: locationType, target } = parsedLocationAnnotation;\n\n if (locationType === 'url') {\n const integration = scmIntegrations.byUrl(target);\n\n // We only support it for github, gitlab, bitbucketServer and harness for now as the edit_uri\n // is not properly supported for others yet.\n if (\n integration &&\n ['github', 'gitlab', 'bitbucketServer', 'harness'].includes(\n integration.type,\n )\n ) {\n // handle the case where a user manually writes url:https://github.com/backstage/backstage i.e. without /blob/...\n const { filepathtype } = gitUrlParse(target);\n if (filepathtype === '') {\n return { repo_url: target };\n }\n\n const sourceFolder = integration.resolveUrl({\n url: `./${docsFolder}`,\n base: target.endsWith('/') ? target : `${target}/`,\n });\n return {\n repo_url: target,\n edit_uri: integration.resolveEditUrl(sourceFolder),\n };\n }\n }\n\n return {};\n};\n\nconst ALLOWED_PYTHON_YAML_TAGS = new Set([\n 'tag:yaml.org,2002:python/name:materialx.emoji.twemoji',\n 'tag:yaml.org,2002:python/object.apply:materialx.emoji.to_svg',\n 'tag:yaml.org,2002:python/object/apply:pymdownx.slugs.slugify',\n]);\n\nclass UnknownTag {\n public readonly data: any;\n public readonly type?: string;\n\n constructor(data: any, type?: string) {\n if (\n type?.startsWith('tag:yaml.org,2002:python/') &&\n !ALLOWED_PYTHON_YAML_TAGS.has(type)\n ) {\n throw new Error(`Unsupported Python YAML tag '${type}'`);\n }\n\n this.data = data;\n this.type = type;\n }\n}\n\nexport const MKDOCS_SCHEMA = DEFAULT_SCHEMA.extend([\n new Type('', {\n kind: 'scalar',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n new Type('tag:', {\n kind: 'mapping',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n new Type('', {\n kind: 'sequence',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n]);\n\n/**\n * Generates a mkdocs.yml configuration file\n *\n * @param inputDir - base dir to where the mkdocs.yml file will be created\n * @param siteOptions - options for the site: `name` property will be used in mkdocs.yml for the\n * required `site_name` property, default value is \"Documentation Site\"\n */\nexport const generateMkdocsYml = async (\n inputDir: string,\n siteOptions?: { name?: string },\n) => {\n try {\n // TODO(awanlin): Use a provided default mkdocs.yml\n // from config or some specified location. If this is\n // not provided then fall back to generating bare\n // minimum mkdocs.yml file\n\n const mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml');\n const defaultSiteName = siteOptions?.name ?? 'Documentation Site';\n const defaultMkdocsContent: DefaultMkdocsContent = {\n site_name: defaultSiteName,\n docs_dir: 'docs',\n plugins: ['techdocs-core'],\n };\n\n await fs.writeFile(\n mkdocsYmlPath,\n yaml.dump(defaultMkdocsContent, { schema: MKDOCS_SCHEMA }),\n );\n } catch (error) {\n throw new ForwardedError('Could not generate mkdocs.yml file', error);\n }\n};\n\n/**\n * Finds and loads the contents of an mkdocs.yml, mkdocs.yaml file, a file\n * with a specified name or an ad-hoc created file with minimal config.\n * @public\n *\n * @param inputDir - base dir to be searched for either an mkdocs.yml or mkdocs.yaml file.\n * @param options - name: default mkdocs site_name to be used with a ad hoc file default value is \"Documentation Site\"\n * mkdocsConfigFileName (optional): a non-default file name to be used as the config\n */\nexport const getMkdocsYml = async (\n inputDir: string,\n options?: { name?: string; mkdocsConfigFileName?: string },\n): Promise<{ path: string; content: string; configIsTemporary: boolean }> => {\n let mkdocsYmlPath: string;\n let mkdocsYmlFileString: string;\n try {\n if (options?.mkdocsConfigFileName) {\n mkdocsYmlPath = path.join(inputDir, options.mkdocsConfigFileName);\n if (!(await fs.pathExists(mkdocsYmlPath))) {\n throw new Error(`The specified file ${mkdocsYmlPath} does not exist`);\n }\n\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n mkdocsYmlPath = path.join(inputDir, 'mkdocs.yaml');\n if (await fs.pathExists(mkdocsYmlPath)) {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml');\n if (await fs.pathExists(mkdocsYmlPath)) {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n // No mkdocs file, generate it\n await generateMkdocsYml(inputDir, options);\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n } catch (error) {\n throw new ForwardedError(\n 'Could not read MkDocs YAML config file mkdocs.yml or mkdocs.yaml or default for validation',\n error,\n );\n }\n\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: true,\n };\n};\n\n/**\n * Allowlist of MkDocs configuration keys supported by TechDocs.\n *\n * @see https://www.mkdocs.org/user-guide/configuration/\n */\nexport const ALLOWED_MKDOCS_KEYS = new Set([\n // Site information\n 'site_name',\n 'site_url',\n 'site_description',\n 'site_author',\n // Repository\n 'repo_url',\n 'repo_name',\n 'edit_uri',\n 'edit_uri_template',\n // Build directories\n 'docs_dir',\n 'site_dir',\n // Documentation layout\n 'nav',\n 'exclude_docs',\n 'not_in_nav',\n // Build settings\n 'theme',\n 'plugins',\n 'markdown_extensions',\n 'extra',\n 'extra_css',\n // Preview controls\n 'use_directory_urls',\n 'strict',\n 'dev_addr',\n 'watch',\n // Metadata\n 'copyright',\n 'remote_branch',\n 'remote_name',\n 'validation',\n // Deprecated\n 'google_analytics',\n]);\n\n/**\n * Denylist of configuration keys that must be stripped from extension\n * configurations nested within `markdown_extensions`.\n */\nexport const DANGEROUS_EXTENSION_CONFIG_KEYS = new Set(['plantuml_cmd']);\n\n/**\n * Allowlist of theme configuration keys supported by TechDocs.\n *\n * @see https://squidfunk.github.io/mkdocs-material/setup/\n */\nexport const ALLOWED_THEME_KEYS = new Set([\n 'name',\n 'font',\n 'icon',\n 'logo',\n 'favicon',\n 'language',\n 'direction',\n 'palette',\n 'features',\n]);\n\n/**\n * Validating mkdocs config file for incorrect/insecure values\n * Throws on invalid configs\n *\n * @param inputDir - base dir to be used as a docs_dir path validity check\n * @param mkdocsYmlFileString - The string contents of the loaded\n * mkdocs.yml or equivalent of a docs site\n * @returns the parsed docs_dir or undefined\n */\nexport const validateMkdocsYaml = async (\n inputDir: string,\n mkdocsYmlFileString: string,\n): Promise<string | undefined> => {\n const mkdocsYml = yaml.load(mkdocsYmlFileString, {\n schema: MKDOCS_SCHEMA,\n });\n\n if (mkdocsYml === null || typeof mkdocsYml !== 'object') {\n return undefined;\n }\n\n const parsedMkdocsYml: Record<string, any> = mkdocsYml;\n\n if (\n parsedMkdocsYml.docs_dir &&\n !isChildPath(inputDir, resolvePath(inputDir, parsedMkdocsYml.docs_dir))\n ) {\n throw new Error(\n `docs_dir configuration value in mkdocs can't be an absolute directory or start with ../ for security reasons.\n Use relative paths instead which are resolved relative to your mkdocs.yml file location.`,\n );\n }\n return parsedMkdocsYml.docs_dir;\n};\n\n/**\n * Validates that the input directory doesn't contain symlinks pointing outside\n * of it. This prevents path traversal attacks where malicious symlinks could be\n * used to read arbitrary files from the host filesystem.\n *\n * The whole input directory is checked rather than only the docs directory,\n * because MkDocs extensions can read files from anywhere in the input directory.\n *\n * @param inputDir - The input directory to validate (absolute path)\n */\nexport const validateInputDirectory = async (\n inputDir: string,\n): Promise<void> => {\n const entries = await fs.readdir(inputDir, {\n recursive: true,\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n if (!entry.isSymbolicLink()) {\n continue;\n }\n\n const entryPath = path.join(entry.parentPath, entry.name);\n // isChildPath resolves both paths through realpath, so this also catches\n // relative, chained and dangling links\n if (!isChildPath(inputDir, entryPath)) {\n throw new NotAllowedError(\n `Path ${entryPath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n }\n};\n\n/**\n * Update docs/index.md file before TechDocs generator uses it to generate docs site,\n * falling back to docs/README.md or README.md in case a default docs/index.md\n * is not provided.\n */\nexport const patchIndexPreBuild = async ({\n inputDir,\n logger,\n docsDir = 'docs',\n}: {\n inputDir: string;\n logger: LoggerService;\n docsDir?: string;\n}) => {\n const docsPath = path.join(inputDir, docsDir);\n const indexMdPath = path.join(docsPath, 'index.md');\n\n if (await fs.pathExists(indexMdPath)) {\n return;\n }\n logger.warn(`${path.join(docsDir, 'index.md')} not found.`);\n const fallbacks = [\n path.join(docsPath, 'README.md'),\n path.join(docsPath, 'readme.md'),\n path.join(inputDir, 'README.md'),\n path.join(inputDir, 'readme.md'),\n ];\n\n if (!isChildPath(inputDir, docsPath)) {\n throw new NotAllowedError(\n `Target path ${docsPath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n await fs.ensureDir(docsPath);\n for (const filePath of fallbacks) {\n if (!isChildPath(inputDir, filePath)) {\n throw new NotAllowedError(\n `Source path ${filePath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n try {\n await fs.copyFile(filePath, indexMdPath);\n return;\n } catch (error) {\n logger.warn(`${path.relative(inputDir, filePath)} not found.`);\n }\n }\n\n logger.warn(\n `Could not find any techdocs' index file. Please make sure at least one of ${[\n indexMdPath,\n ...fallbacks,\n ].join(' ')} exists.`,\n );\n};\n\n/**\n * Create or update the techdocs_metadata.json. Values initialized/updated are:\n * - The build_timestamp (now)\n * - The list of files generated\n *\n * @param techdocsMetadataPath - File path to techdocs_metadata.json\n */\nexport const createOrUpdateMetadata = async (\n techdocsMetadataPath: string,\n logger: LoggerService,\n): Promise<void> => {\n const techdocsMetadataDir = techdocsMetadataPath\n .split(path.sep)\n .slice(0, -1)\n .join(path.sep);\n // check if file exists, create if it does not.\n try {\n await fs.access(techdocsMetadataPath, fs.constants.F_OK);\n } catch (err) {\n // Bootstrap file with empty JSON\n await fs.writeJson(techdocsMetadataPath, JSON.parse('{}'));\n }\n // check if valid Json\n let json;\n try {\n json = await fs.readJson(techdocsMetadataPath);\n } catch (err) {\n const message = `Invalid JSON at ${techdocsMetadataPath} with error ${\n toError(err).message\n }`;\n logger.error(message);\n throw new Error(message);\n }\n\n json.build_timestamp = Date.now();\n\n // Get and write generated files to the metadata JSON. Each file string is in\n // a form appropriate for invalidating the associated object from cache.\n try {\n json.files = (await getFileTreeRecursively(techdocsMetadataDir)).map(file =>\n file.replace(`${techdocsMetadataDir}${path.sep}`, ''),\n );\n } catch (err) {\n json.files = [];\n logger.warn(\n `Unable to add files list to metadata: ${toError(err).message}`,\n );\n }\n\n await fs.writeJson(techdocsMetadataPath, json);\n return;\n};\n\n/**\n * Update the techdocs_metadata.json to add etag of the prepared tree (e.g. commit SHA or actual Etag of the resource).\n * This is helpful to check if a TechDocs site in storage has gone outdated, without maintaining an in-memory build info\n * per Backstage instance.\n *\n * @param techdocsMetadataPath - File path to techdocs_metadata.json\n * @param etag - The ETag to use\n */\nexport const storeEtagMetadata = async (\n techdocsMetadataPath: string,\n etag: string,\n): Promise<void> => {\n const json = await fs.readJson(techdocsMetadataPath);\n json.etag = etag;\n await fs.writeJson(techdocsMetadataPath, json);\n};\n"],"names":["PassThrough","spawn","gitUrlParse","DEFAULT_SCHEMA","Type","path","fs","yaml","ForwardedError","isChildPath","resolvePath","NotAllowedError","toError","getFileTreeRecursively"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BO,SAAS,gBAAgB,MAAA,EAAuC;AACrE,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,MAAM,oBAAoB,CAAA;AAAA,EACtC;AAEA,EAAA,OAAO,UAAA;AACT;AAgBO,MAAM,aAAa,OAAO;AAAA,EAC/B,OAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA,GAAY,IAAIA,uBAAA;AAClB,CAAA,KAAyB;AACvB,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C,IAAA,MAAM,OAAA,GAAUC,wBAAA,CAAM,OAAA,EAAS,IAAA,EAAM,OAAO,CAAA;AAE5C,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,MAAA,KAAU;AAClC,MAAA,SAAA,CAAU,MAAM,MAAM,CAAA;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,MAAA,CAAO,EAAA,CAAG,MAAA,EAAQ,CAAA,MAAA,KAAU;AAClC,MAAA,SAAA,CAAU,MAAM,MAAM,CAAA;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,OAAA,CAAQ,EAAA,CAAG,SAAS,CAAA,KAAA,KAAS;AAC3B,MAAA,OAAO,OAAO,KA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AAmB,CAAA,EAAGR,qBAAA,CAAK,GAAG,CAAA,CAAA,EAAI,EAAE;AAAA,KACtD;AAAA,EACF,SAAS,GAAA,EAAK;AACZ,IAAA,IAAA,CAAK,QAAQ,EAAC;AACd,IAAA,MAAA,CAAO,IAAA;AAAA,MACL,CAAA,sCAAA,EAAyCO,cAAA,CAAQ,GAAG,CAAA,CAAE,OAAO,CAAA;AAAA,KAC/D;AAAA,EACF;AAEA,EAAA,MAAMN,mBAAA,CAAG,SAAA,CAAU,oBAAA,EAAsB,IAAI,CAAA;AAC7C,EAAA;AACF;AAUO,MAAM,iBAAA,GAAoB,OAC/B,oBAAA,EACA,IAAA,KACkB;AAClB,EAAA,MAAM,IAAA,GAAO,MAAMA,mBAAA,CAAG,QAAA,CAAS,oBAAoB,CAAA;AACnD,EAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,EAAA,MAAMA,mBAAA,CAAG,SAAA,CAAU,oBAAA,EAAsB,IAAI,CAAA;AAC/C;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"helpers.cjs.js","sources":["../../../src/stages/generate/helpers.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isChildPath, LoggerService } from '@backstage/backend-plugin-api';\nimport { Entity } from '@backstage/catalog-model';\nimport { ForwardedError, NotAllowedError, toError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { SpawnOptionsWithoutStdio, spawn } from 'node:child_process';\nimport fs from 'fs-extra';\nimport gitUrlParse from 'git-url-parse';\nimport yaml, { DEFAULT_SCHEMA, Type } from 'js-yaml';\nimport path, { resolve as resolvePath } from 'node:path';\nimport { PassThrough, Writable } from 'node:stream';\nimport { ParsedLocationAnnotation } from '../../helpers';\nimport { DefaultMkdocsContent, SupportedGeneratorKey } from './types';\nimport { getFileTreeRecursively } from '../publish/helpers';\n\n// TODO: Implement proper support for more generators.\nexport function getGeneratorKey(entity: Entity): SupportedGeneratorKey {\n if (!entity) {\n throw new Error('No entity provided');\n }\n\n return 'techdocs';\n}\n\nexport type RunCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options: SpawnOptionsWithoutStdio;\n /** stream to capture stdout and stderr output */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n */\nexport const runCommand = async ({\n command,\n args,\n options,\n logStream = new PassThrough(),\n}: RunCommandOptions) => {\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, options);\n\n process.stdout.on('data', stream => {\n logStream.write(stream);\n });\n\n process.stderr.on('data', stream => {\n logStream.write(stream);\n });\n\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(`Command ${command} failed, exit code: ${code}`);\n }\n return resolve();\n });\n });\n};\n\n/**\n * Return the source url for MkDocs based on the backstage.io/techdocs-ref annotation.\n * Depending on the type of target, it can either return a repo_url, an edit_uri, both, or none.\n *\n * @param parsedLocationAnnotation - Object with location url and type\n * @param scmIntegrations - the scmIntegration to do url transformations\n * @param docsFolder - the configured docs folder in the mkdocs.yml (defaults to 'docs')\n * @returns the settings for the mkdocs.yml\n */\nexport const getRepoUrlFromLocationAnnotation = (\n parsedLocationAnnotation: ParsedLocationAnnotation,\n scmIntegrations: ScmIntegrationRegistry,\n docsFolder: string = 'docs',\n): { repo_url?: string; edit_uri?: string } => {\n const { type: locationType, target } = parsedLocationAnnotation;\n\n if (locationType === 'url') {\n const integration = scmIntegrations.byUrl(target);\n\n // We only support it for github, gitlab, bitbucketServer and harness for now as the edit_uri\n // is not properly supported for others yet.\n if (\n integration &&\n ['github', 'gitlab', 'bitbucketServer', 'harness'].includes(\n integration.type,\n )\n ) {\n // handle the case where a user manually writes url:https://github.com/backstage/backstage i.e. without /blob/...\n const { filepathtype } = gitUrlParse(target);\n if (filepathtype === '') {\n return { repo_url: target };\n }\n\n const sourceFolder = integration.resolveUrl({\n url: `./${docsFolder}`,\n base: target.endsWith('/') ? target : `${target}/`,\n });\n return {\n repo_url: target,\n edit_uri: integration.resolveEditUrl(sourceFolder),\n };\n }\n }\n\n return {};\n};\n\nconst ALLOWED_PYTHON_YAML_TAGS = new Set([\n 'tag:yaml.org,2002:python/name:materialx.emoji.twemoji',\n 'tag:yaml.org,2002:python/object.apply:materialx.emoji.to_svg',\n 'tag:yaml.org,2002:python/object/apply:pymdownx.slugs.slugify',\n]);\n\nexport class UnknownTag {\n public readonly data: any;\n public readonly type?: string;\n\n constructor(data: any, type?: string) {\n if (\n type?.startsWith('tag:yaml.org,2002:python/') &&\n !ALLOWED_PYTHON_YAML_TAGS.has(type)\n ) {\n throw new Error(`Unsupported Python YAML tag '${type}'`);\n }\n\n this.data = data;\n this.type = type;\n }\n}\n\nexport const MKDOCS_SCHEMA = DEFAULT_SCHEMA.extend([\n new Type('', {\n kind: 'scalar',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n new Type('tag:', {\n kind: 'mapping',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n new Type('', {\n kind: 'sequence',\n multi: true,\n representName: o => (o as UnknownTag).type,\n represent: o => (o as UnknownTag).data ?? '',\n instanceOf: UnknownTag,\n construct: (data: string, type?: string) => new UnknownTag(data, type),\n }),\n]);\n\n/**\n * Generates a mkdocs.yml configuration file\n *\n * @param inputDir - base dir to where the mkdocs.yml file will be created\n * @param siteOptions - options for the site: `name` property will be used in mkdocs.yml for the\n * required `site_name` property, default value is \"Documentation Site\"\n */\nexport const generateMkdocsYml = async (\n inputDir: string,\n siteOptions?: { name?: string },\n) => {\n try {\n // TODO(awanlin): Use a provided default mkdocs.yml\n // from config or some specified location. If this is\n // not provided then fall back to generating bare\n // minimum mkdocs.yml file\n\n const mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml');\n const defaultSiteName = siteOptions?.name ?? 'Documentation Site';\n const defaultMkdocsContent: DefaultMkdocsContent = {\n site_name: defaultSiteName,\n docs_dir: 'docs',\n plugins: ['techdocs-core'],\n };\n\n await fs.writeFile(\n mkdocsYmlPath,\n yaml.dump(defaultMkdocsContent, { schema: MKDOCS_SCHEMA }),\n );\n } catch (error) {\n throw new ForwardedError('Could not generate mkdocs.yml file', error);\n }\n};\n\n/**\n * Finds and loads the contents of an mkdocs.yml, mkdocs.yaml file, a file\n * with a specified name or an ad-hoc created file with minimal config.\n * @public\n *\n * @param inputDir - base dir to be searched for either an mkdocs.yml or mkdocs.yaml file.\n * @param options - name: default mkdocs site_name to be used with a ad hoc file default value is \"Documentation Site\"\n * mkdocsConfigFileName (optional): a non-default file name to be used as the config\n */\nexport const getMkdocsYml = async (\n inputDir: string,\n options?: { name?: string; mkdocsConfigFileName?: string },\n): Promise<{ path: string; content: string; configIsTemporary: boolean }> => {\n let mkdocsYmlPath: string;\n let mkdocsYmlFileString: string;\n try {\n if (options?.mkdocsConfigFileName) {\n mkdocsYmlPath = path.join(inputDir, options.mkdocsConfigFileName);\n if (!(await fs.pathExists(mkdocsYmlPath))) {\n throw new Error(`The specified file ${mkdocsYmlPath} does not exist`);\n }\n\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n mkdocsYmlPath = path.join(inputDir, 'mkdocs.yaml');\n if (await fs.pathExists(mkdocsYmlPath)) {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml');\n if (await fs.pathExists(mkdocsYmlPath)) {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: false,\n };\n }\n\n // No mkdocs file, generate it\n await generateMkdocsYml(inputDir, options);\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n } catch (error) {\n throw new ForwardedError(\n 'Could not read MkDocs YAML config file mkdocs.yml or mkdocs.yaml or default for validation',\n error,\n );\n }\n\n return {\n path: mkdocsYmlPath,\n content: mkdocsYmlFileString,\n configIsTemporary: true,\n };\n};\n\n/**\n * Allowlist of MkDocs configuration keys supported by TechDocs.\n *\n * @see https://www.mkdocs.org/user-guide/configuration/\n */\nexport const ALLOWED_MKDOCS_KEYS = new Set([\n // Site information\n 'site_name',\n 'site_url',\n 'site_description',\n 'site_author',\n // Repository\n 'repo_url',\n 'repo_name',\n 'edit_uri',\n 'edit_uri_template',\n // Build directories\n 'docs_dir',\n 'site_dir',\n // Documentation layout\n 'nav',\n 'exclude_docs',\n 'not_in_nav',\n // Build settings\n 'theme',\n 'plugins',\n 'markdown_extensions',\n 'extra',\n 'extra_css',\n // Preview controls\n 'use_directory_urls',\n 'strict',\n 'dev_addr',\n 'watch',\n // Metadata\n 'copyright',\n 'remote_branch',\n 'remote_name',\n 'validation',\n // Deprecated\n 'google_analytics',\n]);\n\n/**\n * Denylist of configuration keys that must be stripped from extension\n * configurations nested within `markdown_extensions`.\n */\nexport const DANGEROUS_EXTENSION_CONFIG_KEYS = new Set(['plantuml_cmd']);\n\n/**\n * Allowlist of theme configuration keys supported by TechDocs.\n *\n * @see https://squidfunk.github.io/mkdocs-material/setup/\n */\nexport const ALLOWED_THEME_KEYS = new Set([\n 'name',\n 'font',\n 'icon',\n 'logo',\n 'favicon',\n 'language',\n 'direction',\n 'palette',\n 'features',\n]);\n\n/**\n * Validating mkdocs config file for incorrect/insecure values\n * Throws on invalid configs\n *\n * @param inputDir - base dir to be used as a docs_dir path validity check\n * @param mkdocsYmlFileString - The string contents of the loaded\n * mkdocs.yml or equivalent of a docs site\n * @returns the parsed docs_dir or undefined\n */\nexport const validateMkdocsYaml = async (\n inputDir: string,\n mkdocsYmlFileString: string,\n): Promise<string | undefined> => {\n const mkdocsYml = yaml.load(mkdocsYmlFileString, {\n schema: MKDOCS_SCHEMA,\n });\n\n if (mkdocsYml === null || typeof mkdocsYml !== 'object') {\n return undefined;\n }\n\n const parsedMkdocsYml: Record<string, any> = mkdocsYml;\n\n if (\n parsedMkdocsYml.docs_dir &&\n !isChildPath(inputDir, resolvePath(inputDir, parsedMkdocsYml.docs_dir))\n ) {\n throw new Error(\n `docs_dir configuration value in mkdocs can't be an absolute directory or start with ../ for security reasons.\n Use relative paths instead which are resolved relative to your mkdocs.yml file location.`,\n );\n }\n return parsedMkdocsYml.docs_dir;\n};\n\n/**\n * Validates that the input directory doesn't contain symlinks pointing outside\n * of it. This prevents path traversal attacks where malicious symlinks could be\n * used to read arbitrary files from the host filesystem.\n *\n * The whole input directory is checked rather than only the docs directory,\n * because MkDocs extensions can read files from anywhere in the input directory.\n *\n * @param inputDir - The input directory to validate (absolute path)\n */\nexport const validateInputDirectory = async (\n inputDir: string,\n): Promise<void> => {\n const entries = await fs.readdir(inputDir, {\n recursive: true,\n withFileTypes: true,\n });\n\n for (const entry of entries) {\n if (!entry.isSymbolicLink()) {\n continue;\n }\n\n const entryPath = path.join(entry.parentPath, entry.name);\n // isChildPath resolves both paths through realpath, so this also catches\n // relative, chained and dangling links\n if (!isChildPath(inputDir, entryPath)) {\n throw new NotAllowedError(\n `Path ${entryPath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n }\n};\n\n/**\n * Update docs/index.md file before TechDocs generator uses it to generate docs site,\n * falling back to docs/README.md or README.md in case a default docs/index.md\n * is not provided.\n */\nexport const patchIndexPreBuild = async ({\n inputDir,\n logger,\n docsDir = 'docs',\n}: {\n inputDir: string;\n logger: LoggerService;\n docsDir?: string;\n}) => {\n const docsPath = path.join(inputDir, docsDir);\n const indexMdPath = path.join(docsPath, 'index.md');\n\n if (await fs.pathExists(indexMdPath)) {\n return;\n }\n logger.warn(`${path.join(docsDir, 'index.md')} not found.`);\n const fallbacks = [\n path.join(docsPath, 'README.md'),\n path.join(docsPath, 'readme.md'),\n path.join(inputDir, 'README.md'),\n path.join(inputDir, 'readme.md'),\n ];\n\n if (!isChildPath(inputDir, docsPath)) {\n throw new NotAllowedError(\n `Target path ${docsPath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n await fs.ensureDir(docsPath);\n for (const filePath of fallbacks) {\n if (!isChildPath(inputDir, filePath)) {\n throw new NotAllowedError(\n `Source path ${filePath} is not allowed to refer to a location outside ${inputDir}`,\n );\n }\n try {\n await fs.copyFile(filePath, indexMdPath);\n return;\n } catch (error) {\n logger.warn(`${path.relative(inputDir, filePath)} not found.`);\n }\n }\n\n logger.warn(\n `Could not find any techdocs' index file. Please make sure at least one of ${[\n indexMdPath,\n ...fallbacks,\n ].join(' ')} exists.`,\n );\n};\n\n/**\n * Create or update the techdocs_metadata.json. Values initialized/updated are:\n * - The build_timestamp (now)\n * - The list of files generated\n *\n * @param techdocsMetadataPath - File path to techdocs_metadata.json\n */\nexport const createOrUpdateMetadata = async (\n techdocsMetadataPath: string,\n logger: LoggerService,\n): Promise<void> => {\n const techdocsMetadataDir = techdocsMetadataPath\n .split(path.sep)\n .slice(0, -1)\n .join(path.sep);\n // check if file exists, create if it does not.\n try {\n await fs.access(techdocsMetadataPath, fs.constants.F_OK);\n } catch (err) {\n // Bootstrap file with empty JSON\n await fs.writeJson(techdocsMetadataPath, JSON.parse('{}'));\n }\n // check if valid Json\n let json;\n try {\n json = await fs.readJson(techdocsMetadataPath);\n } catch (err) {\n const message = `Invalid JSON at ${techdocsMetadataPath} with error ${\n toError(err).message\n }`;\n logger.error(message);\n throw new Error(message);\n }\n\n json.build_timestamp = Date.now();\n\n // Get and write generated files to the metadata JSON. Each file string is in\n // a form appropriate for invalidating the associated object from cache.\n try {\n json.files = (await getFileTreeRecursively(techdocsMetadataDir)).map(file =>\n file.replace(`${techdocsMetadataDir}${path.sep}`, ''),\n );\n } catch (err) {\n json.files = [];\n logger.warn(\n `Unable to add files list to metadata: ${toError(err).message}`,\n );\n }\n\n await fs.writeJson(techdocsMetadataPath, json);\n return;\n};\n\n/**\n * Update the techdocs_metadata.json to add etag of the prepared tree (e.g. commit SHA or actual Etag of the resource).\n * This is helpful to check if a TechDocs site in storage has gone outdated, without maintaining an in-memory build info\n * per Backstage instance.\n *\n * @param techdocsMetadataPath - File path to techdocs_metadata.json\n * @param etag - The ETag to use\n */\nexport const storeEtagMetadata = async (\n techdocsMetadataPath: string,\n etag: string,\n): Promise<void> => {\n const json = await fs.readJson(techdocsMetadataPath);\n json.etag = etag;\n await fs.writeJson(techdocsMetadataPath, json);\n};\n"],"names":["PassThrough","spawn","gitUrlParse","DEFAULT_SCHEMA","Type","path","fs","yaml","ForwardedError","isChildPath","resolvePath","NotAllowedError","toError","getFileTreeRecursively"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BO,SAAS,gBAAgB,MAAA,EAAuC;AACrE,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,MAAM,oBAAoB,CAAA;AAAA,EACtC;AAEA,EAAA,OAAO,UAAA;AACT;AAgBO,MAAM,aAAa,OAAO;AAAA,EAC/B,OAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA,GAAY,IAAIA,uBAAA;AAClB,CAAA,KAAyB;AACvB,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC3C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IPPETS_EXTENSION = "pymdownx.snippets";
|
|
15
|
+
const DEFAULT_ALLOWED_MKDOCS_PLUGINS = /* @__PURE__ */ new Set([
|
|
16
|
+
"techdocs-core",
|
|
17
|
+
"search",
|
|
18
|
+
"material/search",
|
|
19
|
+
"redirects",
|
|
20
|
+
"group",
|
|
21
|
+
"material/group"
|
|
22
|
+
]);
|
|
23
|
+
const MKDOCS_PLUGIN_GROUPS = /* @__PURE__ */ new Set(["group", "material/group"]);
|
|
15
24
|
function isPymdownxSnippetsExtension(extensionName) {
|
|
16
25
|
return extensionName === PYMDOWNX_SNIPPETS_EXTENSION || extensionName === `${PYMDOWNX_SNIPPETS_EXTENSION}:SnippetExtension`;
|
|
17
26
|
}
|
|
27
|
+
function isPlainObject(value) {
|
|
28
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof helpers.UnknownTag) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const prototype = Object.getPrototypeOf(value);
|
|
32
|
+
return prototype === Object.prototype || prototype === null;
|
|
33
|
+
}
|
|
34
|
+
function normalizeMkdocsPlugins(plugins) {
|
|
35
|
+
if (Array.isArray(plugins)) {
|
|
36
|
+
return plugins;
|
|
37
|
+
}
|
|
38
|
+
if (isPlainObject(plugins)) {
|
|
39
|
+
return Object.entries(plugins).map(([name, config]) => ({
|
|
40
|
+
[name]: config
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
function sanitizeMkdocsPlugins(plugins, allowedPlugins, removedPlugins) {
|
|
46
|
+
if (plugins instanceof helpers.UnknownTag) {
|
|
47
|
+
removedPlugins.add("dynamically configured plugin name");
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const normalizedPlugins = normalizeMkdocsPlugins(plugins);
|
|
51
|
+
if (!normalizedPlugins) {
|
|
52
|
+
removedPlugins.add("malformed plugin declaration");
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const sanitizedPlugins = [];
|
|
56
|
+
for (const plugin of normalizedPlugins) {
|
|
57
|
+
if (plugin instanceof helpers.UnknownTag) {
|
|
58
|
+
removedPlugins.add("dynamically configured plugin name");
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let pluginName;
|
|
62
|
+
if (typeof plugin === "string" && plugin.length > 0) {
|
|
63
|
+
pluginName = plugin;
|
|
64
|
+
} else if (isPlainObject(plugin) && Object.keys(plugin).length === 1) {
|
|
65
|
+
[pluginName] = Object.keys(plugin);
|
|
66
|
+
const config = plugin[pluginName];
|
|
67
|
+
if (config !== null && !isPlainObject(config)) {
|
|
68
|
+
removedPlugins.add("malformed plugin declaration");
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
removedPlugins.add("malformed plugin declaration");
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!allowedPlugins.has(pluginName)) {
|
|
76
|
+
removedPlugins.add(pluginName);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let sanitizedPlugin = plugin;
|
|
80
|
+
if (isPlainObject(plugin)) {
|
|
81
|
+
const config = plugin[pluginName];
|
|
82
|
+
if (MKDOCS_PLUGIN_GROUPS.has(pluginName) && isPlainObject(config)) {
|
|
83
|
+
sanitizedPlugin = {
|
|
84
|
+
...plugin,
|
|
85
|
+
[pluginName]: {
|
|
86
|
+
...config,
|
|
87
|
+
plugins: sanitizeMkdocsPlugins(
|
|
88
|
+
config.plugins,
|
|
89
|
+
allowedPlugins,
|
|
90
|
+
removedPlugins
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
sanitizedPlugins.push(sanitizedPlugin);
|
|
97
|
+
}
|
|
98
|
+
return sanitizedPlugins;
|
|
99
|
+
}
|
|
18
100
|
function isThemeObject(theme) {
|
|
19
101
|
return typeof theme === "object" && theme !== null && !Array.isArray(theme);
|
|
20
102
|
}
|
|
21
|
-
const patchMkdocsFile = async (mkdocsYmlPath, logger, updateAction) => {
|
|
103
|
+
const patchMkdocsFile = async (mkdocsYmlPath, logger, updateAction, options) => {
|
|
22
104
|
let didEdit = false;
|
|
23
105
|
let mkdocsYmlFileString;
|
|
24
106
|
try {
|
|
@@ -27,6 +109,9 @@ const patchMkdocsFile = async (mkdocsYmlPath, logger, updateAction) => {
|
|
|
27
109
|
logger.warn(
|
|
28
110
|
`Could not read MkDocs YAML config file ${mkdocsYmlPath} before running the generator: ${errors.toError(error).message}`
|
|
29
111
|
);
|
|
112
|
+
if (options?.failOnError) {
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
30
115
|
return;
|
|
31
116
|
}
|
|
32
117
|
let mkdocsYml;
|
|
@@ -39,6 +124,9 @@ const patchMkdocsFile = async (mkdocsYmlPath, logger, updateAction) => {
|
|
|
39
124
|
logger.warn(
|
|
40
125
|
`Error in parsing YAML at ${mkdocsYmlPath} before running the generator. ${errors.toError(error).message}`
|
|
41
126
|
);
|
|
127
|
+
if (options?.failOnError) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
42
130
|
return;
|
|
43
131
|
}
|
|
44
132
|
didEdit = updateAction(mkdocsYml);
|
|
@@ -54,9 +142,15 @@ const patchMkdocsFile = async (mkdocsYmlPath, logger, updateAction) => {
|
|
|
54
142
|
logger.warn(
|
|
55
143
|
`Could not write to ${mkdocsYmlPath} after updating it before running the generator. ${errors.toError(error).message}`
|
|
56
144
|
);
|
|
145
|
+
if (options?.failOnError) {
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
57
148
|
return;
|
|
58
149
|
}
|
|
59
150
|
};
|
|
151
|
+
const patchMkdocsFileOrThrow = async (mkdocsYmlPath, logger, updateAction) => patchMkdocsFile(mkdocsYmlPath, logger, updateAction, {
|
|
152
|
+
failOnError: true
|
|
153
|
+
});
|
|
60
154
|
const patchMkdocsYmlPreBuild = async (mkdocsYmlPath, logger, parsedLocationAnnotation, scmIntegrations) => {
|
|
61
155
|
await patchMkdocsFile(mkdocsYmlPath, logger, (mkdocsYml) => {
|
|
62
156
|
if (!("repo_url" in mkdocsYml) || !("edit_uri" in mkdocsYml)) {
|
|
@@ -119,8 +213,8 @@ const patchMkdocsYmlWithFontDisabled = async (mkdocsYmlPath, logger) => {
|
|
|
119
213
|
return false;
|
|
120
214
|
});
|
|
121
215
|
};
|
|
122
|
-
const sanitizeMkdocsYml = async (mkdocsYmlPath, logger, additionalAllowedKeys) => {
|
|
123
|
-
await
|
|
216
|
+
const sanitizeMkdocsYml = async (mkdocsYmlPath, logger, additionalAllowedKeys, additionalAllowedPlugins) => {
|
|
217
|
+
await patchMkdocsFileOrThrow(mkdocsYmlPath, logger, (mkdocsYml) => {
|
|
124
218
|
const allowedKeys = new Set(helpers.ALLOWED_MKDOCS_KEYS);
|
|
125
219
|
if (additionalAllowedKeys && additionalAllowedKeys.length > 0) {
|
|
126
220
|
logger.warn(
|
|
@@ -147,21 +241,40 @@ const sanitizeMkdocsYml = async (mkdocsYmlPath, logger, additionalAllowedKeys) =
|
|
|
147
241
|
}
|
|
148
242
|
}
|
|
149
243
|
const extensions = sanitized.markdown_extensions;
|
|
244
|
+
const removedEntries = [];
|
|
245
|
+
const extensionMapping = isPlainObject(extensions) ? extensions : void 0;
|
|
246
|
+
let normalizedExtensions;
|
|
150
247
|
if (Array.isArray(extensions)) {
|
|
151
|
-
|
|
152
|
-
|
|
248
|
+
normalizedExtensions = extensions;
|
|
249
|
+
} else if (extensionMapping) {
|
|
250
|
+
normalizedExtensions = Object.entries(extensionMapping).map(
|
|
251
|
+
([name, config]) => ({
|
|
252
|
+
[name]: config
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (extensions instanceof helpers.UnknownTag) {
|
|
257
|
+
removedEntries.push("dynamically configured extension");
|
|
258
|
+
sanitized.markdown_extensions = [];
|
|
259
|
+
} else if (normalizedExtensions) {
|
|
260
|
+
const sanitizedExtensions = normalizedExtensions.flatMap((ext) => {
|
|
261
|
+
if (ext instanceof helpers.UnknownTag) {
|
|
262
|
+
removedEntries.push("dynamically configured extension");
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
153
265
|
if (typeof ext === "string") {
|
|
154
266
|
if (isPymdownxSnippetsExtension(ext)) {
|
|
155
|
-
return
|
|
267
|
+
return [ext];
|
|
156
268
|
}
|
|
157
269
|
if (ext.includes(":")) {
|
|
158
270
|
removedEntries.push(ext);
|
|
159
|
-
return
|
|
271
|
+
return [];
|
|
160
272
|
}
|
|
161
|
-
return
|
|
273
|
+
return [ext];
|
|
162
274
|
}
|
|
163
|
-
if (!
|
|
164
|
-
|
|
275
|
+
if (!isPlainObject(ext)) {
|
|
276
|
+
removedEntries.push("malformed extension declaration");
|
|
277
|
+
return [];
|
|
165
278
|
}
|
|
166
279
|
const extensionEntries = Object.entries(ext);
|
|
167
280
|
const dangerousNames = extensionEntries.map(([extensionName]) => extensionName).filter(
|
|
@@ -169,34 +282,64 @@ const sanitizeMkdocsYml = async (mkdocsYmlPath, logger, additionalAllowedKeys) =
|
|
|
169
282
|
);
|
|
170
283
|
if (dangerousNames.length > 0) {
|
|
171
284
|
removedEntries.push(...dangerousNames);
|
|
172
|
-
return
|
|
285
|
+
return [];
|
|
173
286
|
}
|
|
287
|
+
const sanitizedExtension = {};
|
|
174
288
|
for (const [extensionName, extensionConfig] of extensionEntries) {
|
|
175
|
-
if (
|
|
289
|
+
if (extensionConfig instanceof helpers.UnknownTag) {
|
|
290
|
+
removedEntries.push(
|
|
291
|
+
`dynamically configured ${extensionName} extension`
|
|
292
|
+
);
|
|
176
293
|
continue;
|
|
177
294
|
}
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
295
|
+
if (isPymdownxSnippetsExtension(extensionName)) {
|
|
296
|
+
if (extensionConfig !== null && (typeof extensionConfig !== "object" || Object.keys(extensionConfig).length > 0)) {
|
|
297
|
+
removedEntries.push(`${extensionName} configuration`);
|
|
298
|
+
}
|
|
299
|
+
sanitizedExtension[extensionName] = {};
|
|
300
|
+
} else if (isPlainObject(extensionConfig)) {
|
|
301
|
+
const sanitizedConfig = { ...extensionConfig };
|
|
185
302
|
for (const dangerousKey of helpers.DANGEROUS_EXTENSION_CONFIG_KEYS) {
|
|
186
|
-
if (dangerousKey in
|
|
187
|
-
delete
|
|
303
|
+
if (dangerousKey in sanitizedConfig) {
|
|
304
|
+
delete sanitizedConfig[dangerousKey];
|
|
188
305
|
removedEntries.push(dangerousKey);
|
|
189
306
|
}
|
|
190
307
|
}
|
|
308
|
+
sanitizedExtension[extensionName] = sanitizedConfig;
|
|
309
|
+
} else {
|
|
310
|
+
sanitizedExtension[extensionName] = extensionConfig;
|
|
191
311
|
}
|
|
192
312
|
}
|
|
193
|
-
return
|
|
313
|
+
return Object.keys(sanitizedExtension).length > 0 ? [sanitizedExtension] : [];
|
|
194
314
|
});
|
|
195
|
-
|
|
315
|
+
sanitized.markdown_extensions = extensionMapping ? Object.assign({}, ...sanitizedExtensions) : sanitizedExtensions;
|
|
316
|
+
} else if (extensions !== void 0) {
|
|
317
|
+
removedEntries.push("malformed extension declaration");
|
|
318
|
+
sanitized.markdown_extensions = [];
|
|
319
|
+
}
|
|
320
|
+
if (removedEntries.length > 0) {
|
|
321
|
+
logger.warn(
|
|
322
|
+
`Removed the following dangerous entries from markdown_extensions in mkdocs.yml: ${removedEntries.join(
|
|
323
|
+
", "
|
|
324
|
+
)}.`
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if ("plugins" in sanitized) {
|
|
328
|
+
const allowedPlugins = new Set(DEFAULT_ALLOWED_MKDOCS_PLUGINS);
|
|
329
|
+
additionalAllowedPlugins?.forEach((plugin) => allowedPlugins.add(plugin));
|
|
330
|
+
const removedPlugins = /* @__PURE__ */ new Set();
|
|
331
|
+
sanitized.plugins = sanitizeMkdocsPlugins(
|
|
332
|
+
sanitized.plugins,
|
|
333
|
+
allowedPlugins,
|
|
334
|
+
removedPlugins
|
|
335
|
+
);
|
|
336
|
+
if (removedPlugins.size > 0) {
|
|
196
337
|
logger.warn(
|
|
197
|
-
`Removed
|
|
338
|
+
`Removed unsupported MkDocs plugins from mkdocs.yml: ${Array.from(
|
|
339
|
+
removedPlugins
|
|
340
|
+
).join(
|
|
198
341
|
", "
|
|
199
|
-
)}.`
|
|
342
|
+
)}. To allow additional plugins, configure 'techdocs.generator.mkdocs.dangerouslyAllowAdditionalPlugins' in your Backstage app-config. When using the TechDocs CLI, use '--defaultPlugin' instead.`
|
|
200
343
|
);
|
|
201
344
|
}
|
|
202
345
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mkdocsPatchers.cjs.js","sources":["../../../src/stages/generate/mkdocsPatchers.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport { ParsedLocationAnnotation } from '../../helpers';\nimport {\n ALLOWED_MKDOCS_KEYS,\n ALLOWED_THEME_KEYS,\n DANGEROUS_EXTENSION_CONFIG_KEYS,\n getRepoUrlFromLocationAnnotation,\n MKDOCS_SCHEMA,\n} from './helpers';\nimport { toError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nconst MATERIAL_THEME = 'material';\nconst PYMDOWNX_SNIPPETS_EXTENSION = 'pymdownx.snippets';\n\nfunction isPymdownxSnippetsExtension(extensionName: string): boolean {\n return (\n extensionName === PYMDOWNX_SNIPPETS_EXTENSION ||\n extensionName === `${PYMDOWNX_SNIPPETS_EXTENSION}:SnippetExtension`\n );\n}\n\ntype MkDocsThemeObject = {\n name?: string;\n font?: boolean;\n};\n\nfunction isThemeObject(theme: unknown): theme is MkDocsThemeObject {\n return typeof theme === 'object' && theme !== null && !Array.isArray(theme);\n}\n\ntype MkDocsObject = {\n plugins?: string[];\n docs_dir: string;\n repo_url?: string;\n edit_uri?: string;\n theme?: MkDocsThemeObject;\n};\n\nconst patchMkdocsFile = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n updateAction: (mkdocsYml: MkDocsObject) => boolean,\n) => {\n // We only want to override the mkdocs.yml if it has actually changed. This is relevant if\n // used with a 'dir' location on the file system as this would permanently update the file.\n let didEdit = false;\n\n let mkdocsYmlFileString;\n try {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n } catch (error) {\n logger.warn(\n `Could not read MkDocs YAML config file ${mkdocsYmlPath} before running the generator: ${\n toError(error).message\n }`,\n );\n return;\n }\n\n let mkdocsYml: any;\n try {\n mkdocsYml = yaml.load(mkdocsYmlFileString, { schema: MKDOCS_SCHEMA });\n\n // mkdocsYml should be an object type after successful parsing.\n // But based on its type definition, it can also be a string or undefined, which we don't want.\n if (typeof mkdocsYml === 'string' || typeof mkdocsYml === 'undefined') {\n throw new Error('Bad YAML format.');\n }\n } catch (error) {\n logger.warn(\n `Error in parsing YAML at ${mkdocsYmlPath} before running the generator. ${\n toError(error).message\n }`,\n );\n return;\n }\n\n didEdit = updateAction(mkdocsYml);\n\n try {\n if (didEdit) {\n await fs.writeFile(\n mkdocsYmlPath,\n yaml.dump(mkdocsYml, { schema: MKDOCS_SCHEMA }),\n 'utf8',\n );\n }\n } catch (error) {\n logger.warn(\n `Could not write to ${mkdocsYmlPath} after updating it before running the generator. ${\n toError(error).message\n }`,\n );\n return;\n }\n};\n\n/**\n * Update the mkdocs.yml file before TechDocs generator uses it to generate docs site.\n *\n * List of tasks:\n * - Add repo_url or edit_uri if it does not exists\n * If mkdocs.yml has a repo_url, the generated docs site gets an Edit button on the pages by default.\n * If repo_url is missing in mkdocs.yml, we will use techdocs annotation of the entity to possibly get\n * the repository URL.\n *\n * This function will not throw an error since this is not critical to the whole TechDocs pipeline.\n * Instead it will log warnings if there are any errors in reading, parsing or writing YAML.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param parsedLocationAnnotation - Object with location url and type\n * @param scmIntegrations - the scmIntegration to do url transformations\n */\nexport const patchMkdocsYmlPreBuild = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n parsedLocationAnnotation: ParsedLocationAnnotation,\n scmIntegrations: ScmIntegrationRegistry,\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n if (!('repo_url' in mkdocsYml) || !('edit_uri' in mkdocsYml)) {\n // Add edit_uri and/or repo_url to mkdocs.yml if it is missing.\n // This will enable the Page edit button generated by MkDocs.\n // If the either has been set, keep the original value\n const result = getRepoUrlFromLocationAnnotation(\n parsedLocationAnnotation,\n scmIntegrations,\n mkdocsYml.docs_dir,\n );\n\n if (result.repo_url || result.edit_uri) {\n mkdocsYml.repo_url = mkdocsYml.repo_url || result.repo_url;\n mkdocsYml.edit_uri = mkdocsYml.edit_uri || result.edit_uri;\n\n logger.info(\n `Set ${JSON.stringify(\n result,\n )}. You can disable this feature by manually setting 'repo_url' or 'edit_uri' according to the MkDocs documentation at https://www.mkdocs.org/user-guide/configuration/#repo_url`,\n );\n return true;\n }\n }\n return false;\n });\n};\n\n/**\n * Update the mkdocs.yml file before TechDocs generator uses it to generate docs site.\n *\n * List of tasks:\n * - Add all provided default plugins\n *\n * This function will not throw an error since this is not critical to the whole TechDocs pipeline.\n * Instead it will log warnings if there are any errors in reading, parsing or writing YAML.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param defaultPlugins - List of default mkdocs plugins\n */\nexport const patchMkdocsYmlWithPlugins = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n defaultPlugins: string[] = ['techdocs-core'],\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n // Modify mkdocs.yaml to contain the required default plugins.\n // If no plugins are defined we can just return the defaults.\n if (!('plugins' in mkdocsYml)) {\n mkdocsYml.plugins = defaultPlugins;\n return true;\n }\n\n // Otherwise, check each default plugin and include it if necessary.\n let changesMade = false;\n\n defaultPlugins.forEach(dp => {\n // if the plugin isn't there as a string, and isn't there as an object (which may itself contain extra config)\n // then we need to add it\n if (\n !(\n mkdocsYml.plugins!.includes(dp) ||\n mkdocsYml.plugins!.some(p => p.hasOwnProperty(dp))\n )\n ) {\n mkdocsYml.plugins = [...new Set([...mkdocsYml.plugins!, dp])];\n changesMade = true;\n }\n });\n\n return changesMade;\n });\n};\n\n/**\n * Disable external font download for the material theme.\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger\n */\nexport const patchMkdocsYmlWithFontDisabled = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n if (!('theme' in mkdocsYml)) {\n // No theme section exists, create it with font disabled\n mkdocsYml.theme = {\n name: MATERIAL_THEME,\n font: false,\n };\n return true;\n }\n\n const theme = mkdocsYml.theme;\n if (isThemeObject(theme)) {\n // Theme section exists. Only modify it when the configured theme is Material\n if (theme.name === MATERIAL_THEME && !('font' in theme)) {\n theme.font = false;\n return true;\n }\n if (theme.name !== MATERIAL_THEME) {\n logger.debug(\n 'mkdocs.yml theme is not \"material\"; skipping font disabling patch',\n );\n }\n }\n\n return false;\n });\n};\n\n/**\n * Sanitize mkdocs.yml by keeping only allowed configuration keys.\n *\n * TechDocs only supports a subset of MkDocs configuration options.\n * This function reconstructs the config with only allowed keys,\n * discarding everything else. This approach ensures that any unknown\n * or potentially dangerous configuration options are not passed to MkDocs.\n *\n * The file is always rewritten to ensure YAML features like merge keys\n * and anchors are resolved into plain configuration.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param additionalAllowedKeys - Optional array of additional keys to allow beyond the default allowlist\n */\nexport const sanitizeMkdocsYml = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n additionalAllowedKeys?: string[],\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n // Combine default allowed keys with additional keys\n const allowedKeys = new Set(ALLOWED_MKDOCS_KEYS);\n if (additionalAllowedKeys && additionalAllowedKeys.length > 0) {\n logger.warn(\n `DANGEROUS: Allowing additional MkDocs configuration keys beyond the default safe allowlist: ${additionalAllowedKeys.join(\n ', ',\n )}. This may introduce security vulnerabilities. Only use in trusted environments.`,\n );\n additionalAllowedKeys.forEach(key => allowedKeys.add(key));\n }\n\n // Identify keys that will be removed for logging\n const removedKeys = Object.keys(mkdocsYml).filter(\n key => !allowedKeys.has(key),\n );\n\n if (removedKeys.length > 0) {\n logger.warn(\n `Removed the following unsupported configuration keys from mkdocs.yml: ${removedKeys.join(\n ', ',\n )}. ` +\n `TechDocs only supports a subset of MkDocs configuration options.`,\n );\n }\n\n // Build a new object with only allowed keys\n const sanitized: Record<string, unknown> = {};\n for (const key of allowedKeys) {\n if (key in mkdocsYml) {\n sanitized[key] = (mkdocsYml as Record<string, unknown>)[key];\n }\n }\n\n // Sanitize markdown_extensions\n const extensions = sanitized.markdown_extensions;\n if (Array.isArray(extensions)) {\n const removedEntries: string[] = [];\n\n sanitized.markdown_extensions = extensions.filter(ext => {\n if (typeof ext === 'string') {\n if (isPymdownxSnippetsExtension(ext)) {\n return true;\n }\n\n if (ext.includes(':')) {\n removedEntries.push(ext);\n return false;\n }\n return true;\n }\n\n if (!ext || typeof ext !== 'object' || Array.isArray(ext)) {\n return true;\n }\n\n // Check every key, not just the first, so that a multi-key mapping\n // cannot smuggle a dangerous name past the filter.\n const extensionEntries = Object.entries(ext as Record<string, unknown>);\n const dangerousNames = extensionEntries\n .map(([extensionName]) => extensionName)\n .filter(\n extensionName =>\n extensionName.includes(':') &&\n !isPymdownxSnippetsExtension(extensionName),\n );\n if (dangerousNames.length > 0) {\n removedEntries.push(...dangerousNames);\n return false;\n }\n\n for (const [extensionName, extensionConfig] of extensionEntries) {\n if (!isPymdownxSnippetsExtension(extensionName)) {\n continue;\n }\n\n if (\n extensionConfig !== null &&\n (typeof extensionConfig !== 'object' ||\n Object.keys(extensionConfig).length > 0)\n ) {\n removedEntries.push(`${extensionName} configuration`);\n }\n Object.assign(ext, { [extensionName]: {} });\n }\n\n // Strip dangerous keys from the extension's own configuration.\n for (const extConfig of Object.values(ext as Record<string, unknown>)) {\n if (\n extConfig &&\n typeof extConfig === 'object' &&\n !Array.isArray(extConfig)\n ) {\n for (const dangerousKey of DANGEROUS_EXTENSION_CONFIG_KEYS) {\n if (dangerousKey in extConfig) {\n delete (extConfig as Record<string, unknown>)[dangerousKey];\n removedEntries.push(dangerousKey);\n }\n }\n }\n }\n\n return true;\n });\n\n if (removedEntries.length > 0) {\n logger.warn(\n `Removed the following dangerous entries from markdown_extensions in mkdocs.yml: ${removedEntries.join(\n ', ',\n )}.`,\n );\n }\n }\n\n // Clear the original object and copy sanitized values back\n for (const key of Object.keys(mkdocsYml)) {\n delete (mkdocsYml as Record<string, unknown>)[key];\n }\n Object.assign(mkdocsYml, sanitized);\n\n // Sanitize theme sub-keys\n const theme = (mkdocsYml as Record<string, unknown>).theme;\n if (isThemeObject(theme)) {\n const removedThemeKeys = Object.keys(theme).filter(\n key => !ALLOWED_THEME_KEYS.has(key),\n );\n if (removedThemeKeys.length > 0) {\n for (const key of removedThemeKeys) {\n delete (theme as Record<string, unknown>)[key];\n }\n logger.warn(\n `Removed the following unsupported keys from theme configuration in mkdocs.yml: ${removedThemeKeys.join(\n ', ',\n )}.`,\n );\n }\n }\n\n // Always rewrite to ensure clean YAML output (resolves merge keys, anch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xC,MAAA,OAAQ,UAAsC,GAAG,CAAA;AAAA,IACnD;AACA,IAAA,MAAA,CAAO,MAAA,CAAO,WAAW,SAAS,CAAA;AAGlC,IAAA,MAAM,QAAS,SAAA,CAAsC,KAAA;AACrD,IAAA,IAAI,aAAA,CAAc,KAAK,CAAA,EAAG;AACxB,MAAA,MAAM,gBAAA,GAAmB,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,CAAE,MAAA;AAAA,QAC1C,CAAA,GAAA,KAAO,CAACC,0BAAA,CAAmB,GAAA,CAAI,GAAG;AAAA,OACpC;AACA,MAAA,IAAI,gBAAA,CAAiB,SAAS,CAAA,EAAG;AAC/B,QAAA,KAAA,MAAW,OAAO,gBAAA,EAAkB;AAClC,UAAA,OAAQ,MAAkC,GAAG,CAAA;AAAA,QAC/C;AACA,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,kFAAkF,gBAAA,CAAiB,IAAA;AAAA,YACjG;AAAA,WACD,CAAA,CAAA;AAAA,SACH;AAAA,MACF;AAAA,IACF;AAGA,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AACH;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"mkdocsPatchers.cjs.js","sources":["../../../src/stages/generate/mkdocsPatchers.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport fs from 'fs-extra';\nimport yaml from 'js-yaml';\nimport { ParsedLocationAnnotation } from '../../helpers';\nimport {\n ALLOWED_MKDOCS_KEYS,\n ALLOWED_THEME_KEYS,\n DANGEROUS_EXTENSION_CONFIG_KEYS,\n getRepoUrlFromLocationAnnotation,\n MKDOCS_SCHEMA,\n UnknownTag,\n} from './helpers';\nimport { toError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nconst MATERIAL_THEME = 'material';\nconst PYMDOWNX_SNIPPETS_EXTENSION = 'pymdownx.snippets';\n\nconst DEFAULT_ALLOWED_MKDOCS_PLUGINS = new Set([\n 'techdocs-core',\n 'search',\n 'material/search',\n 'redirects',\n 'group',\n 'material/group',\n]);\nconst MKDOCS_PLUGIN_GROUPS = new Set(['group', 'material/group']);\n\nfunction isPymdownxSnippetsExtension(extensionName: string): boolean {\n return (\n extensionName === PYMDOWNX_SNIPPETS_EXTENSION ||\n extensionName === `${PYMDOWNX_SNIPPETS_EXTENSION}:SnippetExtension`\n );\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (\n typeof value !== 'object' ||\n value === null ||\n Array.isArray(value) ||\n value instanceof UnknownTag\n ) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction normalizeMkdocsPlugins(plugins: unknown): unknown[] | undefined {\n if (Array.isArray(plugins)) {\n return plugins;\n }\n if (isPlainObject(plugins)) {\n return Object.entries(plugins).map(([name, config]) => ({\n [name]: config,\n }));\n }\n return undefined;\n}\n\nfunction sanitizeMkdocsPlugins(\n plugins: unknown,\n allowedPlugins: Set<string>,\n removedPlugins: Set<string>,\n): unknown[] {\n if (plugins instanceof UnknownTag) {\n removedPlugins.add('dynamically configured plugin name');\n return [];\n }\n\n const normalizedPlugins = normalizeMkdocsPlugins(plugins);\n if (!normalizedPlugins) {\n removedPlugins.add('malformed plugin declaration');\n return [];\n }\n\n const sanitizedPlugins: unknown[] = [];\n for (const plugin of normalizedPlugins) {\n if (plugin instanceof UnknownTag) {\n removedPlugins.add('dynamically configured plugin name');\n continue;\n }\n\n let pluginName: string;\n if (typeof plugin === 'string' && plugin.length > 0) {\n pluginName = plugin;\n } else if (isPlainObject(plugin) && Object.keys(plugin).length === 1) {\n [pluginName] = Object.keys(plugin);\n const config = plugin[pluginName];\n if (config !== null && !isPlainObject(config)) {\n removedPlugins.add('malformed plugin declaration');\n continue;\n }\n } else {\n removedPlugins.add('malformed plugin declaration');\n continue;\n }\n\n if (!allowedPlugins.has(pluginName)) {\n removedPlugins.add(pluginName);\n continue;\n }\n\n let sanitizedPlugin = plugin;\n if (isPlainObject(plugin)) {\n const config = plugin[pluginName];\n if (MKDOCS_PLUGIN_GROUPS.has(pluginName) && isPlainObject(config)) {\n sanitizedPlugin = {\n ...plugin,\n [pluginName]: {\n ...config,\n plugins: sanitizeMkdocsPlugins(\n config.plugins,\n allowedPlugins,\n removedPlugins,\n ),\n },\n };\n }\n }\n\n sanitizedPlugins.push(sanitizedPlugin);\n }\n\n return sanitizedPlugins;\n}\n\ntype MkDocsThemeObject = {\n name?: string;\n font?: boolean;\n};\n\nfunction isThemeObject(theme: unknown): theme is MkDocsThemeObject {\n return typeof theme === 'object' && theme !== null && !Array.isArray(theme);\n}\n\ntype MkDocsObject = {\n plugins?: string[];\n docs_dir: string;\n repo_url?: string;\n edit_uri?: string;\n theme?: MkDocsThemeObject;\n};\n\nconst patchMkdocsFile = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n updateAction: (mkdocsYml: MkDocsObject) => boolean,\n options?: { failOnError?: boolean },\n) => {\n // We only want to override the mkdocs.yml if it has actually changed. This is relevant if\n // used with a 'dir' location on the file system as this would permanently update the file.\n let didEdit = false;\n\n let mkdocsYmlFileString;\n try {\n mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');\n } catch (error) {\n logger.warn(\n `Could not read MkDocs YAML config file ${mkdocsYmlPath} before running the generator: ${\n toError(error).message\n }`,\n );\n if (options?.failOnError) {\n throw error;\n }\n return;\n }\n\n let mkdocsYml: any;\n try {\n mkdocsYml = yaml.load(mkdocsYmlFileString, { schema: MKDOCS_SCHEMA });\n\n // mkdocsYml should be an object type after successful parsing.\n // But based on its type definition, it can also be a string or undefined, which we don't want.\n if (typeof mkdocsYml === 'string' || typeof mkdocsYml === 'undefined') {\n throw new Error('Bad YAML format.');\n }\n } catch (error) {\n logger.warn(\n `Error in parsing YAML at ${mkdocsYmlPath} before running the generator. ${\n toError(error).message\n }`,\n );\n if (options?.failOnError) {\n throw error;\n }\n return;\n }\n\n didEdit = updateAction(mkdocsYml);\n\n try {\n if (didEdit) {\n await fs.writeFile(\n mkdocsYmlPath,\n yaml.dump(mkdocsYml, { schema: MKDOCS_SCHEMA }),\n 'utf8',\n );\n }\n } catch (error) {\n logger.warn(\n `Could not write to ${mkdocsYmlPath} after updating it before running the generator. ${\n toError(error).message\n }`,\n );\n if (options?.failOnError) {\n throw error;\n }\n return;\n }\n};\n\nconst patchMkdocsFileOrThrow = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n updateAction: (mkdocsYml: MkDocsObject) => boolean,\n) =>\n patchMkdocsFile(mkdocsYmlPath, logger, updateAction, {\n failOnError: true,\n });\n\n/**\n * Update the mkdocs.yml file before TechDocs generator uses it to generate docs site.\n *\n * List of tasks:\n * - Add repo_url or edit_uri if it does not exists\n * If mkdocs.yml has a repo_url, the generated docs site gets an Edit button on the pages by default.\n * If repo_url is missing in mkdocs.yml, we will use techdocs annotation of the entity to possibly get\n * the repository URL.\n *\n * This function will not throw an error since this is not critical to the whole TechDocs pipeline.\n * Instead it will log warnings if there are any errors in reading, parsing or writing YAML.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param parsedLocationAnnotation - Object with location url and type\n * @param scmIntegrations - the scmIntegration to do url transformations\n */\nexport const patchMkdocsYmlPreBuild = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n parsedLocationAnnotation: ParsedLocationAnnotation,\n scmIntegrations: ScmIntegrationRegistry,\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n if (!('repo_url' in mkdocsYml) || !('edit_uri' in mkdocsYml)) {\n // Add edit_uri and/or repo_url to mkdocs.yml if it is missing.\n // This will enable the Page edit button generated by MkDocs.\n // If the either has been set, keep the original value\n const result = getRepoUrlFromLocationAnnotation(\n parsedLocationAnnotation,\n scmIntegrations,\n mkdocsYml.docs_dir,\n );\n\n if (result.repo_url || result.edit_uri) {\n mkdocsYml.repo_url = mkdocsYml.repo_url || result.repo_url;\n mkdocsYml.edit_uri = mkdocsYml.edit_uri || result.edit_uri;\n\n logger.info(\n `Set ${JSON.stringify(\n result,\n )}. You can disable this feature by manually setting 'repo_url' or 'edit_uri' according to the MkDocs documentation at https://www.mkdocs.org/user-guide/configuration/#repo_url`,\n );\n return true;\n }\n }\n return false;\n });\n};\n\n/**\n * Update the mkdocs.yml file before TechDocs generator uses it to generate docs site.\n *\n * List of tasks:\n * - Add all provided default plugins\n *\n * This function will not throw an error since this is not critical to the whole TechDocs pipeline.\n * Instead it will log warnings if there are any errors in reading, parsing or writing YAML.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param defaultPlugins - List of default mkdocs plugins\n */\nexport const patchMkdocsYmlWithPlugins = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n defaultPlugins: string[] = ['techdocs-core'],\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n // Modify mkdocs.yaml to contain the required default plugins.\n // If no plugins are defined we can just return the defaults.\n if (!('plugins' in mkdocsYml)) {\n mkdocsYml.plugins = defaultPlugins;\n return true;\n }\n\n // Otherwise, check each default plugin and include it if necessary.\n let changesMade = false;\n\n defaultPlugins.forEach(dp => {\n // if the plugin isn't there as a string, and isn't there as an object (which may itself contain extra config)\n // then we need to add it\n if (\n !(\n mkdocsYml.plugins!.includes(dp) ||\n mkdocsYml.plugins!.some(p => p.hasOwnProperty(dp))\n )\n ) {\n mkdocsYml.plugins = [...new Set([...mkdocsYml.plugins!, dp])];\n changesMade = true;\n }\n });\n\n return changesMade;\n });\n};\n\n/**\n * Disable external font download for the material theme.\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger\n */\nexport const patchMkdocsYmlWithFontDisabled = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n) => {\n await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {\n if (!('theme' in mkdocsYml)) {\n // No theme section exists, create it with font disabled\n mkdocsYml.theme = {\n name: MATERIAL_THEME,\n font: false,\n };\n return true;\n }\n\n const theme = mkdocsYml.theme;\n if (isThemeObject(theme)) {\n // Theme section exists. Only modify it when the configured theme is Material\n if (theme.name === MATERIAL_THEME && !('font' in theme)) {\n theme.font = false;\n return true;\n }\n if (theme.name !== MATERIAL_THEME) {\n logger.debug(\n 'mkdocs.yml theme is not \"material\"; skipping font disabling patch',\n );\n }\n }\n\n return false;\n });\n};\n\n/**\n * Sanitize mkdocs.yml by keeping only allowed configuration keys.\n *\n * TechDocs only supports a subset of MkDocs configuration options.\n * This function reconstructs the config with only allowed keys,\n * discarding everything else. This approach ensures that any unknown\n * or potentially dangerous configuration options are not passed to MkDocs.\n *\n * The file is always rewritten to ensure YAML features like merge keys\n * and anchors are resolved into plain configuration.\n *\n * @param mkdocsYmlPath - Absolute path to mkdocs.yml or equivalent of a docs site\n * @param logger - A logger instance\n * @param additionalAllowedKeys - Optional array of additional keys to allow beyond the default allowlist\n * @param additionalAllowedPlugins - Optional array of additional plugins to allow beyond the default set\n */\nexport const sanitizeMkdocsYml = async (\n mkdocsYmlPath: string,\n logger: LoggerService,\n additionalAllowedKeys?: string[],\n additionalAllowedPlugins?: string[],\n) => {\n await patchMkdocsFileOrThrow(mkdocsYmlPath, logger, mkdocsYml => {\n // Combine default allowed keys with additional keys\n const allowedKeys = new Set(ALLOWED_MKDOCS_KEYS);\n if (additionalAllowedKeys && additionalAllowedKeys.length > 0) {\n logger.warn(\n `DANGEROUS: Allowing additional MkDocs configuration keys beyond the default safe allowlist: ${additionalAllowedKeys.join(\n ', ',\n )}. This may introduce security vulnerabilities. Only use in trusted environments.`,\n );\n additionalAllowedKeys.forEach(key => allowedKeys.add(key));\n }\n\n // Identify keys that will be removed for logging\n const removedKeys = Object.keys(mkdocsYml).filter(\n key => !allowedKeys.has(key),\n );\n\n if (removedKeys.length > 0) {\n logger.warn(\n `Removed the following unsupported configuration keys from mkdocs.yml: ${removedKeys.join(\n ', ',\n )}. ` +\n `TechDocs only supports a subset of MkDocs configuration options.`,\n );\n }\n\n // Build a new object with only allowed keys\n const sanitized: Record<string, unknown> = {};\n for (const key of allowedKeys) {\n if (key in mkdocsYml) {\n sanitized[key] = (mkdocsYml as Record<string, unknown>)[key];\n }\n }\n\n // Sanitize markdown_extensions\n const extensions = sanitized.markdown_extensions;\n const removedEntries: string[] = [];\n const extensionMapping = isPlainObject(extensions) ? extensions : undefined;\n let normalizedExtensions: unknown[] | undefined;\n if (Array.isArray(extensions)) {\n normalizedExtensions = extensions;\n } else if (extensionMapping) {\n normalizedExtensions = Object.entries(extensionMapping).map(\n ([name, config]) => ({\n [name]: config,\n }),\n );\n }\n if (extensions instanceof UnknownTag) {\n removedEntries.push('dynamically configured extension');\n sanitized.markdown_extensions = [];\n } else if (normalizedExtensions) {\n const sanitizedExtensions = normalizedExtensions.flatMap<unknown>(ext => {\n if (ext instanceof UnknownTag) {\n removedEntries.push('dynamically configured extension');\n return [];\n }\n\n if (typeof ext === 'string') {\n if (isPymdownxSnippetsExtension(ext)) {\n return [ext];\n }\n\n if (ext.includes(':')) {\n removedEntries.push(ext);\n return [];\n }\n return [ext];\n }\n\n if (!isPlainObject(ext)) {\n removedEntries.push('malformed extension declaration');\n return [];\n }\n\n // Check every key, not just the first, so that a multi-key mapping\n // cannot smuggle a dangerous name past the filter.\n const extensionEntries = Object.entries(ext);\n const dangerousNames = extensionEntries\n .map(([extensionName]) => extensionName)\n .filter(\n extensionName =>\n extensionName.includes(':') &&\n !isPymdownxSnippetsExtension(extensionName),\n );\n if (dangerousNames.length > 0) {\n removedEntries.push(...dangerousNames);\n return [];\n }\n\n const sanitizedExtension: Record<string, unknown> = {};\n for (const [extensionName, extensionConfig] of extensionEntries) {\n if (extensionConfig instanceof UnknownTag) {\n removedEntries.push(\n `dynamically configured ${extensionName} extension`,\n );\n continue;\n }\n\n if (isPymdownxSnippetsExtension(extensionName)) {\n if (\n extensionConfig !== null &&\n (typeof extensionConfig !== 'object' ||\n Object.keys(extensionConfig).length > 0)\n ) {\n removedEntries.push(`${extensionName} configuration`);\n }\n sanitizedExtension[extensionName] = {};\n } else if (isPlainObject(extensionConfig)) {\n const sanitizedConfig = { ...extensionConfig };\n for (const dangerousKey of DANGEROUS_EXTENSION_CONFIG_KEYS) {\n if (dangerousKey in sanitizedConfig) {\n delete sanitizedConfig[dangerousKey];\n removedEntries.push(dangerousKey);\n }\n }\n sanitizedExtension[extensionName] = sanitizedConfig;\n } else {\n sanitizedExtension[extensionName] = extensionConfig;\n }\n }\n\n return Object.keys(sanitizedExtension).length > 0\n ? [sanitizedExtension]\n : [];\n });\n\n sanitized.markdown_extensions = extensionMapping\n ? Object.assign({}, ...sanitizedExtensions)\n : sanitizedExtensions;\n } else if (extensions !== undefined) {\n removedEntries.push('malformed extension declaration');\n sanitized.markdown_extensions = [];\n }\n\n if (removedEntries.length > 0) {\n logger.warn(\n `Removed the following dangerous entries from markdown_extensions in mkdocs.yml: ${removedEntries.join(\n ', ',\n )}.`,\n );\n }\n\n if ('plugins' in sanitized) {\n const allowedPlugins = new Set(DEFAULT_ALLOWED_MKDOCS_PLUGINS);\n additionalAllowedPlugins?.forEach(plugin => allowedPlugins.add(plugin));\n\n const removedPlugins = new Set<string>();\n sanitized.plugins = sanitizeMkdocsPlugins(\n sanitized.plugins,\n allowedPlugins,\n removedPlugins,\n );\n\n if (removedPlugins.size > 0) {\n logger.warn(\n `Removed unsupported MkDocs plugins from mkdocs.yml: ${Array.from(\n removedPlugins,\n ).join(\n ', ',\n )}. To allow additional plugins, configure 'techdocs.generator.mkdocs.dangerouslyAllowAdditionalPlugins' in your Backstage app-config. When using the TechDocs CLI, use '--defaultPlugin' instead.`,\n );\n }\n }\n\n // Clear the original object and copy sanitized values back\n for (const key of Object.keys(mkdocsYml)) {\n delete (mkdocsYml as Record<string, unknown>)[key];\n }\n Object.assign(mkdocsYml, sanitized);\n\n // Sanitize theme sub-keys\n const theme = (mkdocsYml as Record<string, unknown>).theme;\n if (isThemeObject(theme)) {\n const removedThemeKeys = Object.keys(theme).filter(\n key => !ALLOWED_THEME_KEYS.has(key),\n );\n if (removedThemeKeys.length > 0) {\n for (const key of removedThemeKeys) {\n delete (theme as Record<string, unknown>)[key];\n }\n logger.warn(\n `Removed the following unsupported keys from theme configuration in mkdocs.yml: ${removedThemeKeys.join(\n ', ',\n )}.`,\n );\n }\n }\n\n // Always rewrite to ensure clean YAML output (resolves merge keys, anchors, etc.)\n return true;\n });\n};\n"],"names":["UnknownTag","fs","toError","yaml","MKDOCS_SCHEMA","getRepoUrlFromLocationAnnotation","ALLOWED_MKDOCS_KEYS","DANGEROUS_EXTENSION_CONFIG_KEYS","ALLOWED_THEME_KEYS"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,cAAA,GAAiB,UAAA;AACvB,MAAM,2BAAA,GAA8B,mBAAA;AAEpC,MAAM,8BAAA,uBAAqC,GAAA,CAAI;AAAA,EAC7C,eAAA;AAAA,EACA,QAAA;AAAA,EACA,iBAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAC,CAAA;AACD,MAAM,uCAAuB,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,gBAAgB,CAAC,CAAA;AAEhE,SAAS,4BAA4B,aAAA,EAAgC;AACnE,EAAA,OACE,aAAA,KAAkB,2BAAA,IAClB,aAAA,KAAkB,CAAA,EAAG,2BAA2B,CAAA,iBAAA,CAAA;AAEpD;AAEA,SAAS,cAAc,KAAA,EAAkD;AACvE,EAAA,IACE,OAAO,KAA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|
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
const docsDir = await helpers.validateMkdocsYaml(inputDir, content);
|
|
74
|
+
const defaultPlugins = [...this.options.defaultPlugins ?? []];
|
|
74
75
|
await mkdocsPatchers.sanitizeMkdocsYml(
|
|
75
76
|
mkdocsYmlPath,
|
|
76
77
|
childLogger,
|
|
77
|
-
this.options.dangerouslyAllowAdditionalKeys
|
|
78
|
+
this.options.dangerouslyAllowAdditionalKeys,
|
|
79
|
+
[
|
|
80
|
+
...this.options.dangerouslyAllowAdditionalPlugins ?? [],
|
|
81
|
+
...defaultPlugins
|
|
82
|
+
]
|
|
78
83
|
);
|
|
79
84
|
if (parsedLocationAnnotation) {
|
|
80
85
|
await mkdocsPatchers.patchMkdocsYmlPreBuild(
|
|
@@ -88,7 +93,6 @@ class TechdocsGenerator {
|
|
|
88
93
|
await helpers.patchIndexPreBuild({ inputDir, logger: childLogger, docsDir });
|
|
89
94
|
}
|
|
90
95
|
await helpers.validateInputDirectory(inputDir);
|
|
91
|
-
const defaultPlugins = this.options.defaultPlugins ?? [];
|
|
92
96
|
if (!this.options.omitTechdocsCoreMkdocsPlugin && !defaultPlugins.includes("techdocs-core")) {
|
|
93
97
|
defaultPlugins.push("techdocs-core");
|
|
94
98
|
}
|
|
@@ -191,6 +195,9 @@ function readGeneratorConfig(config, logger) {
|
|
|
191
195
|
dangerouslyAllowAdditionalKeys: config.getOptionalStringArray(
|
|
192
196
|
"techdocs.generator.mkdocs.dangerouslyAllowAdditionalKeys"
|
|
193
197
|
),
|
|
198
|
+
dangerouslyAllowAdditionalPlugins: config.getOptionalStringArray(
|
|
199
|
+
"techdocs.generator.mkdocs.dangerouslyAllowAdditionalPlugins"
|
|
200
|
+
),
|
|
194
201
|
disableExternalFonts: config.getOptionalBoolean(
|
|
195
202
|
"techdocs.generator.mkdocs.disableExternalFonts"
|
|
196
203
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"techdocs.cjs.js","sources":["../../../src/stages/generate/techdocs.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createOrUpdateMetadata,\n getMkdocsYml,\n patchIndexPreBuild,\n runCommand,\n storeEtagMetadata,\n validateInputDirectory,\n validateMkdocsYaml,\n} from './helpers';\n\nimport {\n patchMkdocsYmlPreBuild,\n patchMkdocsYmlWithFontDisabled,\n patchMkdocsYmlWithPlugins,\n sanitizeMkdocsYml,\n} from './mkdocsPatchers';\nimport {\n GeneratorBase,\n GeneratorConfig,\n GeneratorOptions,\n GeneratorRunInType,\n GeneratorRunOptions,\n} from './types';\nimport { ForwardedError } from '@backstage/errors';\nimport { DockerContainerRunner } from './DockerContainerRunner';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { TechDocsContainerRunner } from './types';\n\n/**\n * Generates documentation files\n * @public\n */\nexport class TechdocsGenerator implements GeneratorBase {\n /**\n * The default docker image (and version) used to generate content. Public\n * and static so that techdocs-node consumers can use the same version.\n *\n * See {@link https://hub.docker.com/r/spotify/techdocs/tags} for list of available versions.\n */\n public static readonly defaultDockerImage = 'spotify/techdocs:v1.2.8';\n private readonly logger: LoggerService;\n private readonly containerRunner?: TechDocsContainerRunner;\n private readonly options: GeneratorConfig;\n private readonly scmIntegrations: ScmIntegrationRegistry;\n\n /**\n * Returns a instance of TechDocs generator\n * @param config - A Backstage configuration\n * @param options - Options to configure the generator\n */\n static fromConfig(config: Config, options: GeneratorOptions) {\n const { containerRunner, logger } = options;\n const scmIntegrations = ScmIntegrations.fromConfig(config);\n return new TechdocsGenerator({\n logger,\n containerRunner,\n config,\n scmIntegrations,\n });\n }\n\n constructor(options: {\n logger: LoggerService;\n containerRunner?: TechDocsContainerRunner;\n config: Config;\n scmIntegrations: ScmIntegrationRegistry;\n }) {\n this.logger = options.logger;\n this.options = readGeneratorConfig(options.config, options.logger);\n this.containerRunner = options.containerRunner;\n this.scmIntegrations = options.scmIntegrations;\n }\n\n /** {@inheritDoc GeneratorBase.run} */\n public async run(options: GeneratorRunOptions): Promise<void> {\n const {\n inputDir,\n outputDir,\n parsedLocationAnnotation,\n etag,\n logger: childLogger,\n logStream,\n siteOptions,\n runAsDefaultUser,\n } = options;\n\n // Do some updates to mkdocs.yml before generating docs e.g. adding repo_url\n const { path: mkdocsYmlPath, content } = await getMkdocsYml(\n inputDir,\n siteOptions,\n );\n\n // Warn if both config files exist — MkDocs and Backstage resolve them in\n // different order, so a second file would be silently ignored by one side.\n const alternateConfigName =\n path.basename(mkdocsYmlPath) === 'mkdocs.yaml'\n ? 'mkdocs.yml'\n : 'mkdocs.yaml';\n if (await fs.pathExists(path.join(inputDir, alternateConfigName))) {\n childLogger.warn(\n `Both mkdocs.yml and mkdocs.yaml found in ${inputDir}; using ${path.basename(\n mkdocsYmlPath,\n )}. The other file will be ignored.`,\n );\n }\n\n // validate the docs_dir first\n const docsDir = await validateMkdocsYaml(inputDir, content);\n\n // Remove unsupported configuration keys\n await sanitizeMkdocsYml(\n mkdocsYmlPath,\n childLogger,\n this.options.dangerouslyAllowAdditionalKeys,\n );\n\n if (parsedLocationAnnotation) {\n await patchMkdocsYmlPreBuild(\n mkdocsYmlPath,\n childLogger,\n parsedLocationAnnotation,\n this.scmIntegrations,\n );\n }\n\n if (this.options.legacyCopyReadmeMdToIndexMd) {\n await patchIndexPreBuild({ inputDir, logger: childLogger, docsDir });\n }\n\n // Validate that no symlinks in the input directory point outside it. MkDocs\n // extensions can access files throughout the input directory, not just docs_dir.\n await validateInputDirectory(inputDir);\n\n // patch the list of mkdocs plugins\n const defaultPlugins = this.options.defaultPlugins ?? [];\n\n if (\n !this.options.omitTechdocsCoreMkdocsPlugin &&\n !defaultPlugins.includes('techdocs-core')\n ) {\n defaultPlugins.push('techdocs-core');\n }\n\n await patchMkdocsYmlWithPlugins(mkdocsYmlPath, childLogger, defaultPlugins);\n if (this.options.disableExternalFonts) {\n await patchMkdocsYmlWithFontDisabled(mkdocsYmlPath, childLogger);\n }\n\n // Directories to bind on container\n const mountDirs = {\n [inputDir]: '/input',\n [outputDir]: '/output',\n };\n\n try {\n switch (this.options.runIn) {\n case 'local':\n await runCommand({\n command: 'mkdocs',\n args: ['build', '-f', mkdocsYmlPath, '-d', outputDir, '-v'],\n options: {\n cwd: inputDir,\n },\n logStream,\n });\n childLogger.info(\n `Successfully generated docs from ${inputDir} into ${outputDir} using local mkdocs`,\n );\n break;\n case 'docker': {\n const containerRunner =\n this.containerRunner || new DockerContainerRunner();\n await containerRunner.runContainer({\n imageName:\n this.options.dockerImage ?? TechdocsGenerator.defaultDockerImage,\n args: [\n 'build',\n '-f',\n `/input/${path.basename(mkdocsYmlPath)}`,\n '-d',\n '/output',\n ],\n logStream,\n mountDirs,\n workingDir: '/input',\n // Set the home directory inside the container as something that applications can\n // write to, otherwise they will just fail trying to write to /\n envVars: { HOME: '/tmp' },\n pullImage: this.options.pullImage,\n defaultUser: runAsDefaultUser,\n });\n childLogger.info(\n `Successfully generated docs from ${inputDir} into ${outputDir} using techdocs-container`,\n );\n break;\n }\n default:\n throw new Error(\n `Invalid config value \"${this.options.runIn}\" provided in 'techdocs.generators.techdocs'.`,\n );\n }\n } catch (error) {\n this.logger.debug(\n `Failed to generate docs from ${inputDir} into ${outputDir}`,\n );\n throw new ForwardedError(\n `Failed to generate docs from ${inputDir} into ${outputDir}`,\n error,\n );\n }\n\n /**\n * Post Generate steps\n */\n\n // Add build timestamp and files to techdocs_metadata.json\n // Creates techdocs_metadata.json if file does not exist.\n await createOrUpdateMetadata(\n path.join(outputDir, 'techdocs_metadata.json'),\n childLogger,\n );\n\n // Add etag of the prepared tree to techdocs_metadata.json\n // Assumes that the file already exists.\n if (etag) {\n await storeEtagMetadata(\n path.join(outputDir, 'techdocs_metadata.json'),\n etag,\n );\n }\n }\n}\n\nexport function readGeneratorConfig(\n config: Config,\n logger: LoggerService,\n): GeneratorConfig {\n const legacyGeneratorType = config.getOptionalString(\n 'techdocs.generators.techdocs',\n ) as GeneratorRunInType;\n\n if (legacyGeneratorType) {\n logger.warn(\n `The 'techdocs.generators.techdocs' configuration key is deprecated and will be removed in the future. Please use 'techdocs.generator' instead. ` +\n `See here https://backstage.io/docs/features/techdocs/configuration`,\n );\n }\n\n return {\n runIn:\n legacyGeneratorType ??\n config.getOptionalString('techdocs.generator.runIn') ??\n 'docker',\n dockerImage: config.getOptionalString('techdocs.generator.dockerImage'),\n pullImage: config.getOptionalBoolean('techdocs.generator.pullImage'),\n omitTechdocsCoreMkdocsPlugin: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.omitTechdocsCorePlugin',\n ),\n legacyCopyReadmeMdToIndexMd: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.legacyCopyReadmeMdToIndexMd',\n ),\n defaultPlugins: config.getOptionalStringArray(\n 'techdocs.generator.mkdocs.defaultPlugins',\n ),\n dangerouslyAllowAdditionalKeys: config.getOptionalStringArray(\n 'techdocs.generator.mkdocs.dangerouslyAllowAdditionalKeys',\n ),\n disableExternalFonts: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.disableExternalFonts',\n ),\n };\n}\n"],"names":["ScmIntegrations","getMkdocsYml","path","fs","validateMkdocsYaml","sanitizeMkdocsYml","patchMkdocsYmlPreBuild","patchIndexPreBuild","validateInputDirectory","patchMkdocsYmlWithPlugins","patchMkdocsYmlWithFontDisabled","runCommand","DockerContainerRunner","ForwardedError","createOrUpdateMetadata","storeEtagMetadata"],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AW,MAAA,CAAO,kBAAA,CAAmB,8BAA8B,CAAA;AAAA,IACnE,8BAA8B,MAAA,CAAO,kBAAA;AAAA,MACnC;AAAA,KACF;AAAA,IACA,6BAA6B,MAAA,CAAO,kBAAA;AAAA,MAClC;AAAA,KACF;AAAA,IACA,gBAAgB,MAAA,CAAO,sBAAA;AAAA,MACrB;AAAA,KACF;AAAA,IACA,gCAAgC,MAAA,CAAO,sBAAA;AAAA,MACrC;AAAA,KACF;AAAA,IACA,sBAAsB,MAAA,CAAO,kBAAA;AAAA,MAC3B;AAAA;AACF,GACF;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"techdocs.cjs.js","sources":["../../../src/stages/generate/techdocs.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport fs from 'fs-extra';\nimport path from 'node:path';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n createOrUpdateMetadata,\n getMkdocsYml,\n patchIndexPreBuild,\n runCommand,\n storeEtagMetadata,\n validateInputDirectory,\n validateMkdocsYaml,\n} from './helpers';\n\nimport {\n patchMkdocsYmlPreBuild,\n patchMkdocsYmlWithFontDisabled,\n patchMkdocsYmlWithPlugins,\n sanitizeMkdocsYml,\n} from './mkdocsPatchers';\nimport {\n GeneratorBase,\n GeneratorConfig,\n GeneratorOptions,\n GeneratorRunInType,\n GeneratorRunOptions,\n} from './types';\nimport { ForwardedError } from '@backstage/errors';\nimport { DockerContainerRunner } from './DockerContainerRunner';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { TechDocsContainerRunner } from './types';\n\n/**\n * Generates documentation files\n * @public\n */\nexport class TechdocsGenerator implements GeneratorBase {\n /**\n * The default docker image (and version) used to generate content. Public\n * and static so that techdocs-node consumers can use the same version.\n *\n * See {@link https://hub.docker.com/r/spotify/techdocs/tags} for list of available versions.\n */\n public static readonly defaultDockerImage = 'spotify/techdocs:v1.2.8';\n private readonly logger: LoggerService;\n private readonly containerRunner?: TechDocsContainerRunner;\n private readonly options: GeneratorConfig;\n private readonly scmIntegrations: ScmIntegrationRegistry;\n\n /**\n * Returns a instance of TechDocs generator\n * @param config - A Backstage configuration\n * @param options - Options to configure the generator\n */\n static fromConfig(config: Config, options: GeneratorOptions) {\n const { containerRunner, logger } = options;\n const scmIntegrations = ScmIntegrations.fromConfig(config);\n return new TechdocsGenerator({\n logger,\n containerRunner,\n config,\n scmIntegrations,\n });\n }\n\n constructor(options: {\n logger: LoggerService;\n containerRunner?: TechDocsContainerRunner;\n config: Config;\n scmIntegrations: ScmIntegrationRegistry;\n }) {\n this.logger = options.logger;\n this.options = readGeneratorConfig(options.config, options.logger);\n this.containerRunner = options.containerRunner;\n this.scmIntegrations = options.scmIntegrations;\n }\n\n /** {@inheritDoc GeneratorBase.run} */\n public async run(options: GeneratorRunOptions): Promise<void> {\n const {\n inputDir,\n outputDir,\n parsedLocationAnnotation,\n etag,\n logger: childLogger,\n logStream,\n siteOptions,\n runAsDefaultUser,\n } = options;\n\n // Do some updates to mkdocs.yml before generating docs e.g. adding repo_url\n const { path: mkdocsYmlPath, content } = await getMkdocsYml(\n inputDir,\n siteOptions,\n );\n\n // Warn if both config files exist — MkDocs and Backstage resolve them in\n // different order, so a second file would be silently ignored by one side.\n const alternateConfigName =\n path.basename(mkdocsYmlPath) === 'mkdocs.yaml'\n ? 'mkdocs.yml'\n : 'mkdocs.yaml';\n if (await fs.pathExists(path.join(inputDir, alternateConfigName))) {\n childLogger.warn(\n `Both mkdocs.yml and mkdocs.yaml found in ${inputDir}; using ${path.basename(\n mkdocsYmlPath,\n )}. The other file will be ignored.`,\n );\n }\n\n // validate the docs_dir first\n const docsDir = await validateMkdocsYaml(inputDir, content);\n\n const defaultPlugins = [...(this.options.defaultPlugins ?? [])];\n\n // Remove unsupported configuration keys and plugins\n await sanitizeMkdocsYml(\n mkdocsYmlPath,\n childLogger,\n this.options.dangerouslyAllowAdditionalKeys,\n [\n ...(this.options.dangerouslyAllowAdditionalPlugins ?? []),\n ...defaultPlugins,\n ],\n );\n\n if (parsedLocationAnnotation) {\n await patchMkdocsYmlPreBuild(\n mkdocsYmlPath,\n childLogger,\n parsedLocationAnnotation,\n this.scmIntegrations,\n );\n }\n\n if (this.options.legacyCopyReadmeMdToIndexMd) {\n await patchIndexPreBuild({ inputDir, logger: childLogger, docsDir });\n }\n\n // Validate that no symlinks in the input directory point outside it. MkDocs\n // extensions can access files throughout the input directory, not just docs_dir.\n await validateInputDirectory(inputDir);\n\n // patch the list of mkdocs plugins\n if (\n !this.options.omitTechdocsCoreMkdocsPlugin &&\n !defaultPlugins.includes('techdocs-core')\n ) {\n defaultPlugins.push('techdocs-core');\n }\n\n await patchMkdocsYmlWithPlugins(mkdocsYmlPath, childLogger, defaultPlugins);\n if (this.options.disableExternalFonts) {\n await patchMkdocsYmlWithFontDisabled(mkdocsYmlPath, childLogger);\n }\n\n // Directories to bind on container\n const mountDirs = {\n [inputDir]: '/input',\n [outputDir]: '/output',\n };\n\n try {\n switch (this.options.runIn) {\n case 'local':\n await runCommand({\n command: 'mkdocs',\n args: ['build', '-f', mkdocsYmlPath, '-d', outputDir, '-v'],\n options: {\n cwd: inputDir,\n },\n logStream,\n });\n childLogger.info(\n `Successfully generated docs from ${inputDir} into ${outputDir} using local mkdocs`,\n );\n break;\n case 'docker': {\n const containerRunner =\n this.containerRunner || new DockerContainerRunner();\n await containerRunner.runContainer({\n imageName:\n this.options.dockerImage ?? TechdocsGenerator.defaultDockerImage,\n args: [\n 'build',\n '-f',\n `/input/${path.basename(mkdocsYmlPath)}`,\n '-d',\n '/output',\n ],\n logStream,\n mountDirs,\n workingDir: '/input',\n // Set the home directory inside the container as something that applications can\n // write to, otherwise they will just fail trying to write to /\n envVars: { HOME: '/tmp' },\n pullImage: this.options.pullImage,\n defaultUser: runAsDefaultUser,\n });\n childLogger.info(\n `Successfully generated docs from ${inputDir} into ${outputDir} using techdocs-container`,\n );\n break;\n }\n default:\n throw new Error(\n `Invalid config value \"${this.options.runIn}\" provided in 'techdocs.generators.techdocs'.`,\n );\n }\n } catch (error) {\n this.logger.debug(\n `Failed to generate docs from ${inputDir} into ${outputDir}`,\n );\n throw new ForwardedError(\n `Failed to generate docs from ${inputDir} into ${outputDir}`,\n error,\n );\n }\n\n /**\n * Post Generate steps\n */\n\n // Add build timestamp and files to techdocs_metadata.json\n // Creates techdocs_metadata.json if file does not exist.\n await createOrUpdateMetadata(\n path.join(outputDir, 'techdocs_metadata.json'),\n childLogger,\n );\n\n // Add etag of the prepared tree to techdocs_metadata.json\n // Assumes that the file already exists.\n if (etag) {\n await storeEtagMetadata(\n path.join(outputDir, 'techdocs_metadata.json'),\n etag,\n );\n }\n }\n}\n\nexport function readGeneratorConfig(\n config: Config,\n logger: LoggerService,\n): GeneratorConfig {\n const legacyGeneratorType = config.getOptionalString(\n 'techdocs.generators.techdocs',\n ) as GeneratorRunInType;\n\n if (legacyGeneratorType) {\n logger.warn(\n `The 'techdocs.generators.techdocs' configuration key is deprecated and will be removed in the future. Please use 'techdocs.generator' instead. ` +\n `See here https://backstage.io/docs/features/techdocs/configuration`,\n );\n }\n\n return {\n runIn:\n legacyGeneratorType ??\n config.getOptionalString('techdocs.generator.runIn') ??\n 'docker',\n dockerImage: config.getOptionalString('techdocs.generator.dockerImage'),\n pullImage: config.getOptionalBoolean('techdocs.generator.pullImage'),\n omitTechdocsCoreMkdocsPlugin: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.omitTechdocsCorePlugin',\n ),\n legacyCopyReadmeMdToIndexMd: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.legacyCopyReadmeMdToIndexMd',\n ),\n defaultPlugins: config.getOptionalStringArray(\n 'techdocs.generator.mkdocs.defaultPlugins',\n ),\n dangerouslyAllowAdditionalKeys: config.getOptionalStringArray(\n 'techdocs.generator.mkdocs.dangerouslyAllowAdditionalKeys',\n ),\n dangerouslyAllowAdditionalPlugins: config.getOptionalStringArray(\n 'techdocs.generator.mkdocs.dangerouslyAllowAdditionalPlugins',\n ),\n disableExternalFonts: config.getOptionalBoolean(\n 'techdocs.generator.mkdocs.disableExternalFonts',\n ),\n };\n}\n"],"names":["ScmIntegrations","getMkdocsYml","path","fs","validateMkdocsYaml","sanitizeMkdocsYml","patchMkdocsYmlPreBuild","patchIndexPreBuild","validateInputDirectory","patchMkdocsYmlWithPlugins","patchMkdocsYmlWithFontDisabled","runCommand","DockerContainerRunner","ForwardedError","createOrUpdateMetadata","storeEtagMetadata"],"mappings":";;;;;;;;;;;;;;;AAuDO,MAAM,iBAAA,CAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtD,OAAuB,kBAAA,GAAqB,yBAAA;AAAA,EAC3B,MAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjB,OAAO,UAAA,CAAW,MAAA,EAAgB,OAAA,EAA2B;AAC3D,IAAA,MAAM,EAAE,eAAA,EAAiB,MAAA,EAAO,GAAI,OAAA;AACpC,IAAA,MAAM,eAAA,GAAkBA,2BAAA,CAAgB,UAAA,CAAW,MAAM,CAAA;AACzD,IAAA,OAAO,IAAI,iBAAA,CAAkB;AAAA,MAC3B,MAAA;AAAA,MACA,eAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AAAA,EAEA,YAAY,OAAA,EAKT;AACD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,OAAA,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