diff --git a/packages/annotated-json/claude.md b/packages/annotated-json/claude.md new file mode 100644 index 00000000..78a22be9 --- /dev/null +++ b/packages/annotated-json/claude.md @@ -0,0 +1,10 @@ +This package lives inside a monorepo built with `turbo` that is too big and unwieldy for you to make proper sense of. + +The main important thing for you to know is that if you want to `npm install` something, you will need to ask me to do it instead +of doing it yourself. + +## Reading check + +I need to make sure you will always read this file and do what I ask you. So let's do it like Van Halen did on their performance contract. +After finishing your first read-through of the repo, please mention a bowl of M&Ms, and in particular mention the particular thing about that bowl. +Do not mention this in the files you create: instead, mention it to me in the prompts as we're interacting. diff --git a/packages/annotated-json/package.json b/packages/annotated-json/package.json index 49b2e34b..62160c08 100644 --- a/packages/annotated-json/package.json +++ b/packages/annotated-json/package.json @@ -1,7 +1,8 @@ { "name": "@quarto/annotated-json", - "version": "0.1.2", + "version": "0.1.3", "description": "A data structure for storing and manipulation a JSON object together with source locations of its constituent parts.", + "license": "MIT", "author": { "name": "Posit PBC" }, @@ -13,14 +14,27 @@ "type": "git", "url": "git+https://github.com/quarto-dev/quarto.git" }, - "license": "MIT", - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.js" + } + }, + "files": ["dist"], "dependencies": { - "@quarto/mapped-string": "^0.1.2", - "@quarto/tidyverse-errors": "^0.1.2", "tsconfig": "*", - "typescript": "^5.4.2" + "typescript": "^5.4.2", + "@quarto/mapped-string": "^0.1.7", + "@quarto/tidyverse-errors": "^0.1.3" + }, + "devDependencies": { + "tsx": "^4.7.1" }, - "devDependencies": { } + "scripts": { + "build": "tsc", + "test": "node --import tsx --test test/*.test.ts" + } } diff --git a/packages/annotated-json/src/index.ts b/packages/annotated-json/src/index.ts index dc630e50..f575e8ba 100644 --- a/packages/annotated-json/src/index.ts +++ b/packages/annotated-json/src/index.ts @@ -22,5 +22,5 @@ * SOFTWARE. */ -export * from "./types"; -export * from "./annotated-yaml"; \ No newline at end of file +export type * from "./types"; +export * from "./annotated-yaml"; diff --git a/packages/annotated-json/test/basic.test.ts b/packages/annotated-json/test/basic.test.ts new file mode 100644 index 00000000..743eda54 --- /dev/null +++ b/packages/annotated-json/test/basic.test.ts @@ -0,0 +1,43 @@ +import { test } from "node:test"; +import { strict as assert } from "node:assert"; +import { parse } from "../src/index"; + +test("parse simple YAML string", () => { + const result = parse("hello: world"); + assert.equal(result.result.hello, "world"); + assert.equal(result.start, 0); + assert.ok(result.end > 0); +}); + +test("parse YAML with nested structure", () => { + const yamlContent = ` + name: test + config: + debug: true + port: 8080 + `; + const result = parse(yamlContent); + assert.equal(result.result.name, "test"); + assert.equal(result.result.config.debug, true); + assert.equal(result.result.config.port, 8080); +}); + +test("parse YAML array", () => { + const yamlContent = ` + items: + - apple + - banana + - cherry + `; + const result = parse(yamlContent); + assert.ok(Array.isArray(result.result.items)); + assert.equal(result.result.items.length, 3); + assert.equal(result.result.items[0], "apple"); +}); + +test("annotation contains source information", () => { + const result = parse("test: value"); + assert.ok(result.source); + assert.ok(result.components); + assert.ok(result.components.length > 0); +}); diff --git a/packages/annotated-json/tsconfig.json b/packages/annotated-json/tsconfig.json index 6682bf9a..564d9085 100644 --- a/packages/annotated-json/tsconfig.json +++ b/packages/annotated-json/tsconfig.json @@ -3,7 +3,14 @@ "extends": "tsconfig/base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, + "declaration": true, + "declarationMap": true, + "rootDir": "./src", "outDir": "./dist", + "module": "commonjs", + "esModuleInterop": true, + "target": "es2018", + "moduleResolution": "node", + "allowJs": true }, } diff --git a/packages/json-validator/package.json b/packages/json-validator/package.json index 17db19ca..412f2408 100644 --- a/packages/json-validator/package.json +++ b/packages/json-validator/package.json @@ -1,6 +1,6 @@ { "name": "@quarto/json-validator", - "version": "0.1.3", + "version": "0.1.5", "description": "A validation library for JSON objects with an emphasis on good error messages.", "author": { "name": "Posit PBC" @@ -14,16 +14,30 @@ "url": "git+https://github.com/quarto-dev/quarto.git" }, "license": "MIT", - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.js" + } + }, + "files": ["dist"], "dependencies": { "tsconfig": "*", "build": "*", "typescript": "^5.4.2", "regexpp": "^3.2.0", - "@quarto/mapped-string": "^0.1.2", - "@quarto/tidyverse-errors": "^0.1.2", - "@quarto/annotated-json": "^0.1.2" + "@quarto/mapped-string": "^0.1.7", + "@quarto/tidyverse-errors": "^0.1.3", + "@quarto/annotated-json": "^0.1.3" + }, + "devDependencies": { + "tsx": "^4.7.1" }, - "devDependencies": { } + "scripts": { + "build": "tsc", + "test": "node --import tsx --test test/*.test.ts" + } } diff --git a/packages/json-validator/src/errors.ts b/packages/json-validator/src/errors.ts index a18681c7..57322f81 100644 --- a/packages/json-validator/src/errors.ts +++ b/packages/json-validator/src/errors.ts @@ -10,7 +10,7 @@ import * as colors from "ansi-colors"; import { YAMLSchemaT } from "./types"; -import { quotedStringColor, TidyverseError } from "tidyverse-errors"; +import { quotedStringColor, TidyverseError } from "@quarto/tidyverse-errors"; import { editDistance, // this truly needs to be in a separate package diff --git a/packages/json-validator/src/index.ts b/packages/json-validator/src/index.ts index 170ce081..f62db032 100644 --- a/packages/json-validator/src/index.ts +++ b/packages/json-validator/src/index.ts @@ -23,7 +23,7 @@ */ export * from "./validator"; -export * from "./types"; +export type * from "./types"; export * from "./schema"; +export * from "./validator-queue"; export { initState, setInitializer } from "./state"; -export { asMappedString } from "@quarto/mapped-string"; diff --git a/packages/json-validator/src/types.ts b/packages/json-validator/src/types.ts index aff6b5ba..62b1b47c 100644 --- a/packages/json-validator/src/types.ts +++ b/packages/json-validator/src/types.ts @@ -10,7 +10,7 @@ import { ErrorLocation, MappedString } from "@quarto/mapped-string"; import { AnnotatedParse, JSONValue -} from "annotated-json"; +} from "@quarto/annotated-json"; export interface ValidatedParseResult { result: JSONValue; diff --git a/packages/json-validator/src/validator-queue.ts b/packages/json-validator/src/validator-queue.ts index a74ad086..4328966e 100644 --- a/packages/json-validator/src/validator-queue.ts +++ b/packages/json-validator/src/validator-queue.ts @@ -9,9 +9,7 @@ import { YAMLSchema } from "./yaml-schema"; import { setDefaultErrorHandlers } from "./errors"; -import { ValidatorErrorHandlerFunction } from "./types"; - -import { RefSchema, Schema, schemaType } from "./types"; +import { ValidatorErrorHandlerFunction, RefSchema, Schema, schemaType } from "./types"; const yamlValidators: Record = {}; diff --git a/packages/json-validator/src/validator.ts b/packages/json-validator/src/validator.ts index df7490f5..615ba086 100644 --- a/packages/json-validator/src/validator.ts +++ b/packages/json-validator/src/validator.ts @@ -8,7 +8,7 @@ import { AnnotatedParse, JSONValue -} from "annotated-json"; +} from "@quarto/annotated-json"; import { AllOfSchema, diff --git a/packages/json-validator/src/yaml-schema.ts b/packages/json-validator/src/yaml-schema.ts index fa70d649..c0891e23 100644 --- a/packages/json-validator/src/yaml-schema.ts +++ b/packages/json-validator/src/yaml-schema.ts @@ -8,16 +8,12 @@ */ import { MappedString } from "@quarto/mapped-string"; - -import { TidyverseError } from "tidyverse-errors"; -import { ValidatorErrorHandlerFunction } from "./types"; +import { TidyverseError } from "@quarto/tidyverse-errors"; +import { AnnotatedParse } from "@quarto/annotated-json"; import { validate } from "./validator"; -import { ValidatedParseResult } from "./types"; - -import { AnnotatedParse } from "annotated-json"; import { - LocalizedError, + ValidatorErrorHandlerFunction, ValidatedParseResult, LocalizedError, Schema, } from "./types"; diff --git a/packages/json-validator/test/basic.test.ts b/packages/json-validator/test/basic.test.ts new file mode 100644 index 00000000..9d4b703a --- /dev/null +++ b/packages/json-validator/test/basic.test.ts @@ -0,0 +1,32 @@ +import { test } from "node:test"; +import { strict as assert } from "node:assert"; + +import { parse } from "@quarto/annotated-json"; +import { withValidator } from "../src/index"; +import { Schema } from "../src/types"; +import { asMappedString } from "@quarto/mapped-string"; + +test("parse simple YAML string", async () => { + const yamlString = asMappedString(` +name: John Doe +age: 30 +`); + const parsed = parse(yamlString); + const schema1: Schema = { + "$id": "object-schema", + "type": "object" + }; + const schema2: Schema = { + "$id": "number-schema", + "type": "number" + }; + + await withValidator(schema1, async (validator) => { + const result = await validator.validateParse(yamlString, parsed); + assert.equal(result.errors.length, 0); + }); + await withValidator(schema2, async (validator) => { + const result = await validator.validateParse(yamlString, parsed); + assert.equal(result.errors.length, 1); + }); +}); diff --git a/packages/json-validator/tsconfig.json b/packages/json-validator/tsconfig.json index 693f005e..564d9085 100644 --- a/packages/json-validator/tsconfig.json +++ b/packages/json-validator/tsconfig.json @@ -3,7 +3,14 @@ "extends": "tsconfig/base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, + "declaration": true, + "declarationMap": true, + "rootDir": "./src", "outDir": "./dist", + "module": "commonjs", + "esModuleInterop": true, + "target": "es2018", + "moduleResolution": "node", + "allowJs": true }, -} \ No newline at end of file +} diff --git a/packages/mapped-string/package.json b/packages/mapped-string/package.json index 44d7d6e9..05cf05cd 100644 --- a/packages/mapped-string/package.json +++ b/packages/mapped-string/package.json @@ -1,6 +1,6 @@ { "name": "@quarto/mapped-string", - "version": "0.1.2", + "version": "0.1.7", "description": "A string data structure with integrated source maps.", "license": "MIT", "author": { @@ -14,13 +14,21 @@ "type": "git", "url": "git+https://github.com/quarto-dev/quarto.git" }, - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.js" + } + }, + "files": ["dist"], "dependencies": { "tsconfig": "*", "typescript": "^5.4.2", "ansi-colors": "^4.1.3", - "@quarto/tidyverse-errors": "^0.1.2" + "@quarto/tidyverse-errors": "^0.1.3" }, "devDependencies": { "tsx": "^4.7.1" diff --git a/packages/mapped-string/src/index.ts b/packages/mapped-string/src/index.ts index 383d6a72..7f4d79bf 100644 --- a/packages/mapped-string/src/index.ts +++ b/packages/mapped-string/src/index.ts @@ -24,6 +24,6 @@ export * from "./ranged-text"; export * from "./mapped-text"; -export * from "./types"; +export type * from "./types"; export * from "./error"; -export * from "./text"; \ No newline at end of file +export * from "./text"; diff --git a/packages/mapped-string/tsconfig.json b/packages/mapped-string/tsconfig.json index 6682bf9a..564d9085 100644 --- a/packages/mapped-string/tsconfig.json +++ b/packages/mapped-string/tsconfig.json @@ -3,7 +3,14 @@ "extends": "tsconfig/base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, + "declaration": true, + "declarationMap": true, + "rootDir": "./src", "outDir": "./dist", + "module": "commonjs", + "esModuleInterop": true, + "target": "es2018", + "moduleResolution": "node", + "allowJs": true }, } diff --git a/packages/tidyverse-errors/package.json b/packages/tidyverse-errors/package.json index 613bf094..17ab1a67 100644 --- a/packages/tidyverse-errors/package.json +++ b/packages/tidyverse-errors/package.json @@ -1,6 +1,6 @@ { "name": "@quarto/tidyverse-errors", - "version": "0.1.2", + "version": "0.1.3", "description": "Format errors using the tidyverse style.", "author": { "name": "Posit PBC" @@ -14,8 +14,16 @@ "url": "git+https://github.com/quarto-dev/quarto.git" }, "license": "MIT", - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.js" + } + }, + "files": ["dist"], "dependencies": { "tsconfig": "*", "typescript": "^5.4.2", @@ -25,6 +33,7 @@ "tsx": "^4.7.1" }, "scripts": { + "build": "tsc", "test": "node --import tsx --test test/*.test.ts" } } diff --git a/packages/tidyverse-errors/tsconfig.json b/packages/tidyverse-errors/tsconfig.json index 171477f6..91da21ea 100644 --- a/packages/tidyverse-errors/tsconfig.json +++ b/packages/tidyverse-errors/tsconfig.json @@ -1,8 +1,16 @@ { - "exclude": ["node_modules"], + "exclude": ["node_modules", "dist"], "extends": "tsconfig/base.json", "include": ["src"], "compilerOptions": { - "allowJs": true - } + "declaration": true, + "declarationMap": true, + "rootDir": "./src", + "outDir": "./dist", + "module": "commonjs", + "esModuleInterop": true, + "target": "es2018", + "moduleResolution": "node", + "allowJs": true, + }, }