New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

majo

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

majo - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

445

dist/majo.cjs.js
'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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc