From c94f31493debf33eab3a674ca7254beb5c8a34a2 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 11:53:41 +0200 Subject: [PATCH 01/11] refactor: update ci workflow --- .github/workflows/ci.yml | 176 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76d8546..d4aa2f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,20 +1,96 @@ name: CI on: - pull_request: + push: branches: - main - push: + pull_request: branches: - main jobs: - lint: + # Always use Node 20 + # Add Node 18 to the matrix if we’re in the release PR + define-matrix: + runs-on: ubuntu-latest + + outputs: + node-versions: ${{ steps.node-versions.outputs.node-versions }} + + steps: + - name: Node version matrix + id: node-versions + run: | + if [ "${{ github.head_ref }}" == "changeset-release/main" ]; then + echo 'node-versions=[18, 20]' >> "$GITHUB_OUTPUT" + else + echo 'node-versions=[20]' >> "$GITHUB_OUTPUT" + fi + - name: Print Node version matrix + run: echo "node-versions=${{ steps.node-versions.outputs.node-versions }}" + - name: Check Node version matrix + run: | + if [ "${{ steps.node-versions.outputs.node-versions }}" != "[18, 20]" ] && [ "${{ steps.node-versions.outputs.node-versions }}" != "[20]" ]; then + echo "Node version matrix is not [18, 20] or [20]" + exit 1 + fi + + build: + runs-on: ubuntu-20.04 + needs: define-matrix + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - name: Update Turborepo cache + uses: actions/cache/save@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + + format: runs-on: ubuntu-20.04 strategy: matrix: node-version: [20] + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dev dependencies + run: pnpm install --dev + - name: Check code style + run: pnpm format:check + + types: + runs-on: ubuntu-20.04 + needs: [define-matrix, build] + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 @@ -26,8 +102,94 @@ jobs: - name: Install dependencies run: pnpm install - name: Turborepo cache - uses: dtinth/setup-github-actions-caching-for-turbo@v1 + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - if: matrix.node-version == 20 || github.head_ref == 'changeset-release/main' + name: Check types + run: pnpm turbo types:check + + test: + runs-on: ubuntu-20.04 + needs: [define-matrix, build] + strategy: + matrix: + node-version: ${{ fromJSON(needs.define-matrix.outputs.node-versions) }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build packages + run: pnpm build:packages + - name: Run tests + run: pnpm test:ci + + release: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-20.04 + permissions: + contents: write + id-token: write + needs: [build, test] + strategy: + matrix: + node-version: [20] + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Turborepo cache + uses: actions/cache/restore@v4 + with: + path: .turbo + key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} + - name: Build + run: pnpm turbo build + - name: Git Status + run: git status + - name: Stash changes + run: git stash + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 with: - cache-prefix: snippetz - - name: Build & test - run: pnpm turbo test + # The pull request title. + title: 'chore: release' + # The command to update version, edit CHANGELOG, read and delete changesets. + version: 'pnpm changeset version' + # The commit message to use. + commit: 'chore: version packages' + # The command to use to build and publish packages + publish: 'pnpm -r publish --access public' + env: + # https://github.com/settings/tokens/new + # Expiration: No expiration + # Select: repo.* + GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + # https://www.npmjs.com/settings/YOUR_ACCOUNT_HANDLE/tokens/granular-access-tokens/new + # Custom Expiration: 01-01-2100 + # Permissions: Read and Write + # Select packages: @scalar + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From 26d8b1f5b47d78a9c59626043937d3d93e3c7a7f Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 11:53:56 +0200 Subject: [PATCH 02/11] chore: remove old release workflow --- .github/workflows/release.yml | 50 ----------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 0473567..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Release - -on: - push: - branches: - - main - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -jobs: - release: - name: Release - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [20] - - steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - - name: Install dependencies - run: pnpm install - - name: Turborepo cache - uses: dtinth/setup-github-actions-caching-for-turbo@v1 - with: - cache-prefix: snippetz - - name: Build & test - run: pnpm turbo test - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@v1 - with: - # The pull request title. - title: 'chore: release' - # The command to update version, edit CHANGELOG, read and delete changesets. - version: 'pnpm run bump' - # The commit message to use. - commit: 'chore: version packages' - # The command to use to build and publish packages - publish: 'pnpm -r publish --access public' - env: - GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From 5aeda7a59d038a607d1640a92e90912accf7d979 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 13:13:32 +0200 Subject: [PATCH 03/11] chore: add missing tasks --- .github/workflows/ci.yml | 4 ++-- package.json | 10 +++++----- turbo.json | 10 +++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4aa2f7..8f17e52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,8 +134,8 @@ jobs: with: path: .turbo key: turbo-${{ runner.os }}-node-${{ matrix.node-version }} - - name: Build packages - run: pnpm build:packages + - name: Build + run: pnpm build - name: Run tests run: pnpm test:ci diff --git a/package.json b/package.json index 3b57a25..088b699 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "version": "0.0.0", "type": "module", "scripts": { - "build": "pnpm -r build", - "test": "pnpm -r test", - "dev": "pnpm --filter demo dev", - "bump": "CI=true pnpm run test && pnpm changeset version", - "types:check": "pnpm -r types:check" + "build": "turbo build", + "lint": "pnpm -r lint:check", + "lint:fix": "pnpm -r lint:fix", + "test": "vitest", + "types:check": "turbo --concurrency=100 types:check" }, "devDependencies": { "@changesets/cli": "^2.27.7", diff --git a/turbo.json b/turbo.json index 7afa6c7..06140fc 100644 --- a/turbo.json +++ b/turbo.json @@ -1,12 +1,16 @@ { "$schema": "https://turbo.build/schema.json", "tasks": { + "lint:fix": {}, "build": { "outputs": ["dist/**"], "dependsOn": ["^build"] }, - "test": { - "dependsOn": ["build"] - } + "dev": { + "cache": false, + "persistent": true, + "dependsOn": ["^build"] + }, + "types:check": {} } } From bd154c5d7dfd5cf20c138eeb10272c19ec6a98df Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 13:24:15 +0200 Subject: [PATCH 04/11] fix: TS issue --- packages/snippetz/src/snippetz.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/snippetz/src/snippetz.test.ts b/packages/snippetz/src/snippetz.test.ts index 284ed85..2a84175 100644 --- a/packages/snippetz/src/snippetz.test.ts +++ b/packages/snippetz/src/snippetz.test.ts @@ -58,6 +58,7 @@ describe('hasPlugin', async () => { }) it('returns false if it doesn’t know the plugin', async () => { + // @ts-expect-error Testing invalid input const result = snippetz().hasPlugin('node', 'fantasy') expect(result).toBe(false) From 71eaddc30d54fa3acf506136f1fd825e7edef71a Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 13:25:55 +0200 Subject: [PATCH 05/11] chore: ignore vue TypeScript configuration issue --- demo/src/main.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/demo/src/main.ts b/demo/src/main.ts index 2425c0f..10d1b10 100644 --- a/demo/src/main.ts +++ b/demo/src/main.ts @@ -1,5 +1,6 @@ import { createApp } from 'vue' import './style.css' +// @ts-ignore TODO: Fix tsconfig in a separate PR import App from './App.vue' createApp(App).mount('#app') From e182d00a3e8d98bf76c5a0135816d6e9b88ccc24 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Tue, 23 Jul 2024 14:03:29 +0200 Subject: [PATCH 06/11] chore: update TS config --- demo/package.json | 2 + demo/src/App.vue | 102 +++++++++++------- demo/src/main.ts | 1 - demo/src/vite-env.d.ts | 1 - demo/tsconfig.json | 36 +++---- demo/tsconfig.node.json | 10 -- demo/vite.config.ts | 28 ++--- package.json | 1 + packages/snippetz-core/tsconfig.json | 5 + .../snippetz-plugin-js-fetch/tsconfig.json | 5 + .../snippetz-plugin-js-ofetch/tsconfig.json | 5 + .../snippetz-plugin-node-fetch/tsconfig.json | 5 + .../snippetz-plugin-node-ofetch/tsconfig.json | 5 + packages/snippetz/src/snippetz.test.ts | 1 - packages/snippetz/src/snippetz.ts | 4 +- packages/snippetz/tsconfig.json | 5 + tsconfig.json | 35 +++--- 17 files changed, 142 insertions(+), 109 deletions(-) delete mode 100644 demo/src/vite-env.d.ts delete mode 100644 demo/tsconfig.node.json create mode 100644 packages/snippetz-core/tsconfig.json create mode 100644 packages/snippetz-plugin-js-fetch/tsconfig.json create mode 100644 packages/snippetz-plugin-js-ofetch/tsconfig.json create mode 100644 packages/snippetz-plugin-node-fetch/tsconfig.json create mode 100644 packages/snippetz-plugin-node-ofetch/tsconfig.json create mode 100644 packages/snippetz/tsconfig.json diff --git a/demo/package.json b/demo/package.json index cff62fe..ceca236 100644 --- a/demo/package.json +++ b/demo/package.json @@ -6,6 +6,8 @@ "scripts": { "dev": "vite", "build": "vue-tsc && vite build", + "types:build": "vue-tsc -p tsconfig.build.json", + "types:check": "vue-tsc --composite false", "preview": "vite preview" }, "dependencies": { diff --git a/demo/src/App.vue b/demo/src/App.vue index 0a931a7..914f774 100644 --- a/demo/src/App.vue +++ b/demo/src/App.vue @@ -1,70 +1,98 @@