Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a monorepo #3531

Merged
merged 42 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8dd8283
Relocation of files
knsv Sep 21, 2022
9b0d4a2
Temp removaof some hursky rules etc for the build
knsv Sep 21, 2022
ffbae08
wip: esbuild Package
sidharthv96 Sep 21, 2022
db31f61
Use of pnpm for the monorepo
knsv Sep 22, 2022
cccbb69
Use of pnpm for the monorepo
knsv Sep 22, 2022
0e0a6c0
Fixed paths for dev server
knsv Sep 22, 2022
404b718
Merge branch '3061_making_a_monorepo' into sidv/3061_monorepo
sidharthv96 Sep 23, 2022
bf25be7
Merge branch 'sidv/viteVitest' into sidv/3061_monorepo
sidharthv96 Sep 23, 2022
ad49564
vite build
sidharthv96 Sep 23, 2022
913468a
Merge branch 'sidv/viteVitest' into sidv/3061_monorepo
sidharthv96 Sep 23, 2022
53bbf44
fix build
sidharthv96 Sep 23, 2022
9fac786
Merge pull request #3514 from mermaid-js/sidv/3061_monorepo
knsv Sep 23, 2022
8dcbe83
fix types for mermaid-mindmap
sidharthv96 Sep 23, 2022
c32e76a
Merge branch 'sidv/3061_monorepo' into 3061_making_a_monorepo
sidharthv96 Sep 23, 2022
af2b194
Detector registering itself on load
knsv Sep 23, 2022
535f555
test: fix unit tests in new mono-repo
aloisklink Sep 25, 2022
97637da
build: set "packageManager" to `pnpm@7.12.2`
aloisklink Sep 25, 2022
69d05c4
style: ignore pnpm-lock.yaml from prettier
aloisklink Sep 25, 2022
69c13a6
build(docs): fix docs:build command for mono-repo
aloisklink Sep 25, 2022
d633ec6
ci(unit): fix unit tests CI to use pnpm
aloisklink Sep 25, 2022
77831c4
ci(lint): fix lint tests CI to use pnpm
aloisklink Sep 25, 2022
29c52ec
chore: update pnpm-lock.yaml lockfile
aloisklink Sep 25, 2022
24d46fb
ci(e2e): fix e2e tests CI to use pnpm
aloisklink Sep 25, 2022
e72059b
ci(e2e-applitools): fix applitools CI to use pnpm
aloisklink Sep 25, 2022
e0805b8
ci(build): fix build CI to use pnpm
aloisklink Sep 25, 2022
493aac6
Merge branch 'aloisklink/3061_monorepo-e2e-tests' into 3061_making_a_…
aloisklink Sep 25, 2022
9566f51
Commiton issue #3061 Injecting mermaid utilities in registered diagram
knsv Sep 26, 2022
98ddc95
Deoupling, inecting mermaid utilities in external diagram
knsv Sep 26, 2022
ebdec77
#3061 Fixing unit tests
knsv Sep 26, 2022
a928120
#3061 Log handing and other fixes, error handling in diagram creation
knsv Sep 26, 2022
982c1b4
#3061 Lazy loading auto derived path
knsv Sep 26, 2022
f60c7ff
Merge branch 'develop' into 3061_making_a_monorepo
knsv Sep 28, 2022
be34e61
Fix for tests
knsv Sep 28, 2022
053a20b
Returning the borders to the e2e tests
knsv Sep 28, 2022
bed9b1b
Removed test folder
knsv Sep 28, 2022
f46f875
Adding example diagram as a template for a new diagram
knsv Sep 28, 2022
766bdde
Fixed sample test
knsv Sep 28, 2022
5cfbc91
build(dev): Fix dev server not showing mermaid.js
aloisklink Sep 28, 2022
30f6550
ci(e2e): remove `headless` arg from cypress run
aloisklink Sep 28, 2022
693616b
ci(e2e): Skip pnpm cache if skipping cypress run
aloisklink Sep 28, 2022
972d025
Merge branch 'develop' into 3061_making_a_monorepo
knsv Sep 29, 2022
96cde8a
updated pnpm-lock file
knsv Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 15 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,32 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: yarn
cache: pnpm
node-version: ${{ matrix.node-version }}

- name: Install Yarn
run: npm i yarn --global

- name: Install Packages
run: |
yarn install --frozen-lockfile
pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress

- name: Run Build
run: yarn build
run: pnpm run build

- name: Upload Mermaid Build as Artifact
uses: actions/upload-artifact@v3
with:
name: mermaid-build
path: packages/mermaid/dist

- name: Upload Build as Artifact
- name: Upload Mermaid Mindmap Build as Artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
name: mermaid-mindmap-build
path: packages/mermaid-mindmap/dist
17 changes: 8 additions & 9 deletions .github/workflows/e2e-applitools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@ jobs:
name: Warn if not using Applitools
run: |
echo "::error,title=Not using Applitols::APPLITOOLS_API_KEY is empty, disabling Applitools for this run."

- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: yarn
cache: pnpm
node-version: ${{ matrix.node-version }}

- name: Install Yarn
run: npm i yarn --global

- name: Install Packages
run: |
yarn install --frozen-lockfile
pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress

- name: Run Build
run: yarn build

- if: ${{ env.USE_APPLI }}
name: Notify applitools of new batch
# Copied from docs https://applitools.com/docs/topics/integrations/github-integration-ci-setup.html
Expand All @@ -60,7 +59,7 @@ jobs:
APPLITOOLS_SERVER_URL: 'https://eyesapi.applitools.com'

- name: Run E2E Tests
run: yarn e2e
run: pnpm run e2e
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress
# Mermaid applitools.config.js uses this to pick batch name.
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,31 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: yarn-and-build-cache
with:
path: |
~/.cache/Cypress
build
node_modules
key: ${{ runner.os }}-node_modules-build-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node_modules-build-
- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
# Need to skip setup if Cypress run is skipped, otherwise an error
# is thrown since the pnpm cache step fails
if: ${{ ( env.CYPRESS_RECORD_KEY != '' ) || ( matrix.containers == 1 ) }}
with:
cache: yarn
cache: pnpm
node-version: ${{ matrix.node-version }}

# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v3
uses: cypress-io/github-action@v4
# If CYPRESS_RECORD_KEY is set, run in parallel on all containers
# Otherwise (e.g. if running from fork), we run on a single container only
if: ${{ ( env.CYPRESS_RECORD_KEY != '' ) || ( matrix.containers == 1 ) }}
with:
start: yarn dev
start: pnpm run dev
wait-on: 'http://localhost:9000'
# Disable recording if we don't have an API key
# e.g. if this action was run from a fork
record: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
parallel: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
headless: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: yarn
cache: pnpm
node-version: ${{ matrix.node-version }}

- name: Install Yarn
run: npm i yarn --global

- name: Install Packages
run: |
yarn install --frozen-lockfile
pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress

- name: Run Linting
run: yarn lint
run: pnpm run lint

- name: Verify Docs
run: yarn docs:verify
run: pnpm run docs:verify
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
# uses version from "packageManager" field in package.json

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: yarn
cache: pnpm
node-version: ${{ matrix.node-version }}

- name: Install Yarn
run: npm i yarn --global

- name: Install Packages
run: |
yarn install --frozen-lockfile
pnpm install --frozen-lockfile
env:
CYPRESS_CACHE_FOLDER: .cache/Cypress

- name: Run Unit Tests
run: |
yarn ci --coverage
pnpm run ci --coverage

- name: Upload Coverage to Coveralls
# it feels a bit weird to use @master, but that's what the docs use
Expand Down
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dist
cypress/platform/xss3.html
.cache
coverage
coverage
# Autogenerated by PNPM
pnpm-lock.yaml
87 changes: 70 additions & 17 deletions .vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,67 @@ import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
import pkg from '../package.json' assert { type: 'json' };

const { dependencies } = pkg;
const watch = process.argv.includes('--watch');
const __dirname = fileURLToPath(new URL('.', import.meta.url));

type OutputOptions = Exclude<
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
undefined
>['output'];

const { dependencies } = pkg;
const watch = process.argv.includes('--watch');
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const packageOptions = {
mermaid: {
name: 'mermaid',
packageName: 'mermaid',
file: 'mermaid.ts',
},
'mermaid-mindmap': {
name: 'mermaid-mindmap',
packageName: 'mermaid-mindmap',
file: 'add-diagram.ts',
},
'mermaid-mindmap-detector': {
name: 'mermaid-mindmap-detector',
packageName: 'mermaid-mindmap',
file: 'registry.ts',
},
'mermaid-example-diagram': {
name: 'mermaid-example-diagram',
packageName: 'mermaid-example-diagram',
file: 'add-diagram.ts',
},
'mermaid-example-diagram-detector': {
name: 'mermaid-example-diagram-detector',
packageName: 'mermaid-example-diagram',
file: 'registry.ts',
},
};

interface BuildOptions {
minify: boolean | 'esbuild';
core?: boolean;
watch?: boolean;
entryName: keyof typeof packageOptions;
}

export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions): InlineConfig => {
const external = ['require', 'fs', 'path'];
console.log(entryName, packageOptions[entryName]);
const { name, file, packageName } = packageOptions[entryName];
let output: OutputOptions = [
{
name: 'mermaid',
name,
format: 'esm',
sourcemap: true,
entryFileNames: `[name].esm${minify ? '.min' : ''}.mjs`,
entryFileNames: `${name}.esm${minify ? '.min' : ''}.mjs`,
},
{
name: 'mermaid',
name,
format: 'umd',
sourcemap: true,
entryFileNames: `[name]${minify ? '.min' : ''}.js`,
entryFileNames: `${name}${minify ? '.min' : ''}.js`,
},
];

Expand All @@ -42,9 +74,10 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon
// This needs to be an array. Otherwise vite will build esm & umd with same name and overwrite esm with umd.
output = [
{
name,
format: 'esm',
sourcemap: true,
entryFileNames: `[name].core.mjs`,
entryFileNames: `${name}.core.mjs`,
},
];
}
Expand All @@ -53,11 +86,12 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon
configFile: false,
build: {
emptyOutDir: false,
outDir: resolve(__dirname, `../packages/${packageName}/dist`),
lib: {
entry: resolve(__dirname, '../src/mermaid.ts'),
name: 'mermaid',
entry: resolve(__dirname, `../packages/${packageName}/src/${file}`),
name,
// the proper extensions will be added
fileName: 'mermaid',
fileName: name,
},
minify,
rollupOptions: {
Expand All @@ -73,17 +107,36 @@ export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineCon

if (watch && config.build) {
config.build.watch = {
include: 'src/**',
include: [
'packages/mermaid-mindmap/src/**',
'packages/mermaid/src/**',
'packages/mermaid-example-diagram/src/**',
],
};
}

return config;
};

const buildPackage = async (entryName: keyof typeof packageOptions) => {
return Promise.allSettled([
build(getBuildConfig({ minify: false, entryName })),
build(getBuildConfig({ minify: 'esbuild', entryName })),
build(getBuildConfig({ minify: false, core: true, entryName })),
]);
};

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 }));
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid' }));
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-mindmap' }));
build(getBuildConfig({ minify: false, watch, entryName: 'mermaid-example-diagram' }));
} else {
build(getBuildConfig({ minify: false }));
build(getBuildConfig({ minify: 'esbuild' }));
build(getBuildConfig({ minify: false, core: true }));
void main();
}
2 changes: 1 addition & 1 deletion .vite/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function createServer() {
});

app.use(vite.middlewares);
app.use(express.static('dist'));
app.use(express.static('./packages/mermaid/dist'));
app.use(express.static('demos'));
app.use(express.static('cypress/platform'));

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# mermaid [![Build Status](https://travis-ci.org/mermaid-js/mermaid.svg?branch=master)](https://travis-ci.org/mermaid-js/mermaid) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE)

# Whoa, whats going on here?

We are transforming the Mermaid repository to a so called mono-repo. This is a part of the effort to decouple the diagrams from the core of mermaid. This will:

- Make it possible to select which diagrams to include on your site
- Open up for lazy loading
- Make it possible to add diagrams from outside of the Mermaid repository
- Separate the release flow between different diagrams and the Mermaid core

As such be aware of sime changes..

# We use pnpm now

# The source code has moved

It is now localted in the src forunder for respoective package located as subfoders in packages.

English | [简体中文](./README.zh-CN.md)

<img src="./img/header.png" alt="" />
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/bundle-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mermaid from '../../src/mermaid';
import mermaid from '../../packages/mermaid/src/mermaid';

let code = `flowchart LR
Power_Supply --> Transmitter_A
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/e2e.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset="utf-8" />
<!-- <meta charset="iso-8859-15"/> -->
<script src="./viewer.js" type="module" />
<script src="./viewer.js" type="module"></script>
<!-- <link href="https://fonts.googleapis.com/css?family=Mansalva&display=swap" rel="stylesheet" /> -->
<link
href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap"
Expand Down
Loading