@stacksjs/path 0.75.72 → 0.75.73
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 +35 -29
- package/dist/project.js +14 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import {
|
|
4
|
-
existsSync,
|
|
4
|
+
existsSync as existsSync2,
|
|
5
5
|
lstatSync,
|
|
6
6
|
mkdirSync,
|
|
7
7
|
readFileSync,
|
|
@@ -19,34 +19,40 @@ import {
|
|
|
19
19
|
dirname,
|
|
20
20
|
extname,
|
|
21
21
|
isAbsolute,
|
|
22
|
-
join,
|
|
22
|
+
join as join2,
|
|
23
23
|
normalize,
|
|
24
24
|
parse,
|
|
25
25
|
relative as relative2,
|
|
26
26
|
resolve as resolve2,
|
|
27
|
-
sep,
|
|
27
|
+
sep as sep2,
|
|
28
28
|
toNamespacedPath
|
|
29
29
|
} from "path";
|
|
30
30
|
import process2 from "process";
|
|
31
31
|
|
|
32
32
|
// src/project.ts
|
|
33
|
-
import {
|
|
33
|
+
import { existsSync } from "fs";
|
|
34
|
+
import { join, relative, resolve, sep } from "path";
|
|
34
35
|
import process from "process";
|
|
35
36
|
var cachedCwd;
|
|
36
37
|
var cachedProjectRoot = "";
|
|
38
|
+
function projectRootFor(cwd) {
|
|
39
|
+
if (existsSync(join(cwd, "storage", "framework")))
|
|
40
|
+
return cwd;
|
|
41
|
+
const segments = cwd.split(sep);
|
|
42
|
+
const candidates = [];
|
|
43
|
+
for (let i = segments.length - 1;i > 0; i--) {
|
|
44
|
+
if (segments[i] === "storage")
|
|
45
|
+
candidates.push(segments.slice(0, i).join(sep) || sep);
|
|
46
|
+
}
|
|
47
|
+
return candidates.find((candidate) => existsSync(join(candidate, "storage", "framework"))) ?? candidates.find((candidate) => existsSync(join(candidate, "package.json"))) ?? cwd;
|
|
48
|
+
}
|
|
37
49
|
function projectPath(filePath = "", options) {
|
|
38
50
|
const cwd = process.cwd();
|
|
39
51
|
let path;
|
|
40
52
|
if (cwd === cachedCwd) {
|
|
41
53
|
path = cachedProjectRoot;
|
|
42
54
|
} else {
|
|
43
|
-
path = cwd;
|
|
44
|
-
while (path.includes("storage")) {
|
|
45
|
-
const parent = resolve(path, "..");
|
|
46
|
-
if (parent === path)
|
|
47
|
-
break;
|
|
48
|
-
path = parent;
|
|
49
|
-
}
|
|
55
|
+
path = projectRootFor(cwd);
|
|
50
56
|
cachedCwd = cwd;
|
|
51
57
|
cachedProjectRoot = path;
|
|
52
58
|
}
|
|
@@ -108,7 +114,7 @@ function userViewsPath(path) {
|
|
|
108
114
|
function userFunctionsPath(path) {
|
|
109
115
|
return `${resolveUserLibBase(projectPath("functions"), resourcesPath("functions"))}/${path || ""}`;
|
|
110
116
|
}
|
|
111
|
-
function resolveUserLibBase(rootDir, resourcesDir, exists =
|
|
117
|
+
function resolveUserLibBase(rootDir, resourcesDir, exists = existsSync2) {
|
|
112
118
|
return exists(rootDir) ? rootDir : resourcesDir;
|
|
113
119
|
}
|
|
114
120
|
function userJobsPath(path) {
|
|
@@ -226,8 +232,8 @@ function configPath(path) {
|
|
|
226
232
|
return corePath(`config/${path || ""}`);
|
|
227
233
|
}
|
|
228
234
|
function siteConfigPath(root = projectPath()) {
|
|
229
|
-
const configured =
|
|
230
|
-
return
|
|
235
|
+
const configured = join2(root, "config/site.ts");
|
|
236
|
+
return existsSync2(configured) ? configured : join2(root, "site.config.ts");
|
|
231
237
|
}
|
|
232
238
|
function corePath(path) {
|
|
233
239
|
return frameworkPath(`core/${path || ""}`);
|
|
@@ -375,11 +381,11 @@ function notApplicable() {
|
|
|
375
381
|
return { status: "not-applicable", installed: null, vendored: null, syncedAt: null };
|
|
376
382
|
}
|
|
377
383
|
function defaultsPackagePath(projectRoot = projectPath()) {
|
|
378
|
-
return
|
|
384
|
+
return join2(projectRoot, "node_modules/@stacksjs/defaults");
|
|
379
385
|
}
|
|
380
386
|
function manifestVersion(packageRoot) {
|
|
381
387
|
try {
|
|
382
|
-
const version = JSON.parse(readFileSync(
|
|
388
|
+
const version = JSON.parse(readFileSync(join2(packageRoot, "package.json"), "utf8"))?.version;
|
|
383
389
|
return typeof version === "string" ? version : null;
|
|
384
390
|
} catch {
|
|
385
391
|
return null;
|
|
@@ -390,17 +396,17 @@ function installedDefaultsVersion(projectRoot = projectPath()) {
|
|
|
390
396
|
}
|
|
391
397
|
function isInside(child, parent) {
|
|
392
398
|
const resolved = realpathSync(child);
|
|
393
|
-
return resolved === parent || resolved.startsWith(`${parent}${
|
|
399
|
+
return resolved === parent || resolved.startsWith(`${parent}${sep2}`);
|
|
394
400
|
}
|
|
395
401
|
function inspectDefaultsProvenance(projectRoot = projectPath()) {
|
|
396
|
-
const targetDefaults =
|
|
402
|
+
const targetDefaults = join2(projectRoot, "storage/framework/defaults");
|
|
397
403
|
const packageRoot = defaultsPackagePath(projectRoot);
|
|
398
|
-
if (!
|
|
404
|
+
if (!existsSync2(targetDefaults) || !existsSync2(join2(packageRoot, "package.json")))
|
|
399
405
|
return notApplicable();
|
|
400
|
-
if (
|
|
406
|
+
if (existsSync2(join2(projectRoot, "storage/framework/core/buddy/package.json")))
|
|
401
407
|
return notApplicable();
|
|
402
408
|
try {
|
|
403
|
-
if (!isInside(packageRoot,
|
|
409
|
+
if (!isInside(packageRoot, join2(realpathSync(projectRoot), "node_modules")))
|
|
404
410
|
return notApplicable();
|
|
405
411
|
} catch {
|
|
406
412
|
return notApplicable();
|
|
@@ -410,7 +416,7 @@ function inspectDefaultsProvenance(projectRoot = projectPath()) {
|
|
|
410
416
|
return notApplicable();
|
|
411
417
|
let marker = null;
|
|
412
418
|
try {
|
|
413
|
-
const raw = JSON.parse(readFileSync(
|
|
419
|
+
const raw = JSON.parse(readFileSync(join2(targetDefaults, DEFAULTS_SYNC_MARKER), "utf8"));
|
|
414
420
|
if (typeof raw?.version === "string")
|
|
415
421
|
marker = { version: raw.version, syncedAt: typeof raw.syncedAt === "string" ? raw.syncedAt : "" };
|
|
416
422
|
} catch {}
|
|
@@ -573,9 +579,9 @@ function applyRuntimeDirectoryEnv() {
|
|
|
573
579
|
function mergeDirectoryInto(from, to) {
|
|
574
580
|
mkdirSync(to, { recursive: true });
|
|
575
581
|
for (const entry of readdirSync(from)) {
|
|
576
|
-
const source =
|
|
577
|
-
const destination =
|
|
578
|
-
if (!
|
|
582
|
+
const source = join2(from, entry);
|
|
583
|
+
const destination = join2(to, entry);
|
|
584
|
+
if (!existsSync2(destination)) {
|
|
579
585
|
renameSync(source, destination);
|
|
580
586
|
continue;
|
|
581
587
|
}
|
|
@@ -769,12 +775,12 @@ var path = {
|
|
|
769
775
|
dirname,
|
|
770
776
|
extname,
|
|
771
777
|
isAbsolute,
|
|
772
|
-
join,
|
|
778
|
+
join: join2,
|
|
773
779
|
normalize,
|
|
774
780
|
relative: relative2,
|
|
775
781
|
resolve: resolve2,
|
|
776
782
|
parse,
|
|
777
|
-
sep: () =>
|
|
783
|
+
sep: () => sep2,
|
|
778
784
|
toNamespacedPath
|
|
779
785
|
};
|
|
780
786
|
export {
|
|
@@ -844,7 +850,7 @@ export {
|
|
|
844
850
|
installedDefaultsVersion,
|
|
845
851
|
isAbsolute,
|
|
846
852
|
jobsPath,
|
|
847
|
-
join,
|
|
853
|
+
join2 as join,
|
|
848
854
|
langPath,
|
|
849
855
|
layoutsPath,
|
|
850
856
|
libraryPackagePath,
|
|
@@ -889,7 +895,7 @@ export {
|
|
|
889
895
|
scriptsPath,
|
|
890
896
|
searchEnginePath,
|
|
891
897
|
securityPath,
|
|
892
|
-
sep,
|
|
898
|
+
sep2 as sep,
|
|
893
899
|
serverPath,
|
|
894
900
|
serverlessPath,
|
|
895
901
|
settingsPath,
|
package/dist/project.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/project.ts
|
|
3
|
-
import {
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { join, relative, resolve, sep } from "path";
|
|
4
5
|
import process from "process";
|
|
5
6
|
var cachedCwd;
|
|
6
7
|
var cachedProjectRoot = "";
|
|
8
|
+
function projectRootFor(cwd) {
|
|
9
|
+
if (existsSync(join(cwd, "storage", "framework")))
|
|
10
|
+
return cwd;
|
|
11
|
+
const segments = cwd.split(sep);
|
|
12
|
+
const candidates = [];
|
|
13
|
+
for (let i = segments.length - 1;i > 0; i--) {
|
|
14
|
+
if (segments[i] === "storage")
|
|
15
|
+
candidates.push(segments.slice(0, i).join(sep) || sep);
|
|
16
|
+
}
|
|
17
|
+
return candidates.find((candidate) => existsSync(join(candidate, "storage", "framework"))) ?? candidates.find((candidate) => existsSync(join(candidate, "package.json"))) ?? cwd;
|
|
18
|
+
}
|
|
7
19
|
function projectPath(filePath = "", options) {
|
|
8
20
|
const cwd = process.cwd();
|
|
9
21
|
let path;
|
|
10
22
|
if (cwd === cachedCwd) {
|
|
11
23
|
path = cachedProjectRoot;
|
|
12
24
|
} else {
|
|
13
|
-
path = cwd;
|
|
14
|
-
while (path.includes("storage")) {
|
|
15
|
-
const parent = resolve(path, "..");
|
|
16
|
-
if (parent === path)
|
|
17
|
-
break;
|
|
18
|
-
path = parent;
|
|
19
|
-
}
|
|
25
|
+
path = projectRootFor(cwd);
|
|
20
26
|
cachedCwd = cwd;
|
|
21
27
|
cachedProjectRoot = path;
|
|
22
28
|
}
|