From 3a87b1754aeaa6257ad6de03fae625b647b3bd40 Mon Sep 17 00:00:00 2001 From: Michael Tyson Date: Mon, 4 Nov 2024 23:14:38 -0500 Subject: [PATCH] refactor: consolidate CI workflows and enhance publishing process for JSR and NPM --- .github/workflows/main.yml | 44 ++++++++++++++++++++++++++++++++--- .github/workflows/publish.yml | 41 -------------------------------- README.md | 20 +++++----------- deno.json | 2 +- scripts/build_npm.ts | 3 +-- src/immutable-record.ts | 18 +++++++++++++- 6 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 289f680..d8c5181 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,10 @@ -name: CI +name: CI/CD on: [push] jobs: - build: - name: Build, lint, and test on Deno + integrate: + name: Format, Lint, Test runs-on: ubuntu-latest @@ -25,3 +25,41 @@ jobs: - name: Deno Test run: deno test + + publish: + name: Publish to JSR and NPM + needs: [integrate] + if: startsWith(github.event.ref, 'refs/tags/v') + + runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + - name: Publish package to JSR + run: | + deno run -A ./scripts/prep-jsr.ts ${{ github.ref }} + deno publish --allow-dirty + + - name: build npm package + run: deno run -A ./scripts/build_npm.ts ${{ github.ref }} + + - uses: actions/setup-node@v4 + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + + - name: publish npm package + run: | + cd npm + npm publish --access=public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index f1dfb9e..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Publish to JSR and NPM - -on: - workflow_dispatch: - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - - permissions: - contents: read - id-token: write - - steps: - - uses: actions/checkout@v4 - - - uses: denoland/setup-deno@v2 - with: - deno-version: v2.x - - - name: Publish package to JSR - run: | - deno run -A ./scripts/prep-jsr.ts ${{ github.ref }} - deno publish --allow-dirty - - - name: build npm package - run: deno run -A ./scripts/build_npm.ts ${{ github.ref }} - - - uses: actions/setup-node@v4 - with: - node-version: "20.x" - registry-url: "https://registry.npmjs.org" - - - name: publish npm package - run: | - cd npm - npm publish --access=public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 27fa020..07fc974 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,24 @@ # Introduction -The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a `with` method to the record class. +Built on `immer`, immutable recorda are class factories for immutable types. ## Deno -```typescript -import { - ImmutableConstructor, - ImmutableRecord, - ImmutableWith, -} from "https://deno.land/x/simple-immutable-record/mod.ts"; -``` - -## Node - ```sh -npm install simple-immutable-record +deno add jsr:@myty/immutable-record ``` -or +## Node ```sh -yarn add simple-immutable-record +npm install @myty/immutable-record ``` ## Usage ```typescript +import { ImmutableConstructor, ImmutableRecord, ImmutableWith } from "@myty/immutable-record"; + interface TestDataInterface { testNumber: number; testString: string; diff --git a/deno.json b/deno.json index c591975..4910b08 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@myty/immutable-record", - "description": "The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a with method to the record class.", + "description": "Built on immer, immutable recorda are class factories for immutable types.", "exports": "./mod.ts", "lint": { "rules": { diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index d01903e..00d04cd 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -30,8 +30,7 @@ async function start() { package: { name: "@myty/immutable-record", version: Deno.args[0].substring("refs/tags/v".length), - description: - "The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a with method to the record class.", + description: "Built on immer, immutable recorda are class factories for immutable types.", license: "MIT", author: "Michael Tyson", engines: { diff --git a/src/immutable-record.ts b/src/immutable-record.ts index 0ee6c57..eb41d39 100644 --- a/src/immutable-record.ts +++ b/src/immutable-record.ts @@ -2,20 +2,37 @@ import { enableMapSet, immerable, Immutable, produce } from "immer"; enableMapSet(); +/** + * immutable record interface + */ export interface ImmutableWith { + /** + * Returns a new object if values changed + */ with: (values: Partial>) => this; } +/** + * Represents a constructor for an immutable object + */ export type ImmutableConstructor = new ( value?: Partial>, ) => Immutable & ImmutableWith; +/** + * Class factory to create an immutable record + * @param defaultValues Default values + * @param processor Processor for values + */ export function ImmutableRecord( defaultValues: T | Immutable, processor?: (values: Partial>) => Partial>, ): ImmutableConstructor { const classProcessor = processor ?? ((value: Partial>) => value); + /** + * Immutable record class + */ class ImmutableRecordClass implements ImmutableWith { [immerable] = true; @@ -44,7 +61,6 @@ export function ImmutableRecord( (prev as any)[key] = (values as any)[key]; } }); - ``; }); } }