Skip to content

Commit

Permalink
refactor(kumascript): convert to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Apr 20, 2023
1 parent b2c1140 commit cfbe861
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build/extract-specifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { packageBCD } from "./resolve-bcd.js";
import bcd from "@mdn/browser-compat-data/types";
import { Specification } from "../libs/types/document.js";
import specs from "web-specs/index.json" assert { type: "json" };
import web from "../kumascript/src/api/web.js";
import web from "@yari-internal/kumascript/src/api/web.js";

export function extractSpecifications(
query: string | undefined,
Expand Down
6 changes: 3 additions & 3 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
MacroInvocationError,
MacroLiveSampleError,
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";
} from "@yari-internal/kumascript/src/errors.js";

import { Doc } from "../libs/types/document.js";
import { Document, Image, execGit } from "../content/index.js";
import { CONTENT_ROOT, REPOSITORY_URLS } from "../libs/env/index.js";
import * as kumascript from "../kumascript/index.js";
import * as kumascript from "@yari-internal/kumascript/index.js";

import { FLAW_LEVELS } from "../libs/constants/index.js";
import { extractSections } from "./extract-sections.js";
Expand All @@ -29,7 +29,7 @@ import { syntaxHighlight } from "./syntax-highlight.js";
import { formatNotecards } from "./format-notecards.js";
import buildOptions from "./build-options.js";
import LANGUAGES_RAW from "../libs/languages/index.js";
import { safeDecodeURIComponent } from "../kumascript/src/api/util.js";
import { safeDecodeURIComponent } from "@yari-internal/kumascript/src/api/util.js";
import { wrapTables } from "./wrap-tables.js";
export { default as SearchIndex } from "./search-index.js";
export { gather as gatherGitHistory } from "./git-history.js";
Expand Down
3 changes: 2 additions & 1 deletion content/translation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Parser from "../kumascript/src/parser.js";
// eslint-disable-next-line n/no-extraneous-import
import * as Parser from "@yari-internal/kumascript/src/parser.js";

function* fastKSParser(s: string) {
for (const match of s.matchAll(
Expand Down
16 changes: 16 additions & 0 deletions kumascript/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extensionsToTreatAsEsm": [".ts", ".tsx"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"preset": "ts-jest/presets/default-esm",
"transform": {
"\\.tsx?$": [
"ts-jest",
{
"babelConfig": true,
"useESM": true
}
]
}
}
27 changes: 27 additions & 0 deletions kumascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@yari-internal/kumascript",
"version": "0.0.1",
"private": true,
"license": "MPL-2.0",
"type": "module",
"scripts": {
"jest": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"test": "npm run jest kumascript -- --env=node"
},
"dependencies": {
"@webref/css": "^6.5.2",
"cheerio": "^1.0.0-rc.12",
"css-tree": "^2.3.1",
"ejs": "^3.1.9",
"got": "^12.6.0",
"lru-cache": "^7.18.3",
"sanitize-filename": "^1.6.3"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"html-validate": "^7.15.1",
"jest": "^29.5.0",
"jsdom": "^21.1.1",
"ts-jest": "^29.1.0"
}
}
30 changes: 30 additions & 0 deletions kumascript/src/parser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface Position {
offset: number;
line: number;
column: number;
}
interface Location {
start: Position;
end: Position;
}

interface TextToken {
type: "TEXT";
chars: string;
}
interface MacroToken {
type: "MACRO";
name: string;
args: unknown[];
location: Location;
}

type Token = TextToken | MacroToken;

export const SyntaxError: (
message: string,
expected: string | null,
found: string | null,
location: Location | null
) => void;
export const parse: (input: string, options?: unknown) => Token[];
37 changes: 36 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"workspaces": [
"./client",
"./client/pwa",
"./kumascript",
"./libs/*"
],
"scripts": {
Expand Down Expand Up @@ -50,7 +51,7 @@
"test:content": "npm run jest content",
"test:developing": "cross-env CONTENT_ROOT=mdn/content/files TESTING_DEVELOPING=true playwright test developing",
"test:headless": "playwright test headless",
"test:kumascript": "npm run jest kumascript -- --env=node",
"test:kumascript": "npm --prefix kumascript test",
"test:prepare": "npm run build:prepare && npm run build && npm run start:static-server",
"test:testing": "npm run jest -- --rootDir testing",
"tool": "ts-node tool/cli.ts",
Expand Down
4 changes: 2 additions & 2 deletions tool/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { runOptimizeClientBuild } from "./optimize-client-build.js";
import { runBuildRobotsTxt } from "./build-robots-txt.js";
import { syncAllTranslatedContent } from "./sync-translated-content.js";
import { macroUsageReport } from "./macro-usage-report.js";
import * as kumascript from "../kumascript/index.js";
import * as kumascript from "@yari-internal/kumascript/index.js";
import {
MacroInvocationError,
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";
} from "@yari-internal/kumascript/src/errors.js";
import { whatsdeployed } from "./whatsdeployed.js";

const { program } = caporal;
Expand Down

0 comments on commit cfbe861

Please sign in to comment.