-
-
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.
Feat: multiple sets of options (#41)
* Schema: allowing multiple sets of options. * Draft implementation. * Ref: moving lookup. * Ref: extracting splitPeers and correcting the type of Manifest. * FIX: working for multiple options. * removing non-null assertion (fixed). * minor: todo. * Extending Manifest type. * More readable Manifest interface. * REF: flattening the actual rule handler. * REF: using R import from ramda. * Fix extra options in Manifest. * Ref: using R.map instead of const assertion. * Ref: extracting typed const slices. * REF: moving splitPeers to helpers, removing flip on R.path, ensuring boolean type. * Testing splitPeers, using exact bool match. * Minor: naming. * Enh: create RegExp once. * Ref: using R.any() instead of Array::some(). * Ref: extracting tester using R.invoker(). * Ref: extracting makeTester. * v1.2.0-beta.1 * Ref: simpler isOptional, without R.path. * v1.2.0-beta.2
- Loading branch information
Showing
6 changed files
with
126 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
import { readFileSync } from "node:fs"; | ||
import { join as joinPath } from "node:path"; | ||
import { flow, join, split, startsWith, take } from "ramda"; | ||
import { join } from "node:path"; | ||
import * as R from "ramda"; | ||
|
||
/** is scoped import: starts with "at" */ | ||
const hasScope = startsWith("@"); | ||
const hasScope = R.startsWith("@"); | ||
|
||
/** gets the dependency name even when importing its internal path */ | ||
export const getName = (imp: string) => | ||
flow(imp, [split("/"), take(hasScope(imp) ? 2 : 1), join("/")]); | ||
R.flow(imp, [R.split("/"), R.take(hasScope(imp) ? 2 : 1), R.join("/")]); | ||
|
||
type Dependencies = Record<string, string>; | ||
type PeerMeta = Record<string, { optional?: boolean }>; | ||
export interface Manifest { | ||
dependencies?: Dependencies; | ||
devDependencies?: Dependencies; | ||
peerDependencies?: Dependencies; | ||
peerDependenciesMeta?: PeerMeta; | ||
[K: string]: unknown; | ||
} | ||
|
||
export const getManifest = (path: string) => | ||
JSON.parse(readFileSync(joinPath(path, "package.json"), "utf8")); | ||
JSON.parse(readFileSync(join(path, "package.json"), "utf8")) as Manifest; | ||
|
||
export const splitPeers = (manifest: Manifest) => { | ||
const isOptional = (name: string) => | ||
manifest.peerDependenciesMeta?.[name]?.optional === true; | ||
const [optionalPeers, requiredPeers] = R.partition( | ||
isOptional, | ||
Object.keys(manifest.peerDependencies || {}), | ||
); | ||
return { requiredPeers, optionalPeers }; | ||
}; |
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