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,115 @@
|
|
|
1
|
+
import obsidianmd from "eslint-plugin-obsidianmd";
|
|
2
|
+
/**
|
|
3
|
+
* What every plugin on the kit leaves out of linting (the intersection of their lists, not the union): dependencies and build output, unit-test files, e2e folders, scripts, and the config files of the test
|
|
4
|
+
* runners (they are not in the tsconfig). Paths only some plugins have (`site/**`, `.preview/**`,
|
|
5
|
+
* `src/test/**`, `tools/**`, `integration/**`) belong in that plugin's `ignores` option.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_IGNORES = [
|
|
8
|
+
"node_modules/**",
|
|
9
|
+
"coverage/**",
|
|
10
|
+
"dist/**",
|
|
11
|
+
"main.js",
|
|
12
|
+
"scripts/**",
|
|
13
|
+
"src/**/*.test.ts",
|
|
14
|
+
"vitest.config.ts",
|
|
15
|
+
"e2e/**",
|
|
16
|
+
"e2e-vault.pristine/**",
|
|
17
|
+
"playwright.config.ts",
|
|
18
|
+
".obsidian-unpacked/**",
|
|
19
|
+
"design/**",
|
|
20
|
+
];
|
|
21
|
+
/** Applies the defaults and rejects values of the wrong type, naming the option. */
|
|
22
|
+
export function resolveOptions(options, cwd) {
|
|
23
|
+
const known = ["rootDir", "tsconfig", "ignores"];
|
|
24
|
+
const unknownKeys = Object.keys(options).filter((key) => !known.includes(key));
|
|
25
|
+
if (unknownKeys.length > 0) {
|
|
26
|
+
throw new Error(`obsidianPlugin(): unknown option(s): ${unknownKeys.join(", ")}. Allowed options: ${known.join(", ")}.`);
|
|
27
|
+
}
|
|
28
|
+
const { rootDir = cwd, tsconfig = "./tsconfig.json" } = options;
|
|
29
|
+
const extra = options.ignores ?? [];
|
|
30
|
+
if (typeof rootDir !== "string" || rootDir === "") {
|
|
31
|
+
throw new Error('obsidianPlugin(): "rootDir" must be a non-empty string, for example import.meta.dirname.');
|
|
32
|
+
}
|
|
33
|
+
if (typeof tsconfig !== "string" || tsconfig === "") {
|
|
34
|
+
throw new Error('obsidianPlugin(): "tsconfig" must be a non-empty string such as "./tsconfig.json".');
|
|
35
|
+
}
|
|
36
|
+
if (!isGlobList(extra)) {
|
|
37
|
+
throw new Error('obsidianPlugin(): "ignores" must be an array of non-empty glob strings.');
|
|
38
|
+
}
|
|
39
|
+
return { rootDir, tsconfig, ignores: [...DEFAULT_IGNORES, ...extra] };
|
|
40
|
+
}
|
|
41
|
+
function isGlobList(value) {
|
|
42
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" && item !== "");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `window.<member>` is allowed for these: `window.open` and the timer functions (`obsidianmd/prefer-window-timers`
|
|
46
|
+
* wants the timers on `window`, a popout window's timer resolves through its own closure).
|
|
47
|
+
*/
|
|
48
|
+
const WINDOW_MEMBER_EXCEPTIONS = "open|setTimeout|clearTimeout|setInterval|clearInterval|requestAnimationFrame|cancelAnimationFrame";
|
|
49
|
+
/** Selector of `no-restricted-syntax` below. A computed access (`window["x"]`) has no `property.name`, so it is reported. */
|
|
50
|
+
export const BARE_WINDOW_SELECTOR = `MemberExpression[object.name='window']:not([property.name=/^(${WINDOW_MEMBER_EXCEPTIONS})$/])`;
|
|
51
|
+
/**
|
|
52
|
+
* The lint setup the kit's plugins share, as a flat config to spread into the plugin's own
|
|
53
|
+
* `eslint.config.js`:
|
|
54
|
+
*
|
|
55
|
+
* ```js
|
|
56
|
+
* import { obsidianPlugin } from "obsidian-plugin-dev-kit/eslint";
|
|
57
|
+
* export default [...obsidianPlugin({ rootDir: import.meta.dirname })];
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* It is eslint-plugin-obsidianmd's `recommended` preset as is (that carries ESLint's core rules and
|
|
61
|
+
* typescript-eslint's `recommendedTypeChecked` for TypeScript), plus the three things all three plugins add:
|
|
62
|
+
* timers on `window` and a settings tab that declares its settings are errors rather than warnings, and unused
|
|
63
|
+
* arguments, variables and caught errors are errors unless they start with `_`. On top of that comes one rule of
|
|
64
|
+
* the kit's own: a bare `window.<member>` is an error (use `activeWindow`; `window.open` and the timer functions
|
|
65
|
+
* are exempt). Turn it off with `"no-restricted-syntax": "off"` in a block after the preset; setting
|
|
66
|
+
* `no-restricted-syntax` yourself replaces it.
|
|
67
|
+
*
|
|
68
|
+
* Do not enable `@typescript-eslint/no-misused-promises` next to it: the preset replaces it with
|
|
69
|
+
* `obsidianmd/no-misused-promises`, which does not count Obsidian's chaining `then` as a Promise.
|
|
70
|
+
*/
|
|
71
|
+
export function obsidianPlugin(options = {}) {
|
|
72
|
+
const { rootDir, tsconfig, ignores } = resolveOptions(options, process.cwd());
|
|
73
|
+
return [
|
|
74
|
+
...obsidianmd.configs.recommended,
|
|
75
|
+
{
|
|
76
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
77
|
+
languageOptions: {
|
|
78
|
+
parserOptions: { project: tsconfig, tsconfigRootDir: rootDir },
|
|
79
|
+
},
|
|
80
|
+
rules: {
|
|
81
|
+
// Timers go through `window`, not `activeWindow`: a popout window gets a `window` that resolves
|
|
82
|
+
// correctly through the timer's own closure.
|
|
83
|
+
"obsidianmd/prefer-window-timers": "error",
|
|
84
|
+
// Presence-only check: it flags a PluginSettingTab without a getSettingDefinitions() method.
|
|
85
|
+
"obsidianmd/settings-tab/prefer-setting-definitions": "error",
|
|
86
|
+
// A bare `window` is the main window, which is the wrong one in a popout window, where
|
|
87
|
+
// `activeWindow` is the right one. Plain Obsidian behaviour that every plugin meets. The
|
|
88
|
+
// community scanner does not report it (`prefer-active-doc` covers `document` only), so this is
|
|
89
|
+
// the kit's own rule, not scanner parity. A handler parameter named `window` (the second argument
|
|
90
|
+
// of `workspace.on("window-open")`) is the popout's own window but is reported all the same:
|
|
91
|
+
// rename the binding.
|
|
92
|
+
"no-restricted-syntax": [
|
|
93
|
+
"error",
|
|
94
|
+
{
|
|
95
|
+
selector: BARE_WINDOW_SELECTOR,
|
|
96
|
+
message: "A bare `window.*` refers to the main window, not the popout window the code runs in. Use `activeWindow.*` (`window.open` and the timer functions are the only exceptions). If `window` is a handler parameter, rename it.",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
// Match the scanner's strict no-unused-vars policy: every declared argument must be used (or
|
|
100
|
+
// start with `_`).
|
|
101
|
+
"@typescript-eslint/no-unused-vars": [
|
|
102
|
+
"error",
|
|
103
|
+
{
|
|
104
|
+
args: "all",
|
|
105
|
+
argsIgnorePattern: "^_",
|
|
106
|
+
varsIgnorePattern: "^_",
|
|
107
|
+
caughtErrors: "all",
|
|
108
|
+
caughtErrorsIgnorePattern: "^_",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{ ignores },
|
|
114
|
+
];
|
|
115
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig } from "./config/define-config.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface UpgradeArgs {
|
|
2
|
+
/** `vX.Y.Z`; undefined means the latest release. */
|
|
3
|
+
readonly target: string | undefined;
|
|
4
|
+
readonly dryRun: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** Parses what follows `opdk kit upgrade`. `0.2.0` and `v0.2.0` both mean the tag `v0.2.0`. */
|
|
7
|
+
export declare function parseUpgradeArgs(args: readonly string[]): UpgradeArgs;
|
package/dist/kit/args.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const USAGE_HINT = 'Run "opdk kit --help".';
|
|
2
|
+
/** Parses what follows `opdk kit upgrade`. `0.2.0` and `v0.2.0` both mean the tag `v0.2.0`. */
|
|
3
|
+
export function parseUpgradeArgs(args) {
|
|
4
|
+
let target;
|
|
5
|
+
let dryRun = false;
|
|
6
|
+
for (const arg of args) {
|
|
7
|
+
if (arg === "--dry-run") {
|
|
8
|
+
dryRun = true;
|
|
9
|
+
}
|
|
10
|
+
else if (/^v?\d+\.\d+\.\d+$/.test(arg) && target === undefined) {
|
|
11
|
+
target = arg.startsWith("v") ? arg : `v${arg}`;
|
|
12
|
+
}
|
|
13
|
+
else if (arg.startsWith("-")) {
|
|
14
|
+
throw new Error(`Unknown option "${arg}" for "opdk kit upgrade". ${USAGE_HINT}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
throw new Error(`"${arg}" is not a kit release tag${target === undefined ? "" : " (one is enough)"}. Write it like v0.2.0, or leave it out for the latest release. ${USAGE_HINT}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { target, dryRun };
|
|
21
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createRunGit } from "../release/git.js";
|
|
2
|
+
import { parseUpgradeArgs } from "./args.js";
|
|
3
|
+
import { createRunNpm, fetchText } from "./runners.js";
|
|
4
|
+
import { runKitUpgrade } from "./upgrade.js";
|
|
5
|
+
const kitUsage = `Usage: opdk kit upgrade [vX.Y.Z] [--dry-run]
|
|
6
|
+
|
|
7
|
+
opdk kit upgrade moves the plugin to a kit release. The kit is pinned in three places, and they must name one
|
|
8
|
+
commit: the tag in package.json, the commit the lockfile resolved it to, and the commit in every
|
|
9
|
+
"uses: <owner>/obsidian-plugin-dev-kit/.github/workflows/<file>@<sha> # vX.Y.Z" line of .github/workflows/*.yml.
|
|
10
|
+
Without a tag it takes the latest vX.Y.Z tag of the kit's repository (git ls-remote --tags, so it needs the
|
|
11
|
+
network and no GitHub login). It:
|
|
12
|
+
- resolves the tag to its commit;
|
|
13
|
+
- rewrites the tag in package.json and runs \`npm install\` for that one package, so the lockfile follows (npm
|
|
14
|
+
builds the kit, which takes a minute); if npm fails, package.json and the lockfile are put back (run \`npm ci\`
|
|
15
|
+
if node_modules looks off); without a lockfile npm does not run and node_modules keeps the old kit;
|
|
16
|
+
- rewrites every kit workflow line of the package.json owner to the new commit and sets its "# vX.Y.Z" comment;
|
|
17
|
+
- runs the "kit" step of \`opdk release check\` on the result;
|
|
18
|
+
- prints the kit's CHANGELOG sections between the old and the new version, read from the tag on GitHub (a
|
|
19
|
+
failure to read them is only reported).
|
|
20
|
+
It never commits or pushes: review the diff, commit on a branch and open a pull request. Configure Dependabot
|
|
21
|
+
to ignore the kit (a bump of one pin alone makes the check fail; see docs/ci.md for the entries) and watch the
|
|
22
|
+
kit's releases on GitHub to learn about a new one.
|
|
23
|
+
|
|
24
|
+
--dry-run prints the lines that would change and the changelog, writes nothing, runs no npm; works on a
|
|
25
|
+
dirty tree and outside a git repository. Without it the tree must be clean.
|
|
26
|
+
|
|
27
|
+
Run \`opdk release check\` to see whether the three places agree (it is part of CI). A plugin that does not use the
|
|
28
|
+
kit's workflows only has package.json and the lockfile to compare.
|
|
29
|
+
`;
|
|
30
|
+
export const kitCommand = {
|
|
31
|
+
name: "kit",
|
|
32
|
+
summary: "Move the plugin to another kit release (package.json, lockfile and workflow pins together)",
|
|
33
|
+
usage: kitUsage,
|
|
34
|
+
async run(args, ctx) {
|
|
35
|
+
const [sub, ...rest] = args;
|
|
36
|
+
if (sub !== "upgrade") {
|
|
37
|
+
throw new Error(`"opdk kit" needs "upgrade", for example "opdk kit upgrade v0.2.0". Run "opdk kit --help".`);
|
|
38
|
+
}
|
|
39
|
+
const parsed = parseUpgradeArgs(rest);
|
|
40
|
+
return runKitUpgrade({
|
|
41
|
+
cwd: ctx.cwd,
|
|
42
|
+
target: parsed.target,
|
|
43
|
+
dryRun: parsed.dryRun,
|
|
44
|
+
reporter: ctx.reporter,
|
|
45
|
+
stdout: (text) => {
|
|
46
|
+
ctx.stdout(text);
|
|
47
|
+
},
|
|
48
|
+
deps: { run: createRunGit(ctx.cwd), npm: createRunNpm(ctx.cwd), fetchText },
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export const kitCommands = [kitCommand];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadText } from "../release/json.js";
|
|
4
|
+
const WORKFLOWS = ".github/workflows";
|
|
5
|
+
/** The workflow files of the plugin, sorted by name. None when the folder does not exist. */
|
|
6
|
+
export function loadWorkflows(cwd) {
|
|
7
|
+
let names;
|
|
8
|
+
try {
|
|
9
|
+
names = readdirSync(path.join(cwd, WORKFLOWS));
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Cannot read ${WORKFLOWS}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
16
|
+
}
|
|
17
|
+
return names
|
|
18
|
+
.filter((name) => /\.ya?ml$/.test(name))
|
|
19
|
+
.sort()
|
|
20
|
+
.flatMap((name) => {
|
|
21
|
+
const text = loadText(path.join(cwd, WORKFLOWS, name));
|
|
22
|
+
return text === undefined ? [] : [{ file: `${WORKFLOWS}/${name}`, text }];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** The kit's own package name: the dependency a plugin declares. */
|
|
2
|
+
export declare const KIT_PACKAGE = "obsidian-plugin-dev-kit";
|
|
3
|
+
export declare function isFullSha(value: string): boolean;
|
|
4
|
+
export declare function shortSha(sha: string): string;
|
|
5
|
+
/** `v0.1.0` and `0.1.0` are one version. */
|
|
6
|
+
export declare function stripV(tag: string): string;
|
|
7
|
+
export interface KitSpec {
|
|
8
|
+
readonly owner: string;
|
|
9
|
+
/** Whatever follows `#`: a tag, a branch or a commit. */
|
|
10
|
+
readonly ref: string;
|
|
11
|
+
}
|
|
12
|
+
/** Undefined when the spec does not point at the kit's repository on GitHub. */
|
|
13
|
+
export declare function parseKitSpec(spec: string): KitSpec | undefined;
|
|
14
|
+
/** The kit as package.json declares it. */
|
|
15
|
+
export interface PackageJsonPin {
|
|
16
|
+
readonly section: string;
|
|
17
|
+
readonly spec: string;
|
|
18
|
+
readonly parsed: KitSpec;
|
|
19
|
+
}
|
|
20
|
+
/** The kit as the lockfile resolved it. */
|
|
21
|
+
export interface LockPin {
|
|
22
|
+
/** The package version at that commit. */
|
|
23
|
+
readonly version: string | undefined;
|
|
24
|
+
/** Undefined when `resolved` does not name a commit. */
|
|
25
|
+
readonly commit: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface UsesPin {
|
|
28
|
+
/** Path relative to the plugin root, with forward slashes. */
|
|
29
|
+
readonly file: string;
|
|
30
|
+
/** 1-based. */
|
|
31
|
+
readonly line: number;
|
|
32
|
+
readonly owner: string;
|
|
33
|
+
/** The ref after `@`: a full commit SHA when pinned properly. */
|
|
34
|
+
readonly ref: string;
|
|
35
|
+
/** The tag the trailing comment names, if it starts with one. */
|
|
36
|
+
readonly commentTag: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
export interface KitPins {
|
|
39
|
+
readonly packageJson: readonly PackageJsonPin[];
|
|
40
|
+
readonly lock: LockPin | undefined;
|
|
41
|
+
readonly uses: readonly UsesPin[];
|
|
42
|
+
}
|
|
43
|
+
export interface WorkflowFile {
|
|
44
|
+
readonly file: string;
|
|
45
|
+
readonly text: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function readPackageJsonPins(packageJson: unknown): PackageJsonPin[];
|
|
48
|
+
export declare function readLockPin(lock: unknown): LockPin | undefined;
|
|
49
|
+
export declare function readUsesPins(workflows: readonly WorkflowFile[]): UsesPin[];
|
|
50
|
+
export declare function readKitPins(input: {
|
|
51
|
+
packageJson: unknown;
|
|
52
|
+
lock: unknown;
|
|
53
|
+
workflows: readonly WorkflowFile[];
|
|
54
|
+
}): KitPins;
|
|
55
|
+
/** What the pins say, and what is wrong with them. */
|
|
56
|
+
export interface PinVerdict {
|
|
57
|
+
/** Reasons the pins disagree, one sentence each. Empty when they agree. */
|
|
58
|
+
readonly reasons: readonly string[];
|
|
59
|
+
/** One line per place that names the kit, for the details under the failure. */
|
|
60
|
+
readonly places: readonly string[];
|
|
61
|
+
/** The tag package.json names, if it names one. */
|
|
62
|
+
readonly tag: string | undefined;
|
|
63
|
+
/** The commit all places agree on, if they do and any names one. */
|
|
64
|
+
readonly commit: string | undefined;
|
|
65
|
+
readonly usesCount: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether package.json, the lockfile and the workflows name one kit release. No network: the lockfile holds the
|
|
69
|
+
* commit, and its `version` stands for the tag (a kit tag is `v` plus the package version).
|
|
70
|
+
*/
|
|
71
|
+
export declare function judgePins(pins: KitPins): PinVerdict;
|
|
72
|
+
export interface TextChange {
|
|
73
|
+
readonly line: number;
|
|
74
|
+
readonly before: string;
|
|
75
|
+
readonly after: string;
|
|
76
|
+
}
|
|
77
|
+
export interface Rewritten {
|
|
78
|
+
readonly text: string;
|
|
79
|
+
readonly changes: readonly TextChange[];
|
|
80
|
+
}
|
|
81
|
+
/** Points every kit dependency spec in package.json at `tag`, keeping the rest of the text as it is. */
|
|
82
|
+
export declare function rewritePackageJson(text: string, tag: string): Rewritten;
|
|
83
|
+
/**
|
|
84
|
+
* Points every `uses: <owner>/obsidian-plugin-dev-kit/.github/workflows/<file>@...` line of that owner (the one in
|
|
85
|
+
* package.json; GitHub names are case-insensitive) at `sha`. A comment that
|
|
86
|
+
* starts with a version gets the new tag; no comment gets `# <tag>` (unless the line is at `sha` already); any other
|
|
87
|
+
* comment stays as written.
|
|
88
|
+
*/
|
|
89
|
+
export declare function rewriteWorkflow(text: string, sha: string, tag: string, wantedOwner: string): Rewritten;
|
package/dist/kit/pins.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { asRecord } from "../release/json.js";
|
|
2
|
+
/** The kit's own package name: the dependency a plugin declares. */
|
|
3
|
+
export const KIT_PACKAGE = "obsidian-plugin-dev-kit";
|
|
4
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
5
|
+
/** A GitHub user or organization name: letters, digits and hyphens, no leading hyphen, 39 characters at most. No dots, so `..` is not an owner. */
|
|
6
|
+
const OWNER = "([A-Za-z0-9][A-Za-z0-9-]{0,38})";
|
|
7
|
+
/** `github:owner/obsidian-plugin-dev-kit#ref`, and the forms npm writes into a lockfile (`git+ssh://git@github.com/...#sha`). */
|
|
8
|
+
const KIT_SPEC = new RegExp(`^(?:github:|(?:git\\+)?(?:ssh://git@|https://)github\\.com/)${OWNER}/obsidian-plugin-dev-kit(?:\\.git)?#(\\S+)$`);
|
|
9
|
+
/** `uses: owner/obsidian-plugin-dev-kit/.github/workflows/file.yml@ref # comment`, with an optional list dash. */
|
|
10
|
+
const USES_LINE = new RegExp(`^(\\s*(?:-\\s+)?uses:\\s+)${OWNER}/obsidian-plugin-dev-kit/(\\.github/workflows/[^\\s@#]+)@([^\\s#]+)(?:(\\s+#\\s*)(.*?))?\\s*$`);
|
|
11
|
+
/** A release tag in a workflow comment: `v0.1.0` or `0.1.0`, followed by nothing or by more text. */
|
|
12
|
+
const COMMENT_TAG = /^(v?\d+\.\d+\.\d+)(?![\w.])/;
|
|
13
|
+
const DEPENDENCY_SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
14
|
+
export function isFullSha(value) {
|
|
15
|
+
return FULL_SHA.test(value);
|
|
16
|
+
}
|
|
17
|
+
export function shortSha(sha) {
|
|
18
|
+
return sha.slice(0, 7);
|
|
19
|
+
}
|
|
20
|
+
/** `v0.1.0` and `0.1.0` are one version. */
|
|
21
|
+
export function stripV(tag) {
|
|
22
|
+
return tag.replace(/^v/, "");
|
|
23
|
+
}
|
|
24
|
+
/** Undefined when the spec does not point at the kit's repository on GitHub. */
|
|
25
|
+
export function parseKitSpec(spec) {
|
|
26
|
+
const match = KIT_SPEC.exec(spec);
|
|
27
|
+
const owner = match?.[1];
|
|
28
|
+
const ref = match?.[2];
|
|
29
|
+
return owner === undefined || ref === undefined ? undefined : { owner, ref };
|
|
30
|
+
}
|
|
31
|
+
export function readPackageJsonPins(packageJson) {
|
|
32
|
+
const root = asRecord(packageJson);
|
|
33
|
+
return DEPENDENCY_SECTIONS.flatMap((section) => {
|
|
34
|
+
const spec = asRecord(root?.[section])?.[KIT_PACKAGE];
|
|
35
|
+
const parsed = typeof spec === "string" ? parseKitSpec(spec) : undefined;
|
|
36
|
+
return typeof spec === "string" && parsed !== undefined ? [{ section, spec, parsed }] : [];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function readLockPin(lock) {
|
|
40
|
+
const entry = asRecord(asRecord(asRecord(lock)?.packages)?.[`node_modules/${KIT_PACKAGE}`]);
|
|
41
|
+
if (entry === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const resolved = typeof entry.resolved === "string" ? parseKitSpec(entry.resolved)?.ref : undefined;
|
|
45
|
+
return { version: typeof entry.version === "string" ? entry.version : undefined, commit: resolved !== undefined && isFullSha(resolved) ? resolved : undefined };
|
|
46
|
+
}
|
|
47
|
+
export function readUsesPins(workflows) {
|
|
48
|
+
return workflows.flatMap(({ file, text }) => text.split("\n").flatMap((raw, index) => {
|
|
49
|
+
const match = USES_LINE.exec(raw.replace(/\r$/, ""));
|
|
50
|
+
const owner = match?.[2];
|
|
51
|
+
const ref = match?.[4];
|
|
52
|
+
if (owner === undefined || ref === undefined) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
return [{ file, line: index + 1, owner, ref, commentTag: COMMENT_TAG.exec(match?.[6] ?? "")?.[1] }];
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
export function readKitPins(input) {
|
|
59
|
+
return { packageJson: readPackageJsonPins(input.packageJson), lock: readLockPin(input.lock), uses: readUsesPins(input.workflows) };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether package.json, the lockfile and the workflows name one kit release. No network: the lockfile holds the
|
|
63
|
+
* commit, and its `version` stands for the tag (a kit tag is `v` plus the package version).
|
|
64
|
+
*/
|
|
65
|
+
export function judgePins(pins) {
|
|
66
|
+
const reasons = [];
|
|
67
|
+
const places = [];
|
|
68
|
+
const commits = new Set();
|
|
69
|
+
const tags = [];
|
|
70
|
+
for (const pin of pins.packageJson) {
|
|
71
|
+
const { ref } = pin.parsed;
|
|
72
|
+
if (isFullSha(ref)) {
|
|
73
|
+
commits.add(ref);
|
|
74
|
+
places.push(`package.json (${pin.section}): commit ${shortSha(ref)}`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
tags.push(ref);
|
|
78
|
+
places.push(`package.json (${pin.section}): ${ref}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (pins.lock !== undefined) {
|
|
82
|
+
if (pins.lock.commit !== undefined) {
|
|
83
|
+
commits.add(pins.lock.commit);
|
|
84
|
+
}
|
|
85
|
+
places.push(`package-lock.json: ${pins.lock.commit === undefined ? "no commit in `resolved`" : `commit ${shortSha(pins.lock.commit)}`}${pins.lock.version === undefined ? "" : `, version ${pins.lock.version}`}`);
|
|
86
|
+
}
|
|
87
|
+
for (const use of pins.uses) {
|
|
88
|
+
const where = `${use.file}:${String(use.line)}`;
|
|
89
|
+
const comment = use.commentTag === undefined ? "" : ` (# ${use.commentTag})`;
|
|
90
|
+
if (isFullSha(use.ref)) {
|
|
91
|
+
commits.add(use.ref);
|
|
92
|
+
places.push(`${where}: commit ${shortSha(use.ref)}${comment}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
reasons.push(`${where} pins the kit's workflow to "${use.ref}", not to a full commit SHA.`);
|
|
96
|
+
places.push(`${where}: ${use.ref}${comment}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (commits.size > 1) {
|
|
100
|
+
reasons.push(`the places below name ${String(commits.size)} different commits of the kit.`);
|
|
101
|
+
}
|
|
102
|
+
const installedOwner = pins.packageJson[0]?.parsed.owner;
|
|
103
|
+
if (installedOwner !== undefined) {
|
|
104
|
+
for (const use of pins.uses) {
|
|
105
|
+
if (use.owner.toLowerCase() !== installedOwner.toLowerCase()) {
|
|
106
|
+
reasons.push(`${use.file}:${String(use.line)} calls ${use.owner}'s kit workflow, but package.json installs ${installedOwner}'s kit; \`opdk kit upgrade\` does not rewrite that line, edit it by hand.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const tag = tags[0];
|
|
111
|
+
const wanted = tag !== undefined ? stripV(tag) : pins.lock?.version;
|
|
112
|
+
if (tag !== undefined && pins.lock?.version !== undefined && stripV(tag) !== pins.lock.version) {
|
|
113
|
+
reasons.push(`package.json asks for ${tag}, but the lockfile holds kit version ${pins.lock.version}.`);
|
|
114
|
+
}
|
|
115
|
+
if (wanted !== undefined) {
|
|
116
|
+
for (const use of pins.uses) {
|
|
117
|
+
if (use.commentTag !== undefined && stripV(use.commentTag) !== wanted) {
|
|
118
|
+
reasons.push(`${use.file}:${String(use.line)} says # ${use.commentTag}, but the kit is at ${wanted}.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { reasons, places, tag, commit: commits.size === 1 ? [...commits][0] : undefined, usesCount: pins.uses.length };
|
|
123
|
+
}
|
|
124
|
+
/** Points every kit dependency spec in package.json at `tag`, keeping the rest of the text as it is. */
|
|
125
|
+
export function rewritePackageJson(text, tag) {
|
|
126
|
+
const changes = [];
|
|
127
|
+
const lines = text.split("\n").map((raw, index) => {
|
|
128
|
+
const cr = raw.endsWith("\r") ? "\r" : "";
|
|
129
|
+
const line = cr === "" ? raw : raw.slice(0, -1);
|
|
130
|
+
const match = /^(\s*"obsidian-plugin-dev-kit"\s*:\s*")([^"]*)(".*)$/.exec(line);
|
|
131
|
+
const spec = match?.[2];
|
|
132
|
+
if (match?.[1] === undefined || spec === undefined || match[3] === undefined || parseKitSpec(spec) === undefined) {
|
|
133
|
+
return raw;
|
|
134
|
+
}
|
|
135
|
+
const after = `${match[1]}${spec.slice(0, spec.lastIndexOf("#") + 1)}${tag}${match[3]}`;
|
|
136
|
+
if (after !== line) {
|
|
137
|
+
changes.push({ line: index + 1, before: line, after });
|
|
138
|
+
}
|
|
139
|
+
return `${after}${cr}`;
|
|
140
|
+
});
|
|
141
|
+
return { text: lines.join("\n"), changes };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Points every `uses: <owner>/obsidian-plugin-dev-kit/.github/workflows/<file>@...` line of that owner (the one in
|
|
145
|
+
* package.json; GitHub names are case-insensitive) at `sha`. A comment that
|
|
146
|
+
* starts with a version gets the new tag; no comment gets `# <tag>` (unless the line is at `sha` already); any other
|
|
147
|
+
* comment stays as written.
|
|
148
|
+
*/
|
|
149
|
+
export function rewriteWorkflow(text, sha, tag, wantedOwner) {
|
|
150
|
+
const changes = [];
|
|
151
|
+
const lines = text.split("\n").map((raw, index) => {
|
|
152
|
+
const cr = raw.endsWith("\r") ? "\r" : "";
|
|
153
|
+
const line = cr === "" ? raw : raw.slice(0, -1);
|
|
154
|
+
const match = USES_LINE.exec(line);
|
|
155
|
+
const prefix = match?.[1];
|
|
156
|
+
const owner = match?.[2];
|
|
157
|
+
const workflow = match?.[3];
|
|
158
|
+
if (prefix === undefined || owner === undefined || workflow === undefined || owner.toLowerCase() !== wantedOwner.toLowerCase()) {
|
|
159
|
+
return raw;
|
|
160
|
+
}
|
|
161
|
+
const comment = match?.[6];
|
|
162
|
+
if (match?.[4] === sha && (comment === undefined || comment === "")) {
|
|
163
|
+
// Already at the commit: the comment is optional, so a missing one is not worth a change.
|
|
164
|
+
return raw;
|
|
165
|
+
}
|
|
166
|
+
const commentTag = comment === undefined ? undefined : COMMENT_TAG.exec(comment)?.[1];
|
|
167
|
+
let tail = ` # ${tag}`;
|
|
168
|
+
if (comment !== undefined && comment !== "") {
|
|
169
|
+
tail = commentTag === undefined ? `${match?.[5] ?? " # "}${comment}` : `${match?.[5] ?? " # "}${tag}${comment.slice(commentTag.length)}`;
|
|
170
|
+
}
|
|
171
|
+
const after = `${prefix}${owner}/obsidian-plugin-dev-kit/${workflow}@${sha}${tail}`;
|
|
172
|
+
if (after !== line) {
|
|
173
|
+
changes.push({ line: index + 1, before: line, after });
|
|
174
|
+
}
|
|
175
|
+
return `${after}${cr}`;
|
|
176
|
+
});
|
|
177
|
+
return { text: lines.join("\n"), changes };
|
|
178
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Tag name to the commit it points at. */
|
|
2
|
+
export type KitTags = ReadonlyMap<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* Reads `git ls-remote --tags` output. An annotated tag is listed twice: the tag object, then `<tag>^{}` with the
|
|
5
|
+
* commit it points at; the commit wins. Only `vX.Y.Z` tags are kept (the kit's release tags).
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseKitTags(output: string): KitTags;
|
|
8
|
+
/** Release tags, highest first. */
|
|
9
|
+
export declare function sortedTags(tags: KitTags): string[];
|
|
10
|
+
/** The highest `vX.Y.Z` tag, or undefined when there is none. */
|
|
11
|
+
export declare function latestTag(tags: KitTags): string | undefined;
|
|
12
|
+
export declare function kitRepositoryUrl(owner: string): string;
|
|
13
|
+
export declare function kitChangelogUrl(owner: string, tag: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { compareVersions, isPlainVersion } from "../release/semver.js";
|
|
2
|
+
import { stripV } from "./pins.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reads `git ls-remote --tags` output. An annotated tag is listed twice: the tag object, then `<tag>^{}` with the
|
|
5
|
+
* commit it points at; the commit wins. Only `vX.Y.Z` tags are kept (the kit's release tags).
|
|
6
|
+
*/
|
|
7
|
+
export function parseKitTags(output) {
|
|
8
|
+
const direct = new Map();
|
|
9
|
+
const peeled = new Map();
|
|
10
|
+
for (const line of output.split("\n")) {
|
|
11
|
+
const match = /^([0-9a-f]{40})\s+refs\/tags\/(v\d+\.\d+\.\d+)(\^\{\})?$/.exec(line.trim());
|
|
12
|
+
const sha = match?.[1];
|
|
13
|
+
const name = match?.[2];
|
|
14
|
+
if (sha !== undefined && name !== undefined) {
|
|
15
|
+
(match?.[3] === undefined ? direct : peeled).set(name, sha);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return new Map([...direct].map(([name, sha]) => [name, peeled.get(name) ?? sha]));
|
|
19
|
+
}
|
|
20
|
+
/** Release tags, highest first. */
|
|
21
|
+
export function sortedTags(tags) {
|
|
22
|
+
return [...tags.keys()].filter((name) => isPlainVersion(stripV(name))).sort((a, b) => compareVersions(stripV(b), stripV(a)) ?? 0);
|
|
23
|
+
}
|
|
24
|
+
/** The highest `vX.Y.Z` tag, or undefined when there is none. */
|
|
25
|
+
export function latestTag(tags) {
|
|
26
|
+
return sortedTags(tags)[0];
|
|
27
|
+
}
|
|
28
|
+
export function kitRepositoryUrl(owner) {
|
|
29
|
+
return `https://github.com/${owner}/obsidian-plugin-dev-kit.git`;
|
|
30
|
+
}
|
|
31
|
+
export function kitChangelogUrl(owner, tag) {
|
|
32
|
+
return `https://raw.githubusercontent.com/${owner}/obsidian-plugin-dev-kit/${tag}/CHANGELOG.md`;
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** `npm install` builds the kit (`prepare`) after downloading it; a slow disk or network gets this long, no longer. */
|
|
2
|
+
export declare const NPM_TIMEOUT_MS: number;
|
|
3
|
+
/** The most of a fetched file that is kept. The kit's CHANGELOG is a few tens of kilobytes. */
|
|
4
|
+
export declare const MAX_FETCH_BYTES: number;
|
|
5
|
+
/** Runs `npm <args>` in `cwd`, ten minutes at most. A failure carries the tail of npm's own output. */
|
|
6
|
+
export declare function createRunNpm(cwd: string, command?: string, timeoutMs?: number): (args: readonly string[]) => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* GET a URL as text, 20 seconds at most. Reads no more than `maxBytes`; a longer body is cut and ends with a note
|
|
9
|
+
* saying so.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fetchText(url: string, maxBytes?: number): Promise<string>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const execFileAsync = promisify(execFile);
|
|
4
|
+
/** `npm install` builds the kit (`prepare`) after downloading it; a slow disk or network gets this long, no longer. */
|
|
5
|
+
export const NPM_TIMEOUT_MS = 10 * 60_000;
|
|
6
|
+
/** The most of a fetched file that is kept. The kit's CHANGELOG is a few tens of kilobytes. */
|
|
7
|
+
export const MAX_FETCH_BYTES = 1024 * 1024;
|
|
8
|
+
/** Runs `npm <args>` in `cwd`, ten minutes at most. A failure carries the tail of npm's own output. */
|
|
9
|
+
export function createRunNpm(cwd, command = "npm", timeoutMs = NPM_TIMEOUT_MS) {
|
|
10
|
+
return async (args) => {
|
|
11
|
+
try {
|
|
12
|
+
await execFileAsync(command, [...args], { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: timeoutMs, shell: process.platform === "win32" });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
16
|
+
throw new Error(`${command} is not installed or not on PATH.`, { cause: error });
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof Error && "killed" in error && error.killed === true) {
|
|
19
|
+
throw new Error(`${command} ${args.join(" ")} did not finish in ${String(timeoutMs / 1000)} seconds and was stopped.`, { cause: error });
|
|
20
|
+
}
|
|
21
|
+
const stderr = error instanceof Error && "stderr" in error && typeof error.stderr === "string" ? error.stderr.trim().split("\n").slice(-8).join("\n") : "";
|
|
22
|
+
throw new Error(`${command} ${args.join(" ")} failed: ${stderr === "" ? String(error) : stderr}`, { cause: error });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* GET a URL as text, 20 seconds at most. Reads no more than `maxBytes`; a longer body is cut and ends with a note
|
|
28
|
+
* saying so.
|
|
29
|
+
*/
|
|
30
|
+
export async function fetchText(url, maxBytes = MAX_FETCH_BYTES) {
|
|
31
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(20_000) });
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`${url} answered ${String(response.status)}`);
|
|
34
|
+
}
|
|
35
|
+
if (response.body === null) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
const chunks = [];
|
|
39
|
+
let size = 0;
|
|
40
|
+
let cut = false;
|
|
41
|
+
for await (const chunk of response.body) {
|
|
42
|
+
const room = maxBytes - size;
|
|
43
|
+
if (chunk.byteLength > room) {
|
|
44
|
+
chunks.push(chunk.subarray(0, room));
|
|
45
|
+
cut = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
chunks.push(chunk);
|
|
49
|
+
size += chunk.byteLength;
|
|
50
|
+
}
|
|
51
|
+
const text = new TextDecoder().decode(Buffer.concat(chunks));
|
|
52
|
+
return cut ? `${text}\n[opdk: ${url} is longer than ${String(maxBytes)} bytes; the rest was not read]\n` : text;
|
|
53
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from the network made safe to print: escape sequences and control characters are removed, newlines and tabs
|
|
3
|
+
* stay. A fetched file could otherwise rewrite the terminal (hide lines, set the title, write the clipboard through
|
|
4
|
+
* OSC 52, plant a link with OSC 8).
|
|
5
|
+
*/
|
|
6
|
+
export declare function stripTerminalControls(text: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape sequences that carry their own payload: OSC (`ESC ]`, ended by BEL or `ESC \`, used for hyperlinks, window
|
|
3
|
+
* titles and clipboard writes), DCS, SOS, PM and APC. An unterminated one ends at the end of the line.
|
|
4
|
+
*/
|
|
5
|
+
// eslint-disable-next-line no-control-regex -- matching control characters is the point of this module.
|
|
6
|
+
const STRING_SEQUENCE = /\u001b[\]PX^_][^\u0007\u001b\n]*(?:\u0007|\u001b\\)?/g;
|
|
7
|
+
/** CSI sequences (`ESC [ ... final byte`, colours and cursor moves) and any other two-byte escape. */
|
|
8
|
+
// eslint-disable-next-line no-control-regex -- matching control characters is the point of this module.
|
|
9
|
+
const ESCAPE_SEQUENCE = /\u001b(?:\[[0-?]*[ -/]*[@-~]?|[^\n])/g;
|
|
10
|
+
/** C0 controls except tab and newline (so BEL, CR, backspace, a lone ESC), DEL and the C1 range 0x80-0x9f. */
|
|
11
|
+
// eslint-disable-next-line no-control-regex -- matching control characters is the point of this module.
|
|
12
|
+
const CONTROL_CHARACTERS = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
13
|
+
/**
|
|
14
|
+
* Text from the network made safe to print: escape sequences and control characters are removed, newlines and tabs
|
|
15
|
+
* stay. A fetched file could otherwise rewrite the terminal (hide lines, set the title, write the clipboard through
|
|
16
|
+
* OSC 52, plant a link with OSC 8).
|
|
17
|
+
*/
|
|
18
|
+
export function stripTerminalControls(text) {
|
|
19
|
+
return text.replace(STRING_SEQUENCE, "").replace(ESCAPE_SEQUENCE, "").replace(CONTROL_CHARACTERS, "");
|
|
20
|
+
}
|