@mastrojs/create-mastro 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +28 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -13,13 +13,17 @@
13
13
  import { exec } from "node:child_process";
14
14
  import { createWriteStream } from "node:fs";
15
15
  import fs from "node:fs/promises";
16
+ import { join } from "node:path";
16
17
  import { stdin, stdout } from "node:process";
17
18
  import { createInterface } from "node:readline/promises";
18
19
  import { Readable } from "node:stream";
19
20
 
21
+ const userAgent = process.env.npm_config_user_agent;
22
+
20
23
  const runtime = typeof Deno === "object"
21
24
  ? "deno"
22
- : (process.env.npm_config_user_agent?.startsWith("bun") ? "bun" : "node");
25
+ // the usual ways to detect Bun don't appear to work in `bun create`
26
+ : (userAgent?.startsWith("bun/") ? "bun" : "node");
23
27
 
24
28
  /**
25
29
  * @param {string} path
@@ -83,13 +87,33 @@ if (dir) {
83
87
  if (unzipSuccess) {
84
88
  await fs.rename(outDir, dir);
85
89
 
86
- const bunOrPnpm = runtime === "bun" ? "bun" : "pnpm";
90
+ const packageManager = (() => {
91
+ switch (userAgent?.split("/")[0]) {
92
+ case "pnpm": return "pnpm";
93
+ case "yarn": return "yarn";
94
+ case "bun": return "bun";
95
+ default: return "npm";
96
+ }
97
+ })();
98
+
99
+ if (packageManager === "npm") {
100
+ try {
101
+ const path = join(dir, "package.json");
102
+ const packageJson = JSON.parse(await fs.readFile(path, { encoding: "utf8" }));
103
+ packageJson.dependencies["@mastrojs/mastro"] = "npm:@jsr/mastrojs__mastro@^0";
104
+ await fs.writeFile(path, JSON.stringify(packageJson, null, 2));
105
+ await fs.writeFile(join(dir, ".npmrc"), "@jsr:registry=https://npm.jsr.io");
106
+ } catch (e) {
107
+ console.error(`Created folder ${dir} but failed to patch it for npm. Please use pnpm instead.`);
108
+ }
109
+ }
110
+
87
111
  const installInstr = runtime === "deno"
88
112
  ? ""
89
- : `\n\nThen install dependencies with: ${bunOrPnpm} install\n`;
113
+ : `\n\nThen install dependencies with: ${packageManager} install\n`;
90
114
  const startInstr = runtime === "deno"
91
115
  ? "deno task start"
92
- : `${bunOrPnpm} run start`;
116
+ : `${packageManager} run start`;
93
117
 
94
118
  const codeStyle = "color: blue";
95
119
  console.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastrojs/create-mastro",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "npm-publish": "deno check && npm publish --access public"