Skip to content

Commit

Permalink
Merge pull request #562 from eik-lib/convert_codebase_to_esm
Browse files Browse the repository at this point in the history
chore: convert codebase to ESM
  • Loading branch information
digitalsadhu authored Jul 31, 2024
2 parents 59bb4f2 + 94924bc commit 0e892f5
Show file tree
Hide file tree
Showing 64 changed files with 410 additions and 502 deletions.
14 changes: 8 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"extends": ["airbnb-base", "prettier"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier"],
"rules": {
"strict": [0, "global"],
"class-methods-use-this": [0],
"no-restricted-syntax": [0],
"default-param-last": [0]
"env": { "es6": true, "node": true },
"parser": "@babel/eslint-parser",
"ignorePatterns": ["build", "public"],
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 2020,
"sourceType": "module"
}
}
18 changes: 8 additions & 10 deletions classes/alias.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
import assert from 'assert';
import abslog from 'abslog';
import { join } from 'path';
import { schemas, validators } from '@eik/common';
import { request } from '../utils/http/index.js';
import { typeSlug } from '../utils/index.js';

const assert = require('assert');
const abslog = require('abslog');
const { join } = require('path');
const { schemas, validators } = require('@eik/common');
const { request } = require('../utils/http');
const { typeSlug } = require('../utils');

module.exports = class Alias {
export default class Alias {
constructor({ logger, server, token, type, name, version, alias } = {}) {
this.log = abslog(logger);
this.server = server;
Expand Down Expand Up @@ -121,4 +119,4 @@ module.exports = class Alias {
}
}
}
};
}
22 changes: 10 additions & 12 deletions classes/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict';

const Ping = require('./ping');
const Alias = require('./alias');
const Meta = require('./meta');
const Login = require('./login');
const PublishMap = require('./publish/map');
const PublishPackage = require('./publish/package/index');
const Integrity = require('./integrity');
const Version = require('./version');

module.exports = {
import Ping from './ping.js';
import Alias from './alias.js';
import Meta from './meta.js';
import Login from './login.js';
import PublishMap from './publish/map.js';
import PublishPackage from './publish/package/index.js';
import Integrity from './integrity.js';
import Version from './version.js';

export default {
ping(opts) {
return new Ping(opts).run();
},
Expand Down
16 changes: 7 additions & 9 deletions classes/integrity.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-plusplus */
import abslog from 'abslog';
import { join } from 'path';
import eik from '@eik/common';
import { typeSlug } from '../utils/index.js';

'use strict';
const { schemas, ValidationError } = eik;

const abslog = require('abslog');
const { join } = require('path');
const { schemas, ValidationError } = require('@eik/common');
const fetch = require('node-fetch');
const { typeSlug } = require('../utils');

module.exports = class Integrity {
export default class Integrity {
constructor({
logger,
name,
Expand Down Expand Up @@ -93,4 +91,4 @@ module.exports = class Integrity {
);
}
}
};
}
12 changes: 6 additions & 6 deletions classes/login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
import abslog from 'abslog';
import eik from '@eik/common';
import { request } from '../utils/http/index.js';

const abslog = require('abslog');
const { schemas, ValidationError } = require('@eik/common');
const { request } = require('../utils/http');
const { schemas, ValidationError } = eik;

module.exports = class Login {
export default class Login {
constructor({ logger, server, key } = {}) {
this.log = abslog(logger);
this.server = server;
Expand Down Expand Up @@ -46,4 +46,4 @@ module.exports = class Login {
}
}
}
};
}
14 changes: 5 additions & 9 deletions classes/meta.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-plusplus */

'use strict';

const abslog = require('abslog');
const { join } = require('path');
const { schemas } = require('@eik/common');
const fetch = require('node-fetch');
import abslog from 'abslog';
import { join } from 'path';
import { schemas } from '@eik/common';

const types = ['pkg', 'map', 'npm'];

module.exports = class Meta {
export default class Meta {
constructor({ logger, server, name, version } = {}) {
this.log = abslog(logger);
this.server = server;
Expand Down Expand Up @@ -90,4 +86,4 @@ module.exports = class Meta {
return false;
}
}
};
}
11 changes: 4 additions & 7 deletions classes/ping.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';
import abslog from 'abslog';
import { schemas } from '@eik/common';

const fetch = require('node-fetch');
const abslog = require('abslog');
const { schemas } = require('@eik/common');

module.exports = class Ping {
export default class Ping {
constructor({ logger, server } = {}) {
this.log = abslog(logger);
this.server = server;
Expand Down Expand Up @@ -48,4 +45,4 @@ module.exports = class Ping {
}
}
}
};
}
18 changes: 8 additions & 10 deletions classes/publish/map.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';
import assert from 'assert';
import abslog from 'abslog';
import { join, parse, isAbsolute } from 'path';
import { existsSync } from 'fs';
import { schemas } from '@eik/common';
import { request } from '../../utils/http/index.js';

const assert = require('assert');
const abslog = require('abslog');
const { join, parse, isAbsolute } = require('path');
const { existsSync } = require('fs');
const { schemas } = require('@eik/common');
const { request } = require('../../utils/http');

module.exports = class PublishMap {
export default class PublishMap {
constructor({
logger,
cwd = process.cwd(),
Expand Down Expand Up @@ -93,4 +91,4 @@ module.exports = class PublishMap {
}
}
}
};
}
32 changes: 15 additions & 17 deletions classes/publish/package/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
'use strict';
import abslog from 'abslog';
import { join, isAbsolute } from 'path';
import { EikConfig } from '@eik/common';
import { typeSlug } from '../../../utils/index.js';
import ValidateInput from './tasks/validate-input.js';
import CreateTempDirectory from './tasks/create-temp-directory.js';
import CreateZipFile from './tasks/create-zip-file.js';
import CheckBundleSizes from './tasks/check-bundle-sizes.js';
import DryRun from './tasks/dry-run.js';
import CheckIfAlreadyPublished from './tasks/check-if-already-published.js';
import UploadFiles from './tasks/upload-files.js';
import SaveMetafile from './tasks/save-metafile.js';
import Cleanup from './tasks/cleanup.js';

const abslog = require('abslog');
const { join, isAbsolute } = require('path');
const { EikConfig } = require('@eik/common');
const { typeSlug } = require('../../../utils');
const ValidateInput = require('./tasks/validate-input');
const CreateTempDirectory = require('./tasks/create-temp-directory');
const CreateZipFile = require('./tasks/create-zip-file');
const CheckBundleSizes = require('./tasks/check-bundle-sizes');
const DryRun = require('./tasks/dry-run');
const CheckIfAlreadyPublished = require('./tasks/check-if-already-published');
const UploadFiles = require('./tasks/upload-files');
const SaveMetafile = require('./tasks/save-metafile');
const Cleanup = require('./tasks/cleanup');

module.exports = class Publish {
export default class Publish {
constructor({
logger,
cwd = process.cwd(),
Expand Down Expand Up @@ -131,4 +129,4 @@ module.exports = class Publish {
...response,
};
}
};
}
16 changes: 6 additions & 10 deletions classes/publish/package/tasks/check-bundle-sizes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* eslint-disable no-await-in-loop */
import bytes from 'bytes';
import fs from 'fs';
import gzipSize from 'gzip-size';
import Task from './task.js';

'use strict';

const bytes = require('bytes');
const fs = require('fs');
const gzipSize = require('gzip-size');
const Task = require('./task');

module.exports = class CheckBundleSizes extends Task {
export default class CheckBundleSizes extends Task {
async process() {
this.log.debug('Checking bundle file sizes');
try {
Expand All @@ -25,4 +21,4 @@ module.exports = class CheckBundleSizes extends Task {
throw new Error(`Failed to check bundle sizes: ${err.message}`);
}
}
};
}
18 changes: 7 additions & 11 deletions classes/publish/package/tasks/check-if-already-published.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/* eslint-disable no-param-reassign */
import { join } from 'path';
import { integrity, versions } from '../../../../utils/http/index.js';
import hash from '../../../../utils/hash/index.js';
import { typeSlug } from '../../../../utils/index.js';
import Task from './task.js';

'use strict';

const { join } = require('path');
const { integrity, versions } = require('../../../../utils/http');
const hash = require('../../../../utils/hash');
const { typeSlug } = require('../../../../utils');
const Task = require('./task');

module.exports = class CheckIfAlreadyPublished extends Task {
export default class CheckIfAlreadyPublished extends Task {
async process() {
const { log, path } = this;
const { server, name, version, files, type } = this.config;
Expand Down Expand Up @@ -84,4 +80,4 @@ module.exports = class CheckIfAlreadyPublished extends Task {

return localHash;
}
};
}
14 changes: 6 additions & 8 deletions classes/publish/package/tasks/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';
import { join } from 'path';
import fs from 'fs';
import rimraf from 'rimraf';
import Task from './task.js';

const { join } = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const Task = require('./task');

module.exports = class Cleanup extends Task {
export default class Cleanup extends Task {
async process() {
const { log, path } = this;
log.debug('Cleaning up');
Expand All @@ -16,4 +14,4 @@ module.exports = class Cleanup extends Task {
.forEach((file) => rimraf.sync(join(path, file)));
}
}
};
}
11 changes: 4 additions & 7 deletions classes/publish/package/tasks/create-temp-directory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable max-classes-per-file */

'use strict';

const mkdir = require('make-dir');
const Task = require('./task');
import mkdir from 'make-dir';
import Task from './task.js';

class IOError extends Error {
constructor(message, err) {
Expand All @@ -13,7 +10,7 @@ class IOError extends Error {
}
}

module.exports = class CreateTempDir extends Task {
export default class CreateTempDir extends Task {
async process() {
const { log, path } = this;

Expand All @@ -26,4 +23,4 @@ module.exports = class CreateTempDir extends Task {
throw new IOError('Unable to create temp dir', err);
}
}
};
}
15 changes: 6 additions & 9 deletions classes/publish/package/tasks/create-zip-file.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* eslint-disable no-plusplus */
/* eslint-disable no-await-in-loop */

'use strict';

const fs = require('fs');
const { join, resolve, basename, dirname } = require('path');
const tar = require('tar');
const Task = require('./task');
import fs from 'fs';
import { join, resolve, basename, dirname } from 'path';
import tar from 'tar';
import Task from './task.js';

const { copyFileSync, writeFileSync } = fs;

module.exports = class CreateZipFile extends Task {
export default class CreateZipFile extends Task {
async process() {
const { log, path } = this;
const { name, map, server, out, files } = this.config;
Expand Down Expand Up @@ -80,4 +77,4 @@ module.exports = class CreateZipFile extends Task {
throw new Error(`Unable to create zip file: ${err.message}`);
}
}
};
}
11 changes: 4 additions & 7 deletions classes/publish/package/tasks/dry-run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* eslint-disable no-param-reassign */
import { join } from 'path';
import Task from './task.js';

'use strict';

const { join } = require('path');
const Task = require('./task');

module.exports = class DryRun extends Task {
export default class DryRun extends Task {
async process(zipFile) {
const { path } = this;

Expand All @@ -23,4 +20,4 @@ module.exports = class DryRun extends Task {

return files;
}
};
}
Loading

0 comments on commit 0e892f5

Please sign in to comment.