diff --git a/.github/workflows/js.yml b/.github/workflows/js.yml index fb4c3e0..c7e30f0 100644 --- a/.github/workflows/js.yml +++ b/.github/workflows/js.yml @@ -83,7 +83,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Install dependencies run: npm install @@ -110,20 +110,20 @@ jobs: timeout-minutes: 10 needs: [detect-changes] if: | - github.event_name == 'push' || + always() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.mjs-changed == 'true' || needs.detect-changes.outputs.js-changed == 'true' || needs.detect-changes.outputs.docs-changed == 'true' || needs.detect-changes.outputs.package-changed == 'true' || - needs.detect-changes.outputs.workflow-changed == 'true' + needs.detect-changes.outputs.workflow-changed == 'true') steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Install dependencies run: npm install @@ -178,7 +178,7 @@ jobs: - name: Run tests (Bun) if: matrix.runtime == 'bun' - run: bun test + run: bun test ./tests - name: Setup Deno if: matrix.runtime == 'deno' @@ -203,7 +203,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Install dependencies run: npm install @@ -219,11 +219,26 @@ jobs: path: js/coverage/ retention-days: 14 + # Test the tarball in an isolated consumer, including all integration exports. + package: + name: Verify npm Package + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '24.x' + - name: Verify release tooling startup on Node 24 + run: node scripts/version-and-commit.mjs --help + - run: node --test scripts/publish-to-npm.test.mjs + - run: npm run test:package + # Release - only runs on main after tests pass (for push events) release: name: Release - needs: [lint, test] - if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.lint.result == 'success' && needs.test.result == 'success' + needs: [lint, test, package] + if: always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.lint.result == 'success' && needs.test.result == 'success' && needs.package.result == 'success' runs-on: ubuntu-latest permissions: contents: write @@ -237,7 +252,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' - name: Install dependencies @@ -279,7 +294,8 @@ jobs: # Manual Instant Release instant-release: name: Instant Release - if: github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant' + if: always() && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'instant' && needs.lint.result == 'success' && needs.test.result == 'success' && needs.package.result == 'success' + needs: [lint, test, package] runs-on: ubuntu-latest permissions: contents: write @@ -293,7 +309,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' - name: Install dependencies @@ -339,7 +355,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Install dependencies run: npm install diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 668fb2f..5c5cb2e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -60,7 +60,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Detect changes id: changes @@ -131,7 +131,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Cache cargo registry uses: actions/cache@v4 @@ -153,6 +153,9 @@ jobs: - name: Check file size limit run: node scripts/check-file-size.mjs + - name: Verify release tooling startup on Node 24 + run: node scripts/version-and-commit.mjs --help + - name: Test release scripts run: node --test scripts/crates-io.test.mjs @@ -283,7 +286,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Configure git run: | @@ -379,7 +382,7 @@ jobs: manual-release: name: Manual Release needs: [lint, test, build] - if: always() && github.event_name == 'workflow_dispatch' && needs.build.result == 'success' + if: always() && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && needs.build.result == 'success' runs-on: ubuntu-latest permissions: contents: write @@ -398,7 +401,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' - name: Configure git run: | diff --git a/README.md b/README.md index 788b155..b8ef2ba 100644 --- a/README.md +++ b/README.md @@ -111,3 +111,5 @@ Changes to files in `js/` trigger the JS workflow, and changes to files in `rust ## License [Unlicense](LICENSE) - Public Domain + +Publishing: [npm and crates.io release setup](docs/guides/releasing.md). diff --git a/WORK_PLAN.md b/WORK_PLAN.md new file mode 100644 index 0000000..77f8973 --- /dev/null +++ b/WORK_PLAN.md @@ -0,0 +1,38 @@ +# Issue 55 work plan + +- [x] Read issue 55, referenced issue 53, all comments, and PR 56 feedback (none). +- [x] Inspect recent merged PRs and existing release scripts/workflows. +- [x] Consolidate npm metadata, exports, dependencies, examples, docs, release tooling. +- [x] Verify installed tarball: core, server/client, all four integrations and types. +- [x] Repair npm and Rust OIDC release paths; add release triggers and startup verification. +- [ ] Verify live registry acceptance: canonical npm name and Rust crate published by workflow; split npm names absent. +- [x] Review diff, commit, push only issue-55-ec61bae8f6e4, update PR 56. +Final-SHA CI and ready status are tracked on PR #56. + +Registry publication is a separate acceptance criterion from CI. Keep it unfinished +if registry ownership/bootstrap credentials or trusted-publisher registration are unavailable. + +Initial evidence: all six npm names returned E404. Main Rust release run +39921677800 failed before authentication: `TEXT_ENCODINGS.union is not a function` +from command-stream's execa dependency under Node 20 (log lines 8634–8652). +Both workflow release runtimes are being updated to Node 24. + +Verification: installed tarball test passed locally and on CI; pre-change main +fails the same test (`experiments/issue-55-package-regression.sh`). npm publisher +unit tests and all 11 Rust release helper tests pass. JS lint, formatting, +duplication checks, and changeset status pass. CI verifies release script startup +on Node 24 to regress the main-branch failure without creating commits or tags. + +Live publication remains blocked: npm whoami reports ENEEDAUTH; no Cargo +credentials file or repository Actions secrets exist. All npm names still return +E404; cargo search returns no matching crate (direct crates.io API access is +HTTP 403 in this environment). A registry owner must bootstrap and register the +trusted publishers; this is documented in the PR and release guide. The PR is +kept unmerged and live publication is not claimed as complete. + +CI investigation: the initial Bun/Windows job also discovered Node-only release +script tests. Its package test failed because shell invocation split inline +JavaScript (`Unexpected end of file`, job log lines 183–225). The package test +now uses a real module file and invokes executables without a shell. Bun CI is +scoped to its existing runtime suite in tests/; packaging remains explicitly +covered by the Node 24 Verify npm Package job. diff --git a/docs/README.md b/docs/README.md index cf6da73..6ad0f77 100644 --- a/docs/README.md +++ b/docs/README.md @@ -35,7 +35,7 @@ Links Queue provides implementations in multiple languages: | Language | Package | Documentation | | --------------------- | -------------------------------------------------------------- | ----------------------------------- | -| JavaScript/TypeScript | [links-queue-js](https://www.npmjs.com/package/links-queue-js) | [js/README.md](../js/README.md) | +| JavaScript/TypeScript | [links-queue](https://www.npmjs.com/package/links-queue) | [js/README.md](../js/README.md) | | Rust | [links-queue](https://crates.io/crates/links-queue) | [rust/README.md](../rust/README.md) | ## Feature Status diff --git a/docs/api/js/README.md b/docs/api/js/README.md index e4cc9ad..64bd784 100644 --- a/docs/api/js/README.md +++ b/docs/api/js/README.md @@ -5,7 +5,7 @@ Complete API documentation for the Links Queue JavaScript/TypeScript implementat ## Installation ```bash -npm install links-queue-js +npm install links-queue ``` ## Quick Reference @@ -73,7 +73,7 @@ interface LinkPattern { Special symbol for wildcard matching in patterns. ```typescript -import { Any } from "links-queue-js"; +import { Any } from "links-queue"; // Match any source, specific target const pattern = { source: Any, target: 30 }; @@ -99,7 +99,7 @@ function createLink( **Example:** ```javascript -import { createLink } from "links-queue-js"; +import { createLink } from "links-queue"; const link = createLink(1, "task", "process-data"); // { id: 1, source: 'task', target: 'process-data' } @@ -151,7 +151,7 @@ function matchesPattern(link: Link, pattern: LinkPattern): boolean; **Example:** ```javascript -import { createLink, matchesPattern, Any } from "links-queue-js"; +import { createLink, matchesPattern, Any } from "links-queue"; const link = createLink(1, 10, 20); @@ -221,7 +221,7 @@ const store = new MemoryLinkStore(); **Example:** ```javascript -import { MemoryLinkStore, Any } from "links-queue-js"; +import { MemoryLinkStore, Any } from "links-queue"; const store = new MemoryLinkStore(); @@ -323,7 +323,7 @@ const queue = new LinksQueue(config); **Example:** ```javascript -import { LinksQueue, MemoryLinkStore, createLink } from "links-queue-js"; +import { LinksQueue, MemoryLinkStore, createLink } from "links-queue"; const store = new MemoryLinkStore(); const queue = new LinksQueue({ @@ -376,7 +376,7 @@ const queue = new MemoryQueue(name, options?); **Example:** ```javascript -import { MemoryQueue, createLink } from "links-queue-js"; +import { MemoryQueue, createLink } from "links-queue"; const queue = new MemoryQueue("tasks"); @@ -426,7 +426,7 @@ class MemoryQueueManager implements QueueManager **Example:** ```javascript -import { MemoryQueueManager, MemoryLinkStore } from "links-queue-js"; +import { MemoryQueueManager, MemoryLinkStore } from "links-queue"; const store = new MemoryLinkStore(); const manager = new MemoryQueueManager({ store }); @@ -457,7 +457,7 @@ await manager.deleteQueue("events"); TCP server for remote queue access. ```typescript -import { LinksQueueServer } from "links-queue-js/server"; +import { LinksQueueServer } from "links-queue/server"; ``` **Constructor Options:** @@ -480,7 +480,7 @@ import { LinksQueueServer } from "links-queue-js/server"; **Example:** ```javascript -import { LinksQueueServer } from "links-queue-js/server"; +import { LinksQueueServer } from "links-queue/server"; const server = new LinksQueueServer({ port: 5000, @@ -503,7 +503,7 @@ process.on("SIGTERM", async () => { TCP client for connecting to Links Queue servers. ```typescript -import { LinksQueueClient } from "links-queue-js/client"; +import { LinksQueueClient } from "links-queue/client"; ``` **Constructor:** @@ -541,8 +541,8 @@ const client = new LinksQueueClient(address, options?); **Example:** ```javascript -import { LinksQueueClient } from "links-queue-js/client"; -import { createLink } from "links-queue-js"; +import { LinksQueueClient } from "links-queue/client"; +import { createLink } from "links-queue"; const client = new LinksQueueClient("localhost:5000"); await client.connect(); @@ -591,7 +591,7 @@ type QueueErrorCode = **Example:** ```javascript -import { QueueError } from "links-queue-js"; +import { QueueError } from "links-queue"; try { await queue.enqueue(link); @@ -620,7 +620,7 @@ import { LinksNotation, NotationParser, NotationStreamParser, -} from "links-queue-js"; +} from "links-queue"; ``` ### LinksNotation @@ -635,7 +635,7 @@ class LinksNotation { **Example:** ```javascript -import { LinksNotation } from "links-queue-js"; +import { LinksNotation } from "links-queue"; // Parse Links Notation const links = LinksNotation.parse("((1 2) (3 4))"); @@ -664,14 +664,14 @@ import { RequestType, ResponseStatus, ErrorCode, -} from "links-queue-js"; +} from "links-queue"; ``` --- ## Exports Summary -### Main Module (`links-queue-js`) +### Main Module (`links-queue`) ```javascript // Core @@ -698,13 +698,13 @@ export { LinksNotation, NotationParser, NotationStreamParser }; export { Message, MessageBuilder, RequestType, ResponseStatus, ErrorCode }; ``` -### Server Module (`links-queue-js/server`) +### Server Module (`links-queue/server`) ```javascript export { LinksQueueServer, ServerConnection, RequestRouter }; ``` -### Client Module (`links-queue-js/client`) +### Client Module (`links-queue/client`) ```javascript export { LinksQueueClient, ClientConnection }; diff --git a/docs/guides/best-practices.md b/docs/guides/best-practices.md index 26a6590..493c73d 100644 --- a/docs/guides/best-practices.md +++ b/docs/guides/best-practices.md @@ -53,7 +53,7 @@ if (stats.depth > 100) { Implement exponential backoff for transient failures: ```javascript -import { MemoryQueue } from "links-queue-js"; +import { MemoryQueue } from "links-queue"; const queue = new MemoryQueue("tasks", { retryDelay: (attempt) => Math.min(1000 * Math.pow(2, attempt), 60000), @@ -115,7 +115,7 @@ async function processBatch(queue, batchSize = 10) { Use connection pools for client connections: ```javascript -import { ConnectionPool } from "links-queue-js/client"; +import { ConnectionPool } from "links-queue/client"; const pool = new ConnectionPool({ address: "localhost:5000", @@ -494,7 +494,7 @@ const server = new LinksQueueServer({ Test individual components: ```javascript -import { MemoryQueue, createLink } from "links-queue-js"; +import { MemoryQueue, createLink } from "links-queue"; import { test } from "node:test"; import assert from "node:assert"; @@ -586,7 +586,7 @@ DEBUG=links-queue:* node app.js ```javascript // Programmatic debug -import { setLogLevel } from "links-queue-js"; +import { setLogLevel } from "links-queue"; setLogLevel("debug"); ``` diff --git a/docs/guides/clustering.md b/docs/guides/clustering.md index 38eacbf..ca52f47 100644 --- a/docs/guides/clustering.md +++ b/docs/guides/clustering.md @@ -44,7 +44,7 @@ Links Queue supports multi-node clustering for: ### JavaScript ```javascript -import { createClusterCoordinator, LinksQueueManager } from "links-queue-js"; +import { createClusterCoordinator, LinksQueueManager } from "links-queue"; // Create a cluster coordinator for this node const coordinator = createClusterCoordinator({ diff --git a/docs/guides/core-concepts.md b/docs/guides/core-concepts.md index 2f845b9..c139201 100644 --- a/docs/guides/core-concepts.md +++ b/docs/guides/core-concepts.md @@ -29,7 +29,7 @@ In code, a link has three required properties: The simplest link connects two IDs: ```javascript -import { createLink } from "links-queue-js"; +import { createLink } from "links-queue"; // A link from ID 2 to ID 3 const link = createLink(1, 2, 3); @@ -73,7 +73,7 @@ Link IDs can be: - **Strings**: `"uuid-123"`, `"user-456"` (for UUID-based systems) ```javascript -import { isLinkId } from "links-queue-js"; +import { isLinkId } from "links-queue"; isLinkId(42); // true isLinkId(1n); // true @@ -180,7 +180,7 @@ const queue = await manager.createQueue("tasks", { Links Queue supports pattern-based queries to find links: ```javascript -import { Any, matchesPattern } from "links-queue-js"; +import { Any, matchesPattern } from "links-queue"; const links = [ createLink(1, 10, 20), @@ -240,7 +240,7 @@ Response: The `LinkStore` interface provides persistence for links: ```javascript -import { MemoryLinkStore } from "links-queue-js"; +import { MemoryLinkStore } from "links-queue"; const store = new MemoryLinkStore(); diff --git a/docs/guides/getting-started.md b/docs/guides/getting-started.md index 61750bc..2b3bd34 100644 --- a/docs/guides/getting-started.md +++ b/docs/guides/getting-started.md @@ -10,22 +10,22 @@ Links Queue supports Node.js, Bun, and Deno. ```bash # Using npm -npm install links-queue-js +npm install links-queue # Using yarn -yarn add links-queue-js +yarn add links-queue # Using bun -bun add links-queue-js +bun add links-queue # Using pnpm -pnpm add links-queue-js +pnpm add links-queue ``` For Deno, import directly from npm: ```typescript -import { LinksQueue } from "npm:links-queue-js"; +import { LinksQueue } from "npm:links-queue"; ``` ### Rust @@ -43,7 +43,7 @@ tokio = { version = "1", features = ["full"] } ### JavaScript ```javascript -import { MemoryLinkStore, MemoryQueue, createLink } from "links-queue-js"; +import { MemoryLinkStore, MemoryQueue, createLink } from "links-queue"; // Create a link store and queue const store = new MemoryLinkStore(); @@ -94,7 +94,7 @@ For applications with multiple queues, use the queue manager: ### JavaScript ```javascript -import { LinksQueueManager, MemoryLinkStore } from "links-queue-js"; +import { LinksQueueManager, MemoryLinkStore } from "links-queue"; const store = new MemoryLinkStore(); const manager = new LinksQueueManager({ store }); @@ -143,7 +143,7 @@ Links Queue supports multiple operating modes through configuration: Best for development and testing: ```javascript -import { MemoryQueueManager, MemoryLinkStore } from "links-queue-js"; +import { MemoryQueueManager, MemoryLinkStore } from "links-queue"; const store = new MemoryLinkStore(); const manager = new MemoryQueueManager({ store }); @@ -154,7 +154,7 @@ const manager = new MemoryQueueManager({ store }); For production use with data persistence: ```javascript -import { LinksQueueManager, LinkCliBackend } from "links-queue-js"; +import { LinksQueueManager, LinkCliBackend } from "links-queue"; const backend = new LinkCliBackend({ path: "./data/queue.links", @@ -169,7 +169,7 @@ const manager = new LinksQueueManager({ backend }); Run as a standalone TCP server: ```javascript -import { LinksQueueServer } from "links-queue-js/server"; +import { LinksQueueServer } from "links-queue/server"; const server = new LinksQueueServer({ port: 5000, @@ -183,7 +183,7 @@ console.log("Server listening on port 5000"); Connect from a client: ```javascript -import { LinksQueueClient } from "links-queue-js/client"; +import { LinksQueueClient } from "links-queue/client"; const client = new LinksQueueClient("localhost:5000"); await client.connect(); @@ -199,7 +199,7 @@ Process queue items with automatic acknowledgment: ### JavaScript ```javascript -import { MemoryQueue, createLink } from "links-queue-js"; +import { MemoryQueue, createLink } from "links-queue"; const queue = new MemoryQueue("tasks"); @@ -224,10 +224,10 @@ Links Queue includes a command-line interface: ```bash # Start a server -npx links-queue-js server --port 5000 +npx links-queue server --port 5000 # With custom host -npx links-queue-js server --host 127.0.0.1 --port 8080 +npx links-queue server --host 127.0.0.1 --port 8080 ``` ## Next Steps diff --git a/docs/guides/operating-modes.md b/docs/guides/operating-modes.md index 49700a8..7cf090a 100644 --- a/docs/guides/operating-modes.md +++ b/docs/guides/operating-modes.md @@ -34,7 +34,7 @@ The simplest and fastest mode. Data is stored only in memory and lost on restart ### JavaScript ```javascript -import { MemoryLinkStore, MemoryQueueManager } from "links-queue-js"; +import { MemoryLinkStore, MemoryQueueManager } from "links-queue"; const store = new MemoryLinkStore(); const manager = new MemoryQueueManager({ store }); @@ -72,7 +72,7 @@ Persistent storage using the link-cli backend. Data survives restarts. ### JavaScript ```javascript -import { LinkCliBackend, LinksQueueManager } from "links-queue-js"; +import { LinkCliBackend, LinksQueueManager } from "links-queue"; const backend = new LinkCliBackend({ path: "./data/queue.links", @@ -130,8 +130,8 @@ Distributed queue across multiple nodes, but without persistence. ### JavaScript ```javascript -import { LinksQueueManager, MemoryLinkStore } from "links-queue-js"; -import { createClusterCoordinator } from "links-queue-js"; +import { LinksQueueManager, MemoryLinkStore } from "links-queue"; +import { createClusterCoordinator } from "links-queue"; const store = new MemoryLinkStore(); const coordinator = createClusterCoordinator({ @@ -190,8 +190,8 @@ Full distributed queue with persistence on each node. ### JavaScript ```javascript -import { LinksQueueManager, LinkCliBackend } from "links-queue-js"; -import { createClusterCoordinator } from "links-queue-js"; +import { LinksQueueManager, LinkCliBackend } from "links-queue"; +import { createClusterCoordinator } from "links-queue"; const backend = new LinkCliBackend({ path: "./data/queue.links", diff --git a/docs/guides/releasing.md b/docs/guides/releasing.md new file mode 100644 index 0000000..f4d9fc3 --- /dev/null +++ b/docs/guides/releasing.md @@ -0,0 +1,89 @@ +# Publishing links-queue + +The npm package and Rust crate are both named `links-queue`. There are no +independently published JavaScript integration packages. Install `links-queue` +and import `links-queue/express`, `links-queue/fastify`, `links-queue/hono`, or +`links-queue/nestjs`. Install the corresponding framework separately; framework +peer dependencies are optional so core consumers do not install all frameworks. +The integrations and their TypeScript declarations ship inside the same tarball. + +## Release workflows + +- `.github/workflows/js.yml`: merging a changeset under `js/.changeset/` into + main versions the package and publishes it after lint, tests, and an installed + tarball smoke test pass. Manual instant releases also require these checks and + run only on main. The release job grants `id-token: write`, runs npm 11 or + later on Node 24, and invokes `npm publish --access public --provenance`. + Publication succeeds only after the exact name/version is visible on npm. +- `.github/workflows/rust.yml`: merging a changelog fragment under + `rust/changelog.d/` into main versions and publishes the crate after lint, + tests, package verification, and builds. Both automatic and manual release + jobs exchange the GitHub OIDC identity using the pinned + `rust-lang/crates-io-auth-action`, then run `cargo publish` and verify registry + visibility. The existing optional token fallback remains for compatibility + with issue #53's policy; configured trusted publishing needs no repository + token secret. + +Neither workflow publishes from a pull request. A passing PR verifies packaging +and release logic; it does not establish that a live registry upload occurred. + +## Initial registry setup + +Registry account access is required to bootstrap a new package/crate and register +its trusted publisher. A GitHub repository credential alone cannot do this. +Do not add long-lived registry tokens to repository secrets. + +For npm, publish the first package version from an authenticated maintainer +session if the package does not exist yet. Under the package's Settings → +Trusted publishing, register: + +- Provider: GitHub Actions +- Owner: `link-foundation` +- Repository: `links-queue` +- Workflow filename: `js.yml` +- Environment: leave empty + +Use the [npm trusted publishing documentation](https://docs.npmjs.com/trusted-publishers/) +for account setup. The split names must remain unpublished; do not run npm publish +from an integration directory. + +For crates.io, the first version must exist before a trusted publisher can be +registered. An authenticated maintainer can bootstrap with +`package-registry-manager setup --repository . --registry crates-io --execute`, +which publishes with a short-lived credential and registers the publisher, or +publish once manually and register it under the crate's settings: + +- Owner: `link-foundation` +- Repository: `links-queue` +- Workflow filename: `rust.yml` +- Environment: leave empty + +See [crates.io trusted publishing](https://crates.io/docs/trusted-publishing). +Subsequent releases use OIDC without `NPM_TOKEN`, `CARGO_TOKEN`, or +`CARGO_REGISTRY_TOKEN` secrets. Run a release on main and confirm the publishing +step and registry visibility; an initial manual upload alone does not verify +workflow publication. + +## Verification + +```sh +cd js +npm run test:package +node --test scripts/publish-to-npm.test.mjs +npm view links-queue version +# Each of these must return E404: +npm view links-queue-js version +npm view links-queue-express version +npm view links-queue-fastify version +npm view links-queue-hono version +npm view links-queue-nestjs version +cd ../rust +node --test scripts/crates-io.test.mjs +cargo search links-queue --limit 5 +``` + +The package test installs the packed artifact into a temporary consumer, checks +core without frameworks, then loads every integration with framework peers, +creates routers/plugins/services, and checks TypeScript subpath resolution. +Temporary files are removed even on failure. CI runs this test with a finite +job and test timeout. diff --git a/docs/guides/server-mode.md b/docs/guides/server-mode.md index e5bb0b7..077f644 100644 --- a/docs/guides/server-mode.md +++ b/docs/guides/server-mode.md @@ -26,7 +26,7 @@ Links Queue can run as a standalone TCP server, allowing clients to connect over ### JavaScript ```javascript -import { LinksQueueServer } from "links-queue-js/server"; +import { LinksQueueServer } from "links-queue/server"; const server = new LinksQueueServer({ port: 5000, @@ -62,10 +62,10 @@ println!("Server listening on port 5000"); ```bash # JavaScript -npx links-queue-js server --port 5000 +npx links-queue server --port 5000 # With custom host -npx links-queue-js server --host 127.0.0.1 --port 8080 +npx links-queue server --host 127.0.0.1 --port 8080 # Rust links-queue server --port 5000 --host 0.0.0.0 --max-conn 500 @@ -107,7 +107,7 @@ let config = ServerConfig::new() ### JavaScript ```javascript -import { LinksQueueClient } from "links-queue-js/client"; +import { LinksQueueClient } from "links-queue/client"; const client = new LinksQueueClient("localhost:5000"); await client.connect(); @@ -309,7 +309,7 @@ client.on("reconnected", () => { For high-throughput applications: ```javascript -import { ConnectionPool } from "links-queue-js/client"; +import { ConnectionPool } from "links-queue/client"; const pool = new ConnectionPool({ address: "localhost:5000", @@ -341,7 +341,7 @@ try { ### JavaScript Error Handling ```javascript -import { LinksQueueClient } from "links-queue-js/client"; +import { LinksQueueClient } from "links-queue/client"; try { await client.enqueue("nonexistent", link); diff --git a/docs/guides/storage-backends.md b/docs/guides/storage-backends.md index 7cfd71e..88e0f88 100644 --- a/docs/guides/storage-backends.md +++ b/docs/guides/storage-backends.md @@ -46,7 +46,7 @@ The default backend. Stores all data in memory for maximum performance. ### JavaScript ```javascript -import { MemoryLinkStore } from "links-queue-js"; +import { MemoryLinkStore } from "links-queue"; const store = new MemoryLinkStore(); @@ -87,7 +87,7 @@ println!("Found {} links", links.len()); // 2 ### Configuration ```javascript -import { BackendRegistry } from "links-queue-js"; +import { BackendRegistry } from "links-queue"; const registry = new BackendRegistry(); const backend = registry.create({ @@ -124,7 +124,7 @@ clink --version ### JavaScript ```javascript -import { LinkCliBackend, LinkCliProcess } from "links-queue-js"; +import { LinkCliBackend, LinkCliProcess } from "links-queue"; // Create and connect the backend const backend = new LinkCliBackend({ @@ -169,7 +169,7 @@ backend.disconnect().await?; The link-cli backend manages a child process: ```javascript -import { LinkCliProcess, ProcessState } from "links-queue-js"; +import { LinkCliProcess, ProcessState } from "links-queue"; const process = new LinkCliProcess({ path: "./data/queue.links", @@ -217,7 +217,7 @@ Use the registry to create backends dynamically: ### JavaScript ```javascript -import { BackendRegistry } from "links-queue-js"; +import { BackendRegistry } from "links-queue"; const registry = new BackendRegistry(); @@ -325,7 +325,7 @@ class RedisBackend { } // Register the custom backend -import { BackendRegistry } from "links-queue-js"; +import { BackendRegistry } from "links-queue"; const registry = new BackendRegistry(); registry.register("redis", RedisBackend); diff --git a/experiments/issue-55-package-regression.sh b/experiments/issue-55-package-regression.sh new file mode 100644 index 0000000..738b7ee --- /dev/null +++ b/experiments/issue-55-package-regression.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Run the installed-tarball test against pre-consolidation main, expecting failure. +set -eu +repo_root=$(git rev-parse --show-toplevel) +probe_dir=$(mktemp -d) +trap 'rm -rf "$probe_dir"' EXIT +git -C "$repo_root" archive 26126546433d344879cb190818bf9d0091d8b6dc js | tar -x -C "$probe_dir" +cp "$repo_root/js/scripts/package.test.mjs" "$probe_dir/js/scripts/package.test.mjs" +cd "$probe_dir/js" +if node --test scripts/package.test.mjs; then + echo 'ERROR: the pre-fix package unexpectedly passed the regression test' >&2 + exit 1 +fi +echo 'Confirmed: the pre-fix package fails the installed-tarball regression test.' diff --git a/js/.changeset/consolidate-package.md b/js/.changeset/consolidate-package.md new file mode 100644 index 0000000..b3ff171 --- /dev/null +++ b/js/.changeset/consolidate-package.md @@ -0,0 +1,5 @@ +--- +'links-queue': minor +--- + +Publish one links-queue npm package with Express, Fastify, Hono, and NestJS subpath exports and optional framework peers. Verify the installed tarball and publish using OIDC trusted publishing. diff --git a/js/LICENSE b/js/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/js/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/js/README.md b/js/README.md index 261ed79..419106c 100644 --- a/js/README.md +++ b/js/README.md @@ -71,3 +71,10 @@ js/ ## License [Unlicense](../LICENSE) - Public Domain + +## Package and integrations + +Install `npm install links-queue`. Framework integrations ship in the same package: +`links-queue/express`, `links-queue/fastify`, `links-queue/hono`, and +`links-queue/nestjs`. Install the framework you use separately. Each subpath includes +TypeScript declarations. See [publishing and registry setup](../docs/guides/releasing.md). diff --git a/js/package-lock.json b/js/package-lock.json index ad97647..8e72066 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -1,14 +1,15 @@ { - "name": "links-queue-js", + "name": "links-queue", "version": "0.15.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "links-queue-js", + "name": "links-queue", "version": "0.15.1", "license": "Unlicense", "dependencies": { + "fastify-plugin": "^5.0.0", "links-notation": "^0.13.0" }, "bin": { @@ -29,6 +30,30 @@ }, "engines": { "node": ">=20.0.0" + }, + "peerDependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "express": "^4.18.0 || ^5.0.0", + "fastify": "^4.0.0 || ^5.0.0", + "hono": "^4.0.0" + }, + "peerDependenciesMeta": { + "@nestjs/common": { + "optional": true + }, + "@nestjs/core": { + "optional": true + }, + "express": { + "optional": true + }, + "fastify": { + "optional": true + }, + "hono": { + "optional": true + } } }, "node_modules/@ampproject/remapping": { @@ -3165,6 +3190,22 @@ "dev": true, "license": "MIT" }, + "node_modules/fastify-plugin": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-5.1.0.tgz", + "integrity": "sha512-FAIDA8eovSt5qcDgcBvDuX/v0Cjz0ohGhENZ/wpc3y+oZCY2afZ9Baqql3g/lC+OHRnciQol4ww7tuthOb9idw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, "node_modules/fastq": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz", diff --git a/js/package.json b/js/package.json index 79f3e30..b94d1d3 100644 --- a/js/package.json +++ b/js/package.json @@ -1,5 +1,5 @@ { - "name": "links-queue-js", + "name": "links-queue", "version": "0.15.1", "description": "Links Queue - a universal queue system using links (JavaScript implementation)", "type": "module", @@ -18,6 +18,22 @@ }, "./client": { "import": "./src/client/index.js" + }, + "./express": { + "types": "./packages/express/src/index.d.ts", + "import": "./packages/express/src/index.js" + }, + "./fastify": { + "types": "./packages/fastify/src/index.d.ts", + "import": "./packages/fastify/src/index.js" + }, + "./hono": { + "types": "./packages/hono/src/index.d.ts", + "import": "./packages/hono/src/index.js" + }, + "./nestjs": { + "types": "./packages/nestjs/src/index.d.ts", + "import": "./packages/nestjs/src/index.js" } }, "scripts": { @@ -35,8 +51,9 @@ "prepare": "cd .. && husky js/.husky || true", "changeset": "changeset", "changeset:version": "node scripts/changeset-version.mjs", - "changeset:publish": "changeset publish", - "changeset:status": "changeset status --since=origin/main" + "changeset:publish": "npm publish --access public --provenance", + "changeset:status": "changeset status --since=origin/main", + "test:package": "node --test scripts/package.test.mjs" }, "keywords": [ "links-queue", @@ -82,6 +99,46 @@ ] }, "dependencies": { - "links-notation": "^0.13.0" + "links-notation": "^0.13.0", + "fastify-plugin": "^5.0.0" + }, + "files": [ + "src", + "packages/express/src", + "packages/fastify/src", + "packages/hono/src", + "packages/nestjs/src", + "packages/*/README.md", + "README.md", + "CHANGELOG.md", + "LICENSE" + ], + "publishConfig": { + "access": "public", + "provenance": true + }, + "peerDependencies": { + "express": "^4.18.0 || ^5.0.0", + "fastify": "^4.0.0 || ^5.0.0", + "hono": "^4.0.0", + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0" + }, + "peerDependenciesMeta": { + "express": { + "optional": true + }, + "fastify": { + "optional": true + }, + "hono": { + "optional": true + }, + "@nestjs/common": { + "optional": true + }, + "@nestjs/core": { + "optional": true + } } } diff --git a/js/packages/express/README.md b/js/packages/express/README.md index fd3b883..688d369 100644 --- a/js/packages/express/README.md +++ b/js/packages/express/README.md @@ -1,18 +1,18 @@ -# links-queue-express +# links-queue/express Express.js middleware for [Links Queue](https://github.com/link-foundation/links-queue). ## Installation ```bash -npm install links-queue-express +npm install links-queue express ``` ## Quick Start ```javascript import express from 'express'; -import { linksQueueMiddleware } from 'links-queue-express'; +import { linksQueueMiddleware } from 'links-queue/express'; const app = express(); app.use(express.json()); @@ -57,7 +57,7 @@ For a full RESTful API, use the queue router: ```javascript import express from 'express'; -import { linksQueueMiddleware, createQueueRouter } from 'links-queue-express'; +import { linksQueueMiddleware, createQueueRouter } from 'links-queue/express'; const app = express(); app.use(express.json()); @@ -99,7 +99,7 @@ The `req.linksQueue` facade provides these methods: Use the error handler middleware for queue-specific errors: ```javascript -import { linksQueueErrorHandler } from 'links-queue-express'; +import { linksQueueErrorHandler } from 'links-queue/express'; app.use(linksQueueErrorHandler); ``` diff --git a/js/packages/express/package.json b/js/packages/express/package.json deleted file mode 100644 index c248c56..0000000 --- a/js/packages/express/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "links-queue-express", - "version": "0.1.0", - "description": "Express.js middleware for Links Queue", - "type": "module", - "main": "src/index.js", - "types": "src/index.d.ts", - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./src/index.js" - } - }, - "scripts": { - "test": "node --test tests/", - "lint": "eslint .", - "lint:fix": "eslint . --fix" - }, - "keywords": [ - "links-queue", - "express", - "middleware", - "queue", - "message-queue" - ], - "author": "", - "license": "Unlicense", - "repository": { - "type": "git", - "url": "https://github.com/link-foundation/links-queue", - "directory": "js/packages/express" - }, - "engines": { - "node": ">=20.0.0" - }, - "peerDependencies": { - "express": "^4.18.0 || ^5.0.0" - }, - "dependencies": { - "links-queue-js": "^0.11.0" - }, - "devDependencies": { - "express": "^4.21.0" - } -} diff --git a/js/packages/express/src/index.d.ts b/js/packages/express/src/index.d.ts index cbccd35..dad4459 100644 --- a/js/packages/express/src/index.d.ts +++ b/js/packages/express/src/index.d.ts @@ -1,5 +1,5 @@ /** - * Type definitions for links-queue-express. + * Type definitions for links-queue/express. */ import type { Request, Response, NextFunction, Router } from 'express'; diff --git a/js/packages/express/src/index.js b/js/packages/express/src/index.js index aa73439..8b2f895 100644 --- a/js/packages/express/src/index.js +++ b/js/packages/express/src/index.js @@ -3,11 +3,11 @@ * * Provides middleware for integrating Links Queue into Express.js applications. * - * @module links-queue-express + * @module links-queue/express * * @example * import express from 'express'; - * import { linksQueueMiddleware } from 'links-queue-express'; + * import { linksQueueMiddleware } from 'links-queue/express'; * * const app = express(); * app.use(linksQueueMiddleware({ mode: 'single-memory' })); @@ -18,11 +18,12 @@ * }); */ +import { Router } from 'express'; import { MemoryQueueManager, LinksQueueManager, MemoryLinkStore, -} from 'links-queue-js'; +} from 'links-queue'; // ============================================================================= // Constants @@ -51,7 +52,7 @@ export const QueueMode = Object.freeze({ * @param {string} [options.mode='single-memory'] - Queue mode ('single-memory' or 'single-stored') * @param {string} [options.requestProperty='linksQueue'] - Property name on request object * @param {Object} [options.storeOptions] - Options for the link store (for single-stored mode) - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} [options.queueManager] - Custom queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} [options.queueManager] - Custom queue manager * @returns {Function} Express middleware function * * @example @@ -117,12 +118,12 @@ export class LinksQueueFacade { /** * Creates a new LinksQueueFacade. * - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} queueManager - The queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} queueManager - The queue manager */ constructor(queueManager) { /** * The underlying queue manager. - * @type {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @type {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} * @private */ this._manager = queueManager; @@ -131,7 +132,7 @@ export class LinksQueueFacade { /** * Gets the underlying queue manager. * - * @returns {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @returns {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} */ get manager() { return this._manager; @@ -142,7 +143,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ createQueue(name, options = {}) { return this._manager.createQueue(name, options); @@ -152,7 +153,7 @@ export class LinksQueueFacade { * Gets an existing queue. * * @param {string} name - Queue name - * @returns {Promise} + * @returns {Promise} */ getQueue(name) { return this._manager.getQueue(name); @@ -163,7 +164,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options (used only if creating) - * @returns {Promise} + * @returns {Promise} */ async getOrCreateQueue(name, options = {}) { let queue = await this._manager.getQueue(name); @@ -186,7 +187,7 @@ export class LinksQueueFacade { /** * Lists all queues. * - * @returns {Promise} + * @returns {Promise} */ listQueues() { return this._manager.listQueues(); @@ -293,7 +294,7 @@ export class LinksQueueFacade { * * @example * import express from 'express'; - * import { linksQueueMiddleware, createQueueRouter } from 'links-queue-express'; + * import { linksQueueMiddleware, createQueueRouter } from 'links-queue/express'; * * const app = express(); * app.use(express.json()); @@ -313,9 +314,6 @@ export class LinksQueueFacade { export function createQueueRouter(options = {}) { const { basePath = '/queues', requestProperty = 'linksQueue' } = options; - // Use dynamic require to get express Router - // eslint-disable-next-line no-undef - const { Router } = require('express'); const router = Router(); // List queues diff --git a/js/packages/fastify/README.md b/js/packages/fastify/README.md index cb62bfc..f487b03 100644 --- a/js/packages/fastify/README.md +++ b/js/packages/fastify/README.md @@ -1,18 +1,18 @@ -# links-queue-fastify +# links-queue/fastify Fastify plugin for [Links Queue](https://github.com/link-foundation/links-queue). ## Installation ```bash -npm install links-queue-fastify +npm install links-queue fastify ``` ## Quick Start ```javascript import Fastify from 'fastify'; -import linksQueuePlugin from 'links-queue-fastify'; +import linksQueuePlugin from 'links-queue/fastify'; const fastify = Fastify(); await fastify.register(linksQueuePlugin, { mode: 'single-memory' }); @@ -57,7 +57,7 @@ For a full RESTful API, use the queue routes plugin: ```javascript import Fastify from 'fastify'; -import linksQueuePlugin, { createQueueRoutes } from 'links-queue-fastify'; +import linksQueuePlugin, { createQueueRoutes } from 'links-queue/fastify'; const fastify = Fastify(); await fastify.register(linksQueuePlugin); diff --git a/js/packages/fastify/package.json b/js/packages/fastify/package.json deleted file mode 100644 index 2d10566..0000000 --- a/js/packages/fastify/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "links-queue-fastify", - "version": "0.1.0", - "description": "Fastify plugin for Links Queue", - "type": "module", - "main": "src/index.js", - "types": "src/index.d.ts", - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./src/index.js" - } - }, - "scripts": { - "test": "node --test tests/", - "lint": "eslint .", - "lint:fix": "eslint . --fix" - }, - "keywords": [ - "links-queue", - "fastify", - "plugin", - "queue", - "message-queue" - ], - "author": "", - "license": "Unlicense", - "repository": { - "type": "git", - "url": "https://github.com/link-foundation/links-queue", - "directory": "js/packages/fastify" - }, - "engines": { - "node": ">=20.0.0" - }, - "peerDependencies": { - "fastify": "^4.0.0 || ^5.0.0" - }, - "dependencies": { - "fastify-plugin": "^5.0.0", - "links-queue-js": "^0.11.0" - }, - "devDependencies": { - "fastify": "^5.0.0" - } -} diff --git a/js/packages/fastify/src/index.d.ts b/js/packages/fastify/src/index.d.ts index 1ebc392..9d53d0c 100644 --- a/js/packages/fastify/src/index.d.ts +++ b/js/packages/fastify/src/index.d.ts @@ -1,5 +1,5 @@ /** - * Type definitions for links-queue-fastify. + * Type definitions for links-queue/fastify. */ import type { diff --git a/js/packages/fastify/src/index.js b/js/packages/fastify/src/index.js index a1bc046..fc04ff2 100644 --- a/js/packages/fastify/src/index.js +++ b/js/packages/fastify/src/index.js @@ -3,11 +3,11 @@ * * Provides a plugin for integrating Links Queue into Fastify applications. * - * @module links-queue-fastify + * @module links-queue/fastify * * @example * import Fastify from 'fastify'; - * import linksQueuePlugin from 'links-queue-fastify'; + * import linksQueuePlugin from 'links-queue/fastify'; * * const fastify = Fastify(); * await fastify.register(linksQueuePlugin, { mode: 'single-memory' }); @@ -23,7 +23,7 @@ import { MemoryQueueManager, LinksQueueManager, MemoryLinkStore, -} from 'links-queue-js'; +} from 'links-queue'; // ============================================================================= // Constants @@ -52,7 +52,7 @@ export const QueueMode = Object.freeze({ * @param {Object} options - Plugin options * @param {string} [options.mode='single-memory'] - Queue mode * @param {string} [options.decoratorName='linksQueue'] - Decorator name - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} [options.queueManager] - Custom queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} [options.queueManager] - Custom queue manager */ function linksQueuePluginImpl(fastify, options = {}) { const { @@ -113,7 +113,7 @@ export class LinksQueueFacade { /** * Creates a new LinksQueueFacade. * - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} queueManager - The queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} queueManager - The queue manager */ constructor(queueManager) { this._manager = queueManager; @@ -122,7 +122,7 @@ export class LinksQueueFacade { /** * Gets the underlying queue manager. * - * @returns {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @returns {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} */ get manager() { return this._manager; @@ -133,7 +133,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ createQueue(name, options = {}) { return this._manager.createQueue(name, options); @@ -143,7 +143,7 @@ export class LinksQueueFacade { * Gets an existing queue. * * @param {string} name - Queue name - * @returns {Promise} + * @returns {Promise} */ getQueue(name) { return this._manager.getQueue(name); @@ -154,7 +154,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ async getOrCreateQueue(name, options = {}) { let queue = await this._manager.getQueue(name); @@ -177,7 +177,7 @@ export class LinksQueueFacade { /** * Lists all queues. * - * @returns {Promise} + * @returns {Promise} */ listQueues() { return this._manager.listQueues(); @@ -284,7 +284,7 @@ export class LinksQueueFacade { * * @example * import Fastify from 'fastify'; - * import linksQueuePlugin, { createQueueRoutes } from 'links-queue-fastify'; + * import linksQueuePlugin, { createQueueRoutes } from 'links-queue/fastify'; * * const fastify = Fastify(); * await fastify.register(linksQueuePlugin); diff --git a/js/packages/hono/README.md b/js/packages/hono/README.md index 27db7d5..3f52012 100644 --- a/js/packages/hono/README.md +++ b/js/packages/hono/README.md @@ -1,4 +1,4 @@ -# links-queue-hono +# links-queue/hono Hono middleware for [Links Queue](https://github.com/link-foundation/links-queue). @@ -7,14 +7,14 @@ Works great for edge environments like Cloudflare Workers, Deno Deploy, Bun, and ## Installation ```bash -npm install links-queue-hono +npm install links-queue hono ``` ## Quick Start ```javascript import { Hono } from 'hono'; -import { linksQueue } from 'links-queue-hono'; +import { linksQueue } from 'links-queue/hono'; const app = new Hono(); app.use('*', linksQueue({ mode: 'single-memory' })); @@ -59,7 +59,7 @@ For a full RESTful API, use the queue app: ```javascript import { Hono } from 'hono'; -import { linksQueue, createQueueApp } from 'links-queue-hono'; +import { linksQueue, createQueueApp } from 'links-queue/hono'; const app = new Hono(); app.use('*', linksQueue()); @@ -99,7 +99,7 @@ The `c.get('linksQueue')` facade provides these methods: ```javascript import { Hono } from 'hono'; -import { linksQueue } from 'links-queue-hono'; +import { linksQueue } from 'links-queue/hono'; const app = new Hono(); app.use('*', linksQueue()); diff --git a/js/packages/hono/package.json b/js/packages/hono/package.json deleted file mode 100644 index 9b39dad..0000000 --- a/js/packages/hono/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "links-queue-hono", - "version": "0.1.0", - "description": "Hono middleware for Links Queue", - "type": "module", - "main": "src/index.js", - "types": "src/index.d.ts", - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./src/index.js" - } - }, - "scripts": { - "test": "node --test tests/", - "lint": "eslint .", - "lint:fix": "eslint . --fix" - }, - "keywords": [ - "links-queue", - "hono", - "middleware", - "queue", - "message-queue", - "edge", - "cloudflare-workers" - ], - "author": "", - "license": "Unlicense", - "repository": { - "type": "git", - "url": "https://github.com/link-foundation/links-queue", - "directory": "js/packages/hono" - }, - "engines": { - "node": ">=20.0.0" - }, - "peerDependencies": { - "hono": "^4.0.0" - }, - "dependencies": { - "links-queue-js": "^0.11.0" - }, - "devDependencies": { - "hono": "^4.0.0" - } -} diff --git a/js/packages/hono/src/index.d.ts b/js/packages/hono/src/index.d.ts index 81e2ade..db9ffff 100644 --- a/js/packages/hono/src/index.d.ts +++ b/js/packages/hono/src/index.d.ts @@ -1,5 +1,5 @@ /** - * Type definitions for links-queue-hono. + * Type definitions for links-queue/hono. */ import type { MiddlewareHandler, Hono, Context } from 'hono'; diff --git a/js/packages/hono/src/index.js b/js/packages/hono/src/index.js index 77e1e6b..3635b9e 100644 --- a/js/packages/hono/src/index.js +++ b/js/packages/hono/src/index.js @@ -4,11 +4,11 @@ * Provides middleware for integrating Links Queue into Hono applications. * Works great for edge environments like Cloudflare Workers, Deno Deploy, etc. * - * @module links-queue-hono + * @module links-queue/hono * * @example * import { Hono } from 'hono'; - * import { linksQueue } from 'links-queue-hono'; + * import { linksQueue } from 'links-queue/hono'; * * const app = new Hono(); * app.use('*', linksQueue({ mode: 'single-memory' })); @@ -20,11 +20,12 @@ * }); */ +import { Hono } from 'hono'; import { MemoryQueueManager, LinksQueueManager, MemoryLinkStore, -} from 'links-queue-js'; +} from 'links-queue'; // ============================================================================= // Constants @@ -53,7 +54,7 @@ export class LinksQueueFacade { /** * Creates a new LinksQueueFacade. * - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} queueManager - The queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} queueManager - The queue manager */ constructor(queueManager) { this._manager = queueManager; @@ -62,7 +63,7 @@ export class LinksQueueFacade { /** * Gets the underlying queue manager. * - * @returns {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @returns {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} */ get manager() { return this._manager; @@ -73,7 +74,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ createQueue(name, options = {}) { return this._manager.createQueue(name, options); @@ -83,7 +84,7 @@ export class LinksQueueFacade { * Gets an existing queue. * * @param {string} name - Queue name - * @returns {Promise} + * @returns {Promise} */ getQueue(name) { return this._manager.getQueue(name); @@ -94,7 +95,7 @@ export class LinksQueueFacade { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ async getOrCreateQueue(name, options = {}) { let queue = await this._manager.getQueue(name); @@ -117,7 +118,7 @@ export class LinksQueueFacade { /** * Lists all queues. * - * @returns {Promise} + * @returns {Promise} */ listQueues() { return this._manager.listQueues(); @@ -220,12 +221,12 @@ export class LinksQueueFacade { * @param {Object} [options] - Middleware options * @param {string} [options.mode='single-memory'] - Queue mode ('single-memory' or 'single-stored') * @param {string} [options.contextKey='linksQueue'] - Key on context object - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} [options.queueManager] - Custom queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} [options.queueManager] - Custom queue manager * @returns {import('hono').MiddlewareHandler} Hono middleware * * @example * import { Hono } from 'hono'; - * import { linksQueue } from 'links-queue-hono'; + * import { linksQueue } from 'links-queue/hono'; * * const app = new Hono(); * app.use('*', linksQueue()); @@ -283,7 +284,7 @@ export function linksQueue(options = {}) { * * @example * import { Hono } from 'hono'; - * import { linksQueue, createQueueApp } from 'links-queue-hono'; + * import { linksQueue, createQueueApp } from 'links-queue/hono'; * * const app = new Hono(); * app.use('*', linksQueue()); @@ -292,8 +293,6 @@ export function linksQueue(options = {}) { export function createQueueApp(options = {}) { const { contextKey = 'linksQueue' } = options; - // Dynamic import for Hono - const { Hono } = globalThis.Hono || {}; const app = new Hono(); // List queues diff --git a/js/packages/nestjs/README.md b/js/packages/nestjs/README.md index c1e73f6..bfc72bf 100644 --- a/js/packages/nestjs/README.md +++ b/js/packages/nestjs/README.md @@ -1,11 +1,11 @@ -# links-queue-nestjs +# links-queue/nestjs NestJS module for [Links Queue](https://github.com/link-foundation/links-queue). ## Installation ```bash -npm install links-queue-nestjs +npm install links-queue @nestjs/common@10 @nestjs/core@10 ``` ## Quick Start @@ -14,7 +14,7 @@ npm install links-queue-nestjs ```typescript import { Module } from '@nestjs/common'; -import { LinksQueueModule } from 'links-queue-nestjs'; +import { LinksQueueModule } from 'links-queue/nestjs'; @Module({ imports: [LinksQueueModule.forRoot({ mode: 'single-memory' })], @@ -26,7 +26,7 @@ export class AppModule {} ```typescript import { Injectable } from '@nestjs/common'; -import { LinksQueueService } from 'links-queue-nestjs'; +import { LinksQueueService } from 'links-queue/nestjs'; @Injectable() export class TaskService { @@ -84,7 +84,7 @@ Register specific queues in feature modules: ```typescript import { Module } from '@nestjs/common'; -import { LinksQueueModule } from 'links-queue-nestjs'; +import { LinksQueueModule } from 'links-queue/nestjs'; @Module({ imports: [ @@ -117,7 +117,7 @@ The `LinksQueueService` provides these methods: ```typescript import { Controller, Post, Get, Body, Param } from '@nestjs/common'; -import { LinksQueueService } from 'links-queue-nestjs'; +import { LinksQueueService } from 'links-queue/nestjs'; @Controller('tasks') export class TasksController { diff --git a/js/packages/nestjs/package.json b/js/packages/nestjs/package.json deleted file mode 100644 index 1cf83f1..0000000 --- a/js/packages/nestjs/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "links-queue-nestjs", - "version": "0.1.0", - "description": "NestJS module for Links Queue", - "type": "module", - "main": "src/index.js", - "types": "src/index.d.ts", - "exports": { - ".": { - "types": "./src/index.d.ts", - "import": "./src/index.js" - } - }, - "scripts": { - "test": "node --test tests/", - "lint": "eslint .", - "lint:fix": "eslint . --fix" - }, - "keywords": [ - "links-queue", - "nestjs", - "module", - "queue", - "message-queue" - ], - "author": "", - "license": "Unlicense", - "repository": { - "type": "git", - "url": "https://github.com/link-foundation/links-queue", - "directory": "js/packages/nestjs" - }, - "engines": { - "node": ">=20.0.0" - }, - "peerDependencies": { - "@nestjs/common": "^10.0.0", - "@nestjs/core": "^10.0.0" - }, - "dependencies": { - "links-queue-js": "^0.11.0" - }, - "devDependencies": { - "@nestjs/common": "^10.0.0", - "@nestjs/core": "^10.0.0", - "reflect-metadata": "^0.2.0", - "rxjs": "^7.8.0" - } -} diff --git a/js/packages/nestjs/src/index.d.ts b/js/packages/nestjs/src/index.d.ts index 4dd51b6..50926f5 100644 --- a/js/packages/nestjs/src/index.d.ts +++ b/js/packages/nestjs/src/index.d.ts @@ -1,5 +1,5 @@ /** - * Type definitions for links-queue-nestjs. + * Type definitions for links-queue/nestjs. */ import type { DynamicModule, OnModuleDestroy, Type } from '@nestjs/common'; diff --git a/js/packages/nestjs/src/index.js b/js/packages/nestjs/src/index.js index 663e841..6f1d2fd 100644 --- a/js/packages/nestjs/src/index.js +++ b/js/packages/nestjs/src/index.js @@ -3,11 +3,11 @@ * * Provides a NestJS module for integrating Links Queue into NestJS applications. * - * @module links-queue-nestjs + * @module links-queue/nestjs * * @example * import { Module } from '@nestjs/common'; - * import { LinksQueueModule } from 'links-queue-nestjs'; + * import { LinksQueueModule } from 'links-queue/nestjs'; * * @Module({ * imports: [LinksQueueModule.forRoot({ mode: 'single-memory' })] @@ -19,7 +19,7 @@ import { MemoryQueueManager, LinksQueueManager, MemoryLinkStore, -} from 'links-queue-js'; +} from 'links-queue'; // ============================================================================= // Constants & Tokens @@ -63,7 +63,7 @@ export const QueueMode = Object.freeze({ * * @example * import { Injectable } from '@nestjs/common'; - * import { LinksQueueService } from 'links-queue-nestjs'; + * import { LinksQueueService } from 'links-queue/nestjs'; * * @Injectable() * export class TaskService { @@ -78,7 +78,7 @@ export class LinksQueueService { /** * Creates a new LinksQueueService. * - * @param {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} queueManager - The queue manager + * @param {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} queueManager - The queue manager */ constructor(queueManager) { this._manager = queueManager; @@ -87,7 +87,7 @@ export class LinksQueueService { /** * Gets the underlying queue manager. * - * @returns {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @returns {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} */ get manager() { return this._manager; @@ -98,7 +98,7 @@ export class LinksQueueService { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ createQueue(name, options = {}) { return this._manager.createQueue(name, options); @@ -108,7 +108,7 @@ export class LinksQueueService { * Gets an existing queue. * * @param {string} name - Queue name - * @returns {Promise} + * @returns {Promise} */ getQueue(name) { return this._manager.getQueue(name); @@ -119,7 +119,7 @@ export class LinksQueueService { * * @param {string} name - Queue name * @param {Object} [options] - Queue options - * @returns {Promise} + * @returns {Promise} */ async getOrCreateQueue(name, options = {}) { let queue = await this._manager.getQueue(name); @@ -142,7 +142,7 @@ export class LinksQueueService { /** * Lists all queues. * - * @returns {Promise} + * @returns {Promise} */ listQueues() { return this._manager.listQueues(); @@ -252,7 +252,7 @@ export class LinksQueueService { * Creates the queue manager based on options. * * @param {Object} options - Module options - * @returns {import('links-queue-js').MemoryQueueManager|import('links-queue-js').LinksQueueManager} + * @returns {import('links-queue').MemoryQueueManager|import('links-queue').LinksQueueManager} */ function createQueueManager(options = {}) { const { mode = QueueMode.SINGLE_MEMORY, queueManager: customManager } = diff --git a/js/scripts/create-manual-changeset.mjs b/js/scripts/create-manual-changeset.mjs index 956257c..7987d5b 100644 --- a/js/scripts/create-manual-changeset.mjs +++ b/js/scripts/create-manual-changeset.mjs @@ -13,7 +13,7 @@ import { writeFileSync } from 'fs'; import { randomBytes } from 'crypto'; -const PACKAGE_NAME = 'links-queue-js'; +const PACKAGE_NAME = 'links-queue'; // Load use-m dynamically const { use } = eval( diff --git a/js/scripts/format-release-notes.mjs b/js/scripts/format-release-notes.mjs index 173fd37..964b395 100644 --- a/js/scripts/format-release-notes.mjs +++ b/js/scripts/format-release-notes.mjs @@ -21,7 +21,7 @@ * Note: Uses --release-version instead of --version to avoid conflict with yargs' built-in --version flag. */ -const PACKAGE_NAME = 'links-queue-js'; +const PACKAGE_NAME = 'links-queue'; // Load use-m dynamically const { use } = eval( diff --git a/js/scripts/package.test.mjs b/js/scripts/package.test.mjs new file mode 100644 index 0000000..1fcfcc5 --- /dev/null +++ b/js/scripts/package.test.mjs @@ -0,0 +1,146 @@ +/** Test the shipped tarball from outside the source tree. */ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import { mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = fileURLToPath(new URL('../', import.meta.url)); +const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; +function run(command, args, cwd) { + return execFileSync(command, args, { + cwd, + encoding: 'utf8', + shell: command === 'npm.cmd', + }); +} + +test( + 'installed package preserves core and integration entry points', + { timeout: 180000 }, + () => { + const dir = mkdtempSync(join(tmpdir(), 'links-queue-package-')); + try { + const [pack] = JSON.parse( + run( + npm, + ['pack', '--ignore-scripts', '--json', '--pack-destination', dir], + root + ) + ); + const files = pack.files.map((file) => file.path); + for (const framework of ['express', 'fastify', 'hono', 'nestjs']) { + assert.ok(files.includes(`packages/${framework}/src/index.js`)); + assert.ok(files.includes(`packages/${framework}/src/index.d.ts`)); + assert.ok(!files.includes(`packages/${framework}/package.json`)); + } + assert.ok(files.includes('LICENSE')); + assert.ok( + !files.some((file) => /^(tests|scripts|experiments)\//.test(file)) + ); + writeFileSync( + join(dir, 'package.json'), + JSON.stringify({ private: true, type: 'module' }) + ); + run( + npm, + [ + 'install', + '--ignore-scripts', + '--no-audit', + '--no-fund', + join(dir, pack.filename), + ], + dir + ); + // Core must load without any optional framework installed. + writeFileSync( + join(dir, 'core.mjs'), + "import 'links-queue'; import 'links-queue/server'; import 'links-queue/client';" + ); + run(process.execPath, ['core.mjs'], dir); + run( + npm, + [ + 'install', + '--ignore-scripts', + '--no-audit', + '--no-fund', + 'express@4', + 'fastify@5', + 'hono@4', + '@nestjs/common@10', + '@nestjs/core@10', + 'reflect-metadata', + 'rxjs', + 'typescript', + '@types/express@4', + ], + dir + ); + const manifest = JSON.parse( + readFileSync(join(dir, 'node_modules/links-queue/package.json'), 'utf8') + ); + assert.equal(manifest.name, 'links-queue'); + for (const name of Object.keys(manifest.peerDependencies)) { + assert.equal(manifest.peerDependenciesMeta[name].optional, true); + } + writeFileSync( + join(dir, 'smoke.mjs'), + ` + import assert from 'node:assert/strict'; + import { MemoryQueueManager } from 'links-queue'; + import { linksQueueMiddleware, createQueueRouter } from 'links-queue/express'; + import plugin from 'links-queue/fastify'; + import { linksQueue, createQueueApp } from 'links-queue/hono'; + import { LinksQueueModule, LinksQueueService } from 'links-queue/nestjs'; + import Fastify from 'fastify'; + assert.equal(typeof linksQueueMiddleware(), 'function'); + assert.equal(typeof createQueueRouter(), 'function'); + assert.equal(typeof linksQueue(), 'function'); + assert.ok(createQueueApp()); + const manager = new MemoryQueueManager(); + const service = new LinksQueueService(manager); + await service.createQueue('smoke'); + const result = await service.enqueue('smoke', { hello: 'world' }); + assert.ok(result); + assert.ok(LinksQueueModule.forRoot()); + const app = Fastify(); + await app.register(plugin); + await app.ready(); + await app.close(); + ` + ); + run(process.execPath, ['smoke.mjs'], dir); + writeFileSync( + join(dir, 'types.mts'), + ` + import * as core from 'links-queue'; + import express from 'links-queue/express'; + import fastify from 'links-queue/fastify'; + import hono from 'links-queue/hono'; + import nestjs from 'links-queue/nestjs'; + void [core, express, fastify, hono, nestjs]; + ` + ); + run( + process.execPath, + [ + 'node_modules/typescript/bin/tsc', + '--noEmit', + '--skipLibCheck', + '--module', + 'NodeNext', + '--moduleResolution', + 'NodeNext', + 'types.mts', + ], + dir + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + } +); diff --git a/js/scripts/publish-to-npm.mjs b/js/scripts/publish-to-npm.mjs index c75600d..664dba7 100644 --- a/js/scripts/publish-to-npm.mjs +++ b/js/scripts/publish-to-npm.mjs @@ -1,126 +1,95 @@ #!/usr/bin/env node -/** - * Publish to npm using OIDC trusted publishing - * Usage: node scripts/publish-to-npm.mjs [--should-pull] - * should_pull: Optional flag to pull latest changes before publishing (for release job) - * - * Uses link-foundation libraries: - * - use-m: Dynamic package loading without package.json dependencies - * - command-stream: Modern shell command execution with streaming support - * - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files - */ - -import { readFileSync, appendFileSync } from 'fs'; - -const PACKAGE_NAME = 'links-queue-js'; - -// Load use-m dynamically -const { use } = eval( - await (await fetch('https://unpkg.com/use-m/use.js')).text() -); - -// Import link-foundation libraries -const { $ } = await use('command-stream'); -const { makeConfig } = await use('lino-arguments'); - -// Parse CLI arguments using lino-arguments -const config = makeConfig({ - yargs: ({ yargs, getenv }) => - yargs.option('should-pull', { - type: 'boolean', - default: getenv('SHOULD_PULL', false), - describe: 'Pull latest changes before publishing', - }), -}); - -const { shouldPull } = config; -const MAX_RETRIES = 3; -const RETRY_DELAY = 10000; // 10 seconds - -/** - * Sleep for specified milliseconds - * @param {number} ms - */ -function sleep(ms) { - return new Promise((resolve) => globalThis.setTimeout(resolve, ms)); -} - -/** - * Append to GitHub Actions output file - * @param {string} key - * @param {string} value - */ -function setOutput(key, value) { - const outputFile = process.env.GITHUB_OUTPUT; - if (outputFile) { - appendFileSync(outputFile, `${key}=${value}\n`); +/** Publish the single npm package with GitHub Actions OIDC, then verify it. */ +import { readFileSync, appendFileSync } from 'node:fs'; +import { execFileSync } from 'node:child_process'; +import { pathToFileURL } from 'node:url'; + +export async function registryVersion(name, version, fetchImpl = fetch) { + const response = await fetchImpl( + `https://registry.npmjs.org/${name}/${version}` + ); + if (response.status === 404) { + return false; + } + if (!response.ok) { + throw new Error(`npm registry returned HTTP ${response.status}`); } + const data = await response.json(); + return data.name === name && data.version === version; } -async function main() { - try { - if (shouldPull) { - // Pull the latest changes we just pushed - await $`git pull origin main`; - } - - // Get current version - const packageJson = JSON.parse(readFileSync('./package.json', 'utf8')); - const currentVersion = packageJson.version; - console.log(`Current version to publish: ${currentVersion}`); - - // Check if this version is already published on npm - console.log( - `Checking if version ${currentVersion} is already published...` +export async function publishPackage({ + manifest, + run = (command, args) => execFileSync(command, args, { stdio: 'inherit' }), + lookup = registryVersion, + wait = () => new Promise((resolve) => setTimeout(resolve, 10000)), +}) { + if (manifest.name !== 'links-queue') { + throw new Error( + 'Only the consolidated links-queue package may be published' ); - const checkResult = - await $`npm view "${PACKAGE_NAME}@${currentVersion}" version`.run({ - capture: true, - }); - - // command-stream returns { code: 0 } on success, { code: 1 } on failure (e.g., E404) - // Exit code 0 means version exists, non-zero means version not found - if (checkResult.code === 0) { - console.log(`Version ${currentVersion} is already published to npm`); - setOutput('published', 'true'); - setOutput('published_version', currentVersion); - setOutput('already_published', 'true'); - return; - } else { - // Version not found on npm (E404), proceed with publish - console.log( - `Version ${currentVersion} not found on npm, proceeding with publish...` - ); - } - - // Publish to npm using OIDC trusted publishing with retry logic - for (let i = 1; i <= MAX_RETRIES; i++) { - console.log(`Publish attempt ${i} of ${MAX_RETRIES}...`); - try { - await $`npm run changeset:publish`; - setOutput('published', 'true'); - setOutput('published_version', currentVersion); - console.log( - `\u2705 Published ${PACKAGE_NAME}@${currentVersion} to npm` - ); - return; - } catch (error) { - if (i < MAX_RETRIES) { - console.log( - `Publish failed: ${error.message}, waiting ${RETRY_DELAY / 1000}s before retry...` - ); - await sleep(RETRY_DELAY); - } + } + const { name, version } = manifest; + if (await lookup(name, version)) { + console.log(`${name}@${version} is already published`); + return { alreadyPublished: true }; + } + // npm >= 11.5.1 discovers the Actions OIDC credentials automatically. + // Publish only the current package, never traverse integration directories. + for (let attempt = 0; attempt < 3; attempt++) { + try { + await run('npm', ['publish', '--access', 'public', '--provenance']); + break; + } catch (error) { + // A registry may accept an upload before the client loses its connection. + if (await lookup(name, version)) { + return { alreadyPublished: true }; } + if (attempt === 2) { + throw error; + } + console.log(`Publish attempt ${attempt + 1} failed: ${error.message}`); + await wait(); + } + } + for (let attempt = 0; attempt < 12; attempt++) { + if (await lookup(name, version)) { + console.log(`Verified ${name}@${version} on npm`); + return { alreadyPublished: false }; + } + if (attempt < 11) { + await wait(); } + } + throw new Error(`${name}@${version} is missing from npm after publication`); +} - console.error(`\u274C Failed to publish after ${MAX_RETRIES} attempts`); - process.exit(1); - } catch (error) { - console.error('Error:', error.message); - process.exit(1); +async function main() { + if ( + process.argv.includes('--should-pull') || + process.env.SHOULD_PULL === 'true' + ) { + execFileSync('git', ['pull', '--ff-only', 'origin', 'main'], { + stdio: 'inherit', + }); + } + const manifest = JSON.parse(readFileSync('package.json', 'utf8')); + const result = await publishPackage({ manifest }); + if (process.env.GITHUB_OUTPUT) { + appendFileSync( + process.env.GITHUB_OUTPUT, + `published=true\npublished_version=${manifest.version}\nalready_published=${result.alreadyPublished}\n` + ); } } -main(); +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch((error) => { + console.error(error.message); + console.error( + 'Register link-foundation/links-queue and workflow js.yml as the npm trusted publisher. See docs/guides/releasing.md for first-publication setup.' + ); + process.exitCode = 1; + }); +} diff --git a/js/scripts/publish-to-npm.test.mjs b/js/scripts/publish-to-npm.test.mjs new file mode 100644 index 0000000..4fec0d1 --- /dev/null +++ b/js/scripts/publish-to-npm.test.mjs @@ -0,0 +1,105 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { publishPackage, registryVersion } from './publish-to-npm.mjs'; + +const manifest = { name: 'links-queue', version: '0.16.0' }; + +test('publishes only the canonical package and verifies registry visibility', async () => { + const calls = []; + let checks = 0; + await publishPackage({ + manifest, + lookup: async (name, version) => { + assert.equal(name, manifest.name); + assert.equal(version, manifest.version); + return ++checks === 3; + }, + run: (...args) => calls.push(args), + wait: async () => {}, + }); + assert.deepEqual(calls, [ + ['npm', ['publish', '--access', 'public', '--provenance']], + ]); +}); + +test('reruns skip existing versions', async () => { + await publishPackage({ + manifest, + lookup: async () => true, + run: () => assert.fail('must not republish'), + }); +}); + +test('failed or invisible publishes cannot report success', async () => { + await assert.rejects( + publishPackage({ + manifest, + lookup: async () => false, + run: () => { + throw new Error('OIDC rejected'); + }, + wait: async () => {}, + }), + /OIDC rejected/ + ); + await assert.rejects( + publishPackage({ + manifest, + lookup: async () => false, + run: () => {}, + wait: async () => {}, + }), + /missing from npm/ + ); +}); + +test('split names cannot be published by this helper', async () => { + await assert.rejects( + publishPackage({ + manifest: { name: 'links-queue-express', version: '1.0.0' }, + }), + /Only the consolidated/ + ); +}); + +test('registry failures are distinguished from absent versions', async () => { + assert.equal( + await registryVersion('links-queue', '1', async () => ({ status: 404 })), + false + ); + await assert.rejects( + registryVersion('links-queue', '1', async () => ({ status: 503 })), + /HTTP 503/ + ); +}); + +test('retries transient publish failures without uploading existing versions twice', async () => { + let uploads = 0; + let visible = false; + await publishPackage({ + manifest, + lookup: async () => visible, + run: () => { + if (++uploads === 1) { + throw new Error('connection reset'); + } + visible = true; + }, + wait: async () => {}, + }); + assert.equal(uploads, 2); + uploads = 0; + visible = false; + const result = await publishPackage({ + manifest, + lookup: async () => visible, + run: () => { + uploads++; + visible = true; + throw new Error('connection lost after upload'); + }, + wait: async () => {}, + }); + assert.equal(uploads, 1); + assert.equal(result.alreadyPublished, true); +}); diff --git a/js/scripts/validate-changeset.mjs b/js/scripts/validate-changeset.mjs index 092f2bb..ee308a9 100644 --- a/js/scripts/validate-changeset.mjs +++ b/js/scripts/validate-changeset.mjs @@ -7,7 +7,7 @@ import { readdirSync, readFileSync } from 'fs'; import { join } from 'path'; -const PACKAGE_NAME = 'links-queue-js'; +const PACKAGE_NAME = 'links-queue'; try { // Count changeset files (excluding README.md and config.json) diff --git a/rust/changelog.d/issue-55-release-runtime.md b/rust/changelog.d/issue-55-release-runtime.md new file mode 100644 index 0000000..fc4e303 --- /dev/null +++ b/rust/changelog.d/issue-55-release-runtime.md @@ -0,0 +1,5 @@ +--- +bump: patch +--- + +Use Node 24 for release tooling so dependency use of Set.union cannot prevent crates.io publishing. Restrict manual registry releases to main.