Skip to content

Commit

Permalink
Merge pull request #82 from usds/tomn-usds/checkpackage
Browse files Browse the repository at this point in the history
added checkpackage
  • Loading branch information
TomNUSDS authored Aug 23, 2024
2 parents 6b3c7a6 + 8c5824f commit 0568f7c
Show file tree
Hide file tree
Showing 16 changed files with 1,539 additions and 2,034 deletions.
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,32 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint . --ext ts,tsx --ignore-pattern \"**/*.config.ts\" --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"update": "yarn upgrade-interactive --latest"
"update": "yarn upgrade-interactive --latest",
"checkpackage": "node scripts/check_mdx_packages.cjs"
},
"sideEffects": [
"*.css"
],
"dependencies": {
"@lexical/react": "^0.16.0",
"@lexical/react": "^0.17.0",
"@mdxeditor/editor": "^3.4.2",
"@mdxeditor/gurx": "^1.1.3",
"@trussworks/react-uswds": "^6.2.0",
"@uswds/uswds": "^3.8.1",
"downshift": "^7.6.0",
"js-yaml": "^4.1.0",
"jszip": "^3.10.1",
"lexical": "^0.14.5",
"lexical": "^0.17.0",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-frontmatter": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"micromark-extension-gfm": "^3.0.0",
"moment": "^2.30.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.52.0",
"react-toastify": "^10.0.5",
"yjs": "^13.6.17"
Expand All @@ -49,6 +51,7 @@
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"node": "^20.17.0",
"postcss": "^8.4.38",
"postcss-extend": "^1.0.5",
"postcss-mixins": "^10.0.1",
Expand All @@ -59,14 +62,14 @@
"vite-plugin-svgr": "^4.2.0"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"resolutions": {
"@lexical/react": "^0.14.5",
"@lexical/react": "^0.17.0",
"@mdxeditor/gurx": "^1.1.3",
"downshift": "^7.6.0",
"lexical": "^0.14.5",
"lexical": "^0.17.0",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-frontmatter": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
Expand Down
110 changes: 110 additions & 0 deletions scripts/check_mdx_packages.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Because MDX Editor doesn't allow all the customization we need, we have to write
// code that runs within the context of that library. THAT requires we have the exact
// same revisions for dependencies or we get weird compiler errors from the libraries.
//
// This script just sanity checks that the revisions match.
//

const path = require('path');
const fs = require('fs');

function intersection_keys(o1, o2) {
const [k1, k2] = [Object.keys(o1), Object.keys(o2)];
const [first, next] = k1.length > k2.length ? [k2, o1] : [k1, o2];
return first.filter(k => k in next);
}

function check_mdx_packages() {
// load our package.json,
const basepath = ".";
const ourpackagepath = path.join(basepath, 'package.json');
const ourpackage = JSON.parse(fs.readFileSync(ourpackagepath, 'utf8'));

// find the mdx dependency
const mdxpackagepath = path.join(basepath, 'node_modules/@mdxeditor/editor/package.json');
const mdxpackage = JSON.parse(fs.readFileSync(mdxpackagepath, 'utf8'));

console.log(`Checking our package.json and mdxeditor's package.json for possible conflicts`);

// check that dev doesn't over devDependencies and dependencies don't have any overlaps
{
const overlapkeys = intersection_keys(ourpackage["dependencies"] ?? {}, ourpackage["devDependencies"] ?? {});
if (overlapkeys.length > 0) {
console.log(` "${ourpackagepath}" has overlapping "dependencies" and "devDependencies" for keys: ${JSON.stringify(overlapkeys)}`);
}
}

// check the "peerDependencies" have the same version as what in "devDependencies" and "dependencies"
const allourdepends = {...(ourpackage["dependencies"] ??{}), ...(ourpackage["devDependencies"] ?? {})};
{
const peerdepends = ourpackage["peerDependencies"] ?? {}; // readabillity
const overlapkeys = intersection_keys(peerdepends, allourdepends ?? {});
if (overlapkeys.length > 0) {
// loop over and compare values
for (const key of overlapkeys) {
if (allourdepends[key] !== peerdepends[key]) {
console.log(` "${ourpackagepath}" package for "peerDependencies" version mismatch for "${key}" ("${allourdepends[key]}" <> ${peerdepends[key]})`);
}
}
}
}

// make sure the "resolutions" versions match
{
let printed_header = false;
const resolutiondepends = ourpackage["resolutions"] ?? {}; // readabillity
const overlapkeys = intersection_keys(resolutiondepends, allourdepends ?? {});
if (overlapkeys.length > 0) {
// loop over and compare values
for (const key of overlapkeys) {
if (allourdepends[key] !== resolutiondepends[key]) {
if (!printed_header) {
console.warn(` "${ourpackagepath}" package for the "resolutiondepends" version mismatch.\n [major.minor.fix] as long as major and minor are close, it's probably fine.:`);
printed_header = true;
}

console.warn(` "${key}" "${allourdepends[key]}"<>"${resolutiondepends[key]}" (resolutiondepends)`);
}
}
}
}

// Now check against the mdxeditor we have installed.
{
let printed_header = false;
const allmdxdepends = {...(mdxpackage["dependencies"] ?? {})};
const overlapkeys = intersection_keys(allmdxdepends, allourdepends);
if (overlapkeys.length > 0) {
// loop over and compare values
for (const key of overlapkeys) {
if (allourdepends[key] !== allmdxdepends[key]) {
if (!printed_header) {
console.warn(` "${ourpackagepath}" package vs "${mdxpackagepath}" dependencies package (more important):`);
printed_header = true;
}
console.warn(` "${key}": (ours) "${allourdepends[key]}"<>"${allmdxdepends[key]}" (mdx)`);
}
}
}
}

{
let printed_header = false;
const allmdxdepends = { ...(mdxpackage["devDependencies"] ?? {})};
const overlapkeys = intersection_keys(allmdxdepends, allourdepends);
if (overlapkeys.length > 0) {
// loop over and compare values
for (const key of overlapkeys) {
if (allourdepends[key] !== allmdxdepends[key]) {
if (!printed_header) {
console.log(` "${ourpackagepath}" package vs "${mdxpackagepath}" devDependencies package (less important, but watch for issues):`);
printed_header = true;
}
console.log(` DEV "${key}": (ours) "${allourdepends[key]}"<>"${allmdxdepends[key]}" (mdx)`);
}
}
}
}
}

check_mdx_packages();
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type PagesMap = {


function App() {
// this is basically useState that persists to localstorage
// this is basically useState that persists to sessionStorage
const [page, setPage] = useReducer((_prev: PagesType, cur: PagesType) => {
localStorage.setItem('currentPage', cur);
sessionStorage.setItem('currentPage', cur);
return cur;
}, (localStorage.getItem('currentPage') as PagesType) || "Home");
}, (sessionStorage.getItem('currentPage') as PagesType) || "Home");
const PAGES_MAP: PagesMap = {
"Home": <HomePage/>,
"Blog Edit": <BlogEditorPage/>,
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditActionsToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getBlogTemplateMarkdown,
saveDataToZip,
} from "../mdxcomponents/frontmatterUtils.ts";
import {showToast} from "./showToast.tsx";
import {showToast} from "./ShowToast.tsx";
import {MARKDOWN_LOCAL_STORAGE_KEY} from "../types/commontypes.ts";
import { Fragment, useRef} from "react";

Expand Down
11 changes: 9 additions & 2 deletions src/components/ErrorElement.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import {Fragment} from "react";
import {Fragment, useEffect} from "react";
import {Alert} from "@trussworks/react-uswds";
import {showToast} from "./ShowToast.tsx";

export const ErrorElement = () => {
useEffect(() => {
showToast("Some of the data caused a crash. Probably format related.", "error");
}, []);
return (<Fragment>
ErrorElement placeholder
<h2>Error in App</h2>
<Alert type={"error"} headingLevel={"h2"}>There was some unexpected error.</Alert>
Try using the Reset Data button found in the bottom left of the screen.
</Fragment>)
}
File renamed without changes.
19 changes: 19 additions & 0 deletions src/components/ResetButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Button} from "@trussworks/react-uswds";
import {devResetEverything} from "../misc.ts";
import {MDXEditorMethods} from "@mdxeditor/editor";

export const ResetButton = ({ mdxeditorref }: { mdxeditorref?: React.RefObject<MDXEditorMethods> }) => {
// disable for usability study
return <div className={"developer_div"}>
<Button
type={"button"}
accentStyle={"warm"}
outline={true}
unstyled={true}
onClick={() => {
if (confirm("Clear all settings and data? This will lose everything and start fresh.\n\nContinue?")) {
mdxeditorref?.current?.setMarkdown("");
void devResetEverything()
}
}}>Reset</Button></div>
};
File renamed without changes.
Loading

0 comments on commit 0568f7c

Please sign in to comment.