Skip to content

Commit

Permalink
Make package ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
knutkirkhorn committed Feb 20, 2023
1 parent e613364 commit e7db3a1
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 111 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
79 changes: 32 additions & 47 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
4,
{"SwitchCase": 1}
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"linebreak-style": "off",
"arrow-parens": [
"error",
"as-needed"
],
"object-curly-spacing": [
"error",
"never"
],
"comma-dangle": [
"error",
"never"
],
"no-console": "off",
"max-len": "off",
"no-plusplus": "off",
"strict": "off",
"consistent-return": "off",
"no-loop-func": "off",
"no-shadow": "off"
}
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"airbnb-base",
"plugin:ava/recommended",
"plugin:import/recommended",
"plugin:unicorn/recommended"
],
"parserOptions": {
"ecmaVersion": 2023,
"sourceType": "module"
},
"rules": {
"indent": ["error", "tab", {"SwitchCase": 1}],
"no-tabs": "off",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"linebreak-style": "off",
"arrow-parens": ["error", "as-needed"],
"object-curly-spacing": ["error", "never"],
"comma-dangle": ["error", "never"],
"no-console": "off",
"max-len": "off",
"no-plusplus": "off",
"strict": "off",
"consistent-return": "off",
"no-loop-func": "off",
"no-shadow": "off"
}
}
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ jobs:
strategy:
matrix:
node-version:
- 14
- 12
- 10
- 18
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
## Installation

```
$ npm install --global square-and-multiply-cli
npm install --global square-and-multiply-cli
```

## Usage

```
$ square-and-multiply --help
Usage
$ square-and-multiply <base> <exponent> <modulus>
Examples
$ square-and-multiply 14 27 37
$ square-and-multiply 23 22 86
Usage
$ square-and-multiply <base> <exponent> <modulus>
Examples
$ square-and-multiply 14 27 37
$ square-and-multiply 23 22 86
```

## Related
Expand Down
24 changes: 11 additions & 13 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
#!/usr/bin/env node

'use strict';

const squareAndMultiply = require('square-and-multiply');
const meow = require('meow');
import squareAndMultiply from 'square-and-multiply';
import meow from 'meow';

const cli = meow(`
Usage
$ square-and-multiply <base> <exponent> <modulus>
Examples
$ square-and-multiply 14 27 37
$ square-and-multiply 23 22 86
`);
Usage
$ square-and-multiply <base> <exponent> <modulus>
Examples
$ square-and-multiply 14 27 37
$ square-and-multiply 23 22 86
`, {importMeta: import.meta});

const basis = cli.input[0];
const exponent = cli.input[1];
const modulus = cli.input[2];

if (!(basis && exponent && modulus)) {
console.log('You need to specify all three numbers.');
process.exit(1);
console.log('You need to specify all three numbers.');
process.exit(1);
}

console.log(squareAndMultiply(basis, exponent, modulus));
77 changes: 42 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
{
"name": "square-and-multiply-cli",
"version": "2.0.1",
"description": "Get the square and multiply CLI",
"repository": "knutkirkhorn/square-and-multiply-cli",
"bin": {
"square-and-multiply": "cli.js"
},
"main": "index.js",
"scripts": {
"test": "ava",
"lint": "eslint ."
},
"files": [
"cli.js"
],
"keywords": [
"square",
"and",
"multiply",
"math",
"cli"
],
"author": "Knut Kirkhorn",
"license": "MIT",
"dependencies": {
"meow": "^8.1.0",
"square-and-multiply": "^1.0.5"
},
"devDependencies": {
"ava": "^3.15.0",
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"execa": "^5.0.0"
}
"name": "square-and-multiply-cli",
"version": "2.0.1",
"description": "Get the square and multiply CLI",
"repository": "knutkirkhorn/square-and-multiply-cli",
"bin": {
"square-and-multiply": "cli.js"
},
"scripts": {
"test": "ava",
"lint": "eslint ."
},
"files": [
"cli.js"
],
"keywords": [
"square",
"and",
"multiply",
"math",
"cli"
],
"author": "Knut Kirkhorn",
"type": "module",
"exports": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=14.16"
},
"license": "MIT",
"dependencies": {
"meow": "^11.0.0",
"square-and-multiply": "^2.0.0"
},
"devDependencies": {
"ava": "^5.2.0",
"eslint": "^8.34.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unicorn": "^45.0.2",
"execa": "^7.0.0"
}
}
9 changes: 5 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const test = require('ava');
const execa = require('execa');
// eslint-disable-next-line import/no-unresolved
import test from 'ava';
import {execa} from 'execa';

test('outprint something', async t => {
const {stdout} = await execa('./cli.js', ['--version']);
t.true(stdout.length > 0);
const {stdout} = await execa('./cli.js', ['--version']);
t.true(stdout.length > 0);
});

0 comments on commit e7db3a1

Please sign in to comment.