Skip to content

Commit

Permalink
Modernize dependencies (jscheiny#178)
Browse files Browse the repository at this point in the history
* Modernize dependencies

* Action?
  • Loading branch information
jscheiny authored May 16, 2024
1 parent 44af31b commit 21d6afb
Show file tree
Hide file tree
Showing 22 changed files with 3,653 additions and 2,916 deletions.
27 changes: 27 additions & 0 deletions .github/actions/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: yarn verify
2 changes: 1 addition & 1 deletion codegen/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "../dist/codegen"
}
}
2 changes: 1 addition & 1 deletion docsgen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const pages = readdirSync("docs")
const orderPath = join("docs", "order.txt");
let order: string[] = [];
if (existsSync(orderPath) && !statSync(orderPath).isDirectory()) {
order = readFileSync(orderPath, "UTF8").split("\n");
order = readFileSync(orderPath, "utf-8").split("\n");
}

function orderBy(order: string[]): (a: PageModel, b: PageModel) => number {
Expand Down
21 changes: 12 additions & 9 deletions docsgen/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from "commonmark";
import { highlight } from "highlight.js";
import highlight from "highlight.js";
import * as React from "react";
import { createNodeId, getNodeText } from "./markdownUtils";
import { component } from "./style";
Expand All @@ -14,41 +14,43 @@ export const Markdown: MarkdownComponent = ({ root }) => {
switch (root.type) {
case "document":
return <MarkdownChildren root={root} />;
case "paragraph":
case "paragraph": {
const children = <MarkdownChildren root={root} />;
const grandparent = root.parent ? root.parent.parent : null;
if (grandparent !== null && grandparent.type === "list" && grandparent.listTight) {
return children;
} else {
return <p>{children}</p>;
}
}
case "text":
return <>{root.literal}</>;
case "heading":
return <MarkdownHeading root={root} />;
case "linebreak":
return <br />;
case "html_inline":
return <span dangerouslySetInnerHTML={{ __html: root.literal || "" }} />;
return <span dangerouslySetInnerHTML={{ __html: root.literal ?? "" }} />;
case "html_block":
return <span dangerouslySetInnerHTML={{ __html: root.literal || "" }} />;
return <span dangerouslySetInnerHTML={{ __html: root.literal ?? "" }} />;
case "link":
return (
<Link href={root.destination || ""}>
<Link href={root.destination ?? ""}>
<MarkdownChildren root={root} />
</Link>
);
case "image":
return <img src={root.destination || ""} alt={getNodeText(root)} />;
return <img src={root.destination ?? ""} alt={getNodeText(root)} />;
case "thematic_break":
return <hr />;
case "code_block":
const highlightedCode = highlight("typescript", root.literal || "", true).value;
case "code_block": {
const highlightedCode = highlight.highlight(root.literal ?? "", { language: "typescript" }).value;
return (
<pre>
<CodeBlock className="hljs typescript" dangerouslySetInnerHTML={{ __html: highlightedCode }} />
</pre>
);
}
case "code":
return <CodeInline>{root.literal}</CodeInline>;
case "softbreak":
Expand All @@ -59,9 +61,10 @@ export const Markdown: MarkdownComponent = ({ root }) => {
case "custom_block":
// TODO Handle this
return null;
default:
default: {
const tag = getTag(root.type, root);
return React.createElement(tag, {}, <MarkdownChildren root={root} />);
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions docsgen/pageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PageSection {
export class PageModel {
public static from(path: string): PageModel {
const name = basename(path, ".md");
const source = readFileSync(path, "UTF8");
const source = readFileSync(path, "utf-8");
const root = parser.parse(source);
return new PageModel(name, root, getTitle(root), getSections(root));
}
Expand Down Expand Up @@ -49,7 +49,7 @@ function getTitle(root: Node): string {
}

function getSections(root: Node): PageSection[] {
let sections: PageSection[] = [];
const sections: PageSection[] = [];
walkMarkdown(root, node => {
if (node.type === "heading" && node.level !== 1) {
sections.push(getSection(node));
Expand Down
18 changes: 10 additions & 8 deletions docsgen/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ interface SidebarProps {
}

export const Sidebar: React.FunctionComponent<SidebarProps> = ({ pages, selectedIndex }) => {
const pageSections = pages[selectedIndex].sections.filter(({ level }) => level <= 3).map(({ id, node, level }) => {
const className = classes(level === 2 && section, level === 3 && subsection);
return (
<SectionLink key={id} href={`#${id}`} className={className}>
<MarkdownChildren root={node} />
</SectionLink>
);
});
const pageSections = pages[selectedIndex].sections
.filter(({ level }) => level <= 3)
.map(({ id, node, level }) => {
const className = classes(level === 2 && section, level === 3 && subsection);
return (
<SectionLink key={id} href={`#${id}`} className={className}>
<MarkdownChildren root={node} />
</SectionLink>
);
});

const links = pages.map((page, index) => {
const isSelected = index === selectedIndex;
Expand Down
2 changes: 1 addition & 1 deletion docsgen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../tsconfig.base.json",
"compilerOptions": {
"jsx": "react",
"outDir": "./dist",
"outDir": "../dist/docsgen",
"lib": [
"dom",
"esnext",
Expand Down
33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check

import eslint from "@eslint/js";
import stylisticTs from "@stylistic/eslint-plugin-ts";
import tseslint from "typescript-eslint";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

export default tseslint.config(
eslint.configs.recommended,
eslintPluginPrettierRecommended,
...tseslint.configs.recommended,
{
plugins: {
"@stylistic/ts": stylisticTs,
},
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@/linebreak-style": ["error", "unix"],
"prettier/prettier": [
"error",
{
arrowParens: "avoid",
printWidth: 120,
tabWidth: 4,
trailingComma: "all",
},
],
},
},
);
32 changes: 0 additions & 32 deletions jest.config.json

This file was deleted.

24 changes: 24 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Config } from "jest";

const config: Config = {
collectCoverage: true,
collectCoverageFrom: ["<rootDir>/src/**/*.ts"],
coveragePathIgnorePatterns: [".*Tests\\.ts", ".*Spec\\.ts", "index.ts", "src/quantity/.*"],
coverageThreshold: {
global: {
branches: 99,
functions: 99,
lines: 99,
statements: 99,
},
},
moduleFileExtensions: ["js", "json", "ts"],
testEnvironment: "jsdom",
testMatch: ["<rootDir>/src/**/__test__/**/*Tests.ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
verbose: true,
};

export default config;
61 changes: 32 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,55 @@
"type": "git",
"url": "https://github.com/jscheiny/safe-units.git"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"scripts": {
"build": "npm-run-all -s codegen compile:src",
"clean": "rimraf dist codegen/dist docsgen/dist docs/build",
"clean": "rimraf dist docs/build",
"codegen": "npm-run-all -s compile:codegen node:codegen",
"compile:codegen": "tsc -p codegen",
"compile:docs": "tsc -p docsgen",
"compile:src": "tsc -p src",
"docs": "npm-run-all -s compile:docs node:docs",
"lint:codegen": "tslint -p codegen/tsconfig.json -c tslint.json",
"lint:docs": "tslint -p docsgen/tsconfig.json -c tslint.json",
"lint:src": "tslint -p src/tsconfig.json -c tslint.json",
"lint:codegen": "eslint --config eslint.config.mjs codegen",
"lint:docs": "eslint --config eslint.config.mjs docsgen",
"lint:src": "eslint --config eslint.config.mjs src",
"lint:dist": "./scripts/check-typings.sh",
"lint:types": "dtslint test/types",
"lint": "npm-run-all -p lint:codegen lint:docs lint:src lint:dist lint:types",
"node:codegen": "node codegen/dist/emit",
"node:docs": "node docsgen/dist/index",
"test": "jest --config jest.config.json",
"lint": "npm-run-all -p lint:codegen lint:docs lint:src lint:dist",
"node:codegen": "node dist/codegen/emit",
"node:docs": "node dist/docsgen/index",
"test": "jest --config jest.config.ts",
"prepack": "yarn clean && yarn build",
"verify": "npm-run-all -s build lint test docs"
},
"devDependencies": {
"@types/commonmark": "^0.27.1",
"@types/highlight.js": "^9.12.3",
"@types/jest": "^22.2.3",
"@types/node": "^8.10.16",
"@eslint/js": "^9.2.0",
"@types/commonmark": "^0.27.9",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@types/react-dom": "^16.0.11",
"commonmark": "^0.28.1",
"commonmark": "^0.31.0",
"dtslint": "^0.3.0",
"highlight.js": "^9.14.2",
"jest": "^22.4.3",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"highlight.js": "^11.9.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.3",
"prettier": "^1.12.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"rimraf": "^2.6.3",
"ts-jest": "^22.4.6",
"ts-node": "^6.0.3",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.12.0",
"tslint-config-standard": "^7.0.0",
"tslint-no-circular-imports": "^0.4.0",
"tslint-plugin-prettier": "^1.3.0",
"typescript": "~3.5.2",
"typestyle": "^2.0.1"
"rimraf": "^5.0.7",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.9.0",
"typestyle": "^2.4.0"
},
"dependencies": {
"@stylistic/eslint-plugin-ts": "^2.1.0"
}
}
18 changes: 3 additions & 15 deletions src/measure/__test__/numberMeasureTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ describe("Number measures", () => {
expectFormat(meters.per(seconds.times(kilograms)), "1 m / (kg * s)");
expectFormat(meters.squared().per(seconds.squared().times(kilograms)), "1 m^2 / (kg * s^2)");
expectFormat(
meters
.cubed()
.times(kilograms)
.per(kilograms.cubed())
.per(seconds.squared()),
meters.cubed().times(kilograms).per(kilograms.cubed()).per(seconds.squared()),
"1 m^3 / (kg^2 * s^2)",
);
});
Expand All @@ -291,16 +287,8 @@ describe("Number measures", () => {
});

it("should not format using symbol even if present", () => {
expect(
Measure.of(5, meters.squared())
.withSymbol("m2")
.toString(),
).toBe("5 m^2");
expect(
Measure.dimensionless(0)
.withSymbol("rad")
.toString(),
).toBe("0");
expect(Measure.of(5, meters.squared()).withSymbol("m2").toString()).toBe("5 m^2");
expect(Measure.dimensionless(0).withSymbol("rad").toString()).toBe("0");
});

it("should format measures as other measures with symbols", () => {
Expand Down
5 changes: 2 additions & 3 deletions src/measure/genericMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,5 @@ export interface GenericMeasure<N, U extends Unit> {
* const metersPerSecond = meters.per(seconds);
* type Velocity<N> = LiftMeasure<typeof metersPerSecond, N>;
*/
export type LiftMeasure<M extends GenericMeasure<any, any>, N> = M extends GenericMeasure<any, infer U>
? GenericMeasure<N, U>
: never;
export type LiftMeasure<M extends GenericMeasure<any, any>, N> =
M extends GenericMeasure<any, infer U> ? GenericMeasure<N, U> : never;
Loading

0 comments on commit 21d6afb

Please sign in to comment.