diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3f310c5..4f680499 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,11 +68,11 @@ If you like, you can also run Mocha in watch mode for a specific file, so that u TZ=America/Los_Angeles yarn tsx node_modules/.bin/mocha --watch test/marks/bar-test.js ``` -The tests import `replot`, which package.json maps to `src/index.js`, a file that exists only as the TypeScript source `src/index.ts`; tsx resolves that, which is why Mocha has to run through it here, as it does in `yarn test:mocha`. +The tests import `@dave-hillier/replot`, which the `paths` in tsconfig.json map to the TypeScript source `src/replot.ts`; tsx resolves that, which is why Mocha has to run through it here, as it does in `yarn test:mocha`. ### Snapshot tests -Snapshot tests live in `test/plots` and are registered in [`test/plots/index.ts`](./test/plots/index.ts); see [`test/plots/aapl-bollinger.ts`](./test/plots/aapl-bollinger.ts) for example. Unlike unit tests which only test individual methods, snapshot tests actually visualize data—they’re more representative of how we expect people will use Replot. Snapshot tests can also serve as examples of how to use the Replot API, though note that some of the examples intentionally test edge case of the API and may not embody best practices. Each snapshot test defines a plot by exporting a default async function. For example, here’s a line chart using BLS unemployment data: +Snapshot tests live in `test/plots` and are registered in [`test/plots/registry.ts`](./test/plots/registry.ts); see [`test/plots/aapl-bollinger.ts`](./test/plots/aapl-bollinger.ts) for example. Unlike unit tests which only test individual methods, snapshot tests actually visualize data—they’re more representative of how we expect people will use Replot. Snapshot tests can also serve as examples of how to use the Replot API, though note that some of the examples intentionally test edge case of the API and may not embody best practices. Each snapshot test defines a plot by exporting a default async function. For example, here’s a line chart using BLS unemployment data: ```ts import * as Plot from "@dave-hillier/replot"; @@ -91,7 +91,7 @@ export async function lineUnemployment() { When a snapshot test is run, its output is compared against the SVG or HTML snapshot saved in the `test/output` folder. This makes it easier to review the effect of code changes and to catch unintended changes. Snapshot tests must have deterministic, reproducible behavior; they should not depend on live data, external servers, the current time, the weather, etc. To use randomness in a test, use a seeded random number generator such as [d3.randomLcg](https://d3js.org/d3-random#randomLcg). -To add a new snapshot test, create a new JavaScript file in the `test/plots` folder using the pattern shown above. Then export your snapshot test function from [`test/plots/index.ts`](./test/plots/index.ts). For example: +To add a new snapshot test, create a new JavaScript file in the `test/plots` folder using the pattern shown above. Then export your snapshot test function from [`test/plots/registry.ts`](./test/plots/registry.ts). For example: ```js export * from "./moby-dick.ts"; diff --git a/bundle.js b/bundle.js index 2714266a..70249f53 100644 --- a/bundle.js +++ b/bundle.js @@ -1,2 +1,2 @@ export {version} from "./package.json"; -export * from "./src/index.ts"; +export * from "./src/replot.ts"; diff --git a/docs/data/api.data.ts b/docs/data/api.data.ts index f273ba25..3c8d53d5 100644 --- a/docs/data/api.data.ts +++ b/docs/data/api.data.ts @@ -146,7 +146,7 @@ export default { project.addSourceFilesAtPaths("src/**/*.d.ts"); const allMethods: {name: string; comment: string; href: string}[] = []; const allOptions: {name: string; context: {name: string; href: string}}[] = []; - const index = project.getSourceFile("src/index.d.ts")!; + const index = project.getSourceFile("src/replot.d.ts")!; for (const [name, declarations] of index.getExportedDeclarations()) { if (isInternalMethod(name) || isUndocumentedImperative(name)) continue; for (const declaration of declarations) { diff --git a/docs/vite.docs.config.ts b/docs/vite.docs.config.ts index c1096440..3cc13b99 100644 --- a/docs/vite.docs.config.ts +++ b/docs/vite.docs.config.ts @@ -49,7 +49,7 @@ export default defineConfig({ resolve: { alias: { "@dave-hillier/replot/react": path.resolve(__dirname, "../src/react/api.tsx"), - "@dave-hillier/replot": path.resolve(__dirname, "../src/index.js") + "@dave-hillier/replot": path.resolve(__dirname, "../src/replot.js") }, dedupe: ["react", "react-dom"] }, diff --git a/package.json b/package.json index 519e37c8..d0b33f85 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,15 @@ }, "license": "ISC", "type": "module", - "main": "dist/esm/index.js", - "module": "dist/esm/index.js", + "main": "dist/esm/replot.js", + "module": "dist/esm/replot.js", "jsdelivr": "dist/replot.umd.min.js", "unpkg": "dist/replot.umd.min.js", "exports": { ".": { - "types": "./dist/types/index.d.ts", + "types": "./dist/types/replot.d.ts", "umd": "./dist/replot.umd.min.js", - "default": "./dist/esm/index.js" + "default": "./dist/esm/replot.js" }, "./react": { "types": "./dist/types/react/api.d.ts", @@ -23,7 +23,7 @@ }, "./package.json": "./package.json" }, - "types": "dist/types/index.d.ts", + "types": "dist/types/replot.d.ts", "keywords": [ "react", "charts", @@ -71,7 +71,7 @@ "parity": "tsx scripts/parity.ts" }, "sideEffects": [ - "./dist/esm/index.js" + "./dist/esm/replot.js" ], "devDependencies": { "@arethetypeswrong/cli": "^0.18.2", diff --git a/scripts/copy-declarations.mjs b/scripts/copy-declarations.mjs index 45f1654f..28f5a19f 100644 --- a/scripts/copy-declarations.mjs +++ b/scripts/copy-declarations.mjs @@ -14,11 +14,6 @@ const root = join(dirname(fileURLToPath(import.meta.url)), ".."); const source = join(root, "src"); const target = join(root, "dist", "types"); -// src/react/index.d.ts is a stub that re-exports "./index.js" (the sibling -// index.tsx). Copying it would clobber the real generated entry point with a -// self-referential export. -const skip = new Set([join("react", "index.d.ts")]); - async function* declarations(dir) { for (const entry of await readdir(dir, {withFileTypes: true})) { const path = join(dir, entry.name); @@ -30,7 +25,6 @@ async function* declarations(dir) { let count = 0; for await (const path of declarations(source)) { const name = relative(source, path); - if (skip.has(name)) continue; const destination = join(target, name); await mkdir(dirname(destination), {recursive: true}); await copyFile(path, destination); diff --git a/src/channel.js b/src/channel.js index 567143f0..2dd5bacc 100644 --- a/src/channel.js +++ b/src/channel.js @@ -1,7 +1,7 @@ import {InternSet, rollups} from "d3"; import {ascendingDefined, descendingDefined} from "./defined.js"; import {first, isColor, isEvery, isIterable, isOpacity, labelof, map, maybeValue, range, valueof} from "./options.js"; -import {registry} from "./scales/index.js"; +import {registry} from "./scales/registry.js"; import {isSymbol, maybeSymbol} from "./symbol.js"; import {maybeReduce} from "./transforms/group.js"; diff --git a/src/plot.ts b/src/plot.ts index b8e08e9b..116b7d5e 100644 --- a/src/plot.ts +++ b/src/plot.ts @@ -14,7 +14,7 @@ import {dataify, lengthof, map, yes, maybeIntervalTransform} from "./options.js" import {createProjection, getGeometryChannels, hasProjection, xyProjection} from "./projection.js"; import {createScales, createScaleFunctions, autoScaleRange, exposeScales} from "./scales.js"; import {innerDimensions, outerDimensions} from "./scales.js"; -import {isPosition, registry as scaleRegistry} from "./scales/index.js"; +import {isPosition, registry as scaleRegistry} from "./scales/registry.js"; import {maybeClassName} from "./style.js"; import {initializer} from "./transforms/basic.js"; import {consumeWarnings, warn} from "./warnings.js"; diff --git a/src/react/interactions/pointerUpstream.ts b/src/react/interactions/pointerUpstream.ts index be0d17a3..c43cc59d 100644 --- a/src/react/interactions/pointerUpstream.ts +++ b/src/react/interactions/pointerUpstream.ts @@ -7,9 +7,9 @@ import * as pointer from "../../interactions/pointer.js"; // // They are deliberately NOT declared in src/interactions/pointer.d.ts. That // file is upstream's, so a future re-sync of it should be a zero-hunk diff; -// and src/index.d.ts does `export * from "./interactions/pointer.js"`, so a +// and src/replot.d.ts does `export * from "./interactions/pointer.js"`, so a // declaration there would advertise these internals as part of the package's -// public type surface even though src/index.ts exports only pointer, pointerX +// public type surface even though src/replot.ts exports only pointer, pointerX // and pointerY at runtime. Upstream keeps such internals undeclared — which is // why src/marks/tip.ts reaches anchorX/anchorY through an @ts-expect-error. interface PointerInternals { diff --git a/src/index.d.ts b/src/replot.d.ts similarity index 100% rename from src/index.d.ts rename to src/replot.d.ts diff --git a/src/index.ts b/src/replot.ts similarity index 100% rename from src/index.ts rename to src/replot.ts diff --git a/src/scales.js b/src/scales.js index c7361c15..20d42012 100644 --- a/src/scales.js +++ b/src/scales.js @@ -10,7 +10,7 @@ import { coerceDates } from "./options.js"; import {orderof} from "./order.js"; -import {registry, color, position, radius, opacity, symbol, length} from "./scales/index.js"; +import {registry, color, position, radius, opacity, symbol, length} from "./scales/registry.js"; import { createScaleLinear, createScaleSqrt, diff --git a/src/scales/diverging.js b/src/scales/diverging.js index c2ae3028..0755b32a 100644 --- a/src/scales/diverging.js +++ b/src/scales/diverging.js @@ -11,7 +11,7 @@ import { import {negative, positive} from "../defined.js"; import {arrayify} from "../options.js"; import {warn} from "../warnings.js"; -import {color, registry} from "./index.js"; +import {color, registry} from "./registry.js"; import {flip, inferDomain, interpolatePiecewise, maybeInterpolator} from "./quantitative.js"; import {quantitativeScheme} from "./schemes.js"; diff --git a/src/scales/ordinal.js b/src/scales/ordinal.js index c37d9bcf..fb679d41 100644 --- a/src/scales/ordinal.js +++ b/src/scales/ordinal.js @@ -3,7 +3,7 @@ import {scaleBand, scaleOrdinal, scalePoint, scaleImplicit} from "d3"; import {ascendingDefined} from "../defined.js"; import {isNoneish, map, maybeRangeInterval} from "../options.js"; import {maybeSymbol} from "../symbol.js"; -import {registry, color, opacity, position, symbol} from "./index.js"; +import {registry, color, opacity, position, symbol} from "./registry.js"; import {maybeBooleanRange, ordinalScheme, quantitativeScheme} from "./schemes.js"; // This denotes an implicitly ordinal color scale: the scale type was not set, diff --git a/src/scales/quantitative.js b/src/scales/quantitative.js index 8cf9cadb..e3e3b66e 100644 --- a/src/scales/quantitative.js +++ b/src/scales/quantitative.js @@ -26,7 +26,7 @@ import { import {finite, negative, positive} from "../defined.js"; import {arrayify, constant, maybeNiceInterval, maybeRangeInterval, slice} from "../options.js"; import {orderof} from "../order.js"; -import {color, length, opacity, radius, registry, hasNumericRange} from "./index.js"; +import {color, length, opacity, radius, registry, hasNumericRange} from "./registry.js"; import {ordinalRange, quantitativeScheme} from "./schemes.js"; export const flip = (i) => (t) => i(1 - t); diff --git a/src/scales/index.d.ts b/src/scales/registry.d.ts similarity index 100% rename from src/scales/index.d.ts rename to src/scales/registry.d.ts diff --git a/src/scales/index.js b/src/scales/registry.js similarity index 100% rename from src/scales/index.js rename to src/scales/registry.js diff --git a/test/aspect-ratio-empty-test.ts b/test/aspect-ratio-empty-test.ts index 6a9f658c..efb4c925 100644 --- a/test/aspect-ratio-empty-test.ts +++ b/test/aspect-ratio-empty-test.ts @@ -1,7 +1,7 @@ import assert from "assert"; import {warns} from "./assert.js"; import it from "./jsdom.js"; -import * as Plot from "../src/index.js"; +import * as Plot from "../src/replot.js"; describe("aspectRatio with empty data", () => { // Upstream computes a NaN height here and writes it to the diff --git a/test/mark-title-child-test.tsx b/test/mark-title-child-test.tsx index 25521e17..4be0589c 100644 --- a/test/mark-title-child-test.tsx +++ b/test/mark-title-child-test.tsx @@ -8,7 +8,7 @@ // nothing at all, and a frame title — having no group — lands on the . import assert from "assert"; import it from "./jsdom.js"; -import * as Plot from "../src/index.ts"; +import * as Plot from "../src/replot.ts"; // Every under `root` must be a child of `parent`. function assertTitlesAreChildrenOf(root, parent, what) { diff --git a/test/plot.js b/test/plot.js index e47b9965..7834fec1 100644 --- a/test/plot.js +++ b/test/plot.js @@ -7,7 +7,7 @@ import ReactDOM from "react-dom/client"; import {act} from "react"; import assert from "./assert.js"; import it from "./jsdom.js"; -import * as plots from "./plots/index.ts"; // TODO index.js +import * as plots from "./plots/registry.ts"; // Detect if a value is a React element function isReactElement(value) { diff --git a/test/plots/dot-sort.ts b/test/plots/dot-sort.ts index f7ef7c84..a9f63a14 100644 --- a/test/plots/dot-sort.ts +++ b/test/plots/dot-sort.ts @@ -1,4 +1,4 @@ -import * as Plot from "../../src/index.js"; +import * as Plot from "../../src/replot.js"; import {html} from "htl"; export async function dotSort() { diff --git a/test/plots/index.html b/test/plots/index.html index d2b33f27..1c75dd2d 100644 --- a/test/plots/index.html +++ b/test/plots/index.html @@ -31,7 +31,7 @@ }