Skip to content

Commit

Permalink
Migrate to pnpm (cloudflare#3889)
Browse files Browse the repository at this point in the history
Co-authored-by: Pete Bacon Darwin <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
3 people authored Sep 6, 2023
1 parent c3684e7 commit 0938e25
Show file tree
Hide file tree
Showing 95 changed files with 14,590 additions and 58,871 deletions.
21 changes: 6 additions & 15 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ description: "Install dependencies, fetching from cache when possible"
runs:
using: "composite"
steps:
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
cache: "pnpm"

- name: ESlint and Typescript caching
uses: actions/cache@v3
Expand All @@ -18,18 +21,6 @@ runs:
tsconfig.tsbuildinfo
key: ${{ matrix.os }}-eslint-tsbuildinfo-${{ hashFiles('**/*.ts','**/*.js', 'package.json', 'tsconfig.json') }}

# Attempt to cache all the node_modules directories based on the OS and package lock.
- name: Cache node_modules
id: npm-cache
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
key: ${{ runner.os }}-${{ env.node-version }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
path: "**/node_modules"

# If the cache missed then install using `npm ci` to follow package lock exactly
- if: ${{ steps.npm-cache.outputs.cache-hit != 'true'}}
- name: Install NPM Dependencies
shell: bash
name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile
14 changes: 3 additions & 11 deletions .github/changeset-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ const { execSync } = require("node:child_process");

// This script is used by the `release.yml` workflow to update the version of the packages being released.
// The standard step is only to run `changeset version` but this does not update the package-lock.json file.
// So we also run `npm install`, which does this update.
// So we also run `pnpm install`, which does this update.
// This is a workaround until this is handled automatically by `changeset version`.
// See https://github.com/changesets/changesets/issues/421.
execSync("npx changeset version");
execSync("pnpm exec changeset version");

// HACK: run a newer version of npm that can update package-lock.json using local dependencies.
// See https://github.com/npm/cli/issues/4379 and https://github.com/npm/cli/pull/4371.
// The error looks like: `No matching version found for wrangler@^2.15.0.`
if (!process.version.startsWith("v16")) {
throw new Error(
"You have updated node version and so you must now remove the hack below!"
);
}
execSync("npx -y [email protected] install --package-lock-only");
execSync("pnpm install");
8 changes: 8 additions & 0 deletions .github/extract-runtime-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from "node:fs/promises";
import module from "node:module";
import path from "node:path";
import url from "node:url";
import { execSync } from "node:child_process";

/**
* @param {string} from
Expand Down Expand Up @@ -53,6 +54,12 @@ const workerdPackageJson = await fs.readFile(workerdPackageJsonPath, "utf8");
const workerdPackage = JSON.parse(workerdPackageJson);
const workerdVersion = workerdPackage.version;

const workerdBinary = path.resolve(workerdPackageJsonPath, "../bin/workerd");

const workerdBinaryVersion = execSync(workerdBinary + " --version")
.toString()
.split(" ")[1];

// 4. Write basic markdown report
const report = [
`\`wrangler@${wranglerVersion}\` includes the following runtime dependencies:`,
Expand All @@ -61,6 +68,7 @@ const report = [
"|-------|----------|--------|",
`|\`miniflare\`|${miniflareVersionConstraint}|${miniflareVersion}|`,
`|\`workerd\`|${workerdVersionConstraint}|${workerdVersion}|`,
`|\`workerd --version\`|${workerdVersion}|${workerdBinaryVersion}|`,
"",
"Please ensure constraints are pinned, and `miniflare`/`workerd` minor versions match.",
"",
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/codecov-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ jobs:
uses: actions/checkout@v3
with:
ref: main

- name: Use Node.js 16.13
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js 16.14
uses: actions/setup-node@v3
with:
node-version: 16.13
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
node-version: 16.14
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -30,15 +32,15 @@ jobs:
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile

- name: Build wrangler
run: npm run build
run: pnpm run build
env:
NODE_ENV: "production"

- name: Run tests & collect coverage
run: npm run test:ci -w wrangler
run: pnpm run --filter wrangler test:ci
env:
NODE_OPTIONS: "--max_old_space_size=8192"

Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js 16.13
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js 16.14
uses: actions/setup-node@v3
with:
node-version: 16.13
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
node-version: 16.14
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -28,7 +30,7 @@ jobs:
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile

- name: Extract runtime versions
run: node .github/extract-runtime-versions.mjs # extract versions before modifying version to include commit hash
Expand All @@ -43,14 +45,14 @@ jobs:
run: node .github/version-script.js

- name: Build
run: npm run build
run: pnpm run build
env:
NODE_ENV: "production"
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_PUBLIC_KEY: ${{ secrets.ALGOLIA_PUBLIC_KEY }}

- name: Pack wrangler
run: npm pack
run: pnpm pack
working-directory: packages/wrangler

- name: Upload packaged wrangler artifact
Expand All @@ -60,7 +62,7 @@ jobs:
path: packages/wrangler/wrangler-*.tgz

- name: Pack @cloudflare/pages-shared
run: npm pack
run: pnpm pack
working-directory: packages/pages-shared

- name: Upload packaged @cloudflare/pages-shared artifact
Expand All @@ -70,7 +72,7 @@ jobs:
path: packages/pages-shared/cloudflare-pages-shared-*.tgz

- name: Pack @cloudflare/create-cloudflare
run: npm pack
run: pnpm pack
working-directory: packages/create-cloudflare

- name: Upload packaged @cloudflare/create-cloudflare artifact
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/d1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js 16.13
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js 16.14
uses: actions/setup-node@v3
with:
node-version: 16.13
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
node-version: 16.14
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -30,21 +32,21 @@ jobs:
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile

- name: Build
run: npm run build
run: pnpm run build

- name: Check for errors
run: npm run check
run: pnpm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Modify package.json version
run: node .github/version-script.js

- name: Publish to NPM
run: npm publish --tag d1
run: pnpm publish --tag d1
env:
NODE_ENV: "production"
NPM_PUBLISH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/devtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js
uses: actions/setup-node@v3
with:
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -32,10 +34,10 @@ jobs:
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile

- name: Build
run: npm run build
run: pnpm run build

- name: Run Devtools release & publish
run: cd packages/wrangler-devtools && make publish
Expand Down
43 changes: 17 additions & 26 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
if: github.repository_owner == 'cloudflare' && (github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains(github.event.*.labels.*.name, 'e2e' )) || (github.event_name == 'pull_request' && github.head_ref == 'changeset-release/main'))
name: "E2E Test"
strategy:
fail-fast: false
matrix:
os: [
# macos-11,
Expand All @@ -31,11 +32,14 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "npm"
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -44,55 +48,42 @@ jobs:
sudo apt-get update
sudo apt-get install -y libc++1
# Attempt to cache all the node_modules directories based on the OS and package lock.
- name: Cache node_modules
id: npm-cache
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
key: ${{ runner.os }}-${{ matrix.node }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
path: "**/node_modules"

# If the cache missed then install using `npm ci` to follow package lock exactly
- if: ${{ steps.npm-cache.outputs.cache-hit != 'true'}}
name: Install NPM Dependencies
run: npm ci
- name: Install NPM Dependencies
run: pnpm install --frozen-lockfile

- name: Run builds
run: npm run build
run: pnpm run build
env:
NODE_ENV: "production"

- name: Build Wrangler package for npm
run: cd packages/wrangler && npm pack
run: pnpm pack --pack-destination $HOME
env:
NODE_ENV: "production"
working-directory: packages/wrangler

- name: Move Wrangler package to tmp directory
- name: Find Wrangler
shell: bash
id: "move-wrangler"
run: |
cp packages/wrangler/wrangler-*.tgz $HOME
echo "dir=$(ls $HOME/wrangler-*.tgz)" >> $GITHUB_OUTPUT;
id: "find-wrangler"
run: echo "dir=$(ls $HOME/wrangler-*.tgz)" >> $GITHUB_OUTPUT;
env:
NODE_ENV: "production"

- name: Run tests
id: e2e-1
continue-on-error: true
run: npm run -w wrangler test:e2e
run: pnpm run --filter wrangler test:e2e
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
WRANGLER: npm install ${{ steps.move-wrangler.outputs.dir}} && npx --prefer-offline wrangler
WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Retry tests
if: steps.e2e-1.outcome == 'failure'
run: npm run -w wrangler test:e2e
run: pnpm run --filter wrangler test:e2e
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
WRANGLER: npm install ${{ steps.move-wrangler.outputs.dir}} && npx --prefer-offline wrangler
WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler
NODE_OPTIONS: "--max_old_space_size=8192"
16 changes: 9 additions & 7 deletions .github/workflows/edge-preview-authenticated-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js 16.13
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js 16.14
uses: actions/setup-node@v3
with:
node-version: 16.13
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run
node-version: 16.14
cache: "pnpm"

- name: Install workerd Dependencies
if: ${{ runner.os == 'Linux' }}
Expand All @@ -30,15 +32,15 @@ jobs:
sudo apt-get install -y libc++1
- name: Install NPM Dependencies
run: npm ci
run: pnpm install --frozen-lockfile

- name: Build wrangler
run: npm run build
run: pnpm run build
env:
NODE_ENV: "production"

- name: Build & Publish Worker
run: npm run publish
run: pnpm run publish
env:
NODE_ENV: "production"
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
Loading

0 comments on commit 0938e25

Please sign in to comment.