Skip to content

Commit 1023dc4

Browse files
author
Stefan Buck
committed
Convert to esmodules
1 parent b0b86ad commit 1023dc4

21 files changed

+88
-92
lines changed

devserver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const http = require('http');
2-
const handler = require('./src/handler');
1+
import http from 'http';
2+
import handler from './src/handler';
33

44
http.createServer((req, res) => handler(req, res))
55
.listen(3000);

functional.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const http = require('http');
2-
const got = require('got');
3-
4-
const handler = require('./src/handler');
1+
import http from 'http';
2+
import got from 'got';
3+
import handler from './src/handler';
54

65
describe('functional', () => {
76
let server;

scripts/update-mapping-files.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const got = require('got');
6-
const jsdom = require('jsdom'); // eslint-disable-line import/no-extraneous-dependencies
3+
import fs from 'fs';
4+
5+
import path from 'path';
6+
import got from 'got';
7+
import jsdom from 'jsdom'; // eslint-disable-line import/no-extraneous-dependencies
78

89
const { JSDOM } = jsdom;
910

src/go.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
const findReachableUrls = require('find-reachable-urls');
2-
const readMeta = require('lets-get-meta');
3-
const got = require('got');
4-
const { tldExists } = require('tldjs');
5-
6-
const cache = require('./utils/cache');
7-
const log = require('./utils/log');
1+
import findReachableUrls from 'find-reachable-urls';
2+
import readMeta from 'lets-get-meta';
3+
import got from 'got';
4+
import { tldExists } from 'tldjs';
5+
import cache from './utils/cache';
6+
import log from './utils/log';
87

98
const getGoMeta = async (url) => {
109
const response = await got.get(url);
@@ -62,7 +61,7 @@ const resolveUrl = async (url) => {
6261
return reachableUrl;
6362
};
6463

65-
module.exports = async function (pkg) {
64+
export default async function (pkg) {
6665
try {
6766
return await resolveUrl(pkg);
6867
} catch (err) {
@@ -73,4 +72,4 @@ module.exports = async function (pkg) {
7372
}
7473
return undefined;
7574
}
76-
};
75+
}

src/handler.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
const { parse } = require('url');
2-
const { json } = require('micro');
3-
const pMap = require('p-map');
4-
5-
const go = require('./go');
6-
const java = require('./java');
7-
const nuget = require('./nuget');
8-
const ping = require('./ping');
9-
const registries = require('./registries');
10-
11-
const log = require('./utils/log');
12-
const cache = require('./utils/cache');
13-
const tracking = require('./utils/tracking');
14-
const preparePayload = require('./utils/payload');
1+
import { parse } from 'url';
2+
import { json } from 'micro';
3+
import pMap from 'p-map';
4+
import go from './go';
5+
import java from './java';
6+
import nuget from './nuget';
7+
import ping from './ping';
8+
import registries from './registries';
9+
import log from './utils/log';
10+
import cache from './utils/cache';
11+
import tracking from './utils/tracking';
12+
import preparePayload from './utils/payload';
1513

1614
const logPrefix = log.prefix;
1715

@@ -50,7 +48,7 @@ function errorHandler(error, res) {
5048

5149
tracking.init();
5250

53-
module.exports = async (req, res) => {
51+
export default async (req, res) => {
5452
if (['POST', 'GET'].includes(req.method)) {
5553
const timingTotalStart = Date.now();
5654

src/java/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const findReachableUrls = require('find-reachable-urls');
2-
const flatMappingList = require('./mapping.json');
3-
const cache = require('../utils/cache');
1+
import findReachableUrls from 'find-reachable-urls';
2+
import flatMappingList from './mapping.json';
3+
import cache from '../utils/cache';
44

55
const SUPPORTED_JAVA_VERSIONS = [9, 8, 7];
66

7-
module.exports = async function (pkg) {
7+
export default async function (pkg) {
88
const targetAsPath = pkg.replace(/\./g, '/');
99
const isBuildIn = !!pkg.match(/^javax?/);
1010

@@ -43,4 +43,4 @@ module.exports = async function (pkg) {
4343
await cache.set(cacheKey, reachableUrl);
4444

4545
return reachableUrl;
46-
};
46+
}

src/nuget.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
const findReachableUrls = require('find-reachable-urls');
2-
const got = require('got');
3-
const isUrl = require('is-url');
4-
const { xml2js } = require('xml-js');
5-
6-
const cache = require('./utils/cache');
7-
const log = require('./utils/log');
8-
const repositoryUrl = require('./registries/repository-url');
1+
import findReachableUrls from 'find-reachable-urls';
2+
import got from 'got';
3+
import isUrl from 'is-url';
4+
import { xml2js } from 'xml-js';
5+
import cache from './utils/cache';
6+
import log from './utils/log';
7+
import repositoryUrl from './registries/repository-url';
98

109
const getLatestVersion = async (pkg) => {
1110
let response;
@@ -80,7 +79,7 @@ const getProjectUrls = async (pkg, version) => {
8079
return urls;
8180
};
8281

83-
module.exports = async (pkg) => {
82+
export default async (pkg) => {
8483
pkg = pkg.toLowerCase();
8584

8685
const cacheKey = `nuget_${pkg}`;

src/ping.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const got = require('got');
2-
const cache = require('./utils/cache');
1+
import got from 'got';
2+
import cache from './utils/cache';
33

44
const ERR_PING_NOT_FOUND = 'ERR_PING_NOT_FOUND';
55

6-
module.exports = async function (url) {
6+
export default async function (url) {
77
const cacheKey = `ping_${url}`;
88

99
const cacheValue = await cache.get(cacheKey);
@@ -28,4 +28,4 @@ module.exports = async function (url) {
2828

2929
return undefined;
3030
});
31-
};
31+
}

src/registries/config.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const config = require('./config.json');
1+
import config from './config.json';
22

33
describe('config.json', () => {
44
const props = ['registry', 'xpaths', 'fallback'];

src/registries/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const util = require('util');
2-
const got = require('got');
3-
const isUrl = require('is-url');
4-
const findReachableUrls = require('find-reachable-urls');
5-
const repositoryUrl = require('./repository-url');
6-
const xpathHelper = require('./xpath-helper');
7-
const registryConfig = require('./config.json');
8-
const cache = require('../utils/cache');
9-
const log = require('../utils/log');
10-
const { prioritiesHost } = require('../utils/url');
1+
import util from 'util';
2+
import got from 'got';
3+
import isUrl from 'is-url';
4+
import findReachableUrls from 'find-reachable-urls';
5+
import repositoryUrl from './repository-url';
6+
import xpathHelper from './xpath-helper';
7+
import registryConfig from './config.json';
8+
import cache from '../utils/cache';
9+
import log from '../utils/log';
10+
import { prioritiesHost } from '../utils/url';
1111

1212
const ERR_PACKAGE_NOT_FOUND = 'ERR_PACKAGE_NOT_FOUND';
1313

@@ -112,7 +112,7 @@ async function resolve(type, packageName) {
112112
return reachableUrl;
113113
}
114114

115-
module.exports = {
115+
export default {
116116
supported: Object.keys(registryConfig),
117117
resolve,
118118
};

0 commit comments

Comments
 (0)