Skip to content

Commit

Permalink
Convert workspace to PNPM (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjameswh authored Dec 9, 2024
1 parent 3c23582 commit 564310b
Show file tree
Hide file tree
Showing 123 changed files with 27,893 additions and 19,961 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8080],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// "postCreateCommand": "npm install",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"updateRemoteUserUID": true
Expand Down
87 changes: 27 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,80 +29,47 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
version: 9

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
# Comment out cache line when testing with act:
# (Test command is: act --platform ubuntu-latest=lucasalt/act_base:latest)
cache: 'npm'
- run: yarn
cache: 'pnpm'

- run: pnpm install
working-directory: ${{ matrix.project }}

- run: npm run build
working-directory: ${{ matrix.project }}

- run: npm test
working-directory: ${{ matrix.project }}

lint-individual:
lint-format-build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
project:
[
activities-cancellation-heartbeating,
activities-dependency-injection,
activities-examples,
child-workflows,
continue-as-new,
cron-workflows,
custom-logger,
dsl-interpreter,
ejson,
encryption,
expense,
fetch-esm,
food-delivery,
grpc-calls,
hello-world,
hello-world-js,
hello-world-mtls,
interceptors-opentelemetry,
monorepo-folders,
mutex,
nestjs-exchange-rates,
nextjs-ecommerce-oneclick,
patching-api,
production,
protobufs,
query-subscriptions,
saga,
schedules,
search-attributes,
signals-queries,
sinks,
snippets,
state,
timer-examples,
timer-progress,
vscode-debugger,
worker-specific-task-queues
]

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
version: 9

- uses: actions/setup-node@v4
with:
node-version: 22
# Comment out cache line when testing with act:
# (Test command is: act --platform ubuntu-latest=lucasalt/act_base:latest)
cache: 'npm'
- run: yarn
working-directory: ${{ matrix.project }}
- run: npm run build
working-directory: ${{ matrix.project }}
if: ${{ matrix.project != 'hello-world-js' }}
- run: npm run lint
working-directory: ${{ matrix.project }}
- run: npx prettier . --check
working-directory: ${{ matrix.project }}
cache: 'pnpm'

- run: pnpm install

- run: pnpm lint
- run: pnpm format:check
- run: pnpm build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ dist

lib/

*/**/yarn.lock
# We only keep PNPM's lockfile in the root directory. Ignore all other lock files.
yarn.lock
package-lock.json
*/**/pnpm-lock.yaml
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
link-workspace-packages = true
shared-workspace-lockfile = true
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ protobufs/protos/json-module.js
protobufs/protos/root.d.ts
.scripts/list-of-samples.json
package-lock.json
pnpm-lock.yaml

nestjs-exchange-rates/dist

.github/workflows/ci.yml
.github/workflows/ci.yml
dist.css
10 changes: 0 additions & 10 deletions .scripts/copy-shared-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,17 @@ const testProjectsNode = testNode.value.items
.find((i) => i.key.value === 'strategy')
.value.items.find((i) => i.key.value === 'matrix')
.value.items.find((i) => i.key.value === 'project');
const lintNode = jobsNode.value.items.find((i) => i.key.value === 'lint-individual');
const lintProjectsNode = lintNode.value.items
.find((i) => i.key.value === 'strategy')
.value.items.find((i) => i.key.value === 'matrix')
.value.items.find((i) => i.key.value === 'project');

testProjectsNode.value.items = [];
lintProjectsNode.value.items = [];

for (const sample of samples) {
// Don't use require, because it won't work with ESM samples
const packageJson = JSON.parse(readFileSync(`../${sample}/package.json`));
const hasTestScript = !!packageJson.scripts.test;
const hasLintScript = !!packageJson.scripts.lint;

if (hasTestScript) {
testProjectsNode.value.items.push(sample);
}
if (hasLintScript) {
lintProjectsNode.value.items.push(sample);
}
}

await fs.writeFile('.github/workflows/ci.yml', ciConfig.toString());
Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
- [Full-stack apps](#full-stack-apps)
- [External apps & libraries](#external-apps--libraries)
- [Contributing](#contributing)
- [Upgrading the SDK version](#upgrading-the-sdk-version)
- [Dependencies](#dependencies)
- [Upgrading the SDK version in `package.json`s](#upgrading-the-sdk-version-in-packagejsons)
- [Config files](#config-files)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -56,8 +57,8 @@ Run the [`hello-world`](./hello-world) sample:
```sh
git clone https://github.com/temporalio/samples-typescript.git
cd samples-typescript/hello-world
npm i
npm start
npm install # or `pnpm` or `yarn`
npm run start
```

and in another terminal:
Expand All @@ -66,6 +67,14 @@ and in another terminal:
npm run workflow
```

> [!NOTE]
> Except when indicated otherwise, samples can be run using any package manager, e.g. `npm`,
> `yarn` or `pnpm`. Refer to individual README.md files for specific instructions.
>
> The root project itself is optimized for work with `pnpm`. Installing dependencies of the root project
> is not required, unless you plan to make contributions (see the [Contributing](#contributing) section
> below for more details).
### Scaffold

To scaffold a new project from one of these samples, run:
Expand Down Expand Up @@ -190,34 +199,27 @@ To get started developing, run:
```bash
git clone https://github.com/temporalio/samples-typescript.git
cd samples-typescript
npm install
npm run prepare
npm run bootstrap
pnpm install
pnpm run prepare
```

Prettier and ESLint are run on each commit, but you can also run them manually:

```sh
npm run format
npm run lint
pnpm run format
pnpm run lint
```

### Dependencies

- The docs and tutorials depend on `SNIPSTART` and `SNIPEND` comments in samples. Make sure to search through the [docs](https://github.com/temporalio/documentation/) and [learn](https://github.com/temporalio/temporal-learning) repos to make sure a snippet is unused before removing it.
- There are [blog posts](https://temporal.io/blog/building-reliable-distributed-systems-in-node) and a PDF that depend on the file structure of the `food-delivery/` sample.

### Updating to latest SDK version

```sh
lerna exec -- npm update
```

### Upgrading the SDK version in `package.json`s

```sh
npx zx .scripts/upgrade-versions.mjs 'VERSION_STRING_HERE'
npm run format
pnpm run upgrade-versions -- 'VERSION_STRING_HERE'
pnpm run format
```

### Config files
Expand Down
2 changes: 1 addition & 1 deletion activities-cancellation-heartbeating/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Running [`src/client.ts`](./src/client.ts) does this:
### Running this sample

1. `temporal server start-dev` to start [Temporal Server](https://github.com/temporalio/cli/#installation).
2. `npm install` to install dependencies.
2. `npm install` to install dependencies (or `pnpm` or `yarn`).
3. `npm run start` to start the Worker.
4. In another shell, `npm run workflow` to run the Workflow.
5. In the first shell, watch the Worker output for a few seconds:
Expand Down
2 changes: 1 addition & 1 deletion activities-cancellation-heartbeating/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion activities-dependency-injection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This sample shows how to [share dependencies](https://docs.temporal.io/dev-guide
### Running this sample

1. `temporal server start-dev` to start [Temporal Server](https://github.com/temporalio/cli/#installation).
2. `npm install` to install dependencies.
2. `npm install` to install dependencies (or `pnpm` or `yarn`).
3. `npm run start.watch` to start the Worker.
4. In another shell, `npm run workflow` to run the Workflow.

Expand Down
2 changes: 1 addition & 1 deletion activities-dependency-injection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
"typescript": "^4.9.5"
}
}
3 changes: 2 additions & 1 deletion activities-examples/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
link-workspace-packages = true
prefer-workspace-packages = true
6 changes: 4 additions & 2 deletions activities-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@temporalio/activity": "^1.11.5",
"@temporalio/client": "^1.11.5",
"@temporalio/common": "^1.11.5",
"@temporalio/worker": "^1.11.5",
"@temporalio/workflow": "^1.11.5",
"axios": "^0.26.0",
Expand Down Expand Up @@ -55,7 +56,8 @@
"source-map-support": "^0.5.21",
"ts-jest": "^28.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.2.2",
"uuid": "^8.3.2"
"typescript": "^4.9.5",
"uuid": "^8.3.2",
"webpack": "5.96.1"
}
}
2 changes: 1 addition & 1 deletion child-workflows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion continue-as-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion cron-workflows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion custom-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion dsl-interpreter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion ejson/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
2 changes: 1 addition & 1 deletion empty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.8.1",
"typescript": "^4.4.2"
"typescript": "^4.9.5"
}
}
3 changes: 3 additions & 0 deletions empty/src/activities.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// Add Activity Definitions here.
export async function YOUR_ACTIVITY(name: string): Promise<string> {
return `Hello, ${name}!`;
}
4 changes: 4 additions & 0 deletions empty/src/workflows.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Add Workflow Definitions here.
export async function YOUR_WORKFLOW(name: string): Promise<string> {
// Your workflow code here
return `Hello, ${name}!`;
}
Loading

0 comments on commit 564310b

Please sign in to comment.