mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-05 00:26:40 +02:00
vite build
This commit is contained in:
@@ -3,28 +3,51 @@ import { resolve } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import jisonPlugin from './jisonPlugin.js';
|
import jisonPlugin from './jisonPlugin.js';
|
||||||
import pkg from '../package.json' assert { type: 'json' };
|
import pkg from '../package.json' assert { type: 'json' };
|
||||||
import { OutputOptions } from 'vite/node_modules/rollup';
|
|
||||||
const { dependencies } = pkg;
|
const { dependencies } = pkg;
|
||||||
const watch = process.argv.includes('--watch');
|
const watch = process.argv.includes('--watch');
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
|
type OutputOptions = Exclude<
|
||||||
|
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
|
||||||
|
undefined
|
||||||
|
>['output'];
|
||||||
|
|
||||||
|
const packageOptions = {
|
||||||
|
mermaid: {
|
||||||
|
name: 'mermaid',
|
||||||
|
file: 'mermaid.ts',
|
||||||
|
},
|
||||||
|
'mermaid-mindmap': {
|
||||||
|
name: 'mermaid-mindmap',
|
||||||
|
file: 'registry.ts',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
interface BuildOptions {
|
interface BuildOptions {
|
||||||
minify: boolean | 'esbuild';
|
minify: boolean | 'esbuild';
|
||||||
core?: boolean;
|
core?: boolean;
|
||||||
watch?: boolean;
|
watch?: boolean;
|
||||||
|
packageName: keyof typeof packageOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
|
export const getBuildConfig = ({
|
||||||
|
minify,
|
||||||
|
core,
|
||||||
|
watch,
|
||||||
|
packageName,
|
||||||
|
}: BuildOptions): InlineConfig => {
|
||||||
const external = ['require', 'fs', 'path'];
|
const external = ['require', 'fs', 'path'];
|
||||||
let output: OutputOptions | OutputOptions[] = [
|
const { name, file } = packageOptions[packageName];
|
||||||
|
let output: OutputOptions = [
|
||||||
{
|
{
|
||||||
name: 'mermaid',
|
name,
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
entryFileNames: `[name].esm${minify ? '.min' : ''}.mjs`,
|
entryFileNames: `[name].esm${minify ? '.min' : ''}.mjs`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'mermaid',
|
name,
|
||||||
format: 'umd',
|
format: 'umd',
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
entryFileNames: `[name]${minify ? '.min' : ''}.js`,
|
entryFileNames: `[name]${minify ? '.min' : ''}.js`,
|
||||||
@@ -34,7 +57,7 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon
|
|||||||
if (core) {
|
if (core) {
|
||||||
external.push(...Object.keys(dependencies));
|
external.push(...Object.keys(dependencies));
|
||||||
output = {
|
output = {
|
||||||
name: 'mermaid',
|
name,
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
entryFileNames: `[name].core.mjs`,
|
entryFileNames: `[name].core.mjs`,
|
||||||
@@ -45,11 +68,12 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon
|
|||||||
configFile: false,
|
configFile: false,
|
||||||
build: {
|
build: {
|
||||||
emptyOutDir: false,
|
emptyOutDir: false,
|
||||||
|
outDir: resolve(__dirname, `../packages/${packageName}/dist`),
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, '../src/mermaid.ts'),
|
entry: resolve(__dirname, `../packages/${packageName}/src/${file}`),
|
||||||
name: 'mermaid',
|
name,
|
||||||
// the proper extensions will be added
|
// the proper extensions will be added
|
||||||
fileName: 'mermaid',
|
fileName: name,
|
||||||
},
|
},
|
||||||
minify,
|
minify,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
@@ -72,10 +96,23 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon
|
|||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (watch) {
|
const buildPackage = async (packageName: keyof typeof packageOptions) => {
|
||||||
build(getBuildConfig({ minify: false, watch }));
|
return Promise.allSettled([
|
||||||
} else {
|
build(getBuildConfig({ minify: false, packageName })),
|
||||||
build(getBuildConfig({ minify: false }));
|
build(getBuildConfig({ minify: 'esbuild', packageName })),
|
||||||
build(getBuildConfig({ minify: 'esbuild' }));
|
build(getBuildConfig({ minify: true, core: true, packageName })),
|
||||||
build(getBuildConfig({ minify: true, core: true }));
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
|
||||||
|
for (const pkg of packageNames) {
|
||||||
|
await buildPackage(pkg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (watch) {
|
||||||
|
build(getBuildConfig({ minify: false, watch, packageName: 'mermaid' }));
|
||||||
|
} else {
|
||||||
|
void main();
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build:vite": "ts-node-esm .vite/build.ts",
|
"build:vite": "ts-node-esm .vite/build.ts",
|
||||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
"build:types": "tsc -p ./packages/mermaid/tsconfig.json --emitDeclarationOnly",
|
||||||
"build:watch": "yarn build:code --watch",
|
"build:watch": "yarn build:code --watch",
|
||||||
"build": "yarn clean; concurrently \"yarn build:vite\" \"yarn build:types\"",
|
"build": "yarn clean; concurrently \"yarn build:vite\" \"yarn build:types\"",
|
||||||
"dev": "concurrently \"yarn build:vite --watch\" \"ts-node-esm .vite/server\"",
|
"dev": "concurrently \"yarn build:vite --watch\" \"ts-node-esm .vite/server\"",
|
||||||
@@ -122,7 +122,6 @@
|
|||||||
"prettier-plugin-jsdoc": "^0.4.2",
|
"prettier-plugin-jsdoc": "^0.4.2",
|
||||||
"remark": "^14.0.2",
|
"remark": "^14.0.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rollup": "^2.79.1",
|
|
||||||
"start-server-and-test": "^1.12.6",
|
"start-server-and-test": "^1.12.6",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.8.3",
|
"typescript": "^4.8.3",
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
const { esmBuild, esmCoreBuild, iifeBuild } = require('./util.cjs');
|
|
||||||
const { build } = require('esbuild');
|
|
||||||
|
|
||||||
const handler = (e) => {
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
};
|
|
||||||
const watch = process.argv.includes('--watch');
|
|
||||||
|
|
||||||
// mermaid.js
|
|
||||||
build(iifeBuild({ minify: false, watch })).catch(handler);
|
|
||||||
// mermaid.esm.mjs
|
|
||||||
build(esmBuild({ minify: false, watch })).catch(handler);
|
|
||||||
|
|
||||||
// mermaid.min.js
|
|
||||||
build(iifeBuild()).catch(handler);
|
|
||||||
// mermaid.esm.min.mjs
|
|
||||||
build(esmBuild()).catch(handler);
|
|
||||||
// mermaid.core.mjs (node_modules unbundled)
|
|
||||||
build(esmCoreBuild()).catch(handler);
|
|
@@ -1,14 +0,0 @@
|
|||||||
const { Generator } = require('jison');
|
|
||||||
exports.transformJison = (src) => {
|
|
||||||
const parser = new Generator(src, {
|
|
||||||
moduleType: 'js',
|
|
||||||
'token-stack': true,
|
|
||||||
});
|
|
||||||
const source = parser.generate({ moduleMain: '() => {}' });
|
|
||||||
const exporter = `
|
|
||||||
parser.parser = parser;
|
|
||||||
export { parser };
|
|
||||||
export default parser;
|
|
||||||
`;
|
|
||||||
return `${source} ${exporter}`;
|
|
||||||
};
|
|
@@ -1,79 +0,0 @@
|
|||||||
const esbuild = require('esbuild');
|
|
||||||
const http = require('http');
|
|
||||||
const { iifeBuild, esmBuild } = require('./util.cjs');
|
|
||||||
const express = require('express');
|
|
||||||
|
|
||||||
// Start 2 esbuild servers. One for IIFE and one for ESM
|
|
||||||
// Serve 2 static directories: demo & cypress/platform
|
|
||||||
// Have 3 entry points:
|
|
||||||
// mermaid: './src/mermaid',
|
|
||||||
// e2e: './cypress/platform/viewer.js',
|
|
||||||
// 'bundle-test': './cypress/platform/bundle-test.js',
|
|
||||||
|
|
||||||
const getEntryPointsAndExtensions = (format) => {
|
|
||||||
return {
|
|
||||||
entryPoints: {
|
|
||||||
mermaid: './src/mermaid',
|
|
||||||
e2e: './cypress/platform/viewer.js',
|
|
||||||
'bundle-test': './cypress/platform/bundle-test.js',
|
|
||||||
},
|
|
||||||
outExtension: { '.js': format === 'iife' ? '.js' : '.esm.mjs' },
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateHandler = (server) => {
|
|
||||||
return (req, res) => {
|
|
||||||
const options = {
|
|
||||||
hostname: server.host,
|
|
||||||
port: server.port,
|
|
||||||
path: req.url,
|
|
||||||
method: req.method,
|
|
||||||
headers: req.headers,
|
|
||||||
};
|
|
||||||
// Forward each incoming request to esbuild
|
|
||||||
const proxyReq = http.request(options, (proxyRes) => {
|
|
||||||
// If esbuild returns "not found", send a custom 404 page
|
|
||||||
if (proxyRes.statusCode === 404) {
|
|
||||||
if (!req.url.endsWith('.html')) {
|
|
||||||
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
||||||
res.end('<h1>A custom 404 page</h1>');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, forward the response from esbuild to the client
|
|
||||||
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
|
||||||
proxyRes.pipe(res, { end: true });
|
|
||||||
});
|
|
||||||
// Forward the body of the request to esbuild
|
|
||||||
req.pipe(proxyReq, { end: true });
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const iifeServer = await esbuild.serve(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
...iifeBuild({ minify: false, outfile: undefined, outdir: 'dist' }),
|
|
||||||
...getEntryPointsAndExtensions('iife'),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const esmServer = await esbuild.serve(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
...esmBuild({ minify: false, outfile: undefined, outdir: 'dist' }),
|
|
||||||
...getEntryPointsAndExtensions('esm'),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.static('demos'));
|
|
||||||
app.use(express.static('cypress/platform'));
|
|
||||||
app.all('/mermaid.js', generateHandler(iifeServer));
|
|
||||||
app.all('/mermaid.esm.mjs', generateHandler(esmServer));
|
|
||||||
|
|
||||||
app.all('/e2e.esm.mjs', generateHandler(esmServer));
|
|
||||||
app.all('/bundle-test.esm.mjs', generateHandler(esmServer));
|
|
||||||
app.listen(9000, () => {
|
|
||||||
console.log(`Listening on http://localhost:9000`);
|
|
||||||
});
|
|
||||||
})();
|
|
@@ -1,94 +0,0 @@
|
|||||||
const { transformJison } = require('./jisonTransformer.cjs');
|
|
||||||
const fs = require('fs');
|
|
||||||
const { dependencies } = require('../package.json');
|
|
||||||
|
|
||||||
/** @typedef {import('esbuild').BuildOptions} Options */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Options} override
|
|
||||||
* @returns {Options}
|
|
||||||
*/
|
|
||||||
const buildOptions = (override = {}) => {
|
|
||||||
return {
|
|
||||||
bundle: true,
|
|
||||||
minify: true,
|
|
||||||
keepNames: true,
|
|
||||||
banner: { js: '"use strict";' },
|
|
||||||
globalName: 'mermaid',
|
|
||||||
platform: 'browser',
|
|
||||||
tsconfig: 'tsconfig.json',
|
|
||||||
resolveExtensions: ['.ts', '.js', '.mjs', '.json', '.jison'],
|
|
||||||
external: ['require', 'fs', 'path'],
|
|
||||||
entryPoints: ['src/registry.ts'],
|
|
||||||
outfile: 'dist/mermaid-mindmap.min.js',
|
|
||||||
plugins: [jisonPlugin],
|
|
||||||
sourcemap: 'external',
|
|
||||||
...override,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.esm.* build.
|
|
||||||
*
|
|
||||||
* For ESM browser use.
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.esmBuild = (override = { minify: true }) => {
|
|
||||||
return buildOptions({
|
|
||||||
format: 'esm',
|
|
||||||
outfile: `dist/mermaid.esm${override.minify ? '.min' : ''}.mjs`,
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.core.* build.
|
|
||||||
*
|
|
||||||
* This build does not bundle `./node_modules/`, as it is designed to be used with
|
|
||||||
* Webpack/ESBuild/Vite to use mermaid inside an app/website.
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.esmCoreBuild = (override) => {
|
|
||||||
return buildOptions({
|
|
||||||
format: 'esm',
|
|
||||||
outfile: `dist/mermaid.core.mjs`,
|
|
||||||
external: ['require', 'fs', 'path', ...Object.keys(dependencies)],
|
|
||||||
platform: 'neutral',
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.js build.
|
|
||||||
*
|
|
||||||
* For IIFE browser use (where ESM is not yet supported).
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.iifeBuild = (override = { minify: true }) => {
|
|
||||||
return buildOptions({
|
|
||||||
outfile: `dist/mermaid${override.minify ? '.min' : ''}.js`,
|
|
||||||
format: 'iife',
|
|
||||||
footer: {
|
|
||||||
js: 'mermaid = mermaid.default;',
|
|
||||||
},
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const jisonPlugin = {
|
|
||||||
name: 'jison',
|
|
||||||
setup(build) {
|
|
||||||
build.onLoad({ filter: /\.jison$/ }, async (args) => {
|
|
||||||
// Load the file from the file system
|
|
||||||
const source = await fs.promises.readFile(args.path, 'utf8');
|
|
||||||
const contents = transformJison(source);
|
|
||||||
return { contents, warnings: [] };
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
@@ -56,7 +56,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braintree/sanitize-url": "^6.0.0",
|
"@braintree/sanitize-url": "^6.0.0",
|
||||||
"d3": "^7.0.0",
|
"d3": "^7.0.0",
|
||||||
"mermaid": "*",
|
"mermaid": "workspace:*",
|
||||||
"non-layered-tidy-tree-layout": "^2.0.2"
|
"non-layered-tidy-tree-layout": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@@ -1,108 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist"
|
||||||
/* Projects */
|
},
|
||||||
// "incremental": true /* Enable incremental compilation */,
|
"include": ["./src/**/*.ts", "./package.json"]
|
||||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
||||||
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
|
||||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
|
||||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
||||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
||||||
|
|
||||||
/* Language and Environment */
|
|
||||||
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
||||||
"lib": [
|
|
||||||
"DOM",
|
|
||||||
"ES2021"
|
|
||||||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
|
||||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
||||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
||||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
||||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
|
||||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
||||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
|
||||||
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
|
||||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
||||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
||||||
|
|
||||||
/* Modules */
|
|
||||||
"module": "ES6" /* Specify what module code is generated. */,
|
|
||||||
"rootDir": "./src" /* Specify the root folder within your source files. */,
|
|
||||||
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
||||||
// "baseUrl": "./src" /* Specify the base directory to resolve non-relative module names. */,
|
|
||||||
// "paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
|
||||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
||||||
// "typeRoots": [] /* Specify multiple folders that act like `./node_modules/@types`. */,
|
|
||||||
"types": [
|
|
||||||
"vitest/globals"
|
|
||||||
] /* Specify type package names to be included without being referenced in a source file. */,
|
|
||||||
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
||||||
"resolveJsonModule": true /* Enable importing .json files */,
|
|
||||||
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
|
||||||
|
|
||||||
/* JavaScript Support */
|
|
||||||
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
|
|
||||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
||||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
|
||||||
|
|
||||||
/* Emit */
|
|
||||||
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
|
||||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
||||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
||||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
||||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
|
||||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
|
||||||
// "removeComments": true, /* Disable emitting comments. */
|
|
||||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
||||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
||||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
|
||||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
||||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
||||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
||||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
||||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
||||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
||||||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
|
||||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
|
||||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
||||||
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
|
||||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
||||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
||||||
|
|
||||||
/* Interop Constraints */
|
|
||||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
||||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
|
|
||||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
||||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
||||||
|
|
||||||
/* Type Checking */
|
|
||||||
"strict": true /* Enable all strict type-checking options. */,
|
|
||||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
|
||||||
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
|
||||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
||||||
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
|
||||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
||||||
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
|
||||||
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
|
||||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
||||||
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
|
||||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
|
||||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
||||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
||||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
||||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
||||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
||||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
|
||||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
||||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
||||||
|
|
||||||
/* Completeness */
|
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
||||||
}
|
|
||||||
// "include": ["./src/**/*.ts", "./package.json"]
|
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
const { esmBuild, esmCoreBuild, iifeBuild } = require('./util.cjs');
|
|
||||||
const { build } = require('esbuild');
|
|
||||||
|
|
||||||
const handler = (e) => {
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
};
|
|
||||||
const watch = process.argv.includes('--watch');
|
|
||||||
|
|
||||||
// mermaid.js
|
|
||||||
build(iifeBuild({ minify: false, watch })).catch(handler);
|
|
||||||
// mermaid.esm.mjs
|
|
||||||
build(esmBuild({ minify: false, watch })).catch(handler);
|
|
||||||
|
|
||||||
// mermaid.min.js
|
|
||||||
build(iifeBuild()).catch(handler);
|
|
||||||
// mermaid.esm.min.mjs
|
|
||||||
build(esmBuild()).catch(handler);
|
|
||||||
// mermaid.core.mjs (node_modules unbundled)
|
|
||||||
build(esmCoreBuild()).catch(handler);
|
|
@@ -1,14 +0,0 @@
|
|||||||
const { Generator } = require('jison');
|
|
||||||
exports.transformJison = (src) => {
|
|
||||||
const parser = new Generator(src, {
|
|
||||||
moduleType: 'js',
|
|
||||||
'token-stack': true,
|
|
||||||
});
|
|
||||||
const source = parser.generate({ moduleMain: '() => {}' });
|
|
||||||
const exporter = `
|
|
||||||
parser.parser = parser;
|
|
||||||
export { parser };
|
|
||||||
export default parser;
|
|
||||||
`;
|
|
||||||
return `${source} ${exporter}`;
|
|
||||||
};
|
|
@@ -1,79 +0,0 @@
|
|||||||
const esbuild = require('esbuild');
|
|
||||||
const http = require('http');
|
|
||||||
const { iifeBuild, esmBuild } = require('./util.cjs');
|
|
||||||
const express = require('express');
|
|
||||||
|
|
||||||
// Start 2 esbuild servers. One for IIFE and one for ESM
|
|
||||||
// Serve 2 static directories: demo & cypress/platform
|
|
||||||
// Have 3 entry points:
|
|
||||||
// mermaid: './src/mermaid',
|
|
||||||
// e2e: './cypress/platform/viewer.js',
|
|
||||||
// 'bundle-test': './cypress/platform/bundle-test.js',
|
|
||||||
|
|
||||||
const getEntryPointsAndExtensions = (format) => {
|
|
||||||
return {
|
|
||||||
entryPoints: {
|
|
||||||
mermaid: './src/mermaid',
|
|
||||||
e2e: '../../cypress/platform/viewer.js',
|
|
||||||
'bundle-test': '../../cypress/platform/bundle-test.js',
|
|
||||||
},
|
|
||||||
outExtension: { '.js': format === 'iife' ? '.js' : '.esm.mjs' },
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateHandler = (server) => {
|
|
||||||
return (req, res) => {
|
|
||||||
const options = {
|
|
||||||
hostname: server.host,
|
|
||||||
port: server.port,
|
|
||||||
path: req.url,
|
|
||||||
method: req.method,
|
|
||||||
headers: req.headers,
|
|
||||||
};
|
|
||||||
// Forward each incoming request to esbuild
|
|
||||||
const proxyReq = http.request(options, (proxyRes) => {
|
|
||||||
// If esbuild returns "not found", send a custom 404 page
|
|
||||||
if (proxyRes.statusCode === 404) {
|
|
||||||
if (!req.url.endsWith('.html')) {
|
|
||||||
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
||||||
res.end('<h1>A custom 404 page</h1>');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, forward the response from esbuild to the client
|
|
||||||
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
|
||||||
proxyRes.pipe(res, { end: true });
|
|
||||||
});
|
|
||||||
// Forward the body of the request to esbuild
|
|
||||||
req.pipe(proxyReq, { end: true });
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const iifeServer = await esbuild.serve(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
...iifeBuild({ minify: false, outfile: undefined, outdir: 'dist' }),
|
|
||||||
...getEntryPointsAndExtensions('iife'),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const esmServer = await esbuild.serve(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
...esmBuild({ minify: false, outfile: undefined, outdir: 'dist' }),
|
|
||||||
...getEntryPointsAndExtensions('esm'),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.static('demos'));
|
|
||||||
app.use(express.static('cypress/platform'));
|
|
||||||
app.all('/mermaid.js', generateHandler(iifeServer));
|
|
||||||
app.all('/mermaid.esm.mjs', generateHandler(esmServer));
|
|
||||||
|
|
||||||
app.all('/e2e.esm.mjs', generateHandler(esmServer));
|
|
||||||
app.all('/bundle-test.esm.mjs', generateHandler(esmServer));
|
|
||||||
app.listen(9000, () => {
|
|
||||||
console.log(`Listening on http://localhost:9000`);
|
|
||||||
});
|
|
||||||
})();
|
|
@@ -1,94 +0,0 @@
|
|||||||
const { transformJison } = require('./jisonTransformer.cjs');
|
|
||||||
const fs = require('fs');
|
|
||||||
const { dependencies } = require('../package.json');
|
|
||||||
|
|
||||||
/** @typedef {import('esbuild').BuildOptions} Options */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Options} override
|
|
||||||
* @returns {Options}
|
|
||||||
*/
|
|
||||||
const buildOptions = (override = {}) => {
|
|
||||||
return {
|
|
||||||
bundle: true,
|
|
||||||
minify: true,
|
|
||||||
keepNames: true,
|
|
||||||
banner: { js: '"use strict";' },
|
|
||||||
globalName: 'mermaid',
|
|
||||||
platform: 'browser',
|
|
||||||
tsconfig: 'tsconfig.json',
|
|
||||||
resolveExtensions: ['.ts', '.js', '.mjs', '.json', '.jison'],
|
|
||||||
external: ['require', 'fs', 'path'],
|
|
||||||
entryPoints: ['src/mermaid.ts'],
|
|
||||||
outfile: 'dist/mermaid.min.js',
|
|
||||||
plugins: [jisonPlugin],
|
|
||||||
sourcemap: 'external',
|
|
||||||
...override,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.esm.* build.
|
|
||||||
*
|
|
||||||
* For ESM browser use.
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.esmBuild = (override = { minify: true }) => {
|
|
||||||
return buildOptions({
|
|
||||||
format: 'esm',
|
|
||||||
outfile: `dist/mermaid.esm${override.minify ? '.min' : ''}.mjs`,
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.core.* build.
|
|
||||||
*
|
|
||||||
* This build does not bundle `./node_modules/`, as it is designed to be used with
|
|
||||||
* Webpack/ESBuild/Vite to use mermaid inside an app/website.
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.esmCoreBuild = (override) => {
|
|
||||||
return buildOptions({
|
|
||||||
format: 'esm',
|
|
||||||
outfile: `dist/mermaid.core.mjs`,
|
|
||||||
external: ['require', 'fs', 'path', ...Object.keys(dependencies)],
|
|
||||||
platform: 'neutral',
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build options for mermaid.js build.
|
|
||||||
*
|
|
||||||
* For IIFE browser use (where ESM is not yet supported).
|
|
||||||
*
|
|
||||||
* @param {Options} override - Override options.
|
|
||||||
* @returns {Options} ESBuild build options.
|
|
||||||
*/
|
|
||||||
exports.iifeBuild = (override = { minify: true }) => {
|
|
||||||
return buildOptions({
|
|
||||||
outfile: `dist/mermaid${override.minify ? '.min' : ''}.js`,
|
|
||||||
format: 'iife',
|
|
||||||
footer: {
|
|
||||||
js: 'mermaid = mermaid.default;',
|
|
||||||
},
|
|
||||||
...override,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const jisonPlugin = {
|
|
||||||
name: 'jison',
|
|
||||||
setup(build) {
|
|
||||||
build.onLoad({ filter: /\.jison$/ }, async (args) => {
|
|
||||||
// Load the file from the file system
|
|
||||||
const source = await fs.promises.readFile(args.path, 'utf8');
|
|
||||||
const contents = transformJison(source);
|
|
||||||
return { contents, warnings: [] };
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
@@ -2,9 +2,9 @@
|
|||||||
"name": "mermaid",
|
"name": "mermaid",
|
||||||
"version": "9.2.0-rc2",
|
"version": "9.2.0-rc2",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid.core.mjs",
|
"main": "./dist/mermaid.core.mjs",
|
||||||
"module": "dist/mermaid.core.mjs",
|
"module": "./dist/mermaid.core.mjs",
|
||||||
"types": "dist/mermaid.d.ts",
|
"types": "./dist/mermaid.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
"include": ["./src/**/*.ts", "./package.json"]
|
"include": ["./src/**/*.ts", "./package.json"]
|
||||||
}
|
}
|
||||||
|
1378
pnpm-lock.yaml
generated
1378
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user