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

Support node16 module resolution #4213

Merged
Merged
10 changes: 8 additions & 2 deletions .vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
import { readFileSync } from 'fs';
import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
import type { TemplateType } from 'rollup-plugin-visualizer/dist/plugin/template-types.js';

Expand Down Expand Up @@ -102,9 +103,14 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
},
},
resolve: {
extensions: ['.jison', '.js', '.ts', '.json'],
extensions: [],
},
Comment on lines 105 to 107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this block?

Copy link
Contributor Author

@remcohaszing remcohaszing Apr 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, according to https://vitejs.dev/config/shared-options.html#resolve-extensions, ths allows some extensions by default, which we don’t want.

plugins: [jisonPlugin(), ...visualizerOptions(packageName, core)],
plugins: [
jisonPlugin(),
// @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite
typescript({ compilerOptions: { declaration: false } }),
...visualizerOptions(packageName, core),
],
};

if (watch && config.build) {
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/d3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck TODO: Fix TS
import { MockedD3 } from '../packages/mermaid/src/tests/MockedD3';
import { MockedD3 } from '../packages/mermaid/src/tests/MockedD3.js';

export const select = function () {
return new MockedD3();
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/other/configuration.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderGraph } from '../../helpers/util';
import { renderGraph } from '../../helpers/util.js';
describe('Configuration', () => {
describe('arrowMarkerAbsolute', () => {
it('should handle default value false of arrowMarkerAbsolute', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/other/external-diagrams.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { urlSnapshotTest } from '../../helpers/util';
import { urlSnapshotTest } from '../../helpers/util.js';

describe('mermaid', () => {
describe('registerDiagram', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/other/ghsa.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { urlSnapshotTest } from '../../helpers/util';
import { urlSnapshotTest } from '../../helpers/util.js';

describe('CSS injections', () => {
it('should not allow CSS injections outside of the diagram', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/classDiagram-v2.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest } from '../../helpers/util';
import { imgSnapshotTest } from '../../helpers/util.js';
describe('Class diagram V2', () => {
it('0: should render a simple class diagram', () => {
imgSnapshotTest(
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/classDiagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('Class diagram', () => {
it('1: should render a simple class diagram', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/current.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest } from '../../helpers/util';
import { imgSnapshotTest } from '../../helpers/util.js';

describe('Current diagram', () => {
it('should render a state with states in it', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/debug.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest } from '../../helpers/util';
import { imgSnapshotTest } from '../../helpers/util.js';

describe('Flowchart', () => {
it('34: testing the label width in percy', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/erDiagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('Entity Relationship Diagram', () => {
it('should render a simple ER diagram', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/flowchart-elk.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe.skip('Flowchart ELK', () => {
it('1-elk: should render a simple flowchart', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/flowchart-v2.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('Flowchart v2', () => {
it('1: should render a simple flowchart', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/flowchart.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('Graph', () => {
it('1: should render a simple flowchart no htmlLabels', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/sequencediagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="Cypress" />

import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

context('Sequence diagram', () => {
it('should render a sequence diagram with boxes', () => {
Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/rendering/stateDiagram-v2.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('State diagram', () => {
it('v2 should render a simple info', () => {
Expand Down Expand Up @@ -530,7 +530,7 @@ stateDiagram-v2
[*] --> A
A --> B: test({ foo#colon; 'far' })
B --> [*]
classDef badBadEvent fill:#f00,color:white,font-weight:bold
classDef badBadEvent fill:#f00,color:white,font-weight:bold
class B badBadEvent
`,
{ logLevel: 0, fontFamily: 'courier' }
Expand All @@ -543,14 +543,14 @@ stateDiagram-v2
classDef notMoving fill:white
classDef movement font-style:italic;
classDef badBadEvent fill:#f00,color:white,font-weight:bold

[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]

class Still notMoving
class Moving, Crash movement
class Crash badBadEvent
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/rendering/stateDiagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

describe('State diagram', () => {
it('should render a simple state diagrams', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/ashish2.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
//import mindmap from '../../packages/mermaid-mindmap/src/detector';
// import example from '../../packages/mermaid-example-diagram/src/detector';
// import timeline from '../../packages/mermaid-timeline/src/detector';
import mermaid from '../../packages/mermaid/src/mermaid';
import mermaid from './mermaid.esm.mjs';
// await mermaid.registerExternalDiagrams([]);
mermaid.parseError = function (err, hash) {
// console.error('Mermaid error: ', err);
Expand Down
3 changes: 2 additions & 1 deletion cypress/platform/bundle-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mermaid from '../../packages/mermaid/src/mermaid';
// TODO: this file should be testing the ./mermaid.core.mjs file, as that's the file listed in the package.json file that users will use
import mermaid from './mermaid.esm.mjs';

let code = `flowchart LR
Power_Supply --> Transmitter_A
Expand Down
4 changes: 2 additions & 2 deletions cypress/platform/external-diagrams-example-diagram.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ <h1>Should correctly load a third-party diagram using registerDiagram</h1>
<!-- <script src="//cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js"></script> -->
<!-- <script type="module" src="./external-diagrams-mindmap.mjs" /> -->
<script type="module">
import exampleDiagram from '../../packages/mermaid-example-diagram/src/detector';
import exampleDiagram from '../../packages/mermaid-example-diagram/dist/mermaid-example-diagram.core.mjs';
// import example from '../../packages/mermaid-example-diagram/src/detector';
import mermaid from '../../packages/mermaid/src/mermaid';
import mermaid from './mermaid.esm.mjs';

await mermaid.registerExternalDiagrams([exampleDiagram]);
await mermaid.initialize({ logLevel: 0 });
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/flow2.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</pre>

<script type="module">
import mermaid from '../../packages/mermaid/src/mermaid';
import mermaid from './mermaid.esm.mjs';

mermaid.initialize({
theme: 'forest',
Expand Down
4 changes: 2 additions & 2 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@

<script type="module">
// import mindmap from '../../packages/mermaid-mindmap/src/detector';
import example from '../../packages/mermaid-example-diagram/src/detector';
import mermaid from '../../packages/mermaid/src/mermaid';
import example from '../../packages/mermaid-example-diagram/src/mermaid-example-diagram.core.mjs';
import mermaid from './mermaid.esm.mjs';
await mermaid.registerExternalDiagrams([example]);
mermaid.parseError = function (err, hash) {
// console.error('Mermaid error: ', err);
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/knsv3.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2>Mindmap with root wrapping text and a shape</h2>

<script type="module">
// import mermaid from './mermaid.esm.mjs';
import mermaid from '../../packages/mermaid/src/mermaid';
import mermaid from '../../packages/mermaid/dist/mermaid.esm.mjs';
// import mermaidMindmap from './mermaid-mindmap.esm.mjs';

// import mermaidMindmap from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-mindmap@9.3.0/+esm';
Expand Down
4 changes: 2 additions & 2 deletions cypress/platform/viewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mermaid2 from '../../packages/mermaid/src/mermaid';
import externalExample from '../../packages/mermaid-example-diagram/src/detector';
import mermaid2 from './mermaid.esm.mjs';
import externalExample from '../../packages/mermaid-example-diagram/dist/mermaid-example-diagram.core.mjs';

function b64ToUtf8(str) {
return decodeURIComponent(escape(window.atob(str)));
Expand Down
6 changes: 3 additions & 3 deletions docs/intro/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ To Deploy Mermaid:

### [Mermaid API](../config/setup/README.md):

**To deploy mermaid without a bundler, one can insert a `script` tag with an absolute address and a `mermaid.initialize` call into the HTML like so:**
**To deploy mermaid without a bundler, insert a `script` tag with an absolute address and a `mermaid.initialize` call into the HTML using the following example:**

```html
<script type="module">
Expand All @@ -272,9 +272,9 @@ To Deploy Mermaid:
</script>
```

**Doing so will command the mermaid parser to look for the `<div>` or `<pre>` tags with `class="mermaid"`. From these tags mermaid will try to read the diagram/chart definitions and render them into SVG charts.**
**Doing so commands the mermaid parser to look for the `<div>` or `<pre>` tags with `class="mermaid"`. From these tags, mermaid tries read the diagram/chart definitions and render them into SVG charts.**

**Examples can be found at** [Other examples](../syntax/examples.md)
**Examples can be found in** [Other examples](../syntax/examples.md)

## Sibling projects

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@commitlint/cli": "^17.2.0",
"@commitlint/config-conventional": "^17.2.0",
"@cspell/eslint-plugin": "^6.14.2",
"@rollup/plugin-typescript": "^11.0.0",
"@types/cors": "^2.8.13",
"@types/eslint": "^8.4.10",
"@types/express": "^4.17.17",
Expand Down
10 changes: 5 additions & 5 deletions packages/mermaid-example-diagram/src/diagram-definition.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-ignore: TODO Fix ts errors
import parser from './parser/exampleDiagram';
import * as db from './exampleDiagramDb';
import renderer from './exampleDiagramRenderer';
import styles from './styles';
import { injectUtils } from './mermaidUtils';
import parser from './parser/exampleDiagram.jison';
import * as db from './exampleDiagramDb.js';
import renderer from './exampleDiagramRenderer.js';
import styles from './styles.js';
import { injectUtils } from './mermaidUtils.js';

export const diagram = {
db,
Expand Down
8 changes: 4 additions & 4 deletions packages/mermaid-example-diagram/src/exampleDiagram.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { parser } from './parser/exampleDiagram';
import * as db from './exampleDiagramDb';
import { injectUtils } from './mermaidUtils';
import { parser } from './parser/exampleDiagram.jison';
import * as db from './exampleDiagramDb.js';
import { injectUtils } from './mermaidUtils.js';
// Todo fix utils functions for tests
import {
log,
setLogLevel,
getConfig,
sanitizeText,
setupGraphViewBox,
} from '../../mermaid/src/diagram-api/diagramAPI';
} from '../../mermaid/src/diagram-api/diagramAPI.js';

injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewBox);

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid-example-diagram/src/exampleDiagramDb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Created by knut on 15-01-14. */
import { log } from './mermaidUtils';
import { log } from './mermaidUtils.js';

var message = '';
var info = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Created by knut on 14-12-11. */
import { select } from 'd3';
import { log, getConfig, setupGraphViewbox } from './mermaidUtils';
import { log, getConfig, setupGraphViewbox } from './mermaidUtils.js';

/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
Expand Down
1 change: 0 additions & 1 deletion packages/mermaid-example-diagram/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"extends": "../../tsconfig.json",
"module": "esnext",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
Expand Down
16 changes: 8 additions & 8 deletions packages/mermaid/src/Diagram.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as configApi from './config';
import { log } from './logger';
import { getDiagram, registerDiagram } from './diagram-api/diagramAPI';
import { detectType, getDiagramLoader } from './diagram-api/detectType';
import { extractFrontMatter } from './diagram-api/frontmatter';
import { UnknownDiagramError } from './errors';
import { DetailedError } from './utils';
import { cleanupComments } from './diagram-api/comments';
import * as configApi from './config.js';
import { log } from './logger.js';
import { getDiagram, registerDiagram } from './diagram-api/diagramAPI.js';
import { detectType, getDiagramLoader } from './diagram-api/detectType.js';
import { extractFrontMatter } from './diagram-api/frontmatter.js';
import { UnknownDiagramError } from './errors.js';
import { DetailedError } from './utils.js';
import { cleanupComments } from './diagram-api/comments.js';

export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/__mocks__/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* We can't easily use `vi.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`.
*/
import * as configApi from '../config';
import * as configApi from '../config.js';
import { vi } from 'vitest';
import { mermaidAPI as mAPI } from '../mermaidAPI';
import { mermaidAPI as mAPI } from '../mermaidAPI.js';

// original version cannot be modified since it was frozen with `Object.freeze()`
export const mermaidAPI = {
Expand Down
6 changes: 3 additions & 3 deletions packages/mermaid/src/accessibility.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MockedD3 } from './tests/MockedD3';
import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility';
import { D3Element } from './mermaidAPI';
import { MockedD3 } from './tests/MockedD3.js';
import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility.js';
import { D3Element } from './mermaidAPI.js';

describe('accessibility', () => {
const fauxSvgNode = new MockedD3();
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @see https://www.w3.org/TR/svg-aam-1.0/
*
*/
import { D3Element } from './mermaidAPI';
import { D3Element } from './mermaidAPI.js';

import isEmpty from 'lodash-es/isEmpty.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/commonDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sanitizeText as _sanitizeText } from './diagrams/common/common';
import { getConfig } from './config';
import { sanitizeText as _sanitizeText } from './diagrams/common/common.js';
import { getConfig } from './config.js';
let title = '';
let diagramTitle = '';
let description = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/config.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as configApi from './config';
import * as configApi from './config.js';

describe('when working with site config', function () {
beforeEach(() => {
Expand Down
10 changes: 5 additions & 5 deletions packages/mermaid/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assignWithDepth from './assignWithDepth';
import { log } from './logger';
import theme from './themes';
import config from './defaultConfig';
import type { MermaidConfig } from './config.type';
import assignWithDepth from './assignWithDepth.js';
import { log } from './logger.js';
import theme from './themes/index.js';
import config from './defaultConfig.js';
import type { MermaidConfig } from './config.type.js';

export const defaultConfig: MermaidConfig = Object.freeze(config);

Expand Down
12 changes: 6 additions & 6 deletions packages/mermaid/src/dagre-wrapper/clusters.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import intersectRect from './intersect/intersect-rect';
import { log } from '../logger';
import createLabel from './createLabel';
import { createText } from '../rendering-util/createText';
import intersectRect from './intersect/intersect-rect.js';
import { log } from '../logger.js';
import createLabel from './createLabel.js';
import { createText } from '../rendering-util/createText.js';
import { select } from 'd3';
import { getConfig } from '../config';
import { evaluate } from '../diagrams/common/common';
import { getConfig } from '../config.js';
import { evaluate } from '../diagrams/common/common.js';

const rect = (parent, node) => {
log.info('Creating subgraph rect for ', node.id, node);
Expand Down
Loading