From a572e64d9735616767f248a058ebfa62500d89c5 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Wed, 1 Nov 2023 15:54:20 -0700 Subject: [PATCH] Update docs. --- crates/bun/platform/src/lib.rs | 3 +- crates/bun/platform/src/manifest_hash.rs | 10 ----- packages/cli/CHANGELOG.md | 4 ++ .../__partials__/create-task/bun/args.mdx | 8 ++++ .../__partials__/create-task/bun/base.mdx | 8 ++++ .../create-task/bun/filegroups.mdx | 17 ++++++++ .../__partials__/create-task/bun/inputs.mdx | 12 ++++++ .../__partials__/create-task/bun/outputs.mdx | 14 +++++++ .../docs/__partials__/migrate/bun/migrate.mdx | 41 +++++++++++++++++++ .../docs/__partials__/migrate/bun/scripts.mdx | 21 ++++++++++ website/docs/concepts/cache.mdx | 4 +- website/docs/concepts/toolchain.mdx | 5 +++ website/docs/config/project.mdx | 21 ++++++++++ website/docs/config/toolchain.mdx | 21 ++++++++++ website/docs/create-task.mdx | 10 +++++ website/docs/install.mdx | 2 +- website/docs/intro.mdx | 2 +- website/docs/migrate-to-moon.mdx | 4 ++ website/src/components/AddDepsTabs.tsx | 22 ++++++++++ website/src/components/ComparisonTable.tsx | 2 +- website/src/components/LangSelector.tsx | 1 + 21 files changed, 215 insertions(+), 17 deletions(-) delete mode 100644 crates/bun/platform/src/manifest_hash.rs create mode 100644 website/docs/__partials__/create-task/bun/args.mdx create mode 100644 website/docs/__partials__/create-task/bun/base.mdx create mode 100644 website/docs/__partials__/create-task/bun/filegroups.mdx create mode 100644 website/docs/__partials__/create-task/bun/inputs.mdx create mode 100644 website/docs/__partials__/create-task/bun/outputs.mdx create mode 100644 website/docs/__partials__/migrate/bun/migrate.mdx create mode 100644 website/docs/__partials__/migrate/bun/scripts.mdx diff --git a/crates/bun/platform/src/lib.rs b/crates/bun/platform/src/lib.rs index 88878ddf11b..73f7f83b31e 100644 --- a/crates/bun/platform/src/lib.rs +++ b/crates/bun/platform/src/lib.rs @@ -1,6 +1,5 @@ -mod bun_platform; -// mod manifest_hash; mod actions; +mod bun_platform; mod target_hash; pub use bun_platform::*; diff --git a/crates/bun/platform/src/manifest_hash.rs b/crates/bun/platform/src/manifest_hash.rs deleted file mode 100644 index f0e79136b8e..00000000000 --- a/crates/bun/platform/src/manifest_hash.rs +++ /dev/null @@ -1,10 +0,0 @@ -use moon_hash::hash_content; -use moon_rust_lang::cargo_toml::DependencyDetail; -use std::collections::BTreeMap; - -hash_content!( - pub struct RustManifestHash { - pub dependencies: BTreeMap, - pub name: String, - } -); diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index bc616dbf351..55e12f278ed 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -15,9 +15,13 @@ #### 🚀 Updates - Integrated full Bun support (tier 1-3). + - Will download and install Bun into the toolchain when a `version` is configured. + - Will parse the `bun.lockb` lockfile to extract and resolve dependencies. + - Will hash manifests and inputs for Bun specific caching. - Added a `bun` setting to `.moon/toolchain.yml`. - Added a `toolchain.bun` setting to `moon.yml`. - Updated `moon bin` and `moon docker` commands to support Bun. + - Updated task `platform` to support "bun". ## 1.16.0 diff --git a/website/docs/__partials__/create-task/bun/args.mdx b/website/docs/__partials__/create-task/bun/args.mdx new file mode 100644 index 00000000000..42366ac5ce8 --- /dev/null +++ b/website/docs/__partials__/create-task/bun/args.mdx @@ -0,0 +1,8 @@ +```yaml title="/moon.yml" {6} +language: 'javascript' +platform: 'bun' + +tasks: + build: + command: 'webpack build --mode production --no-stats' +``` diff --git a/website/docs/__partials__/create-task/bun/base.mdx b/website/docs/__partials__/create-task/bun/base.mdx new file mode 100644 index 00000000000..2b04efd58c1 --- /dev/null +++ b/website/docs/__partials__/create-task/bun/base.mdx @@ -0,0 +1,8 @@ +```yaml title="/moon.yml" {5,6} +language: 'javascript' +platform: 'bun' + +tasks: + build: + command: 'webpack build' +``` diff --git a/website/docs/__partials__/create-task/bun/filegroups.mdx b/website/docs/__partials__/create-task/bun/filegroups.mdx new file mode 100644 index 00000000000..0ced7c25bee --- /dev/null +++ b/website/docs/__partials__/create-task/bun/filegroups.mdx @@ -0,0 +1,17 @@ +```yaml title="/moon.yml" {11} +language: 'javascript' +platform: 'bun' + +fileGroups: + # ... + +tasks: + build: + command: 'webpack build --mode production --no-stats --output-path @out(0)' + inputs: + - '@globs(sources)' + - 'webpack.config.js' + - '/webpack-shared.config.js' + outputs: + - 'build' +``` diff --git a/website/docs/__partials__/create-task/bun/inputs.mdx b/website/docs/__partials__/create-task/bun/inputs.mdx new file mode 100644 index 00000000000..5c8c0ee4353 --- /dev/null +++ b/website/docs/__partials__/create-task/bun/inputs.mdx @@ -0,0 +1,12 @@ +```yaml title="/moon.yml" {7-10} +language: 'javascript' +platform: 'bun' + +tasks: + build: + command: 'webpack build --mode production --no-stats' + inputs: + - 'src/**/*' + - 'webpack.config.js' + - '/webpack-shared.config.js' +``` diff --git a/website/docs/__partials__/create-task/bun/outputs.mdx b/website/docs/__partials__/create-task/bun/outputs.mdx new file mode 100644 index 00000000000..a7824d18f5f --- /dev/null +++ b/website/docs/__partials__/create-task/bun/outputs.mdx @@ -0,0 +1,14 @@ +```yaml title="/moon.yml" {6,11,12} +language: 'javascript' +platform: 'bun' + +tasks: + build: + command: 'webpack build --mode production --no-stats --output-path @out(0)' + inputs: + - 'src/**/*' + - 'webpack.config.js' + - '/webpack-shared.config.js' + outputs: + - 'build' +``` diff --git a/website/docs/__partials__/migrate/bun/migrate.mdx b/website/docs/__partials__/migrate/bun/migrate.mdx new file mode 100644 index 00000000000..cb755d1b2c3 --- /dev/null +++ b/website/docs/__partials__/migrate/bun/migrate.mdx @@ -0,0 +1,41 @@ +```yaml title="/moon.yml" +language: 'typescript' +platform: 'bun' + +fileGroups: + sources: + - 'src/**/*' + - '*.ts' + - 'bunfig.toml' + tests: + - 'tests/**/*' + +tasks: + dev: + command: 'bun run dev' + inputs: + - '@globs(sources)' + local: true + format: + command: 'bun run format' + inputs: + - '@globs(sources)' + - '@globs(tests)' + lint: + command: 'bun run lint' + inputs: + - '@globs(sources)' + - '@globs(tests)' + test: + command: 'bun test --bail' + inputs: + - '@globs(sources)' + - '@globs(tests)' + typecheck: + command: 'bun run typecheck' + inputs: + - '@globs(sources)' + - '@globs(tests)' + - 'tsconfig.json' + - '/tsconfig.json' +``` diff --git a/website/docs/__partials__/migrate/bun/scripts.mdx b/website/docs/__partials__/migrate/bun/scripts.mdx new file mode 100644 index 00000000000..cd787dd7a2d --- /dev/null +++ b/website/docs/__partials__/migrate/bun/scripts.mdx @@ -0,0 +1,21 @@ +Bun provides a built-in script runner through the [`bun run` command](https://bun.sh/docs/cli/run). +While Bun scripts are great, they're not as efficient as moon. They _do not_ support granular +inputs, smart hashing, incremental caching, and all the other performance benefits that moon +provides. + +With that being said, you _do not_ have to migrate away from Bun scripts. Instead, you can simply +run them from within moon tasks. This gives you the best of both worlds. + +```yaml title="/moon.yml" +language: 'typescript' + +tasks: + analyze: + command: 'bun run analyze' + inputs: + - '@globs(sources)' + - '@globs(tests)' +``` + +> When Bun scripts are ran through moon tasks, the current working directory is set to the project +> root. diff --git a/website/docs/concepts/cache.mdx b/website/docs/concepts/cache.mdx index 2bee28b0593..bc51d5d4822 100644 --- a/website/docs/concepts/cache.mdx +++ b/website/docs/concepts/cache.mdx @@ -27,8 +27,8 @@ Our smart hashing currently takes the following sources into account: - Deno version. - `deno.json`/`deps.ts` imports, import maps, and scopes. - `tsconfig.json` compiler options (when applicable). -- **For Node.js tasks**: - - Node.js version. +- **For Bun and Node.js tasks**: + - Bun/Node.js version. - `package.json` dependencies (including development and peer). - `tsconfig.json` compiler options (when applicable). diff --git a/website/docs/concepts/toolchain.mdx b/website/docs/concepts/toolchain.mdx index eea3e4e8426..9f9ebbf2cf0 100644 --- a/website/docs/concepts/toolchain.mdx +++ b/website/docs/concepts/toolchain.mdx @@ -65,6 +65,11 @@ locally. The following tools are currently managed by the toolchain. +### Bun + +- Configured with: [`bun`](../config/toolchain#bun) +- Installed to: `~/.proto/tools/bun/x.x.x` + ### Deno - Configured with: [`deno`](../config/toolchain#deno) diff --git a/website/docs/config/project.mdx b/website/docs/config/project.mdx index d38007a9a90..6506564ee39 100644 --- a/website/docs/config/project.mdx +++ b/website/docs/config/project.mdx @@ -418,6 +418,8 @@ For interoperability reasons, the following command names have special handling. - `noop`, `no-op`, `nop` - Marks the task as a "no operation". Will not execute a command in the action pipeline but can define dependencies. +- When `platform` is "bun": + - `bun`, `bunx` - Uses the binaries from the toolchain. - When `platform` is "deno": - Will execute with `deno` binary. - When `platform` is "node": @@ -622,6 +624,8 @@ The `platform` field defines the platform (language runtime) the command runs on its executable, and which tool to execute it with. By default moon will set to a value based on the project's [`language`](#language) or default [`platform`](#platform). +- `bun` - Command is a binary within `node_modules` and will be executed with Bun. + - `deno` - Command is executed with Deno, or is a Deno binary located in `~/.deno/bin`. - `node` - Command is a binary within `node_modules` and will be executed with Node.js. - `rust` - Command is executed with Cargo, or is a Cargo binary located in `~/.cargo/bin`. @@ -960,6 +964,23 @@ Dictates how a project interacts with settings defined at the top-level. +### `bun` + + + +Configures Bun for this project and overrides the top-level [`bun`](./toolchain#bun) setting. + +#### `version` + +Defines the explicit Bun [version specification](../concepts/toolchain#version-specification) to use +when _running tasks_ for this project. + +```yaml title="moon.yml" {2,3} +toolchain: + bun: + version: '1.0.0' +``` + ### `node` diff --git a/website/docs/config/toolchain.mdx b/website/docs/config/toolchain.mdx index 412b98b0dd9..16c06e57f8e 100644 --- a/website/docs/config/toolchain.mdx +++ b/website/docs/config/toolchain.mdx @@ -40,6 +40,27 @@ taking precedence over those defined in the extended configuration. ## JavaScript +## `bun` + + + +Enables and configures [Bun](../guides/bun/handbook). + +### `version` + + + +Defines the explicit Bun toolchain +[version specification](../concepts/toolchain#version-specification) to use. If this field is _not +defined_, the global `bun` binary will be used. + +```yaml title=".moon/toolchain.yml" {2} +bun: + version: '1.0.0' +``` + +> Version can also be defined with [`.prototools`](../proto/config). + ## `deno` diff --git a/website/docs/create-task.mdx b/website/docs/create-task.mdx index 6fd0d8831ee..abcc24ec425 100644 --- a/website/docs/create-task.mdx +++ b/website/docs/create-task.mdx @@ -30,6 +30,7 @@ a project using [`moon.yml`](./config/project). Begin by creating the `moon.yml` file at the root of a project and add `build` to the [`tasks`](./config/project#tasks) field, with a [`command`](./config/project#command) parameter. +import BaseBun from './__partials__/create-task/bun/base.mdx'; import BaseDeno from './__partials__/create-task/deno/base.mdx'; import BaseGo from './__partials__/create-task/go/base.mdx'; import BaseNode from './__partials__/create-task/node/base.mdx'; @@ -39,6 +40,7 @@ import BaseRuby from './__partials__/create-task/ruby/base.mdx'; import BaseRust from './__partials__/create-task/rust/base.mdx'; + @@ -51,6 +53,7 @@ import BaseRust from './__partials__/create-task/rust/base.mdx'; By itself, this isn't doing much, so let's add some arguments. Arguments can also be defined with the [`args`](./config/project#args) setting. +import ArgsBun from './__partials__/create-task/bun/args.mdx'; import ArgsDeno from './__partials__/create-task/deno/args.mdx'; import ArgsGo from './__partials__/create-task/go/args.mdx'; import ArgsNode from './__partials__/create-task/node/args.mdx'; @@ -60,6 +63,7 @@ import ArgsRuby from './__partials__/create-task/ruby/args.mdx'; import ArgsRust from './__partials__/create-task/rust/args.mdx'; + @@ -86,6 +90,7 @@ inputs to calculate whether to run, or to return the previous run state from the If you're a bit confused, let's demonstrate this by expanding the task with the [`inputs`](./config/project#inputs) setting. +import InputsBun from './__partials__/create-task/bun/inputs.mdx'; import InputsDeno from './__partials__/create-task/deno/inputs.mdx'; import InputsGo from './__partials__/create-task/go/inputs.mdx'; import InputsNode from './__partials__/create-task/node/inputs.mdx'; @@ -95,6 +100,7 @@ import InputsRuby from './__partials__/create-task/ruby/inputs.mdx'; import InputsRust from './__partials__/create-task/rust/inputs.mdx'; + @@ -134,6 +140,7 @@ then immediately exits. No more waiting for long builds! Continuing our example, let's route the built files and expand our task with the [`outputs`](./config/project#outputs) setting. +import OutputsBun from './__partials__/create-task/bun/outputs.mdx'; import OutputsDeno from './__partials__/create-task/deno/outputs.mdx'; import OutputsGo from './__partials__/create-task/go/outputs.mdx'; import OutputsNode from './__partials__/create-task/node/outputs.mdx'; @@ -143,6 +150,7 @@ import OutputsRuby from './__partials__/create-task/ruby/outputs.mdx'; import OutputsRust from './__partials__/create-task/rust/outputs.mdx'; + @@ -200,6 +208,7 @@ We can then replace the inputs in our task above with these new file groups usin [`@files`](./concepts/token#files) token functions. Tokens are an advanced feature, so please refer to their documentation for more information! +import FilegroupsBun from './__partials__/create-task/bun/filegroups.mdx'; import FilegroupsDeno from './__partials__/create-task/deno/filegroups.mdx'; import FilegroupsGo from './__partials__/create-task/go/filegroups.mdx'; import FilegroupsNode from './__partials__/create-task/node/filegroups.mdx'; @@ -209,6 +218,7 @@ import FilegroupsRuby from './__partials__/create-task/ruby/filegroups.mdx'; import FilegroupsRust from './__partials__/create-task/rust/filegroups.mdx'; + diff --git a/website/docs/install.mdx b/website/docs/install.mdx index d3bf821c294..8f3f034f7a8 100644 --- a/website/docs/install.mdx +++ b/website/docs/install.mdx @@ -69,7 +69,7 @@ irm https://moonrepo.dev/install/moon.ps1 | iex This will install moon to `~\.moon\bin` and prepend to the `PATH` environment variable for the current session. To persist across sessions, update `PATH` manually. -### Node.js +### npm moon is also packaged and shipped as a single binary through the [`@moonrepo/cli`](https://www.npmjs.com/package/@moonrepo/cli) npm package. Begin by installing this diff --git a/website/docs/intro.mdx b/website/docs/intro.mdx index 974dd4fd4cb..55228c3245f 100644 --- a/website/docs/intro.mdx +++ b/website/docs/intro.mdx @@ -73,7 +73,7 @@ incremental integrate and improve them over time. The 4 tiers are as follows: | | Tier 0 | Tier 1 | Tier 2 | Tier 3 | | :---------------------------- | :----: | :----: | :----: | :----: | | Bash/Batch | 🟢 | 🟢 | | | -| Bun (JavaScript, TypeScript) | 🟢 | 🟢 | | 🟣 | +| Bun (JavaScript, TypeScript) | 🟢 | 🟢 | 🟢 | 🟢 | | Deno (JavaScript, TypeScript) | 🟢 | 🟢 | 🟣 | | | Go | 🟢 | 🟢 | | | | Node (JavaScript, TypeScript) | 🟢 | 🟢 | 🟢 | 🟢 | diff --git a/website/docs/migrate-to-moon.mdx b/website/docs/migrate-to-moon.mdx index 7be6f4466cf..d9d6bbfccdc 100644 --- a/website/docs/migrate-to-moon.mdx +++ b/website/docs/migrate-to-moon.mdx @@ -19,6 +19,7 @@ enough to scale for large codebases. An example of what this may look like can be found below. This _may_ look like a lot, but it pays dividends in the long run. +import MigrateBun from './__partials__/migrate/bun/migrate.mdx'; import MigrateDeno from './__partials__/migrate/deno/migrate.mdx'; import MigrateGo from './__partials__/migrate/go/migrate.mdx'; import MigrateNode from './__partials__/migrate/node/migrate.mdx'; @@ -28,6 +29,7 @@ import MigrateRuby from './__partials__/migrate/ruby/migrate.mdx'; import MigrateRust from './__partials__/migrate/rust/migrate.mdx'; + @@ -39,6 +41,7 @@ import MigrateRust from './__partials__/migrate/rust/migrate.mdx'; ## Continue using scripts +import ScriptsBun from './__partials__/migrate/bun/scripts.mdx'; import ScriptsDeno from './__partials__/migrate/deno/scripts.mdx'; import ScriptsGo from './__partials__/migrate/go/scripts.mdx'; import ScriptsNode from './__partials__/migrate/node/scripts.mdx'; @@ -48,6 +51,7 @@ import ScriptsRuby from './__partials__/migrate/ruby/scripts.mdx'; import ScriptsRust from './__partials__/migrate/rust/scripts.mdx'; + diff --git a/website/src/components/AddDepsTabs.tsx b/website/src/components/AddDepsTabs.tsx index 44d38dc1576..56556953a27 100644 --- a/website/src/components/AddDepsTabs.tsx +++ b/website/src/components/AddDepsTabs.tsx @@ -66,6 +66,24 @@ function getPnpm(props: AddDepsTabsProps, workspaces: boolean) { return cmd; } +function getBun(props: AddDepsTabsProps) { + let cmd = `bun install `; + + if (props.dev) { + cmd += '--dev '; + } else if (props.peer) { + cmd += '--peer '; + } + + // if (props.package) { + // cmd += `--workspace ${props.package} `; + // } + + cmd += props.dep; + + return cmd; +} + export default function AddDepsTabs(props: AddDepsTabsProps) { let yarn1 = getYarn(props, false, true); let pnpm = getPnpm(props, false); @@ -87,6 +105,7 @@ export default function AddDepsTabs(props: AddDepsTabsProps) { { label: 'Yarn (classic)', value: 'yarn1' }, { label: 'npm', value: 'npm' }, { label: 'pnpm', value: 'pnpm' }, + { label: 'Bun', value: 'bun' }, ]} > @@ -101,6 +120,9 @@ export default function AddDepsTabs(props: AddDepsTabsProps) { {pnpm} + + {getBun(props)} + ); } diff --git a/website/src/components/ComparisonTable.tsx b/website/src/components/ComparisonTable.tsx index b4b18444e50..f06e634006f 100644 --- a/website/src/components/ComparisonTable.tsx +++ b/website/src/components/ComparisonTable.tsx @@ -105,7 +105,7 @@ const toolchainRows: Comparison[] = [ { feature: 'Supported dependency managers', support: { - moon: 'npm, pnpm, yarn', + moon: 'npm, pnpm, yarn, bun', nx: 'npm, pnpm, yarn', turborepo: 'npm, pnpm, yarn', }, diff --git a/website/src/components/LangSelector.tsx b/website/src/components/LangSelector.tsx index a9a1fea05e0..a1a61027961 100644 --- a/website/src/components/LangSelector.tsx +++ b/website/src/components/LangSelector.tsx @@ -73,6 +73,7 @@ export default function LangSelector() { onChange={handleChange} className="outline-none min-w-0 bg-white border border-solid border-gray-400 dark:border-transparent rounded-md p-0.5 text-sm text-gray-800 placeholder-gray-600 h-full font-sans" > +