Skip to content

Commit

Permalink
Fixes an issue with scoped packages in additionalPackages option
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam committed May 13, 2024
1 parent 864498e commit b8477ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-sheep-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fixes an issue with scoped packages in additionalPackages option
29 changes: 23 additions & 6 deletions packages/cli-v3/src/utilities/installPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,34 @@ export function stripWorkspaceFromVersion(version: string) {
}

export function parsePackageName(packageSpecifier: string): { name: string; version?: string } {
const parts = packageSpecifier.split("@");
let name: string | undefined;
let version: string | undefined;

if (parts.length === 1 && typeof parts[0] === "string") {
return { name: parts[0] };
// Check if the package is scoped
if (packageSpecifier.startsWith("@")) {
const atIndex = packageSpecifier.indexOf("@", 1);
// If a version is included
if (atIndex !== -1) {
name = packageSpecifier.slice(0, atIndex);
version = packageSpecifier.slice(atIndex + 1);
} else {
name = packageSpecifier;
}
} else {
const [packageName, packageVersion] = packageSpecifier.split("@");

if (typeof packageName === "string") {
name = packageName;
}

version = packageVersion;
}

if (parts.length === 2 && typeof parts[0] === "string" && typeof parts[1] === "string") {
return { name: parts[0], version: parts[1] };
if (!name) {
return { name: packageSpecifier };
}

return { name: packageSpecifier };
return { name, version };
}

async function setPackageJsonDeps(path: string, deps: Record<string, string>) {
Expand Down

0 comments on commit b8477ea

Please sign in to comment.