-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
39 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import { Effect } from "effect"; | ||
import { Data, Effect } from "effect"; | ||
import { readPackage } from "read-pkg"; | ||
|
||
/** @internal */ | ||
export class PackageJsonError { | ||
readonly _tag = "PackageJsonError"; | ||
constructor(readonly cause?: unknown) {} | ||
} | ||
export class PackageJsonError extends Data.TaggedError("PackageJsonError")<{ | ||
cause?: unknown; | ||
}> {} | ||
|
||
/** @internal */ | ||
export const packageJson = (pkgDir: string) => | ||
Effect.tryPromise({ | ||
try: () => readPackage({ cwd: pkgDir }), | ||
catch: (e) => new PackageJsonError(e), | ||
catch: (e) => new PackageJsonError({ cause: e }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { Effect } from "effect"; | ||
import { Data, Effect } from "effect"; | ||
import validate from "validate-npm-package-name"; | ||
|
||
/** @internal */ | ||
export class PackageNameError { | ||
readonly _tag = "PackageNameError"; | ||
} | ||
export class PackageNameError extends Data.TaggedError("PackageNameError")<{ | ||
warnings?: string[]; | ||
errors?: string[]; | ||
}> {} | ||
|
||
/** @internal */ | ||
export const packageName = (pkg: string) => | ||
Effect.suspend(() => { | ||
Effect.gen(function* (_) { | ||
const versionMarker = pkg.lastIndexOf("@"); | ||
const name = pkg.slice(0, versionMarker > 0 ? versionMarker : undefined); | ||
if (!validate(name).validForNewPackages) { | ||
return Effect.fail(new PackageNameError()); | ||
const pkgName = pkg.slice(0, versionMarker > 0 ? versionMarker : undefined); | ||
const { validForNewPackages, warnings, errors } = validate(pkgName); | ||
if (!validForNewPackages) { | ||
return yield* _(new PackageNameError({ warnings, errors })); | ||
} | ||
return Effect.succeed(name); | ||
return pkgName; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters