Add the versioned plugin SDK package and its release script
The new package packages/plugin-sdk (@runestone/plugin-sdk) is the one source of the public plugin types. It contains PluginApi and its members, the manifest type, API_VERSION, and feature checks (hasFeature, requireFeature, requireFeatures, missingFeatures). It also contains the action icons and the tooltip helper as DOM functions, because RuneStone has no API for them. Menus stay host-drawn through api.ui.showActionMenu, so the SDK contains only the menu types. The SDK uses the Apache License 2.0. The host imports the SDK with relative paths in src/lib/plugins/sdk.ts, src/lib/ui/actionIcons.ts, and src/lib/ui/tooltip.ts. The completion, Git, background, and contribution contract files export the SDK types. The menu files keep their types, because the Terminal plugin keeps copies of them. A unit test makes sure that those types and the SDK types are the same. The menu inventory now scans the SDK source. pnpm sdk:build compiles the SDK to dist/. pnpm release:sdk --version <v> builds it, then commits and tags v<v> in a local clone of the public repository. It never pushes, and it prints the push commands. It stops before a change in these conditions: - The clone is missing, has changes, or is not on a branch. - The tag exists, or the version is not greater than the current version. - The package has no LICENSE file, or the SDK source has changes that are not committed. A failed attempt restores the version and the clone. pnpm check type checks the SDK and the example plugin. The example plugin now has JSDoc types from the SDK. pnpm test covers the feature checks, the host and SDK parity, and the release script with temporary Git repositories. The plugin development, release, development, and completion guides describe the SDK.
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, mkdir, readFile, writeFile, copyFile, rm, access, readdir } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { clonePath, describePlan, git, parseArguments, planSdkRelease, releasePackageJson, runSdkRelease } from "../../../scripts/releaseSdk.mjs";
|
||||
|
||||
// These tests use temporary Git repositories. They need no network and never push.
|
||||
const repository = path.resolve(".");
|
||||
const sdk = "packages/plugin-sdk";
|
||||
const exists = (file: string) => access(file).then(() => true, () => false);
|
||||
const identity = async (folder: string) => {
|
||||
await git(folder, ["config", "user.name", "SDK test"]);
|
||||
await git(folder, ["config", "user.email", "[email protected]"]);
|
||||
};
|
||||
|
||||
type Setup = { base: string; root: string; clone: string; remote: string; env: Record<string, string> };
|
||||
|
||||
// A host repository with the SDK package files, a clone of the public repository, and a bare remote for that clone.
|
||||
async function fixture(options: { empty?: boolean; origin?: boolean } = {}): Promise<Setup> {
|
||||
const base = await mkdtemp(path.join(tmpdir(), "runestone-sdk-release-"));
|
||||
const root = path.join(base, "RuneStone");
|
||||
await mkdir(path.join(root, sdk), { recursive: true });
|
||||
for (const file of ["package.json", "README.md", "LICENSE", "NOTICE"]) await copyFile(path.join(repository, sdk, file), path.join(root, sdk, file));
|
||||
const source = JSON.parse(await readFile(path.join(root, sdk, "package.json"), "utf8"));
|
||||
await writeFile(path.join(root, sdk, "package.json"), JSON.stringify({ ...source, version: "0.0.0", scripts: { build: "tsc" }, devDependencies: { typescript: "6" } }, null, 2) + "\n");
|
||||
await writeFile(path.join(root, ".gitignore"), "dist/\n");
|
||||
await git(root, ["init", "-q", "-b", "master"]);
|
||||
await identity(root);
|
||||
await git(root, ["add", "-A"]);
|
||||
await git(root, ["commit", "-q", "-m", "host"]);
|
||||
|
||||
const remote = path.join(base, "remote.git");
|
||||
await git(base, ["init", "-q", "--bare", remote]);
|
||||
const clone = path.join(base, "RuneStone_Plugin_SDK");
|
||||
await mkdir(clone);
|
||||
await git(clone, ["init", "-q", "-b", "main"]);
|
||||
await identity(clone);
|
||||
if (options.origin !== false) await git(clone, ["remote", "add", "origin", remote]);
|
||||
if (!options.empty) {
|
||||
await writeFile(path.join(clone, ".gitignore"), "dist/\nnode_modules/\n");
|
||||
await git(clone, ["add", "-A"]);
|
||||
await git(clone, ["commit", "-q", "-m", "Start"]);
|
||||
}
|
||||
return { base, root, clone, remote, env: { RUNESTONE_PLUGIN_REPOS: base } };
|
||||
}
|
||||
|
||||
async function withFixture(options: { empty?: boolean; origin?: boolean }, body: (setup: Setup) => Promise<void>) {
|
||||
const setup = await fixture(options);
|
||||
try { await body(setup); } finally { await rm(setup.base, { recursive: true, force: true }); }
|
||||
}
|
||||
|
||||
// A build that writes a small dist/ folder in place of the TypeScript compiler.
|
||||
const fakeBuild = async (root: string) => {
|
||||
const dist = path.join(root, sdk, "dist");
|
||||
await mkdir(path.join(dist, "nested"), { recursive: true });
|
||||
await writeFile(path.join(dist, "index.js"), "export const API_VERSION = 1;\n");
|
||||
await writeFile(path.join(dist, "index.d.ts"), "export declare const API_VERSION = 1;\n");
|
||||
await writeFile(path.join(dist, "nested", "extra.js"), "export {};\n");
|
||||
return dist;
|
||||
};
|
||||
const failingBuild = async () => { throw Error("The compiler failed."); };
|
||||
|
||||
async function state(setup: Setup) {
|
||||
return {
|
||||
source: await readFile(path.join(setup.root, sdk, "package.json"), "utf8"),
|
||||
head: await git(setup.clone, ["rev-parse", "--verify", "--quiet", "HEAD"]).catch(() => null),
|
||||
status: await git(setup.clone, ["status", "--porcelain", "--untracked-files=all"]),
|
||||
tags: await git(setup.clone, ["tag", "--list"]),
|
||||
files: (await readdir(setup.clone)).sort(),
|
||||
};
|
||||
}
|
||||
const quiet = async <T>(work: () => Promise<T>) => {
|
||||
const error = console.error;
|
||||
console.error = () => {};
|
||||
try { return await work(); } finally { console.error = error; }
|
||||
};
|
||||
|
||||
test("the SDK release script reads --version and --dry-run", () => {
|
||||
assert.deepEqual(parseArguments(["--version", "0.1.0"]), { version: "0.1.0", dryRun: false });
|
||||
assert.deepEqual(parseArguments(["--dry-run", "--version", "0.1.0a"]), { version: "0.1.0a", dryRun: true });
|
||||
for (const args of [[], ["--dry-run"], ["--version"], ["0.1.0"], ["--version", "0.1.0", "--version", "0.1.1"], ["--push"]]) assert.throws(() => parseArguments(args));
|
||||
});
|
||||
|
||||
test("the clone path comes from RUNESTONE_SDK_REPO, then RUNESTONE_PLUGIN_REPOS, then the parent folder", () => {
|
||||
const root = path.resolve("/work/RuneStone");
|
||||
assert.equal(clonePath(root, { RUNESTONE_SDK_REPO: "/elsewhere/sdk", RUNESTONE_PLUGIN_REPOS: "/plugins" }), path.resolve("/elsewhere/sdk"));
|
||||
assert.equal(clonePath(root, { RUNESTONE_PLUGIN_REPOS: "/plugins" }), path.join(path.resolve("/plugins"), "RuneStone_Plugin_SDK"));
|
||||
assert.equal(clonePath(root, {}), path.join(path.resolve("/work"), "RuneStone_Plugin_SDK"));
|
||||
});
|
||||
|
||||
test("the release package.json has the version and no build scripts or development dependencies", () => {
|
||||
const source = { name: "@runestone/plugin-sdk", version: "0.0.0", types: "./dist/index.d.ts", exports: {}, files: ["dist"], license: "Apache-2.0", scripts: { build: "tsc" }, devDependencies: { typescript: "6" } };
|
||||
assert.deepEqual(releasePackageJson(source, "0.1.0"), { name: "@runestone/plugin-sdk", version: "0.1.0", types: "./dist/index.d.ts", exports: {}, files: ["dist"], license: "Apache-2.0" });
|
||||
assert.throws(() => releasePackageJson({ ...source, license: undefined }, "0.1.0"), /license/);
|
||||
});
|
||||
|
||||
test("a dry run plans the release, prints the push commands, and changes no file", () => withFixture({}, async setup => {
|
||||
const before = await state(setup);
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
const text = describePlan(plan);
|
||||
assert.match(text, /SDK version: 0\.1\.0 \(current 0\.0\.0\)/);
|
||||
assert.match(text, /Replace dist, package\.json, README\.md, LICENSE, NOTICE in the clone/);
|
||||
assert.match(text, /create the tag v0\.1\.0/);
|
||||
assert.deepEqual(plan.pushCommands, [`git -C "${setup.clone}" push origin main`, `git -C "${setup.clone}" push origin v0.1.0`]);
|
||||
assert.equal(plan.packageJson.version, "0.1.0");
|
||||
assert.equal(plan.packageJson.scripts, undefined);
|
||||
assert.equal(plan.packageJson.devDependencies, undefined);
|
||||
assert.deepEqual(await state(setup), before);
|
||||
}));
|
||||
|
||||
test("a clone without an origin remote gets the command that adds it", () => withFixture({ origin: false }, async setup => {
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
assert.match(plan.pushCommands[0], /remote add origin https:\/\/git\.knottywyvern\.com\/kwyvern\/RuneStone_Plugin_SDK\.git$/);
|
||||
}));
|
||||
|
||||
test("the release refuses a missing, unrelated, dirty, or detached clone", () => withFixture({}, async setup => {
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", { RUNESTONE_SDK_REPO: path.join(setup.base, "missing") }), /clone is missing/);
|
||||
const plain = path.join(setup.root, sdk);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", { RUNESTONE_SDK_REPO: plain }), /not the root of a Git repository/);
|
||||
await writeFile(path.join(setup.clone, "notes.txt"), "draft");
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /clone has changes/);
|
||||
await rm(path.join(setup.clone, "notes.txt"));
|
||||
await git(setup.clone, ["checkout", "-q", "--detach"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /not on a branch/);
|
||||
}));
|
||||
|
||||
test("the release never replaces a tag and never goes back to an earlier version", () => withFixture({}, async setup => {
|
||||
await git(setup.clone, ["tag", "v0.1.0"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /The tag v0\.1\.0 exists/);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.0.0", setup.env), /greater than the current version 0\.0\.0/);
|
||||
await assert.rejects(planSdkRelease(setup.root, "1.0", setup.env), /release version/);
|
||||
await writeFile(path.join(setup.clone, "package.json"), JSON.stringify({ version: "0.2.0" }));
|
||||
await git(setup.clone, ["add", "-A"]);
|
||||
await git(setup.clone, ["commit", "-q", "-m", "Earlier release"]);
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.1", setup.env), /greater than the version 0\.2\.0 in the clone/);
|
||||
}));
|
||||
|
||||
test("the release refuses a package without a license file or with source changes that are not committed", () => withFixture({}, async setup => {
|
||||
await rm(path.join(setup.root, sdk, "LICENSE"));
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /no LICENSE file/);
|
||||
await git(setup.root, ["checkout", "-q", "--", sdk]);
|
||||
await writeFile(path.join(setup.root, sdk, "README.md"), "changed");
|
||||
await assert.rejects(planSdkRelease(setup.root, "0.1.0", setup.env), /not committed/);
|
||||
}));
|
||||
|
||||
test("a completed release commits and tags in the clone, sets the source version, and pushes nothing", () => withFixture({}, async setup => {
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
const result = await runSdkRelease(plan, fakeBuild);
|
||||
assert.equal(result.tag, "v0.1.0");
|
||||
assert.equal(await git(setup.clone, ["status", "--porcelain", "--untracked-files=all"]), "");
|
||||
assert.equal(await git(setup.clone, ["cat-file", "-t", "v0.1.0"]), "tag");
|
||||
assert.equal(await git(setup.clone, ["rev-parse", "v0.1.0^{commit}"]), result.commit);
|
||||
const tracked = (await git(setup.clone, ["ls-files"])).split("\n").sort();
|
||||
assert.deepEqual(tracked, [".gitignore", "LICENSE", "NOTICE", "README.md", "dist/index.d.ts", "dist/index.js", "dist/nested/extra.js", "package.json"]);
|
||||
const published = JSON.parse(await readFile(path.join(setup.clone, "package.json"), "utf8"));
|
||||
assert.equal(published.version, "0.1.0");
|
||||
assert.equal(published.license, "Apache-2.0");
|
||||
assert.equal(published.scripts, undefined);
|
||||
assert.equal(await readFile(path.join(setup.clone, "LICENSE"), "utf8"), await readFile(path.join(setup.root, sdk, "LICENSE"), "utf8"));
|
||||
assert.match(await git(setup.clone, ["log", "-1", "--format=%B"]), new RegExp(`^Release @runestone/plugin-sdk 0\\.1\\.0\\n\\nBuilt from RuneStone ${plan.hostCommit}\\.`));
|
||||
assert.equal(JSON.parse(await readFile(path.join(setup.root, sdk, "package.json"), "utf8")).version, "0.1.0");
|
||||
assert.equal(await git(setup.remote, ["for-each-ref"]), "", "The release must not push.");
|
||||
|
||||
// The next release replaces dist/ and removes files that the new build does not contain.
|
||||
await git(setup.root, ["commit", "-q", "-am", "Record 0.1.0"]);
|
||||
const next = await planSdkRelease(setup.root, "0.1.1", setup.env);
|
||||
await runSdkRelease(next, async root => { const dist = await fakeBuild(root); await rm(path.join(dist, "nested"), { recursive: true }); return dist; });
|
||||
assert.equal(await exists(path.join(setup.clone, "dist/nested/extra.js")), false);
|
||||
assert.deepEqual((await git(setup.clone, ["tag", "--list"])).split("\n"), ["v0.1.0", "v0.1.1"]);
|
||||
}));
|
||||
|
||||
test("a failed build restores the version and leaves the clone unchanged", () => withFixture({}, async setup => {
|
||||
const before = await state(setup);
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
await quiet(() => assert.rejects(runSdkRelease(plan, failingBuild), /compiler failed/));
|
||||
assert.deepEqual(await state(setup), before);
|
||||
}));
|
||||
|
||||
test("a failed commit restores the clone, also in a clone without commits", async () => {
|
||||
for (const empty of [false, true]) {
|
||||
await withFixture({ empty }, async setup => {
|
||||
const before = await state(setup);
|
||||
await writeFile(path.join(setup.clone, ".git/hooks/pre-commit"), "#!/bin/sh\nexit 1\n");
|
||||
const plan = await planSdkRelease(setup.root, "0.1.0", setup.env);
|
||||
assert.equal(plan.head, empty ? null : before.head);
|
||||
await quiet(() => assert.rejects(runSdkRelease(plan, fakeBuild), /git commit/));
|
||||
assert.deepEqual(await state(setup), before);
|
||||
await rm(path.join(setup.clone, ".git/hooks/pre-commit"));
|
||||
if (empty) {
|
||||
await runSdkRelease(await planSdkRelease(setup.root, "0.1.0", setup.env), fakeBuild);
|
||||
assert.equal(await git(setup.clone, ["rev-list", "--count", "HEAD"]), "1");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile, access } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { API_VERSION, describeFeature, hasFeature, missingFeatures, MissingFeatureError, pluginFeatures, requireFeature, requireFeatures, type PluginApi } from "../../../packages/plugin-sdk/src/index.ts";
|
||||
import * as sdkIcons from "../../../packages/plugin-sdk/src/icons.ts";
|
||||
import * as sdkTooltip from "../../../packages/plugin-sdk/src/tooltip.ts";
|
||||
import * as hostIcons from "../../../src/lib/ui/actionIcons.ts";
|
||||
import * as hostTooltip from "../../../src/lib/ui/tooltip.ts";
|
||||
import { ExternalSession, type SessionServices } from "../../../src/lib/plugins/externalSession.ts";
|
||||
import { ContributionRegistry } from "../../../src/lib/plugins/registry.ts";
|
||||
import { ServiceHub } from "../../../src/lib/plugins/services.ts";
|
||||
import { declarationImports } from "../../../scripts/buildSdk.mjs";
|
||||
import type { ActionMenuItem as HostMenuItem } from "../../../src/lib/ui/actionMenu.ts";
|
||||
import type { MenuOptions as HostMenuOptions } from "../../../src/lib/ui/managedActionMenu.ts";
|
||||
import type { ActionMenuItem, ActionMenuOptions } from "../../../packages/plugin-sdk/src/index.ts";
|
||||
|
||||
// The host menu files must match the copies in the Terminal plugin (scripts/menuSurfaceAudit.mjs), so they keep
|
||||
// their own menu types. `pnpm check` fails when those types and the SDK types differ.
|
||||
type Same<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
|
||||
const sameMenuTypes: [Same<HostMenuItem, ActionMenuItem>, Same<HostMenuOptions, ActionMenuOptions>] = [true, true];
|
||||
|
||||
const base: SessionServices = {
|
||||
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
||||
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
||||
};
|
||||
|
||||
async function hostApi(services: Partial<SessionServices>, views = false) {
|
||||
let api!: PluginApi;
|
||||
const session = views
|
||||
? new ExternalSession("org.test.sdk", { ...base, ...services }, () => {}, () => {}, new ContributionRegistry(), async () => {}, async () => "", () => {}, () => {}, () => {})
|
||||
: new ExternalSession("org.test.sdk", { ...base, ...services }, () => {}, () => {}, new ContributionRegistry());
|
||||
await session.start({ activate(value) { api = value; } });
|
||||
return { api, session };
|
||||
}
|
||||
|
||||
test("feature checks find optional members, and missing members give an update message", () => {
|
||||
const read = async () => new Uint8Array([1]);
|
||||
const api = { workspace: { readBytes: read }, git: { status: async () => ({}) } } as unknown as PluginApi;
|
||||
assert.equal(hasFeature(api, "workspace.readBytes"), true);
|
||||
assert.equal(hasFeature(api, "git"), true);
|
||||
assert.equal(hasFeature(api, "git.push"), false);
|
||||
assert.equal(hasFeature(api, "pty"), false);
|
||||
assert.deepEqual(missingFeatures(api, ["pty", "workspace.readBytes", "settings.subscribe"]), ["pty", "settings.subscribe"]);
|
||||
assert.equal(requireFeature(api, "git"), (api as unknown as { git: unknown }).git);
|
||||
assert.throws(() => requireFeature(api, "pty"), (error: unknown) => error instanceof MissingFeatureError
|
||||
&& error.name === "MissingFeatureError" && error.features.length === 1 && error.features[0] === "pty"
|
||||
&& error.message === "This plugin needs the terminal API (api.pty). Update RuneStone to a version that has this feature.");
|
||||
assert.throws(() => requireFeatures(api, ["pty", "files", "workspace.readBytes"]), {
|
||||
message: "This plugin needs the terminal API (api.pty) and the folder grant API (api.files). Update RuneStone to a version that has these features.",
|
||||
});
|
||||
assert.doesNotThrow(() => requireFeatures(api, ["git", "workspace.readBytes"]));
|
||||
assert.throws(() => hasFeature(api, "workspace.read" as never), TypeError);
|
||||
assert.equal(describeFeature("ui.showActionMenu"), "the shared action menu (api.ui.showActionMenu)");
|
||||
assert.equal(API_VERSION, 1);
|
||||
});
|
||||
|
||||
test("a required function stays bound to its parent object", async () => {
|
||||
const workspace = { prefix: "ws:", async readOptional(this: { prefix: string }, file: string) { return this.prefix + file; } };
|
||||
const api = { workspace } as unknown as PluginApi;
|
||||
const readOptional = requireFeature(api, "workspace.readOptional");
|
||||
assert.equal(await readOptional("a.md"), "ws:a.md");
|
||||
});
|
||||
|
||||
test("the current host gives every SDK feature when all services are present", async () => {
|
||||
const pty = { open: async () => {}, write: async () => {}, resize: async () => {}, close: async () => {}, profiles: async () => [], openWindow: async () => {}, dictation: async () => {} };
|
||||
const files = { chooseFolder: async () => null, pictureFolder: async () => ({ id: "g", path: "p", name: "n" }), grants: async () => [], revoke: async () => false, list: async () => [], readBytes: async () => new Uint8Array(), readSidecar: async () => null, writeSidecar: async () => {} };
|
||||
const git = { status: async () => ({ available: true, repository: true, branch: null, changes: [] }), diff: async () => "", stage: async () => {}, unstage: async () => {}, commit: async () => {}, push: async () => {}, pull: async () => {}, graph: async () => ({ commits: [] }), commitDetails: async () => ({ id: "", parents: [], author: "", date: "", message: "", files: [] }), commitDiff: async () => "", blame: async () => null };
|
||||
const backgrounds = { chooseFolder: async () => null, list: async () => [], read: async () => new Uint8Array() };
|
||||
const { api, session } = await hostApi({
|
||||
pty, files, git, backgrounds, serviceHub: new ServiceHub(), openFile: async () => {}, completionTransport: async () => {},
|
||||
workspace: { ...base.workspace, listMarkdown: async () => [], readMany: async () => [], readBytes: async () => new Uint8Array(), readOptional: async () => null, create: async () => {}, subscribe: () => () => {} },
|
||||
settings: { ...base.settings, subscribe: () => () => {} },
|
||||
}, true);
|
||||
assert.deepEqual(missingFeatures(api, pluginFeatures), []);
|
||||
await session.stop();
|
||||
});
|
||||
|
||||
test("the host without optional services lacks only the features that depend on them", async () => {
|
||||
const { api, session } = await hostApi({});
|
||||
assert.deepEqual(missingFeatures(api, pluginFeatures).sort(), [
|
||||
"backgrounds", "closeView", "completion.transport", "files", "git", "git.commitDetails", "git.commitDiff", "git.graph", "git.pull", "git.push",
|
||||
"openFile", "pty", "renameDocument", "replaceDocumentWithView", "replaceView", "settings.subscribe",
|
||||
"workspace.create", "workspace.listMarkdown", "workspace.readBytes", "workspace.readMany", "workspace.readOptional", "workspace.subscribe",
|
||||
]);
|
||||
await session.stop();
|
||||
});
|
||||
|
||||
test("the host uses the SDK icons and tooltip, so plugins get the same artwork and behavior", () => {
|
||||
assert.equal(hostIcons.actionIcons, sdkIcons.actionIcons);
|
||||
assert.equal(hostIcons.actionIcon, sdkIcons.actionIcon);
|
||||
assert.equal(hostTooltip.attachTooltip, sdkTooltip.attachTooltip);
|
||||
for (const [name, markup] of Object.entries(sdkIcons.actionIcons)) assert.match(markup, /^<(path|circle|rect|ellipse)\b/, name);
|
||||
});
|
||||
|
||||
test("the host menu types are the SDK menu types", () => {
|
||||
assert.deepEqual(sameMenuTypes, [true, true]);
|
||||
});
|
||||
|
||||
test("the SDK build gives declaration imports with .js paths", () => {
|
||||
assert.equal(declarationImports('export type * from "./api.ts";\nimport type { A } from \'../b.ts\';\ntype C = import("./c.ts").C;\nimport x from "node:fs";'),
|
||||
'export type * from "./api.js";\nimport type { A } from \'../b.js\';\ntype C = import("./c.js").C;\nimport x from "node:fs";');
|
||||
});
|
||||
|
||||
test("each SDK export has a source module, and the package is not for npm", async () => {
|
||||
const folder = path.resolve("packages/plugin-sdk");
|
||||
const manifest = JSON.parse(await readFile(path.join(folder, "package.json"), "utf8"));
|
||||
assert.equal(manifest.name, "@runestone/plugin-sdk");
|
||||
assert.equal(manifest.private, true);
|
||||
assert.equal(manifest.license, "Apache-2.0");
|
||||
assert.equal(manifest.dependencies, undefined);
|
||||
assert.deepEqual(manifest.files, ["dist", "README.md", "LICENSE", "NOTICE"]);
|
||||
for (const file of ["README.md", "LICENSE", "NOTICE"]) await access(path.join(folder, file));
|
||||
for (const [entry, target] of Object.entries(manifest.exports as Record<string, string | { types: string; default: string }>)) {
|
||||
if (typeof target === "string") continue;
|
||||
assert.equal(target.types.replace(/\.d\.ts$/, ""), target.default.replace(/\.js$/, ""), entry);
|
||||
await access(path.join(folder, target.default.replace(/^\.\/dist\//, "src/").replace(/\.js$/, ".ts")));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user