@ionic/utils-fs
Advanced tools
Comparing version 0.1.0-testing.e70f2d6e to 1.0.0
@@ -6,2 +6,75 @@ # Change Log | ||
<a name="1.0.0"></a> | ||
# [1.0.0](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.7...@ionic/utils-fs@1.0.0) (2019-01-08) | ||
### Bug Fixes | ||
* rimraf is a full dependency ([962ad94](https://github.com/ionic-team/ionic-cli/commit/962ad94)) | ||
### Features | ||
* switch to fs-extra ([c17d8d8](https://github.com/ionic-team/ionic-cli/commit/c17d8d8)) | ||
### BREAKING CHANGES | ||
* `readDir`, `readDirp`, `readDirSafe` were renamed to be | ||
consistent with fs and fs-extra. `readJsonFile` and `writeJsonFile` have | ||
been renamed to `readJson` and `writeJson` and use the fs-extra version | ||
directly. `isDir` was removed (use stat). `copyFile` and `copyDirectory` | ||
were removed (use `copy`). `removeDirectory` was removed (use `remove`). | ||
<a name="0.0.7"></a> | ||
## [0.0.7](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.6...@ionic/utils-fs@0.0.7) (2019-01-07) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.6"></a> | ||
## [0.0.6](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.5...@ionic/utils-fs@0.0.6) (2018-12-19) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.5"></a> | ||
## [0.0.5](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.4...@ionic/utils-fs@0.0.5) (2018-11-20) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.4"></a> | ||
## [0.0.4](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.3...@ionic/utils-fs@0.0.4) (2018-10-31) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.3"></a> | ||
## [0.0.3](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.2...@ionic/utils-fs@0.0.3) (2018-10-05) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.2"></a> | ||
## [0.0.2](https://github.com/ionic-team/ionic-cli/compare/@ionic/utils-fs@0.0.1...@ionic/utils-fs@0.0.2) (2018-10-03) | ||
**Note:** Version bump only for package @ionic/utils-fs | ||
<a name="0.0.1"></a> | ||
@@ -8,0 +81,0 @@ ## 0.0.1 (2018-09-05) |
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
import * as fs from 'fs-extra'; | ||
import * as stream from 'stream'; | ||
import * as ζncp from 'ncp'; | ||
export interface ReadFileOptions { | ||
encoding: string; | ||
flag?: string; | ||
} | ||
export interface WriteFileOptions { | ||
encoding: string; | ||
mode?: number; | ||
flag?: string; | ||
} | ||
export declare const access: (arg1: string, arg2: number) => Promise<void>; | ||
export declare const mkdir: (arg1: string, arg2: number) => Promise<void>; | ||
export declare const open: (arg1: string, arg2: string) => Promise<number>; | ||
export declare const stat: (arg1: string) => Promise<fs.Stats>; | ||
export declare const unlink: (arg1: string) => Promise<void>; | ||
export declare const readFile: (arg1: string, arg2: ReadFileOptions) => Promise<string>; | ||
export declare const writeFile: (arg1: string, arg2: any, arg3: WriteFileOptions) => Promise<void>; | ||
export declare const readDir: (arg1: string) => Promise<string[]>; | ||
export declare function statSafe(p: string): Promise<fs.Stats | undefined>; | ||
export interface ReadDirROptions { | ||
export * from 'fs-extra'; | ||
export { stat as statSafe, readdir as readdirSafe } from './safe'; | ||
export interface ReaddirPOptions { | ||
readonly filter?: (item: WalkerItem) => boolean; | ||
readonly walkerOptions?: WalkerOptions; | ||
} | ||
export declare function readDirp(dir: string, { filter, walkerOptions }?: ReadDirROptions): Promise<string[]>; | ||
export declare function readDirSafe(dir: string): Promise<string[]>; | ||
export declare function readJsonFile(filePath: string, options?: ReadFileOptions): Promise<{ | ||
[key: string]: any; | ||
}>; | ||
export declare function writeJsonFile(filePath: string, json: { | ||
[key: string]: any; | ||
}, options: WriteFileOptions): Promise<void>; | ||
export declare function readdirp(dir: string, { filter, walkerOptions }?: ReaddirPOptions): Promise<string[]>; | ||
export declare function fileToString(filePath: string): Promise<string>; | ||
export declare function mkdirp(p: string, mode?: number): Promise<void>; | ||
export declare function mkdirpSync(p: string, mode?: number): void; | ||
export declare function getFileChecksum(filePath: string): Promise<string>; | ||
@@ -57,5 +31,2 @@ /** | ||
export declare function writeStreamToFile(stream: NodeJS.ReadableStream, destination: string): Promise<any>; | ||
export declare function copyDirectory(source: string, destination: string, options?: ζncp.Options): Promise<void>; | ||
export declare function removeDirectory(dir: string): Promise<void>; | ||
export declare function copyFile(fileName: string, target: string, mode?: number): Promise<{}>; | ||
export declare function pathAccessible(filePath: string, mode: number): Promise<boolean>; | ||
@@ -82,3 +53,2 @@ export declare function pathExists(filePath: string): Promise<boolean>; | ||
export declare function compilePaths(filePath: string): string[]; | ||
export declare function isDir(p: string): Promise<boolean>; | ||
export interface WalkerItem { | ||
@@ -85,0 +55,0 @@ readonly path: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs = require("fs"); | ||
const fs = require("fs-extra"); | ||
const os = require("os"); | ||
@@ -9,35 +9,9 @@ const path = require("path"); | ||
const through2 = require("through2"); | ||
const promisify = (func) => { | ||
return (...args) => { | ||
return new Promise((resolve, reject) => { | ||
func(...args, (err, response) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(response); | ||
}); | ||
}); | ||
}; | ||
}; | ||
exports.access = promisify(fs.access); | ||
exports.mkdir = promisify(fs.mkdir); | ||
exports.open = promisify(fs.open); | ||
exports.stat = promisify(fs.stat); | ||
exports.unlink = promisify(fs.unlink); | ||
exports.readFile = promisify(fs.readFile); | ||
exports.writeFile = promisify(fs.writeFile); | ||
exports.readDir = promisify(fs.readdir); | ||
function statSafe(p) { | ||
const safe = require("./safe"); | ||
tslib_1.__exportStar(require("fs-extra"), exports); | ||
var safe_1 = require("./safe"); | ||
exports.statSafe = safe_1.stat; | ||
exports.readdirSafe = safe_1.readdir; | ||
function readdirp(dir, { filter, walkerOptions } = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield exports.stat(p); | ||
} | ||
catch (e) { | ||
// ignore | ||
} | ||
}); | ||
} | ||
exports.statSafe = statSafe; | ||
function readDirp(dir, { filter, walkerOptions } = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
@@ -61,31 +35,7 @@ const items = []; | ||
} | ||
exports.readDirp = readDirp; | ||
function readDirSafe(dir) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield exports.readDir(dir); | ||
} | ||
catch (e) { | ||
return []; | ||
} | ||
}); | ||
} | ||
exports.readDirSafe = readDirSafe; | ||
function readJsonFile(filePath, options = { encoding: 'utf8' }) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const f = yield exports.readFile(filePath, options); | ||
return JSON.parse(f); | ||
}); | ||
} | ||
exports.readJsonFile = readJsonFile; | ||
function writeJsonFile(filePath, json, options) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return exports.writeFile(filePath, JSON.stringify(json, undefined, 2) + '\n', options); | ||
}); | ||
} | ||
exports.writeJsonFile = writeJsonFile; | ||
exports.readdirp = readdirp; | ||
function fileToString(filePath) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield exports.readFile(filePath, { encoding: 'utf8' }); | ||
return yield fs.readFile(filePath, { encoding: 'utf8' }); | ||
} | ||
@@ -101,38 +51,2 @@ catch (e) { | ||
exports.fileToString = fileToString; | ||
function mkdirp(p, mode = 0o777) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const absPath = path.resolve(p); | ||
const pathObj = path.parse(absPath); | ||
const dirnames = absPath.split(path.sep).splice(1); | ||
const dirs = dirnames.map((v, i) => path.resolve(pathObj.root, ...dirnames.slice(0, i), v)); | ||
for (const dir of dirs) { | ||
try { | ||
yield exports.mkdir(dir, mode); | ||
} | ||
catch (e) { | ||
if (e.code !== 'EEXIST') { | ||
throw e; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
exports.mkdirp = mkdirp; | ||
function mkdirpSync(p, mode = 0o777) { | ||
const absPath = path.resolve(p); | ||
const pathObj = path.parse(absPath); | ||
const dirnames = absPath.split(path.sep).splice(1); | ||
const dirs = dirnames.map((v, i) => path.resolve(pathObj.root, ...dirnames.slice(0, i), v)); | ||
for (const dir of dirs) { | ||
try { | ||
fs.mkdirSync(dir, mode); | ||
} | ||
catch (e) { | ||
if (e.code !== 'EEXIST') { | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
exports.mkdirpSync = mkdirpSync; | ||
function getFileChecksum(filePath) { | ||
@@ -171,3 +85,3 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const md5 = yield exports.readFile(`${p}.md5`, { encoding: 'utf8' }); | ||
const md5 = yield fs.readFile(`${p}.md5`, { encoding: 'utf8' }); | ||
return md5.trim(); | ||
@@ -194,3 +108,3 @@ } | ||
const md5 = yield getFileChecksum(p); | ||
yield exports.writeFile(`${p}.md5`, md5, { encoding: 'utf8' }); | ||
yield fs.writeFile(`${p}.md5`, md5, { encoding: 'utf8' }); | ||
}); | ||
@@ -208,41 +122,6 @@ } | ||
exports.writeStreamToFile = writeStreamToFile; | ||
function copyDirectory(source, destination, options = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const ncp = yield Promise.resolve().then(() => require('ncp')); | ||
return new Promise((resolve, reject) => { | ||
ncp.ncp(source, destination, options, err => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
exports.copyDirectory = copyDirectory; | ||
function removeDirectory(dir) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const rimraf = yield Promise.resolve().then(() => require('rimraf')); | ||
const rimrafp = promisify(rimraf); | ||
yield rimrafp(dir); | ||
}); | ||
} | ||
exports.removeDirectory = removeDirectory; | ||
function copyFile(fileName, target, mode = 0o666) { | ||
return new Promise((resolve, reject) => { | ||
const rs = fs.createReadStream(fileName); | ||
const ws = fs.createWriteStream(target, { mode }); | ||
rs.on('error', reject); | ||
ws.on('error', reject); | ||
ws.on('open', () => { | ||
rs.pipe(ws); | ||
}); | ||
ws.once('finish', resolve); | ||
}); | ||
} | ||
exports.copyFile = copyFile; | ||
function pathAccessible(filePath, mode) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield exports.access(filePath, mode); | ||
yield fs.access(filePath, mode); | ||
} | ||
@@ -271,3 +150,3 @@ catch (e) { | ||
for (const d of compilePaths(dir)) { | ||
const results = yield readDirSafe(d); | ||
const results = yield safe.readdir(d); | ||
if (results.includes(file)) { | ||
@@ -315,12 +194,2 @@ return d; | ||
exports.compilePaths = compilePaths; | ||
function isDir(p) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const stats = yield statSafe(p); | ||
if (stats && stats.isDirectory()) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
exports.isDir = isDir; | ||
class Walker extends stream.Readable { | ||
@@ -327,0 +196,0 @@ constructor(p, options = {}) { |
{ | ||
"name": "@ionic/utils-fs", | ||
"version": "0.1.0-testing.e70f2d6e", | ||
"version": "1.0.0", | ||
"description": "Filesystem utils for Node", | ||
@@ -24,8 +24,7 @@ "main": "dist/index.js", | ||
"clean": "rimraf dist", | ||
"lint": "tslint --config tslint.js --project tsconfig.json", | ||
"lint": "tslint --project tsconfig.json", | ||
"build": "npm run clean && tsc", | ||
"watch": "tsc -w --preserveWatchOutput", | ||
"test": "jest", | ||
"prepublishOnly": "npm run build", | ||
"precommit": "lint-staged" | ||
"test": "jest --maxWorkers=4", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -42,9 +41,10 @@ "lint-staged": { | ||
"debug": "^4.0.0", | ||
"ncp": "^2.0.0", | ||
"through2": "^2.0.3", | ||
"fs-extra": "^7.0.1", | ||
"through2": "^3.0.0", | ||
"tslib": "^1.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/debug": "0.0.30", | ||
"@types/ncp": "^2.0.1", | ||
"@types/debug": "0.0.31", | ||
"@types/fs-extra": "^5.0.4", | ||
"@types/jest": "^23.3.5", | ||
"@types/node": "^6.0.101", | ||
@@ -54,8 +54,8 @@ "@types/through2": "^2.0.33", | ||
"jest-cli": "^23.0.1", | ||
"lint-staged": "^7.2.0", | ||
"lint-staged": "^8.0.0", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "~23.1.0", | ||
"ts-jest": "^23.10.1", | ||
"tslint": "^5.9.1", | ||
"typescript": "~3.0.1" | ||
"typescript": "~3.2.1" | ||
} | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance 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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8
0
15953
12
331
3
+ Addedfs-extra@^7.0.1
+ Addedfs-extra@7.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedthrough2@3.0.2(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removedncp@^2.0.0
- Removedcore-util-is@1.0.3(transitive)
- Removedisarray@1.0.0(transitive)
- Removedncp@2.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedxtend@4.0.2(transitive)
Updatedthrough2@^3.0.0