Comparing version 0.5.1 to 0.6.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var fsExtra = require('fs-extra'); | ||
var globby = _interopDefault(require('globby')); | ||
var path = _interopDefault(require('path')); | ||
var fs = _interopDefault(require('fs-extra')); | ||
var glob = _interopDefault(require('fast-glob')); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
function step(key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
function _next(value) { | ||
step("next", value); | ||
} | ||
function _throw(err) { | ||
step("throw", err); | ||
} | ||
_next(); | ||
}); | ||
}; | ||
} | ||
class Wares { | ||
constructor() { | ||
this.middlewares = []; | ||
} | ||
use(middleware) { | ||
this.middlewares = this.middlewares.concat(middleware); | ||
return this; | ||
} | ||
run(context) { | ||
return this.middlewares.reduce((current, next) => { | ||
return current.then(() => Promise.resolve(next(context))); | ||
}, Promise.resolve()); | ||
} | ||
constructor() { | ||
this.middlewares = []; | ||
} | ||
use(middleware) { | ||
this.middlewares = this.middlewares.concat(middleware); | ||
return this; | ||
} | ||
run(context) { | ||
return this.middlewares.reduce((current, next) => { | ||
return current.then(() => Promise.resolve(next(context))); | ||
}, Promise.resolve()); | ||
} | ||
} | ||
class Majo { | ||
constructor() { | ||
this.middlewares = []; | ||
this.meta = {}; | ||
} | ||
constructor() { | ||
/** | ||
* Define how to find files | ||
* @param source Glob patterns | ||
* @param options | ||
* @param options.baseDir The base dir to look for files | ||
* @param options.dotFiles Include dot files | ||
*/ | ||
source(source, { baseDir = '.', dotFiles = true } = {}) { | ||
this.baseDir = path.resolve(baseDir); | ||
this.sourcePatterns = source; | ||
this.dotFiles = dotFiles; | ||
return this; | ||
} | ||
* @typedef {(ctx: Majo) => Promise<void> | void} Middleware | ||
* @type {Middleware[]} */ | ||
this.middlewares = []; | ||
/** | ||
* Add middleware | ||
* @param middleware Middleware | ||
* An object you can use across middleware to share states | ||
* @type {{[k: string]: any}} | ||
*/ | ||
use(middleware) { | ||
this.middlewares.push(middleware); | ||
return this; | ||
} | ||
/** | ||
* Process all middlewares | ||
*/ | ||
process() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const statCache = {}; | ||
const paths = yield globby(this.sourcePatterns, { | ||
cwd: this.baseDir, | ||
dot: this.dotFiles, | ||
nodir: true, | ||
statCache | ||
}); | ||
this.files = {}; | ||
yield Promise.all(paths.map((relative) => __awaiter(this, void 0, void 0, function* () { | ||
const absolutePath = path.resolve(this.baseDir, relative); | ||
return fsExtra.readFile(absolutePath).then(contents => { | ||
const stats = statCache[path.isAbsolute(this.baseDir) ? absolutePath : relative]; | ||
const file = { contents, stats, path: absolutePath }; | ||
this.files[relative] = file; | ||
}); | ||
}))); | ||
yield new Wares().use(this.middlewares).run(this); | ||
return this.files; | ||
this.meta = {}; | ||
} | ||
/** | ||
* Find files from specific directory | ||
* @param {string | string[]} source Glob patterns | ||
* @param {{baseDir?: string, dotFiles?: boolean}} opts | ||
* @param opts.baseDir The base directory to find files | ||
* @param opts.dotFiles Including dot files | ||
*/ | ||
source(patterns, { | ||
baseDir = '.', | ||
dotFiles = true | ||
} = {}) { | ||
this.baseDir = path.resolve(baseDir); | ||
this.sourcePatterns = patterns; | ||
this.dotFiles = dotFiles; | ||
return this; | ||
} | ||
/** | ||
* Use a middleware | ||
* @param {(ctx: Majo) => Promise<void> | void} middleware | ||
*/ | ||
use(middleware) { | ||
this.middlewares.push(middleware); | ||
return this; | ||
} | ||
/** | ||
* Process middlewares against files | ||
*/ | ||
process() { | ||
var _this = this; | ||
return _asyncToGenerator(function* () { | ||
const allStats = yield glob(_this.sourcePatterns, { | ||
cwd: _this.baseDir, | ||
dot: _this.dotFiles, | ||
stats: true | ||
}); | ||
/** | ||
* @typedef {{path: string, stats: fs.Stats, contents: Buffer}} File | ||
* @type {{[relativePath: string]: File}} | ||
*/ | ||
_this.files = {}; | ||
yield Promise.all(allStats.map(stats => { | ||
const absolutePath = path.resolve(_this.baseDir, stats.path); | ||
return fs.readFile(absolutePath).then(contents => { | ||
const file = { | ||
contents, | ||
stats, | ||
path: absolutePath | ||
}; | ||
_this.files[stats.path] = file; | ||
}); | ||
})); | ||
yield new Wares().use(_this.middlewares).run(_this); | ||
return _this; | ||
})(); | ||
} | ||
/** | ||
* Filter files | ||
* @param {(relativePath: string, file: File) => boolean} fn Filter handler | ||
*/ | ||
filter(fn) { | ||
return this.use(context => { | ||
for (const relativePath in context.files) { | ||
if (!fn(relativePath, context.files[relativePath])) { | ||
delete context.files[relativePath]; | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
* Transform file at given path | ||
* @param {string} relativePath Relative path | ||
* @param {(contents: string) => string} fn Transform handler | ||
*/ | ||
transform(relativePath, fn) { | ||
const contents = this.files[relativePath].contents.toString(); | ||
const result = fn(contents); | ||
if (!result.then) { | ||
this.files[relativePath].contents = Buffer.from(result); | ||
return; | ||
} | ||
/** | ||
* Add a filter to include/exclude files | ||
*/ | ||
filter(fn) { | ||
return this.use(context => { | ||
Object.keys(context.files).forEach(relative => { | ||
if (!fn(relative, context.files[relative])) { | ||
// tslint:disable-next-line | ||
delete context.files[relative]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Transform files | ||
* @param relative Relative path of a file | ||
* @param fn The function to transform file | ||
*/ | ||
transform(relative, fn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const contents = this.files[relative].contents.toString(); | ||
const result = yield fn(contents); | ||
this.files[relative].contents = Buffer.from(result); | ||
return this; | ||
}); | ||
} | ||
/** | ||
* Write files | ||
* @param dest The output directory | ||
* @param options | ||
* @param options.baseDir The base directory to resolve `dest` | ||
* @param options.clean Whether to clean output directory before writing | ||
*/ | ||
dest(dest, { baseDir = '.', clean = false } = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const destPath = path.resolve(baseDir, dest); | ||
const files = yield this.process(); | ||
if (clean) { | ||
yield fsExtra.remove(destPath); | ||
} | ||
yield Promise.all(Object.keys(files).map((filename) => __awaiter(this, void 0, void 0, function* () { | ||
const { contents } = files[filename]; | ||
const target = path.join(destPath, filename); | ||
return fsExtra.ensureDir(path.dirname(target)).then(() => __awaiter(this, void 0, void 0, function* () { return fsExtra.writeFile(target, contents); })); | ||
}))); | ||
}); | ||
} | ||
/** | ||
* Get contents of specific file | ||
* @param relative The relative path of a file | ||
*/ | ||
fileContents(relative) { | ||
return this.file(relative).contents.toString(); | ||
} | ||
/** | ||
* Write contents to a file | ||
* @param relative The relative path of a file | ||
* @param str File contents as a string | ||
*/ | ||
writeContents(relative, str) { | ||
this.files[relative].contents = Buffer.from(str); | ||
return this; | ||
} | ||
/** | ||
* Get the stats of a file | ||
* @param relative The relative path of a file | ||
*/ | ||
fileStats(relative) { | ||
return this.file(relative).stats; | ||
} | ||
/** | ||
* Get a file | ||
* @param relative The relative path of a file | ||
*/ | ||
file(relative) { | ||
return this.files[relative]; | ||
} | ||
/** | ||
* Delete a file | ||
* @param relative The relative path of a file | ||
*/ | ||
deleteFile(relative) { | ||
// tslint:disable-next-line | ||
delete this.files[relative]; | ||
return this; | ||
} | ||
/** | ||
* Create a file | ||
* @param relative The relative path of a file | ||
* @param file File | ||
*/ | ||
createFile(relative, file) { | ||
this.files[relative] = file; | ||
return this; | ||
} | ||
/** | ||
* Get the list of file names | ||
*/ | ||
get fileList() { | ||
return Object.keys(this.files).sort(); | ||
} | ||
return result.then(newContents => { | ||
this.files[relativePath].contents = Buffer.from(newContents); | ||
}); | ||
} | ||
/** | ||
* Run middlewares and write processed files to disk | ||
* @param {string} dest Target directory | ||
* @param {{baseDir?: string, clean?: boolean}} opts | ||
* @param opts.baseDir Base directory to resolve target directory | ||
* @param opts.clean Clean directory before writing | ||
*/ | ||
dest(dest, { | ||
baseDir = '.', | ||
clean = false | ||
} = {}) { | ||
var _this2 = this; | ||
return _asyncToGenerator(function* () { | ||
const destPath = path.resolve(baseDir, dest); | ||
yield _this2.process(); | ||
if (clean) { | ||
yield fs.remove(destPath); | ||
} | ||
yield Promise.all(Object.keys(_this2.files).map(filename => { | ||
const contents = _this2.files[filename].contents; | ||
const target = path.join(destPath, filename); | ||
return fs.ensureDir(path.dirname(target)).then(() => fs.writeFile(target, contents)); | ||
})); | ||
return _this2; | ||
})(); | ||
} | ||
/** | ||
* Get file contents as a UTF-8 string | ||
* @param {string} relativePath Relative path | ||
* @return {string} | ||
*/ | ||
fileContents(relativePath) { | ||
return this.file(relativePath).contents.toString(); | ||
} | ||
/** | ||
* Write contents to specific file | ||
* @param {string} relativePath Relative path | ||
* @param {string} string File content as a UTF-8 string | ||
*/ | ||
writeContents(relativePath, string) { | ||
this.files[relativePath].contents = Buffer.from(string); | ||
return this; | ||
} | ||
/** | ||
* Get the fs.Stats object of specified file | ||
* @param {string} relativePath Relative path | ||
* @return {fs.Stats} | ||
*/ | ||
fileStats(relativePath) { | ||
return this.file(relativePath).stats; | ||
} | ||
/** | ||
* Get a file by relativePath path | ||
* @param {string} relativePath Relative path | ||
* @return {File} | ||
*/ | ||
file(relativePath) { | ||
return this.files[relativePath]; | ||
} | ||
/** | ||
* Delete a file | ||
* @param {string} relativePath Relative path | ||
*/ | ||
deleteFile(relativePath) { | ||
delete this.files[relativePath]; | ||
return this; | ||
} | ||
/** | ||
* Create a new file | ||
* @param {string} relativePath Relative path | ||
* @param {File} file | ||
*/ | ||
createFile(relativePath, file) { | ||
this.files[relativePath] = file; | ||
return this; | ||
} | ||
/** | ||
* Get an array of sorted file paths | ||
* @return {string[]} | ||
*/ | ||
get fileList() { | ||
return Object.keys(this.files).sort(); | ||
} | ||
} | ||
const majo = () => new Majo(); | ||
// For CommonJS default export support | ||
module.exports = majo; | ||
// So that const majo = require('majo').default works too | ||
module.exports.default = majo; | ||
exports.Majo = Majo; | ||
exports.default = majo; | ||
var index = (() => new Majo()); | ||
module.exports = index; |
{ | ||
"name": "majo", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "my badass project", | ||
@@ -10,3 +10,2 @@ "repository": { | ||
"main": "dist/majo.cjs.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -18,9 +17,5 @@ "dist" | ||
"prepublishOnly": "npm run build", | ||
"lint": "tslint -p .", | ||
"build": "bili && rm -rf dist/__test__" | ||
"lint": "xo", | ||
"build": "bili" | ||
}, | ||
"bili": { | ||
"input": "src/index.ts", | ||
"js": "typescript2" | ||
}, | ||
"author": "egoist <0x142857@gmail.com>", | ||
@@ -35,21 +30,31 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/fs-extra": "^5.0.2", | ||
"@types/globby": "^6.1.0", | ||
"@types/jest": "^22.2.3", | ||
"@types/node": "^9.6.4", | ||
"bili": "^3.0.15", | ||
"jest": "^22.4.3", | ||
"rollup-plugin-typescript2": "^0.12.0", | ||
"ts-jest": "^22.4.2", | ||
"tslint": "^5.9.1", | ||
"tslint-xo": "^0.7.0", | ||
"typescript": "^2.8.1" | ||
"@babel/core": "^7.0.0-beta.44", | ||
"@babel/preset-env": "^7.0.0-beta.44", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^22.4.3", | ||
"bili": "^3.1.0", | ||
"buble": "^0.15.2", | ||
"eslint-config-rem": "^3.0.0", | ||
"jest-cli": "^22.4.3", | ||
"xo": "^0.18.0" | ||
}, | ||
"xo": { | ||
"extends": "rem", | ||
"esnext": true, | ||
"envs": [ | ||
"jest" | ||
], | ||
"ignores": [ | ||
"test/fixture/**", | ||
"test/output/**", | ||
"examples/**" | ||
], | ||
"rules": { | ||
"guard-for-in": 0 | ||
} | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^3.0.1", | ||
"globby": "^6.1.0" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"fast-glob": "^2.2.0", | ||
"fs-extra": "^3.0.1" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
9
0
10788
4
231
2
+ Addedfast-glob@^2.2.0
+ Added@mrmlnc/readdir-enhanced@2.2.1(transitive)
+ Added@nodelib/fs.stat@1.1.3(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedcall-me-maybe@1.0.2(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfast-glob@2.2.7(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob-parent@3.1.0(transitive)
+ Addedglob-to-regexp@0.3.0(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@3.1.04.0.3(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-dirname@1.0.2(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
- Removedglobby@^6.1.0
- Removedarray-union@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@6.1.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedwrappy@1.0.2(transitive)