@stacksjs/utils 0.59.11 → 0.61.0
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 +132 -55
- package/package.json +5 -5
- package/src/base.ts +1 -1
- package/src/equal.ts +3 -6
- package/src/find.ts +11 -20
- package/src/function.ts +1 -1
- package/src/git.ts +1 -2
- package/src/hash.ts +5 -9
- package/src/helpers.ts +40 -53
- package/src/promise.ts +6 -7
- package/src/regex.ts +35 -2
- package/src/retry.ts +8 -5
- package/src/sleep.ts +5 -5
- package/src/throttle.ts +10 -8
- package/dist/base.d.ts +0 -2
- package/dist/clean.d.ts +0 -1
- package/dist/config.d.ts +0 -1
- package/dist/currency.d.ts +0 -3
- package/dist/debounce.d.ts +0 -1
- package/dist/equal.d.ts +0 -1
- package/dist/export-size.d.ts +0 -1
- package/dist/find.d.ts +0 -5
- package/dist/function.d.ts +0 -18
- package/dist/git.d.ts +0 -1
- package/dist/guards.d.ts +0 -28
- package/dist/hash.d.ts +0 -2
- package/dist/helpers.d.ts +0 -51
- package/dist/index.d.ts +0 -22
- package/dist/macroable.d.ts +0 -1
- package/dist/math.d.ts +0 -3
- package/dist/promise.d.ts +0 -61
- package/dist/regex.d.ts +0 -2
- package/dist/retry.d.ts +0 -2
- package/dist/sleep.d.ts +0 -32
- package/dist/throttle.d.ts +0 -20
- package/dist/vendors.d.ts +0 -4
- package/dist/versions.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -103,8 +103,8 @@ function isDeepEqual(value1, value2) {
|
|
|
103
103
|
// src/export-size.ts
|
|
104
104
|
import {getExportsSize} from "export-size";
|
|
105
105
|
// src/find.ts
|
|
106
|
-
import os from "os";
|
|
107
106
|
import fs from "fs/promises";
|
|
107
|
+
import os from "os";
|
|
108
108
|
import path2 from "path";
|
|
109
109
|
import {italic} from "@stacksjs/cli";
|
|
110
110
|
import {log} from "@stacksjs/logging";
|
|
@@ -172,7 +172,7 @@ var excludePatterns = [
|
|
|
172
172
|
];
|
|
173
173
|
// src/function.ts
|
|
174
174
|
function batchInvoke(functions) {
|
|
175
|
-
functions.forEach((fn) => fn
|
|
175
|
+
functions.forEach((fn) => fn?.());
|
|
176
176
|
}
|
|
177
177
|
function tap(value, callback) {
|
|
178
178
|
callback(value);
|
|
@@ -202,10 +202,10 @@ function isTruthy(v) {
|
|
|
202
202
|
return Boolean(v);
|
|
203
203
|
}
|
|
204
204
|
// src/hash.ts
|
|
205
|
-
import {hashPaths} from "@stacksjs/storage";
|
|
206
|
-
import {path as p2} from "@stacksjs/path";
|
|
207
205
|
import {config as config2} from "@stacksjs/config";
|
|
208
206
|
import {log as log2} from "@stacksjs/logging";
|
|
207
|
+
import {path as p2} from "@stacksjs/path";
|
|
208
|
+
import {hashPaths} from "@stacksjs/storage";
|
|
209
209
|
function originRequestFunctionHash() {
|
|
210
210
|
try {
|
|
211
211
|
return hashPaths(p2.cloudPath("src/edge"));
|
|
@@ -216,43 +216,93 @@ function originRequestFunctionHash() {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
function websiteSourceHash() {
|
|
219
|
-
const docsSrc = [
|
|
220
|
-
p2.projectPath("docs"),
|
|
221
|
-
p2.projectPath("config/docs.ts")
|
|
222
|
-
];
|
|
219
|
+
const docsSrc = [p2.projectPath("docs"), p2.projectPath("config/docs.ts")];
|
|
223
220
|
const websiteSrc = [
|
|
224
221
|
p2.projectPath("resources/views")
|
|
225
222
|
];
|
|
226
223
|
return config2.app.docMode === true ? hashPaths(docsSrc) : hashPaths(websiteSrc);
|
|
227
224
|
}
|
|
228
|
-
// src/
|
|
229
|
-
import {log as log3, runCommand} from "@stacksjs/cli";
|
|
230
|
-
import {err, handleError, ok} from "@stacksjs/error-handling";
|
|
231
|
-
import {frameworkPath, projectPath} from "@stacksjs/path";
|
|
232
|
-
import * as storage2 from "@stacksjs/storage";
|
|
225
|
+
// ../actions/src/dev/index.ts
|
|
233
226
|
import {Action} from "@stacksjs/enums";
|
|
234
|
-
import {
|
|
227
|
+
import {log as log4} from "@stacksjs/logging";
|
|
228
|
+
|
|
229
|
+
// ../actions/src/helpers/utils.ts
|
|
230
|
+
import {buddyOptions, runCommand, runCommands} from "@stacksjs/cli";
|
|
231
|
+
import {err} from "@stacksjs/error-handling";
|
|
232
|
+
import {log as log3} from "@stacksjs/logging";
|
|
233
|
+
import * as p3 from "@stacksjs/path";
|
|
234
|
+
import {glob} from "@stacksjs/storage";
|
|
235
|
+
var {Glob } = globalThis.Bun;
|
|
236
|
+
async function runAction(action, options) {
|
|
237
|
+
const glob2 = new Glob("**/*.ts");
|
|
238
|
+
const scanOptions = { cwd: p3.userActionsPath(), onlyFiles: true };
|
|
239
|
+
for await (const file of glob2.scan(scanOptions)) {
|
|
240
|
+
log3.debug("file", file);
|
|
241
|
+
if (file === `${action}.ts` || file.endsWith(`${action}.ts`))
|
|
242
|
+
return (await import(p3.userActionsPath(file))).default.handle();
|
|
243
|
+
const a = await import(p3.userActionsPath(file));
|
|
244
|
+
if (a.name === action)
|
|
245
|
+
return await a.handle();
|
|
246
|
+
}
|
|
247
|
+
const opts = buddyOptions();
|
|
248
|
+
const path4 = p3.relativeActionsPath(`src/${action}.ts`);
|
|
249
|
+
const cmd = `bun --bun ${path4} ${opts}`.trimEnd();
|
|
250
|
+
const optionsWithCwd = {
|
|
251
|
+
cwd: options?.cwd || p3.projectPath(),
|
|
252
|
+
...options
|
|
253
|
+
};
|
|
254
|
+
log3.debug("runAction:", cmd);
|
|
255
|
+
log3.debug("action options:", optionsWithCwd);
|
|
256
|
+
return await runCommand(cmd, optionsWithCwd);
|
|
257
|
+
}
|
|
258
|
+
// ../actions/src/generate/index.ts
|
|
259
|
+
import {runCommand as runCommand2} from "@stacksjs/cli";
|
|
260
|
+
import {Action as Action2, NpmScript} from "@stacksjs/enums";
|
|
261
|
+
import {log as log6} from "@stacksjs/logging";
|
|
262
|
+
import {frameworkPath, projectPath as projectPath2} from "@stacksjs/path";
|
|
263
|
+
|
|
264
|
+
// ../actions/src/helpers/vscode-custom-data.ts
|
|
265
|
+
import {log as log5} from "@stacksjs/logging";
|
|
266
|
+
import {customElementsDataPath} from "@stacksjs/path";
|
|
267
|
+
import {writeTextFile} from "@stacksjs/storage";
|
|
268
|
+
// ../actions/src/commit.ts
|
|
269
|
+
import {NpmScript as NpmScript2} from "@stacksjs/enums";
|
|
270
|
+
import {log as log7} from "@stacksjs/logging";
|
|
271
|
+
// ../actions/src/add.ts
|
|
272
|
+
import {installPackage} from "@stacksjs/cli";
|
|
273
|
+
// ../actions/src/make.ts
|
|
274
|
+
import {italic as italic2} from "@stacksjs/cli";
|
|
275
|
+
import {log as log8} from "@stacksjs/logging";
|
|
276
|
+
import {frameworkPath as frameworkPath2, path as p4, resolve} from "@stacksjs/path";
|
|
277
|
+
import {createFolder, doesFolderExist, writeTextFile as writeTextFile2} from "@stacksjs/storage";
|
|
278
|
+
// src/helpers.ts
|
|
279
|
+
import {log as log9, runCommand as runCommand3} from "@stacksjs/cli";
|
|
235
280
|
import {app, ui} from "@stacksjs/config";
|
|
281
|
+
import {Action as Action3} from "@stacksjs/enums";
|
|
282
|
+
import {err as err2, handleError, ok} from "@stacksjs/error-handling";
|
|
283
|
+
import {frameworkPath as frameworkPath3, projectPath as projectPath4} from "@stacksjs/path";
|
|
284
|
+
import * as storage6 from "@stacksjs/storage";
|
|
285
|
+
import {parse} from "yaml";
|
|
236
286
|
async function packageManager() {
|
|
237
|
-
const { packageManager: packageManager2 } = await
|
|
287
|
+
const { packageManager: packageManager2 } = await storage6.readPackageJson(frameworkPath3("package.json"));
|
|
238
288
|
return packageManager2;
|
|
239
289
|
}
|
|
240
290
|
async function initProject() {
|
|
241
291
|
if (app.env !== "production")
|
|
242
|
-
|
|
292
|
+
log9.info("Project not yet initialized, generating application key...");
|
|
243
293
|
else
|
|
244
294
|
handleError("Please run `buddy key:generate` to generate an application key");
|
|
245
|
-
const result = await runAction(
|
|
295
|
+
const result = await runAction(Action3.KeyGenerate, { cwd: projectPath4() });
|
|
246
296
|
if (result.isErr())
|
|
247
|
-
return
|
|
248
|
-
|
|
297
|
+
return err2(handleError(result.error));
|
|
298
|
+
log9.info("Application key generated.");
|
|
249
299
|
return ok(result.value);
|
|
250
300
|
}
|
|
251
301
|
async function ensureProjectIsInitialized() {
|
|
252
|
-
if (
|
|
302
|
+
if (storage6.isFile(projectPath4(".env")))
|
|
253
303
|
return await isAppKeySet();
|
|
254
|
-
if (
|
|
255
|
-
await
|
|
304
|
+
if (storage6.isFile(projectPath4(".env.example")))
|
|
305
|
+
await runCommand3("cp .env.example .env", { cwd: projectPath4() });
|
|
256
306
|
else
|
|
257
307
|
console.error("no .env.example file found");
|
|
258
308
|
return await isAppKeySet();
|
|
@@ -260,10 +310,10 @@ async function ensureProjectIsInitialized() {
|
|
|
260
310
|
async function installIfVersionMismatch() {
|
|
261
311
|
}
|
|
262
312
|
async function frameworkVersion() {
|
|
263
|
-
return (await
|
|
313
|
+
return (await storage6.readPackageJson(frameworkPath3("package.json"))).version;
|
|
264
314
|
}
|
|
265
315
|
async function isAppKeySet() {
|
|
266
|
-
const env = await
|
|
316
|
+
const env = await storage6.readTextFile(".env", projectPath4());
|
|
267
317
|
const lines = env.data.split("\n");
|
|
268
318
|
const appKey = lines.find((line) => line.startsWith("APP_KEY="));
|
|
269
319
|
return !!(appKey && appKey.length > 16);
|
|
@@ -272,15 +322,15 @@ function determineResetPreset(preset) {
|
|
|
272
322
|
if (ui.reset)
|
|
273
323
|
preset = ui.reset;
|
|
274
324
|
if (preset === "tailwind")
|
|
275
|
-
return ["import
|
|
325
|
+
return ["import '@unocss/reset/tailwind.css'"];
|
|
276
326
|
if (preset === "normalize")
|
|
277
|
-
return ["import
|
|
327
|
+
return ["import '@unocss/reset/normalize.css'"];
|
|
278
328
|
if (preset === "sanitize")
|
|
279
|
-
return ["import
|
|
329
|
+
return ["import '@unocss/reset/sanitize/sanitize.css'", "import '@unocss/reset/sanitize/assets.css"];
|
|
280
330
|
if (preset === "eric-meyer")
|
|
281
|
-
return ["import
|
|
331
|
+
return ["import '@unocss/reset/eric-meyer.css'"];
|
|
282
332
|
if (preset === "antfu")
|
|
283
|
-
return ["import
|
|
333
|
+
return ["import '@unocss/reset/antfu.css'"];
|
|
284
334
|
return [];
|
|
285
335
|
}
|
|
286
336
|
function isManifest(obj) {
|
|
@@ -291,17 +341,17 @@ function isOptionalString(value) {
|
|
|
291
341
|
return value === null || type === "undefined" || type === "string";
|
|
292
342
|
}
|
|
293
343
|
async function setEnvValue(key, value) {
|
|
294
|
-
const file = await
|
|
295
|
-
await
|
|
296
|
-
path:
|
|
344
|
+
const file = await storage6.readTextFile(projectPath4(".env"));
|
|
345
|
+
await storage6.writeTextFile({
|
|
346
|
+
path: projectPath4(".env"),
|
|
297
347
|
data: file.data.replace(/APP_KEY=/g, `APP_KEY=${value}`)
|
|
298
348
|
});
|
|
299
349
|
}
|
|
300
350
|
async function runNpmScript(script, options) {
|
|
301
|
-
const { data: manifest } = await
|
|
351
|
+
const { data: manifest } = await storage6.readJsonFile("package.json", frameworkPath3());
|
|
302
352
|
if (isManifest(manifest) && hasScript(manifest, script))
|
|
303
|
-
return await
|
|
304
|
-
return
|
|
353
|
+
return await runCommand3(`bun --bun run ${script}`, options);
|
|
354
|
+
return err2(handleError(`The ${script} script does not exist in the package.json file.`));
|
|
305
355
|
}
|
|
306
356
|
function hasScript(manifest, script) {
|
|
307
357
|
const scripts = manifest.scripts;
|
|
@@ -372,12 +422,12 @@ function createPromiseLock() {
|
|
|
372
422
|
const locks = [];
|
|
373
423
|
return {
|
|
374
424
|
async run(fn) {
|
|
375
|
-
const
|
|
376
|
-
locks.push(
|
|
425
|
+
const p5 = fn();
|
|
426
|
+
locks.push(p5);
|
|
377
427
|
try {
|
|
378
|
-
return await
|
|
428
|
+
return await p5;
|
|
379
429
|
} finally {
|
|
380
|
-
remove(locks,
|
|
430
|
+
remove(locks, p5);
|
|
381
431
|
}
|
|
382
432
|
},
|
|
383
433
|
async wait() {
|
|
@@ -392,28 +442,55 @@ function createPromiseLock() {
|
|
|
392
442
|
};
|
|
393
443
|
}
|
|
394
444
|
function createControlledPromise() {
|
|
395
|
-
let
|
|
445
|
+
let resolve2;
|
|
446
|
+
let reject;
|
|
396
447
|
const promise = new Promise((_resolve, _reject) => {
|
|
397
|
-
|
|
448
|
+
resolve2 = _resolve;
|
|
398
449
|
reject = _reject;
|
|
399
450
|
});
|
|
400
|
-
promise.resolve =
|
|
451
|
+
promise.resolve = resolve2;
|
|
401
452
|
promise.reject = reject;
|
|
402
453
|
return promise;
|
|
403
454
|
}
|
|
404
455
|
// src/regex.ts
|
|
405
|
-
import {
|
|
456
|
+
import {
|
|
457
|
+
createRegExp,
|
|
458
|
+
caseInsensitive,
|
|
459
|
+
anyOf,
|
|
460
|
+
carriageReturn,
|
|
461
|
+
char,
|
|
462
|
+
charIn,
|
|
463
|
+
charNotIn,
|
|
464
|
+
digit,
|
|
465
|
+
dotAll,
|
|
466
|
+
exactly,
|
|
467
|
+
global,
|
|
468
|
+
letter,
|
|
469
|
+
linefeed,
|
|
470
|
+
maybe,
|
|
471
|
+
multiline,
|
|
472
|
+
not,
|
|
473
|
+
oneOrMore,
|
|
474
|
+
sticky,
|
|
475
|
+
tab,
|
|
476
|
+
unicode,
|
|
477
|
+
whitespace,
|
|
478
|
+
withIndices,
|
|
479
|
+
word,
|
|
480
|
+
wordBoundary,
|
|
481
|
+
wordChar
|
|
482
|
+
} from "magic-regexp";
|
|
406
483
|
// src/retry.ts
|
|
407
484
|
function retry(fn, options) {
|
|
408
485
|
const { retries = 3, initialDelay = 1000, backoffFactor = 2, jitter = true } = options;
|
|
409
|
-
return new Promise((
|
|
486
|
+
return new Promise((resolve2, reject) => {
|
|
410
487
|
let attemptCount = 0;
|
|
411
488
|
const attempt = async () => {
|
|
412
489
|
try {
|
|
413
|
-
|
|
414
|
-
} catch (
|
|
490
|
+
resolve2(await fn());
|
|
491
|
+
} catch (err3) {
|
|
415
492
|
if (attemptCount >= retries) {
|
|
416
|
-
reject(
|
|
493
|
+
reject(err3);
|
|
417
494
|
} else {
|
|
418
495
|
const delay = calculateDelay(attemptCount, initialDelay, backoffFactor, jitter);
|
|
419
496
|
setTimeout(() => attempt(), delay);
|
|
@@ -435,30 +512,30 @@ function calculateDelay(attemptCount, initialDelay, backoffFactor, jitter) {
|
|
|
435
512
|
}
|
|
436
513
|
// src/sleep.ts
|
|
437
514
|
function sleep(ms) {
|
|
438
|
-
return new Promise((
|
|
515
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
439
516
|
}
|
|
440
517
|
function wait(ms) {
|
|
441
|
-
return new Promise((
|
|
518
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
442
519
|
}
|
|
443
520
|
function delay(ms) {
|
|
444
|
-
return new Promise((
|
|
521
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
445
522
|
}
|
|
446
523
|
function waitUntil(condition, interval = 1000) {
|
|
447
|
-
return new Promise((
|
|
524
|
+
return new Promise((resolve2) => {
|
|
448
525
|
const check = setInterval(() => {
|
|
449
526
|
if (condition()) {
|
|
450
527
|
clearInterval(check);
|
|
451
|
-
|
|
528
|
+
resolve2();
|
|
452
529
|
}
|
|
453
530
|
}, interval);
|
|
454
531
|
});
|
|
455
532
|
}
|
|
456
533
|
function waitWhile(condition, interval = 1000) {
|
|
457
|
-
return new Promise((
|
|
534
|
+
return new Promise((resolve2) => {
|
|
458
535
|
const check = setInterval(() => {
|
|
459
536
|
if (!condition()) {
|
|
460
537
|
clearInterval(check);
|
|
461
|
-
|
|
538
|
+
resolve2();
|
|
462
539
|
}
|
|
463
540
|
}, interval);
|
|
464
541
|
});
|
|
@@ -830,7 +907,7 @@ function prettyBytes(number, options) {
|
|
|
830
907
|
return prefix + numberString + separator + unit;
|
|
831
908
|
}
|
|
832
909
|
// package.json
|
|
833
|
-
var version = "0.
|
|
910
|
+
var version = "0.61.0";
|
|
834
911
|
export {
|
|
835
912
|
wordChar,
|
|
836
913
|
wordBoundary,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "The Stacks helper functions.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"@vueuse/math": "^10.9.0",
|
|
69
69
|
"@vueuse/shared": "^10.9.0",
|
|
70
70
|
"bun-plugin-env": "^0.4.1",
|
|
71
|
-
"bun-plugin-yml": "^0.3.
|
|
71
|
+
"bun-plugin-yml": "^0.3.1",
|
|
72
72
|
"export-size": "^0.7.0",
|
|
73
|
-
"yaml": "^2.4.
|
|
73
|
+
"yaml": "^2.4.2"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@dinero.js/currencies": "2.0.0-alpha.14",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@vueuse/math": "^10.9.0",
|
|
89
89
|
"@vueuse/shared": "^10.9.0",
|
|
90
90
|
"bun-plugin-env": "^0.4.1",
|
|
91
|
-
"bun-plugin-yml": "^0.3.
|
|
91
|
+
"bun-plugin-yml": "^0.3.1",
|
|
92
92
|
"defu": "^6.1.4",
|
|
93
93
|
"detect-indent": "^7.0.1",
|
|
94
94
|
"detect-newline": "^4.0.1",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"magic-regexp": "^0.8.0",
|
|
101
101
|
"perfect-debounce": "^1.0.0",
|
|
102
102
|
"pretty-bytes": "^6.1.1",
|
|
103
|
-
"yaml": "^2.4.
|
|
103
|
+
"yaml": "^2.4.2"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@stacksjs/development": "latest",
|
package/src/base.ts
CHANGED
|
@@ -8,5 +8,5 @@ export { toString } from '@stacksjs/strings'
|
|
|
8
8
|
// export function noop() {}
|
|
9
9
|
|
|
10
10
|
export async function loop(times: number, callback: any) {
|
|
11
|
-
[...Array(times)].forEach(async (item, i) => await callback(i))
|
|
11
|
+
;[...Array(times)].forEach(async (item, i) => await callback(i))
|
|
12
12
|
}
|
package/src/equal.ts
CHANGED
|
@@ -3,12 +3,10 @@ import { getTypeName } from '@stacksjs/types'
|
|
|
3
3
|
export function isDeepEqual(value1: any, value2: any): boolean {
|
|
4
4
|
const type1 = getTypeName(value1)
|
|
5
5
|
const type2 = getTypeName(value2)
|
|
6
|
-
if (type1 !== type2)
|
|
7
|
-
return false
|
|
6
|
+
if (type1 !== type2) return false
|
|
8
7
|
|
|
9
8
|
if (type1 === 'array') {
|
|
10
|
-
if (value1.length !== value2.length)
|
|
11
|
-
return false
|
|
9
|
+
if (value1.length !== value2.length) return false
|
|
12
10
|
|
|
13
11
|
return value1.every((item: any, i: number) => {
|
|
14
12
|
return isDeepEqual(item, value2[i])
|
|
@@ -16,8 +14,7 @@ export function isDeepEqual(value1: any, value2: any): boolean {
|
|
|
16
14
|
}
|
|
17
15
|
if (type1 === 'object') {
|
|
18
16
|
const keyArr = Object.keys(value1)
|
|
19
|
-
if (keyArr.length !== Object.keys(value2).length)
|
|
20
|
-
return false
|
|
17
|
+
if (keyArr.length !== Object.keys(value2).length) return false
|
|
21
18
|
|
|
22
19
|
return keyArr.every((key: string) => {
|
|
23
20
|
return isDeepEqual(value1[key], value2[key])
|
package/src/find.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Dirent } from 'node:fs'
|
|
2
2
|
import fs from 'node:fs/promises'
|
|
3
|
+
import os from 'node:os'
|
|
3
4
|
import path from 'node:path'
|
|
4
|
-
import type { Dirent } from 'node:fs'
|
|
5
5
|
import { italic } from '@stacksjs/cli'
|
|
6
6
|
import { log } from '@stacksjs/logging'
|
|
7
7
|
|
|
8
8
|
const targetFileName = 'buddy' // The exact name of the target file
|
|
9
9
|
|
|
10
|
-
// Assuming excludePatterns is defined somewhere in your script
|
|
11
10
|
const excludePatterns = [
|
|
12
11
|
'node_modules',
|
|
13
12
|
'dist',
|
|
@@ -30,21 +29,16 @@ export async function findStacksProjects(dir?: string, options?: FindStacksProje
|
|
|
30
29
|
if (!options?.quiet) {
|
|
31
30
|
log.info(`Searching for Stacks projects in: ${italic(dir)}`)
|
|
32
31
|
log.info(`This may take a few moments...`)
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
32
|
console.log('')
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
33
|
console.log(italic(' Please note, while Stacks is searching for projects on your machine,'))
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
34
|
console.log(italic(' you may be asked for permissions to scan certain directories.'))
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
35
|
console.log('')
|
|
41
36
|
log.debug(`Excluding directories: ${excludePatterns.join(', ')}`)
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
const foundProjects = await searchDirectory(dir)
|
|
45
40
|
|
|
46
|
-
if (!foundProjects)
|
|
47
|
-
throw new Error('No Stacks projects found')
|
|
41
|
+
if (!foundProjects) throw new Error('No Stacks projects found')
|
|
48
42
|
|
|
49
43
|
return foundProjects
|
|
50
44
|
}
|
|
@@ -52,15 +46,15 @@ export async function findStacksProjects(dir?: string, options?: FindStacksProje
|
|
|
52
46
|
async function searchDirectory(directory: string) {
|
|
53
47
|
const foundProjects: string[] = []
|
|
54
48
|
|
|
55
|
-
const isExcluded = excludePatterns.some(
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const isExcluded = excludePatterns.some((pattern) =>
|
|
50
|
+
typeof pattern === 'string' ? directory.includes(pattern) : pattern.test(directory),
|
|
51
|
+
)
|
|
52
|
+
if (isExcluded) return
|
|
58
53
|
|
|
59
54
|
let items: Dirent[]
|
|
60
55
|
try {
|
|
61
56
|
items = await fs.readdir(directory, { withFileTypes: true })
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
57
|
+
} catch (error) {
|
|
64
58
|
console.error(`Error reading directory ${directory}:`, error)
|
|
65
59
|
return
|
|
66
60
|
}
|
|
@@ -71,8 +65,7 @@ async function searchDirectory(directory: string) {
|
|
|
71
65
|
for (const item of items) {
|
|
72
66
|
if (item.isFile() && item.name === targetFileName) {
|
|
73
67
|
buddyFileFound = true
|
|
74
|
-
}
|
|
75
|
-
else if (item.isDirectory()) {
|
|
68
|
+
} else if (item.isDirectory()) {
|
|
76
69
|
// Recursively search in directories
|
|
77
70
|
const fullPath = path.join(directory, item.name)
|
|
78
71
|
if (item.name === 'storage') {
|
|
@@ -81,8 +74,7 @@ async function searchDirectory(directory: string) {
|
|
|
81
74
|
const storagePath = path.join(fullPath, 'framework/core/buddy')
|
|
82
75
|
await fs.access(storagePath)
|
|
83
76
|
storageDirFound = true
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
77
|
+
} catch (error) {
|
|
86
78
|
// The specific directory structure does not exist
|
|
87
79
|
}
|
|
88
80
|
}
|
|
@@ -90,8 +82,7 @@ async function searchDirectory(directory: string) {
|
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
84
|
|
|
93
|
-
if (buddyFileFound && storageDirFound)
|
|
94
|
-
foundProjects.push(directory) // Both conditions are met
|
|
85
|
+
if (buddyFileFound && storageDirFound) foundProjects.push(directory) // Both conditions are met
|
|
95
86
|
|
|
96
87
|
return foundProjects
|
|
97
88
|
}
|
package/src/function.ts
CHANGED
package/src/git.ts
CHANGED
package/src/hash.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { hashPaths } from '@stacksjs/storage'
|
|
2
|
-
import { path as p } from '@stacksjs/path'
|
|
3
1
|
import { config } from '@stacksjs/config'
|
|
4
2
|
import { log } from '@stacksjs/logging'
|
|
3
|
+
import { path as p } from '@stacksjs/path'
|
|
4
|
+
import { hashPaths } from '@stacksjs/storage'
|
|
5
5
|
|
|
6
6
|
export function originRequestFunctionHash() {
|
|
7
7
|
try {
|
|
8
8
|
return hashPaths(p.cloudPath('src/edge'))
|
|
9
|
-
}
|
|
10
|
-
catch (error: any) {
|
|
9
|
+
} catch (error: any) {
|
|
11
10
|
log.error('Are we in a Docker container? Failed to hash paths. Error below:')
|
|
12
11
|
log.error(error)
|
|
13
12
|
return undefined
|
|
@@ -15,14 +14,11 @@ export function originRequestFunctionHash() {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export function websiteSourceHash() {
|
|
18
|
-
const docsSrc = [
|
|
19
|
-
p.projectPath('docs'),
|
|
20
|
-
p.projectPath('config/docs.ts'),
|
|
21
|
-
]
|
|
17
|
+
const docsSrc = [p.projectPath('docs'), p.projectPath('config/docs.ts')]
|
|
22
18
|
|
|
23
19
|
const websiteSrc = [
|
|
24
20
|
p.projectPath('resources/views'),
|
|
25
|
-
|
|
21
|
+
// p.projectPath('config/app.ts'),
|
|
26
22
|
]
|
|
27
23
|
|
|
28
24
|
return config.app.docMode === true ? hashPaths(docsSrc) : hashPaths(websiteSrc)
|
package/src/helpers.ts
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import type { AddressInfo } from 'node:net'
|
|
2
|
-
|
|
3
|
-
// import { runAction } from '@stacksjs/actions'
|
|
2
|
+
import { runAction } from '@stacksjs/actions'
|
|
4
3
|
import { log, runCommand } from '@stacksjs/cli'
|
|
4
|
+
import { app, ui } from '@stacksjs/config'
|
|
5
|
+
import type { NpmScript } from '@stacksjs/enums'
|
|
6
|
+
import { Action } from '@stacksjs/enums'
|
|
5
7
|
import type { Result } from '@stacksjs/error-handling'
|
|
6
8
|
import { err, handleError, ok } from '@stacksjs/error-handling'
|
|
7
9
|
import { frameworkPath, projectPath } from '@stacksjs/path'
|
|
8
10
|
import * as storage from '@stacksjs/storage'
|
|
9
|
-
import type { CliOptions, Manifest,
|
|
10
|
-
import type { NpmScript } from '@stacksjs/enums'
|
|
11
|
-
import { Action } from '@stacksjs/enums'
|
|
11
|
+
import type { CliOptions, Manifest, Subprocess } from '@stacksjs/types'
|
|
12
12
|
import { parse } from 'yaml'
|
|
13
13
|
|
|
14
14
|
// import { semver } from './versions'
|
|
15
|
-
import { app, ui } from '@stacksjs/config'
|
|
16
15
|
|
|
17
16
|
export async function packageManager() {
|
|
18
17
|
const { packageManager } = await storage.readPackageJson(frameworkPath('package.json'))
|
|
19
18
|
return packageManager
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
export async function initProject(): Promise<Result<
|
|
23
|
-
if (app.env !== 'production')
|
|
24
|
-
|
|
25
|
-
else
|
|
26
|
-
handleError('Please run `buddy key:generate` to generate an application key')
|
|
21
|
+
export async function initProject(): Promise<Result<Subprocess, Error>> {
|
|
22
|
+
if (app.env !== 'production') log.info('Project not yet initialized, generating application key...')
|
|
23
|
+
else handleError('Please run `buddy key:generate` to generate an application key')
|
|
27
24
|
|
|
28
25
|
const result = await runAction(Action.KeyGenerate, { cwd: projectPath() })
|
|
29
26
|
|
|
30
|
-
if (result.isErr())
|
|
31
|
-
return err(handleError(result.error))
|
|
27
|
+
if (result.isErr()) return err(handleError(result.error))
|
|
32
28
|
|
|
33
29
|
log.info('Application key generated.')
|
|
34
30
|
|
|
@@ -36,14 +32,11 @@ export async function initProject(): Promise<Result<SyncSubprocess, Error>> {
|
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
export async function ensureProjectIsInitialized() {
|
|
39
|
-
if (storage.isFile(projectPath('.env')))
|
|
40
|
-
return await isAppKeySet()
|
|
35
|
+
if (storage.isFile(projectPath('.env'))) return await isAppKeySet()
|
|
41
36
|
|
|
42
37
|
// copy the .env.example file to .env
|
|
43
|
-
if (storage.isFile(projectPath('.env.example')))
|
|
44
|
-
|
|
45
|
-
else
|
|
46
|
-
console.error('no .env.example file found')
|
|
38
|
+
if (storage.isFile(projectPath('.env.example'))) await runCommand('cp .env.example .env', { cwd: projectPath() })
|
|
39
|
+
else console.error('no .env.example file found')
|
|
47
40
|
|
|
48
41
|
return await isAppKeySet()
|
|
49
42
|
}
|
|
@@ -51,7 +44,6 @@ export async function ensureProjectIsInitialized() {
|
|
|
51
44
|
export async function installIfVersionMismatch() {
|
|
52
45
|
// const requiredBunVersion = '0.8.1'
|
|
53
46
|
// const installedBunVersion = process.version
|
|
54
|
-
|
|
55
47
|
// if (!semver.satisfies(installedBunVersion, requiredBunVersion)) {
|
|
56
48
|
// log.warn(`Installed Bun version ${italic(installedBunVersion)} does not satisfy required version ${italic(requiredBunVersion)}. Adding it to your environment. One moment...`)
|
|
57
49
|
// await runCommand(`tea +bun.sh${requiredBunVersion} >/dev/null 2>&1`)
|
|
@@ -65,7 +57,7 @@ export async function frameworkVersion(): Promise<string> {
|
|
|
65
57
|
export async function isAppKeySet() {
|
|
66
58
|
const env = await storage.readTextFile('.env', projectPath())
|
|
67
59
|
const lines = env.data.split('\n')
|
|
68
|
-
const appKey = lines.find(line => line.startsWith('APP_KEY='))
|
|
60
|
+
const appKey = lines.find((line) => line.startsWith('APP_KEY='))
|
|
69
61
|
|
|
70
62
|
return !!(appKey && appKey.length > 16)
|
|
71
63
|
}
|
|
@@ -77,23 +69,18 @@ export async function isAppKeySet() {
|
|
|
77
69
|
* @param preset
|
|
78
70
|
*/
|
|
79
71
|
export function determineResetPreset(preset?: string) {
|
|
80
|
-
if (ui.reset)
|
|
81
|
-
preset = ui.reset
|
|
72
|
+
if (ui.reset) preset = ui.reset
|
|
82
73
|
|
|
83
|
-
if (preset === 'tailwind')
|
|
84
|
-
return ['import \'@unocss/reset/tailwind.css\'']
|
|
74
|
+
if (preset === 'tailwind') return ["import '@unocss/reset/tailwind.css'"]
|
|
85
75
|
|
|
86
|
-
if (preset === 'normalize')
|
|
87
|
-
return ['import \'@unocss/reset/normalize.css\'']
|
|
76
|
+
if (preset === 'normalize') return ["import '@unocss/reset/normalize.css'"]
|
|
88
77
|
|
|
89
78
|
if (preset === 'sanitize')
|
|
90
|
-
return [
|
|
79
|
+
return ["import '@unocss/reset/sanitize/sanitize.css'", "import '@unocss/reset/sanitize/assets.css"]
|
|
91
80
|
|
|
92
|
-
if (preset === 'eric-meyer')
|
|
93
|
-
return ['import \'@unocss/reset/eric-meyer.css\'']
|
|
81
|
+
if (preset === 'eric-meyer') return ["import '@unocss/reset/eric-meyer.css'"]
|
|
94
82
|
|
|
95
|
-
if (preset === 'antfu')
|
|
96
|
-
return ['import \'@unocss/reset/antfu.css\'']
|
|
83
|
+
if (preset === 'antfu') return ["import '@unocss/reset/antfu.css'"]
|
|
97
84
|
|
|
98
85
|
return []
|
|
99
86
|
}
|
|
@@ -102,11 +89,13 @@ export function determineResetPreset(preset?: string) {
|
|
|
102
89
|
* Determines whether the specified value is a package manifest.
|
|
103
90
|
*/
|
|
104
91
|
export function isManifest(obj: any): obj is Manifest {
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
92
|
+
return (
|
|
93
|
+
obj &&
|
|
94
|
+
typeof obj === 'object' &&
|
|
95
|
+
isOptionalString(obj.name) &&
|
|
96
|
+
isOptionalString(obj.version) &&
|
|
97
|
+
isOptionalString(obj.description)
|
|
98
|
+
)
|
|
110
99
|
}
|
|
111
100
|
|
|
112
101
|
/**
|
|
@@ -114,9 +103,7 @@ export function isManifest(obj: any): obj is Manifest {
|
|
|
114
103
|
*/
|
|
115
104
|
export function isOptionalString(value: any): value is string | undefined {
|
|
116
105
|
const type = typeof value
|
|
117
|
-
return value === null
|
|
118
|
-
|| type === 'undefined'
|
|
119
|
-
|| type === 'string'
|
|
106
|
+
return value === null || type === 'undefined' || type === 'string'
|
|
120
107
|
}
|
|
121
108
|
|
|
122
109
|
export async function setEnvValue(key: string, value: string) {
|
|
@@ -131,11 +118,11 @@ export async function setEnvValue(key: string, value: string) {
|
|
|
131
118
|
/**
|
|
132
119
|
* Runs the specified NPM script in the package.json file.
|
|
133
120
|
*/
|
|
134
|
-
export async function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<
|
|
121
|
+
export async function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<Subprocess, Error>> {
|
|
135
122
|
const { data: manifest } = await storage.readJsonFile('package.json', frameworkPath())
|
|
136
123
|
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
// simple, yet effective check to see if the script exists
|
|
125
|
+
if (isManifest(manifest) && hasScript(manifest, script)) return await runCommand(`bun --bun run ${script}`, options)
|
|
139
126
|
|
|
140
127
|
return err(handleError(`The ${script} script does not exist in the package.json file.`))
|
|
141
128
|
}
|
|
@@ -146,8 +133,7 @@ export async function runNpmScript(script: NpmScript, options?: CliOptions): Pro
|
|
|
146
133
|
export function hasScript(manifest: Manifest, script: NpmScript): boolean {
|
|
147
134
|
const scripts = manifest.scripts as Record<NpmScript, string> | undefined
|
|
148
135
|
|
|
149
|
-
if (scripts && typeof scripts === 'object')
|
|
150
|
-
return Boolean(scripts[script])
|
|
136
|
+
if (scripts && typeof scripts === 'object') return Boolean(scripts[script])
|
|
151
137
|
|
|
152
138
|
return false
|
|
153
139
|
}
|
|
@@ -169,19 +155,20 @@ export function parseYaml(content: any) {
|
|
|
169
155
|
* @param options
|
|
170
156
|
*/
|
|
171
157
|
export function determineDebugLevel(options?: CliOptions) {
|
|
172
|
-
if (options?.verbose === true)
|
|
173
|
-
return true
|
|
158
|
+
if (options?.verbose === true) return true
|
|
174
159
|
|
|
175
160
|
return app.debug === true
|
|
176
161
|
}
|
|
177
162
|
|
|
178
163
|
export function isIpv6(address: AddressInfo): boolean {
|
|
179
|
-
return
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
164
|
+
return (
|
|
165
|
+
address.family === 'IPv6' ||
|
|
166
|
+
// in node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
|
|
167
|
+
// See: https://github.com/laravel/vite-plugin/issues/103
|
|
168
|
+
|
|
169
|
+
// @ts-expect-error-next-line
|
|
170
|
+
address.family === 6
|
|
171
|
+
)
|
|
185
172
|
}
|
|
186
173
|
|
|
187
174
|
export { dump as dumpYaml, load as loadYaml } from 'js-yaml'
|
package/src/promise.ts
CHANGED
|
@@ -28,15 +28,13 @@ export function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromis
|
|
|
28
28
|
let _promise: Promise<T> | undefined
|
|
29
29
|
|
|
30
30
|
function wrapper() {
|
|
31
|
-
if (!_promise)
|
|
32
|
-
_promise = fn()
|
|
31
|
+
if (!_promise) _promise = fn()
|
|
33
32
|
return _promise
|
|
34
33
|
}
|
|
35
34
|
wrapper.reset = async () => {
|
|
36
35
|
const _prev = _promise
|
|
37
36
|
_promise = undefined
|
|
38
|
-
if (_prev)
|
|
39
|
-
await _prev
|
|
37
|
+
if (_prev) await _prev
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
return wrapper
|
|
@@ -67,8 +65,7 @@ export function createPromiseLock() {
|
|
|
67
65
|
locks.push(p)
|
|
68
66
|
try {
|
|
69
67
|
return await p
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
68
|
+
} finally {
|
|
72
69
|
remove(locks, p)
|
|
73
70
|
}
|
|
74
71
|
},
|
|
@@ -99,7 +96,9 @@ export function createPromiseLock() {
|
|
|
99
96
|
* ```
|
|
100
97
|
*/
|
|
101
98
|
export function createControlledPromise<T>(): ControlledPromise<T> {
|
|
102
|
-
let resolve: any
|
|
99
|
+
let resolve: any
|
|
100
|
+
let reject: any
|
|
101
|
+
|
|
103
102
|
const promise = new Promise<T>((_resolve, _reject) => {
|
|
104
103
|
resolve = _resolve
|
|
105
104
|
reject = _reject
|
package/src/regex.ts
CHANGED
|
@@ -1,2 +1,35 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
|
|
1
|
+
export type {
|
|
2
|
+
Flag,
|
|
3
|
+
MagicRegExp,
|
|
4
|
+
MagicRegExpMatchArray,
|
|
5
|
+
Input,
|
|
6
|
+
MapToStringCapturedBy,
|
|
7
|
+
StringCapturedBy,
|
|
8
|
+
} from 'magic-regexp'
|
|
9
|
+
export {
|
|
10
|
+
createRegExp,
|
|
11
|
+
caseInsensitive,
|
|
12
|
+
anyOf,
|
|
13
|
+
carriageReturn,
|
|
14
|
+
char,
|
|
15
|
+
charIn,
|
|
16
|
+
charNotIn,
|
|
17
|
+
digit,
|
|
18
|
+
dotAll,
|
|
19
|
+
exactly,
|
|
20
|
+
global,
|
|
21
|
+
letter,
|
|
22
|
+
linefeed,
|
|
23
|
+
maybe,
|
|
24
|
+
multiline,
|
|
25
|
+
not,
|
|
26
|
+
oneOrMore,
|
|
27
|
+
sticky,
|
|
28
|
+
tab,
|
|
29
|
+
unicode,
|
|
30
|
+
whitespace,
|
|
31
|
+
withIndices,
|
|
32
|
+
word,
|
|
33
|
+
wordBoundary,
|
|
34
|
+
wordChar,
|
|
35
|
+
} from 'magic-regexp'
|
package/src/retry.ts
CHANGED
|
@@ -6,12 +6,10 @@ export function retry(fn: Function, options: any): Promise<any> {
|
|
|
6
6
|
const attempt = async () => {
|
|
7
7
|
try {
|
|
8
8
|
resolve(await fn())
|
|
9
|
-
}
|
|
10
|
-
catch (err) {
|
|
9
|
+
} catch (err) {
|
|
11
10
|
if (attemptCount >= retries) {
|
|
12
11
|
reject(err)
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
12
|
+
} else {
|
|
15
13
|
const delay = calculateDelay(attemptCount, initialDelay, backoffFactor, jitter)
|
|
16
14
|
setTimeout(() => attempt(), delay)
|
|
17
15
|
attemptCount++
|
|
@@ -22,7 +20,12 @@ export function retry(fn: Function, options: any): Promise<any> {
|
|
|
22
20
|
})
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
export function calculateDelay(
|
|
23
|
+
export function calculateDelay(
|
|
24
|
+
attemptCount: number,
|
|
25
|
+
initialDelay: number,
|
|
26
|
+
backoffFactor: number,
|
|
27
|
+
jitter?: boolean,
|
|
28
|
+
): number {
|
|
26
29
|
let delay = initialDelay * backoffFactor ** attemptCount
|
|
27
30
|
if (jitter) {
|
|
28
31
|
const random = Math.random() // Generates a number between 0 and 1
|
package/src/sleep.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @returns A promise that resolves after the specified delay.
|
|
5
5
|
*/
|
|
6
6
|
export function sleep(ms: number): Promise<void> {
|
|
7
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
7
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -13,7 +13,7 @@ export function sleep(ms: number): Promise<void> {
|
|
|
13
13
|
* @returns A promise that resolves after the specified delay.
|
|
14
14
|
*/
|
|
15
15
|
export function wait(ms: number): Promise<void> {
|
|
16
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
16
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -22,7 +22,7 @@ export function wait(ms: number): Promise<void> {
|
|
|
22
22
|
* @returns A promise that resolves after the specified delay.
|
|
23
23
|
*/
|
|
24
24
|
export function delay(ms: number): Promise<void> {
|
|
25
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -31,7 +31,7 @@ export function delay(ms: number): Promise<void> {
|
|
|
31
31
|
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
32
32
|
* @returns A promise that resolves when the condition is met.
|
|
33
33
|
*/
|
|
34
|
-
export function waitUntil(condition: () => boolean, interval
|
|
34
|
+
export function waitUntil(condition: () => boolean, interval = 1000): Promise<void> {
|
|
35
35
|
return new Promise((resolve) => {
|
|
36
36
|
const check = setInterval(() => {
|
|
37
37
|
if (condition()) {
|
|
@@ -48,7 +48,7 @@ export function waitUntil(condition: () => boolean, interval: number = 1000): Pr
|
|
|
48
48
|
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
49
49
|
* @returns A promise that resolves when the condition is no longer met.
|
|
50
50
|
*/
|
|
51
|
-
export function waitWhile(condition: () => boolean, interval
|
|
51
|
+
export function waitWhile(condition: () => boolean, interval = 1000): Promise<void> {
|
|
52
52
|
return new Promise((resolve) => {
|
|
53
53
|
const check = setInterval(() => {
|
|
54
54
|
if (!condition()) {
|
package/src/throttle.ts
CHANGED
|
@@ -29,16 +29,18 @@ export function throttle(fn: Function, wait = 300) {
|
|
|
29
29
|
|
|
30
30
|
lastTime = Date.now()
|
|
31
31
|
inThrottle = true
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
32
|
+
} else {
|
|
34
33
|
clearTimeout(lastFn)
|
|
35
34
|
|
|
36
|
-
lastFn = setTimeout(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
lastFn = setTimeout(
|
|
36
|
+
() => {
|
|
37
|
+
if (Date.now() - lastTime >= wait) {
|
|
38
|
+
fn.apply(this, args) // Use 'this' directly
|
|
39
|
+
lastTime = Date.now()
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
Math.max(wait - (Date.now() - lastTime), 0),
|
|
43
|
+
)
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
package/dist/base.d.ts
DELETED
package/dist/clean.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function cleanProject(): Promise<void>;
|
package/dist/config.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { defineApp, defineCache, defineCli, defineCdn, defineCronJob, defineJob, defineDependencies, defineDatabase, defineDns, defineEmailConfig, defineGit, defineHashing, defineLibrary, defineNotification, defineSms, defineEmail, defineChat, definePayment, defineQueue, defineSearchEngine, defineServices, defineStorage, defineUi, } from '@stacksjs/config';
|
package/dist/currency.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { add, allocate, compare, convert, equal, greaterThan, greaterThanOrEqual, hasSubUnits, isZero, lessThan, lessThanOrEqual, maximum, minimum, multiply, normalizeScale, dinero, dinero as money, subtract, toSnapshot, toUnits, toDecimal, trimScale, haveSameCurrency, haveSameAmount, dinero as currency, } from 'dinero.js';
|
|
2
|
-
export { USD } from '@dinero.js/currencies';
|
|
3
|
-
export type { Dinero, Currency } from 'dinero.js';
|
package/dist/debounce.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { debounce } from 'perfect-debounce';
|
package/dist/equal.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDeepEqual(value1: any, value2: any): boolean;
|
package/dist/export-size.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getExportsSize } from 'export-size';
|
package/dist/find.d.ts
DELETED
package/dist/function.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Fn, Nullable } from '@stacksjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* Call every function in an array
|
|
4
|
-
*/
|
|
5
|
-
export declare function batchInvoke(functions: Nullable<Fn>[]): void;
|
|
6
|
-
/**
|
|
7
|
-
* Pass the value through the callback, and return the value
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```
|
|
11
|
-
* function createUser(name: string): User {
|
|
12
|
-
* return tap(new User, user => {
|
|
13
|
-
* user.name = name
|
|
14
|
-
* })
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function tap<T>(value: T, callback: (value: T) => void): T;
|
package/dist/git.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isGitClean(): boolean;
|
package/dist/guards.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard to filter out null-ish values
|
|
3
|
-
*
|
|
4
|
-
* @category Guards
|
|
5
|
-
* @example array.filter(notNullish)
|
|
6
|
-
*/
|
|
7
|
-
export declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
|
8
|
-
/**
|
|
9
|
-
* Type guard to filter out null values
|
|
10
|
-
*
|
|
11
|
-
* @category Guards
|
|
12
|
-
* @example array.filter(noNull)
|
|
13
|
-
*/
|
|
14
|
-
export declare function noNull<T>(v: T | null): v is Exclude<T, null>;
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to filter out null-ish values
|
|
17
|
-
*
|
|
18
|
-
* @category Guards
|
|
19
|
-
* @example array.filter(notUndefined)
|
|
20
|
-
*/
|
|
21
|
-
export declare function notUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
22
|
-
/**
|
|
23
|
-
* Type guard to filter out falsy values
|
|
24
|
-
*
|
|
25
|
-
* @category Guards
|
|
26
|
-
* @example array.filter(isTruthy)
|
|
27
|
-
*/
|
|
28
|
-
export declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
package/dist/hash.d.ts
DELETED
package/dist/helpers.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { AddressInfo } from 'node:net';
|
|
3
|
-
import type { Result } from '@stacksjs/error-handling';
|
|
4
|
-
import type { CliOptions, Manifest, SyncSubprocess } from '@stacksjs/types';
|
|
5
|
-
import type { NpmScript } from '@stacksjs/enums';
|
|
6
|
-
export declare function packageManager(): Promise<any>;
|
|
7
|
-
export declare function initProject(): Promise<Result<SyncSubprocess, Error>>;
|
|
8
|
-
export declare function ensureProjectIsInitialized(): Promise<boolean>;
|
|
9
|
-
export declare function installIfVersionMismatch(): Promise<void>;
|
|
10
|
-
export declare function frameworkVersion(): Promise<string>;
|
|
11
|
-
export declare function isAppKeySet(): Promise<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* Determines the utilized reset preset.
|
|
14
|
-
*
|
|
15
|
-
* @url https://www.npmjs.com/package/@unocss/reset
|
|
16
|
-
* @param preset
|
|
17
|
-
*/
|
|
18
|
-
export declare function determineResetPreset(preset?: string): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Determines whether the specified value is a package manifest.
|
|
21
|
-
*/
|
|
22
|
-
export declare function isManifest(obj: any): obj is Manifest;
|
|
23
|
-
/**
|
|
24
|
-
* Determines whether the specified value is a string, null, or undefined.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isOptionalString(value: any): value is string | undefined;
|
|
27
|
-
export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Runs the specified NPM script in the package.json file.
|
|
30
|
-
*/
|
|
31
|
-
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<Result<SyncSubprocess, Error>>;
|
|
32
|
-
/**
|
|
33
|
-
* Determines whether the specified NPM script exists in the given manifest.
|
|
34
|
-
*/
|
|
35
|
-
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
36
|
-
export declare function parseYaml(content: any): any;
|
|
37
|
-
/**
|
|
38
|
-
* Determines the level of debugging.
|
|
39
|
-
*
|
|
40
|
-
* The debug level is determined by the following:
|
|
41
|
-
* 1. The --verbose flag
|
|
42
|
-
* 2. The debug property in the app configuration
|
|
43
|
-
*
|
|
44
|
-
* Currently, we don't support a custom debug level,
|
|
45
|
-
* though, we would like to in the future.
|
|
46
|
-
*
|
|
47
|
-
* @param options
|
|
48
|
-
*/
|
|
49
|
-
export declare function determineDebugLevel(options?: CliOptions): boolean;
|
|
50
|
-
export declare function isIpv6(address: AddressInfo): boolean;
|
|
51
|
-
export { dump as dumpYaml, load as loadYaml } from 'js-yaml';
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export * from './base';
|
|
2
|
-
export * from './clean';
|
|
3
|
-
export * from './config';
|
|
4
|
-
export * from './currency';
|
|
5
|
-
export * from './debounce';
|
|
6
|
-
export * from './equal';
|
|
7
|
-
export * from './export-size';
|
|
8
|
-
export * from './find';
|
|
9
|
-
export * from './function';
|
|
10
|
-
export * from './git';
|
|
11
|
-
export * from './guards';
|
|
12
|
-
export * from './hash';
|
|
13
|
-
export * from './helpers';
|
|
14
|
-
export * from './macroable';
|
|
15
|
-
export * from './math';
|
|
16
|
-
export * from './promise';
|
|
17
|
-
export * from './regex';
|
|
18
|
-
export * from './retry';
|
|
19
|
-
export * from './sleep';
|
|
20
|
-
export * from './throttle';
|
|
21
|
-
export * from './vendors';
|
|
22
|
-
export * from './versions';
|
package/dist/macroable.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Macroable } from 'macroable';
|
package/dist/math.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const clamp: (n: number, min: number, max: number) => number;
|
|
2
|
-
export declare function rand(min: number, max: number): number;
|
|
3
|
-
export { and, createGenericProjection, createProjection, logicNot, logicOr, or, useAbs, useAverage, useCeil, useClamp, useFloor, useMath, useMax, useMin, usePrecision, useProjection, useRound, useSum, useTrunc, } from '@vueuse/math';
|
package/dist/promise.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
export interface SingletonPromiseReturn<T> {
|
|
2
|
-
(): Promise<T>;
|
|
3
|
-
/**
|
|
4
|
-
* Reset current staled promise.
|
|
5
|
-
* Await it to have proper shutdown.
|
|
6
|
-
*/
|
|
7
|
-
reset: () => Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Promise with `resolve` and `reject` methods of itself
|
|
11
|
-
*/
|
|
12
|
-
export interface ControlledPromise<T = void> extends Promise<T> {
|
|
13
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
14
|
-
reject: (reason?: any) => void;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create singleton promise function.
|
|
18
|
-
*
|
|
19
|
-
* @category Promise
|
|
20
|
-
*/
|
|
21
|
-
export declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>;
|
|
22
|
-
/**
|
|
23
|
-
* Create a promise lock.
|
|
24
|
-
*
|
|
25
|
-
* @category Promise
|
|
26
|
-
* @example
|
|
27
|
-
* ```
|
|
28
|
-
* const lock = createPromiseLock()
|
|
29
|
-
*
|
|
30
|
-
* lock.run(async () => {
|
|
31
|
-
* await doSomething()
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* // in anther context:
|
|
35
|
-
* await lock.wait() // it will wait all tasking finished
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function createPromiseLock(): {
|
|
39
|
-
run<T = void>(fn: () => Promise<T>): Promise<T>;
|
|
40
|
-
wait(): Promise<void>;
|
|
41
|
-
isWaiting(): boolean;
|
|
42
|
-
clear(): void;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Return a Promise with `resolve` and `reject` methods
|
|
46
|
-
*
|
|
47
|
-
* @category Promise
|
|
48
|
-
* @example
|
|
49
|
-
* ```
|
|
50
|
-
* const promise = createControlledPromise()
|
|
51
|
-
*
|
|
52
|
-
* await promise
|
|
53
|
-
*
|
|
54
|
-
* // in anther context:
|
|
55
|
-
* promise.resolve(data)
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function createControlledPromise<T>(): ControlledPromise<T>;
|
|
59
|
-
/**
|
|
60
|
-
* Create a promise that will be resolved after `ms` milliseconds.
|
|
61
|
-
*/
|
package/dist/regex.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export type { Flag, MagicRegExp, MagicRegExpMatchArray, Input, MapToStringCapturedBy, StringCapturedBy } from 'magic-regexp';
|
|
2
|
-
export { createRegExp, caseInsensitive, anyOf, carriageReturn, char, charIn, charNotIn, digit, dotAll, exactly, global, letter, linefeed, maybe, multiline, not, oneOrMore, sticky, tab, unicode, whitespace, withIndices, word, wordBoundary, wordChar } from 'magic-regexp';
|
package/dist/retry.d.ts
DELETED
package/dist/sleep.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pauses execution for a specified number of milliseconds.
|
|
3
|
-
* @param ms The number of milliseconds to pause execution.
|
|
4
|
-
* @returns A promise that resolves after the specified delay.
|
|
5
|
-
*/
|
|
6
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Pauses execution for a specified number of milliseconds.
|
|
9
|
-
* @param ms The number of milliseconds to pause execution.
|
|
10
|
-
* @returns A promise that resolves after the specified delay.
|
|
11
|
-
*/
|
|
12
|
-
export declare function wait(ms: number): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Pauses execution for a specified number of milliseconds.
|
|
15
|
-
* @param ms The number of milliseconds to pause execution.
|
|
16
|
-
* @returns A promise that resolves after the specified delay.
|
|
17
|
-
*/
|
|
18
|
-
export declare function delay(ms: number): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Pauses execution until a specified condition is met.
|
|
21
|
-
* @param condition The condition to wait for.
|
|
22
|
-
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
23
|
-
* @returns A promise that resolves when the condition is met.
|
|
24
|
-
*/
|
|
25
|
-
export declare function waitUntil(condition: () => boolean, interval?: number): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Pauses execution while a specified condition is met.
|
|
28
|
-
* @param condition The condition to wait while.
|
|
29
|
-
* @param interval The interval at which to check the condition, in milliseconds. Defaults to 1000.
|
|
30
|
-
* @returns A promise that resolves when the condition is no longer met.
|
|
31
|
-
*/
|
|
32
|
-
export declare function waitWhile(condition: () => boolean, interval?: number): Promise<void>;
|
package/dist/throttle.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Throttle a function.
|
|
3
|
-
*
|
|
4
|
-
* @param {Function} fn - The function to throttle.
|
|
5
|
-
* @param {number} [wait] - The time to wait between function calls.
|
|
6
|
-
* @returns {Function} - A new function that throttles the calls to the original function.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // logs window dimensions at most every 250ms
|
|
11
|
-
* window.addEventListener(
|
|
12
|
-
* "resize",
|
|
13
|
-
* throttle(function (evt) {
|
|
14
|
-
* console.log(window.innerWidth)
|
|
15
|
-
* console.log(window.innerHeight)
|
|
16
|
-
* }, 250)
|
|
17
|
-
* )
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function throttle(fn: Function, wait?: number): (this: unknown, ...args: any[]) => void;
|
package/dist/vendors.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { asyncComputed, breakpointsAntDesign, breakpointsBootstrapV5, breakpointsMasterCss, breakpointsQuasar, breakpointsSematic, breakpointsTailwind, breakpointsVuetify, cloneFnJSON, computedAsync, computedInject, createFetch, createReusableTemplate, createTemplatePromise, createUnrefFn, customStorageEventName, defaultDocument, defaultLocation, defaultNavigator, defaultWindow, executeTransition, formatTimeAgo, getSSRHandler, mapGamepadToXbox360Controller, onClickOutside, onKeyDown, onKeyPressed, onKeyStroke, onKeyUp, onLongPress, onStartTyping, setSSRHandler, templateRef, unrefElement, useActiveElement, useAnimate, useAsyncQueue, useAsyncState, useBase64, useBattery, useBluetooth, useBreakpoints, useBroadcastChannel, useBrowserLocation, useCached, useClipboard, useCloned, useColorMode, useConfirmDialog, useCssVar, useCurrentElement, useCycleList, useDark, useDebouncedRefHistory, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDisplayMedia, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementByPoint, useElementHover, useElementSize, useElementVisibility, useEventBus, useEventListener, useEventSource, useEyeDropper, useFavicon, useFetch, useFileDialog, useFileSystemAccess, useFocus, useFocusWithin, useFps, useFullscreen, useGamepad, useGeolocation, useIdle, useImage, useInfiniteScroll, useIntersectionObserver, useKeyModifier, useLocalStorage, useMagicKeys, useManualRefHistory, useMediaControls, useMediaQuery, useMemoize, useMemory, useMounted, useMouse, useMouseInElement, useMousePressed, useMutationObserver, useNavigatorLanguage, useNetwork, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, useParallax, useParentElement, usePerformanceObserver, usePermission, usePointer, usePointerLock, usePointerSwipe, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePreferredLanguages, usePreferredReducedMotion, usePrevious, useRafFn, useRefHistory, useResizeObserver, useScreenOrientation, useScreenSafeArea, useScriptTag, useScroll, useScrollLock, useSessionStorage, useShare, useSorted, useSpeechRecognition, useSpeechSynthesis, useStepper, useStorage, useStorageAsync, useStyleTag, useSupported, useSwipe, useTemplateRefsList, useTextDirection, useTextSelection, useTextareaAutosize, useThrottledRefHistory, useTimeAgo, useTimeoutPoll, useTimestamp, useTitle, useTransition, useToggle, useUrlSearchParams, useUserMedia, useVModel, useVModels, useVibrate, useVirtualList, useWakeLock, useWebNotification, useWebSocket, useWebWorker, useWebWorkerFn, useWindowFocus, useWindowScroll, useWindowSize, useDateFormat, useNow, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever, syncRef, syncRefs, throttledRef, throttledWatch, toReactive, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, isDefined, ignorableWatch, extendRef, eagerComputed, debouncedRef, debouncedWatch, createReactiveFn, createSharedComposable, createInjectionState, createGlobalState, createEventHook, controlledRef, controlledComputed, computedEager, computedWithControl, autoResetRef, injectLocal, makeDestructurable, pausableWatch, provideLocal, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayIncludes, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useClipboardItems, useCounter, useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, } from '@vueuse/core';
|
|
2
|
-
export type { HeadObject, HeadObjectPlain, } from '@vueuse/head';
|
|
3
|
-
export { Head, HeadVuePlugin, createHead, renderHeadToString, } from '@vueuse/head';
|
|
4
|
-
export { default as readableSize } from 'pretty-bytes';
|
package/dist/versions.d.ts
DELETED