obsidian-plugin-dev-kit 0.0.0-stage → 0.3.3
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,35 @@
|
|
|
1
|
+
import { errorProblem, warningProblem } from "./problems.js";
|
|
2
|
+
const GROUP = "assets";
|
|
3
|
+
/**
|
|
4
|
+
* What a GitHub release must hold: `main.js`, `manifest.json`, and `styles.css` only if the plugin has CSS. The
|
|
5
|
+
* kit's build writes `main.js` and `styles.css`; the `manifest.json` asset is the one at the plugin root, so a copy
|
|
6
|
+
* next to a bundle that is built outside the root must be that same file.
|
|
7
|
+
*/
|
|
8
|
+
export function checkAssets(input) {
|
|
9
|
+
const problems = [];
|
|
10
|
+
if (input.mainJs === undefined) {
|
|
11
|
+
problems.push(errorProblem(GROUP, `the build did not write ${input.outfile}.`, "Check build.outfile in opdk.config.mjs."));
|
|
12
|
+
}
|
|
13
|
+
else if (input.mainJs.length === 0) {
|
|
14
|
+
problems.push(errorProblem(GROUP, `${input.outfile} is empty.`, "The entry point produced no code; check build.entry in opdk.config.mjs."));
|
|
15
|
+
}
|
|
16
|
+
const css = input.builtCss ?? input.rootCss;
|
|
17
|
+
if (css === undefined) {
|
|
18
|
+
problems.push(warningProblem(GROUP, "the plugin ships no styles.css (no CSS entry and no styles.css at the plugin root).", "Fine for a plugin without styles; otherwise create src/styles/main.css or set build.css.entry."));
|
|
19
|
+
}
|
|
20
|
+
else if (css.length === 0) {
|
|
21
|
+
problems.push(errorProblem(GROUP, "styles.css is empty.", "Delete it, or put the plugin's styles in it: an empty asset lowers the scorecard."));
|
|
22
|
+
}
|
|
23
|
+
if (input.outputManifestText !== undefined && !sameJson(input.outputManifestText, input.manifestText)) {
|
|
24
|
+
problems.push(errorProblem(GROUP, `the manifest.json next to ${input.outfile} differs from the one at the plugin root.`, "Release assets must carry the root manifest: copy it after the build, or build into the plugin root."));
|
|
25
|
+
}
|
|
26
|
+
return problems;
|
|
27
|
+
}
|
|
28
|
+
function sameJson(a, b) {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.stringify(JSON.parse(a)) === JSON.stringify(JSON.parse(b));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return a === b;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ResolvedBuild } from "../build/options.js";
|
|
2
|
+
import { type GroupResult, type Problem } from "./problems.js";
|
|
3
|
+
import type { CommittedTree } from "./committed-tree.js";
|
|
4
|
+
import type { CleanupSet } from "./interrupt.js";
|
|
5
|
+
export interface BuildCheckInput {
|
|
6
|
+
readonly cwd: string;
|
|
7
|
+
/** Text of manifest.json at the plugin root. */
|
|
8
|
+
readonly manifestText: string;
|
|
9
|
+
readonly desktopOnly: boolean;
|
|
10
|
+
readonly build: ResolvedBuild;
|
|
11
|
+
/** Build a second time and compare the bytes. */
|
|
12
|
+
readonly reproducible: boolean;
|
|
13
|
+
/** Extracts the committed tree into the given empty folder. Without it the second build runs in the plugin folder. */
|
|
14
|
+
readonly committed?: (workDir: string) => Promise<CommittedTree>;
|
|
15
|
+
/** Findings about the build setup itself (the package.json script), reported with the `build` group. */
|
|
16
|
+
readonly buildNotes: readonly Problem[];
|
|
17
|
+
/** Where the temp folders are listed, so Ctrl+C can remove them. */
|
|
18
|
+
readonly cleanups: CleanupSet;
|
|
19
|
+
}
|
|
20
|
+
export interface Built {
|
|
21
|
+
readonly mainJs: Buffer;
|
|
22
|
+
/** Undefined when the plugin has no CSS entry. */
|
|
23
|
+
readonly css: Buffer | undefined;
|
|
24
|
+
}
|
|
25
|
+
export type BuildOutcome = {
|
|
26
|
+
readonly ok: true;
|
|
27
|
+
readonly built: Built;
|
|
28
|
+
} | {
|
|
29
|
+
readonly ok: false;
|
|
30
|
+
readonly problem: Problem;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* One production build, written into `outDir` instead of the plugin folder: the check must not replace the
|
|
34
|
+
* developer's own `main.js` or `styles.css`. The options are the ones `opdk build` uses (`toEsbuildOptions`, the
|
|
35
|
+
* CSS bundler), with absolute output paths.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildOnce(cwd: string, build: ResolvedBuild, outDir: string, options?: {
|
|
38
|
+
readonly preserveSymlinks?: boolean;
|
|
39
|
+
}): Promise<BuildOutcome>;
|
|
40
|
+
/** The groups of a release check that need a build: `build`, `assets` and, when asked, `reproducible`. */
|
|
41
|
+
export declare function checkBuild(input: BuildCheckInput): Promise<GroupResult[]>;
|
|
42
|
+
/** The hint for a committed-tree build that failed: a missing file for a relative import, the dependency layout for a package. */
|
|
43
|
+
export declare function committedBuildHint(message: string, details: readonly string[] | undefined): string;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { build as esbuildBuild, formatMessages } from "esbuild";
|
|
5
|
+
import { findNodeOnlyReferences } from "../build/bundle-check.js";
|
|
6
|
+
import { buildCss } from "../build/css.js";
|
|
7
|
+
import { toEsbuildOptions } from "../build/options.js";
|
|
8
|
+
import { formatKib, isBuildFailure } from "../build/report.js";
|
|
9
|
+
import { checkAssets } from "./assets.js";
|
|
10
|
+
import { loadText } from "./json.js";
|
|
11
|
+
import { errorProblem, warningProblem } from "./problems.js";
|
|
12
|
+
import { describeDifference, firstDifference, LIKELY_CAUSES, LIKELY_CAUSES_SAME_TREE } from "./reproducible.js";
|
|
13
|
+
const readBytes = (file) => {
|
|
14
|
+
try {
|
|
15
|
+
return readFileSync(file);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One production build, written into `outDir` instead of the plugin folder: the check must not replace the
|
|
26
|
+
* developer's own `main.js` or `styles.css`. The options are the ones `opdk build` uses (`toEsbuildOptions`, the
|
|
27
|
+
* CSS bundler), with absolute output paths.
|
|
28
|
+
*/
|
|
29
|
+
export async function buildOnce(cwd, build, outDir, options = {}) {
|
|
30
|
+
const stylesFile = path.join(outDir, "styles.css");
|
|
31
|
+
let css;
|
|
32
|
+
if (build.css !== false) {
|
|
33
|
+
try {
|
|
34
|
+
const result = buildCss(cwd, { entry: build.css.entry, outfile: stylesFile });
|
|
35
|
+
css = result.status === "built" ? readFileSync(stylesFile) : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return { ok: false, problem: errorProblem("build", `the CSS step failed: ${error instanceof Error ? error.message : String(error)}`, "Fix the @import lines of the CSS entry, then rerun.") };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const mainFile = path.join(outDir, "main.js");
|
|
42
|
+
try {
|
|
43
|
+
await esbuildBuild({ ...toEsbuildOptions({ ...build, outfile: mainFile }, cwd, { kind: "release" }), ...(options.preserveSymlinks === true && { preserveSymlinks: true }) });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (!isBuildFailure(error)) {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
const details = (await formatMessages(error.errors, { kind: "error", color: false, terminalWidth: 100 })).flatMap((text) => text.trimEnd().split("\n"));
|
|
50
|
+
return { ok: false, problem: errorProblem("build", `the production build failed with ${String(error.errors.length)} error(s).`, "Fix them; `opdk build` prints the same messages.", details) };
|
|
51
|
+
}
|
|
52
|
+
return { ok: true, built: { mainJs: readFileSync(mainFile), css } };
|
|
53
|
+
}
|
|
54
|
+
/** The groups of a release check that need a build: `build`, `assets` and, when asked, `reproducible`. */
|
|
55
|
+
export async function checkBuild(input) {
|
|
56
|
+
const { cwd, build } = input;
|
|
57
|
+
const dirs = [];
|
|
58
|
+
const tempDir = () => {
|
|
59
|
+
// The real path: on macOS the temp folder is reached through a symlink (/var -> /private/var), and esbuild
|
|
60
|
+
// then writes `../..` paths for files it finds through the other spelling.
|
|
61
|
+
const dir = mkdtempSync(path.join(realpathSync(tmpdir()), "opdk-release-"));
|
|
62
|
+
dirs.push(dir);
|
|
63
|
+
// Ctrl+C removes the folder from the signal listener; the finally below covers every other way out.
|
|
64
|
+
input.cleanups.add(() => {
|
|
65
|
+
rmSync(dir, { recursive: true, force: true });
|
|
66
|
+
});
|
|
67
|
+
return dir;
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const first = await buildOnce(cwd, build, tempDir());
|
|
71
|
+
if (!first.ok) {
|
|
72
|
+
return [{ group: "build", passed: "", problems: [first.problem, ...input.buildNotes] }];
|
|
73
|
+
}
|
|
74
|
+
const results = [buildResult(input, first.built), assetsResult(input, first.built)];
|
|
75
|
+
if (input.reproducible) {
|
|
76
|
+
results.push(await reproducibleResult(input, first.built, tempDir));
|
|
77
|
+
}
|
|
78
|
+
return results;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
for (const dir of dirs) {
|
|
82
|
+
rmSync(dir, { recursive: true, force: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function buildResult({ build, desktopOnly, buildNotes }, built) {
|
|
87
|
+
const problems = [...buildNotes];
|
|
88
|
+
const size = formatKib(built.mainJs.length);
|
|
89
|
+
if (!desktopOnly) {
|
|
90
|
+
const references = findNodeOnlyReferences(built.mainJs.toString("utf8"));
|
|
91
|
+
if (references.length > 0) {
|
|
92
|
+
problems.push(errorProblem("build", `${build.outfile} cannot run on mobile.`, "Check the esbuild platform: an Obsidian plugin bundles as `browser`. Set isDesktopOnly in manifest.json only if the plugin needs Node.", references.map((reference) => `- ${reference}`)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { group: "build", passed: `production build of ${build.entry}: ${build.outfile} ${size}${desktopOnly ? "" : ", free of Node-only references"}`, problems };
|
|
96
|
+
}
|
|
97
|
+
function assetsResult({ cwd, manifestText, build }, built) {
|
|
98
|
+
const outputDir = path.dirname(path.resolve(cwd, build.outfile));
|
|
99
|
+
const outputManifestText = outputDir === path.resolve(cwd) ? undefined : loadText(path.join(outputDir, "manifest.json"));
|
|
100
|
+
const stylesAtRoot = path.resolve(cwd, build.css === false ? "styles.css" : build.css.outfile);
|
|
101
|
+
const problems = checkAssets({
|
|
102
|
+
mainJs: built.mainJs,
|
|
103
|
+
builtCss: built.css,
|
|
104
|
+
rootCss: readBytes(stylesAtRoot),
|
|
105
|
+
manifestText,
|
|
106
|
+
outputManifestText,
|
|
107
|
+
outfile: build.outfile,
|
|
108
|
+
});
|
|
109
|
+
const styles = built.css !== undefined ? ", styles.css (built)" : readBytes(stylesAtRoot) !== undefined ? ", styles.css (as committed)" : "";
|
|
110
|
+
return { group: "assets", passed: `main.js, manifest.json${styles}`, problems };
|
|
111
|
+
}
|
|
112
|
+
const NOT_IN_COMMIT_HINT = "An input of the build is not in the commit: a file that is untracked, ignored by .gitignore or excluded by export-ignore. Commit it, or fix the import, then rerun.";
|
|
113
|
+
const DEPENDENCY_LAYOUT_HINT = "A package could not be resolved in the copy of the committed tree. That points at the dependency layout (node_modules is linked package by package, so a hoisted or linked layout may not resolve), not at a file missing from the commit. Check `opdk build` resolves it in the plugin folder, or skip the check with --no-reproducible.";
|
|
114
|
+
/** The hint for a committed-tree build that failed: a missing file for a relative import, the dependency layout for a package. */
|
|
115
|
+
export function committedBuildHint(message, details) {
|
|
116
|
+
const text = [message, ...(details ?? [])].join("\n");
|
|
117
|
+
const specifiers = [...text.matchAll(/Could not resolve "([^"]+)"/g)].map((match) => match[1] ?? "");
|
|
118
|
+
const bare = specifiers.some((specifier) => !specifier.startsWith(".") && !specifier.startsWith("/"));
|
|
119
|
+
return bare || text.includes("node_modules/") ? DEPENDENCY_LAYOUT_HINT : NOT_IN_COMMIT_HINT;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The second build is made from the committed tree (`git archive HEAD`) extracted to another folder, and compared
|
|
123
|
+
* with the working-tree build. That catches inputs git does not hold and absolute paths in the output. Without a
|
|
124
|
+
* repository or a commit it builds the working tree again and says that this proves much less.
|
|
125
|
+
*/
|
|
126
|
+
async function reproducibleResult(input, first, tempDir) {
|
|
127
|
+
const workDir = tempDir();
|
|
128
|
+
let tree;
|
|
129
|
+
try {
|
|
130
|
+
tree = input.committed === undefined ? { kind: "unavailable", reason: "the folder is not inside a git repository" } : await input.committed(workDir);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
return {
|
|
134
|
+
group: "reproducible",
|
|
135
|
+
passed: "",
|
|
136
|
+
problems: [errorProblem("reproducible", `the committed tree could not be extracted for the second build: ${error instanceof Error ? error.message : String(error)}`, "Fix the problem above (git and tar must work), or skip the check with --no-reproducible.")],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const outDir = path.join(workDir, "out");
|
|
140
|
+
mkdirSync(outDir);
|
|
141
|
+
const problems = [];
|
|
142
|
+
let comparison;
|
|
143
|
+
let causes;
|
|
144
|
+
let second;
|
|
145
|
+
if (tree.kind === "ready") {
|
|
146
|
+
comparison = `the working-tree build and a build of the committed tree (HEAD ${tree.commit}) extracted to another folder`;
|
|
147
|
+
causes = LIKELY_CAUSES;
|
|
148
|
+
// The packages of node_modules are symlinks there: keep the paths as written so the real folder does not leak into the output.
|
|
149
|
+
second = await buildOnce(tree.dir, input.build, outDir, { preserveSymlinks: true });
|
|
150
|
+
if (!second.ok) {
|
|
151
|
+
return {
|
|
152
|
+
group: "reproducible",
|
|
153
|
+
passed: "",
|
|
154
|
+
problems: [
|
|
155
|
+
errorProblem("reproducible", `the committed tree (HEAD ${tree.commit}) does not build, although the working tree does: ${second.problem.message}`, committedBuildHint(second.problem.message, second.problem.details), second.problem.details),
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
comparison = "two builds of the working tree";
|
|
162
|
+
causes = LIKELY_CAUSES_SAME_TREE;
|
|
163
|
+
problems.push(warningProblem("reproducible", `${tree.reason.includes("compared two builds") ? tree.reason : `${tree.reason}, so the committed tree could not be compared: two builds of the working tree were`}. That cannot see files git does not hold or absolute paths.`, tree.hint ?? "Run the check in a git repository with at least one commit."));
|
|
164
|
+
second = await buildOnce(input.cwd, input.build, outDir);
|
|
165
|
+
if (!second.ok) {
|
|
166
|
+
return { group: "reproducible", passed: "", problems: [...problems, { ...second.problem, group: "reproducible" }] };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const pairs = [["main.js", first.mainJs, second.built.mainJs]];
|
|
170
|
+
if (first.css !== undefined && second.built.css !== undefined) {
|
|
171
|
+
pairs.push(["styles.css", first.css, second.built.css]);
|
|
172
|
+
}
|
|
173
|
+
const dirty = tree.kind === "ready" ? tree.uncommitted : [];
|
|
174
|
+
for (const [file, a, b] of pairs) {
|
|
175
|
+
const difference = firstDifference(a, b);
|
|
176
|
+
if (difference !== undefined) {
|
|
177
|
+
const shown = dirty.slice(0, 3).map((line) => line.trim()).join(", ");
|
|
178
|
+
const uncommitted = dirty.length > 0 ? ` The working tree has ${String(dirty.length)} uncommitted change(s) (${shown}${dirty.length > 3 ? ", ..." : ""}): commit them first to rule them out.` : "";
|
|
179
|
+
problems.push(errorProblem("reproducible", describeDifference(file, comparison, a, b, difference), `${causes}${uncommitted}`));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const note = dirty.length > 0 ? `; ${String(dirty.length)} uncommitted change(s) are not in the committed tree` : "";
|
|
183
|
+
return { group: "reproducible", passed: `${pairs.map(([file]) => file).join(", ")} identical byte for byte between ${comparison}${note}`, problems };
|
|
184
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Problem } from "./problems.js";
|
|
2
|
+
/**
|
|
3
|
+
* The scripts the community directory tries, in its order (external.md, FAQ source 2026-08-07): the first one that
|
|
4
|
+
* exists is what rebuilds `main.js` from the tagged commit.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DIRECTORY_BUILD_SCRIPTS: readonly ["build", "build:plugin", "compile"];
|
|
7
|
+
/**
|
|
8
|
+
* Warns when the script the directory runs does not call `opdk build`. The release check builds with the kit's
|
|
9
|
+
* options, but the directory builds with that script, so a different script can produce other bytes. A script that
|
|
10
|
+
* only calls another npm script is not followed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkBuildScript(packageJson: unknown): Problem[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { warningProblem } from "./problems.js";
|
|
2
|
+
import { asRecord } from "./json.js";
|
|
3
|
+
/**
|
|
4
|
+
* The scripts the community directory tries, in its order (external.md, FAQ source 2026-08-07): the first one that
|
|
5
|
+
* exists is what rebuilds `main.js` from the tagged commit.
|
|
6
|
+
*/
|
|
7
|
+
export const DIRECTORY_BUILD_SCRIPTS = ["build", "build:plugin", "compile"];
|
|
8
|
+
/** `opdk build` as a command, not `opdk build-css`, and not the dev-vault build. */
|
|
9
|
+
const PRODUCTION_BUILD = /\bopdk\s+build(?![\w-])(?!.*--(?:vault|watch))/;
|
|
10
|
+
/**
|
|
11
|
+
* Warns when the script the directory runs does not call `opdk build`. The release check builds with the kit's
|
|
12
|
+
* options, but the directory builds with that script, so a different script can produce other bytes. A script that
|
|
13
|
+
* only calls another npm script is not followed.
|
|
14
|
+
*/
|
|
15
|
+
export function checkBuildScript(packageJson) {
|
|
16
|
+
const scripts = asRecord(asRecord(packageJson)?.scripts) ?? {};
|
|
17
|
+
const name = DIRECTORY_BUILD_SCRIPTS.find((candidate) => typeof scripts[candidate] === "string");
|
|
18
|
+
if (name === undefined) {
|
|
19
|
+
return [
|
|
20
|
+
warningProblem("build", `package.json has none of the scripts ${DIRECTORY_BUILD_SCRIPTS.map((script) => `"${script}"`).join(", ")}, so the community directory has nothing to rebuild main.js with.`, 'Add "build": "opdk build" to scripts in package.json.'),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
const command = String(scripts[name]);
|
|
24
|
+
if (PRODUCTION_BUILD.test(command)) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return [
|
|
28
|
+
warningProblem("build", `package.json scripts.${name} is "${command}" and does not run \`opdk build\`. The directory rebuilds main.js with that script, so the bytes this check builds with the kit may not be the ones it compares.`, `Make scripts.${name} "opdk build", or call \`opdk build\` from it (a script that only calls another npm script is not followed).`),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ResolvedBuild } from "../build/options.js";
|
|
2
|
+
import type { RunGit } from "./git.js";
|
|
3
|
+
import type { CleanupSet } from "./interrupt.js";
|
|
4
|
+
/** The files a release of the tagged commit must carry, as this machine builds them. */
|
|
5
|
+
export interface TaggedBuild {
|
|
6
|
+
readonly commit: string;
|
|
7
|
+
readonly mainJs: Buffer;
|
|
8
|
+
/** Undefined when the plugin has no CSS. */
|
|
9
|
+
readonly css: Buffer | undefined;
|
|
10
|
+
/** The `manifest.json` committed at the plugin root of the tag. */
|
|
11
|
+
readonly manifest: Buffer;
|
|
12
|
+
}
|
|
13
|
+
export interface TaggedBuildInput {
|
|
14
|
+
readonly cwd: string;
|
|
15
|
+
readonly run: RunGit;
|
|
16
|
+
readonly version: string;
|
|
17
|
+
readonly build: ResolvedBuild;
|
|
18
|
+
readonly cleanups: CleanupSet;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A production build of the commit the tag points at: `git archive <tag>` extracted to a temp folder, built with
|
|
22
|
+
* the options of `opdk build`, the same way the reproducibility check builds the committed tree. The release assets
|
|
23
|
+
* must equal these bytes, which also proves the workflow built the tag and nothing else. The temp folder is removed
|
|
24
|
+
* when this returns, fails, or Ctrl+C arrives.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildTagged({ cwd, run, version, build, cleanups }: TaggedBuildInput): Promise<TaggedBuild>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { buildOnce } from "./build-check.js";
|
|
5
|
+
import { extractCommittedTree } from "./committed-tree.js";
|
|
6
|
+
const readIfPresent = (file) => {
|
|
7
|
+
try {
|
|
8
|
+
return readFileSync(file);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A production build of the commit the tag points at: `git archive <tag>` extracted to a temp folder, built with
|
|
19
|
+
* the options of `opdk build`, the same way the reproducibility check builds the committed tree. The release assets
|
|
20
|
+
* must equal these bytes, which also proves the workflow built the tag and nothing else. The temp folder is removed
|
|
21
|
+
* when this returns, fails, or Ctrl+C arrives.
|
|
22
|
+
*/
|
|
23
|
+
export async function buildTagged({ cwd, run, version, build, cleanups }) {
|
|
24
|
+
// The real path: esbuild writes `../..` paths for files it reaches through the /var -> /private/var symlink of macOS.
|
|
25
|
+
const workDir = mkdtempSync(path.join(realpathSync(tmpdir()), "opdk-release-"));
|
|
26
|
+
const remove = () => {
|
|
27
|
+
rmSync(workDir, { recursive: true, force: true });
|
|
28
|
+
};
|
|
29
|
+
const unregister = cleanups.add(remove);
|
|
30
|
+
try {
|
|
31
|
+
const tree = await extractCommittedTree({ cwd, run, workDir, overlay: [], ref: `refs/tags/${version}` });
|
|
32
|
+
if (tree.kind === "unavailable") {
|
|
33
|
+
throw new Error(`the tag ${version} cannot be built for the comparison: ${tree.reason}.${tree.hint === undefined ? "" : ` ${tree.hint}`}`);
|
|
34
|
+
}
|
|
35
|
+
const outDir = path.join(workDir, "out");
|
|
36
|
+
mkdirSync(outDir);
|
|
37
|
+
const outcome = await buildOnce(tree.dir, build, outDir, { preserveSymlinks: true });
|
|
38
|
+
if (!outcome.ok) {
|
|
39
|
+
throw new Error(`the tag ${version} does not build: ${outcome.problem.message}${(outcome.problem.details ?? []).map((line) => `\n${line}`).join("")}`);
|
|
40
|
+
}
|
|
41
|
+
const committedCss = readIfPresent(path.resolve(tree.dir, build.css === false ? "styles.css" : build.css.outfile));
|
|
42
|
+
const manifest = readIfPresent(path.join(tree.dir, "manifest.json"));
|
|
43
|
+
if (manifest === undefined) {
|
|
44
|
+
throw new Error(`the tag ${version} has no manifest.json at the plugin root.`);
|
|
45
|
+
}
|
|
46
|
+
return { commit: tree.commit, mainJs: outcome.built.mainJs, css: outcome.built.css ?? committedCss, manifest };
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
unregister();
|
|
50
|
+
remove();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProjectFiles } from "./project-files.js";
|
|
2
|
+
/** A file the bump rewrites: its path relative to the plugin root, and its text before and after. */
|
|
3
|
+
export interface PlannedFile {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
/** Undefined when the file does not exist yet (versions.json in a plugin that has none). */
|
|
6
|
+
readonly before: string | undefined;
|
|
7
|
+
readonly after: string;
|
|
8
|
+
}
|
|
9
|
+
export interface BumpPlanInput {
|
|
10
|
+
readonly files: ProjectFiles;
|
|
11
|
+
readonly changelogFile: string;
|
|
12
|
+
/** The version to release. */
|
|
13
|
+
readonly version: string;
|
|
14
|
+
/** `YYYY-MM-DD`, for the changelog heading. */
|
|
15
|
+
readonly date: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The new text of every file a release changes: `package.json`, `package-lock.json` (both version fields),
|
|
19
|
+
* `manifest.json`, `versions.json` (the new version is added; an existing entry is never rewritten) and the
|
|
20
|
+
* changelog. Pure: nothing is written here. Throws when a file is not in a shape it can edit.
|
|
21
|
+
*/
|
|
22
|
+
export declare function planBump({ files, changelogFile, version, date }: BumpPlanInput): PlannedFile[];
|
|
23
|
+
/** `2026-11-11` for the local date of `now`. */
|
|
24
|
+
export declare function formatDate(now: Date): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { promoteUnreleased } from "./changelog.js";
|
|
2
|
+
import { asRecord, stringifyLike } from "./json.js";
|
|
3
|
+
function okJson(loaded, name) {
|
|
4
|
+
const value = loaded.kind === "ok" ? asRecord(loaded.value) : undefined;
|
|
5
|
+
if (loaded.kind !== "ok" || value === undefined) {
|
|
6
|
+
throw new Error(`${name} cannot be read as a JSON object.`);
|
|
7
|
+
}
|
|
8
|
+
return { text: loaded.text, value };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The new text of every file a release changes: `package.json`, `package-lock.json` (both version fields),
|
|
12
|
+
* `manifest.json`, `versions.json` (the new version is added; an existing entry is never rewritten) and the
|
|
13
|
+
* changelog. Pure: nothing is written here. Throws when a file is not in a shape it can edit.
|
|
14
|
+
*/
|
|
15
|
+
export function planBump({ files, changelogFile, version, date }) {
|
|
16
|
+
const planned = [];
|
|
17
|
+
const pkg = okJson(files.packageJson, "package.json");
|
|
18
|
+
planned.push({ path: "package.json", before: pkg.text, after: stringifyLike(pkg.text, pkg.value, { ...pkg.value, version }, "package.json") });
|
|
19
|
+
if (files.lock.kind === "ok") {
|
|
20
|
+
const lock = okJson(files.lock, "package-lock.json");
|
|
21
|
+
const packages = asRecord(lock.value.packages);
|
|
22
|
+
const root = asRecord(packages?.[""]);
|
|
23
|
+
const changed = {
|
|
24
|
+
...lock.value,
|
|
25
|
+
version,
|
|
26
|
+
...(packages !== undefined && root !== undefined && { packages: { ...packages, "": { ...root, version } } }),
|
|
27
|
+
};
|
|
28
|
+
planned.push({ path: "package-lock.json", before: lock.text, after: stringifyLike(lock.text, lock.value, changed, "package-lock.json") });
|
|
29
|
+
}
|
|
30
|
+
const manifest = okJson(files.manifest, "manifest.json");
|
|
31
|
+
const minAppVersion = manifest.value.minAppVersion;
|
|
32
|
+
if (typeof minAppVersion !== "string") {
|
|
33
|
+
throw new Error("manifest.json has no minAppVersion to map the new version to.");
|
|
34
|
+
}
|
|
35
|
+
planned.push({ path: "manifest.json", before: manifest.text, after: stringifyLike(manifest.text, manifest.value, { ...manifest.value, version }, "manifest.json") });
|
|
36
|
+
if (files.versions.kind === "ok") {
|
|
37
|
+
const versions = okJson(files.versions, "versions.json");
|
|
38
|
+
if (!Object.hasOwn(versions.value, version)) {
|
|
39
|
+
planned.push({ path: "versions.json", before: versions.text, after: stringifyLike(versions.text, versions.value, { ...versions.value, [version]: minAppVersion }, "versions.json") });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (files.versions.kind === "missing") {
|
|
43
|
+
planned.push({ path: "versions.json", before: undefined, after: `${JSON.stringify({ [version]: minAppVersion }, null, 2)}\n` });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(`versions.json is not valid JSON: ${files.versions.message}.`);
|
|
47
|
+
}
|
|
48
|
+
if (files.changelog === undefined) {
|
|
49
|
+
throw new Error(`${changelogFile} does not exist.`);
|
|
50
|
+
}
|
|
51
|
+
planned.push({ path: changelogFile, before: files.changelog, after: promoteUnreleased(files.changelog, version, date) });
|
|
52
|
+
return planned;
|
|
53
|
+
}
|
|
54
|
+
/** `2026-11-11` for the local date of `now`. */
|
|
55
|
+
export function formatDate(now) {
|
|
56
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
57
|
+
return `${String(now.getFullYear())}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Problem } from "./problems.js";
|
|
2
|
+
/**
|
|
3
|
+
* The CHANGELOG rule: a `## [x.y.z]` section for the version with at least one entry. The kit's CHANGELOG is
|
|
4
|
+
* written by hand, and the section is what the release notes are taken from.
|
|
5
|
+
*/
|
|
6
|
+
export declare function checkChangelog(text: string | undefined, version: string, file: string): Problem[];
|
|
7
|
+
/**
|
|
8
|
+
* The body of the `## [version]` section: what the release notes show. The heading, the date and the link
|
|
9
|
+
* footer are left out, `###` subheadings stay, and the blank lines around the body are trimmed. Undefined when
|
|
10
|
+
* the section does not exist; an empty string when it has no text.
|
|
11
|
+
*/
|
|
12
|
+
export declare function releaseNotes(text: string, version: string): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The `## [x.y.z]` sections above `from` (exclusive; every version when undefined) up to `to` (inclusive), newest
|
|
15
|
+
* first, each as its heading line plus body. For showing someone else's changelog; nothing is rewritten.
|
|
16
|
+
*/
|
|
17
|
+
export declare function sectionsBetween(text: string, from: string | undefined, to: string): string[];
|
|
18
|
+
/** Why `[Unreleased]` cannot be released, or undefined when it has entries. */
|
|
19
|
+
export declare function unreleasedProblem(text: string | undefined, file: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Moves the entries of `[Unreleased]` under `## [version] - date` and leaves an empty `[Unreleased]` above it. When
|
|
22
|
+
* the footer has an `[Unreleased]: <base>/compare/<tag>...<head>` link, it points at the new version and a link
|
|
23
|
+
* for the new version is added after it (compared with the version of the section below, else the release page).
|
|
24
|
+
*/
|
|
25
|
+
export declare function promoteUnreleased(text: string, version: string, date: string): string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { errorProblem } from "./problems.js";
|
|
2
|
+
import { compareVersions } from "./semver.js";
|
|
3
|
+
const GROUP = "changelog";
|
|
4
|
+
const HEADING = /^## \[([^\]]+)\]/;
|
|
5
|
+
const LINK_DEFINITION = /^\[[^\]]+\]:\s*\S+/;
|
|
6
|
+
const UNRELEASED_LINK = /^\[Unreleased\]:\s*(\S+?)\/compare\/(\S+?)\.\.\.(\S+)\s*$/;
|
|
7
|
+
function eolOf(text) {
|
|
8
|
+
return text.includes("\r\n") ? "\r\n" : "\n";
|
|
9
|
+
}
|
|
10
|
+
function splitLines(text) {
|
|
11
|
+
return text.split(/\r?\n/);
|
|
12
|
+
}
|
|
13
|
+
/** Index where the trailing block of link definitions (`[1.0.0]: https://...`) starts, or `lines.length`. */
|
|
14
|
+
function footerStart(lines) {
|
|
15
|
+
let start = lines.length;
|
|
16
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
17
|
+
const line = lines[index] ?? "";
|
|
18
|
+
if (LINK_DEFINITION.test(line)) {
|
|
19
|
+
start = index;
|
|
20
|
+
}
|
|
21
|
+
else if (line.trim() !== "") {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return start;
|
|
26
|
+
}
|
|
27
|
+
function findSections(lines) {
|
|
28
|
+
const footer = footerStart(lines);
|
|
29
|
+
const headings = lines.flatMap((line, index) => {
|
|
30
|
+
const match = HEADING.exec(line);
|
|
31
|
+
return match?.[1] === undefined ? [] : [{ title: match[1], heading: index }];
|
|
32
|
+
});
|
|
33
|
+
return headings.map((entry, position) => ({
|
|
34
|
+
...entry,
|
|
35
|
+
end: Math.min(headings[position + 1]?.heading ?? lines.length, Math.max(footer, entry.heading + 1)),
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** Lines that say something: not blank, not a `###` heading. */
|
|
39
|
+
function entryCount(lines, section) {
|
|
40
|
+
return lines.slice(section.heading + 1, section.end).filter((line) => line.trim() !== "" && !line.startsWith("#")).length;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The CHANGELOG rule: a `## [x.y.z]` section for the version with at least one entry. The kit's CHANGELOG is
|
|
44
|
+
* written by hand, and the section is what the release notes are taken from.
|
|
45
|
+
*/
|
|
46
|
+
export function checkChangelog(text, version, file) {
|
|
47
|
+
if (text === undefined) {
|
|
48
|
+
return [errorProblem(GROUP, `${file} is missing.`, `Create it with a "## [${version}]" section (Keep a Changelog format).`)];
|
|
49
|
+
}
|
|
50
|
+
const lines = splitLines(text);
|
|
51
|
+
const section = findSections(lines).find((candidate) => candidate.title === version);
|
|
52
|
+
if (section === undefined) {
|
|
53
|
+
return [errorProblem(GROUP, `${file} has no "## [${version}]" section.`, `Move the entries from "## [Unreleased]" under "## [${version}] - YYYY-MM-DD", or run \`opdk release <patch|minor|major>\`.`)];
|
|
54
|
+
}
|
|
55
|
+
if (entryCount(lines, section) === 0) {
|
|
56
|
+
return [errorProblem(GROUP, `the "## [${version}]" section of ${file} has no entries.`, "Say what changed in this version.")];
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The body of the `## [version]` section: what the release notes show. The heading, the date and the link
|
|
62
|
+
* footer are left out, `###` subheadings stay, and the blank lines around the body are trimmed. Undefined when
|
|
63
|
+
* the section does not exist; an empty string when it has no text.
|
|
64
|
+
*/
|
|
65
|
+
export function releaseNotes(text, version) {
|
|
66
|
+
const lines = splitLines(text);
|
|
67
|
+
const section = findSections(lines).find((candidate) => candidate.title === version);
|
|
68
|
+
if (section === undefined) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return lines.slice(section.heading + 1, section.end).join("\n").trim();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The `## [x.y.z]` sections above `from` (exclusive; every version when undefined) up to `to` (inclusive), newest
|
|
75
|
+
* first, each as its heading line plus body. For showing someone else's changelog; nothing is rewritten.
|
|
76
|
+
*/
|
|
77
|
+
export function sectionsBetween(text, from, to) {
|
|
78
|
+
const lines = splitLines(text);
|
|
79
|
+
return findSections(lines)
|
|
80
|
+
.filter((section) => {
|
|
81
|
+
const aboveFrom = from === undefined ? 1 : compareVersions(section.title, from);
|
|
82
|
+
const belowTo = compareVersions(section.title, to);
|
|
83
|
+
return aboveFrom !== undefined && aboveFrom > 0 && belowTo !== undefined && belowTo <= 0;
|
|
84
|
+
})
|
|
85
|
+
.map((section) => lines.slice(section.heading, section.end).join("\n").trim());
|
|
86
|
+
}
|
|
87
|
+
/** Why `[Unreleased]` cannot be released, or undefined when it has entries. */
|
|
88
|
+
export function unreleasedProblem(text, file) {
|
|
89
|
+
if (text === undefined) {
|
|
90
|
+
return `${file} is missing. Create it with a "## [Unreleased]" section that lists the changes.`;
|
|
91
|
+
}
|
|
92
|
+
const lines = splitLines(text);
|
|
93
|
+
const section = findSections(lines).find((candidate) => candidate.title.toLowerCase() === "unreleased");
|
|
94
|
+
if (section === undefined) {
|
|
95
|
+
return `${file} has no "## [Unreleased]" section. Add one and list the changes of the release in it.`;
|
|
96
|
+
}
|
|
97
|
+
if (entryCount(lines, section) === 0) {
|
|
98
|
+
return `the "## [Unreleased]" section of ${file} has no entries. Write down what changed before releasing.`;
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Moves the entries of `[Unreleased]` under `## [version] - date` and leaves an empty `[Unreleased]` above it. When
|
|
104
|
+
* the footer has an `[Unreleased]: <base>/compare/<tag>...<head>` link, it points at the new version and a link
|
|
105
|
+
* for the new version is added after it (compared with the version of the section below, else the release page).
|
|
106
|
+
*/
|
|
107
|
+
export function promoteUnreleased(text, version, date) {
|
|
108
|
+
const eol = eolOf(text);
|
|
109
|
+
const lines = splitLines(text);
|
|
110
|
+
const sections = findSections(lines);
|
|
111
|
+
const index = sections.findIndex((candidate) => candidate.title.toLowerCase() === "unreleased");
|
|
112
|
+
const unreleased = sections[index];
|
|
113
|
+
if (unreleased === undefined) {
|
|
114
|
+
throw new Error('The changelog has no "## [Unreleased]" section.');
|
|
115
|
+
}
|
|
116
|
+
const body = lines.slice(unreleased.heading + 1, unreleased.end);
|
|
117
|
+
while (body[0]?.trim() === "") {
|
|
118
|
+
body.shift();
|
|
119
|
+
}
|
|
120
|
+
while (body.at(-1)?.trim() === "") {
|
|
121
|
+
body.pop();
|
|
122
|
+
}
|
|
123
|
+
const after = lines.slice(unreleased.end);
|
|
124
|
+
const previous = sections[index + 1]?.title;
|
|
125
|
+
const result = [
|
|
126
|
+
...lines.slice(0, unreleased.heading),
|
|
127
|
+
"## [Unreleased]",
|
|
128
|
+
"",
|
|
129
|
+
`## [${version}] - ${date}`,
|
|
130
|
+
"",
|
|
131
|
+
...body,
|
|
132
|
+
...(after.length > 0 && after[0] !== "" ? [""] : []),
|
|
133
|
+
...after,
|
|
134
|
+
];
|
|
135
|
+
const promoted = updateFooter(result, version, previous).join(eol);
|
|
136
|
+
return text.endsWith("\n") && !promoted.endsWith("\n") ? `${promoted}${eol}` : promoted;
|
|
137
|
+
}
|
|
138
|
+
function updateFooter(lines, version, previous) {
|
|
139
|
+
const at = lines.findIndex((line) => UNRELEASED_LINK.test(line));
|
|
140
|
+
const match = UNRELEASED_LINK.exec(lines[at] ?? "");
|
|
141
|
+
const base = match?.[1];
|
|
142
|
+
const head = match?.[3];
|
|
143
|
+
if (at < 0 || base === undefined || head === undefined || lines.some((line) => line.startsWith(`[${version}]:`))) {
|
|
144
|
+
return lines;
|
|
145
|
+
}
|
|
146
|
+
const compare = previous !== undefined && /^\d+\.\d+\.\d+/.test(previous) ? `${base}/compare/${previous}...${version}` : `${base}/releases/tag/${version}`;
|
|
147
|
+
return [...lines.slice(0, at), `[Unreleased]: ${base}/compare/${version}...${head}`, `[${version}]: ${compare}`, ...lines.slice(at + 1)];
|
|
148
|
+
}
|