syncpack 12.2.0 → 12.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/bin-fix-mismatches/fix-mismatches.d.ts +9 -9
- package/dist/bin-fix-mismatches/fix-mismatches.js +43 -54
- package/dist/bin-fix-mismatches/index.js +26 -31
- package/dist/bin-format/format.d.ts +6 -4
- package/dist/bin-format/format.js +78 -53
- package/dist/bin-format/index.js +20 -25
- package/dist/bin-lint/index.js +15 -20
- package/dist/bin-lint/lint.d.ts +4 -4
- package/dist/bin-lint/lint.js +51 -19
- package/dist/bin-lint-semver-ranges/index.js +24 -29
- package/dist/bin-lint-semver-ranges/lint-semver-ranges.d.ts +8 -8
- package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +34 -44
- package/dist/bin-list/index.js +24 -29
- package/dist/bin-list/list.d.ts +7 -7
- package/dist/bin-list/list.js +55 -64
- package/dist/bin-list-mismatches/index.js +24 -29
- package/dist/bin-list-mismatches/list-mismatches.d.ts +10 -10
- package/dist/bin-list-mismatches/list-mismatches.js +62 -70
- package/dist/bin-prompt/index.js +26 -31
- package/dist/bin-prompt/prompt.d.ts +4 -4
- package/dist/bin-prompt/prompt.js +41 -48
- package/dist/bin-set-semver-ranges/index.js +26 -31
- package/dist/bin-set-semver-ranges/set-semver-ranges.d.ts +4 -4
- package/dist/bin-set-semver-ranges/set-semver-ranges.js +26 -30
- package/dist/bin-update/effects.d.ts +18 -18
- package/dist/bin-update/effects.js +77 -106
- package/dist/bin-update/index.js +23 -28
- package/dist/bin-update/update.d.ts +5 -5
- package/dist/bin-update/update.js +37 -45
- package/dist/bin.js +8 -5
- package/dist/config/get-custom-types.d.ts +9 -9
- package/dist/config/get-custom-types.js +22 -27
- package/dist/config/get-enabled-types.d.ts +8 -8
- package/dist/config/get-enabled-types.js +42 -48
- package/dist/config/get-filter.d.ts +1 -1
- package/dist/config/get-filter.js +6 -9
- package/dist/config/get-indent.d.ts +1 -1
- package/dist/config/get-indent.js +6 -9
- package/dist/config/get-sort-az.d.ts +1 -1
- package/dist/config/get-sort-az.js +6 -17
- package/dist/config/get-sort-exports.d.ts +2 -0
- package/dist/config/get-sort-exports.js +8 -0
- package/dist/config/get-sort-first.d.ts +1 -1
- package/dist/config/get-sort-first.js +6 -8
- package/dist/config/get-source.d.ts +1 -1
- package/dist/config/get-source.js +4 -8
- package/dist/config/tag.d.ts +1 -1
- package/dist/config/tag.js +2 -5
- package/dist/config/types.d.ts +16 -5
- package/dist/config/types.js +1 -2
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +25 -10
- package/dist/error-handlers/default-error-handlers.d.ts +10 -10
- package/dist/error-handlers/default-error-handlers.js +55 -61
- package/dist/get-context/index.d.ts +5 -5
- package/dist/get-context/index.js +13 -17
- package/dist/get-context/lib/key-by.js +1 -5
- package/dist/get-instances/index.d.ts +7 -7
- package/dist/get-instances/index.js +19 -23
- package/dist/get-instances/instance.d.ts +7 -7
- package/dist/get-instances/instance.js +4 -8
- package/dist/get-package-json-files/get-file-paths.d.ts +7 -7
- package/dist/get-package-json-files/get-file-paths.js +10 -15
- package/dist/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-lerna-patterns.js +8 -12
- package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.js +8 -12
- package/dist/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-yarn-patterns.js +14 -18
- package/dist/get-package-json-files/get-patterns/index.d.ts +3 -3
- package/dist/get-package-json-files/get-patterns/index.js +11 -15
- package/dist/get-package-json-files/index.d.ts +8 -8
- package/dist/get-package-json-files/index.js +6 -10
- package/dist/get-package-json-files/package-json-file.d.ts +6 -6
- package/dist/get-package-json-files/package-json-file.js +8 -12
- package/dist/guards/can-add-to-group.d.ts +4 -4
- package/dist/guards/can-add-to-group.js +10 -14
- package/dist/guards/is-semver.js +3 -7
- package/dist/guards/is-valid-semver-range.d.ts +1 -1
- package/dist/guards/is-valid-semver-range.js +12 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/io/ask-for-choice.d.ts +5 -5
- package/dist/io/ask-for-choice.js +5 -9
- package/dist/io/ask-for-input.d.ts +5 -5
- package/dist/io/ask-for-input.js +5 -9
- package/dist/io/exit-if-invalid.d.ts +3 -3
- package/dist/io/exit-if-invalid.js +5 -9
- package/dist/io/glob-sync.d.ts +5 -5
- package/dist/io/glob-sync.js +4 -9
- package/dist/io/index.d.ts +8 -8
- package/dist/io/index.js +12 -38
- package/dist/io/read-config-file.d.ts +7 -0
- package/dist/io/read-config-file.js +22 -0
- package/dist/io/read-file-sync.d.ts +5 -5
- package/dist/io/read-file-sync.js +4 -9
- package/dist/io/read-json-file-sync.d.ts +8 -8
- package/dist/io/read-json-file-sync.js +10 -16
- package/dist/io/read-yaml-file-sync.d.ts +5 -5
- package/dist/io/read-yaml-file-sync.js +4 -8
- package/dist/io/to-json.d.ts +9 -0
- package/dist/io/to-json.js +29 -0
- package/dist/io/write-file-sync.d.ts +5 -5
- package/dist/io/write-file-sync.js +5 -10
- package/dist/io/write-if-changed.d.ts +4 -10
- package/dist/io/write-if-changed.js +9 -44
- package/dist/lib/format-repository-url.js +1 -5
- package/dist/lib/get-group-header.d.ts +2 -2
- package/dist/lib/get-group-header.js +4 -12
- package/dist/lib/get.d.ts +10 -10
- package/dist/lib/get.js +15 -19
- package/dist/lib/pad-start.js +1 -5
- package/dist/lib/ring-buffer.js +1 -5
- package/dist/lib/set-semver-range.d.ts +1 -1
- package/dist/lib/set-semver-range.js +8 -12
- package/dist/lib/show-help-on-error.js +3 -10
- package/dist/lib/sort-by-name.js +1 -5
- package/dist/lib/with-logger.d.ts +1 -1
- package/dist/lib/with-logger.js +17 -24
- package/dist/option.d.ts +1 -1
- package/dist/option.js +8 -14
- package/dist/report.d.ts +2 -2
- package/dist/report.js +2 -5
- package/dist/schema.json +24 -0
- package/dist/semver-group/create-semver-groups.d.ts +3 -3
- package/dist/semver-group/create-semver-groups.js +28 -32
- package/dist/semver-group/disabled.d.ts +11 -11
- package/dist/semver-group/disabled.js +6 -10
- package/dist/semver-group/filtered-out.d.ts +12 -12
- package/dist/semver-group/filtered-out.js +8 -12
- package/dist/semver-group/ignored.d.ts +11 -11
- package/dist/semver-group/ignored.js +6 -10
- package/dist/semver-group/index.d.ts +6 -7
- package/dist/semver-group/index.js +4 -7
- package/dist/semver-group/with-range.d.ts +11 -11
- package/dist/semver-group/with-range.js +13 -17
- package/dist/specifier/alias.d.ts +5 -5
- package/dist/specifier/alias.js +9 -13
- package/dist/specifier/base.d.ts +7 -7
- package/dist/specifier/base.js +9 -13
- package/dist/specifier/delete.d.ts +5 -5
- package/dist/specifier/delete.js +5 -9
- package/dist/specifier/exact.d.ts +6 -6
- package/dist/specifier/exact.js +7 -11
- package/dist/specifier/file.d.ts +1 -1
- package/dist/specifier/file.js +2 -6
- package/dist/specifier/hosted-git.d.ts +5 -5
- package/dist/specifier/hosted-git.js +9 -13
- package/dist/specifier/index.d.ts +13 -13
- package/dist/specifier/index.js +28 -31
- package/dist/specifier/latest.d.ts +6 -6
- package/dist/specifier/latest.js +7 -11
- package/dist/specifier/lib/non-semver-error.d.ts +5 -5
- package/dist/specifier/lib/non-semver-error.js +3 -7
- package/dist/specifier/lib/parse-specifier.d.ts +1 -1
- package/dist/specifier/lib/parse-specifier.js +4 -11
- package/dist/specifier/lib/specific-registry-result.js +1 -2
- package/dist/specifier/range.d.ts +6 -6
- package/dist/specifier/range.js +7 -11
- package/dist/specifier/tag.d.ts +2 -2
- package/dist/specifier/tag.js +2 -6
- package/dist/specifier/unsupported.d.ts +1 -1
- package/dist/specifier/unsupported.js +2 -6
- package/dist/specifier/url.d.ts +1 -1
- package/dist/specifier/url.js +2 -6
- package/dist/specifier/workspace-protocol.d.ts +7 -7
- package/dist/specifier/workspace-protocol.js +9 -13
- package/dist/strategy/lib/get-non-empty-string-prop.d.ts +2 -2
- package/dist/strategy/lib/get-non-empty-string-prop.js +6 -10
- package/dist/strategy/name-and-version-props.d.ts +4 -4
- package/dist/strategy/name-and-version-props.js +19 -23
- package/dist/strategy/named-version-string.d.ts +4 -4
- package/dist/strategy/named-version-string.js +20 -24
- package/dist/strategy/unnamed-version-string.d.ts +4 -4
- package/dist/strategy/unnamed-version-string.js +17 -21
- package/dist/strategy/versions-by-name.d.ts +4 -4
- package/dist/strategy/versions-by-name.js +11 -15
- package/dist/version-group/banned.d.ts +7 -7
- package/dist/version-group/banned.js +8 -12
- package/dist/version-group/create-version-groups.d.ts +3 -3
- package/dist/version-group/create-version-groups.js +34 -38
- package/dist/version-group/filtered-out.d.ts +8 -8
- package/dist/version-group/filtered-out.js +8 -12
- package/dist/version-group/ignored.d.ts +7 -7
- package/dist/version-group/ignored.js +6 -10
- package/dist/version-group/index.d.ts +9 -10
- package/dist/version-group/index.js +4 -7
- package/dist/version-group/lib/clean.js +4 -11
- package/dist/version-group/lib/delete.js +1 -4
- package/dist/version-group/lib/get-highest-version.d.ts +2 -2
- package/dist/version-group/lib/get-highest-version.js +3 -7
- package/dist/version-group/lib/get-lowest-version.d.ts +2 -2
- package/dist/version-group/lib/get-lowest-version.js +3 -7
- package/dist/version-group/lib/get-preferred-version.d.ts +4 -4
- package/dist/version-group/lib/get-preferred-version.js +17 -24
- package/dist/version-group/lib/get-range-score.js +13 -17
- package/dist/version-group/lib/group-by.js +1 -5
- package/dist/version-group/pinned.d.ts +7 -7
- package/dist/version-group/pinned.js +8 -12
- package/dist/version-group/same-range.d.ts +8 -8
- package/dist/version-group/same-range.js +23 -30
- package/dist/version-group/snapped-to.d.ts +7 -7
- package/dist/version-group/snapped-to.js +20 -24
- package/dist/version-group/standard.d.ts +7 -7
- package/dist/version-group/standard.js +29 -33
- package/package.json +30 -37
- package/dist/io/read-config-file-sync.d.ts +0 -7
- package/dist/io/read-config-file-sync.js +0 -26
package/dist/io/index.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { cosmiconfig } from 'cosmiconfig';
|
|
3
3
|
import { Context } from 'effect';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
4
|
+
import enquirer from 'enquirer';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { globbySync } from 'globby';
|
|
7
|
+
import { sync as readYamlFileSync } from 'read-yaml-file';
|
|
8
8
|
export interface Io {
|
|
9
9
|
cosmiconfig: {
|
|
10
10
|
cosmiconfig: typeof cosmiconfig;
|
|
11
11
|
};
|
|
12
12
|
enquirer: {
|
|
13
|
-
prompt: typeof prompt<any>;
|
|
13
|
+
prompt: typeof enquirer.prompt<any>;
|
|
14
14
|
};
|
|
15
15
|
fs: typeof fs;
|
|
16
16
|
globby: {
|
|
17
|
-
sync: typeof
|
|
17
|
+
sync: typeof globbySync;
|
|
18
18
|
};
|
|
19
19
|
process: {
|
|
20
20
|
cwd: typeof process.cwd;
|
|
21
21
|
exit: typeof process.exit;
|
|
22
22
|
};
|
|
23
23
|
readYamlFile: {
|
|
24
|
-
sync: typeof
|
|
24
|
+
sync: typeof readYamlFileSync<any>;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
export declare const IoTag: Context.Tag<Io, Io>;
|
package/dist/io/index.js
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.io = exports.IoTag = void 0;
|
|
27
|
-
const cosmiconfig_1 = require("cosmiconfig");
|
|
28
|
-
const effect_1 = require("effect");
|
|
29
|
-
const enquirer_1 = require("enquirer");
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
const globby = __importStar(require("globby"));
|
|
32
|
-
const readYamlFile = __importStar(require("read-yaml-file"));
|
|
33
|
-
exports.IoTag = effect_1.Context.Tag();
|
|
34
|
-
exports.io = {
|
|
1
|
+
import { cosmiconfig } from 'cosmiconfig';
|
|
2
|
+
import { Context } from 'effect';
|
|
3
|
+
import enquirer from 'enquirer';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { globbySync } from 'globby';
|
|
6
|
+
import { sync as readYamlFileSync } from 'read-yaml-file';
|
|
7
|
+
export const IoTag = Context.GenericTag('@services/IoTag');
|
|
8
|
+
export const io = {
|
|
35
9
|
cosmiconfig: {
|
|
36
|
-
cosmiconfig
|
|
10
|
+
cosmiconfig,
|
|
37
11
|
},
|
|
38
12
|
enquirer: {
|
|
39
|
-
prompt:
|
|
13
|
+
prompt: enquirer.prompt,
|
|
40
14
|
},
|
|
41
15
|
fs: fs,
|
|
42
16
|
globby: {
|
|
43
|
-
sync:
|
|
17
|
+
sync: globbySync,
|
|
44
18
|
},
|
|
45
19
|
process: {
|
|
46
20
|
cwd: process.cwd,
|
|
47
21
|
exit: process.exit,
|
|
48
22
|
},
|
|
49
23
|
readYamlFile: {
|
|
50
|
-
sync:
|
|
24
|
+
sync: readYamlFileSync,
|
|
51
25
|
},
|
|
52
26
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { O } from 'ts-toolbelt';
|
|
3
|
+
import type { RcConfig } from '../config/types.js';
|
|
4
|
+
import type { Io } from './index.js';
|
|
5
|
+
type UnverifiedRcConfig = O.Partial<RcConfig, 'deep'>;
|
|
6
|
+
export declare function readConfigFile(io: Io, configPath?: string): Effect.Effect<UnverifiedRcConfig>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Effect, Option, pipe } from 'effect';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { isNonEmptyObject } from 'tightrope/guard/is-non-empty-object.js';
|
|
4
|
+
import { readJsonFileSync } from './read-json-file-sync.js';
|
|
5
|
+
const getOptionOfNonEmptyObject = Option.liftPredicate((isNonEmptyObject));
|
|
6
|
+
export function readConfigFile(io, configPath) {
|
|
7
|
+
return pipe(Effect.try(() => io.cosmiconfig.cosmiconfig('syncpack')), Effect.flatMap((client) => Effect.tryPromise(() => (configPath ? client.load(configPath) : client.search()))), Effect.flatMap((result) => result !== null ? getValueFromCosmiconfig(result) : findConfigInPackageJson(io)), Effect.tap((config) => Effect.logDebug(`config file found: ${JSON.stringify(config)}`)), Effect.tapError(() => Effect.logDebug('no config file found, will use defaults')), Effect.catchAll(() => Effect.succeed({})));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Look for a .config.syncpack property in the root package.json.
|
|
11
|
+
* @see https://github.com/JamieMason/syncpack/issues/86
|
|
12
|
+
*/
|
|
13
|
+
function findConfigInPackageJson(io) {
|
|
14
|
+
return pipe(Effect.Do, Effect.bind('rcPath', () => Effect.succeed(join(io.process.cwd(), 'package.json'))), Effect.bind('packageJson', ({ rcPath }) => readJsonFileSync(io, rcPath)), Effect.bind('config', ({ packageJson }) => Effect.try(() => packageJson.contents?.config?.syncpack)), Effect.flatMap(({ config }) => getOptionOfNonEmptyObject(config)), Effect.tapBoth({
|
|
15
|
+
onSuccess: () => Effect.logDebug('config found in <package.json>.config.syncpack'),
|
|
16
|
+
onFailure: () => Effect.logDebug('config not found in <package.json>.config.syncpack'),
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
/** Extract the value from a successful search by cosmiconfig */
|
|
20
|
+
function getValueFromCosmiconfig(result) {
|
|
21
|
+
return pipe(Effect.succeed(result), Effect.tap((result) => Effect.logDebug(`cosmiconfig found ${result.filepath}`)), Effect.flatMap((result) => getOptionOfNonEmptyObject(result.config)));
|
|
22
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Io } from '.';
|
|
3
|
-
declare const ReadFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { Io } from './index.js';
|
|
3
|
+
declare const ReadFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
4
4
|
readonly _tag: "ReadFileError";
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
6
|
export declare class ReadFileError extends ReadFileError_base<{
|
|
7
7
|
readonly filePath: string;
|
|
8
8
|
readonly error: string;
|
|
9
9
|
}> {
|
|
10
10
|
}
|
|
11
|
-
export declare function readFileSync(io: Io, filePath: string): Effect.Effect<
|
|
11
|
+
export declare function readFileSync(io: Io, filePath: string): Effect.Effect<string, ReadFileError>;
|
|
12
12
|
export {};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.readFileSync = exports.ReadFileError = void 0;
|
|
4
|
-
const effect_1 = require("effect");
|
|
5
|
-
class ReadFileError extends effect_1.Data.TaggedClass('ReadFileError') {
|
|
1
|
+
import { Data, Effect } from 'effect';
|
|
2
|
+
export class ReadFileError extends Data.TaggedClass('ReadFileError') {
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return effect_1.Effect.try({
|
|
4
|
+
export function readFileSync(io, filePath) {
|
|
5
|
+
return Effect.try({
|
|
10
6
|
try: () => io.fs.readFileSync(filePath, { encoding: 'utf8' }),
|
|
11
7
|
catch: (err) => new ReadFileError({ filePath, error: String(err) }),
|
|
12
8
|
});
|
|
13
9
|
}
|
|
14
|
-
exports.readFileSync = readFileSync;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Io } from '.';
|
|
3
|
-
import type { ReadFileError } from './read-file-sync';
|
|
4
|
-
declare const JsonParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { Io } from './index.js';
|
|
3
|
+
import type { ReadFileError } from './read-file-sync.js';
|
|
4
|
+
declare const JsonParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
5
5
|
readonly _tag: "JsonParseError";
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
7
|
export declare class JsonParseError extends JsonParseError_base<{
|
|
8
8
|
readonly error: unknown;
|
|
9
9
|
readonly filePath: string;
|
|
10
10
|
readonly json: string;
|
|
11
11
|
}> {
|
|
12
12
|
}
|
|
13
|
-
declare const JsonFile_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<
|
|
13
|
+
declare const JsonFile_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
14
14
|
readonly _tag: "JsonFile";
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
export declare class JsonFile<T> extends JsonFile_base<{
|
|
17
17
|
/** absolute path on disk to the directory of this file */
|
|
18
18
|
readonly dirPath: string;
|
|
@@ -26,5 +26,5 @@ export declare class JsonFile<T> extends JsonFile_base<{
|
|
|
26
26
|
readonly json: string;
|
|
27
27
|
}> {
|
|
28
28
|
}
|
|
29
|
-
export declare function readJsonFileSync<T>(io: Io, filePath: string): Effect.Effect<
|
|
29
|
+
export declare function readJsonFileSync<T>(io: Io, filePath: string): Effect.Effect<JsonFile<T>, ReadFileError | JsonParseError>;
|
|
30
30
|
export {};
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const read_file_sync_1 = require("./read-file-sync");
|
|
7
|
-
class JsonParseError extends effect_1.Data.TaggedClass('JsonParseError') {
|
|
1
|
+
import { Data, Effect, pipe } from 'effect';
|
|
2
|
+
import { dirname, relative } from 'path';
|
|
3
|
+
import { readFileSync } from './read-file-sync.js';
|
|
4
|
+
export class JsonParseError extends Data.TaggedClass('JsonParseError') {
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
class JsonFile extends effect_1.Data.TaggedClass('JsonFile') {
|
|
6
|
+
export class JsonFile extends Data.TaggedClass('JsonFile') {
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return (0, effect_1.pipe)(effect_1.Effect.Do, effect_1.Effect.bind('json', () => (0, read_file_sync_1.readFileSync)(io, filePath)), effect_1.Effect.bind('contents', ({ json }) => effect_1.Effect.try({
|
|
8
|
+
export function readJsonFileSync(io, filePath) {
|
|
9
|
+
return pipe(Effect.Do, Effect.bind('json', () => readFileSync(io, filePath)), Effect.bind('contents', ({ json }) => Effect.try({
|
|
15
10
|
try: () => JSON.parse(json),
|
|
16
11
|
catch: (error) => new JsonParseError({ error, filePath, json }),
|
|
17
|
-
})),
|
|
12
|
+
})), Effect.map(({ contents, json }) => new JsonFile({
|
|
18
13
|
contents,
|
|
19
|
-
dirPath:
|
|
14
|
+
dirPath: dirname(filePath),
|
|
20
15
|
filePath,
|
|
21
16
|
json,
|
|
22
|
-
shortPath:
|
|
17
|
+
shortPath: relative(io.process.cwd(), filePath),
|
|
23
18
|
})));
|
|
24
19
|
}
|
|
25
|
-
exports.readJsonFileSync = readJsonFileSync;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Io } from '.';
|
|
3
|
-
declare const ReadYamlFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { Io } from './index.js';
|
|
3
|
+
declare const ReadYamlFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
4
4
|
readonly _tag: "ReadYamlFileError";
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
6
|
declare class ReadYamlFileError extends ReadYamlFileError_base<{
|
|
7
7
|
readonly filePath: string;
|
|
8
8
|
readonly error: string;
|
|
9
9
|
}> {
|
|
10
10
|
}
|
|
11
|
-
export declare function readYamlFileSync<T = unknown>(io: Io, filePath: string): Effect.Effect<
|
|
11
|
+
export declare function readYamlFileSync<T = unknown>(io: Io, filePath: string): Effect.Effect<T, ReadYamlFileError>;
|
|
12
12
|
export {};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.readYamlFileSync = void 0;
|
|
4
|
-
const effect_1 = require("effect");
|
|
5
|
-
class ReadYamlFileError extends effect_1.Data.TaggedClass('ReadYamlFileError') {
|
|
1
|
+
import { Data, Effect } from 'effect';
|
|
2
|
+
class ReadYamlFileError extends Data.TaggedClass('ReadYamlFileError') {
|
|
6
3
|
}
|
|
7
|
-
function readYamlFileSync(io, filePath) {
|
|
8
|
-
return
|
|
4
|
+
export function readYamlFileSync(io, filePath) {
|
|
5
|
+
return Effect.try({
|
|
9
6
|
try: () => io.readYamlFile.sync(filePath),
|
|
10
7
|
catch: (err) => new ReadYamlFileError({ filePath, error: String(err) }),
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
|
-
exports.readYamlFileSync = readYamlFileSync;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Ctx } from '../get-context/index.js';
|
|
2
|
+
import type { PackageJsonFile } from '../get-package-json-files/package-json-file.js';
|
|
3
|
+
type Ending = '\n' | '\r' | '\r\n' | string;
|
|
4
|
+
export declare const newlines: {
|
|
5
|
+
detect(source: string): Ending;
|
|
6
|
+
fix(source: string, lineEnding: Ending): string;
|
|
7
|
+
};
|
|
8
|
+
export declare function toJson(ctx: Ctx, file: PackageJsonFile): string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EOL } from 'os';
|
|
2
|
+
import { getIndent } from '../config/get-indent.js';
|
|
3
|
+
const CR = '\r';
|
|
4
|
+
const CRLF = '\r\n';
|
|
5
|
+
const LF = '\n';
|
|
6
|
+
export const newlines = {
|
|
7
|
+
detect(source) {
|
|
8
|
+
const cr = source.split(CR).length;
|
|
9
|
+
const lf = source.split(LF).length;
|
|
10
|
+
const crlf = source.split(CRLF).length;
|
|
11
|
+
if (cr + lf === 0)
|
|
12
|
+
return EOL;
|
|
13
|
+
if (crlf === cr && crlf === lf)
|
|
14
|
+
return CRLF;
|
|
15
|
+
if (cr > lf)
|
|
16
|
+
return CR;
|
|
17
|
+
return LF;
|
|
18
|
+
},
|
|
19
|
+
fix(source, lineEnding) {
|
|
20
|
+
return source.replace(/\r\n|\n|\r/g, lineEnding);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export function toJson(ctx, file) {
|
|
24
|
+
const contents = file.jsonFile.contents;
|
|
25
|
+
const indent = getIndent(ctx.config);
|
|
26
|
+
const EOL = newlines.detect(file.jsonFile.json);
|
|
27
|
+
const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
|
|
28
|
+
return newlines.fix(source, EOL);
|
|
29
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Io } from '.';
|
|
3
|
-
declare const WriteFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import type { Io } from './index.js';
|
|
3
|
+
declare const WriteFileError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
|
|
4
4
|
readonly _tag: "WriteFileError";
|
|
5
|
-
}
|
|
5
|
+
};
|
|
6
6
|
export declare class WriteFileError extends WriteFileError_base<{
|
|
7
7
|
readonly filePath: string;
|
|
8
8
|
readonly error: string;
|
|
9
9
|
}> {
|
|
10
10
|
}
|
|
11
|
-
export declare function writeFileSync(filePath: string, contents: string): Effect.Effect<
|
|
11
|
+
export declare function writeFileSync(filePath: string, contents: string): Effect.Effect<void, WriteFileError, Io>;
|
|
12
12
|
export {};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const effect_1 = require("effect");
|
|
5
|
-
const _1 = require(".");
|
|
6
|
-
class WriteFileError extends effect_1.Data.TaggedClass('WriteFileError') {
|
|
1
|
+
import { Data, Effect, pipe } from 'effect';
|
|
2
|
+
import { IoTag } from './index.js';
|
|
3
|
+
export class WriteFileError extends Data.TaggedClass('WriteFileError') {
|
|
7
4
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return (0, effect_1.pipe)(_1.IoTag, effect_1.Effect.flatMap((io) => effect_1.Effect.try({
|
|
5
|
+
export function writeFileSync(filePath, contents) {
|
|
6
|
+
return pipe(IoTag, Effect.flatMap((io) => Effect.try({
|
|
11
7
|
try: () => io.fs.writeFileSync(filePath, contents),
|
|
12
8
|
catch: (err) => new WriteFileError({ filePath, error: String(err) }),
|
|
13
9
|
})));
|
|
14
10
|
}
|
|
15
|
-
exports.writeFileSync = writeFileSync;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { WriteFileError } from './write-file-sync';
|
|
5
|
-
export declare function writeIfChanged(ctx: Ctx): Effect.Effect<
|
|
6
|
-
type Ending = '\n' | '\r' | '\r\n' | string;
|
|
7
|
-
export declare const newlines: {
|
|
8
|
-
detect(source: string): Ending;
|
|
9
|
-
fix(source: string, lineEnding: Ending): string;
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
2
|
+
import type { Ctx } from '../get-context/index.js';
|
|
3
|
+
import type { Io } from './index.js';
|
|
4
|
+
import type { WriteFileError } from './write-file-sync.js';
|
|
5
|
+
export declare function writeIfChanged(ctx: Ctx): Effect.Effect<Ctx, WriteFileError, Io>;
|
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const get_indent_1 = require("../config/get-indent");
|
|
11
|
-
const constants_1 = require("../constants");
|
|
12
|
-
const write_file_sync_1 = require("./write-file-sync");
|
|
13
|
-
function writeIfChanged(ctx) {
|
|
14
|
-
return (0, effect_1.pipe)(effect_1.Effect.all(ctx.packageJsonFiles.map((file) => (0, effect_1.pipe)(effect_1.Effect.Do, effect_1.Effect.bind('nextJson', () => toJson(file)), effect_1.Effect.bind('hasChanged', ({ nextJson }) => effect_1.Effect.succeed(file.jsonFile.json !== nextJson)), effect_1.Effect.flatMap(({ hasChanged, nextJson }) => hasChanged
|
|
15
|
-
? (0, effect_1.pipe)((0, write_file_sync_1.writeFileSync)(file.jsonFile.filePath, nextJson), effect_1.Effect.flatMap(() => effect_1.Effect.logInfo((0, chalk_1.default) `{green ${constants_1.ICON.tick}} ${file.jsonFile.shortPath}`)))
|
|
16
|
-
: effect_1.Effect.logInfo((0, chalk_1.default) `{dim ${constants_1.ICON.skip} ${file.jsonFile.shortPath}}`))))), effect_1.Effect.map(() => ctx));
|
|
17
|
-
function toJson(file) {
|
|
18
|
-
const contents = file.jsonFile.contents;
|
|
19
|
-
const indent = (0, get_indent_1.getIndent)(ctx.config);
|
|
20
|
-
const EOL = exports.newlines.detect(file.jsonFile.json);
|
|
21
|
-
const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
|
|
22
|
-
return effect_1.Effect.succeed(exports.newlines.fix(source, EOL));
|
|
23
|
-
}
|
|
1
|
+
import chalk from 'chalk-template';
|
|
2
|
+
import { Effect, pipe } from 'effect';
|
|
3
|
+
import { ICON } from '../constants.js';
|
|
4
|
+
import { toJson } from './to-json.js';
|
|
5
|
+
import { writeFileSync } from './write-file-sync.js';
|
|
6
|
+
export function writeIfChanged(ctx) {
|
|
7
|
+
return pipe(Effect.all(ctx.packageJsonFiles.map((file) => pipe(Effect.Do, Effect.bind('nextJson', () => Effect.succeed(toJson(ctx, file))), Effect.bind('hasChanged', ({ nextJson }) => Effect.succeed(file.jsonFile.json !== nextJson)), Effect.flatMap(({ hasChanged, nextJson }) => hasChanged
|
|
8
|
+
? pipe(writeFileSync(file.jsonFile.filePath, nextJson), Effect.flatMap(() => Effect.logInfo(chalk `{green ${ICON.tick}} ${file.jsonFile.shortPath}`)))
|
|
9
|
+
: Effect.logInfo(chalk `{dim ${ICON.skip} ${file.jsonFile.shortPath}}`))))), Effect.map(() => ctx));
|
|
24
10
|
}
|
|
25
|
-
exports.writeIfChanged = writeIfChanged;
|
|
26
|
-
const CR = '\r';
|
|
27
|
-
const CRLF = '\r\n';
|
|
28
|
-
const LF = '\n';
|
|
29
|
-
exports.newlines = {
|
|
30
|
-
detect(source) {
|
|
31
|
-
const cr = source.split(CR).length;
|
|
32
|
-
const lf = source.split(LF).length;
|
|
33
|
-
const crlf = source.split(CRLF).length;
|
|
34
|
-
if (cr + lf === 0)
|
|
35
|
-
return os_1.EOL;
|
|
36
|
-
if (crlf === cr && crlf === lf)
|
|
37
|
-
return CRLF;
|
|
38
|
-
if (cr > lf)
|
|
39
|
-
return CR;
|
|
40
|
-
return LF;
|
|
41
|
-
},
|
|
42
|
-
fix(source, lineEnding) {
|
|
43
|
-
return source.replace(/\r\n|\n|\r/g, lineEnding);
|
|
44
|
-
},
|
|
45
|
-
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatRepositoryUrl = void 0;
|
|
4
|
-
function formatRepositoryUrl(input) {
|
|
1
|
+
export function formatRepositoryUrl(input) {
|
|
5
2
|
if (!input)
|
|
6
3
|
return undefined;
|
|
7
4
|
const extractedUrl = input.match(/https?:\/\/[^\s]+/)?.[0];
|
|
@@ -26,7 +23,6 @@ function formatRepositoryUrl(input) {
|
|
|
26
23
|
return `https://${withoutAffix}`;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.formatRepositoryUrl = formatRepositoryUrl;
|
|
30
26
|
function removeSuffix(url, suffix = '.git') {
|
|
31
27
|
if (url.endsWith(suffix)) {
|
|
32
28
|
return url.slice(0, url.length - suffix.length);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SemverGroup } from '../semver-group';
|
|
2
|
-
import type { VersionGroup } from '../version-group';
|
|
1
|
+
import type { SemverGroup } from '../semver-group/index.js';
|
|
2
|
+
import type { VersionGroup } from '../version-group/index.js';
|
|
3
3
|
export declare function getSemverGroupHeader(input: {
|
|
4
4
|
group: SemverGroup.Any;
|
|
5
5
|
index: number;
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getVersionGroupHeader = exports.getSemverGroupHeader = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
function getSemverGroupHeader(input) {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export function getSemverGroupHeader(input) {
|
|
9
3
|
return getGroupHeader(input.group.config.label || `Semver Group ${input.index + 1}`);
|
|
10
4
|
}
|
|
11
|
-
|
|
12
|
-
function getVersionGroupHeader(input) {
|
|
5
|
+
export function getVersionGroupHeader(input) {
|
|
13
6
|
return getGroupHeader(input.group.config.label || `Version Group ${input.index + 1}`);
|
|
14
7
|
}
|
|
15
|
-
exports.getVersionGroupHeader = getVersionGroupHeader;
|
|
16
8
|
function getGroupHeader(label) {
|
|
17
9
|
const trimmed = label.trim();
|
|
18
10
|
const hasNewLines = trimmed.search(/[\r\n]/) !== -1;
|
|
19
11
|
const header = hasNewLines ? formatMultiLine(trimmed) : formatSingleLine(trimmed);
|
|
20
|
-
return
|
|
12
|
+
return chalk.blue(header);
|
|
21
13
|
}
|
|
22
14
|
function formatSingleLine(label) {
|
|
23
15
|
const leftSide = `= ${label} `;
|
package/dist/lib/get.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Either } from 'effect';
|
|
2
|
-
export declare function get<T, P1 extends keyof NonNullable<T>>(obj: T, prop1: P1): Either.Either<
|
|
3
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>>(obj: T, prop1: P1, prop2: P2): Either.Either<
|
|
4
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>>(obj: T, prop1: P1, prop2: P2, prop3: P3): Either.Either<
|
|
5
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4): Either.Either<
|
|
6
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5): Either.Either<
|
|
7
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6): Either.Either<
|
|
8
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7): Either.Either<
|
|
9
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>, P8 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7, prop8: P8): Either.Either<
|
|
10
|
-
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>, P8 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>, P9 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>[P8]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7, prop8: P8, prop9: P9): Either.Either<
|
|
11
|
-
export declare function get<T>(obj: T, ...props: any[]): Either.Either<
|
|
2
|
+
export declare function get<T, P1 extends keyof NonNullable<T>>(obj: T, prop1: P1): Either.Either<NonNullable<T>[P1], Error>;
|
|
3
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>>(obj: T, prop1: P1, prop2: P2): Either.Either<NonNullable<NonNullable<T>[P1]>[P2], Error>;
|
|
4
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>>(obj: T, prop1: P1, prop2: P2, prop3: P3): Either.Either<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3], Error>;
|
|
5
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4], Error>;
|
|
6
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5], Error>;
|
|
7
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6], Error>;
|
|
8
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7], Error>;
|
|
9
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>, P8 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7, prop8: P8): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>[P8], Error>;
|
|
10
|
+
export declare function get<T, P1 extends keyof NonNullable<T>, P2 extends keyof NonNullable<NonNullable<T>[P1]>, P3 extends keyof NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>, P4 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>, P5 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>, P6 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>, P7 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>, P8 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>, P9 extends keyof NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>[P8]>>(obj: T, prop1: P1, prop2: P2, prop3: P3, prop4: P4, prop5: P5, prop6: P6, prop7: P7, prop8: P8, prop9: P9): Either.Either<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>[P1]>[P2]>[P3]>[P4]>[P5]>[P6]>[P7]>[P8]>[P9], Error>;
|
|
11
|
+
export declare function get<T>(obj: T, ...props: any[]): Either.Either<unknown, Error>;
|
package/dist/lib/get.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const is_readable_1 = require("tightrope/guard/is-readable");
|
|
8
|
-
function get(origin, ...props) {
|
|
9
|
-
return (0, is_readable_1.isReadable)(origin) ? props.reduce(getChild, origin) : ERR_UNREADABLE_ORIGIN(props, origin);
|
|
1
|
+
import { Either } from 'effect';
|
|
2
|
+
import { isFunction } from 'tightrope/guard/is-function.js';
|
|
3
|
+
import { isPrimitive } from 'tightrope/guard/is-primitive.js';
|
|
4
|
+
import { isReadable } from 'tightrope/guard/is-readable.js';
|
|
5
|
+
export function get(origin, ...props) {
|
|
6
|
+
return isReadable(origin) ? props.reduce(getChild, origin) : ERR_UNREADABLE_ORIGIN(props, origin);
|
|
10
7
|
}
|
|
11
|
-
exports.get = get;
|
|
12
8
|
/** Used internally by get to retrieve a single child property from a parent object. */
|
|
13
9
|
function getChild(parent, prop) {
|
|
14
10
|
// quit if any ancestor was already not found
|
|
15
|
-
if (
|
|
11
|
+
if (Either.isEither(parent) && Either.isLeft(parent))
|
|
16
12
|
return parent;
|
|
17
13
|
// ensure we have a plain value and not an Ok
|
|
18
|
-
const value =
|
|
14
|
+
const value = Either.isEither(parent) && Either.isRight(parent) ? Either.getOrThrow(parent) : parent;
|
|
19
15
|
// quit if we can't read properties of value (eg value.likeThis)
|
|
20
|
-
if (!
|
|
16
|
+
if (!isReadable(value))
|
|
21
17
|
return ERR_UNREADABLE_CHILD(prop, value);
|
|
22
18
|
// quit if value is object/array/function etc but the child is not found
|
|
23
|
-
if (!
|
|
19
|
+
if (!isPrimitive(value) && prop in value === false)
|
|
24
20
|
return ERR_NOT_FOUND(prop, value);
|
|
25
21
|
// quit if eg true.toFixed, 12.toUpperCase
|
|
26
|
-
if (
|
|
22
|
+
if (isPrimitive(value) && value[prop] === undefined)
|
|
27
23
|
return ERR_NOT_FOUND(prop, value);
|
|
28
24
|
// the value is present, return it
|
|
29
25
|
const child = value[prop];
|
|
30
|
-
return
|
|
26
|
+
return Either.right(isFunction(child) ? child.bind(value) : child);
|
|
31
27
|
}
|
|
32
28
|
function ERR_UNREADABLE_CHILD(child, value) {
|
|
33
|
-
return
|
|
29
|
+
return Either.left(new Error(`Cannot read "${child}" from unreadable value: ${value}`));
|
|
34
30
|
}
|
|
35
31
|
function ERR_NOT_FOUND(child, value) {
|
|
36
|
-
return
|
|
32
|
+
return Either.left(new Error(`Property "${child}" not found on value: ${value}`));
|
|
37
33
|
}
|
|
38
34
|
function ERR_UNREADABLE_ORIGIN(props, origin) {
|
|
39
|
-
return
|
|
35
|
+
return Either.left(new Error(`Cannot read "${props.join('.')}" from unreadable value: ${origin}`));
|
|
40
36
|
}
|
package/dist/lib/pad-start.js
CHANGED