From ce6946cac4af3a5474d86e57cc866da6309ffb93 Mon Sep 17 00:00:00 2001 From: Joakim Carlstein Date: Tue, 19 Dec 2023 14:00:20 +0100 Subject: [PATCH] feat: support for Bun --- .changeset/lazy-plums-wink.md | 12 ++++++++++++ README.md | 16 +++++++++++++++- docs/src/content/docs/commands/list.mdx | 5 +++++ docs/src/content/docs/commands/new.mdx | 5 +++++ docs/src/content/docs/commands/remove.mdx | 5 +++++ docs/src/content/docs/commands/up.mdx | 5 +++++ docs/src/content/docs/intro/quick-start.mdx | 10 ++++++++++ docs/src/content/docs/intro/whats-emigrate.mdx | 1 + docs/src/content/docs/plugins/generators/js.mdx | 5 +++++ .../content/docs/plugins/generators/mysql.mdx | 5 +++++ .../content/docs/plugins/generators/postgres.mdx | 5 +++++ docs/src/content/docs/plugins/loaders/mysql.mdx | 5 +++++ .../content/docs/plugins/loaders/postgres.mdx | 5 +++++ docs/src/content/docs/plugins/reporters/pino.mdx | 5 +++++ .../content/docs/plugins/storage/file-system.mdx | 5 +++++ docs/src/content/docs/plugins/storage/mysql.mdx | 5 +++++ .../content/docs/plugins/storage/postgres.mdx | 5 +++++ packages/cli/src/cli.ts | 2 +- packages/mysql/package.json | 1 + packages/plugin-generate-js/package.json | 1 + packages/plugin-tools/package.json | 1 + packages/postgres/package.json | 1 + packages/reporter-pino/package.json | 1 + packages/storage-fs/package.json | 1 + packages/types/package.json | 1 + 25 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-plums-wink.md diff --git a/.changeset/lazy-plums-wink.md b/.changeset/lazy-plums-wink.md new file mode 100644 index 0000000..816fab9 --- /dev/null +++ b/.changeset/lazy-plums-wink.md @@ -0,0 +1,12 @@ +--- +'@emigrate/plugin-generate-js': minor +'@emigrate/reporter-pino': minor +'@emigrate/plugin-tools': minor +'@emigrate/storage-fs': minor +'@emigrate/postgres': minor +'@emigrate/mysql': minor +'@emigrate/types': minor +'@emigrate/cli': minor +--- + +Emigrate supports Bun, make use of the `bun` key in package.json `exports` diff --git a/README.md b/README.md index 82ace5e..94c3271 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ It's effectively a successor of [klei-migrate](https://www.npmjs.com/package/klei-migrate) and [Immigration](https://www.npmjs.com/package/immigration). +📖 Read the [documentation](https://emigrate.dev) for more information! + ## Features - Database agnostic @@ -29,6 +31,12 @@ Install the Emigrate CLI in your project: ```bash npm install --save-dev @emigrate/cli +# or +pnpm add --save-dev @emigrate/cli +# or +yarn add --dev @emigrate/cli +# or +bun add --dev @emigrate/cli ``` ## Usage @@ -36,7 +44,13 @@ npm install --save-dev @emigrate/cli Create a new migration: ```bash -emigrate new -d migrations -e .js create some fancy table +npx emigrate new -d migrations -e .js create some fancy table +# or +pnpm emigrate new -d migrations -e .js create some fancy table +# or +yarn emigrate new -d migrations -e .js create some fancy table +# or +bunx --bun emigrate new -d migrations -e .js create some fancy table ``` Will create a new empty JavaScript migration file with the name "YYYYMMDDHHmmssuuu_create_some_fancy_table.js" in the `migrations` directory. diff --git a/docs/src/content/docs/commands/list.mdx b/docs/src/content/docs/commands/list.mdx index e433a34..cb05c16 100644 --- a/docs/src/content/docs/commands/list.mdx +++ b/docs/src/content/docs/commands/list.mdx @@ -29,6 +29,11 @@ It then sorts the migrations by filename in ascending order and outputs them and yarn emigrate list [options] ``` + + ```bash + bunx --bun emigrate list [options] + ``` + ```json {3} { diff --git a/docs/src/content/docs/commands/new.mdx b/docs/src/content/docs/commands/new.mdx index 517bbbb..18b97a8 100644 --- a/docs/src/content/docs/commands/new.mdx +++ b/docs/src/content/docs/commands/new.mdx @@ -28,6 +28,11 @@ The migration file can be based on a template, generated by a + ```bash + bunx --bun emigrate new [options] + ``` + ```json {3} { diff --git a/docs/src/content/docs/commands/remove.mdx b/docs/src/content/docs/commands/remove.mdx index be029eb..600a1df 100644 --- a/docs/src/content/docs/commands/remove.mdx +++ b/docs/src/content/docs/commands/remove.mdx @@ -26,6 +26,11 @@ The `remove` command is used to remove a migration from the history. This is use yarn emigrate remove [options] ``` + + ```bash + bunx --bun emigrate remove [options] + ``` + ```json {3} { diff --git a/docs/src/content/docs/commands/up.mdx b/docs/src/content/docs/commands/up.mdx index b45effb..76d6683 100644 --- a/docs/src/content/docs/commands/up.mdx +++ b/docs/src/content/docs/commands/up.mdx @@ -31,6 +31,11 @@ If any of the migrations fail, the command will be aborted and the rest of the m yarn emigrate up [options] ``` + + ```bash + bunx --bun emigrate up [options] + ``` + ```json {3} { diff --git a/docs/src/content/docs/intro/quick-start.mdx b/docs/src/content/docs/intro/quick-start.mdx index 76cf108..77233c8 100644 --- a/docs/src/content/docs/intro/quick-start.mdx +++ b/docs/src/content/docs/intro/quick-start.mdx @@ -35,6 +35,11 @@ But for now, this is the way to go. yarn add @emigrate/cli ``` + + ```bash + bun add @emigrate/cli + ``` + ### Pick a storage plugin @@ -59,6 +64,11 @@ Install the plugin you want to use, for example the + ```bash + bun add @emigrate/postgres + ``` + ### Create your first migration diff --git a/docs/src/content/docs/intro/whats-emigrate.mdx b/docs/src/content/docs/intro/whats-emigrate.mdx index c152272..fc1a7bd 100644 --- a/docs/src/content/docs/intro/whats-emigrate.mdx +++ b/docs/src/content/docs/intro/whats-emigrate.mdx @@ -8,6 +8,7 @@ import Link from '@components/Link.astro'; Emigrate is written in [TypeScript](https://www.typescriptlang.org) and is a migration tool for any database or data. * It's database agnostic - you can use it with any database, or even with non-database data. +* It can be run on multiple platforms - currently [NodeJS](https://nodejs.org) and [Bun](https://bun.sh) is supported, but more platforms is planned. * It's the successor of [klei-migrate](https://github.com/klei/migrate) and is designed to be compatible with [Immigration](https://github.com/blakeembrey/node-immigration) and many of its storage plugins, as well as [Migrate](https://github.com/tj/node-migrate). * It supports migration files written using CommonJS or ES Modules out of the box, with any of the following extensions: `.js`, `.cjs` or `.mjs`, and supports [async functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function), [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or using the [NodeJS Callback Pattern](https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks#handling-errors-in-callbacks). * Other languages can be used by using a Loader Plugin. diff --git a/docs/src/content/docs/plugins/generators/js.mdx b/docs/src/content/docs/plugins/generators/js.mdx index f344fa5..1e1fae2 100644 --- a/docs/src/content/docs/plugins/generators/js.mdx +++ b/docs/src/content/docs/plugins/generators/js.mdx @@ -25,6 +25,11 @@ A generator plugin for generating new m yarn add @emigrate/plugin-generate-js ``` + + ```bash + bun add @emigrate/plugin-generate-js + ``` + ## Usage diff --git a/docs/src/content/docs/plugins/generators/mysql.mdx b/docs/src/content/docs/plugins/generators/mysql.mdx index 582b16f..786fde0 100644 --- a/docs/src/content/docs/plugins/generators/mysql.mdx +++ b/docs/src/content/docs/plugins/generators/mysql.mdx @@ -25,6 +25,11 @@ The MySQL generator creates new migration files with the `.sql` extension. In th yarn add @emigrate/mysql ``` + + ```bash + bun add @emigrate/mysql + ``` + ## Usage diff --git a/docs/src/content/docs/plugins/generators/postgres.mdx b/docs/src/content/docs/plugins/generators/postgres.mdx index ef7686d..d6e670c 100644 --- a/docs/src/content/docs/plugins/generators/postgres.mdx +++ b/docs/src/content/docs/plugins/generators/postgres.mdx @@ -25,6 +25,11 @@ The PostgreSQL generator creates new migration files with the `.sql` extension. yarn add @emigrate/postgres ``` + + ```bash + bun add @emigrate/postgres + ``` + ## Usage diff --git a/docs/src/content/docs/plugins/loaders/mysql.mdx b/docs/src/content/docs/plugins/loaders/mysql.mdx index a2baab8..52249d0 100644 --- a/docs/src/content/docs/plugins/loaders/mysql.mdx +++ b/docs/src/content/docs/plugins/loaders/mysql.mdx @@ -25,6 +25,11 @@ The MySQL loader plugin transforms `.sql` files into JavaScript functions that E yarn add @emigrate/mysql ``` + + ```bash + bun add @emigrate/mysql + ``` + ## Configuration diff --git a/docs/src/content/docs/plugins/loaders/postgres.mdx b/docs/src/content/docs/plugins/loaders/postgres.mdx index 38ec8ac..39a9f15 100644 --- a/docs/src/content/docs/plugins/loaders/postgres.mdx +++ b/docs/src/content/docs/plugins/loaders/postgres.mdx @@ -25,6 +25,11 @@ The PostgreSQL loader plugin transforms `.sql` files into JavaScript functions t yarn add @emigrate/postgres ``` + + ```bash + bun add @emigrate/postgres + ``` + ## Configuration diff --git a/docs/src/content/docs/plugins/reporters/pino.mdx b/docs/src/content/docs/plugins/reporters/pino.mdx index 37d7be6..5ff75be 100644 --- a/docs/src/content/docs/plugins/reporters/pino.mdx +++ b/docs/src/content/docs/plugins/reporters/pino.mdx @@ -27,6 +27,11 @@ This is useful in production environments where you want all logs as JSON, which yarn add @emigrate/reporter-pino ``` + + ```bash + bun add @emigrate/reporter-pino + ``` + ## Usage diff --git a/docs/src/content/docs/plugins/storage/file-system.mdx b/docs/src/content/docs/plugins/storage/file-system.mdx index 94a5cad..f969129 100644 --- a/docs/src/content/docs/plugins/storage/file-system.mdx +++ b/docs/src/content/docs/plugins/storage/file-system.mdx @@ -29,6 +29,11 @@ This is suitable for simple setups, but for more advanced setups for instance wh yarn add @emigrate/storage-fs ``` + + ```bash + bun add @emigrate/storage-fs + ``` + ## Configuration diff --git a/docs/src/content/docs/plugins/storage/mysql.mdx b/docs/src/content/docs/plugins/storage/mysql.mdx index 8e36a5a..1816179 100644 --- a/docs/src/content/docs/plugins/storage/mysql.mdx +++ b/docs/src/content/docs/plugins/storage/mysql.mdx @@ -25,6 +25,11 @@ The MySQL storage plugin uses a MySQL database to store the migration history (* yarn add @emigrate/mysql ``` + + ```bash + bun add @emigrate/mysql + ``` + ## Configuration diff --git a/docs/src/content/docs/plugins/storage/postgres.mdx b/docs/src/content/docs/plugins/storage/postgres.mdx index 368e894..7e586ed 100644 --- a/docs/src/content/docs/plugins/storage/postgres.mdx +++ b/docs/src/content/docs/plugins/storage/postgres.mdx @@ -25,6 +25,11 @@ The PostgreSQL storage plugin uses a PostgreSQL database to store the migration yarn add @emigrate/postgres ``` + + ```bash + bun add @emigrate/postgres + ``` + ## Configuration diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 0ea469c..de7132b 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -143,7 +143,7 @@ Options: Examples: emigrate new -d src/migrations -t migration-template.js create users table - emigrate new --directory ./migrations --plugin @emigrate/plugin-generate-sql create_users_table + emigrate new --directory ./migrations --plugin @emigrate/postgres create_users_table emigrate new -d ./migrations -e .sql create_users_table emigrate new -d ./migrations -t .migration-template -e .sql "drop some table" `; diff --git a/packages/mysql/package.json b/packages/mysql/package.json index 45f9ef4..dec4f3b 100644 --- a/packages/mysql/package.json +++ b/packages/mysql/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/plugin-generate-js/package.json b/packages/plugin-generate-js/package.json index 6cff96f..4076753 100644 --- a/packages/plugin-generate-js/package.json +++ b/packages/plugin-generate-js/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/plugin-tools/package.json b/packages/plugin-tools/package.json index 04f32a9..7ba094e 100644 --- a/packages/plugin-tools/package.json +++ b/packages/plugin-tools/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/postgres/package.json b/packages/postgres/package.json index 21479ea..1030ad6 100644 --- a/packages/postgres/package.json +++ b/packages/postgres/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/reporter-pino/package.json b/packages/reporter-pino/package.json index f0ece71..95cf8cc 100644 --- a/packages/reporter-pino/package.json +++ b/packages/reporter-pino/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/storage-fs/package.json b/packages/storage-fs/package.json index bcb819e..351a94d 100644 --- a/packages/storage-fs/package.json +++ b/packages/storage-fs/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" } diff --git a/packages/types/package.json b/packages/types/package.json index 0cfaae3..737d465 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -10,6 +10,7 @@ "type": "module", "exports": { ".": { + "bun": "./src/index.ts", "import": "./dist/index.js", "types": "./dist/index.d.ts" }