obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Reporter } from "../cli/reporter.js";
|
|
2
|
+
import { type RunGit } from "../release/git.js";
|
|
3
|
+
/** What the upgrade does to the world. Injected, so a test never touches the network or runs npm. */
|
|
4
|
+
export interface UpgradeDeps {
|
|
5
|
+
/** Git in the plugin folder. Also asked for the kit's tags (`ls-remote`). */
|
|
6
|
+
readonly run: RunGit;
|
|
7
|
+
/** `npm <args>` in the plugin folder; rejects with npm's message. */
|
|
8
|
+
readonly npm: (args: readonly string[]) => Promise<void>;
|
|
9
|
+
/** The text behind a URL; rejects when it cannot be read. */
|
|
10
|
+
readonly fetchText: (url: string) => Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface UpgradeInput {
|
|
13
|
+
readonly cwd: string;
|
|
14
|
+
/** `vX.Y.Z`; undefined asks the kit's repository for the latest release tag. */
|
|
15
|
+
readonly target: string | undefined;
|
|
16
|
+
readonly dryRun: boolean;
|
|
17
|
+
readonly reporter: Reporter;
|
|
18
|
+
readonly stdout: (text: string) => void;
|
|
19
|
+
readonly deps: UpgradeDeps;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `opdk kit upgrade [vX.Y.Z]`: moves package.json, the lockfile and the kit's workflow pins to one kit release, then
|
|
23
|
+
* runs the `kit` release check on the result. Nothing is committed or pushed. With `dryRun` it prints what would
|
|
24
|
+
* change and writes nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runKitUpgrade(input: UpgradeInput): Promise<number>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ALL_CHECKS, reportResults } from "../release/check.js";
|
|
4
|
+
import { sectionsBetween } from "../release/changelog.js";
|
|
5
|
+
import { tryGit } from "../release/git.js";
|
|
6
|
+
import { loadJson } from "../release/json.js";
|
|
7
|
+
import { checkKit } from "../release/kit-check.js";
|
|
8
|
+
import { loadProjectFiles } from "../release/project-files.js";
|
|
9
|
+
import { compareVersions } from "../release/semver.js";
|
|
10
|
+
import { loadWorkflows } from "./files.js";
|
|
11
|
+
import { isFullSha, readLockPin, readPackageJsonPins, rewritePackageJson, rewriteWorkflow, shortSha, stripV } from "./pins.js";
|
|
12
|
+
import { kitChangelogUrl, kitRepositoryUrl, latestTag, parseKitTags, sortedTags } from "./remote.js";
|
|
13
|
+
import { stripTerminalControls } from "./terminal-text.js";
|
|
14
|
+
const STEP = "kit";
|
|
15
|
+
/** `a`, `a and b`, `a, b and c`. */
|
|
16
|
+
const joinList = (items) => (items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1) ?? ""}`);
|
|
17
|
+
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
18
|
+
/** The changed lines as a diff: file, line number, the old line and the new one. */
|
|
19
|
+
function renderChanges(changes) {
|
|
20
|
+
return changes
|
|
21
|
+
.flatMap((file) => file.changes.map((change) => `${file.file}:${String(change.line)}\n- ${change.before.trim()}\n+ ${change.after.trim()}\n`))
|
|
22
|
+
.join("\n");
|
|
23
|
+
}
|
|
24
|
+
function fail(reporter, text, hint, details) {
|
|
25
|
+
reporter.failure(STEP, text, { hint, ...(details !== undefined && { details }) });
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `opdk kit upgrade [vX.Y.Z]`: moves package.json, the lockfile and the kit's workflow pins to one kit release, then
|
|
30
|
+
* runs the `kit` release check on the result. Nothing is committed or pushed. With `dryRun` it prints what would
|
|
31
|
+
* change and writes nothing.
|
|
32
|
+
*/
|
|
33
|
+
export async function runKitUpgrade(input) {
|
|
34
|
+
const { cwd, reporter, deps, dryRun } = input;
|
|
35
|
+
const packagePath = path.join(cwd, "package.json");
|
|
36
|
+
const lockPath = path.join(cwd, "package-lock.json");
|
|
37
|
+
const pkg = loadJson(packagePath);
|
|
38
|
+
if (pkg.kind !== "ok") {
|
|
39
|
+
return fail(reporter, pkg.kind === "missing" ? `package.json is missing in ${cwd}.` : `package.json is not valid JSON: ${pkg.message}.`, "Run opdk from the plugin root.");
|
|
40
|
+
}
|
|
41
|
+
const [spec] = readPackageJsonPins(pkg.value);
|
|
42
|
+
if (spec === undefined) {
|
|
43
|
+
return fail(reporter, "package.json does not depend on obsidian-plugin-dev-kit through GitHub.", "opdk kit upgrade moves only a git-tag install. From npm, run `npm install -D -E obsidian-plugin-dev-kit@X.Y.Z` and point the workflow `uses:` lines at that tag's commit by hand; `opdk release check` shows what disagrees. A kit linked from a folder is not upgraded by opdk.");
|
|
44
|
+
}
|
|
45
|
+
const { owner } = spec.parsed;
|
|
46
|
+
if (!dryRun) {
|
|
47
|
+
const inside = await tryGit(deps.run, ["rev-parse", "--is-inside-work-tree"]);
|
|
48
|
+
if (inside !== "true") {
|
|
49
|
+
return fail(reporter, "this folder is not inside a git repository.", "Run opdk from the plugin repository: the upgrade must be a change you can review and undo with git. --dry-run works anywhere.");
|
|
50
|
+
}
|
|
51
|
+
const dirty = (await deps.run(["status", "--porcelain"])).split("\n").filter((line) => line !== "");
|
|
52
|
+
if (dirty.length > 0) {
|
|
53
|
+
return fail(reporter, `the working tree is not clean (${dirty.slice(0, 5).join(", ")}${dirty.length > 5 ? ` and ${String(dirty.length - 5)} more` : ""}).`, "Commit or discard the changes first, so the upgrade is the only change in its commit. --dry-run works on a dirty tree.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let tags;
|
|
57
|
+
try {
|
|
58
|
+
tags = parseKitTags(await deps.run(["ls-remote", "--tags", kitRepositoryUrl(owner)]));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return fail(reporter, `could not list the kit's release tags: ${message(error)}`, "Check the network and rerun.");
|
|
62
|
+
}
|
|
63
|
+
const tag = input.target ?? latestTag(tags);
|
|
64
|
+
if (tag === undefined) {
|
|
65
|
+
return fail(reporter, `${kitRepositoryUrl(owner)} has no vX.Y.Z release tag.`, "Name the tag yourself: `opdk kit upgrade vX.Y.Z`.");
|
|
66
|
+
}
|
|
67
|
+
const sha = tags.get(tag);
|
|
68
|
+
if (sha === undefined) {
|
|
69
|
+
const known = sortedTags(tags).slice(0, 5).join(", ");
|
|
70
|
+
return fail(reporter, `the kit has no release tag ${tag}.`, known === "" ? "Check the spelling." : `The latest tags are: ${known}.`);
|
|
71
|
+
}
|
|
72
|
+
const current = spec.parsed.ref;
|
|
73
|
+
const lock = loadJson(lockPath);
|
|
74
|
+
if (lock.kind === "invalid") {
|
|
75
|
+
return fail(reporter, `package-lock.json is not valid JSON: ${lock.message}.`, "Restore it from git, or delete it and run `npm install`.");
|
|
76
|
+
}
|
|
77
|
+
const lockText = lock.kind === "ok" ? lock.text : undefined;
|
|
78
|
+
const lockPin = lock.kind === "ok" ? readLockPin(lock.value) : undefined;
|
|
79
|
+
const packageChange = { file: "package.json", ...rewritePackageJson(pkg.text, tag) };
|
|
80
|
+
const workflowChanges = loadWorkflows(cwd).map(({ file, text }) => ({ file, ...rewriteWorkflow(text, sha, tag, owner) })).filter((file) => file.changes.length > 0);
|
|
81
|
+
const changed = [packageChange, ...workflowChanges].filter((file) => file.changes.length > 0);
|
|
82
|
+
const lockStale = lockText !== undefined && lockPin?.commit !== sha;
|
|
83
|
+
// npm also rewrites the lockfile's root entry, which holds the spec from package.json, so a changed spec needs it too.
|
|
84
|
+
const runNpm = lockText !== undefined && (lockStale || packageChange.changes.length > 0);
|
|
85
|
+
reporter.info(STEP, `kit ${isFullSha(current) ? shortSha(current) : current} -> ${tag} (${shortSha(sha)})${dryRun ? " (dry run)" : ""}`);
|
|
86
|
+
if (changed.length === 0 && !lockStale) {
|
|
87
|
+
reporter.success(STEP, `package.json, package-lock.json and the workflow pins are already at ${tag} (${shortSha(sha)}); nothing to change.`);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
if (changed.length > 0) {
|
|
91
|
+
input.stdout(`\n${renderChanges(changed)}\n`);
|
|
92
|
+
}
|
|
93
|
+
if (lockStale) {
|
|
94
|
+
const was = lockPin?.commit === undefined ? "no commit" : shortSha(lockPin.commit);
|
|
95
|
+
reporter.info(STEP, `package-lock.json: ${was} -> ${shortSha(sha)}, rewritten by \`npm install\``);
|
|
96
|
+
}
|
|
97
|
+
else if (runNpm) {
|
|
98
|
+
reporter.info(STEP, "package-lock.json already holds that commit; `npm install` still runs so its record of the package.json spec follows");
|
|
99
|
+
}
|
|
100
|
+
else if (lockText === undefined) {
|
|
101
|
+
reporter.warn(STEP, "there is no package-lock.json, so npm will not run and node_modules keeps the old kit; run `npm install` to create the lockfile and install the new kit.");
|
|
102
|
+
}
|
|
103
|
+
await showKitChanges(input, owner, tag, lockPin?.version ?? (isFullSha(current) ? undefined : stripV(current)));
|
|
104
|
+
if (dryRun) {
|
|
105
|
+
reporter.info(STEP, "dry run: nothing was written. Without --dry-run opdk edits these files and runs `npm install`; it never commits.");
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
// Everything that can fail halfway is written first and restored on failure: package.json, then npm's lockfile.
|
|
109
|
+
writeFileSync(packagePath, packageChange.text);
|
|
110
|
+
if (runNpm) {
|
|
111
|
+
reporter.info(STEP, `npm install obsidian-plugin-dev-kit@${tag} (builds the kit, can take a minute)`);
|
|
112
|
+
try {
|
|
113
|
+
await deps.npm(["install", "--no-audit", "--no-fund", `obsidian-plugin-dev-kit@github:${owner}/obsidian-plugin-dev-kit#${tag}`]);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
writeFileSync(packagePath, pkg.text);
|
|
117
|
+
writeFileSync(lockPath, lockText);
|
|
118
|
+
return fail(reporter, `npm install failed; package.json and package-lock.json were put back, no workflow file was touched: ${message(error)}`, `npm may have left node_modules half installed: run \`npm ci\` if it looks off. Then fix npm, or run \`npm install --save-dev github:${owner}/obsidian-plugin-dev-kit#${tag}\` yourself and then \`opdk kit upgrade ${tag}\` for the workflow pins.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const file of workflowChanges) {
|
|
122
|
+
writeFileSync(path.join(cwd, file.file), file.text);
|
|
123
|
+
}
|
|
124
|
+
const updated = [
|
|
125
|
+
...(packageChange.changes.length > 0 ? ["package.json"] : []),
|
|
126
|
+
...(runNpm ? ["package-lock.json"] : []),
|
|
127
|
+
...(workflowChanges.length > 0 ? [`${String(workflowChanges.length)} workflow ${workflowChanges.length === 1 ? "file" : "files"}`] : []),
|
|
128
|
+
];
|
|
129
|
+
reporter.success(STEP, `${joinList(updated)} updated to ${tag} (${shortSha(sha)})`);
|
|
130
|
+
const errors = reportResults([checkKit(loadProjectFiles(cwd), loadWorkflows(cwd))], ALL_CHECKS, reporter);
|
|
131
|
+
if (errors > 0) {
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
reporter.info(STEP, "nothing was committed: review `git diff`, commit on a branch and open a pull request.");
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
/** The kit's CHANGELOG sections between the current version and the new tag, from the tag on GitHub. Never fails the upgrade. */
|
|
138
|
+
async function showKitChanges(input, owner, tag, from) {
|
|
139
|
+
const { reporter } = input;
|
|
140
|
+
const url = kitChangelogUrl(owner, tag);
|
|
141
|
+
try {
|
|
142
|
+
const order = from === undefined ? 1 : (compareVersions(stripV(tag), from) ?? 1);
|
|
143
|
+
if (order < 0) {
|
|
144
|
+
reporter.warn(STEP, `${tag} is older than ${from ?? "the current kit"}: this is a downgrade.`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (order === 0) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const sections = sectionsBetween(await input.deps.fetchText(url), from, stripV(tag));
|
|
151
|
+
if (sections.length === 0) {
|
|
152
|
+
reporter.info(STEP, `the kit CHANGELOG at ${tag} has no section ${from === undefined ? "for it" : `after ${from}`}.`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
reporter.info(STEP, `kit changes${from === undefined ? "" : ` since ${from}`}, newest first:`);
|
|
156
|
+
// The text came over the network: no escape sequence or control character may reach the terminal.
|
|
157
|
+
input.stdout(`\n${stripTerminalControls(sections.join("\n\n"))}\n\n`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
reporter.info(STEP, `could not read the kit CHANGELOG (${message(error)}); see ${url}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VersionReader } from "./versions.js";
|
|
2
|
+
/**
|
|
3
|
+
* The real reader: Node's resolution from the plugin's folder (`rootDir`), not from the kit, so a hoisted copy or a
|
|
4
|
+
* nested one is found the way the plugin's own code finds it. A package that is not installed gives `undefined`;
|
|
5
|
+
* anything else that goes wrong (an unreadable or malformed `package.json`, a package that does not export it) throws
|
|
6
|
+
* with the package name, because reporting it as "not installed" would send the plugin author the wrong way.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createVersionReader(rootDir: string): VersionReader;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* The real reader: Node's resolution from the plugin's folder (`rootDir`), not from the kit, so a hoisted copy or a
|
|
6
|
+
* nested one is found the way the plugin's own code finds it. A package that is not installed gives `undefined`;
|
|
7
|
+
* anything else that goes wrong (an unreadable or malformed `package.json`, a package that does not export it) throws
|
|
8
|
+
* with the package name, because reporting it as "not installed" would send the plugin author the wrong way.
|
|
9
|
+
*/
|
|
10
|
+
export function createVersionReader(rootDir) {
|
|
11
|
+
const require = createRequire(path.join(path.resolve(rootDir), "noop.js"));
|
|
12
|
+
return (name) => {
|
|
13
|
+
let file;
|
|
14
|
+
try {
|
|
15
|
+
file = require.resolve(`${name}/package.json`);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error && "code" in error && error.code === "MODULE_NOT_FOUND")
|
|
19
|
+
return undefined;
|
|
20
|
+
throw new Error(`Cannot resolve "${name}/package.json" from ${rootDir}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
23
|
+
if (typeof manifest === "object" && manifest !== null && "version" in manifest && typeof manifest.version === "string") {
|
|
24
|
+
return manifest.version;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`${file} has no "version" field. Reinstall "${name}": npm install --save-dev ${name}.`);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** A semantic version reduced to what the peer checks compare. */
|
|
2
|
+
export interface ParsedVersion {
|
|
3
|
+
readonly major: number;
|
|
4
|
+
readonly minor: number;
|
|
5
|
+
}
|
|
6
|
+
/** `5.1.0`, `v5.1.0`, `5.0.0-beta.1`: the numbers up front. Anything else is not a version. */
|
|
7
|
+
export declare function parseVersion(version: string): ParsedVersion | undefined;
|
|
8
|
+
/** A package a module needs the plugin to install, with the versions it accepts. */
|
|
9
|
+
export interface PeerRule {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** Lowest accepted major version. */
|
|
12
|
+
readonly minMajor: number;
|
|
13
|
+
/** Highest accepted major version; omitted means no upper bound. */
|
|
14
|
+
readonly maxMajor?: number;
|
|
15
|
+
/** Lowest accepted minor version inside `minMajor` (Playwright: 1.62). Default 0. */
|
|
16
|
+
readonly minMinor?: number;
|
|
17
|
+
/** The range as the message and the install command show it, for example `^5.0.0` or `>=30`. */
|
|
18
|
+
readonly range: string;
|
|
19
|
+
}
|
|
20
|
+
/** Reads the installed version of a package as the plugin resolves it; `undefined` when it is not installed. */
|
|
21
|
+
export type VersionReader = (name: string) => string | undefined;
|
|
22
|
+
/** One thing to fix: what is wrong, and the `name@range` that fixes it. */
|
|
23
|
+
export interface PeerProblem {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly install: string;
|
|
26
|
+
}
|
|
27
|
+
/** Compares the installed version with the rule. Returns the problem, or `undefined` when the version is accepted. */
|
|
28
|
+
export declare function checkRule(rule: PeerRule, installed: string | undefined): PeerProblem | undefined;
|
|
29
|
+
/** Packs the problems into one error message: a line each, then one install command that fixes all of them. */
|
|
30
|
+
export declare function formatPeerError(prefix: string, problems: readonly PeerProblem[]): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** `5.1.0`, `v5.1.0`, `5.0.0-beta.1`: the numbers up front. Anything else is not a version. */
|
|
2
|
+
export function parseVersion(version) {
|
|
3
|
+
const match = /^v?(\d+)\.(\d+)\.\d+/.exec(version.trim());
|
|
4
|
+
if (match?.[1] === undefined || match[2] === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
return { major: Number(match[1]), minor: Number(match[2]) };
|
|
7
|
+
}
|
|
8
|
+
/** Compares the installed version with the rule. Returns the problem, or `undefined` when the version is accepted. */
|
|
9
|
+
export function checkRule(rule, installed) {
|
|
10
|
+
const install = `${rule.name}@${rule.range}`;
|
|
11
|
+
if (installed === undefined) {
|
|
12
|
+
return { message: `"${rule.name}" is not installed; the kit needs ${rule.range}.`, install };
|
|
13
|
+
}
|
|
14
|
+
const parsed = parseVersion(installed);
|
|
15
|
+
if (parsed === undefined) {
|
|
16
|
+
return { message: `"${rule.name}" reports the version "${installed}", which is not a version number; the kit needs ${rule.range}.`, install };
|
|
17
|
+
}
|
|
18
|
+
const belowMinimum = parsed.major < rule.minMajor || (parsed.major === rule.minMajor && parsed.minor < (rule.minMinor ?? 0));
|
|
19
|
+
const aboveMaximum = rule.maxMajor !== undefined && parsed.major > rule.maxMajor;
|
|
20
|
+
if (belowMinimum || aboveMaximum) {
|
|
21
|
+
return { message: `"${rule.name}" ${installed} is installed; the kit needs ${rule.range}.`, install };
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Packs the problems into one error message: a line each, then one install command that fixes all of them. */
|
|
26
|
+
export function formatPeerError(prefix, problems) {
|
|
27
|
+
const lines = problems.map((problem) => `${prefix}: ${problem.message}`);
|
|
28
|
+
// `electron@>=39.0.0` unquoted is a redirect in a shell.
|
|
29
|
+
const specs = problems.map((problem) => (/[<>|\s]/.test(problem.install) ? `"${problem.install}"` : problem.install));
|
|
30
|
+
const command = `npm install --save-dev ${specs.join(" ")}`;
|
|
31
|
+
return `${lines.join("\n")}\nRun: ${command}`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Linter } from "eslint";
|
|
2
|
+
import { type ResolvedBuild } from "../build/options.js";
|
|
3
|
+
import { type GroupResult } from "./problems.js";
|
|
4
|
+
export interface ApiCheckInput {
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly minAppVersion: string | undefined;
|
|
7
|
+
/** The build section; its entry decides which files are checked. */
|
|
8
|
+
readonly build: ResolvedBuild;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The ESLint configuration of the check: only `obsidianmd/no-unsupported-api`, type-aware, with the manifest's
|
|
12
|
+
* `minAppVersion` passed as the rule's own option so it does not depend on which manifest.json the process can see.
|
|
13
|
+
* `opdk scan` is a mirror of the directory's configuration and is not touched; this rule runs here, at release time.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createApiConfig(cwd: string, minAppVersion: string): Linter.Config[];
|
|
16
|
+
/**
|
|
17
|
+
* `minAppVersion` against the API the plugin calls: runs `obsidianmd/no-unsupported-api` over the files the bundle
|
|
18
|
+
* is made of (esbuild's metafile, not a guess from `src/**`), so a tracked file that is not shipped is not judged
|
|
19
|
+
* and a shipped one is not missed. Needs the plugin's dependencies installed, because the rule reads `@since` tags
|
|
20
|
+
* from `obsidian.d.ts`.
|
|
21
|
+
*
|
|
22
|
+
* Blind spot: the rule reads those tags through the TypeScript program. When the program does not contain the real
|
|
23
|
+
* `obsidian.d.ts` (for example a tsconfig `paths` entry that points `obsidian` at a stub), the rule has nothing to
|
|
24
|
+
* read and reports nothing, and this check cannot tell. A shipped file that no tsconfig covers is an error, because
|
|
25
|
+
* it would not be checked at all.
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkApiUsage({ cwd, minAppVersion, build }: ApiCheckInput): Promise<GroupResult>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { build as esbuildBuild, formatMessages } from "esbuild";
|
|
4
|
+
import { ESLint } from "eslint";
|
|
5
|
+
import obsidianmd from "eslint-plugin-obsidianmd";
|
|
6
|
+
import tseslint from "typescript-eslint";
|
|
7
|
+
import { toEsbuildOptions } from "../build/options.js";
|
|
8
|
+
import { isBuildFailure } from "../build/report.js";
|
|
9
|
+
import { isOutsideProject } from "../scanner/outside-project.js";
|
|
10
|
+
import { errorProblem, warningProblem } from "./problems.js";
|
|
11
|
+
const RULE = "obsidianmd/no-unsupported-api";
|
|
12
|
+
/**
|
|
13
|
+
* The ESLint configuration of the check: only `obsidianmd/no-unsupported-api`, type-aware, with the manifest's
|
|
14
|
+
* `minAppVersion` passed as the rule's own option so it does not depend on which manifest.json the process can see.
|
|
15
|
+
* `opdk scan` is a mirror of the directory's configuration and is not touched; this rule runs here, at release time.
|
|
16
|
+
*/
|
|
17
|
+
export function createApiConfig(cwd, minAppVersion) {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
21
|
+
languageOptions: {
|
|
22
|
+
parser: tseslint.parser,
|
|
23
|
+
parserOptions: { projectService: true, tsconfigRootDir: cwd },
|
|
24
|
+
},
|
|
25
|
+
plugins: { obsidianmd },
|
|
26
|
+
// Only one rule runs here, so a plugin's disable comments for other rules would all read as unused.
|
|
27
|
+
linterOptions: { reportUnusedDisableDirectives: "off", reportUnusedInlineConfigs: "off" },
|
|
28
|
+
rules: { [RULE]: ["error", { minAppVersion }] },
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
/** True when `obsidian` (the package that carries the `@since` tags the rule reads) can be resolved from the plugin. */
|
|
33
|
+
function obsidianTypesInstalled(cwd) {
|
|
34
|
+
try {
|
|
35
|
+
createRequire(path.join(cwd, "package.json")).resolve("obsidian/package.json");
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The TypeScript files that end up in `main.js`, from esbuild's metafile of the production build (nothing is
|
|
44
|
+
* written), minus `node_modules`. Paths are relative to the plugin folder; a file above it keeps its `..`.
|
|
45
|
+
*/
|
|
46
|
+
async function bundledSources(cwd, build) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await esbuildBuild({ ...toEsbuildOptions(build, cwd, { kind: "release" }), write: false, metafile: true });
|
|
49
|
+
const files = Object.keys(result.metafile.inputs)
|
|
50
|
+
.map((input) => input.split("\\").join("/"))
|
|
51
|
+
.filter((input) => !input.split("/").includes("node_modules") && /\.[cm]?tsx?$/.test(input));
|
|
52
|
+
return { ok: true, files };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (!isBuildFailure(error)) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const details = (await formatMessages(error.errors, { kind: "error", color: false, terminalWidth: 100 })).flatMap((text) => text.trimEnd().split("\n"));
|
|
59
|
+
return { ok: false, problem: errorProblem("api", "the bundle could not be analysed because the production build fails, so the files it ships are unknown.", "Fix the build errors (see the build group), or skip this check with --no-api.", details) };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* `minAppVersion` against the API the plugin calls: runs `obsidianmd/no-unsupported-api` over the files the bundle
|
|
64
|
+
* is made of (esbuild's metafile, not a guess from `src/**`), so a tracked file that is not shipped is not judged
|
|
65
|
+
* and a shipped one is not missed. Needs the plugin's dependencies installed, because the rule reads `@since` tags
|
|
66
|
+
* from `obsidian.d.ts`.
|
|
67
|
+
*
|
|
68
|
+
* Blind spot: the rule reads those tags through the TypeScript program. When the program does not contain the real
|
|
69
|
+
* `obsidian.d.ts` (for example a tsconfig `paths` entry that points `obsidian` at a stub), the rule has nothing to
|
|
70
|
+
* read and reports nothing, and this check cannot tell. A shipped file that no tsconfig covers is an error, because
|
|
71
|
+
* it would not be checked at all.
|
|
72
|
+
*/
|
|
73
|
+
export async function checkApiUsage({ cwd, minAppVersion, build }) {
|
|
74
|
+
if (minAppVersion === undefined) {
|
|
75
|
+
return { group: "api", passed: "", problems: [errorProblem("api", "manifest.json has no minAppVersion, so the API calls cannot be checked against it.", 'Add "minAppVersion" to manifest.json.')] };
|
|
76
|
+
}
|
|
77
|
+
if (!obsidianTypesInstalled(cwd)) {
|
|
78
|
+
return {
|
|
79
|
+
group: "api",
|
|
80
|
+
passed: "",
|
|
81
|
+
problems: [
|
|
82
|
+
errorProblem("api", 'the "obsidian" package is not installed, so no API version can be checked.', "Run `npm ci` in the plugin folder, or skip this check with --no-api."),
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const inputs = await bundledSources(cwd, build);
|
|
87
|
+
if (!inputs.ok) {
|
|
88
|
+
return { group: "api", passed: "", problems: [inputs.problem] };
|
|
89
|
+
}
|
|
90
|
+
if (inputs.files.length === 0) {
|
|
91
|
+
return { group: "api", passed: "", problems: [warningProblem("api", `the bundle of ${build.entry} contains no TypeScript files, so nothing was checked.`, "Nothing to do for a plugin written in JavaScript.")] };
|
|
92
|
+
}
|
|
93
|
+
const inside = inputs.files.filter((file) => !file.startsWith(".."));
|
|
94
|
+
const eslint = new ESLint({ cwd, overrideConfigFile: true, baseConfig: createApiConfig(cwd, minAppVersion), warnIgnored: false, errorOnUnmatchedPattern: false });
|
|
95
|
+
const results = inside.length === 0 ? [] : await eslint.lintFiles(inside);
|
|
96
|
+
const problems = [];
|
|
97
|
+
const covered = new Set();
|
|
98
|
+
for (const result of results) {
|
|
99
|
+
const file = path.relative(cwd, result.filePath).split(path.sep).join("/");
|
|
100
|
+
if (isOutsideProject(result)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
covered.add(file);
|
|
104
|
+
for (const message of result.messages) {
|
|
105
|
+
const where = `${file}:${String(message.line)}`;
|
|
106
|
+
if (message.ruleId === RULE) {
|
|
107
|
+
problems.push(errorProblem("api", `${where} ${message.message}`, "Raise minAppVersion in manifest.json (and versions.json for a new version), or guard the call with requireApiVersion()."));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
problems.push(errorProblem("api", `${where} could not be analysed: ${message.message}`, "Fix the error; a file that does not parse cannot be checked."));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const unchecked = inputs.files.filter((file) => !covered.has(file));
|
|
115
|
+
if (unchecked.length > 0) {
|
|
116
|
+
problems.push(errorProblem("api", `${String(unchecked.length)} file(s) in the bundle are not covered by a tsconfig (or lie outside the plugin folder), so their Obsidian API calls were not checked: ${unchecked.join(", ")}.`, "Include them in tsconfig.json (include or files): the rule needs type information. Files above the plugin folder cannot be checked."));
|
|
117
|
+
}
|
|
118
|
+
return { group: "api", passed: `${String(covered.size)} bundled source file(s) use nothing newer than minAppVersion ${minAppVersion}`, problems };
|
|
119
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CheckFlags } from "./check.js";
|
|
2
|
+
import { type BumpKind } from "./semver.js";
|
|
3
|
+
/** What the user asked the new version to be: a bump of the current one, or an exact version. */
|
|
4
|
+
export type VersionSpec = {
|
|
5
|
+
readonly kind: "bump";
|
|
6
|
+
readonly bump: BumpKind;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "exact";
|
|
9
|
+
readonly version: string;
|
|
10
|
+
};
|
|
11
|
+
/** Options of the push flow: whether to run it, how long to wait for the workflow, whether the release carries a zip. */
|
|
12
|
+
export interface PushOptions {
|
|
13
|
+
readonly push: boolean;
|
|
14
|
+
/** Undefined: the default. */
|
|
15
|
+
readonly timeoutMinutes: number | undefined;
|
|
16
|
+
readonly zip: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type ReleaseArgs = {
|
|
19
|
+
readonly mode: "check";
|
|
20
|
+
readonly tag: string | undefined;
|
|
21
|
+
readonly flags: CheckFlags;
|
|
22
|
+
} | {
|
|
23
|
+
readonly mode: "bump";
|
|
24
|
+
readonly spec: VersionSpec;
|
|
25
|
+
readonly dryRun: boolean;
|
|
26
|
+
readonly flags: CheckFlags;
|
|
27
|
+
readonly pushing: PushOptions;
|
|
28
|
+
readonly test: boolean;
|
|
29
|
+
} | {
|
|
30
|
+
readonly mode: "publish";
|
|
31
|
+
readonly version: string | undefined;
|
|
32
|
+
readonly pushing: PushOptions;
|
|
33
|
+
} | {
|
|
34
|
+
readonly mode: "notes";
|
|
35
|
+
readonly version: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
/** Parses what follows `opdk release`. Throws a message that says what to type instead. */
|
|
38
|
+
export declare function parseReleaseArgs(args: readonly string[]): ReleaseArgs;
|
|
39
|
+
/** The version a spec leads to from `current`. */
|
|
40
|
+
export declare function resolveVersion(spec: VersionSpec, current: string): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ALL_CHECKS } from "./check.js";
|
|
2
|
+
import { bumpVersion, isBumpKind, isPlainVersion } from "./semver.js";
|
|
3
|
+
const SKIP_FLAGS = {
|
|
4
|
+
"--no-build": { build: false },
|
|
5
|
+
"--no-reproducible": { reproducible: false },
|
|
6
|
+
"--no-api": { api: false },
|
|
7
|
+
};
|
|
8
|
+
const USAGE_HINT = 'Run "opdk release --help".';
|
|
9
|
+
/** Parses what follows `opdk release`. Throws a message that says what to type instead. */
|
|
10
|
+
export function parseReleaseArgs(args) {
|
|
11
|
+
const [first, ...rest] = args;
|
|
12
|
+
if (first === undefined) {
|
|
13
|
+
throw new Error(`"opdk release" needs "check", patch, minor, major or a version such as 1.4.0. ${USAGE_HINT}`);
|
|
14
|
+
}
|
|
15
|
+
let flags = ALL_CHECKS;
|
|
16
|
+
let tag;
|
|
17
|
+
let dryRun = false;
|
|
18
|
+
let push = true;
|
|
19
|
+
let zip = false;
|
|
20
|
+
let test = true;
|
|
21
|
+
let timeoutMinutes;
|
|
22
|
+
let positional;
|
|
23
|
+
const used = [];
|
|
24
|
+
for (let index = 0; index < rest.length; index++) {
|
|
25
|
+
const arg = rest[index] ?? "";
|
|
26
|
+
const skip = SKIP_FLAGS[arg];
|
|
27
|
+
if (skip !== undefined) {
|
|
28
|
+
flags = { ...flags, ...skip };
|
|
29
|
+
used.push(arg);
|
|
30
|
+
}
|
|
31
|
+
else if (arg === "--dry-run") {
|
|
32
|
+
dryRun = true;
|
|
33
|
+
used.push(arg);
|
|
34
|
+
}
|
|
35
|
+
else if (arg === "--no-push") {
|
|
36
|
+
push = false;
|
|
37
|
+
used.push(arg);
|
|
38
|
+
}
|
|
39
|
+
else if (arg === "--no-test") {
|
|
40
|
+
test = false;
|
|
41
|
+
used.push(arg);
|
|
42
|
+
}
|
|
43
|
+
else if (arg === "--zip") {
|
|
44
|
+
zip = true;
|
|
45
|
+
used.push(arg);
|
|
46
|
+
}
|
|
47
|
+
else if (arg === "--timeout" || arg.startsWith("--timeout=")) {
|
|
48
|
+
const value = arg === "--timeout" ? rest[++index] : arg.slice("--timeout=".length);
|
|
49
|
+
timeoutMinutes = Number(value);
|
|
50
|
+
if (value === undefined || !/^\d+$/.test(value) || timeoutMinutes < 1) {
|
|
51
|
+
throw new Error(`"--timeout" needs a whole number of minutes, for example --timeout 30. ${USAGE_HINT}`);
|
|
52
|
+
}
|
|
53
|
+
used.push("--timeout");
|
|
54
|
+
}
|
|
55
|
+
else if (arg === "--tag" || arg.startsWith("--tag=")) {
|
|
56
|
+
const value = arg === "--tag" ? rest[++index] : arg.slice("--tag=".length);
|
|
57
|
+
if (value === undefined || value === "" || value.startsWith("--")) {
|
|
58
|
+
throw new Error(`"--tag" needs the tag name, for example --tag 1.2.3. ${USAGE_HINT}`);
|
|
59
|
+
}
|
|
60
|
+
tag = value;
|
|
61
|
+
used.push("--tag");
|
|
62
|
+
}
|
|
63
|
+
else if ((first === "publish" || first === "notes") && !arg.startsWith("-") && positional === undefined) {
|
|
64
|
+
positional = arg;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Unknown argument "${arg}" for "opdk release ${first}". ${USAGE_HINT}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const reject = (allowed, what) => {
|
|
71
|
+
const wrong = used.find((flag) => !allowed.includes(flag));
|
|
72
|
+
if (wrong !== undefined) {
|
|
73
|
+
throw new Error(`"${wrong}" does not belong to "${what}". ${USAGE_HINT}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
if (first === "check") {
|
|
77
|
+
if (dryRun) {
|
|
78
|
+
throw new Error(`"--dry-run" belongs to "opdk release <version>", not to "check". ${USAGE_HINT}`);
|
|
79
|
+
}
|
|
80
|
+
reject(["--tag", ...Object.keys(SKIP_FLAGS)], "opdk release check");
|
|
81
|
+
return { mode: "check", tag, flags };
|
|
82
|
+
}
|
|
83
|
+
if (first === "notes") {
|
|
84
|
+
reject([], "opdk release notes");
|
|
85
|
+
return { mode: "notes", version: parseOptionalVersion(positional) };
|
|
86
|
+
}
|
|
87
|
+
if (first === "publish") {
|
|
88
|
+
reject(["--timeout", "--zip"], "opdk release publish");
|
|
89
|
+
return { mode: "publish", version: parseOptionalVersion(positional), pushing: { push: true, timeoutMinutes, zip } };
|
|
90
|
+
}
|
|
91
|
+
if (tag !== undefined) {
|
|
92
|
+
throw new Error(`"--tag" belongs to "opdk release check": a release creates the tag itself. ${USAGE_HINT}`);
|
|
93
|
+
}
|
|
94
|
+
if (!push && (zip || timeoutMinutes !== undefined)) {
|
|
95
|
+
throw new Error(`"--zip" and "--timeout" describe the push flow, which "--no-push" turns off. ${USAGE_HINT}`);
|
|
96
|
+
}
|
|
97
|
+
return { mode: "bump", spec: parseSpec(first), dryRun, flags, pushing: { push, timeoutMinutes, zip }, test };
|
|
98
|
+
}
|
|
99
|
+
function parseOptionalVersion(value) {
|
|
100
|
+
if (value !== undefined && !isPlainVersion(value)) {
|
|
101
|
+
throw new Error(`"${value}" is not an x.y.z version. Write it without a "v", for example 1.4.0. ${USAGE_HINT}`);
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
function parseSpec(value) {
|
|
106
|
+
if (isBumpKind(value)) {
|
|
107
|
+
return { kind: "bump", bump: value };
|
|
108
|
+
}
|
|
109
|
+
if (isPlainVersion(value)) {
|
|
110
|
+
return { kind: "exact", version: value };
|
|
111
|
+
}
|
|
112
|
+
const hint = /^v\d+\.\d+\.\d+$/.test(value)
|
|
113
|
+
? ` Obsidian needs the tag to be exactly the manifest version, so write ${value.slice(1)} without the "v".`
|
|
114
|
+
: " Pre-release versions are not supported yet.";
|
|
115
|
+
throw new Error(`"${value}" is not patch, minor, major or an x.y.z version.${hint}`);
|
|
116
|
+
}
|
|
117
|
+
/** The version a spec leads to from `current`. */
|
|
118
|
+
export function resolveVersion(spec, current) {
|
|
119
|
+
return spec.kind === "exact" ? spec.version : bumpVersion(current, spec.bump);
|
|
120
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Problem } from "./problems.js";
|
|
2
|
+
export interface AssetInput {
|
|
3
|
+
/** The built main.js, undefined when the build did not write one. */
|
|
4
|
+
readonly mainJs: Uint8Array | undefined;
|
|
5
|
+
/** styles.css written by the CSS step, undefined when there is no CSS entry. */
|
|
6
|
+
readonly builtCss: Uint8Array | undefined;
|
|
7
|
+
/** The styles.css committed at the plugin root, undefined when there is none. */
|
|
8
|
+
readonly rootCss: Uint8Array | undefined;
|
|
9
|
+
/** Text of manifest.json at the plugin root. */
|
|
10
|
+
readonly manifestText: string;
|
|
11
|
+
/** Text of the manifest.json next to the built main.js when that is not the plugin root; undefined at the root. */
|
|
12
|
+
readonly outputManifestText: string | undefined;
|
|
13
|
+
/** Where the bundle goes, as the build config names it. */
|
|
14
|
+
readonly outfile: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What a GitHub release must hold: `main.js`, `manifest.json`, and `styles.css` only if the plugin has CSS. The
|
|
18
|
+
* kit's build writes `main.js` and `styles.css`; the `manifest.json` asset is the one at the plugin root, so a copy
|
|
19
|
+
* next to a bundle that is built outside the root must be that same file.
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkAssets(input: AssetInput): Problem[];
|