From d6f4a62733474451078ca263e58733da86b1e004 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Thu, 23 Apr 2026 23:45:01 +0900 Subject: [PATCH 1/2] build(parser): bundle types using api-extractor Use `@microsoft/api-extractor` to bundle the TypeScript `.d.ts` types for `@mermaid-js/parser`. In a future commit, we want to bundle `langium`, which would need us to bundle `langium`'s types as well. Bundling reduces the size of our `dist/` folder, and makes it more obvious which of our types are external. I've made this as a `prepack` step, so that it doesn't affect the majority of mermaid developers when they run `pnpm install`. It's only when we publish the package that we'd bundle the code. This also means it will be tested by the `pnpm run test:check:tsc` test that we have. --- packages/parser/api-extractor.json | 233 +++++++++++++++++++++++++++++ packages/parser/package.json | 4 +- packages/parser/scripts/prepack.ts | 60 ++++++++ packages/parser/tsconfig.json | 2 +- pnpm-lock.yaml | 232 +++++++++++++++++++++++++--- scripts/tsc-check.ts | 2 +- 6 files changed, 513 insertions(+), 20 deletions(-) create mode 100644 packages/parser/api-extractor.json create mode 100755 packages/parser/scripts/prepack.ts diff --git a/packages/parser/api-extractor.json b/packages/parser/api-extractor.json new file mode 100644 index 00000000000..f5e310a9646 --- /dev/null +++ b/packages/parser/api-extractor.json @@ -0,0 +1,233 @@ +/** + * Config file for API Extractor. For more info, please visit: https://api-extractor.com + */ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + + /** + * (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor + * analyzes the symbols exported by this module. + * + * The file extension must be ".d.ts" and not ".ts". + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + */ + "mainEntryPointFilePath": "/dist/src/index.d.ts", + + /** + * A list of NPM package names whose exports should be treated as part of this package. + * + * For example, suppose that Webpack is used to generate a distributed bundle for the project "library1", + * and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part + * of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly + * imports library2. To avoid this, we might specify: + * + * "bundledPackages": [ "library2" ], + * + * This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been + * local files for library1. + * + * The "bundledPackages" elements may specify glob patterns using minimatch syntax. To ensure deterministic + * output, globs are expanded by matching explicitly declared top-level dependencies only. For example, + * the pattern below will NOT match "@my-company/example" unless it appears in a field such as "dependencies" + * or "devDependencies" of the project's package.json file: + * + * "bundledPackages": [ "@my-company/*" ], + */ + "bundledPackages": [], + + /** + * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files + * will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead. + * To use the OS's default newline kind, specify "os". + * + * DEFAULT VALUE: "crlf" + */ + "newlineKind": "lf", + + /** + * Specifies how API Extractor sorts members of an enum when generating the .api.json file. By default, the output + * files will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify + * "preserve". + * + * DEFAULT VALUE: "by-name" + */ + // "enumMemberOrder": "by-name", + + /** + * Set to true when invoking API Extractor's test harness. When `testMode` is true, the `toolVersion` field in the + * .api.json file is assigned an empty string to prevent spurious diffs in output files tracked for tests. + * + * DEFAULT VALUE: "false" + */ + // "testMode": false, + + /** + * Determines how the TypeScript compiler engine will be invoked by API Extractor. + */ + "compiler": { + /** + * Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * Note: This setting will be ignored if "overrideTsconfig" is used. + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/tsconfig.json" + */ + // "tsconfigFilePath": "/tsconfig.json", + /** + * Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk. + * The object must conform to the TypeScript tsconfig schema: + * + * http://json.schemastore.org/tsconfig + * + * If omitted, then the tsconfig.json file will be read from the "projectFolder". + * + * DEFAULT VALUE: no overrideTsconfig section + */ + // "overrideTsconfig": { + // . . . + // } + /** + * This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended + * and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when + * dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses + * for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck. + * + * DEFAULT VALUE: false + */ + // "skipLibCheck": true, + }, + + /** + * Configures how the API report file (*.api.md) will be generated. + */ + "apiReport": { + /** + * (REQUIRED) Whether to generate an API report. + */ + "enabled": false + }, + + /** + * Configures how the doc model file (*.api.json) will be generated. + */ + "docModel": { + /** + * (REQUIRED) Whether to generate a doc model file. + */ + "enabled": false + }, + + /** + * Configures how the .d.ts rollup file will be generated. + */ + "dtsRollup": { + /** + * (REQUIRED) Whether to generate the .d.ts rollup file. + */ + "enabled": true, + + /** + * Specifies the output path for a .d.ts rollup file to be generated without any trimming. + * This file will include all declarations that are exported by the main entry point. + * + * If the path is an empty string, then this file will not be written. + * + * The path is resolved relative to the folder of the config file that contains the setting; to change this, + * prepend a folder token such as "". + * + * SUPPORTED TOKENS: , , + * DEFAULT VALUE: "/dist/.d.ts" + */ + "untrimmedFilePath": "/dist/src/index.d.ts" + }, + + /** + * Configures how the tsdoc-metadata.json file will be generated. + */ + "tsdocMetadata": { + /** + * Whether to generate the tsdoc-metadata.json file. + * + * DEFAULT VALUE: true + */ + "enabled": false + }, + + /** + * Configures how API Extractor reports error and warning messages produced during analysis. + * + * There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages. + */ + "messages": { + /** + * Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing + * the input .d.ts files. + * + * TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551" + * + * DEFAULT VALUE: A single "default" entry with logLevel=warning. + */ + "compilerMessageReporting": { + /** + * Configures the default routing for messages that don't match an explicit rule in this table. + */ + "default": { + /** + * Specifies whether the message should be written to the the tool's output log. Note that + * the "addToApiReportFile" property may supersede this option. + * + * Possible values: "error", "warning", "none" + * + * Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail + * and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes + * the "--local" option), the warning is displayed but the build will not fail. + * + * DEFAULT VALUE: "warning" + */ + "logLevel": "warning" + } + }, + + /** + * Configures handling of messages reported by API Extractor during its analysis. + * + * API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag" + * + * DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings + */ + "extractorMessageReporting": { + "default": { + "logLevel": "warning" + }, + "ae-forgotten-export": { + /** Most of our typescript files are generated by langium */ + "logLevel": "none" + }, + "ae-missing-release-tag": { + /** Most of our typescript files are generated by langium */ + "logLevel": "none" + } + }, + + /** + * Configures handling of messages reported by the TSDoc parser when analyzing code comments. + * + * TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text" + * + * DEFAULT VALUE: A single "default" entry with logLevel=warning. + */ + "tsdocMessageReporting": { + "default": { + "logLevel": "warning" + } + } + } +} diff --git a/packages/parser/package.json b/packages/parser/package.json index c8fb333d076..572bf5e5e1c 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -19,7 +19,8 @@ "scripts": { "clean": "rimraf dist src/language/generated", "langium:generate": "langium generate", - "langium:watch": "langium generate --watch" + "langium:watch": "langium generate --watch", + "prepack": "./scripts/prepack.ts" }, "repository": { "type": "git", @@ -36,6 +37,7 @@ "langium": "^4.0.0" }, "devDependencies": { + "@microsoft/api-extractor": "^7.57.0", "chevrotain": "~11.1.1" }, "files": [ diff --git a/packages/parser/scripts/prepack.ts b/packages/parser/scripts/prepack.ts new file mode 100755 index 00000000000..93c62702d40 --- /dev/null +++ b/packages/parser/scripts/prepack.ts @@ -0,0 +1,60 @@ +#!/usr/bin/env -S node --experimental-strip-types + +/** + * Runs `api-extractor` to create a single `dist/src/index.d.ts` bundle, + * then removes all unused `dist/*.d.ts` files. + */ +import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'; +import { glob, rm, rmdir } from 'node:fs/promises'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// Run API extractor to create new `dist/src/index.d.ts` file +let typesBundle; +{ + const apiExtractorJsonPath = fileURLToPath(import.meta.resolve('../api-extractor.json')); + + // Load and parse the api-extractor.json file + const extractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath); + + // Invoke API Extractor + const extractorResult = Extractor.invoke(extractorConfig, { + localBuild: !process.env.CI, + // Equivalent to the "--verbose" command-line parameter + showVerboseMessages: true, + }); + + if (!extractorResult.succeeded) { + throw new Error( + `API Extractor completed with ${extractorResult.errorCount} errors` + + ` and ${extractorResult.warningCount} warnings` + ); + } + typesBundle = extractorResult.extractorConfig.untrimmedFilePath; +} + +// Remove all other `dist/*.d.ts` files +const rootDir = fileURLToPath(import.meta.resolve('../')); +for await (const file of glob('./dist/**/*.d.ts', { + cwd: rootDir, + exclude: [typesBundle], +})) { + await rm(join(rootDir, file)); +} + +// @ts-expect-error -- Our tsconfig.json doesn't support `Array.fromAsync` +const directories: string[] = await Array.fromAsync( + glob('./dist/**/', { + cwd: rootDir, + }) +); +// delete subdirectories before their parents +for (const dir of directories.sort().reverse()) { + try { + await rmdir(join(rootDir, dir)); + } catch (err) { + if (err instanceof Error && 'code' in err && err.code !== 'ENOTEMPTY') { + throw err; + } + } +} diff --git a/packages/parser/tsconfig.json b/packages/parser/tsconfig.json index 4822488c9bd..1f89c08b1ff 100644 --- a/packages/parser/tsconfig.json +++ b/packages/parser/tsconfig.json @@ -6,6 +6,6 @@ "allowJs": false, "strictPropertyInitialization": false }, - "include": ["./src/**/*.ts", "./tests/**/*.ts"], + "include": ["./src/**/*.ts", "./tests/**/*.ts", "./scripts/**/*.ts"], "typeRoots": ["./src/types"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad4fee6f4ac..91bd08f47ba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -551,6 +551,9 @@ importers: specifier: ^4.0.0 version: 4.2.0 devDependencies: + '@microsoft/api-extractor': + specifier: ^7.57.0 + version: 7.57.8(@types/node@22.19.1) chevrotain: specifier: ~11.1.1 version: 11.1.1 @@ -2795,12 +2798,25 @@ packages: '@mdi/font@7.4.47': resolution: {integrity: sha512-43MtGpd585SNzHZPcYowu/84Vz2a2g31TvPMTm9uTiCSWzaheQySUcSyUH/46fPnuPQWof2yd0pGBtzee/IQWw==} + '@microsoft/api-extractor-model@7.33.5': + resolution: {integrity: sha512-Xh4dXuusndVQqVz4nEN9xOp0DyzsKxeD2FFJkSPg4arAjDSKPcy6cAc7CaeBPA7kF2wV1fuDlo2p/bNMpVr8yg==} + + '@microsoft/api-extractor@7.57.8': + resolution: {integrity: sha512-RI0TxUGA3T0zwuyMIg86aHxAqJJNCjoFnIO/oVzyofxyxqokrXXiLenSBTVHGRyh6vUHg1mKGlT+LhKRF+oczg==} + hasBin: true + '@microsoft/tsdoc-config@0.17.1': resolution: {integrity: sha512-UtjIFe0C6oYgTnad4q1QP4qXwLhe6tIpNTRStJ2RZEPIkqQPREAwE5spzVxsdn9UaEMUqhh0AqSx3X4nWAKXWw==} + '@microsoft/tsdoc-config@0.18.1': + resolution: {integrity: sha512-9brPoVdfN9k9g0dcWkFeA7IH9bbcttzDJlXvkf8b2OBzd5MueR1V2wkKBL0abn0otvmkHJC6aapBOTJDDeMCZg==} + '@microsoft/tsdoc@0.15.1': resolution: {integrity: sha512-4aErSrCR/On/e5G2hDP0wjooqDdauzEbIq8hIkIe5pXV0rtWJZvdCEKL0ykZxex+IxIwBp0eGeV48hQN07dXtw==} + '@microsoft/tsdoc@0.16.0': + resolution: {integrity: sha512-xgAyonlVVS+q7Vc7qLW0UrJU7rSFcETRWsqdXZtjzRU8dF+6CkozTK4V4y1LwOX7j8r/vHphjDeMeGI4tNGeGA==} + '@napi-rs/wasm-runtime@0.2.12': resolution: {integrity: sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ==} @@ -3073,6 +3089,36 @@ packages: cpu: [x64] os: [win32] + '@rushstack/node-core-library@5.21.0': + resolution: {integrity: sha512-LFzN+1lyWROit/P8Md6yxAth7lLYKn37oCKJHirEE2TQB25NDUM7bALf0ar+JAtwFfRCH+D+DGOA7DAzIi2r+g==} + peerDependencies: + '@types/node': '*' + peerDependenciesMeta: + '@types/node': + optional: true + + '@rushstack/problem-matcher@0.2.1': + resolution: {integrity: sha512-gulfhBs6n+I5b7DvjKRfhMGyUejtSgOHTclF/eONr8hcgF1APEDjhxIsfdUYYMzC3rvLwGluqLjbwCFZ8nxrog==} + peerDependencies: + '@types/node': '*' + peerDependenciesMeta: + '@types/node': + optional: true + + '@rushstack/rig-package@0.7.2': + resolution: {integrity: sha512-9XbFWuqMYcHUso4mnETfhGVUSaADBRj6HUAAEYk50nMPn8WRICmBuCphycQGNB3duIR6EEZX3Xj3SYc2XiP+9A==} + + '@rushstack/terminal@0.22.4': + resolution: {integrity: sha512-fhtLjnXCc/4WleVbVl6aoc7jcWnU6yqjS1S8WoaNREG3ycu/viZ9R/9QM7Y/b4CDvcXoiDyMNIay7JMwBptM3g==} + peerDependencies: + '@types/node': '*' + peerDependenciesMeta: + '@types/node': + optional: true + + '@rushstack/ts-command-line@5.3.4': + resolution: {integrity: sha512-MLkVKVEN6/2clKTrjN2B2KqKCuPxRwnNsWY7a+FCAq2EMdkj10cM8YgiBSMeGFfzM0mDMzargpHNnNzaBi9Whg==} + '@shikijs/core@2.5.0': resolution: {integrity: sha512-uu/8RExTKtavlpH7XqnVYBrfBkUc20ngXiX9NSrBhOVZYv/7XQRKUyhtkeflY5QsxC0GbJThCerruZfsUaSldg==} @@ -3159,6 +3205,9 @@ packages: '@tybys/wasm-util@0.10.1': resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==} + '@types/argparse@1.0.38': + resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==} + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -4107,6 +4156,14 @@ packages: resolution: {integrity: sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==} engines: {node: '>=12'} + ajv-draft-04@1.0.0: + resolution: {integrity: sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==} + peerDependencies: + ajv: ^8.5.0 + peerDependenciesMeta: + ajv: + optional: true + ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} peerDependencies: @@ -4372,6 +4429,10 @@ packages: balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + balanced-match@4.0.4: + resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==} + engines: {node: 18 || 20 || >=22} + base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} @@ -4450,6 +4511,10 @@ packages: brace-expansion@2.1.0: resolution: {integrity: sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==} + brace-expansion@5.0.5: + resolution: {integrity: sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==} + engines: {node: 18 || 20 || >=22} + braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -5443,6 +5508,10 @@ packages: didyoumean@1.2.2: resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==} + diff@8.0.4: + resolution: {integrity: sha512-DPi0FmjiSU5EvQV0++GFDOJ9ASQUVFh5kD+OzOnYdi7n3Wpm9hWWGfB/O2blfHcMVTL5WkQXSnRiK9makhrcnw==} + engines: {node: '>=0.3.1'} + dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -6551,6 +6620,10 @@ packages: resolution: {integrity: sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==} engines: {node: '>=6'} + import-lazy@4.0.0: + resolution: {integrity: sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==} + engines: {node: '>=8'} + import-local@3.2.0: resolution: {integrity: sha512-2SPlun1JUPWoM6t3F0dw0FkCF/jWY8kttcY4f599GLTSjh2OCuuhdTkJQsEcZzBqbXZGKMK2OqW1oZsjtf/gQA==} engines: {node: '>=8'} @@ -7351,6 +7424,9 @@ packages: lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + lodash@4.17.23: + resolution: {integrity: sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==} + lodash@4.18.1: resolution: {integrity: sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==} @@ -7396,6 +7472,10 @@ packages: lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} + lru-cache@6.0.0: + resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} + engines: {node: '>=10'} + lunr@2.3.9: resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} @@ -7682,13 +7762,13 @@ packages: resolution: {integrity: sha512-IPZ167aShDZZUMdRk66cyQAW3qr0WzbHkPdMYa8bzZhlHhO3jALbKdxcaak7W9FfT2rZNpQuUu4Od7ILEpXSaw==} engines: {node: 20 || >=22} + minimatch@10.2.3: + resolution: {integrity: sha512-Rwi3pnapEqirPSbWbrZaa6N3nmqq4Xer/2XooiOKyV3q12ML06f7MOuc5DVH8ONZIFhwIYQ3yzPH4nt7iWHaTg==} + engines: {node: 18 || 20 || >=22} + minimatch@3.1.2: resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} - minimatch@5.1.6: - resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==} - engines: {node: '>=10'} - minimatch@5.1.9: resolution: {integrity: sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==} engines: {node: '>=10'} @@ -8813,6 +8893,11 @@ packages: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true + semver@7.5.4: + resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} + engines: {node: '>=10'} + hasBin: true + semver@7.6.2: resolution: {integrity: sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==} engines: {node: '>=10'} @@ -9554,6 +9639,11 @@ packages: engines: {node: '>=14.17'} hasBin: true + typescript@5.8.2: + resolution: {integrity: sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==} + engines: {node: '>=14.17'} + hasBin: true + typescript@5.8.3: resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==} engines: {node: '>=14.17'} @@ -10255,6 +10345,9 @@ packages: yallist@3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} + yallist@4.0.0: + resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + yaml@2.8.1: resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==} engines: {node: '>= 14.6'} @@ -12097,7 +12190,7 @@ snapshots: babel-loader: 10.0.0(@babel/core@7.29.0)(webpack@5.101.3(esbuild@0.25.12)) bluebird: 3.7.1 debug: 4.4.0 - lodash: 4.17.21 + lodash: 4.18.1 semver: 7.7.3 webpack: 5.101.3(esbuild@0.25.12) transitivePeerDependencies: @@ -12913,15 +13006,51 @@ snapshots: '@mdi/font@7.4.47': {} + '@microsoft/api-extractor-model@7.33.5(@types/node@22.19.1)': + dependencies: + '@microsoft/tsdoc': 0.16.0 + '@microsoft/tsdoc-config': 0.18.1 + '@rushstack/node-core-library': 5.21.0(@types/node@22.19.1) + transitivePeerDependencies: + - '@types/node' + + '@microsoft/api-extractor@7.57.8(@types/node@22.19.1)': + dependencies: + '@microsoft/api-extractor-model': 7.33.5(@types/node@22.19.1) + '@microsoft/tsdoc': 0.16.0 + '@microsoft/tsdoc-config': 0.18.1 + '@rushstack/node-core-library': 5.21.0(@types/node@22.19.1) + '@rushstack/rig-package': 0.7.2 + '@rushstack/terminal': 0.22.4(@types/node@22.19.1) + '@rushstack/ts-command-line': 5.3.4(@types/node@22.19.1) + diff: 8.0.4 + lodash: 4.17.23 + minimatch: 10.2.3 + resolve: 1.22.12 + semver: 7.5.4 + source-map: 0.6.1 + typescript: 5.8.2 + transitivePeerDependencies: + - '@types/node' + '@microsoft/tsdoc-config@0.17.1': dependencies: '@microsoft/tsdoc': 0.15.1 ajv: 8.12.0 jju: 1.4.0 - resolve: 1.22.10 + resolve: 1.22.12 + + '@microsoft/tsdoc-config@0.18.1': + dependencies: + '@microsoft/tsdoc': 0.16.0 + ajv: 8.18.0 + jju: 1.4.0 + resolve: 1.22.12 '@microsoft/tsdoc@0.15.1': {} + '@microsoft/tsdoc@0.16.0': {} + '@napi-rs/wasm-runtime@0.2.12': dependencies: '@emnapi/core': 1.5.0 @@ -13147,6 +13276,45 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.60.1': optional: true + '@rushstack/node-core-library@5.21.0(@types/node@22.19.1)': + dependencies: + ajv: 8.18.0 + ajv-draft-04: 1.0.0(ajv@8.18.0) + ajv-formats: 3.0.1(ajv@8.18.0) + fs-extra: 11.3.2 + import-lazy: 4.0.0 + jju: 1.4.0 + resolve: 1.22.12 + semver: 7.5.4 + optionalDependencies: + '@types/node': 22.19.1 + + '@rushstack/problem-matcher@0.2.1(@types/node@22.19.1)': + optionalDependencies: + '@types/node': 22.19.1 + + '@rushstack/rig-package@0.7.2': + dependencies: + resolve: 1.22.12 + strip-json-comments: 3.1.1 + + '@rushstack/terminal@0.22.4(@types/node@22.19.1)': + dependencies: + '@rushstack/node-core-library': 5.21.0(@types/node@22.19.1) + '@rushstack/problem-matcher': 0.2.1(@types/node@22.19.1) + supports-color: 8.1.1 + optionalDependencies: + '@types/node': 22.19.1 + + '@rushstack/ts-command-line@5.3.4(@types/node@22.19.1)': + dependencies: + '@rushstack/terminal': 0.22.4(@types/node@22.19.1) + '@types/argparse': 1.0.38 + argparse: 1.0.10 + string-argv: 0.3.2 + transitivePeerDependencies: + - '@types/node' + '@shikijs/core@2.5.0': dependencies: '@shikijs/engine-javascript': 2.5.0 @@ -13253,6 +13421,8 @@ snapshots: tslib: 2.8.1 optional: true + '@types/argparse@1.0.38': {} + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.28.5 @@ -14442,6 +14612,10 @@ snapshots: clean-stack: 4.2.0 indent-string: 5.0.0 + ajv-draft-04@1.0.0(ajv@8.18.0): + optionalDependencies: + ajv: 8.18.0 + ajv-formats@2.1.1(ajv@8.18.0): optionalDependencies: ajv: 8.18.0 @@ -14727,6 +14901,8 @@ snapshots: balanced-match@1.0.2: {} + balanced-match@4.0.4: {} + base64-js@1.5.1: {} baseline-browser-mapping@2.10.18: {} @@ -14830,6 +15006,10 @@ snapshots: dependencies: balanced-match: 1.0.2 + brace-expansion@5.0.5: + dependencies: + balanced-match: 4.0.4 + braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -15934,6 +16114,8 @@ snapshots: didyoumean@1.2.2: {} + diff@8.0.4: {} + dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -16745,7 +16927,7 @@ snapshots: enhanced-resolve: 5.18.3 module-definition: 6.0.1 module-lookup-amd: 9.0.5 - resolve: 1.22.10 + resolve: 1.22.12 resolve-dependency-path: 4.0.1 sass-lookup: 6.1.0 stylus-lookup: 6.1.0 @@ -16792,7 +16974,7 @@ snapshots: console.table: 0.10.0 debug: 4.4.3(supports-color@8.1.1) find-test-names: 1.29.19(@babel/core@7.29.0) - minimatch: 5.1.6 + minimatch: 5.1.9 pluralize: 8.0.0 require-and-forget: 1.0.1 shelljs: 0.10.0 @@ -17067,7 +17249,7 @@ snapshots: fs.realpath: 1.0.0 inflight: 1.0.6 inherits: 2.0.4 - minimatch: 5.1.6 + minimatch: 5.1.9 once: 1.4.0 global-directory@4.0.1: @@ -17371,6 +17553,8 @@ snapshots: parent-module: 1.0.1 resolve-from: 4.0.0 + import-lazy@4.0.0: {} + import-local@3.2.0: dependencies: pkg-dir: 4.2.0 @@ -17837,7 +18021,7 @@ snapshots: get-stdin: 5.0.1 glur: 1.1.2 jest: 30.1.3(@types/node@22.19.1) - lodash: 4.17.21 + lodash: 4.18.1 mkdirp: 0.5.6 pixelmatch: 5.3.0 pngjs: 3.4.0 @@ -18351,6 +18535,8 @@ snapshots: lodash@4.17.21: {} + lodash@4.17.23: {} + lodash@4.18.1: {} log-symbols@4.1.0: @@ -18393,6 +18579,10 @@ snapshots: dependencies: yallist: 3.1.1 + lru-cache@6.0.0: + dependencies: + yallist: 4.0.0 + lunr@2.3.9: {} magic-string@0.25.9: @@ -18859,13 +19049,13 @@ snapshots: dependencies: '@isaacs/brace-expansion': 5.0.0 - minimatch@3.1.2: + minimatch@10.2.3: dependencies: - brace-expansion: 1.1.12 + brace-expansion: 5.0.5 - minimatch@5.1.6: + minimatch@3.1.2: dependencies: - brace-expansion: 2.0.2 + brace-expansion: 1.1.12 minimatch@5.1.9: dependencies: @@ -19465,7 +19655,7 @@ snapshots: postcss: 8.5.8 postcss-value-parser: 4.2.0 read-cache: 1.0.0 - resolve: 1.22.10 + resolve: 1.22.12 postcss-js@4.0.1(postcss@8.5.8): dependencies: @@ -19711,7 +19901,7 @@ snapshots: rechoir@0.7.1: dependencies: - resolve: 1.22.10 + resolve: 1.22.12 reflect.getprototypeof@1.0.10: dependencies: @@ -20046,6 +20236,10 @@ snapshots: semver@6.3.1: {} + semver@7.5.4: + dependencies: + lru-cache: 6.0.0 + semver@7.6.2: {} semver@7.7.2: {} @@ -20662,7 +20856,7 @@ snapshots: dependencies: '@babel/runtime': 7.28.4 bluebird: 3.7.2 - lodash: 4.17.21 + lodash: 4.18.1 shell-quote: 1.8.3 source-map-support: 0.5.21 which: 2.0.2 @@ -20940,6 +21134,8 @@ snapshots: typescript@5.7.3: {} + typescript@5.8.2: {} + typescript@5.8.3: {} typescript@5.9.2: @@ -21959,6 +22155,8 @@ snapshots: yallist@3.1.1: {} + yallist@4.0.0: {} + yaml@2.8.1: {} yargs-parser@18.1.3: diff --git a/scripts/tsc-check.ts b/scripts/tsc-check.ts index 0498a89363e..0cc9f7ab739 100644 --- a/scripts/tsc-check.ts +++ b/scripts/tsc-check.ts @@ -18,9 +18,9 @@ const __dirname = path.dirname(__filename); // get the name of the directory const PACKAGES = { mermaid: 'mermaid', '@mermaid-js/layout-elk': 'mermaid-layout-elk', + '@mermaid-js/parser': 'parser', // TODO: these don't import cleanly yet due to exotic tsconfig.json requirements // '@mermaid-js/mermaid-zenuml': 'mermaid-zenuml', - // '@mermaid-js/parser': 'parser', }; /** From 675a64ca0e3cde8728ca715991623c3fc055ce88 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Fri, 24 Apr 2026 20:42:51 +0900 Subject: [PATCH 2/2] fix(parser): bundle langium and chevrotain Bundle langium and chevrotain in the `@mermaid-js/parser` package, so they're no longer dependencies. This has the following benefits: 1. Chevrotain v11.1.1 has a pin on lodash-es v4.17.23. There are a couple of CVEs/alerts on that version, and chevrotain will not make a new v11 release since those alerts don't affect chevrotain, see https://github.com/Chevrotain/chevrotain/issues/2186 2. Langium v4 raises an install warning on Node.JS v20.0, which is causing issues for some of mermaid's users, even if this code only runs in the browser. I'm using `api-extractor` to bundle the types for this. We're still keeping the `@chevrotatin/types` package as a dependency, since `api-extractor` can't seem to handle it, and it's only used for types. --- .changeset/petite-things-raise.md | 9 +++++++++ packages/parser/api-extractor.json | 20 ++++++++++++++++++-- packages/parser/package.json | 5 +++-- pnpm-lock.yaml | 9 ++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 .changeset/petite-things-raise.md diff --git a/.changeset/petite-things-raise.md b/.changeset/petite-things-raise.md new file mode 100644 index 00000000000..9a48286b0a5 --- /dev/null +++ b/.changeset/petite-things-raise.md @@ -0,0 +1,9 @@ +--- +'@mermaid-js/parser': patch +--- + +fix(parser): bundle langium/chevrotain + +This should silence warnings about lodash-es 4.17.23, which chevrotain@11.1.1 is pinned to, but is not vulnerable to. + +And this avoids warnings when langium v4 is installed on Node.JS v20.0. diff --git a/packages/parser/api-extractor.json b/packages/parser/api-extractor.json index f5e310a9646..76d3fe5d2af 100644 --- a/packages/parser/api-extractor.json +++ b/packages/parser/api-extractor.json @@ -37,7 +37,19 @@ * * "bundledPackages": [ "@my-company/*" ], */ - "bundledPackages": [], + "bundledPackages": [ + "langium", + // Dependencies of langium + "chevrotain", + // Skip bundling `@chevrotain/types` since api-extractor doesn't like it + "chevrotain-allstar", + "vscode-languageserver", + "vscode-languageserver-textdocument", + "vscode-uri", + "vscode-jsonrpc", + "vscode-languageserver-types", + "vscode-languageserver-protocol" + ], /** * Specifies what type of newlines API Extractor should use when writing output files. By default, the output files @@ -226,7 +238,11 @@ */ "tsdocMessageReporting": { "default": { - "logLevel": "warning" + /** + * We have lots of TSDoc warnings in bundled types that we don't have + * control over. + */ + "logLevel": "none" } } } diff --git a/packages/parser/package.json b/packages/parser/package.json index 572bf5e5e1c..26937b1a481 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -34,11 +34,12 @@ "ast" ], "dependencies": { - "langium": "^4.0.0" + "@chevrotain/types": "~11.1.1" }, "devDependencies": { "@microsoft/api-extractor": "^7.57.0", - "chevrotain": "~11.1.1" + "chevrotain": "~11.1.1", + "langium": "^4.0.0" }, "files": [ "dist/" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91bd08f47ba..e6f35f5631c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -547,9 +547,9 @@ importers: packages/parser: dependencies: - langium: - specifier: ^4.0.0 - version: 4.2.0 + '@chevrotain/types': + specifier: ~11.1.1 + version: 11.1.1 devDependencies: '@microsoft/api-extractor': specifier: ^7.57.0 @@ -557,6 +557,9 @@ importers: chevrotain: specifier: ~11.1.1 version: 11.1.1 + langium: + specifier: ^4.0.0 + version: 4.2.0 packages/tiny: {}