@platform/fs
Advanced tools
Comparing version 0.7.5 to 0.7.6
@@ -11,3 +11,3 @@ "use strict"; | ||
var _this = this; | ||
dir = path_1.resolve(dir); | ||
dir = (0, path_1.resolve)(dir); | ||
var walk = function (fn, path, state) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
@@ -37,3 +37,3 @@ var args, _a, parent_1; | ||
if (!(_b.sent())) { | ||
throw new Error("Path does not exist: \"" + path + "\"."); | ||
throw new Error("Path does not exist: \"".concat(path, "\".")); | ||
} | ||
@@ -48,3 +48,3 @@ _a = args.levels === 0; | ||
if (_a) { | ||
path = path_1.dirname(path); | ||
path = (0, path_1.dirname)(path); | ||
args.dir = path; | ||
@@ -57,3 +57,3 @@ } | ||
args.levels++; | ||
parent_1 = path_1.dirname(path); | ||
parent_1 = (0, path_1.dirname)(path); | ||
return [4, walk(fn, parent_1, args)]; | ||
@@ -85,6 +85,6 @@ case 5: | ||
if (!common_1.fs.pathExistsSync(path)) { | ||
throw new Error("Path does not exist: \"" + path + "\"."); | ||
throw new Error("Path does not exist: \"".concat(path, "\".")); | ||
} | ||
if (args.levels === 0 && is_1.is.fileSync(path)) { | ||
path = path_1.dirname(path); | ||
path = (0, path_1.dirname)(path); | ||
args.dir = path; | ||
@@ -98,3 +98,3 @@ } | ||
args.levels++; | ||
var parent_2 = path_1.dirname(path); | ||
var parent_2 = (0, path_1.dirname)(path); | ||
args = walkSync(fn, parent_2, args); | ||
@@ -114,3 +114,3 @@ } | ||
max = options.max; | ||
matcher = match_1.match(name); | ||
matcher = (0, match_1.match)(name); | ||
isMatch = function (input) { return matcher.base(input); }; | ||
@@ -130,3 +130,3 @@ return [4, api.walk(function (e) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
if (!name) return [3, 3]; | ||
path = path_1.join(e.dir, name); | ||
path = (0, path_1.join)(e.dir, name); | ||
return [4, is_1.is.type(path, options.type)]; | ||
@@ -154,3 +154,3 @@ case 2: | ||
var max = options.max; | ||
var matcher = match_1.match(name); | ||
var matcher = (0, match_1.match)(name); | ||
var isMatch = function (input) { return matcher.base(input); }; | ||
@@ -164,3 +164,3 @@ api.walkSync(function (e) { | ||
if (name) { | ||
var path = path_1.join(e.dir, name); | ||
var path = (0, path_1.join)(e.dir, name); | ||
if (is_1.is.typeSync(path, options.type)) { | ||
@@ -167,0 +167,0 @@ res = path; |
@@ -9,4 +9,4 @@ "use strict"; | ||
function stringify(input) { | ||
return JSON.stringify(input, null, ' ') + "\n"; | ||
return "".concat(JSON.stringify(input, null, ' '), "\n"); | ||
} | ||
exports.stringify = stringify; |
@@ -22,4 +22,4 @@ "use strict"; | ||
} | ||
dir = options.dir === undefined ? path_1.resolve('.') : path_1.resolve(options.dir); | ||
key = dir + ":" + (options.file || '') + ":" + (options.ancestor || false); | ||
dir = options.dir === undefined ? (0, path_1.resolve)('.') : (0, path_1.resolve)(options.dir); | ||
key = "".concat(dir, ":").concat(options.file || '', ":").concat(options.ancestor || false); | ||
if (IS_LOADED[key]) { | ||
@@ -30,7 +30,7 @@ return [2]; | ||
max = typeof options.ancestor === 'number' ? options.ancestor : undefined; | ||
path = ancestor_1.ancestor(dir).firstSync(file, { type: 'FILE', max: max }); | ||
path = (0, ancestor_1.ancestor)(dir).firstSync(file, { type: 'FILE', max: max }); | ||
path = path ? path : undefined; | ||
} | ||
else { | ||
path = path_1.join(dir, file); | ||
path = (0, path_1.join)(dir, file); | ||
} | ||
@@ -47,4 +47,4 @@ dotenv.config({ path: path, debug: debug }); | ||
var done = function (value) { | ||
if (options.throw && !Boolean(value)) { | ||
throw new Error("The process.env[\"" + key + "\"] variable does not exist."); | ||
if (options.throw && !value) { | ||
throw new Error("The process.env[\"".concat(key, "\"] variable does not exist.")); | ||
} | ||
@@ -51,0 +51,0 @@ return value; |
@@ -14,3 +14,3 @@ "use strict"; | ||
case 0: | ||
path = path_1.resolve(path); | ||
path = (0, path_1.resolve)(path); | ||
return [4, common_1.fs.pathExists(path)]; | ||
@@ -37,3 +37,3 @@ case 1: | ||
function loadAndParseSync(path, defaultValue) { | ||
path = path_1.resolve(path); | ||
path = (0, path_1.resolve)(path); | ||
if (!common_1.fs.pathExistsSync(path)) { | ||
@@ -59,3 +59,3 @@ return defaultValue; | ||
text = stringify(path, data); | ||
path = path_1.resolve(path); | ||
path = (0, path_1.resolve)(path); | ||
if (!beforeSave) return [3, 2]; | ||
@@ -67,3 +67,3 @@ return [4, beforeSave({ path: path, text: text })]; | ||
_a.label = 2; | ||
case 2: return [4, common_1.fs.ensureDir(path_1.dirname(path))]; | ||
case 2: return [4, common_1.fs.ensureDir((0, path_1.dirname)(path))]; | ||
case 3: | ||
@@ -84,3 +84,3 @@ _a.sent(); | ||
var text = stringify(path, data); | ||
path = path_1.resolve(path); | ||
path = (0, path_1.resolve)(path); | ||
if (beforeSave) { | ||
@@ -90,3 +90,3 @@ var res = beforeSave({ path: path, text: text }); | ||
} | ||
common_1.fs.ensureDirSync(path_1.dirname(path)); | ||
common_1.fs.ensureDirSync((0, path_1.dirname)(path)); | ||
common_1.fs.writeFileSync(path, text); | ||
@@ -106,7 +106,7 @@ return text; | ||
default: | ||
throw new Error("The path '" + path + "' is not a supported file type for parsing. Supported types: " + SUPPORTED); | ||
throw new Error("The path '".concat(path, "' is not a supported file type for parsing. Supported types: ").concat(SUPPORTED)); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error("Failed while parsing file '" + path + "'. " + error.message); | ||
throw new Error("Failed while parsing file '".concat(path, "'. ").concat(error.message)); | ||
} | ||
@@ -117,19 +117,18 @@ } | ||
try { | ||
switch (ext) { | ||
case 'json': | ||
var json = JSON.stringify(data, null, ' '); | ||
return json + "\n"; | ||
case 'yml': | ||
case 'yaml': | ||
return common_1.yaml.dump(data); | ||
default: | ||
throw new Error("The path '" + path + "' is not a supported file type to stringify. Supported types: " + SUPPORTED); | ||
if (ext === 'json') { | ||
var json = JSON.stringify(data, null, ' '); | ||
return "".concat(json, "\n"); | ||
} | ||
if (ext === 'yml' || ext === 'yaml') { | ||
return common_1.yaml.dump(data); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error("Failed while parsing file '" + path + "'. " + error.message); | ||
throw new Error("Failed while parsing file '".concat(path, "'. ").concat(error.message)); | ||
} | ||
var err = "The path '".concat(path, "' is not a supported file type to stringify. Supported types: ").concat(SUPPORTED); | ||
throw new Error(err); | ||
} | ||
function extension(path) { | ||
return path_1.extname(path).replace(/^\./, ''); | ||
return (0, path_1.extname)(path).replace(/^\./, ''); | ||
} |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as path from 'path'; | ||
@@ -44,3 +46,3 @@ import { t } from './common'; | ||
lstat: typeof lstat; | ||
lstatSync: import("fs").StatSyncFn<import("fs").PathLike>; | ||
lstatSync: import("fs").StatSyncFn; | ||
path: path.PlatformPath; | ||
@@ -47,0 +49,0 @@ join: (...paths: string[]) => string; |
@@ -19,7 +19,7 @@ "use strict"; | ||
var join = path.join, resolve = path.resolve, dirname = path.dirname, basename = path.basename, extname = path.extname; | ||
var exists = function (path) { return fs_extra_1.pathExists(path); }; | ||
var exists = function (path) { return (0, fs_extra_1.pathExists)(path); }; | ||
var writeFile = function (path, data) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, fs_extra_1.ensureDir(dirname(path))]; | ||
case 0: return [4, (0, fs_extra_1.ensureDir)(dirname(path))]; | ||
case 1: | ||
@@ -32,3 +32,3 @@ _a.sent(); | ||
return [3, 5]; | ||
case 3: return [4, fs_extra_1.writeFile(path, data)]; | ||
case 3: return [4, (0, fs_extra_1.writeFile)(path, data)]; | ||
case 4: | ||
@@ -35,0 +35,0 @@ _a.sent(); |
@@ -20,4 +20,4 @@ export declare type GlobFindFilter = (path: string) => boolean; | ||
export declare const Glob: { | ||
find(pattern: string, input?: GlobFindFilter | GlobFindOptions | undefined): Promise<string[]>; | ||
remove(pattern: string, options?: GlobFindFilter | GlobFindOptions | undefined): Promise<string[]>; | ||
find(pattern: string, input?: GlobFindOptions | GlobFindFilter): Promise<string[]>; | ||
remove(pattern: string, options?: GlobFindOptions | GlobFindFilter): Promise<string[]>; | ||
}; |
@@ -42,3 +42,3 @@ "use strict"; | ||
paths = _a.sent(); | ||
return [4, Promise.all(paths.map(function (path) { return fs_extra_1.remove(path); }))]; | ||
return [4, Promise.all(paths.map(function (path) { return (0, fs_extra_1.remove)(path); }))]; | ||
case 2: | ||
@@ -45,0 +45,0 @@ _a.sent(); |
@@ -139,3 +139,3 @@ "use strict"; | ||
result = false; | ||
return [4, ancestor_1.ancestor(path_1.dirname(path)).walk(function (visitor) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return [4, (0, ancestor_1.ancestor)((0, path_1.dirname)(path)).walk(function (visitor) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -142,0 +142,0 @@ switch (_a.label) { |
@@ -20,5 +20,5 @@ "use strict"; | ||
if (!(_c.sent())) { | ||
throw new Error("Target path is not a directory: " + targetDir); | ||
throw new Error("Target path is not a directory: ".concat(targetDir)); | ||
} | ||
return [4, glob_1.Glob.find(common_1.join(targetDir, '**'))]; | ||
return [4, glob_1.Glob.find((0, common_1.join)(targetDir, '**'))]; | ||
case 2: | ||
@@ -35,3 +35,3 @@ targets = _c.sent(); | ||
if (!(_c.sent())) { | ||
throw new Error("Source path is not a directory: " + dir); | ||
throw new Error("Source path is not a directory: ".concat(dir)); | ||
} | ||
@@ -45,3 +45,3 @@ _c.label = 5; | ||
sourceDir: sourceDir, | ||
pattern: common_1.join(sourceDir, pattern), | ||
pattern: (0, common_1.join)(sourceDir, pattern), | ||
}); }); | ||
@@ -60,3 +60,3 @@ return [4, Promise.all(patterns.map(function (_a) { | ||
from: from, | ||
to: common_1.join(targetDir, from.substr(sourceDir.length + 1)), | ||
to: (0, common_1.join)(targetDir, from.substr(sourceDir.length + 1)), | ||
}; | ||
@@ -81,6 +81,6 @@ }); | ||
if (exists && !overwrite) { | ||
skipped = tslib_1.__spreadArray(tslib_1.__spreadArray([], skipped), [from]); | ||
skipped = tslib_1.__spreadArray(tslib_1.__spreadArray([], skipped, true), [from], false); | ||
} | ||
if (overwrite || !exists) { | ||
copy = tslib_1.__spreadArray(tslib_1.__spreadArray([], copy), [{ from: from, to: to }]); | ||
copy = tslib_1.__spreadArray(tslib_1.__spreadArray([], copy, true), [{ from: from, to: to }], false); | ||
} | ||
@@ -87,0 +87,0 @@ }); |
@@ -15,3 +15,3 @@ /// <reference types="node" /> | ||
export declare const size: { | ||
toString(input: number | Buffer, options?: IFileSizeStringOptions | undefined): string; | ||
toString(input: number | Buffer, options?: IFileSizeStringOptions): string; | ||
file(path: string): Promise<IFileSize>; | ||
@@ -22,4 +22,4 @@ dir(path: string): Promise<{ | ||
files: IFileSize[]; | ||
toString(options?: IFileSizeStringOptions | undefined): string; | ||
toString(options?: IFileSizeStringOptions): string; | ||
}>; | ||
}; |
@@ -47,3 +47,3 @@ "use strict"; | ||
case 0: | ||
pattern = path_1.resolve(path_1.join(path), '**'); | ||
pattern = (0, path_1.resolve)((0, path_1.join)(path), '**'); | ||
return [4, glob_1.Glob.find(pattern)]; | ||
@@ -50,0 +50,0 @@ case 1: |
import { t } from '../common'; | ||
export declare const Stream: { | ||
isReadableStream(input: any): boolean; | ||
encode(input?: string | undefined): Uint8Array; | ||
decode(input?: BufferSource | undefined, options?: TextDecodeOptions | undefined): string; | ||
encode(input?: string): Uint8Array; | ||
decode(input?: BufferSource, options?: TextDecodeOptions): string; | ||
toUint8Array(input: ReadableStream | t.Json | Uint8Array): Promise<Uint8Array>; | ||
save(path: string, data: ReadableStream | t.Json): Promise<void>; | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var common_1 = require("../common"); | ||
var pipe = util_1.promisify(stream_1.pipeline); | ||
var pipe = (0, util_1.promisify)(stream_1.pipeline); | ||
exports.Stream = { | ||
@@ -43,3 +43,3 @@ isReadableStream: function (input) { | ||
return [2, encode('null')]; | ||
return [2, encode(common_1.stringify(input))]; | ||
return [2, encode((0, common_1.stringify)(input))]; | ||
} | ||
@@ -78,11 +78,11 @@ chunks = []; | ||
throw new Error("No data"); | ||
return [4, fs_extra_1.ensureDir(path_1.dirname(path))]; | ||
return [4, (0, fs_extra_1.ensureDir)((0, path_1.dirname)(path))]; | ||
case 1: | ||
_a.sent(); | ||
if (!exports.Stream.isReadableStream(data)) return [3, 3]; | ||
return [4, pipe(data, fs_extra_1.createWriteStream(path))]; | ||
return [4, pipe(data, (0, fs_extra_1.createWriteStream)(path))]; | ||
case 2: | ||
_a.sent(); | ||
return [2]; | ||
case 3: return [4, fs_extra_1.writeFile(path, common_1.stringify(data))]; | ||
case 3: return [4, (0, fs_extra_1.writeFile)(path, (0, common_1.stringify)(data))]; | ||
case 4: | ||
@@ -93,3 +93,3 @@ _a.sent(); | ||
err_1 = _a.sent(); | ||
throw new Error("Failed to save stream to '" + path + "'. " + err_1.message); | ||
throw new Error("Failed to save stream to '".concat(path, "'. ").concat(err_1.message)); | ||
case 6: return [2]; | ||
@@ -96,0 +96,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
Zipper.prototype.add = function (source, target) { | ||
this.items = tslib_1.__spreadArray(tslib_1.__spreadArray([], this.items), [{ source: source, dest: target }]); | ||
this.items = tslib_1.__spreadArray(tslib_1.__spreadArray([], this.items, true), [{ source: source, dest: target }], false); | ||
return this; | ||
@@ -16,0 +16,0 @@ }; |
{ | ||
"name": "@platform/fs", | ||
"version": "0.7.5", | ||
"version": "0.7.6", | ||
"description": "POSIX style file-system tools.", | ||
@@ -28,4 +28,4 @@ "main": "lib/index", | ||
"devDependencies": { | ||
"@platform/test": "0.2.10", | ||
"@platform/ts.libs": "4.3.3", | ||
"@platform/test": "0.3.0", | ||
"@platform/ts.libs": "4.7.4", | ||
"@types/archiver": "5.1.1", | ||
@@ -32,0 +32,0 @@ "@types/dotenv": "8.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172960
86
3878
22