Skip to content

Commit

Permalink
fix: json import, js-base64
Browse files Browse the repository at this point in the history
Co-authored-by: Alois Klink <alois@aloisklink.com>
  • Loading branch information
sidharthv96 and aloisklink committed Sep 23, 2022
1 parent 2a86ced commit eaa1602
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
11 changes: 4 additions & 7 deletions .vite/build.ts
Expand Up @@ -2,18 +2,15 @@ import { build, InlineConfig } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import jisonPlugin from './jisonPlugin.js';
import { readFileSync } from 'node:fs';

import pkg from '../package.json' assert { type: 'json' };
type OutputOptions = Exclude<
Exclude<InlineConfig['build'], undefined>['rollupOptions'],
undefined
>['output'];

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const { dependencies } = JSON.parse(
readFileSync(resolve(__dirname, '../package.json'), { encoding: 'utf8' })
);
const { dependencies } = pkg;
const watch = process.argv.includes('--watch');
const __dirname = fileURLToPath(new URL('.', import.meta.url));

interface BuildOptions {
minify: boolean | 'esbuild';
Expand All @@ -23,7 +20,7 @@ interface BuildOptions {

export const getBuildConfig = ({ minify, core, watch }: BuildOptions): InlineConfig => {
const external = ['require', 'fs', 'path'];
let output: OutputOptions = [
let output: OutputOptions | OutputOptions[] = [
{
name: 'mermaid',
format: 'esm',
Expand Down
6 changes: 6 additions & 0 deletions .vite/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "ES2022"
}
}
6 changes: 4 additions & 2 deletions cypress/helpers/util.js
@@ -1,12 +1,14 @@
import { Base64 } from 'js-base64';
const utf8ToB64 = (str) => {
return window.btoa(unescape(encodeURIComponent(str)));
};

export const mermaidUrl = (graphStr, options, api) => {
const obj = {
code: graphStr,
mermaid: options,
};
const objStr = JSON.stringify(obj);
let url = 'http://localhost:9000/e2e.html?graph=' + Base64.encodeURI(objStr);
let url = 'http://localhost:9000/e2e.html?graph=' + utf8ToB64(objStr);
if (api) {
url = 'http://localhost:9000/xss.html?graph=' + graphStr;
}
Expand Down
9 changes: 6 additions & 3 deletions cypress/platform/viewer.js
@@ -1,6 +1,9 @@
import { Base64 } from '../../node_modules/js-base64';
import mermaid2 from '../../src/mermaid';

function b64ToUtf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}

/**
* ##contentLoaded Callback function that is called when page is loaded. This functions fetches
* configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
Expand All @@ -11,7 +14,7 @@ const contentLoaded = function () {
if (pos > 0) {
pos = pos + 7;
const graphBase64 = document.location.href.substr(pos);
const graphObj = JSON.parse(Base64.decode(graphBase64));
const graphObj = JSON.parse(b64ToUtf8(graphBase64));
if (graphObj.mermaid && graphObj.mermaid.theme === 'dark') {
document.body.style.background = '#3f3f3f';
}
Expand Down Expand Up @@ -67,7 +70,7 @@ const contentLoadedApi = function () {
if (pos > 0) {
pos = pos + 7;
const graphBase64 = document.location.href.substr(pos);
const graphObj = JSON.parse(Base64.decode(graphBase64));
const graphObj = JSON.parse(window.btoa(graphBase64));
// const graph = 'hello'
if (Array.isArray(graphObj.code)) {
const numCodes = graphObj.code.length;
Expand Down
8 changes: 3 additions & 5 deletions package.json
Expand Up @@ -25,18 +25,18 @@
],
"scripts": {
"clean": "rimraf dist",
"build:vite": "ts-node-esm .vite/build.ts",
"build:vite": "ts-node-esm --transpileOnly --project=.vite/tsconfig.json .vite/build.ts",
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
"build:watch": "yarn build:code --watch",
"build": "yarn clean; concurrently \"yarn build:vite\" \"yarn build:types\"",
"dev": "concurrently \"yarn build:vite --watch\" \"ts-node-esm .vite/server\"",
"docs:build": "ts-node-esm src/docs.mts",
"docs:build": "ts-node-esm --transpileOnly src/docs.mts",
"docs:verify": "yarn docs:build --verify",
"postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md && prettier --write src/docs/Setup.md",
"release": "yarn build",
"lint": "eslint --cache --ignore-path .gitignore . && yarn lint:jison && prettier --check .",
"lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write .",
"lint:jison": "ts-node-esm src/jison/lint.mts",
"lint:jison": "ts-node-esm --transpileOnly src/jison/lint.mts",
"cypress": "cypress run",
"cypress:open": "cypress open",
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
Expand Down Expand Up @@ -98,7 +98,6 @@
"cypress": "^10.0.0",
"cypress-image-snapshot": "^4.0.1",
"documentation": "13.2.0",
"esbuild": "^0.15.8",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-cypress": "^2.12.1",
Expand All @@ -112,7 +111,6 @@
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jison": "^0.4.18",
"js-base64": "3.7.2",
"jsdom": "^20.0.0",
"lint-staged": "^13.0.0",
"moment": "^2.23.0",
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Expand Up @@ -4601,7 +4601,7 @@ esbuild-windows-arm64@0.15.8:
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.8.tgz#1d75235290bf23a111e6c0b03febd324af115cb1"
integrity sha512-dbpAb0VyPaUs9mgw65KRfQ9rqiWCHpNzrJusoPu+LpEoswosjt/tFxN7cd2l68AT4qWdBkzAjDLRon7uqMeWcg==

esbuild@^0.15.6, esbuild@^0.15.8:
esbuild@^0.15.6:
version "0.15.8"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.8.tgz#75daa25d03f6dd9cc9355030eba2b93555b42cd4"
integrity sha512-Remsk2dmr1Ia65sU+QasE6svJbsHe62lzR+CnjpUvbZ+uSYo1SitiOWPRfZQkCu82YWZBBKXiD/j0i//XWMZ+Q==
Expand Down Expand Up @@ -6448,11 +6448,6 @@ jpeg-js@0.4.4:
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.4.tgz#a9f1c6f1f9f0fa80cdb3484ed9635054d28936aa"
integrity sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==

js-base64@3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745"
integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==

js-sdsl@^4.1.4:
version "4.1.4"
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.4.tgz#78793c90f80e8430b7d8dc94515b6c77d98a26a6"
Expand Down

0 comments on commit eaa1602

Please sign in to comment.