@stryke/fs 0.25.0 → 0.26.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/exists.cjs +15 -0
- package/dist/exists.d.ts +14 -0
- package/dist/exists.mjs +1 -0
- package/dist/get-workspace-root.cjs +38 -0
- package/dist/get-workspace-root.d.ts +30 -0
- package/dist/get-workspace-root.mjs +1 -0
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.mjs +1 -1
- package/dist/index.cjs +33 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +1 -1
- package/dist/install.cjs +1 -1
- package/dist/install.mjs +1 -1
- package/dist/package-fns.cjs +9 -7
- package/dist/package-fns.d.ts +1 -1
- package/dist/package-fns.mjs +1 -1
- package/dist/registry.cjs +1 -1
- package/dist/registry.mjs +1 -1
- package/dist/resolve.cjs +59 -0
- package/dist/resolve.d.ts +71 -0
- package/dist/resolve.mjs +1 -0
- package/dist/tsconfig.cjs +1 -1
- package/dist/tsconfig.mjs +1 -1
- package/dist/write-file.cjs +1 -1
- package/dist/write-file.mjs +1 -1
- package/package.json +46 -3
package/dist/exists.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.exists = exists;
|
|
7
|
+
exports.existsSync = existsSync;
|
|
8
|
+
var _nodeFs = require("node:fs");
|
|
9
|
+
var _promises = require("node:fs/promises");
|
|
10
|
+
function existsSync(s) {
|
|
11
|
+
return (0, _nodeFs.existsSync)(s);
|
|
12
|
+
}
|
|
13
|
+
async function exists(s) {
|
|
14
|
+
return (0, _promises.access)(s, _promises.constants.F_OK).then(() => !0).catch(() => !1);
|
|
15
|
+
}
|
package/dist/exists.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a file exists
|
|
3
|
+
*
|
|
4
|
+
* @param filePath - The file path to check
|
|
5
|
+
* @returns An indicator specifying if the file exists
|
|
6
|
+
*/
|
|
7
|
+
export declare function existsSync(filePath: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a file exists
|
|
10
|
+
*
|
|
11
|
+
* @param filePath - The file path to check
|
|
12
|
+
* @returns An indicator specifying if the file exists
|
|
13
|
+
*/
|
|
14
|
+
export declare function exists(filePath: string): Promise<boolean>;
|
package/dist/exists.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as t}from"node:fs";import{access as n,constants as e}from"node:fs/promises";export function existsSync(s){return t(s)}export async function exists(s){return n(s,e.F_OK).then(()=>!0).catch(()=>!1)}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WORKSPACE_ROOT_CONTENT = exports.PROJECT_ROOT_CONTENT = void 0;
|
|
7
|
+
exports.getProjectRoot = getProjectRoot;
|
|
8
|
+
exports.getWorkspaceRoot = getWorkspaceRoot;
|
|
9
|
+
exports.isProjectRoot = isProjectRoot;
|
|
10
|
+
exports.isWorkspaceRoot = isWorkspaceRoot;
|
|
11
|
+
var _configTools = require("@storm-software/config-tools");
|
|
12
|
+
var _getParentPath = require("@stryke/path/get-parent-path");
|
|
13
|
+
var _isRootDir = require("@stryke/path/is-root-dir");
|
|
14
|
+
const WORKSPACE_ROOT_CONTENT = exports.WORKSPACE_ROOT_CONTENT = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock", "nx.json", "knip.json", "pnpm-workspace.yaml", "LICENSE", ".all-contributorsrc", ".whitesource", "syncpack.config.js", "syncpack.json", "socket.yaml", "lefthook.yaml", ".npmrc", ".log4brains.yml", ".huskyrc", ".husky", ".lintstagedrc", ".commitlintrc", "lefthook.yml", ".github", ".nx", ".vscode", "patches"],
|
|
15
|
+
PROJECT_ROOT_CONTENT = exports.PROJECT_ROOT_CONTENT = ["project.json", "package.json", ".storm"];
|
|
16
|
+
function getWorkspaceRoot(o = process.cwd()) {
|
|
17
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
|
|
18
|
+
const t = (0, _configTools.findWorkspaceRootSafe)(o);
|
|
19
|
+
if (t) return t;
|
|
20
|
+
let r = (0, _getParentPath.getParentPath)(WORKSPACE_ROOT_CONTENT, o);
|
|
21
|
+
if (r) return r;
|
|
22
|
+
for (r = o; r && !(0, _isRootDir.isSystemRoot)(r);) if (r = (0, _getParentPath.getParentPath)("storm-workspace.json", r, {
|
|
23
|
+
skipCwd: !0
|
|
24
|
+
}), r) return r;
|
|
25
|
+
return o;
|
|
26
|
+
}
|
|
27
|
+
function isWorkspaceRoot(o = process.cwd()) {
|
|
28
|
+
const t = getWorkspaceRoot(o);
|
|
29
|
+
return t ? t === o : !1;
|
|
30
|
+
}
|
|
31
|
+
function getProjectRoot(o = process.cwd()) {
|
|
32
|
+
const t = (0, _getParentPath.getParentPath)(PROJECT_ROOT_CONTENT, o);
|
|
33
|
+
return t || o;
|
|
34
|
+
}
|
|
35
|
+
function isProjectRoot(o = process.cwd()) {
|
|
36
|
+
const t = getProjectRoot(o);
|
|
37
|
+
return t ? t === o : !1;
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const WORKSPACE_ROOT_CONTENT: string[];
|
|
2
|
+
export declare const PROJECT_ROOT_CONTENT: string[];
|
|
3
|
+
/**
|
|
4
|
+
* Get the workspace root path
|
|
5
|
+
*
|
|
6
|
+
* @param dir - A directory to start the search from
|
|
7
|
+
* @returns The workspace root path
|
|
8
|
+
*/
|
|
9
|
+
export declare function getWorkspaceRoot(dir?: string): any;
|
|
10
|
+
/**
|
|
11
|
+
* Check if the given directory is the workspace root
|
|
12
|
+
*
|
|
13
|
+
* @param dir - A directory to check
|
|
14
|
+
* @returns True if the directory is the workspace root, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function isWorkspaceRoot(dir?: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get the project root path
|
|
19
|
+
*
|
|
20
|
+
* @param dir - A directory to start the search from
|
|
21
|
+
* @returns The project root path
|
|
22
|
+
*/
|
|
23
|
+
export declare function getProjectRoot(dir?: string): any;
|
|
24
|
+
/**
|
|
25
|
+
* Check if the given directory is the project root
|
|
26
|
+
*
|
|
27
|
+
* @param dir - A directory to check
|
|
28
|
+
* @returns True if the directory is the project root, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare function isProjectRoot(dir?: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{findWorkspaceRootSafe as e}from"@storm-software/config-tools";import{getParentPath as s}from"@stryke/path/get-parent-path";import{isSystemRoot as n}from"@stryke/path/is-root-dir";export const WORKSPACE_ROOT_CONTENT=["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock","nx.json","knip.json","pnpm-workspace.yaml","LICENSE",".all-contributorsrc",".whitesource","syncpack.config.js","syncpack.json","socket.yaml","lefthook.yaml",".npmrc",".log4brains.yml",".huskyrc",".husky",".lintstagedrc",".commitlintrc","lefthook.yml",".github",".nx",".vscode","patches"],PROJECT_ROOT_CONTENT=["project.json","package.json",".storm"];export function getWorkspaceRoot(o=process.cwd()){if(process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH)return process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH;const t=e(o);if(t)return t;let r=s(WORKSPACE_ROOT_CONTENT,o);if(r)return r;for(r=o;r&&!n(r);)if(r=s("storm-workspace.json",r,{skipCwd:!0}),r)return r;return o}export function isWorkspaceRoot(o=process.cwd()){const t=getWorkspaceRoot(o);return t?t===o:!1}export function getProjectRoot(o=process.cwd()){const t=s(PROJECT_ROOT_CONTENT,o);return t||o}export function isProjectRoot(o=process.cwd()){const t=getProjectRoot(o);return t?t===o:!1}
|
package/dist/helpers.cjs
CHANGED
|
@@ -9,10 +9,10 @@ exports.extractFileFromTar = extractFileFromTar;
|
|
|
9
9
|
exports.extractFileFromTarGzip = extractFileFromTarGzip;
|
|
10
10
|
exports.removeDirectory = removeDirectory;
|
|
11
11
|
exports.removeDirectorySync = removeDirectorySync;
|
|
12
|
-
var _exists = require("@stryke/path/exists");
|
|
13
12
|
var _nanotar = require("nanotar");
|
|
14
13
|
var _nodeFs = require("node:fs");
|
|
15
14
|
var _promises = require("node:fs/promises");
|
|
15
|
+
var _exists = require("./exists.cjs");
|
|
16
16
|
function createDirectorySync(r) {
|
|
17
17
|
if (!(0, _exists.existsSync)(r)) return (0, _nodeFs.mkdirSync)(r, {
|
|
18
18
|
recursive: !0
|
package/dist/helpers.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{parseTar as y,parseTarGzip as g}from"nanotar";import{createWriteStream as u,mkdirSync as p,rmSync as w}from"node:fs";import{mkdir as c,readFile as o,rm as x}from"node:fs/promises";import{exists as s,existsSync as a}from"./exists";export function createDirectorySync(r){if(!a(r))return p(r,{recursive:!0})}export async function createDirectory(r){if(!await s(r))return c(r,{recursive:!0})}export function removeDirectorySync(r){if(a(r))return w(r,{recursive:!0})}export async function removeDirectory(r){if(a(r))return x(r,{recursive:!0})}export async function extractFileFromTar(r,i,t){const e=y(await o(r)).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}export async function extractFileFromTarGzip(r,i,t){const e=(await g(await o(r))).find(n=>n.name===i);if(!e?.data)return;await s(t)||await c(t,{recursive:!0}),u(t).write(e.data)}
|
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,28 @@ Object.keys(_copyFile).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
var _exists = require("./exists.cjs");
|
|
73
|
+
Object.keys(_exists).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _exists[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _exists[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
84
|
+
Object.keys(_getWorkspaceRoot).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _getWorkspaceRoot[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _getWorkspaceRoot[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
72
94
|
var _helpers = require("./helpers.cjs");
|
|
73
95
|
Object.keys(_helpers).forEach(function (key) {
|
|
74
96
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -157,6 +179,17 @@ Object.keys(_removeFile).forEach(function (key) {
|
|
|
157
179
|
}
|
|
158
180
|
});
|
|
159
181
|
});
|
|
182
|
+
var _resolve = require("./resolve.cjs");
|
|
183
|
+
Object.keys(_resolve).forEach(function (key) {
|
|
184
|
+
if (key === "default" || key === "__esModule") return;
|
|
185
|
+
if (key in exports && exports[key] === _resolve[key]) return;
|
|
186
|
+
Object.defineProperty(exports, key, {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return _resolve[key];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
160
193
|
var _semverFns = require("./semver-fns.cjs");
|
|
161
194
|
Object.keys(_semverFns).forEach(function (key) {
|
|
162
195
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export * from "./command-exists";
|
|
|
12
12
|
export * from "./compress";
|
|
13
13
|
export * from "./constants";
|
|
14
14
|
export * from "./copy-file";
|
|
15
|
+
export * from "./exists";
|
|
16
|
+
export * from "./get-workspace-root";
|
|
15
17
|
export * from "./helpers";
|
|
16
18
|
export * from "./install";
|
|
17
19
|
export * from "./json";
|
|
@@ -20,6 +22,7 @@ export * from "./package-fns";
|
|
|
20
22
|
export * from "./read-file";
|
|
21
23
|
export * from "./registry";
|
|
22
24
|
export * from "./remove-file";
|
|
25
|
+
export * from "./resolve";
|
|
23
26
|
export * from "./semver-fns";
|
|
24
27
|
export * from "./toml";
|
|
25
28
|
export * from "./tsconfig";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./buffer";export*from"./chmod-x";export*from"./command-exists";export*from"./compress";export*from"./constants";export*from"./copy-file";export*from"./helpers";export*from"./install";export*from"./json";export*from"./list-files";export*from"./package-fns";export*from"./read-file";export*from"./registry";export*from"./remove-file";export*from"./semver-fns";export*from"./toml";export*from"./tsconfig";export*from"./write-file";export*from"./yaml";
|
|
1
|
+
export*from"./buffer";export*from"./chmod-x";export*from"./command-exists";export*from"./compress";export*from"./constants";export*from"./copy-file";export*from"./exists";export*from"./get-workspace-root";export*from"./helpers";export*from"./install";export*from"./json";export*from"./list-files";export*from"./package-fns";export*from"./read-file";export*from"./registry";export*from"./remove-file";export*from"./resolve";export*from"./semver-fns";export*from"./toml";export*from"./tsconfig";export*from"./write-file";export*from"./yaml";
|
package/dist/install.cjs
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.install = install;
|
|
7
7
|
exports.packageExists = void 0;
|
|
8
8
|
var _installPkg = require("@antfu/install-pkg");
|
|
9
|
-
var _resolve = require("@stryke/path/resolve");
|
|
10
9
|
require("tinyexec");
|
|
10
|
+
var _resolve = require("./resolve.cjs");
|
|
11
11
|
async function install(t, a) {
|
|
12
12
|
return (0, _installPkg.installPackage)(t, a);
|
|
13
13
|
}
|
package/dist/install.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{installPackage as e}from"@antfu/install-pkg";import{resolve as n}from"
|
|
1
|
+
import{installPackage as e}from"@antfu/install-pkg";import"tinyexec";import{resolve as n}from"./resolve";export async function install(t,a){return e(t,a)}export const packageExists=async(t,a)=>{const s=await n(a?.cwd||process.cwd());try{await n(t,{paths:[s]})}catch{await install(t,a)}};
|
package/dist/package-fns.cjs
CHANGED
|
@@ -10,19 +10,21 @@ exports.getPackageManager = getPackageManager;
|
|
|
10
10
|
exports.isPackageExists = isPackageExists;
|
|
11
11
|
exports.isPackageListed = isPackageListed;
|
|
12
12
|
exports.loadPackageJson = loadPackageJson;
|
|
13
|
-
var
|
|
13
|
+
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
14
14
|
var _getParentPath = require("@stryke/path/get-parent-path");
|
|
15
|
-
var
|
|
16
|
-
var _resolve = require("@stryke/path/resolve");
|
|
15
|
+
var _joinPaths = require("@stryke/path/join-paths");
|
|
17
16
|
var _package = require("@stryke/string-format/package");
|
|
18
17
|
var _isString = require("@stryke/type-checks/is-string");
|
|
19
18
|
var _nodeFs = require("node:fs");
|
|
20
19
|
var _semver = require("semver");
|
|
20
|
+
var _exists = require("./exists.cjs");
|
|
21
|
+
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
21
22
|
var _json = require("./json.cjs");
|
|
23
|
+
var _resolve = require("./resolve.cjs");
|
|
22
24
|
function getPackageManager(t = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
23
25
|
const e = (0, _getParentPath.getParentPath)(["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock"], t);
|
|
24
26
|
if (!e) return "pnpm";
|
|
25
|
-
switch ((0,
|
|
27
|
+
switch ((0, _filePathFns.findFileName)(e)) {
|
|
26
28
|
case "yarn.lock":
|
|
27
29
|
return "yarn";
|
|
28
30
|
case "pnpm-lock.yaml":
|
|
@@ -37,9 +39,9 @@ async function v(t) {
|
|
|
37
39
|
let e;
|
|
38
40
|
for (;;) {
|
|
39
41
|
if (!t) return;
|
|
40
|
-
const n = (0,
|
|
42
|
+
const n = (0, _filePathFns.findFilePath)(t);
|
|
41
43
|
if (n === t) return;
|
|
42
|
-
if (t = n, e = (0,
|
|
44
|
+
if (t = n, e = (0, _joinPaths.joinPaths)(t, "package.json"), await (0, _exists.exists)(e)) break;
|
|
43
45
|
}
|
|
44
46
|
return e;
|
|
45
47
|
}
|
|
@@ -54,7 +56,7 @@ async function getPackageInfo(t, e = {}) {
|
|
|
54
56
|
return {
|
|
55
57
|
name: t,
|
|
56
58
|
version: s.version,
|
|
57
|
-
rootPath: (0,
|
|
59
|
+
rootPath: (0, _filePathFns.findFilePath)(n),
|
|
58
60
|
packageJsonPath: n,
|
|
59
61
|
packageJson: s
|
|
60
62
|
};
|
package/dist/package-fns.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PackageResolvingOptions } from "@stryke/path/resolve";
|
|
2
1
|
import type { PackageJson } from "@stryke/types/package-json";
|
|
3
2
|
import type { PackageManager } from "@stryke/types/package-manager";
|
|
4
3
|
import type { Range } from "semver";
|
|
4
|
+
import type { PackageResolvingOptions } from "./resolve";
|
|
5
5
|
/**
|
|
6
6
|
* Get the package manager used in the project
|
|
7
7
|
* @param dir - The path to the project
|
package/dist/package-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{findFileName as m,findFilePath as r}from"@stryke/path/file-path-fns";import{getParentPath as c}from"@stryke/path/get-parent-path";import{joinPaths as u}from"@stryke/path/join-paths";import{getPackageName as p}from"@stryke/string-format/package";import{isString as g}from"@stryke/type-checks/is-string";import{existsSync as P}from"node:fs";import{subset as l}from"semver";import{exists as y}from"./exists";import{getWorkspaceRoot as d}from"./get-workspace-root";import{readJsonFile as k}from"./json";import{resolvePackage as f}from"./resolve";export function getPackageManager(t=d()){const e=c(["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock"],t);if(!e)return"pnpm";switch(m(e)){case"yarn.lock":return"yarn";case"pnpm-lock.yaml":return"pnpm";case"bun.lock":return"bun";default:return"npm"}}async function v(t){let e;for(;;){if(!t)return;const n=r(t);if(n===t)return;if(t=n,e=u(t,"package.json"),await y(e))break}return e}async function x(t,e={}){const n=await f(t,e);if(n)return v(n)}export async function getPackageInfo(t,e={}){const n=await x(t,e);if(!n)return;const s=await k(n);return{name:t,version:s.version,rootPath:r(n),packageJsonPath:n,packageJson:s}}export async function loadPackageJson(t=d()){const e=c("package.json",t,{skipCwd:!1});return!e||!P(e)?null:k(e)}export async function isPackageListed(t,e){const n=p(t),s=g(e)?e:e?.cwd,a=await loadPackageJson(s);return a?!!(a.dependencies&&n in a.dependencies&&a.dependencies[n]||a.devDependencies&&n in a.devDependencies&&a.devDependencies[n]):!1}export async function getPackageListing(t,e){const n=p(t),s=g(e)?e:e?.cwd,a=await loadPackageJson(s);if(!a)return;const i=a.dependencies&&n in a.dependencies?a.dependencies[n]:a.devDependencies&&n in a.devDependencies?a.devDependencies[n]:void 0,o=(a.dependencies&&n in a.dependencies?"dependencies":a.devDependencies&&n in a.devDependencies?"devDependencies":void 0)||void 0;return i&&o?{version:i,type:o}:void 0}export async function doesPackageMatch(t,e,n){const s=await getPackageListing(t,{cwd:n});return s?s.version.startsWith("catalog:")||s.version.startsWith("workspace:")||l(s.version,e):!1}export function isPackageExists(t,e={}){return!!f(t,e)}
|
package/dist/registry.cjs
CHANGED
|
@@ -9,9 +9,9 @@ exports.getParsedNodeOptionsWithoutInspect = getParsedNodeOptionsWithoutInspect;
|
|
|
9
9
|
exports.getRegistry = getRegistry;
|
|
10
10
|
exports.tokenizeArgs = void 0;
|
|
11
11
|
var _installPkg = require("@antfu/install-pkg");
|
|
12
|
-
var _getWorkspaceRoot = require("@stryke/path/get-workspace-root");
|
|
13
12
|
var _nodeChild_process = require("node:child_process");
|
|
14
13
|
var _nodeUtil = require("node:util");
|
|
14
|
+
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
15
15
|
const l = r => {
|
|
16
16
|
const {
|
|
17
17
|
values: e,
|
package/dist/registry.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{detectPackageManager as s}from"@antfu/install-pkg";import{
|
|
1
|
+
import{detectPackageManager as s}from"@antfu/install-pkg";import{execSync as a}from"node:child_process";import{parseArgs as c}from"node:util";import{getWorkspaceRoot as g}from"./get-workspace-root";const l=r=>{const{values:e,tokens:n}=c({args:r,strict:!1,tokens:!0});let o=null;for(let i=0;i<n.length;i++){const t=n[i];if(t.kind==="option-terminator")break;if(t.kind==="option"){o=typeof t.value>"u"?t:null;continue}if(t.kind!=="positional"){o=null;continue}o&&(o.name in e&&typeof e[o.name]=="string"?e[o.name]+=` ${t.value}`:e[o.name]=t.value)}return e};export const tokenizeArgs=r=>{const e=[];let n=!1,o=!0;for(let i=0;i<r.length;i++){let t=r[i];if(t==="\\"&&n){if(r.length===i+1)throw new Error("Invalid escape character at the end.");t=r[++i]}else if(t===" "&&!n){o=!0;continue}else if(t==='"'){n=!n;continue}o?(e.push(t),o=!1):e[e.length-1]+=t}if(n)throw new Error("Unterminated string");return e};const f=()=>process.env.NODE_OPTIONS?tokenizeArgs(process.env.NODE_OPTIONS):[];export function formatNodeOptions(r){return Object.entries(r).map(([e,n])=>n===!0?`--${e}`:n?`--${e}=${n.includes(" ")&&!n.startsWith('"')?JSON.stringify(n):n}`:null).filter(e=>e!==null).join(" ")}export function getParsedNodeOptionsWithoutInspect(){const r=f();if(r.length===0)return{};const e=l(r);return delete e.inspect,delete e["inspect-brk"],delete e.inspect_brk,e}export function getFormattedNodeOptionsWithoutInspect(){const r=getParsedNodeOptionsWithoutInspect();return Object.keys(r).length===0?"":formatNodeOptions(r)}export async function getRegistry(r){const e=g(r),n=await s(e),o=n==="npm"?"--no-workspaces":"";let i="https://registry.npmjs.org/";try{const t=a(`${n} config get registry ${o}`,{env:{...process.env,NODE_OPTIONS:getFormattedNodeOptionsWithoutInspect()}}).toString().trim();t.startsWith("http")&&(i=t.endsWith("/")?t:`${t}/`)}catch(t){throw new Error(`Failed to get registry from "${n}".`,{cause:t})}return i}
|
package/dist/resolve.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.importModule = importModule;
|
|
7
|
+
exports.resolve = resolve;
|
|
8
|
+
exports.resolvePackage = resolvePackage;
|
|
9
|
+
exports.resolvePackageSync = resolvePackageSync;
|
|
10
|
+
exports.resolveSafe = resolveSafe;
|
|
11
|
+
exports.resolveSafeSync = resolveSafeSync;
|
|
12
|
+
exports.resolveSync = resolveSync;
|
|
13
|
+
var _correctPath = require("@stryke/path/correct-path");
|
|
14
|
+
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
15
|
+
var _joinPaths = require("@stryke/path/join-paths");
|
|
16
|
+
var _mlly = require("mlly");
|
|
17
|
+
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
18
|
+
async function resolve(r, e = {}) {
|
|
19
|
+
const t = e.paths ?? [];
|
|
20
|
+
t.length === 0 && t.push(process.cwd());
|
|
21
|
+
const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
|
|
22
|
+
return t.includes(n) || t.push(n), (0, _correctPath.correctPath)(await (0, _mlly.resolvePath)(r, {
|
|
23
|
+
url: t
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function resolveSync(r, e = {}) {
|
|
27
|
+
const t = e.paths ?? [];
|
|
28
|
+
t.length === 0 && t.push(process.cwd());
|
|
29
|
+
const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
|
|
30
|
+
return t.includes(n) || t.push(n), (0, _correctPath.correctPath)((0, _mlly.resolvePathSync)(r, {
|
|
31
|
+
url: e.paths
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
async function resolveSafe(r, e = {}) {
|
|
35
|
+
try {
|
|
36
|
+
return await resolve(r, e);
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveSafeSync(r, e = {}) {
|
|
42
|
+
try {
|
|
43
|
+
return resolveSync(r, e);
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function importModule(r) {
|
|
49
|
+
const e = await Promise.resolve(`${r}`).then(s => require(s));
|
|
50
|
+
return e && (0, _mlly.interopDefault)(e);
|
|
51
|
+
}
|
|
52
|
+
async function resolvePackage(r, e = {}) {
|
|
53
|
+
let t = await resolveSafe((0, _joinPaths.joinPaths)(r, "package.json"), e);
|
|
54
|
+
return t || (t = await resolveSafe((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = await resolveSafe(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
|
|
55
|
+
}
|
|
56
|
+
function resolvePackageSync(r, e = {}) {
|
|
57
|
+
let t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "package.json"), e);
|
|
58
|
+
return t || (t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = resolveSafeSync(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
|
|
59
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Platform } from "@stryke/types/system";
|
|
2
|
+
export interface PackageResolvingOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Paths to resolve the package from
|
|
5
|
+
*/
|
|
6
|
+
paths?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Resolve path as linux (stand-in for unix/posix) or win32
|
|
9
|
+
*/
|
|
10
|
+
platform?: Platform;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the path to a specified module
|
|
14
|
+
*
|
|
15
|
+
* @param path - The path to the module
|
|
16
|
+
* @param options - The options to use when resolving the module
|
|
17
|
+
* @returns A promise for the path to the module
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolve(path: string, options?: PackageResolvingOptions): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the path to a specified module
|
|
22
|
+
*
|
|
23
|
+
* @param path - The path to the module
|
|
24
|
+
* @param options - The options to use when resolving the module
|
|
25
|
+
* @returns The path to the module or undefined
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveSync(path: string, options?: PackageResolvingOptions): any;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the path to a specified module with error handling
|
|
30
|
+
*
|
|
31
|
+
* @param name - The name of the module
|
|
32
|
+
* @param options - The options to use when resolving the module
|
|
33
|
+
* @returns A promise for the path to the module
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveSafe(name: string, options?: PackageResolvingOptions): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the path to a specified module with error handling
|
|
38
|
+
*
|
|
39
|
+
* @param name - The name of the module
|
|
40
|
+
* @param options - The options to use when resolving the module
|
|
41
|
+
* @returns The path to the module or undefined
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveSafeSync(name: string, options?: PackageResolvingOptions): any;
|
|
44
|
+
/**
|
|
45
|
+
* Import a module from a specified path
|
|
46
|
+
*
|
|
47
|
+
* @param path - The path to the module
|
|
48
|
+
* @returns The module
|
|
49
|
+
*/
|
|
50
|
+
export declare function importModule<T = any>(path: string): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the path to a specified package asynchronously
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
|
|
56
|
+
*
|
|
57
|
+
* @param name - The name of the module
|
|
58
|
+
* @returns A promise for the module or undefined
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolvePackage(name: string, options?: PackageResolvingOptions): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the path to a specified package synchronously
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The name of the module
|
|
68
|
+
* @param options - The options to use when resolving the module
|
|
69
|
+
* @returns The module or undefined
|
|
70
|
+
*/
|
|
71
|
+
export declare function resolvePackageSync(name: string, options?: PackageResolvingOptions): any;
|
package/dist/resolve.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{correctPath as s}from"@stryke/path/correct-path";import{findFilePath as i}from"@stryke/path/file-path-fns";import{joinPaths as o}from"@stryke/path/join-paths";import{interopDefault as c,resolvePath as p,resolvePathSync as f}from"mlly";import{getWorkspaceRoot as a}from"./get-workspace-root";export async function resolve(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(await p(r,{url:t}))}export function resolveSync(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(f(r,{url:e.paths}))}export async function resolveSafe(r,e={}){try{return await resolve(r,e)}catch{return}}export function resolveSafeSync(r,e={}){try{return resolveSync(r,e)}catch{return}}export async function importModule(r){const e=await import(r);return e&&c(e)}export async function resolvePackage(r,e={}){let t=await resolveSafe(o(r,"package.json"),e);return t||(t=await resolveSafe(o(r,"index.js"),e),t||(t=await resolveSafe(r,e))),t?i(t):void 0}export function resolvePackageSync(r,e={}){let t=resolveSafeSync(o(r,"package.json"),e);return t||(t=resolveSafeSync(o(r,"index.js"),e),t||(t=resolveSafeSync(r,e))),t?i(t):void 0}
|
package/dist/tsconfig.cjs
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.loadTsConfig = loadTsConfig;
|
|
7
|
-
var _exists = require("@stryke/path/exists");
|
|
8
7
|
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
9
8
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
10
9
|
var _defu = _interopRequireDefault(require("defu"));
|
|
11
10
|
var _mlly = require("mlly");
|
|
11
|
+
var _exists = require("./exists.cjs");
|
|
12
12
|
var _json = require("./json.cjs");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
async function loadTsConfig(e = process.cwd()) {
|
package/dist/tsconfig.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{findFilePath as i}from"@stryke/path/file-path-fns";import{joinPaths as t}from"@stryke/path/join-paths";import a from"defu";import{resolvePath as p}from"mlly";import{existsSync as r}from"./exists";import{readJsonFile as c}from"./json";export async function loadTsConfig(e=process.cwd()){let s=e.endsWith(".json")?e:t(e,"tsconfig.json");if(!r(s)&&(s=await p(e,{url:import.meta.url}),!r(s)))throw new Error(`tsconfig.json not found at ${s}. Please ensure the file exists.`);let o=await c(s);if(o?.compilerOptions?.baseUrl&&(o.compilerOptions.baseUrl=t(i(s),o.compilerOptions.baseUrl)),o?.extends){const f=Array.isArray(o.extends)?o.extends:[o.extends];for(const m of f){const n=await loadTsConfig(t(i(s),m));n&&(o=a(o,n??{}))}}return o.extends=void 0,o}
|
package/dist/write-file.cjs
CHANGED
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.writeFileSync = exports.writeFile = void 0;
|
|
7
7
|
var _correctPath = require("@stryke/path/correct-path");
|
|
8
|
-
var _exists = require("@stryke/path/exists");
|
|
9
8
|
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
10
9
|
var _nodeFs = require("node:fs");
|
|
11
10
|
var _promises = require("node:fs/promises");
|
|
11
|
+
var _exists = require("./exists.cjs");
|
|
12
12
|
var _helpers = require("./helpers.cjs");
|
|
13
13
|
const writeFileSync = (e, t = "", o = {}) => {
|
|
14
14
|
if (!e) throw new Error("No file path provided to write data");
|
package/dist/write-file.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{correctPath as i}from"@stryke/path/correct-path";import{
|
|
1
|
+
import{correctPath as i}from"@stryke/path/correct-path";import{findFilePath as n}from"@stryke/path/file-path-fns";import{writeFileSync as s}from"node:fs";import{writeFile as d}from"node:fs/promises";import{existsSync as c}from"./exists";import{createDirectory as p,createDirectorySync as a}from"./helpers";export const writeFileSync=(e,t="",o={})=>{if(!e)throw new Error("No file path provided to write data");const r=n(i(e));if(!c(r))if(o.createDirectory!==!1)a(r);else throw new Error(`Directory ${r} does not exist`);s(e,t||"",o)},writeFile=async(e,t="",o={})=>{if(!e)throw new Error("No file path provided to read data");const r=n(i(e));if(!c(r))if(o.createDirectory!==!1)await p(r);else throw new Error(`Directory ${r} does not exist`);return d(e,t||"",o)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@antfu/install-pkg": "^1.0.0",
|
|
16
16
|
"@ltd/j-toml": "^1.38.0",
|
|
17
|
+
"@storm-software/config-tools": "latest",
|
|
17
18
|
"@stryke/convert": "^0.3.1",
|
|
18
|
-
"@stryke/path": "^0.
|
|
19
|
+
"@stryke/path": "^0.13.0",
|
|
19
20
|
"@stryke/string-format": "^0.10.0",
|
|
20
21
|
"@zkochan/js-yaml": "^0.0.7",
|
|
21
22
|
"chalk": "^5.4.1",
|
|
@@ -130,6 +131,20 @@
|
|
|
130
131
|
"default": "./dist/semver-fns.mjs"
|
|
131
132
|
}
|
|
132
133
|
},
|
|
134
|
+
"./resolve": {
|
|
135
|
+
"import": {
|
|
136
|
+
"types": "./dist/resolve.d.ts",
|
|
137
|
+
"default": "./dist/resolve.mjs"
|
|
138
|
+
},
|
|
139
|
+
"require": {
|
|
140
|
+
"types": "./dist/resolve.d.ts",
|
|
141
|
+
"default": "./dist/resolve.cjs"
|
|
142
|
+
},
|
|
143
|
+
"default": {
|
|
144
|
+
"types": "./dist/resolve.d.ts",
|
|
145
|
+
"default": "./dist/resolve.mjs"
|
|
146
|
+
}
|
|
147
|
+
},
|
|
133
148
|
"./remove-file": {
|
|
134
149
|
"import": {
|
|
135
150
|
"types": "./dist/remove-file.d.ts",
|
|
@@ -241,6 +256,34 @@
|
|
|
241
256
|
"default": "./dist/helpers.mjs"
|
|
242
257
|
}
|
|
243
258
|
},
|
|
259
|
+
"./get-workspace-root": {
|
|
260
|
+
"import": {
|
|
261
|
+
"types": "./dist/get-workspace-root.d.ts",
|
|
262
|
+
"default": "./dist/get-workspace-root.mjs"
|
|
263
|
+
},
|
|
264
|
+
"require": {
|
|
265
|
+
"types": "./dist/get-workspace-root.d.ts",
|
|
266
|
+
"default": "./dist/get-workspace-root.cjs"
|
|
267
|
+
},
|
|
268
|
+
"default": {
|
|
269
|
+
"types": "./dist/get-workspace-root.d.ts",
|
|
270
|
+
"default": "./dist/get-workspace-root.mjs"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
"./exists": {
|
|
274
|
+
"import": {
|
|
275
|
+
"types": "./dist/exists.d.ts",
|
|
276
|
+
"default": "./dist/exists.mjs"
|
|
277
|
+
},
|
|
278
|
+
"require": {
|
|
279
|
+
"types": "./dist/exists.d.ts",
|
|
280
|
+
"default": "./dist/exists.cjs"
|
|
281
|
+
},
|
|
282
|
+
"default": {
|
|
283
|
+
"types": "./dist/exists.d.ts",
|
|
284
|
+
"default": "./dist/exists.mjs"
|
|
285
|
+
}
|
|
286
|
+
},
|
|
244
287
|
"./copy-file": {
|
|
245
288
|
"import": {
|
|
246
289
|
"types": "./dist/copy-file.d.ts",
|
|
@@ -338,5 +381,5 @@
|
|
|
338
381
|
"main": "./dist/index.cjs",
|
|
339
382
|
"module": "./dist/index.mjs",
|
|
340
383
|
"types": "./dist/index.d.ts",
|
|
341
|
-
"gitHead": "
|
|
384
|
+
"gitHead": "dc317cbe47e06f3b3f7887b9176087c3de488853"
|
|
342
385
|
}
|