Skip to content

Commit

Permalink
Pnpm (#653)
Browse files Browse the repository at this point in the history
What:

- switch from `npm` to `pnpm` as a package manager
- update a few dependencies

Why:

- it's faster
- I use it on all my other repos
- it seems to be less error-prone - e.g.
fd85701 - the npm install seemed to
install an old version of the ts-command-line package, which meant
strange type assertions were (sometimes?) necessary
- it's now supported by nodejs via corepack:
https://nodejs.org/api/corepack.html#upgrading-the-global-versions
- it's now supported by np:
https://nodejs.org/api/corepack.html#upgrading-the-global-versions
- +7,877 −24,874

---------

Co-authored-by: Misha Kaletsky <mmkal@users.noreply.github.com>
  • Loading branch information
mmkal and mmkal committed Mar 24, 2024
1 parent c21bafb commit dea98cd
Show file tree
Hide file tree
Showing 10 changed files with 7,879 additions and 24,876 deletions.
32 changes: 14 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ name: CI
on: [push, pull_request]

jobs:
test:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node 16
uses: actions/setup-node@v2
with:
node-version: 16.x
- run: npm install
- run: npm run lint
- run: npm test -- --coverage
- uses: actions/checkout@v4
- run: corepack enable
# rather than use strategy.matrix, install once and run multiple times. Some of the devDependencies refuse to install on lower node versions, but we still want to test on them
- run: pnpm install
- run: pnpm lint
- run: pnpm test -- --coverage
- name: Coverage
uses: codecov/codecov-action@v3
- name: Setup node 14
Expand All @@ -32,15 +30,13 @@ jobs:
create_tgz:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node 20
uses: actions/setup-node@v2
with:
node-version: 20.x
- run: npm install
- run: npm run build
- uses: actions/checkout@v4
- run: corepack enable
- run: pnpm install
- run: pnpm build
- run: npm pack
- run: mv $(ls | grep .tgz) umzug.tgz
- name: rename tgz
run: mv $(ls | grep .tgz) umzug.tgz
- uses: actions/upload-artifact@v3
with:
name: tarball
Expand All @@ -49,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
needs: [create_tgz]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: tarball
Expand Down
2 changes: 1 addition & 1 deletion examples/7-bundling-codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.cache
package-lock.json
yarn.lock
migrate/index.js
dist
2 changes: 1 addition & 1 deletion examples/7-bundling-codegen/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = [
{plugins: {codegen}},
{rules: {'codegen/codegen': 'error'}},
{files: ['migrations/*.ts']},
{ignores: ['migrate/index.js']},
{ignores: ['dist/**']},
]
6 changes: 3 additions & 3 deletions examples/7-bundling-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "umzug-bundling-example",
"version": "0.0.0",
"scripts": {
"lint": "eslint .",
"build": "ncc build umzug.ts --transpile-only --out migrate"
"build": "tsup umzug.ts --external pg-hstore",
"lint": "eslint ."
},
"devDependencies": {
"@vercel/ncc": "^0.36.1",
"eslint": "8.57.0",
"eslint-plugin-codegen": "0.28.0",
"tsup": "8.0.2",
"typescript-eslint": "7.3.1"
}
}
8 changes: 4 additions & 4 deletions examples/7-bundling-codegen/readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
This example shows how Umzug can be used with a bundler like webpack, parcel, turbopack, ncc, bun, esbuild, swc, etc. This scenario isn't really what Umzug was designed for, so it depends on the help of codegen tool.
This example shows how Umzug can be used with a bundler like tsup, webpack, parcel, turbopack, microbundle, ncc, bun, esbuild, swc, etc. This scenario isn't really what Umzug was designed for, so it depends on the help of codegen tool.

Since we're going to be bundling this package, (maybe with the purpose of running migrations in another environment), we can't rely on "globbing" the filesystem. Here, [eslint-plugin-codegen](https://npmjs.com/package/eslint-plugin-codegen) is used to glob for the files when the linter runs, and barrel them into an object (see [barrel.ts](./barrel.ts)). That object can then be passed to the Umzug constructor directly as a list of migrations (see [umzug.ts](./umzug.ts)).

When a new migration file is added, the linter can ensure it is added to the barrel by running `eslint . --fix`.

To try out this example, which uses `ncc`, first install dependencies, then bundle and run the migrator:
To try out this example, which uses `tsup`, first install dependencies, then bundle and run the migrator:

```bash
npm install
npm run lint -- --fix # makes sure barrel is up to date
npm run build

node migrate up # apply migrations
node dist/umzug up # apply migrations

node migrate create --name new-migration.ts --skip-verify # create a new migration file
node dist/umzug create --name new-migration.ts --skip-verify # create a new migration file
npm run lint -- --fix # makes sure barrel is up to date
```

Expand Down
Loading

0 comments on commit dea98cd

Please sign in to comment.