Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from CommonJS to ESM and add Windows 11 support #214

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
"bug",
"code"
]
},
{
"login": "HarryGwinnell",
"name": "Harry Gwinnell",
"avatar_url": "https://avatars.githubusercontent.com/u/10196821?v=4",
"profile": "https://harrygwinnell.co.uk",
"contributions": [
"bug",
"code"
]
}
]
}
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
env: {
node: true,
es6: true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
!__tests__/packages/**/node_modules
.DS_Store
.idea/
yarn-error.log
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"singleQuote": true,
"printWidth": 100,
"trailingComma": "es5"
"trailingComma": "es5",
"endOfLine": "auto",
"arrowParens": "avoid"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

[![CircleCI](https://circleci.com/gh/tabrindle/envinfo/tree/master.svg?style=svg)](https://circleci.com/gh/tabrindle/envinfo/tree/master) [![Build Status](https://travis-ci.org/tabrindle/envinfo.svg?branch=master)](https://travis-ci.org/tabrindle/envinfo) [![npm version](https://badge.fury.io/js/envinfo.svg)](https://badge.fury.io/js/envinfo) [![npm downloads per month](https://img.shields.io/npm/dm/envinfo.svg?maxAge=86400)](https://www.npmjs.com/package/envinfo) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors)

## The problem

Expand Down Expand Up @@ -279,7 +279,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
<!-- prettier-ignore -->
| [<img src="https://avatars1.githubusercontent.com/u/2925048?v=4" width="100px;"/><br /><sub><b>Trevor Brindle</b></sub>](http://trevorbrindle.com)<br />[💬](#question-tabrindle "Answering Questions") [📝](#blog-tabrindle "Blogposts") [🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Atabrindle "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=tabrindle "Code") [📖](https://github.com/tabrindle/envinfo/commits?author=tabrindle "Documentation") [💡](#example-tabrindle "Examples") [🤔](#ideas-tabrindle "Ideas, Planning, & Feedback") [👀](#review-tabrindle "Reviewed Pull Requests") [📢](#talk-tabrindle "Talks") [⚠️](https://github.com/tabrindle/envinfo/commits?author=tabrindle "Tests") | [<img src="https://avatars0.githubusercontent.com/u/997157?v=4" width="100px;"/><br /><sub><b>Gant Laborde</b></sub>](http://gantlaborde.com/)<br />[📝](#blog-GantMan "Blogposts") [🐛](https://github.com/tabrindle/envinfo/issues?q=author%3AGantMan "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=GantMan "Code") [🤔](#ideas-GantMan "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/599352?v=4" width="100px;"/><br /><sub><b>Anton Fisher</b></sub>](http://antonfisher.com)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Aantonfisher "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=antonfisher "Code") | [<img src="https://avatars1.githubusercontent.com/u/960133?v=4" width="100px;"/><br /><sub><b>Ahmad Awais ⚡️</b></sub>](https://AhmadAwais.com/)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Aahmadawais "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=ahmadawais "Code") | [<img src="https://avatars2.githubusercontent.com/u/9251453?v=4" width="100px;"/><br /><sub><b>Hasan</b></sub>](https://github.com/LEQADA)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3ALEQADA "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=LEQADA "Code") | [<img src="https://avatars3.githubusercontent.com/u/1232725?v=4" width="100px;"/><br /><sub><b>Ernesto Ramírez</b></sub>](http://twitter.com/_ErnestoR)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3AErnestoR "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=ErnestoR "Code") | [<img src="https://avatars1.githubusercontent.com/u/3759816?v=4" width="100px;"/><br /><sub><b>Jiawen Geng</b></sub>](https://www.gengjiawen.com)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Agengjiawen "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=gengjiawen "Code") [🤔](#ideas-gengjiawen "Ideas, Planning, & Feedback") [⚠️](https://github.com/tabrindle/envinfo/commits?author=gengjiawen "Tests") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/12520493?v=4" width="100px;"/><br /><sub><b>Zac Anger</b></sub>](https://zacanger.com)<br />[💻](https://github.com/tabrindle/envinfo/commits?author=zacanger "Code") [🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Azacanger "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/497214?v=4" width="100px;"/><br /><sub><b>Ville Immonen</b></sub>](https://twitter.com/VilleImmonen)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Afson "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=fson "Code") | [<img src="https://avatars2.githubusercontent.com/u/27246?v=4" width="100px;"/><br /><sub><b>Olmo Maldonado</b></sub>](http://ibolmo.com)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Aibolmo "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=ibolmo "Code") |
| [<img src="https://avatars3.githubusercontent.com/u/12520493?v=4" width="100px;"/><br /><sub><b>Zac Anger</b></sub>](https://zacanger.com)<br />[💻](https://github.com/tabrindle/envinfo/commits?author=zacanger "Code") [🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Azacanger "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/497214?v=4" width="100px;"/><br /><sub><b>Ville Immonen</b></sub>](https://twitter.com/VilleImmonen)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Afson "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=fson "Code") | [<img src="https://avatars2.githubusercontent.com/u/27246?v=4" width="100px;"/><br /><sub><b>Olmo Maldonado</b></sub>](http://ibolmo.com)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3Aibolmo "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=ibolmo "Code") | [<img src="https://avatars.githubusercontent.com/u/10196821?v=4" width="100px;"/><br /><sub><b>Harry Gwinnell</b></sub>](https://harrygwinnell.co.uk)<br />[🐛](https://github.com/tabrindle/envinfo/issues?q=author%3AHarryGwinnell "Bug reports") [💻](https://github.com/tabrindle/envinfo/commits?author=HarryGwinnell "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
4 changes: 2 additions & 2 deletions __tests__/duplicates.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const envinfo = require('../src/envinfo');
const path = require('path');
import envinfo from '../src/envinfo';
import path from 'path';

describe('Running the programmatic interface', () => {
test('return expected duplicates in json', async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/envinfo.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const envinfo = require('../src/envinfo');
const helpers = require('../src/helpers');
import envinfo from '../src/envinfo';
import helpers from '../src/helpers';

jest.mock('../src/helpers');

Expand Down
4 changes: 2 additions & 2 deletions __tests__/scopedPackages.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const envinfo = require('../src/envinfo');
const path = require('path');
import envinfo from '../src/envinfo';
import path from 'path';

describe('envinfo will report on scoped npm packages', () => {
test('return expected packages', async () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const utils = require('../src/utils');
import utils from '../src/utils';

const cases = {
apt: {
string: 'apt 1.4.9 (amd64)',
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
nodejs_version: '8'
nodejs_version: '16'

install:
- ps: Install-Product node $env:nodejs_version x64
Expand All @@ -14,7 +14,7 @@ test_script:
- set PATH=%RPATH%;%PATH%
- SET ENVINFO_DEBUG=trace
- npm run build
- node -r esm src/cli.js
- node src/cli.mjs
- node dist/cli.js
- SET ENVINFO_DEBUG=""
- npm test
Expand Down
13 changes: 2 additions & 11 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
node: '4.9.1',
},
useBuiltIns: 'usage',
},
],
['@babel/preset-env'],
],
plugins: ['@babel/plugin-proposal-optional-chaining'],
plugins: ['@babel/plugin-proposal-optional-chaining']
};
29 changes: 28 additions & 1 deletion dist/cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/envinfo.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const esModules = ['os-name', 'macos-release', 'windows-release'].join('|');

module.exports = {
transform: {
"^.+\\.(mjs|js|jsx)$": "babel-jest",
},
testEnvironment: "node",
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
setupFilesAfterEnv: ["./setupTests.js"],
moduleFileExtensions: ["js", "jsx", "mjs"]
};
70 changes: 34 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "envinfo",
"version": "7.8.0",
"version": "8.0.0",
"description": "Info about your dev environment for debugging purposes",
"repository": "https://github.com/tabrindle/envinfo",
"author": "[email protected]",
"license": "MIT",
"files": [
"dist/"
],
"main": "dist/envinfo.js",
"exports": "./dist/envinfo.js",
"bin": {
"envinfo": "dist/cli.js"
},
Expand All @@ -17,20 +17,20 @@
},
"scripts": {
"build": "webpack --progress",
"check:format": "prettier -l src/**/*.js --verbose",
"check:format": "prettier -l src/**/*.*js --verbose",
"compress": "gzexe envinfo-* && upx envinfo-win.exe",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"postcompress": "tar -czvf envinfo-linux.tar.gz envinfo-linux && tar -czvf envinfo-macos.tar.gz envinfo-macos && zip -r -X envinfo-win.zip envinfo-win.exe",
"executable": "pkg package.json",
"format": "prettier --write src/**/*.js",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
"format": "prettier --write src/**/*.*js",
"lint": "eslint src --ext js,mjs",
"lint-fix": "eslint src --fix --ext js,mjs",
"preversion": "npm run test && webpack && git add .",
"postversion": "npm run executable && npm run compress && npm run release",
"release": "github-release upload --owner=tabrindle --repo=envinfo --tag=${npm_package_version} 'envinfo-linux.tar.gz' 'envinfo-macos.tar.gz' 'envinfo-win.zip'",
"start": "node -r esm src/cli.js",
"test": "jest --env=node && eslint src && prettier -l src/**/*.js"
"start": "node src/cli.mjs",
"test": "jest --config jest.config.js && eslint src --ext js,mjs && prettier -l src/**/*.*js"
},
"husky": {
"hooks": {
Expand All @@ -54,41 +54,39 @@
"win"
]
},
"jest": {
"testEnvironment": "node"
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.1",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.4",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"all-contributors-cli": "^4.11.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "23.6.0",
"babel-loader": "^8.0.5",
"eslint": "^5.13.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.7.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.3.1",
"esm": "^3.2.22",
"babel-jest": "^27.4.2",
"babel-loader": "^8.2.3",
"eslint": "^8.4.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"github-release-cli": "^0.4.1",
"glob": "^7.1.6",
"husky": "^4.2.5",
"jest": "^22.4.3",
"minimist": "^1.2.5",
"os-name": "^3.1.0",
"pkg": "^4.5.1",
"prettier": "^1.19.1",
"prettier-eslint-cli": "^4.1.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.1.2",
"jest": "^27.2.0",
"os-name": "^5.0.1",
"pkg": "^5.5.1",
"prettier": "^2.5.1",
"prettier-eslint-cli": "^5.0.1",
"regenerator-runtime": "^0.13.9",
"terser-webpack-plugin": "^5.2.5",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1",
"which": "^1.2.14",
"yamlify-object": "^0.5.1"
"yamlify-object": "^0.5.1",
"yargs": "^16.2.0"
},
"resolutions": {
"lodash": "4.17.15"
Expand Down
1 change: 1 addition & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('regenerator-runtime/runtime')
9 changes: 7 additions & 2 deletions src/cli.js → src/cli.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const argv = require('minimist')(process.argv.slice(2));
import envinfo from './envinfo.mjs';
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs';

const argv = yargs(hideBin(process.argv)).argv;

const version = global.__VERSION__ || ''; // eslint-disable-line

argv.console = true;
Expand Down Expand Up @@ -50,5 +55,5 @@ if (argv.help || argv._.indexOf('help') > -1) {
} else if (argv.version || argv.v || argv._.indexOf('version') > -1) {
console.log(version); // eslint-disable-line no-console
} else {
require('./envinfo').cli(argv); // eslint-disable-line global-require
envinfo.cli(argv);
}
20 changes: 9 additions & 11 deletions src/envinfo.js → src/envinfo.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

const helpers = require('./helpers');
const formatters = require('./formatters');
const presets = require('./presets');
const utils = require('./utils');
import formatters from './formatters.mjs';
import helpers from './helpers/index.mjs';
import presets from './presets.mjs';
import utils from './utils.mjs';

function format(data, options) {
// set the default formatter (yaml is default, similar to old table)
Expand Down Expand Up @@ -140,9 +138,9 @@ function run(args, options) {
return main(args, options);
}

module.exports = {
cli: cli,
helpers: helpers,
main: main,
run: run,
export default {
cli,
helpers,
main,
run,
};
6 changes: 3 additions & 3 deletions src/formatters.js → src/formatters.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const yamlify = require('yamlify-object');
const utils = require('./utils');
import utils from './utils.mjs';
import yamlify from 'yamlify-object';

function clean(data, options) {
utils.log('trace', 'clean', data);
Expand Down Expand Up @@ -195,7 +195,7 @@ function formatToJson(data, options) {
return data;
}

module.exports = {
export default {
json: formatToJson,
markdown: formatToMarkdown,
yaml: formatToYaml,
Expand Down
11 changes: 5 additions & 6 deletions src/helpers/binaries.js → src/helpers/binaries.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const utils = require('../utils');
import utils from '../utils.mjs';

module.exports = {
export default {
getNodeInfo: () => {
utils.log('trace', 'getNodeInfo');
return Promise.all([
Expand Down Expand Up @@ -33,9 +33,8 @@ module.exports = {

getYarnInfo: () => {
utils.log('trace', 'getYarnInfo');
return Promise.all([
utils.run('yarn -v'),
utils.which('yarn').then(utils.condensePath),
]).then(v => utils.determineFound('Yarn', v[0], v[1]));
return Promise.all([utils.run('yarn -v'), utils.which('yarn').then(utils.condensePath)]).then(
v => utils.determineFound('Yarn', v[0], v[1])
);
},
};
14 changes: 8 additions & 6 deletions src/helpers/browsers.js → src/helpers/browsers.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require('fs');
const os = require('os');
const utils = require('../utils');
const path = require('path');
import fs from 'fs';
import os from 'os';
import path from 'path';
import utils from '../utils.mjs';

module.exports = {
export default {
getBraveBrowserInfo: () => {
utils.log('trace', 'getBraveBrowser');
let braveVersion;
Expand Down Expand Up @@ -156,7 +156,9 @@ module.exports = {
'iexplore.exe',
].join('\\\\');
explorerVersion = utils
.run(`wmic datafile where "name='${explorerPath}'" get Version`)
.run(
`powershell -command "(Get-ItemProperty -LiteralPath '${explorerPath}').VersionInfo | Format-Table -Property FileVersion -HideTableHeaders"`
)
.then(utils.findVersion);
} else {
explorerVersion = Promise.resolve('N/A');
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/databases.js → src/helpers/databases.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const utils = require('../utils');
import utils from '../utils.mjs';

module.exports = {
export default {
getMongoDBInfo: () => {
utils.log('trace', 'getMongoDBInfo');
return Promise.all([
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/ides.js → src/helpers/ides.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const utils = require('../utils');
import path from 'path';
import utils from '../utils.mjs';

module.exports = {
export default {
getAndroidStudioInfo: () => {
let androidStudioVersion = Promise.resolve('N/A');
if (utils.isMacOS) {
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = {
androidStudioVersion = Promise.all([
utils
.run(
'wmic datafile where name="C:\\\\Program Files\\\\Android\\\\Android Studio\\\\bin\\\\studio.exe" get Version'
'powershell -command "(Get-ItemProperty -LiteralPath \'C:\\\\Program Files\\\\Android\\\\Android Studio\\\\bin\\\\studio.exe\').VersionInfo | Format-Table -Property FileVersion -HideTableHeaders"'
)
.then(version => version.replace(/(\r\n|\n|\r)/gm, '')),
utils
Expand Down
Loading