| 'use strict'; | ||
| const path = require('path'); | ||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| module.exports = { getFrameworkPath }; | ||
| /** | ||
| * Find the framework directory, lookup order | ||
| * - specify framework path | ||
| * - get framework name from | ||
| * - use egg by default | ||
| * @param {Object} options - options | ||
| * @param {String} options.baseDir - the current directory of application | ||
| * @param {String} [options.framework] - the directory of framework | ||
| * @return {String} frameworkPath | ||
| */ | ||
| function getFrameworkPath({ framework, baseDir }) { | ||
| const pkgPath = path.join(baseDir, 'package.json'); | ||
| assert(fs.existsSync(pkgPath), `${pkgPath} should exist`); | ||
| const moduleDir = path.join(baseDir, 'node_modules'); | ||
| const pkg = require(pkgPath); | ||
| // 1. pass framework or customEgg | ||
| if (framework) { | ||
| // 1.1 framework is an absolute path | ||
| // framework: path.join(baseDir, 'node_modules/${frameworkName}') | ||
| if (path.isAbsolute(framework)) return assertAndReturn(framework); | ||
| // 1.2 framework is a npm package that required by application | ||
| // framework: 'frameworkName' | ||
| return assertAndReturn(path.join(moduleDir, framework)); | ||
| } | ||
| // 2. framework is not specified | ||
| // 2.1 use framework name from pkg.egg.framework | ||
| if (pkg.egg && pkg.egg.framework) { | ||
| return assertAndReturn(path.join(moduleDir, pkg.egg.framework)); | ||
| } | ||
| // 2.2 use egg by default | ||
| return assertAndReturn(path.join(moduleDir, 'egg')); | ||
| } | ||
| function assertAndReturn(frameworkPath) { | ||
| assert(fs.existsSync(frameworkPath), `${frameworkPath} should exist`); | ||
| return frameworkPath; | ||
| } |
+6
-0
| 2.0.0 / 2017-03-01 | ||
| ================== | ||
| * feat: move getFrameworkPath from egg-cluster (#2) | ||
| * deps: only support node >= 6.0.0 | ||
| 1.1.0 / 2017-01-13 | ||
@@ -3,0 +9,0 @@ ================== |
+10
-3
@@ -6,2 +6,8 @@ 'use strict'; | ||
| [ | ||
| require('./lib/framework'), | ||
| { getFrameworkOrEggPath }, | ||
| ] | ||
| .forEach(obj => Object.assign(exports, obj)); | ||
| /** | ||
@@ -14,5 +20,6 @@ * Try to get framework dir path | ||
| * @return {String} framework or egg dir path | ||
| * @deprecated | ||
| */ | ||
| exports.getFrameworkOrEggPath = (cwd, eggNames) => { | ||
| eggNames = eggNames || ['egg']; | ||
| function getFrameworkOrEggPath(cwd, eggNames) { | ||
| eggNames = eggNames || [ 'egg' ]; | ||
| const moduleDir = path.join(cwd, 'node_modules'); | ||
@@ -60,2 +67,2 @@ if (!fs.existsSync(moduleDir)) { | ||
| return ''; | ||
| }; | ||
| } |
+2
-2
@@ -1,4 +0,4 @@ | ||
| The MIT License (MIT) | ||
| MIT License | ||
| Copyright (c) Alibaba Group Holding Limited and other contributors. | ||
| Copyright (c) 2017 Alibaba Group Holding Limited and other contributors. | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
+15
-18
| { | ||
| "name": "egg-utils", | ||
| "version": "1.1.0", | ||
| "version": "2.0.0", | ||
| "description": "Utils for all egg projects", | ||
| "main": "index.js", | ||
| "files": [ | ||
| "index.js" | ||
| "index.js", | ||
| "lib" | ||
| ], | ||
| "scripts": { | ||
| "test": "NODE_ENV=test ava", | ||
| "cov": "NODE_ENV=test nyc ava && nyc report --reporter=json --reporter=lcov", | ||
| "lint": "eslint *.js test --fix", | ||
| "lint": "eslint .", | ||
| "test": "npm run lint && ypkgfiles && egg-bin test", | ||
| "cov": "egg-bin cov", | ||
| "ci": "npm run lint && npm run cov", | ||
| "autod": "autod -w --prefix='^'" | ||
| "autod": "autod" | ||
| }, | ||
@@ -28,8 +29,8 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "autod": "^2.6.1", | ||
| "ava": "^0.15.2", | ||
| "egg-ci": "^1.0.2", | ||
| "eslint": "^2.13.0", | ||
| "eslint-config-egg": "^2.0.0", | ||
| "nyc": "^6.6.1" | ||
| "autod": "^2.7.1", | ||
| "egg-bin": "^2.2.3", | ||
| "egg-ci": "^1.3.0", | ||
| "eslint": "^3.16.1", | ||
| "eslint-config-egg": "^3.2.0", | ||
| "ypkgfiles": "^1.2.0" | ||
| }, | ||
@@ -39,10 +40,6 @@ "engine": { | ||
| }, | ||
| "ava": { | ||
| "files": [ | ||
| "test/**/*.test.js" | ||
| ] | ||
| }, | ||
| "ci": { | ||
| "version": "6, 7" | ||
| "version": "6, 7", | ||
| "license": true | ||
| } | ||
| } |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
6577
36.14%6
20%98
92.16%5
66.67%