Skip to content

Commit

Permalink
Merge branch 'develop' into pr/dontry/5607
Browse files Browse the repository at this point in the history
* develop: (31 commits)
  ci: upgrade to pnpm/action-setup@v4 to avoid CI failures
  chore(deps): update dependency eslint-plugin-unicorn to v54
  chore(deps): update dependency eslint-plugin-jsdoc to v48.5.0
  chore(deps): update all patch dependencies
  Sync docs folder
  Add Doctave to .cspell libraries
  Adds Doctave to list of integrations
  chore: update browsers list
  chore: Cleanup tsconfig
  chore: Fix lint
  Apply suggestions from code review
  chore: Remove extra words from cspell
  chore: Log granular rebuild times
  fix: Message wrap
  fix: Message wrap
  chore: Use `??` instead of `||`
  chore: Organise imports
  chore: Remove unused variables
  chore: Remove cross-env from eslint
  chore: Cleanup rules
  ...
  • Loading branch information
sidharthv96 committed Jul 4, 2024
2 parents 16a15c4 + 7f81569 commit f014061
Show file tree
Hide file tree
Showing 134 changed files with 1,854 additions and 1,832 deletions.
13 changes: 10 additions & 3 deletions .build/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/* eslint-disable no-console */
import { packageOptions } from './common.js';
import { execSync } from 'child_process';

const buildType = (packageName: string) => {
console.log(`Building types for ${packageName}`);
try {
const out = execSync(`tsc -p ./packages/${packageName}/tsconfig.json --emitDeclarationOnly`);
out.length > 0 && console.log(out.toString());
if (out.length > 0) {
console.log(out.toString());
}
} catch (e) {
console.error(e);
e.stdout.length > 0 && console.error(e.stdout.toString());
e.stderr.length > 0 && console.error(e.stderr.toString());
if (e.stdout.length > 0) {
console.error(e.stdout.toString());
}
if (e.stderr.length > 0) {
console.error(e.stderr.toString());
}
}
};

Expand Down
3 changes: 3 additions & 0 deletions .cspell/code-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bqstring
BQUOTE
bramp
BRKT
brotli
callbackargs
callbackname
classdef
Expand Down Expand Up @@ -111,6 +112,7 @@ STYLECLASS
STYLEOPTS
subcomponent
subcomponents
subconfig
SUBROUTINEEND
SUBROUTINESTART
Subschemas
Expand All @@ -125,6 +127,7 @@ titlevalue
topbar
TRAPEND
TRAPSTART
treemap
ts-nocheck
tsdoc
typeof
Expand Down
1 change: 1 addition & 0 deletions .cspell/contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ cpettitt
Dong Cai
Nikolay Rozhkov
Peng Xiao
Per Brolin
subhash-halder
Vinod Sidharth
3 changes: 3 additions & 0 deletions .cspell/libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dagre-d3
Deepdwn
Docsify
Docsy
Doctave
DokuWiki
dompurify
elkjs
Expand Down Expand Up @@ -55,12 +56,14 @@ pyplot
redmine
rehype
rscratch
shiki
sparkline
sphinxcontrib
ssim
stylis
Swimm
tsbuildinfo
tseslint
Tuleap
Typora
unocss
Expand Down
3 changes: 3 additions & 0 deletions .cspell/misc-terms.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
BRANDES
handdrawn
KOEPF
newbranch
10 changes: 6 additions & 4 deletions .esbuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { build } from 'esbuild';
import { mkdir, writeFile } from 'node:fs/promises';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';
import type { MermaidBuildOptions } from './util.js';
import { defaultOptions, getBuildConfig } from './util.js';

const shouldVisualize = process.argv.includes('--visualize');

Expand Down Expand Up @@ -35,11 +36,11 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {

if (shouldVisualize) {
for (const { metafile } of results) {
if (!metafile) {
if (!metafile?.outputs) {
continue;
}
const fileName = Object.keys(metafile.outputs)
.filter((file) => !file.includes('chunks') && file.endsWith('js'))[0]
.find((file) => !file.includes('chunks') && file.endsWith('js'))
.replace('dist/', '');
// Upload metafile into https://esbuild.github.io/analyze/
await writeFile(`stats/${fileName}.meta.json`, JSON.stringify(metafile));
Expand All @@ -48,13 +49,14 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
};

const handler = (e) => {
// eslint-disable-next-line no-console
console.error(e);
process.exit(1);
};

const main = async () => {
await generateLangium();
await mkdir('stats').catch(() => {});
await mkdir('stats', { recursive: true });
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
// it should build `parser` before `mermaid` because it's a dependency
for (const pkg of packageNames) {
Expand Down
2 changes: 1 addition & 1 deletion .esbuild/jisonPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from 'node:fs/promises';
import { transformJison } from '../.build/jisonTransformer.js';
import { Plugin } from 'esbuild';
import type { Plugin } from 'esbuild';

export const jisonPlugin: Plugin = {
name: 'jison',
Expand Down
51 changes: 33 additions & 18 deletions .esbuild/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import express from 'express';
import type { NextFunction, Request, Response } from 'express';
/* eslint-disable no-console */
import chokidar from 'chokidar';
import cors from 'cors';
import { getBuildConfig, defaultOptions } from './util.js';
import { context } from 'esbuild';
import chokidar from 'chokidar';
import { generateLangium } from '../.build/generateLangium.js';
import type { Request, Response } from 'express';
import express from 'express';
import { packageOptions } from '../.build/common.js';
import { generateLangium } from '../.build/generateLangium.js';
import { defaultOptions, getBuildConfig } from './util.js';

const configs = Object.values(packageOptions).map(({ packageName }) =>
getBuildConfig({ ...defaultOptions, minify: false, core: false, entryName: packageName })
Expand All @@ -19,16 +20,28 @@ const mermaidIIFEConfig = getBuildConfig({
});
configs.push(mermaidIIFEConfig);

const contexts = await Promise.all(configs.map((config) => context(config)));
const contexts = await Promise.all(
configs.map(async (config) => ({ config, context: await context(config) }))
);

let rebuildCounter = 1;
const rebuildAll = async () => {
console.time('Rebuild time');
await Promise.all(contexts.map((ctx) => ctx.rebuild())).catch((e) => console.error(e));
console.timeEnd('Rebuild time');
const buildNumber = rebuildCounter++;
const timeLabel = `Rebuild ${buildNumber} Time (total)`;
console.time(timeLabel);
await Promise.all(
contexts.map(async ({ config, context }) => {
const buildVariant = `Rebuild ${buildNumber} Time (${Object.keys(config.entryPoints!)[0]} ${config.format})`;
console.time(buildVariant);
await context.rebuild();
console.timeEnd(buildVariant);
})
).catch((e) => console.error(e));
console.timeEnd(timeLabel);
};

let clients: { id: number; response: Response }[] = [];
function eventsHandler(request: Request, response: Response, next: NextFunction) {
function eventsHandler(request: Request, response: Response) {
const headers = {
'Content-Type': 'text/event-stream',
Connection: 'keep-alive',
Expand All @@ -45,19 +58,20 @@ function eventsHandler(request: Request, response: Response, next: NextFunction)
});
}

let timeoutId: NodeJS.Timeout | undefined = undefined;
let timeoutID: NodeJS.Timeout | undefined = undefined;

/**
* Debounce file change events to avoid rebuilding multiple times.
*/
function handleFileChange() {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
if (timeoutID !== undefined) {
clearTimeout(timeoutID);
}
timeoutId = setTimeout(async () => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
timeoutID = setTimeout(async () => {
await rebuildAll();
sendEventsToAll();
timeoutId = undefined;
timeoutID = undefined;
}, 100);
}

Expand All @@ -74,15 +88,16 @@ async function createServer() {
ignoreInitial: true,
ignored: [/node_modules/, /dist/, /docs/, /coverage/],
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
.on('all', async (event, path) => {
// Ignore other events.
if (!['add', 'change'].includes(event)) {
return;
}
if (/\.langium$/.test(path)) {
console.log(`${path} changed. Rebuilding...`);
if (path.endsWith('.langium')) {
await generateLangium();
}
console.log(`${path} changed. Rebuilding...`);
handleFileChange();
});

Expand All @@ -99,4 +114,4 @@ async function createServer() {
});
}

createServer();
void createServer();
2 changes: 1 addition & 1 deletion .esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
const external: string[] = ['require', 'fs', 'path'];
const { name, file, packageName } = packageOptions[entryName];
const outFileName = getFileName(name, options);
let output: BuildOptions = buildOptions({
const output: BuildOptions = buildOptions({
absWorkingDir: resolve(__dirname, `../packages/${packageName}`),
entryPoints: {
[outFileName]: `src/${file}`,
Expand Down
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

Loading

0 comments on commit f014061

Please sign in to comment.