Fix astro add @example-org/integration
(#4430)
* fix: parse third-party org names * chore: changeset
This commit is contained in:
parent
bc5cb85232
commit
dc42f2c00f
2 changed files with 15 additions and 8 deletions
5
.changeset/loud-eagles-do.md
Normal file
5
.changeset/loud-eagles-do.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
astro add - Fix third-party npm orgs, i.e. `@example/integration`
|
|
@ -619,7 +619,7 @@ async function fetchPackageJson(
|
||||||
name: string,
|
name: string,
|
||||||
tag: string
|
tag: string
|
||||||
): Promise<object | Error> {
|
): Promise<object | Error> {
|
||||||
const packageName = `${scope ? `@${scope}/` : ''}${name}`;
|
const packageName = `${scope ? `${scope}/` : ''}${name}`;
|
||||||
const res = await fetch(`https://registry.npmjs.org/${packageName}/${tag}`);
|
const res = await fetch(`https://registry.npmjs.org/${packageName}/${tag}`);
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
return new Error();
|
return new Error();
|
||||||
|
@ -637,13 +637,14 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
|
throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let { scope, name, tag } = parsed;
|
let { scope, name, tag } = parsed;
|
||||||
let pkgJson = null;
|
let pkgJson;
|
||||||
let pkgType: 'first-party' | 'third-party' = 'first-party';
|
let pkgType: 'first-party' | 'third-party';
|
||||||
|
|
||||||
if (!scope) {
|
if (scope && scope !== '@astrojs') {
|
||||||
const firstPartyPkgCheck = await fetchPackageJson('astrojs', name, tag);
|
pkgType = 'third-party';
|
||||||
|
} else {
|
||||||
|
const firstPartyPkgCheck = await fetchPackageJson('@astrojs', name, tag);
|
||||||
if (firstPartyPkgCheck instanceof Error) {
|
if (firstPartyPkgCheck instanceof Error) {
|
||||||
spinner.warn(
|
spinner.warn(
|
||||||
yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)
|
yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)
|
||||||
|
@ -664,6 +665,7 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
|
||||||
spinner.start('Resolving with third party packages...');
|
spinner.start('Resolving with third party packages...');
|
||||||
pkgType = 'third-party';
|
pkgType = 'third-party';
|
||||||
} else {
|
} else {
|
||||||
|
pkgType = 'first-party';
|
||||||
pkgJson = firstPartyPkgCheck as any;
|
pkgJson = firstPartyPkgCheck as any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,8 +678,8 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedScope = pkgType === 'first-party' ? 'astrojs' : scope;
|
const resolvedScope = pkgType === 'first-party' ? '@astrojs' : scope;
|
||||||
const packageName = `${resolvedScope ? `@${resolvedScope}/` : ''}${name}`;
|
const packageName = `${resolvedScope ? `${resolvedScope}/` : ''}${name}`;
|
||||||
|
|
||||||
let dependencies: IntegrationInfo['dependencies'] = [
|
let dependencies: IntegrationInfo['dependencies'] = [
|
||||||
[pkgJson['name'], `^${pkgJson['version']}`],
|
[pkgJson['name'], `^${pkgJson['version']}`],
|
||||||
|
|
Loading…
Reference in a new issue