summaryrefslogtreecommitdiff
path: root/packages/create-astro
diff options
context:
space:
mode:
authorGravatar Caleb Williams <caleb.d.williams@gmail.com> 2023-06-08 23:56:29 -0500
committerGravatar GitHub <noreply@github.com> 2023-06-09 07:56:29 +0300
commit1430ffb4734edbb67cbeaaee7e89a9f78e00473c (patch)
tree9c2219fc34cba741b5896b825656744724c19d28 /packages/create-astro
parent5c20476fd333d57c583777893e8c6196b4764d1f (diff)
downloadastro-1430ffb4734edbb67cbeaaee7e89a9f78e00473c.tar.gz
astro-1430ffb4734edbb67cbeaaee7e89a9f78e00473c.tar.zst
astro-1430ffb4734edbb67cbeaaee7e89a9f78e00473c.zip
Fixes an issue where create Astro doesn't respect custom npm registries (#7326)
* Fixes an issue where create Astro doesn't respect custom npm registries * chore: fix pnpm-lock * chore: update lockfile --------- Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to 'packages/create-astro')
-rw-r--r--packages/create-astro/package.json3
-rw-r--r--packages/create-astro/src/messages.ts17
2 files changed, 17 insertions, 3 deletions
diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json
index ff70a70e0..c38e0839a 100644
--- a/packages/create-astro/package.json
+++ b/packages/create-astro/package.json
@@ -35,7 +35,8 @@
"chai": "^4.3.6",
"execa": "^6.1.0",
"giget": "1.0.0",
- "mocha": "^9.2.2"
+ "mocha": "^9.2.2",
+ "preferred-pm": "^3.0.3"
},
"devDependencies": {
"@types/which-pm-runs": "^1.0.0",
diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts
index 45bb7f96a..1134b14df 100644
--- a/packages/create-astro/src/messages.ts
+++ b/packages/create-astro/src/messages.ts
@@ -3,8 +3,20 @@ import { color, label, say as houston, spinner as load } from '@astrojs/cli-kit'
import { align, sleep } from '@astrojs/cli-kit/utils';
import { exec } from 'node:child_process';
import { get } from 'node:https';
+import { execa } from 'execa';
+import preferredPM from 'preferred-pm';
import stripAnsi from 'strip-ansi';
+// Users might lack access to the global npm registry, this function
+// checks the user's project type and will return the proper npm registry
+//
+// A copy of this function also exists in the astro package
+async function getRegistry(): Promise<string> {
+ const packageManager = (await preferredPM(process.cwd()))?.name || 'npm';
+ const { stdout } = await execa(packageManager, ['config', 'get', 'registry']);
+ return stdout || 'https://registry.npmjs.org';
+}
+
let stdout = process.stdout;
/** @internal Used to mock `process.stdout.write` for testing purposes */
export function setStdout(writable: typeof process.stdout) {
@@ -63,9 +75,10 @@ export const getName = () =>
let v: string;
export const getVersion = () =>
- new Promise<string>((resolve) => {
+ new Promise<string>(async (resolve) => {
if (v) return resolve(v);
- get('https://registry.npmjs.org/astro/latest', (res) => {
+ const registry = await getRegistry();
+ get(`${registry}/astro/latest`, (res) => {
let body = '';
res.on('data', (chunk) => (body += chunk));
res.on('end', () => {