scriptable 0.1.0 → 0.1.1

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.
@@ -0,0 +1,8 @@
1
+ # Changesets
2
+
3
+ Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
+ with multi-package repos, or single-package repos to help you version and publish your code. You can
5
+ find the full documentation for it [in our repository](https://github.com/changesets/changesets).
6
+
7
+ We have a quick list of common questions to get you started engaging with this project in
8
+ [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.1.3/schema.json",
3
+ "changelog": "@changesets/cli/changelog",
4
+ "commit": false,
5
+ "fixed": [],
6
+ "linked": [],
7
+ "access": "public",
8
+ "baseBranch": "main",
9
+ "updateInternalDependencies": "patch",
10
+ "ignore": []
11
+ }
@@ -0,0 +1,62 @@
1
+ name: release
2
+
3
+ # Publishes to npm via OIDC trusted publishing — no NPM_TOKEN secret.
4
+ #
5
+ # Triggered by pushing an annotated tag like `v0.1.1`. The local `pnpm release`
6
+ # script handles versioning, committing, tagging, and pushing — the tag push
7
+ # is what starts this workflow.
8
+ #
9
+ # If this workflow file is renamed, update the matching Trusted Publisher
10
+ # config at https://www.npmjs.com/package/scriptable/access — the
11
+ # "Workflow filename" field takes the basename only (e.g. `release.yml`).
12
+
13
+ on:
14
+ push:
15
+ tags:
16
+ - "v*"
17
+
18
+ jobs:
19
+ publish:
20
+ runs-on: ubuntu-latest
21
+ permissions:
22
+ # id-token: write is required for OIDC trusted publishing to npm.
23
+ # This lets `changeset publish` exchange a short-lived GitHub Actions
24
+ # token for an npm publish token — no long-lived NPM_TOKEN secret
25
+ # ever exists in this repo.
26
+ id-token: write
27
+ contents: read
28
+
29
+ steps:
30
+ - uses: actions/checkout@v6
31
+
32
+ - uses: pnpm/action-setup@v5
33
+ with:
34
+ version: 10
35
+
36
+ # Node 24, NOT 22. npm trusted publishing requires npm >= 11.5.1, and
37
+ # Node 22 LTS is permanently stuck on npm 10.9.x.
38
+ - uses: actions/setup-node@v6
39
+ with:
40
+ node-version: 24
41
+ registry-url: https://registry.npmjs.org
42
+ cache: pnpm
43
+
44
+ - name: Install dependencies
45
+ run: pnpm install --frozen-lockfile --ignore-scripts
46
+
47
+ - name: Test
48
+ run: pnpm test
49
+
50
+ - name: Build
51
+ run: pnpm build
52
+
53
+ # --no-git-tag: the tag already exists (we pushed it from the
54
+ # maintainer's laptop — that tag push is what triggered this
55
+ # workflow), so skip changesets' tag creation step.
56
+ # NPM_CONFIG_PROVENANCE=true: stamps the package with an npm
57
+ # provenance attestation so the npmjs.com page shows "Built
58
+ # and signed on GitHub Actions".
59
+ - name: Publish to npm
60
+ run: pnpm exec changeset publish --no-git-tag
61
+ env:
62
+ NPM_CONFIG_PROVENANCE: "true"
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # scriptable
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e243ccb: Releases are now published from GitHub Actions via npm OIDC trusted publishing. Each published artifact carries an npm provenance attestation, and no `NPM_TOKEN` secret is stored anywhere.
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Rewritten in TypeScript, using the `acorn` parser. All legacy runtime dependencies have been dropped.
14
+ - Hardened the sandbox: fixed a set of sandbox-escape and prototype-pollution vectors, and added DoS protections (execution limits) so runaway scripts can no longer lock up the host process.
package/README.md CHANGED
@@ -137,3 +137,49 @@ All tests ported to Vitest. The moment-dependent date tests now use `Intl.DateTi
137
137
  - ESM (`"type": "module"`) with TypeScript build
138
138
  - pnpm for package management
139
139
  - `exports` field with types
140
+
141
+ ## Contributing
142
+
143
+ ### Adding a changeset
144
+
145
+ Every user-facing change needs a changeset so it appears in the CHANGELOG:
146
+
147
+ ```bash
148
+ pnpm changeset # interactive: pick patch/minor/major, write a summary
149
+ git add .changeset # commit the generated .changeset/*.md file with your PR
150
+ ```
151
+
152
+ ### Releasing
153
+
154
+ ```bash
155
+ pnpm release
156
+ ```
157
+
158
+ This runs the release script (`scripts/release.js`), which:
159
+
160
+ 1. Guards: clean tree, on `main`, up to date with `origin/main`, pending changesets exist.
161
+ 2. Runs tests and build as a safety gate.
162
+ 3. Consumes changesets to bump `package.json` and update `CHANGELOG.md`.
163
+ 4. Commits as `Version X.Y.Z` and shows the diff.
164
+ 5. Prompts for confirmation (last chance to abort).
165
+ 6. Pushes `main`, creates an annotated `vX.Y.Z` tag, and pushes the tag.
166
+ 7. The tag push triggers `.github/workflows/release.yml`, which publishes to npm via OIDC trusted publishing with provenance attestation. No `NPM_TOKEN` is involved.
167
+
168
+ ### Recovery: if the release workflow fails after the tag is pushed
169
+
170
+ The version commit is on `main` and the tag is pushed, but npm publish failed. You can't rerun `pnpm release` because the changesets have already been consumed.
171
+
172
+ ```bash
173
+ # 1. Delete the tag locally and on the remote
174
+ git tag -d vX.Y.Z
175
+ git push origin :refs/tags/vX.Y.Z
176
+
177
+ # 2. Fix whatever broke, commit on main
178
+ git commit -am "fix(ci): ..."
179
+ git push origin main
180
+
181
+ # 3. Re-tag HEAD (annotated!) and push to re-trigger the workflow.
182
+ # Same version number — this is a retry, not a new version.
183
+ git tag -a vX.Y.Z -m "Version X.Y.Z"
184
+ git push origin vX.Y.Z
185
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scriptable",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,16 +16,19 @@
16
16
  "type": "git",
17
17
  "url": "https://github.com/lecstor/scriptable.git"
18
18
  },
19
- "scripts": {
20
- "build": "tsc",
21
- "test": "vitest run",
22
- "test:watch": "vitest"
23
- },
24
19
  "dependencies": {
25
20
  "acorn": "^8.14.1"
26
21
  },
27
22
  "devDependencies": {
23
+ "@changesets/cli": "^2.30.0",
28
24
  "typescript": "^5.7.0",
29
25
  "vitest": "^3.1.0"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "changeset": "changeset",
32
+ "release": "node scripts/release.js"
30
33
  }
31
- }
34
+ }
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Release a new version end-to-end.
4
+ *
5
+ * Guards:
6
+ * 1. Refuses to run on a dirty tree.
7
+ * 2. Refuses to run off main.
8
+ * 3. Refuses to run if local main is behind origin/main (fetches first).
9
+ * 4. Refuses to run with no pending changesets.
10
+ *
11
+ * Steps:
12
+ * 5. Runs tests + build as a safety gate.
13
+ * 6. Consumes changesets to bump package.json + CHANGELOG.md.
14
+ * 7. Commits the result as "Version X.Y.Z".
15
+ * 8. Shows the commit and prompts for confirmation.
16
+ * 9. On confirm: pushes main, creates the vX.Y.Z annotated tag,
17
+ * pushes the tag. The tag push triggers .github/workflows/release.yml,
18
+ * which publishes to npm via OIDC (with provenance).
19
+ * 10. On abort: prints instructions to undo the version commit and exits 1.
20
+ *
21
+ * There is deliberately only one user-facing pnpm script (`pnpm release`) —
22
+ * the interactive prompt at step 8 is the abort window. Everything before
23
+ * the prompt is local-only and reversible with `git reset --hard HEAD^`.
24
+ */
25
+ import { execSync } from "node:child_process";
26
+ import { readFileSync, readdirSync } from "node:fs";
27
+ import { createInterface } from "node:readline/promises";
28
+ import { stdin, stdout } from "node:process";
29
+
30
+ function run(cmd) {
31
+ execSync(cmd, { stdio: "inherit" });
32
+ }
33
+
34
+ function capture(cmd) {
35
+ return execSync(cmd, { encoding: "utf-8" }).trim();
36
+ }
37
+
38
+ function fail(msg) {
39
+ console.error(`release: ${msg}`);
40
+ process.exit(1);
41
+ }
42
+
43
+ async function prompt(question) {
44
+ const rl = createInterface({ input: stdin, output: stdout });
45
+ try {
46
+ return (await rl.question(question)).trim().toLowerCase();
47
+ } finally {
48
+ rl.close();
49
+ }
50
+ }
51
+
52
+ // 1. Clean tree check.
53
+ if (capture("git status --porcelain")) {
54
+ fail("working tree is not clean — commit or stash first.");
55
+ }
56
+
57
+ // 2. On main?
58
+ const branch = capture("git rev-parse --abbrev-ref HEAD");
59
+ if (branch !== "main") {
60
+ fail(`not on main branch (currently on ${branch}).`);
61
+ }
62
+
63
+ // 3. Up-to-date check.
64
+ run("git fetch origin main");
65
+ const localMain = capture("git rev-parse main");
66
+ const remoteMain = capture("git rev-parse origin/main");
67
+ if (localMain !== remoteMain) {
68
+ const behind = capture(`git rev-list --count ${localMain}..${remoteMain}`);
69
+ if (behind !== "0") {
70
+ fail(`local main is ${behind} commit(s) behind origin/main — pull first.`);
71
+ }
72
+ }
73
+
74
+ // 4. Pending changeset check.
75
+ const pending = readdirSync(".changeset").filter(
76
+ (f) => f.endsWith(".md") && f.toLowerCase() !== "readme.md",
77
+ );
78
+ if (pending.length === 0) {
79
+ fail("no pending changesets — run `pnpm changeset` first.");
80
+ }
81
+ console.log(
82
+ `Found ${pending.length} pending changeset(s): ${pending.join(", ")}\n`,
83
+ );
84
+
85
+ // 5. Safety gate.
86
+ run("pnpm test");
87
+ run("pnpm build");
88
+
89
+ // 6. Consume changesets → bump package.json + CHANGELOG.md.
90
+ run("pnpm exec changeset version");
91
+
92
+ // 7. Commit. Stage only the files changeset version touches.
93
+ const { version } = JSON.parse(readFileSync("./package.json", "utf-8"));
94
+ run("git add package.json CHANGELOG.md .changeset");
95
+ run(`git commit -m "Version ${version}"`);
96
+
97
+ // 8. Show the commit and prompt.
98
+ console.log("");
99
+ run("git --no-pager show HEAD --stat");
100
+ console.log("");
101
+ console.log("-".repeat(60));
102
+ console.log(` About to release scriptable v${version}`);
103
+ console.log("-".repeat(60));
104
+ console.log(` Next: push main, create tag v${version}, push tag`);
105
+ console.log(" -> tag push triggers .github/workflows/release.yml");
106
+ console.log(" -> CI publishes to npm via OIDC (with provenance)");
107
+ console.log("");
108
+ console.log(" This is your last chance to abort. Once the tag is pushed,");
109
+ console.log(" publishing happens automatically.");
110
+ console.log("");
111
+ const answer = await prompt("Proceed? [y/N] ");
112
+
113
+ if (answer !== "y" && answer !== "yes") {
114
+ console.log("\nAborted. To undo the version commit locally:");
115
+ console.log(" git reset --hard HEAD^");
116
+ console.log(" # your .changeset files will come back from the reset");
117
+ process.exit(1);
118
+ }
119
+
120
+ // 9. Push main, tag, push tag.
121
+ run("git push origin main");
122
+ run("pnpm exec changeset tag");
123
+ run("git push --follow-tags");
124
+
125
+ console.log(`\nv${version} tag pushed.`);
126
+ console.log(` https://github.com/lecstor/scriptable/actions`);
127
+ console.log(` The release workflow will publish to npm shortly.`);
@@ -1,10 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx vitest:*)",
5
- "Bash(pnpm test:*)",
6
- "WebSearch",
7
- "Bash(git push:*)"
8
- ]
9
- }
10
- }