Skip to content

Commit

Permalink
Bun fixes (#115)
Browse files Browse the repository at this point in the history
* doc(docs-site): add bun as package manager

* fix bun exec command

---------

Co-authored-by: Stefan Ruzitschka <362487+icepuma@users.noreply.github.com>
  • Loading branch information
theoephraim and icepuma committed Aug 3, 2024
1 parent a79e243 commit d3eaa3f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-ladybugs-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@dmno/1password-plugin": patch
"@dmno/encrypted-vault-plugin": patch
---

republish latest esm/cjs setup for plugins
5 changes: 5 additions & 0 deletions .changeset/modern-radios-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dmno": patch
---

fix bun exec logic
8 changes: 6 additions & 2 deletions packages/core/src/config-loader/config-server-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ConfigLoaderRequestMap } from './ipc-requests';
import { SerializedService } from './serialization-types';
import { formatError, getItemSummary } from '../cli/lib/formatting';
import { InjectedDmnoEnv } from '../config-engine/config-engine';
import { detectPackageManagerSync } from '../lib/detect-package-manager';
import { detectPackageManagerSync, PACKAGE_MANAGERS_META } from '../lib/detect-package-manager';

const debug = Debug('dmno');
const debugTimer = createDebugTimer('dmno:loader-client');
Expand Down Expand Up @@ -52,9 +52,13 @@ export class ConfigServerClient {
private ownedDmnoConfigServerProcess?: ChildProcess;
private initOwnedConfigServer() {
const { packageManager } = detectPackageManagerSync();
const execCommand = PACKAGE_MANAGERS_META[packageManager].exec;
const execCommandParts = execCommand.split(' ');
const execCommandBaseCommand = execCommandParts.shift()!;
const execCommandRest = execCommandParts.join(' ');

// use `pnpm exec` or `npm exec` etc...
this.ownedDmnoConfigServerProcess = spawn(packageManager, 'exec -- dmno dev --silent'.split(' '), {
this.ownedDmnoConfigServerProcess = spawn(execCommandBaseCommand, `${execCommandRest} -- dmno dev --silent`.split(' '), {
stdio: 'inherit',
env: {
...process.env,
Expand Down
31 changes: 29 additions & 2 deletions packages/core/src/lib/detect-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@ import path from 'path';
import kleur from 'kleur';
import { asyncMapValues } from './async-utils';

export type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun' | 'moon';

// TODO: move PACKAGE_MANAGER_RELEVANT_FILES into this
export const PACKAGE_MANAGERS_META = {
npm: {
exec: 'npm exec',
dlx: 'npx',
},
yarn: {
exec: 'yarn exec',
dlx: 'yarn dlx',
},
pnpm: {
exec: 'pnpm exec',
dlx: 'pnpm dlx',
},
bun: {
exec: 'bun run',
dlx: 'bunx',
},
moon: {
// TODO: fix this... we'll need to track the fact that the user is using moon and a package manager
exec: 'npm exec',
dlx: 'npx',
},
} as const;
export type PackageManager = keyof typeof PACKAGE_MANAGERS_META;



export async function pathExists(p: string) {
Expand Down Expand Up @@ -38,7 +64,6 @@ const PACKAGE_MANAGER_RELEVANT_FILES = {
// SEE SYNC VERSION BELOW - UPDATE BOTH IF ANY CHANGES ARE MADE!
export async function detectPackageManager() {
let cwd = process.cwd();

const cwdParts = cwd.split('/');

let packageManager: PackageManager | undefined;
Expand Down Expand Up @@ -78,6 +103,7 @@ export async function detectPackageManager() {
}
}


return {
packageManager,
rootWorkspacePath: cwd,
Expand Down Expand Up @@ -136,3 +162,4 @@ export function detectPackageManagerSync() {




23 changes: 20 additions & 3 deletions packages/docs-site/src/components/TabbedCode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
import { Tabs, TabItem, Code } from "@astrojs/starlight/components";
// import DmnoTabs from "./DmnoTabs.astro";
interface Props {
packageName: string
command: string
dynamicExec: string
}
const { packageName, command, dynamicExec } = Astro.props;
let variant;
let variant: string;
switch (true) {
case Boolean(packageName):
variant = "packageName";
Expand All @@ -15,9 +22,13 @@ switch (true) {
default:
variant = "dynamicExec";
break;
};
};
interface Platform extends Props {
name: string
}
const platforms = [
const platforms: Platform[] = [
{
name: "npm",
packageName: `npm add ${packageName}`,
Expand All @@ -37,6 +48,12 @@ const platforms = [
command: `yarn exec -- ${command}`,
dynamicExec: `yarn dlx ${dynamicExec}`,
},
{
name: "Bun",
packageName: `bun add ${packageName}`,
command: `bun run ${command}`,
dynamicExec: `bunx ${dynamicExec}`,
}
];
---

Expand Down

0 comments on commit d3eaa3f

Please sign in to comment.