Skip to content

Commit

Permalink
update with types
Browse files Browse the repository at this point in the history
  • Loading branch information
ieedan committed Nov 22, 2024
1 parent d43a359 commit 223e8df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/cli/src/utils/parse-package-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
* @module
*/

import { Err, Ok } from './blocks/types/result';
import { Err, Ok, type Result } from './blocks/types/result';

// Parsed a scoped package name into name, version, and path.
const RE_SCOPED = /^(@[^\/]+\/[^@\/]+)(?:@([^\/]+))?(\/.*)?$/;
// Parsed a non-scoped package name into name, version, path
const RE_NON_SCOPED = /^([^@\/]+)(?:@([^\/]+))?(\/.*)?$/;

const parsePackageName = (input: string) => {
export type Package = {
/** Name of the package as it would be installed from npm */
name: string;
/** Version of the package */
version: string;
path: string;
};

const parsePackageName = (input: string): Result<Package, string> => {
const m = RE_SCOPED.exec(input) || RE_NON_SCOPED.exec(input);

if (!m) return Err(`invalid package name: ${input}`);
Expand Down

0 comments on commit 223e8df

Please sign in to comment.