Skip to content

Commit

Permalink
feat: Convert to ESM (#297)
Browse files Browse the repository at this point in the history
* feat: Convert to ESM

* fix: Adjusting linting to ESM module structure

Co-authored-by: Trygve Lie <trygve.lie@finn.no>
  • Loading branch information
trygve-lie and Trygve Lie authored Jan 7, 2022
1 parent 3ebd04d commit 86c5cb3
Show file tree
Hide file tree
Showing 85 changed files with 547 additions and 688 deletions.
15 changes: 12 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"parser": "@babel/eslint-parser",
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module",
"requireConfigFile": false
},
"rules": {
"strict": [0, "global"],
"import/prefer-default-export": "off",
"import/extensions": ["error", {
"js": "ignorePackages"
}
],
"class-methods-use-this": [0],
"no-underscore-dangle": [0],
"no-restricted-syntax": [0],
"import/extensions": [0]
"no-restricted-syntax": [0]
}
}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
6 changes: 2 additions & 4 deletions examples/auth.post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/map.alias.delete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/map.alias.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/map/buzz/v4', {
method: 'GET',
Expand Down
6 changes: 2 additions & 4 deletions examples/map.alias.post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/map.alias.put.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/map.etag.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

const get = async () => {

Expand Down
4 changes: 1 addition & 3 deletions examples/map.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/map/buzz/4.2.2', {
method: 'GET',
Expand Down
8 changes: 3 additions & 5 deletions examples/map.put.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
const fs = require('fs');
import FormData from 'form-data';
import fetch from 'node-fetch';
import fs from 'node:fs';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/npm.alias.delete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/npm.alias.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/npm/fuzz/v8/main/index.js', {
method: 'GET',
Expand Down
6 changes: 2 additions & 4 deletions examples/npm.alias.post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/npm.alias.put.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/npm.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/npm/fuzz/8.4.1/main/index.js', {
method: 'GET',
Expand Down
8 changes: 3 additions & 5 deletions examples/npm.put.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
const fs = require('fs');
import FormData from 'form-data';
import fetch from 'node-fetch';
import fs from 'node:fs';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/pkg.alias.delete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/pkg.alias.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/pkg/fuzz/v8/main/index.js', {
method: 'GET',
Expand Down
6 changes: 2 additions & 4 deletions examples/pkg.alias.post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
6 changes: 2 additions & 4 deletions examples/pkg.alias.put.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
import FormData from 'form-data';
import fetch from 'node-fetch';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions examples/pkg.etag.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

const get = async () => {

Expand Down
4 changes: 1 addition & 3 deletions examples/pkg.get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const fetch = require('node-fetch');
import fetch from 'node-fetch';

fetch('http://localhost:4001/pkg/fuzz/8.4.1/main/index.js', {
method: 'GET',
Expand Down
8 changes: 3 additions & 5 deletions examples/pkg.put.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

'use strict';

const FormData = require('form-data');
const fetch = require('node-fetch');
const fs = require('fs');
import FormData from 'form-data';
import fetch from 'node-fetch';
import fs from 'node:fs';

const authenticate = async (address) => {
const formData = new FormData();
Expand Down
5 changes: 2 additions & 3 deletions lib/classes/alias.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const Alias = class Alias {
constructor({ name = '', type = '', alias = '', org = '' } = {}) {
this._version = '';
Expand Down Expand Up @@ -47,4 +45,5 @@ const Alias = class Alias {
return 'Alias';
}
}
module.exports = Alias;

export default Alias;
9 changes: 4 additions & 5 deletions lib/classes/asset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const mime = require('mime/lite');
const path = require('path');
import mime from 'mime';
import path from 'node:path';

/**
* Meta information about an Asset.
Expand Down Expand Up @@ -95,4 +93,5 @@ const Asset = class Asset {
return 'Asset';
}
}
module.exports = Asset;

export default Asset;
5 changes: 2 additions & 3 deletions lib/classes/author.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const Author = class Author {
constructor({ name = '', user = '' } = {}) {
this._name = name;
Expand All @@ -25,4 +23,5 @@ const Author = class Author {
return 'Author';
}
}
module.exports = Author;

export default Author;
5 changes: 2 additions & 3 deletions lib/classes/http-incoming.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* A bearer object to hold misc data through a http
* request / response cyclus.
Expand Down Expand Up @@ -70,4 +68,5 @@ const HttpIncoming = class HttpIncoming {
return 'HttpIncoming';
}
};
module.exports = HttpIncoming;

export default HttpIncoming;
6 changes: 2 additions & 4 deletions lib/classes/http-outgoing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const { stream } = require('@eik/common');
import { stream } from '@eik/common';

const STATUS_CODES = [
100, 101, 102, 103,
Expand Down Expand Up @@ -88,4 +86,4 @@ const HttpOutgoing = class HttpOutgoing {
return 'HttpOutgoing';
}
}
module.exports = HttpOutgoing;
export default HttpOutgoing;
5 changes: 2 additions & 3 deletions lib/classes/meta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const Meta = class Meta {
constructor({
value = '',
Expand Down Expand Up @@ -28,4 +26,5 @@ const Meta = class Meta {
return 'Meta';
}
}
module.exports = Meta;

export default Meta;
Loading

0 comments on commit 86c5cb3

Please sign in to comment.