@stacksjs/utils 0.58.63 → 0.58.64
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/dist/index.js +4 -8
- package/package.json +1 -1
- package/src/base.ts +4 -4
- package/src/helpers.ts +3 -3
- package/src/retry.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/base.ts
|
|
3
3
|
import {toString} from "@stacksjs/strings";
|
|
4
|
-
function assert(condition, message) {
|
|
5
|
-
if (!condition)
|
|
6
|
-
throw new Error(message);
|
|
7
|
-
}
|
|
8
4
|
async function loop(times, callback) {
|
|
9
5
|
[...Array(times)].forEach(async (item, i) => await callback(i));
|
|
10
6
|
}
|
|
@@ -516,7 +512,7 @@ function retry(fn, options) {
|
|
|
516
512
|
attempt();
|
|
517
513
|
});
|
|
518
514
|
}
|
|
519
|
-
|
|
515
|
+
function calculateDelay(attemptCount, initialDelay, backoffFactor, jitter) {
|
|
520
516
|
let delay = initialDelay * backoffFactor ** attemptCount;
|
|
521
517
|
if (jitter) {
|
|
522
518
|
const random = Math.random();
|
|
@@ -524,7 +520,7 @@ var calculateDelay = function(attemptCount, initialDelay, backoffFactor, jitter)
|
|
|
524
520
|
delay = delay + jitterValue * (random - 0.5) * 2;
|
|
525
521
|
}
|
|
526
522
|
return delay;
|
|
527
|
-
}
|
|
523
|
+
}
|
|
528
524
|
// src/sleep.ts
|
|
529
525
|
function sleep(ms) {
|
|
530
526
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -922,7 +918,7 @@ function prettyBytes(number, options) {
|
|
|
922
918
|
return prefix + numberString + separator + unit;
|
|
923
919
|
}
|
|
924
920
|
// package.json
|
|
925
|
-
var version = "0.58.
|
|
921
|
+
var version = "0.58.64";
|
|
926
922
|
export {
|
|
927
923
|
wordChar,
|
|
928
924
|
wordBoundary,
|
|
@@ -1293,6 +1289,7 @@ export {
|
|
|
1293
1289
|
char,
|
|
1294
1290
|
caseInsensitive,
|
|
1295
1291
|
carriageReturn,
|
|
1292
|
+
calculateDelay,
|
|
1296
1293
|
breakpointsVuetify,
|
|
1297
1294
|
breakpointsTailwind,
|
|
1298
1295
|
breakpointsSematic,
|
|
@@ -1303,7 +1300,6 @@ export {
|
|
|
1303
1300
|
batchInvoke,
|
|
1304
1301
|
autoResetRef,
|
|
1305
1302
|
asyncComputed,
|
|
1306
|
-
assert,
|
|
1307
1303
|
anyOf,
|
|
1308
1304
|
and,
|
|
1309
1305
|
allocate,
|
package/package.json
CHANGED
package/src/base.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { toString } from '@stacksjs/strings'
|
|
2
2
|
|
|
3
|
-
export function assert(condition: boolean, message: string): asserts condition {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
// export function assert(condition: boolean, message: string): asserts condition {
|
|
4
|
+
// if (!condition)
|
|
5
|
+
// throw new Error(message)
|
|
6
|
+
// }
|
|
7
7
|
|
|
8
8
|
// export function noop() {}
|
|
9
9
|
|
package/src/helpers.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Result } from '@stacksjs/error-handling'
|
|
|
6
6
|
import { err, handleError, ok } from '@stacksjs/error-handling'
|
|
7
7
|
import { frameworkPath, projectPath } from '@stacksjs/path'
|
|
8
8
|
import * as storage from '@stacksjs/storage'
|
|
9
|
-
import type { CliOptions, Manifest,
|
|
9
|
+
import type { CliOptions, Manifest, SyncSubprocess } from '@stacksjs/types'
|
|
10
10
|
import type { NpmScript } from '@stacksjs/enums'
|
|
11
11
|
import { Action } from '@stacksjs/enums'
|
|
12
12
|
import { parse } from 'yaml'
|
|
@@ -19,7 +19,7 @@ export async function packageManager() {
|
|
|
19
19
|
return packageManager
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export async function initProject(): Promise<Result<SyncSubprocess,
|
|
22
|
+
export async function initProject(): Promise<Result<SyncSubprocess, Error>> {
|
|
23
23
|
if (app.env !== 'production')
|
|
24
24
|
log.info('Project not yet initialized, generating application key...')
|
|
25
25
|
else
|
|
@@ -131,7 +131,7 @@ export async function setEnvValue(key: string, value: string) {
|
|
|
131
131
|
/**
|
|
132
132
|
* Runs the specified NPM script in the package.json file.
|
|
133
133
|
*/
|
|
134
|
-
export async function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<SyncSubprocess,
|
|
134
|
+
export async function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<SyncSubprocess, Error>> {
|
|
135
135
|
const { data: manifest } = await storage.readJsonFile('package.json', frameworkPath())
|
|
136
136
|
|
|
137
137
|
if (isManifest(manifest) && hasScript(manifest, script)) // simple, yet effective check to see if the script exists
|
package/src/retry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function retry(fn, options) {
|
|
1
|
+
export function retry(fn: Function, options: any): Promise<any> {
|
|
2
2
|
const { retries = 3, initialDelay = 1000, backoffFactor = 2, jitter = true } = options
|
|
3
3
|
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
@@ -22,7 +22,7 @@ export function retry(fn, options) {
|
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function calculateDelay(attemptCount, initialDelay, backoffFactor, jitter) {
|
|
25
|
+
export function calculateDelay(attemptCount: number, initialDelay: number, backoffFactor: number, jitter?: boolean): number {
|
|
26
26
|
let delay = initialDelay * backoffFactor ** attemptCount
|
|
27
27
|
if (jitter) {
|
|
28
28
|
const random = Math.random() // Generates a number between 0 and 1
|