forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into sidv/parallelE2E
* develop: (28 commits) fix(docs): update link Revert "unify Jison tranformers" Update yarn.lock Revert "fix(test): No esm exports" fix(test): No esm exports fix(docs): `mmd` detection Hope this fails unify Jison tranformers Fix jest Remove `docs:build` from postbuild. Add verification log This should fail CI fix: imports in HTML Revert "Add diagramAPI to outfile" Add `type: module` to package.json chore(deps-dev): bump @types/lodash from 4.14.184 to 4.14.185 Update integrations.md Add vitepress pluin Update mermaid version Fix ports ...
- Loading branch information
Showing
36 changed files
with
824 additions
and
1,753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,79 @@ | ||
const esbuild = require('esbuild'); | ||
const http = require('http'); | ||
const path = require('path'); | ||
const { iifeBuild } = require('./util.cjs'); | ||
const { iifeBuild, esmBuild } = require('./util.cjs'); | ||
const express = require('express'); | ||
|
||
// Start esbuild's server on a random local port | ||
esbuild | ||
.serve( | ||
{ | ||
servedir: path.join(__dirname, '..'), | ||
// 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', | ||
}, | ||
iifeBuild({ minify: false }) | ||
) | ||
.then((result) => { | ||
// The result tells us where esbuild's local server is | ||
const { host, port } = result; | ||
outExtension: { '.js': format === 'iife' ? '.js' : '.esm.mjs' }, | ||
}; | ||
}; | ||
|
||
// Then start a proxy server on port 3000 | ||
http | ||
.createServer((req, res) => { | ||
if (req.url.includes('mermaid.js')) { | ||
req.url = '/dist/mermaid.js'; | ||
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; | ||
} | ||
const options = { | ||
hostname: host, | ||
port: port, | ||
path: req.url, | ||
method: req.method, | ||
headers: req.headers, | ||
}; | ||
} | ||
// 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 }); | ||
}; | ||
}; | ||
|
||
// Forward each incoming request to esbuild | ||
const proxyReq = http.request(options, (proxyRes) => { | ||
// If esbuild returns "not found", send a custom 404 page | ||
console.error('pp', req.url); | ||
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; | ||
} | ||
} | ||
(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(); | ||
|
||
// Otherwise, forward the response from esbuild to the client | ||
res.writeHead(proxyRes.statusCode, proxyRes.headers); | ||
proxyRes.pipe(res, { end: true }); | ||
}); | ||
app.use(express.static('demos')); | ||
app.use(express.static('cypress/platform')); | ||
app.all('/mermaid.js', generateHandler(iifeServer)); | ||
app.all('/mermaid.esm.mjs', generateHandler(esmServer)); | ||
|
||
// Forward the body of the request to esbuild | ||
req.pipe(proxyReq, { end: true }); | ||
}) | ||
.listen(3000); | ||
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`); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"src/docs/**": ["yarn docs:build --git"], | ||
"src/docs.mts": ["yarn docs:build --git"], | ||
"*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"] | ||
"*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"], | ||
"*.jison": ["yarn lint:jison"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.