@rrlab/astro-plugin 0.0.0 → 0.0.1-git-f854273.0

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/README.md CHANGED
@@ -1,3 +1,31 @@
1
1
  # @rrlab/astro-plugin
2
2
 
3
- Placeholder. The first release comes from [withvariablelab/dx](https://github.com/withvariablelab/dx).
3
+ Astro plugin for [`@rrlab/cli`](https://npmjs.com/package/@rrlab/cli). Provides the `typecheck` capability backed by [`astro check`](https://docs.astro.build/en/reference/cli-reference/#astro-check), so `rr tsc` and `rr check` type-check `.astro` files along with the rest of the project.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ rr plugins add astro
9
+ ```
10
+
11
+ `rr plugins add` installs `@rrlab/astro-plugin` and adds `@astrojs/check` and `typescript` as `devDependencies`: `astro check` needs both. It scaffolds no config: your Astro project already has its `tsconfig.json`, and `astro` itself stays your project's own dependency.
12
+
13
+ ## What it provides
14
+
15
+ | Capability | Surface |
16
+ |---|---|
17
+ | `typecheck` | `rr tsc` (workspace-aware in monorepos), `rr check`, `rr tsc doctor` |
18
+
19
+ `rr tsc` runs `astro check` in each package with a `tsconfig.json`. It reports the same diagnostics as `astro check`, for `.astro` files and plain `.ts` files alike, and fails when `astro check` exits non-zero (any error, by default).
20
+
21
+ `astro check` also checks your `.ts` files, so in an Astro project it replaces `ts`. Configure one `typecheck` provider. If another plugin also provides one (`ts`, or `oxc`), narrow it, e.g. `oxc({ only: ["lint", "format"] })`.
22
+
23
+ If `@astrojs/check` or `typescript` is missing, `rr tsc` fails and names it. Left alone, `astro check` would prompt to install them instead of checking anything.
24
+
25
+ ## Removal
26
+
27
+ ```sh
28
+ rr plugins remove astro
29
+ ```
30
+
31
+ Removes `@astrojs/check` and `typescript` from `package.json` and drops the `astro()` entry from `run-run.config.{ts,mts}`. `astro` and your `tsconfig.json` are left untouched.
@@ -0,0 +1,35 @@
1
+ import { InstallContext, InstallResult, RunReport, ToolService, TypeCheckOptions, TypeChecker, UninstallContext, UninstallResult } from "@rrlab/cli/plugin";
2
+ import { ShellService } from "@variablelab/clibuddy";
3
+
4
+ //#region src/tool-versions.d.ts
5
+ declare const TOOL_VERSIONS: {
6
+ readonly "@astrojs/check": {
7
+ readonly install: "^0.9.10";
8
+ };
9
+ readonly typescript: {
10
+ readonly install: "^6.0.0";
11
+ };
12
+ };
13
+ //#endregion
14
+ //#region src/index.d.ts
15
+ declare class AstroCheckService extends ToolService implements TypeChecker {
16
+ #private;
17
+ constructor(shellService: ShellService, cwd: string);
18
+ check(options?: TypeCheckOptions): Promise<RunReport>;
19
+ doctor(): Promise<RunReport>;
20
+ }
21
+ /**
22
+ * Lists the `astro check` dependencies the project at `root` can't resolve,
23
+ * looking them up the way astro does (`require.resolve(pkg, { paths: [root] })`).
24
+ * When one is missing, astro prompts to install it instead of checking: under a
25
+ * captured run that prompt hangs, and with stdin closed astro exits 0 having
26
+ * checked nothing. So we fail before running it.
27
+ */
28
+ declare function missingCheckDeps(root: string): string[];
29
+ declare function install(_ctx: InstallContext): Promise<InstallResult>;
30
+ declare function uninstall(_ctx: UninstallContext): Promise<UninstallResult>;
31
+ declare const astro: (options?: {
32
+ only?: readonly "typecheck"[] | undefined;
33
+ } | undefined) => import("@rrlab/cli/plugin").Plugin;
34
+ //#endregion
35
+ export { AstroCheckService, TOOL_VERSIONS, astro as default, install, missingCheckDeps, uninstall };
package/dist/index.mjs ADDED
@@ -0,0 +1,79 @@
1
+ import { createRequire } from "node:module";
2
+ import { ToolService, definePlugin } from "@rrlab/cli/plugin";
3
+ import { colorize } from "@variablelab/clibuddy";
4
+ //#region src/tool-versions.ts
5
+ const TOOL_VERSIONS = {
6
+ "@astrojs/check": { install: "^0.9.10" },
7
+ typescript: { install: "^6.0.0" }
8
+ };
9
+ //#endregion
10
+ //#region src/index.ts
11
+ const FROM = import.meta.url;
12
+ const localRequire = createRequire(FROM);
13
+ const CHECK_DEPS = ["@astrojs/check", "typescript"];
14
+ const astroColor = colorize("#BC52EE");
15
+ var AstroCheckService = class extends ToolService {
16
+ #cwd;
17
+ constructor(shellService, cwd) {
18
+ super({
19
+ bin: "astro",
20
+ color: astroColor,
21
+ shellService,
22
+ from: FROM
23
+ });
24
+ this.#cwd = cwd;
25
+ }
26
+ async check(options = {}) {
27
+ const cwd = options.cwd ?? this.#cwd;
28
+ const missing = missingCheckDeps(cwd);
29
+ if (missing.length > 0) return missingDepsReport(missing);
30
+ return this.runReport(["check"], { cwd });
31
+ }
32
+ async doctor() {
33
+ const missing = missingCheckDeps(this.#cwd);
34
+ if (missing.length > 0) return missingDepsReport(missing);
35
+ return super.doctor();
36
+ }
37
+ };
38
+ /**
39
+ * Lists the `astro check` dependencies the project at `root` can't resolve,
40
+ * looking them up the way astro does (`require.resolve(pkg, { paths: [root] })`).
41
+ * When one is missing, astro prompts to install it instead of checking: under a
42
+ * captured run that prompt hangs, and with stdin closed astro exits 0 having
43
+ * checked nothing. So we fail before running it.
44
+ */
45
+ function missingCheckDeps(root) {
46
+ return CHECK_DEPS.filter((pkg) => {
47
+ try {
48
+ localRequire.resolve(pkg, { paths: [root] });
49
+ return false;
50
+ } catch {
51
+ return true;
52
+ }
53
+ });
54
+ }
55
+ function missingDepsReport(missing) {
56
+ return {
57
+ ok: false,
58
+ output: `@rrlab/astro-plugin requires ${missing.join(", ")} to be installed in the host project. Run: rr plugins add astro (or: pnpm add -D ${missing.join(" ")})`
59
+ };
60
+ }
61
+ async function install(_ctx) {
62
+ return { devDependencies: {
63
+ "@astrojs/check": TOOL_VERSIONS["@astrojs/check"].install,
64
+ typescript: TOOL_VERSIONS.typescript.install
65
+ } };
66
+ }
67
+ async function uninstall(_ctx) {
68
+ return { removeDependencies: ["@astrojs/check", "typescript"] };
69
+ }
70
+ const astro = definePlugin({
71
+ apiVersion: 1,
72
+ name: "astro",
73
+ color: astroColor,
74
+ install,
75
+ uninstall,
76
+ services: ({ shell, cwd }) => ({ typecheck: new AstroCheckService(shell, cwd) })
77
+ });
78
+ //#endregion
79
+ export { AstroCheckService, TOOL_VERSIONS, astro as default, install, missingCheckDeps, uninstall };
package/package.json CHANGED
@@ -1,11 +1,57 @@
1
1
  {
2
2
  "name": "@rrlab/astro-plugin",
3
- "version": "0.0.0",
4
- "description": "Placeholder. The first release comes from withvariablelab/dx.",
5
- "license": "MIT",
3
+ "version": "0.0.1-git-f854273.0",
4
+ "description": "Astro plugin for @rrlab/cli — provides the typecheck capability via astro check.",
5
+ "homepage": "https://github.com/withvariablelab/dx/tree/main/run-run/astro-plugin#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/withvariablelab/dx/issues"
8
+ },
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "git+https://github.com/withvariablelab/dx.git",
9
12
  "directory": "run-run/astro-plugin"
13
+ },
14
+ "license": "MIT",
15
+ "author": "rcrd <ricardo@variable.land>",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.mts",
20
+ "default": "./dist/index.mjs"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "src",
26
+ "!src/**/__tests__",
27
+ "!src/**/*.test.*"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "engines": {
33
+ "node": ">=22.18.0"
34
+ },
35
+ "dependencies": {
36
+ "@variablelab/clibuddy": "0.7.4"
37
+ },
38
+ "peerDependencies": {
39
+ "@astrojs/check": ">=0.9.0",
40
+ "astro": ">=5.0.0",
41
+ "typescript": "^5.0.0 || ^6.0.0",
42
+ "@rrlab/cli": "^1.3.6-git-f854273.0"
43
+ },
44
+ "devDependencies": {
45
+ "@astrojs/check": "0.9.10",
46
+ "@types/semver": "^7.7.1",
47
+ "astro": "7.4.0",
48
+ "semver": "^7.8.1",
49
+ "typescript": "6.0.3",
50
+ "@rrlab/cli": "1.3.6-git-f854273.0",
51
+ "@rrlab/tsdown-config": "^0.1.2"
52
+ },
53
+ "scripts": {
54
+ "build": "tsdown",
55
+ "test": "vitest run"
10
56
  }
11
- }
57
+ }
package/src/index.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { createRequire } from "node:module";
2
+ import {
3
+ definePlugin,
4
+ type InstallContext,
5
+ type InstallResult,
6
+ type RunReport,
7
+ ToolService,
8
+ type TypeChecker,
9
+ type TypeCheckOptions,
10
+ type UninstallContext,
11
+ type UninstallResult,
12
+ } from "@rrlab/cli/plugin";
13
+ import { colorize, type ShellService } from "@variablelab/clibuddy";
14
+ import { TOOL_VERSIONS } from "./tool-versions.ts";
15
+
16
+ export { TOOL_VERSIONS } from "./tool-versions.ts";
17
+
18
+ const FROM = import.meta.url;
19
+ const localRequire = createRequire(FROM);
20
+ // What `astro check` loads from the project root before checking anything.
21
+ const CHECK_DEPS = ["@astrojs/check", "typescript"] as const;
22
+ const astroColor = colorize("#BC52EE");
23
+
24
+ export class AstroCheckService extends ToolService implements TypeChecker {
25
+ #cwd: string;
26
+
27
+ constructor(shellService: ShellService, cwd: string) {
28
+ super({ bin: "astro", color: astroColor, shellService, from: FROM });
29
+ this.#cwd = cwd;
30
+ }
31
+
32
+ async check(options: TypeCheckOptions = {}): Promise<RunReport> {
33
+ const cwd = options.cwd ?? this.#cwd;
34
+ const missing = missingCheckDeps(cwd);
35
+ if (missing.length > 0) return missingDepsReport(missing);
36
+ // `astro check`, not @astrojs/check's own `astro-check` bin: only the
37
+ // former runs `astro sync` first, so generated types (content collections,
38
+ // `astro:env`, …) exist. Its diagnostics keep their color when captured.
39
+ return this.runReport(["check"], { cwd });
40
+ }
41
+
42
+ override async doctor(): Promise<RunReport> {
43
+ const missing = missingCheckDeps(this.#cwd);
44
+ if (missing.length > 0) return missingDepsReport(missing);
45
+ return super.doctor();
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Lists the `astro check` dependencies the project at `root` can't resolve,
51
+ * looking them up the way astro does (`require.resolve(pkg, { paths: [root] })`).
52
+ * When one is missing, astro prompts to install it instead of checking: under a
53
+ * captured run that prompt hangs, and with stdin closed astro exits 0 having
54
+ * checked nothing. So we fail before running it.
55
+ */
56
+ export function missingCheckDeps(root: string): string[] {
57
+ return CHECK_DEPS.filter((pkg) => {
58
+ try {
59
+ localRequire.resolve(pkg, { paths: [root] });
60
+ return false;
61
+ } catch {
62
+ return true;
63
+ }
64
+ });
65
+ }
66
+
67
+ function missingDepsReport(missing: string[]): RunReport {
68
+ return {
69
+ ok: false,
70
+ output:
71
+ `@rrlab/astro-plugin requires ${missing.join(", ")} to be installed in the host project. ` +
72
+ `Run: rr plugins add astro (or: pnpm add -D ${missing.join(" ")})`,
73
+ };
74
+ }
75
+
76
+ // No config scaffolding: an Astro project already has its tsconfig.json, and
77
+ // `astro` itself is the host's own dependency, so only the checker is added.
78
+ export async function install(_ctx: InstallContext): Promise<InstallResult> {
79
+ return {
80
+ devDependencies: {
81
+ "@astrojs/check": TOOL_VERSIONS["@astrojs/check"].install,
82
+ typescript: TOOL_VERSIONS.typescript.install,
83
+ },
84
+ };
85
+ }
86
+
87
+ export async function uninstall(_ctx: UninstallContext): Promise<UninstallResult> {
88
+ return { removeDependencies: ["@astrojs/check", "typescript"] };
89
+ }
90
+
91
+ const astro = definePlugin({
92
+ apiVersion: 1,
93
+ name: "astro",
94
+ color: astroColor,
95
+ install,
96
+ uninstall,
97
+ services: ({ shell, cwd }) => ({ typecheck: new AstroCheckService(shell, cwd) }),
98
+ });
99
+
100
+ export default astro;
@@ -0,0 +1,7 @@
1
+ export const TOOL_VERSIONS = {
2
+ // `install` is the prescriptive pin used by `rr plugins add`'s nypm call.
3
+ // The looser contracts live in package.json#peerDependencies. `astro` itself
4
+ // isn't here: the host project owns its framework version.
5
+ "@astrojs/check": { install: "^0.9.10" },
6
+ typescript: { install: "^6.0.0" },
7
+ } as const;