├── .gitignore ├── .npmignore ├── screenshot.png ├── package.json ├── README.md ├── LICENSE.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | screenshot.png 2 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juliangruber/native-modules/HEAD/screenshot.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "native-modules", 3 | "version": "3.0.0", 4 | "type": "module", 5 | "license": "MIT", 6 | "repository": "juliangruber/native-modules", 7 | "description": "Report native modules used", 8 | "bin": { 9 | "native-modules": "index.js" 10 | }, 11 | "scripts": { 12 | "test": "prettier-standard && standard && node ." 13 | }, 14 | "dependencies": { 15 | "chalk": "^5.0.1", 16 | "is-native-module": "^1.1.3" 17 | }, 18 | "devDependencies": { 19 | "dat-node": "^4.0.1", 20 | "discovery-swarm": "^6.1.0", 21 | "prettier-standard": "^16.4.1", 22 | "standard": "^17.0.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # native-modules 2 | 3 | Report on the native node modules used by your application or module. 4 | 5 | Checks for presence of [prebuild](https://npmjs.org/package/prebuild), [prebuild-ci](https://npmjs.org/package/prebuild-ci), and [prebuildify](https://github.com/prebuild/prebuildify). 6 | 7 | ![screenshot](screenshot.png) 8 | 9 | ## Usage 10 | 11 | ```text 12 | $ native-modules --help 13 | Usage: native-modules [options] 14 | --format The formatting style for command output 15 | (formats: pretty|json default: pretty) 16 | -h, --help Print command line options 17 | ``` 18 | 19 | ## Installation 20 | 21 | ```bash 22 | $ npm install -g native-modules 23 | ``` 24 | 25 | ## License 26 | 27 | MIT 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Julian Gruber 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { promises as fs } from 'fs' 4 | import isNative from 'is-native-module' 5 | import chalk from 'chalk' 6 | 7 | let isFirst = true 8 | const items = [] 9 | const check = truthy => (truthy ? chalk.green('✓') : chalk.red('×')) 10 | 11 | const FORMAT_PRETTY = 'pretty' 12 | const FORMAT_JSON = 'json' 13 | 14 | function hasArg (arg) { 15 | return process.argv.includes(arg) 16 | } 17 | 18 | function getArgValue (arg) { 19 | const index = process.argv.indexOf(arg) 20 | 21 | if (index > -1) { 22 | return process.argv[index + 1] 23 | } 24 | return undefined 25 | } 26 | 27 | const format = getArgValue('--format') || FORMAT_PRETTY 28 | 29 | const scan = dir => 30 | Promise.all([ 31 | (async () => { 32 | let files 33 | try { 34 | files = await fs.readdir(dir) 35 | } catch (_) { 36 | return 37 | } 38 | await Promise.all( 39 | files.filter(f => !/^\./.test(f)).map(f => scan(`${dir}/${f}`)) 40 | ) 41 | })(), 42 | (async () => { 43 | let pkg 44 | try { 45 | const json = await fs.readFile(`${dir}/package.json`) 46 | pkg = JSON.parse(json.toString('utf8')) 47 | } catch (_) { 48 | return 49 | } 50 | if (isNative(pkg)) { 51 | if (isFirst && format === FORMAT_PRETTY) { 52 | console.log('PB CI PBY Module') 53 | isFirst = false 54 | } 55 | const path = dir 56 | .replace('node_modules/', '') 57 | .replace(/\/?node_modules\//g, ' -> ') 58 | const pb = pkg.dependencies && !!pkg.dependencies.prebuild 59 | const pby = pkg.devDependencies && !!pkg.devDependencies.prebuildify 60 | const pbc = pkg.devDependencies && !!pkg.devDependencies['prebuild-ci'] 61 | 62 | items.push({ 63 | 'prebuild-ci': !!pbc, 64 | prebuild: !!pb, 65 | prebuildify: !!pby, 66 | module: path 67 | }) 68 | 69 | if (format === FORMAT_PRETTY) { 70 | console.log(`${check(pb)} ${check(pbc)} ${check(pby)} ${path}`) 71 | } 72 | } 73 | })() 74 | ]) 75 | 76 | if (hasArg('-h') || hasArg('--help')) { 77 | const help = [ 78 | 'Usage: native-modules [options]', 79 | ' --format The formatting style for command output', 80 | ` (formats: ${FORMAT_PRETTY}|${FORMAT_JSON} default: ${FORMAT_PRETTY})`, 81 | ' -h, --help Print command line options' 82 | ] 83 | console.log(help.join('\n')) 84 | } else { 85 | scan('node_modules') 86 | .then(result => { 87 | if (format === FORMAT_JSON) { 88 | console.log(JSON.stringify(items)) 89 | } 90 | }) 91 | .catch(err => { 92 | console.error(err) 93 | process.exit(1) 94 | }) 95 | } 96 | --------------------------------------------------------------------------------