You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@netlify/framework-info

Package Overview
Dependencies
7
Maintainers
12
Versions
93
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

dist/index.js

7

CHANGELOG.md

@@ -10,2 +10,9 @@ # Changelog

## [1.1.0](https://www.github.com/netlify/framework-info/compare/v1.0.0...v1.1.0) (2020-12-16)
### Features
* make the library browser compatible ([#58](https://www.github.com/netlify/framework-info/issues/58)) ([b172413](https://www.github.com/netlify/framework-info/commit/b17241389e4ead400b8f7bfddd35496b260d6f25))
## [1.0.0](https://www.github.com/netlify/framework-info/compare/v0.3.2...v1.0.0) (2020-12-15)

@@ -12,0 +19,0 @@

41

package.json
{
"name": "@netlify/framework-info",
"version": "1.0.0",
"version": "1.1.0",
"description": "Framework detection utility",
"main": "./src/main.js",
"browser": "./dist/index.js",
"bin": {

@@ -10,2 +11,3 @@ "framework-info": "./src/bin.js"

"files": [
"dist/index.js",
"src/**/*.js",

@@ -16,2 +18,9 @@ "src/**/*.json",

"scripts": {
"prepublishOnly": "run-s build:core",
"build": "run-s build:*",
"build:core": "webpack --config scripts/webpack.config.core.js",
"build:site-react": "webpack --config scripts/webpack.config.site.js",
"build:site-vanilla": "cpy site/vanilla/index.html dist/vanilla",
"build:site-root": "cpy site/index.html dist",
"develop:site-react": "webpack serve --config scripts/webpack.config.site.js",
"test": "npm run format && npm run test:dev",

@@ -66,3 +75,3 @@ "format": "run-s format:check-fix:*",

"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"src/**/*.js\" \"test/*.js\" \"test/helpers/**/*.js\"",
"prettier": "--ignore-path .gitignore --loglevel warn \"{src,test}/**/*.js\" \"*.{js,md,yml,json}\" \"!package-lock.json\" \"!CHANGELOG.md\""
"prettier": "--ignore-path .gitignore --loglevel warn \"{src,site,scripts,test}/**/*.js\" \"*.{js,md,yml,json}\" \"!package-lock.json\" \"!CHANGELOG.md\""
},

@@ -74,3 +83,3 @@ "dependencies": {

"p-filter": "^2.1.0",
"path-exists": "^4.0.0",
"p-locate": "^4.1.0",
"read-pkg-up": "^7.0.1",

@@ -80,2 +89,5 @@ "yargs": "^15.4.1"

"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.10",
"@babel/preset-react": "^7.12.10",
"@commitlint/cli": "^11.0.0",

@@ -85,15 +97,32 @@ "@commitlint/config-conventional": "^11.0.0",

"ajv": "^6.12.3",
"auto-changelog": "^2.2.0",
"ava": "^2.4.0",
"babel-loader": "^8.2.2",
"cpy": "^8.1.0",
"cpy-cli": "^3.1.1",
"del": "^5.1.0",
"eslint-plugin-react": "^7.21.5",
"execa": "^3.4.0",
"get-bin-path": "^4.0.1",
"gh-release": "^4.0.0",
"html-webpack-plugin": "^4.5.0",
"husky": "^3.1.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.0.0",
"path-browserify": "^1.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"test-each": "^1.8.0",
"tmp-promise": "^3.0.2"
"tmp-promise": "^3.0.2",
"webpack": "^5.10.1",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
},
"browserslist": [
"last 2 Chrome versions",
"last 2 Opera versions",
"last 2 Firefox versions",
"last 2 Edge versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 ChromeAndroid versions"
],
"engines": {

@@ -100,0 +129,0 @@ "node": ">=8.3.0"

15

src/detect.js

@@ -1,2 +0,2 @@

const locatePath = require('locate-path')
const pLocate = require('p-locate')

@@ -17,3 +17,3 @@ // Checks if the project is using a specific framework:

},
{ projectDir, npmDependencies },
{ pathExists, npmDependencies },
) {

@@ -23,3 +23,3 @@ return (

lacksExcludedNpmDependencies(frameworkExcludedNpmDependencies, npmDependencies) &&
(await usesConfigFiles(configFiles, projectDir))
(await usesConfigFiles(configFiles, pathExists))
)

@@ -44,6 +44,11 @@ }

const usesConfigFiles = async function (configFiles, projectDir) {
return configFiles.length === 0 || (await locatePath(configFiles, { type: 'file', cwd: projectDir })) !== undefined
const configExists = async (configFiles, pathExists) => {
const exists = await pLocate(configFiles, (file) => pathExists(file))
return exists
}
const usesConfigFiles = async function (configFiles, pathExists) {
return configFiles.length === 0 || (await configExists(configFiles, pathExists))
}
module.exports = { usesFramework }

@@ -1,10 +0,4 @@

const pFilter = require('p-filter')
const { getContext } = require('./context')
const { listFrameworks: list, hasFramework: has, getFramework: get } = require('./core.js')
const { usesFramework } = require('./detect.js')
const { FRAMEWORKS } = require('./frameworks/main.js')
const { getOptions } = require('./options.js')
const { getPackageJsonContent } = require('./package.js')
const { getRunScriptCommand } = require('./run_script.js')
const { getWatchCommands } = require('./watch.js')
/**

@@ -33,3 +27,3 @@ * @typedef {object} Options

*
* @param {Options} [options] - Options
* @param {Options} options - Options
*

@@ -39,7 +33,4 @@ * @returns {Framework[]} frameworks - Frameworks used by a project

const listFrameworks = async function (opts) {
const { projectDir } = getOptions(opts)
const { npmDependencies, scripts, runScriptCommand } = await getProjectInfo({ projectDir })
const frameworks = await pFilter(FRAMEWORKS, (framework) => usesFramework(framework, { projectDir, npmDependencies }))
const frameworkInfos = frameworks.map((framework) => getFrameworkInfo(framework, { scripts, runScriptCommand }))
return frameworkInfos
const context = await getContext(opts)
return await list(context)
}

@@ -51,12 +42,9 @@

* @param {string} frameworkName - Name such as `"gatsby"`
* @param {Options} [options] - Options
* @param {Options} [options] - Context
*
* @returns {boolean} result - Whether the project uses this framework
*/
const hasFramework = async function (frameworkName, opts) {
const framework = getFrameworkByName(frameworkName)
const { projectDir } = getOptions(opts)
const { npmDependencies } = await getProjectInfo({ projectDir })
const result = await usesFramework(framework, { projectDir, npmDependencies })
return result
const hasFramework = async function (frameworkName, options) {
const context = await getContext(options)
return await has(frameworkName, context)
}

@@ -68,41 +56,11 @@

* @param {string} frameworkName - Name such as `"gatsby"`
* @param {Options} [options] - Options
* @param {Context} [context] - Context
*
* @returns {Framework} framework - Framework used by a project
*/
const getFramework = async function (frameworkName, opts) {
const framework = getFrameworkByName(frameworkName)
const { projectDir } = getOptions(opts)
const { scripts, runScriptCommand } = await getProjectInfo({ projectDir })
const frameworkInfo = getFrameworkInfo(framework, { scripts, runScriptCommand })
return frameworkInfo
const getFramework = async function (frameworkName, options) {
const context = await getContext(options)
return await get(frameworkName, context)
}
const getFrameworkByName = function (frameworkName) {
const framework = FRAMEWORKS.find(({ name }) => name === frameworkName)
if (framework === undefined) {
const frameworkNames = FRAMEWORKS.map(getFrameworkName).join(', ')
throw new Error(`Invalid framework "${frameworkName}". It should be one of: ${frameworkNames}`)
}
return framework
}
const getFrameworkName = function ({ name }) {
return name
}
const getProjectInfo = async function ({ projectDir }) {
const { packageJsonPath, npmDependencies, scripts } = await getPackageJsonContent({ projectDir })
const runScriptCommand = await getRunScriptCommand({ projectDir, packageJsonPath })
return { npmDependencies, scripts, runScriptCommand }
}
const getFrameworkInfo = function (
{ name, category, watch: { command: frameworkWatchCommand, directory, port }, env },
{ scripts, runScriptCommand },
) {
const watchCommands = getWatchCommands({ frameworkWatchCommand, scripts, runScriptCommand })
return { name, category, watch: { commands: watchCommands, directory, port }, env }
}
module.exports = { listFrameworks, hasFramework, getFramework }
const filterObj = require('filter-obj')
const isPlainObj = require('is-plain-obj')
const readPkgUp = require('read-pkg-up')
// Find the `package.json` (if there is one) and loads its
// `dependencies|devDependencies` and `scripts` fields
const getPackageJsonContent = async function ({ projectDir }) {
const { packageJson, packageJsonPath } = await getPackageJson(projectDir)
const getPackageJsonContent = function ({ packageJson }) {
if (packageJson === undefined) {
return { packageJsonPath, npmDependencies: [], scripts: {} }
return { npmDependencies: [], scripts: {} }
}

@@ -15,24 +11,5 @@

const scripts = getScripts(packageJson)
return { packageJsonPath, npmDependencies, scripts }
return { npmDependencies, scripts }
}
const getPackageJson = async function (projectDir) {
try {
const result = await readPkgUp({ cwd: projectDir, normalize: false })
if (result === undefined) {
return {}
}
const { packageJson, path: packageJsonPath } = result
if (!isPlainObj(packageJson)) {
return { packageJsonPath }
}
return { packageJson, packageJsonPath }
} catch (error) {
return {}
}
}
// Retrieve `package.json` `dependencies` and `devDependencies` names

@@ -39,0 +16,0 @@ const getNpmDependencies = function ({ dependencies, devDependencies }) {

const { dirname } = require('path')
const pathExists = require('path-exists')
// Retrieve the command to run `package.json` `scripts` commands
const getRunScriptCommand = async function ({ projectDir, packageJsonPath = projectDir }) {
if (await pathExists(`${dirname(packageJsonPath)}/yarn.lock`)) {
const getRunScriptCommand = async function ({ pathExists, packageJsonPath }) {
const yarnExists = await pathExists(`${dirname(packageJsonPath)}/yarn.lock`)
if (yarnExists) {
return 'yarn'

@@ -9,0 +8,0 @@ }

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc