@stacksjs/path 0.70.162 → 0.70.164
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 +1 -1
- package/dist/index.d.ts +131 -0
- package/dist/index.js +103 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ For help, discussion about best practices, or any other conversation that would
|
|
|
49
49
|
|
|
50
50
|
For casual chit-chat with others using this package:
|
|
51
51
|
|
|
52
|
-
[Join the Stacks Discord Server](https://
|
|
52
|
+
[Join the Stacks Discord Server](https://stacksjs.com/discord)
|
|
53
53
|
|
|
54
54
|
## 🙏🏼 Credits
|
|
55
55
|
|
package/dist/index.d.ts
CHANGED
|
@@ -807,6 +807,16 @@ export declare function scriptsPath(path?: string): string;
|
|
|
807
807
|
* @returns The absolute path to the specified file or directory within the scheduler directory.
|
|
808
808
|
*/
|
|
809
809
|
export declare function schedulerPath(path?: string): string;
|
|
810
|
+
/**
|
|
811
|
+
* Returns the path to the `skills` directory within the core directory.
|
|
812
|
+
*
|
|
813
|
+
* That is the `@stacksjs/skills` package. The skills it reads ship from
|
|
814
|
+
* `storage/framework/defaults/ai/skills`, not from here.
|
|
815
|
+
*
|
|
816
|
+
* @param path - The relative path to the file or directory within the skills directory.
|
|
817
|
+
* @returns The absolute path to the specified file or directory within the skills directory.
|
|
818
|
+
*/
|
|
819
|
+
export declare function skillsPath(path?: string): string;
|
|
810
820
|
/**
|
|
811
821
|
* Returns the path to the `slug` directory within the core directory.
|
|
812
822
|
*
|
|
@@ -929,6 +939,108 @@ export declare function utilsPath(path?: string): string;
|
|
|
929
939
|
* @returns The absolute path to the specified file or directory within the validation directory.
|
|
930
940
|
*/
|
|
931
941
|
export declare function validationPath(path?: string): string;
|
|
942
|
+
/**
|
|
943
|
+
* Returns the path to the framework's runtime scratch directory.
|
|
944
|
+
*
|
|
945
|
+
* This is where the framework keeps short-lived, machine-local state that is
|
|
946
|
+
* neither source nor build output: the `buddy migrate` lockfile, the marker a
|
|
947
|
+
* migration subprocess writes back to the CLI, temporary bundles, and similar.
|
|
948
|
+
* Nothing in here is committed, and deleting the whole directory is always safe.
|
|
949
|
+
*
|
|
950
|
+
* It used to live at `./.stacks` in the project root. Everything runtime-owned
|
|
951
|
+
* now sits under `storage/` so the root only holds files you author.
|
|
952
|
+
*
|
|
953
|
+
* @param path - The relative path to the file or directory within the runtime directory.
|
|
954
|
+
* @returns The absolute path to the specified file or directory.
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* import { frameworkRuntimePath } from '@stacksjs/path'
|
|
958
|
+
*
|
|
959
|
+
* console.log(frameworkRuntimePath('migrations.lock'))
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
export declare function frameworkRuntimePath(path?: string): string;
|
|
963
|
+
/**
|
|
964
|
+
* Returns the path to stx's build cache and generated route manifest.
|
|
965
|
+
*
|
|
966
|
+
* stx writes its compiled-template cache, Crosswind CSS cache, client-script
|
|
967
|
+
* bundles and `routes.ts` manifest here. It used to be `./.stx` in the project
|
|
968
|
+
* root; stx now takes the location from its own `stateDir` config option, which
|
|
969
|
+
* `config/ui.ts` sets to this directory and {@link runtimeDirectoryEnv} exports
|
|
970
|
+
* as `STX_DIR` for every process the project starts.
|
|
971
|
+
*
|
|
972
|
+
* @param path - The relative path to the file or directory within the stx cache.
|
|
973
|
+
* @returns The absolute path to the specified file or directory.
|
|
974
|
+
*/
|
|
975
|
+
export declare function stxPath(path?: string): string;
|
|
976
|
+
/**
|
|
977
|
+
* Returns the path to the local cloud state directory.
|
|
978
|
+
*
|
|
979
|
+
* ts-cloud persists per-environment driver state, cached templates, and the
|
|
980
|
+
* management dashboard's credentials here. These are machine-local secrets and
|
|
981
|
+
* caches, never committed. It used to be `./.ts-cloud` in the project root;
|
|
982
|
+
* ts-cloud now takes the location from its own `stateDir` config option, which
|
|
983
|
+
* `config/cloud.ts` sets to this directory and {@link runtimeDirectoryEnv}
|
|
984
|
+
* exports as `TS_CLOUD_STATE_DIR` for every process the project starts.
|
|
985
|
+
*
|
|
986
|
+
* Not to be confused with {@link cloudPath}, which points at the committed
|
|
987
|
+
* `cloud/` infrastructure-as-code directory.
|
|
988
|
+
*
|
|
989
|
+
* @param path - The relative path to the file or directory within the cloud state directory.
|
|
990
|
+
* @returns The absolute path to the specified file or directory.
|
|
991
|
+
*/
|
|
992
|
+
export declare function cloudStatePath(path?: string): string;
|
|
993
|
+
/**
|
|
994
|
+
* The environment stx and ts-cloud need in order to find their state.
|
|
995
|
+
*
|
|
996
|
+
* Both take the directory from their own config (`config/ui.ts` sets stx's
|
|
997
|
+
* `stateDir`, `config/cloud.ts` sets ts-cloud's), but a config is only read
|
|
998
|
+
* once something loads it, and both libraries reach for their state from module
|
|
999
|
+
* scope and from helpers that never see a config object. Their documented
|
|
1000
|
+
* override is an environment variable, which is also what carries the answer
|
|
1001
|
+
* into every process a command spawns. Absolute, so a code path resolving
|
|
1002
|
+
* against a subdirectory still lands in the same place.
|
|
1003
|
+
*/
|
|
1004
|
+
export declare function runtimeDirectoryEnv(): Record<string, string>;
|
|
1005
|
+
/**
|
|
1006
|
+
* Applies {@link runtimeDirectoryEnv} to `process.env`.
|
|
1007
|
+
*
|
|
1008
|
+
* An explicitly set value wins: someone who exports `STX_DIR` before running a
|
|
1009
|
+
* command means it.
|
|
1010
|
+
*/
|
|
1011
|
+
export declare function applyRuntimeDirectoryEnv(): void;
|
|
1012
|
+
/**
|
|
1013
|
+
* Recursively merges `from` into `to`, keeping whatever is already at `to`.
|
|
1014
|
+
*
|
|
1015
|
+
* The recursion matters: a shallow "rename each top-level entry unless it
|
|
1016
|
+
* exists" pass would delete an entire subtree just because a sibling file
|
|
1017
|
+
* inside it happened to be present at the destination. Directories present on
|
|
1018
|
+
* both sides are merged entry by entry; only files that already exist at the
|
|
1019
|
+
* destination are dropped from the source.
|
|
1020
|
+
*/
|
|
1021
|
+
export declare function mergeDirectoryInto(from: string, to: string): void;
|
|
1022
|
+
/**
|
|
1023
|
+
* Creates the framework's runtime directories under `storage/` and clears the
|
|
1024
|
+
* legacy root-level entries.
|
|
1025
|
+
*
|
|
1026
|
+
* For each relocated directory this:
|
|
1027
|
+
*
|
|
1028
|
+
* 1. creates the target under `storage/` if it does not exist yet,
|
|
1029
|
+
* 2. recursively merges a pre-existing real directory in the project root into
|
|
1030
|
+
* it (anything already at the target wins, so re-running is safe),
|
|
1031
|
+
* 3. removes what is left in the root - including the symlink earlier versions
|
|
1032
|
+
* put there, now that stx and ts-cloud are configured to read the target
|
|
1033
|
+
* directly.
|
|
1034
|
+
*
|
|
1035
|
+
* A symlink pointing anywhere other than the target is left alone: it is not
|
|
1036
|
+
* ours to remove (an old checkout's `.stacks` may still be the core-source
|
|
1037
|
+
* shortcut that `buddy generate:core-symlink` now writes to `.framework`).
|
|
1038
|
+
*
|
|
1039
|
+
* Every step is best-effort - this must never throw or block a command.
|
|
1040
|
+
*
|
|
1041
|
+
* @returns What is now in place for each relocated directory.
|
|
1042
|
+
*/
|
|
1043
|
+
export declare function ensureRuntimeDirectories(): RuntimeDirectoryState[];
|
|
932
1044
|
/**
|
|
933
1045
|
* Returns the path to the `validation` directory within the core directory.
|
|
934
1046
|
*
|
|
@@ -944,6 +1056,18 @@ export declare function socialsPath(path?: string): string;
|
|
|
944
1056
|
*/
|
|
945
1057
|
export declare function homeDir(path?: string): string;
|
|
946
1058
|
export declare const path: Path;
|
|
1059
|
+
/**
|
|
1060
|
+
* The outcome of relocating one runtime directory.
|
|
1061
|
+
*
|
|
1062
|
+
* `cleared` says whether the old root-level entry is gone. It stays false only
|
|
1063
|
+
* when something we should not touch is sitting there - a symlink someone else
|
|
1064
|
+
* created, or an entry we could not remove.
|
|
1065
|
+
*/
|
|
1066
|
+
export declare interface RuntimeDirectoryState {
|
|
1067
|
+
legacy: string
|
|
1068
|
+
target: string
|
|
1069
|
+
cleared: boolean
|
|
1070
|
+
}
|
|
947
1071
|
export declare interface Path {
|
|
948
1072
|
actionsPath: (path?: string) => string
|
|
949
1073
|
userActionsPath: (path?: string) => string
|
|
@@ -971,7 +1095,13 @@ export declare interface Path {
|
|
|
971
1095
|
chatPath: (path?: string) => string
|
|
972
1096
|
cliPath: (path?: string) => string
|
|
973
1097
|
cloudPath: (path?: string) => string
|
|
1098
|
+
cloudStatePath: (path?: string) => string
|
|
974
1099
|
frameworkCloudPath: (path?: string) => string
|
|
1100
|
+
frameworkRuntimePath: (path?: string) => string
|
|
1101
|
+
stxPath: (path?: string) => string
|
|
1102
|
+
ensureRuntimeDirectories: () => RuntimeDirectoryState[]
|
|
1103
|
+
runtimeDirectoryEnv: () => Record<string, string>
|
|
1104
|
+
applyRuntimeDirectoryEnv: () => void
|
|
975
1105
|
collectionsPath: (path?: string) => string
|
|
976
1106
|
commandsPath: (path?: string) => string
|
|
977
1107
|
componentsPath: (path?: string) => string
|
|
@@ -1037,6 +1167,7 @@ export declare interface Path {
|
|
|
1037
1167
|
schedulerPath: (path?: string) => string
|
|
1038
1168
|
settingsPath: (path?: string) => string
|
|
1039
1169
|
smsPath: (path?: string) => string
|
|
1170
|
+
skillsPath: (path?: string) => string
|
|
1040
1171
|
slugPath: (path?: string) => string
|
|
1041
1172
|
scriptsPath: (path?: string) => string
|
|
1042
1173
|
securityPath: (path?: string) => string
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/index.ts
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
lstatSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
readlinkSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
unlinkSync
|
|
12
|
+
} from "fs";
|
|
4
13
|
import os from "os";
|
|
5
14
|
import {
|
|
6
15
|
basename,
|
|
@@ -387,6 +396,9 @@ function scriptsPath(path) {
|
|
|
387
396
|
function schedulerPath(path) {
|
|
388
397
|
return corePath(`scheduler/${path || ""}`);
|
|
389
398
|
}
|
|
399
|
+
function skillsPath(path) {
|
|
400
|
+
return corePath(`skills/${path || ""}`);
|
|
401
|
+
}
|
|
390
402
|
function slugPath(path) {
|
|
391
403
|
return corePath(`slug/${path || ""}`);
|
|
392
404
|
}
|
|
@@ -450,6 +462,81 @@ function utilsPath(path) {
|
|
|
450
462
|
function validationPath(path) {
|
|
451
463
|
return corePath(`validation/${path || ""}`);
|
|
452
464
|
}
|
|
465
|
+
function frameworkRuntimePath(path) {
|
|
466
|
+
return frameworkPath(`runtime/${path || ""}`);
|
|
467
|
+
}
|
|
468
|
+
function stxPath(path) {
|
|
469
|
+
return frameworkPath(`stx/${path || ""}`);
|
|
470
|
+
}
|
|
471
|
+
function cloudStatePath(path) {
|
|
472
|
+
return storagePath(`cloud/${path || ""}`);
|
|
473
|
+
}
|
|
474
|
+
var RELOCATED_RUNTIME_DIRECTORIES = [
|
|
475
|
+
{ legacy: ".stx", target: stxPath },
|
|
476
|
+
{ legacy: ".ts-cloud", target: cloudStatePath },
|
|
477
|
+
{ legacy: ".stacks", target: frameworkRuntimePath }
|
|
478
|
+
];
|
|
479
|
+
function runtimeDirectoryEnv() {
|
|
480
|
+
return {
|
|
481
|
+
STX_DIR: stxPath().replace(/\/$/, ""),
|
|
482
|
+
TS_CLOUD_STATE_DIR: cloudStatePath().replace(/\/$/, "")
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function applyRuntimeDirectoryEnv() {
|
|
486
|
+
for (const [key, value] of Object.entries(runtimeDirectoryEnv())) {
|
|
487
|
+
if (!process.env[key]?.trim())
|
|
488
|
+
process.env[key] = value;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function mergeDirectoryInto(from, to) {
|
|
492
|
+
mkdirSync(to, { recursive: true });
|
|
493
|
+
for (const entry of readdirSync(from)) {
|
|
494
|
+
const source = join(from, entry);
|
|
495
|
+
const destination = join(to, entry);
|
|
496
|
+
if (!existsSync(destination)) {
|
|
497
|
+
renameSync(source, destination);
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (lstatSync(source).isDirectory() && lstatSync(destination).isDirectory()) {
|
|
501
|
+
mergeDirectoryInto(source, destination);
|
|
502
|
+
rmSync(source, { recursive: true, force: true });
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
rmSync(source, { recursive: true, force: true });
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function ensureRuntimeDirectories() {
|
|
509
|
+
const results = [];
|
|
510
|
+
for (const { legacy, target } of RELOCATED_RUNTIME_DIRECTORIES) {
|
|
511
|
+
const legacyPath = projectPath(legacy);
|
|
512
|
+
const targetPath = target();
|
|
513
|
+
try {
|
|
514
|
+
mkdirSync(targetPath, { recursive: true });
|
|
515
|
+
const stats = lstatSync(legacyPath, { throwIfNoEntry: false });
|
|
516
|
+
if (!stats) {
|
|
517
|
+
results.push({ legacy: legacyPath, target: targetPath, cleared: true });
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (stats.isSymbolicLink()) {
|
|
521
|
+
const pointsAtTarget = resolve(dirname(legacyPath), readlinkSync(legacyPath)) === resolve(targetPath);
|
|
522
|
+
if (!pointsAtTarget) {
|
|
523
|
+
results.push({ legacy: legacyPath, target: targetPath, cleared: false });
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
unlinkSync(legacyPath);
|
|
527
|
+
} else if (stats.isDirectory()) {
|
|
528
|
+
mergeDirectoryInto(legacyPath, targetPath);
|
|
529
|
+
rmSync(legacyPath, { recursive: true, force: true });
|
|
530
|
+
} else {
|
|
531
|
+
rmSync(legacyPath, { force: true });
|
|
532
|
+
}
|
|
533
|
+
results.push({ legacy: legacyPath, target: targetPath, cleared: true });
|
|
534
|
+
} catch {
|
|
535
|
+
results.push({ legacy: legacyPath, target: targetPath, cleared: false });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return results;
|
|
539
|
+
}
|
|
453
540
|
function socialsPath(path) {
|
|
454
541
|
return corePath(`socials/${path || ""}`);
|
|
455
542
|
}
|
|
@@ -483,6 +570,12 @@ var path = {
|
|
|
483
570
|
chatPath,
|
|
484
571
|
cliPath,
|
|
485
572
|
cloudPath,
|
|
573
|
+
cloudStatePath,
|
|
574
|
+
frameworkRuntimePath,
|
|
575
|
+
stxPath,
|
|
576
|
+
ensureRuntimeDirectories,
|
|
577
|
+
runtimeDirectoryEnv,
|
|
578
|
+
applyRuntimeDirectoryEnv,
|
|
486
579
|
frameworkCloudPath,
|
|
487
580
|
collectionsPath,
|
|
488
581
|
commandsPath,
|
|
@@ -549,6 +642,7 @@ var path = {
|
|
|
549
642
|
schedulerPath,
|
|
550
643
|
settingsPath,
|
|
551
644
|
smsPath,
|
|
645
|
+
skillsPath,
|
|
552
646
|
slugPath,
|
|
553
647
|
scriptsPath,
|
|
554
648
|
securityPath,
|
|
@@ -621,6 +715,7 @@ export {
|
|
|
621
715
|
tinkerPath,
|
|
622
716
|
testsPath,
|
|
623
717
|
testingPath,
|
|
718
|
+
stxPath,
|
|
624
719
|
stringsPath,
|
|
625
720
|
storesPath,
|
|
626
721
|
storagePath,
|
|
@@ -630,6 +725,7 @@ export {
|
|
|
630
725
|
socialsPath,
|
|
631
726
|
smsPath,
|
|
632
727
|
slugPath,
|
|
728
|
+
skillsPath,
|
|
633
729
|
shellPath,
|
|
634
730
|
settingsPath,
|
|
635
731
|
serverlessPath,
|
|
@@ -640,6 +736,7 @@ export {
|
|
|
640
736
|
scriptsPath,
|
|
641
737
|
schedulerPath,
|
|
642
738
|
runtimePath,
|
|
739
|
+
runtimeDirectoryEnv,
|
|
643
740
|
routesPath,
|
|
644
741
|
routerPath,
|
|
645
742
|
resourcesPath,
|
|
@@ -667,6 +764,7 @@ export {
|
|
|
667
764
|
newsletterPath,
|
|
668
765
|
modulesPath,
|
|
669
766
|
modelsPath,
|
|
767
|
+
mergeDirectoryInto,
|
|
670
768
|
logsPath,
|
|
671
769
|
loggingPath,
|
|
672
770
|
listenersPath,
|
|
@@ -683,6 +781,7 @@ export {
|
|
|
683
781
|
healthPath,
|
|
684
782
|
gitPath,
|
|
685
783
|
functionsPath,
|
|
784
|
+
frameworkRuntimePath,
|
|
686
785
|
frameworkPath,
|
|
687
786
|
frameworkCloudPath,
|
|
688
787
|
findProjectPath,
|
|
@@ -694,6 +793,7 @@ export {
|
|
|
694
793
|
eslintPluginPath,
|
|
695
794
|
errorHandlingPath,
|
|
696
795
|
enumsPath,
|
|
796
|
+
ensureRuntimeDirectories,
|
|
697
797
|
emailPath,
|
|
698
798
|
docsPath,
|
|
699
799
|
dnsPath,
|
|
@@ -714,6 +814,7 @@ export {
|
|
|
714
814
|
componentsPath,
|
|
715
815
|
commandsPath,
|
|
716
816
|
collectionsPath,
|
|
817
|
+
cloudStatePath,
|
|
717
818
|
cloudPath,
|
|
718
819
|
cliPath,
|
|
719
820
|
chatPath,
|
|
@@ -728,6 +829,7 @@ export {
|
|
|
728
829
|
authPath,
|
|
729
830
|
assetsPath,
|
|
730
831
|
arraysPath,
|
|
832
|
+
applyRuntimeDirectoryEnv,
|
|
731
833
|
appPath,
|
|
732
834
|
analyticsPath,
|
|
733
835
|
aliasPath,
|