Skip to content

Commit

Permalink
Merge pull request #302 from terascope/convert-to-esm
Browse files Browse the repository at this point in the history
Convert to esm
  • Loading branch information
jsnoble authored Aug 1, 2024
2 parents d04abef + 42f8451 commit 8be5fc9
Show file tree
Hide file tree
Showing 20 changed files with 915 additions and 1,264 deletions.
12 changes: 10 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"extends": "@terascope",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/naming-convention": "off"
}
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-duplicate-enum-values": "warn",
"import/extensions": "off",
"import/no-import-module-exports": "off"
},
"ignorePatterns":[]
}
8 changes: 5 additions & 3 deletions bin/fetch-github-release
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from "node:url";

var path = require('path');
var fs = require('fs');
require(path.join(path.dirname(fs.realpathSync(__filename)), '../dist/src/cli'));
const filename = fileURLToPath(import.meta.url);
import(path.join(path.dirname(fs.realpathSync(filename)), '../dist/src/cli.js'));
14 changes: 9 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = {
export default {
verbose: true,
testEnvironment: 'node',
setupFilesAfterEnv: ['jest-extended/all'],
Expand All @@ -18,13 +16,19 @@ module.exports = {
'<rootDir>/test/**/*-spec.{ts,js}',
'<rootDir>/test/*-spec.{ts,js}',
],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
},
preset: 'ts-jest',
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
tsconfig: './tsconfig.json',
diagnostics: true,
useESM: true
},
ignoreDirectories: ['dist'],
availableExtensions: ['.js', '.ts']
}
availableExtensions: ['.js', '.ts', '.mjs']
},
testTimeout: 60 * 1000
};
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"publishConfig": {
"access": "public"
},
"version": "0.8.11",
"version": "1.0.0",
"description": "Download a specific release from github",
"type": "module",
"files": [
"dist/src/**/*",
"bin/*"
Expand All @@ -17,10 +18,10 @@
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"lint:fix": "yarn lint --fix",
"setup": "yarn && yarn build",
"test": "jest",
"test:cov": "jest --collectCoverage",
"test:watch": "jest --coverage=false --notify --watch --onlyChanged",
"test:debug": "env DEBUG=\"${DEBUG:-*teraslice*}\" jest --detectOpenHandles --coverage=false --runInBand",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
"test:cov": "NODE_OPTIONS='--experimental-vm-modules' jest --collectCoverage",
"test:watch": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage=false --notify --watch --onlyChanged",
"test:debug": "NODE_OPTIONS='--experimental-vm-modules' env DEBUG=\"${DEBUG:-*teraslice*}\" jest --detectOpenHandles --coverage=false --runInBand",
"check": "yarn run lint && yarn run test",
"clean": "rimraf dist coverage",
"prepublishOnly": "yarn run clean && yarn run build"
Expand Down Expand Up @@ -51,19 +52,20 @@
},
"devDependencies": {
"@terascope/eslint-config": "^0.8.0",
"@types/jest": "^27.0.2",
"@types/node": "^18.14.2",
"@types/jest": "^29.5.12",
"@types/multi-progress": "^2.0.6",
"@types/node": "^22.0.2",
"@types/stream-buffers": "^3.0.4",
"@types/tmp": "^0.2.1",
"eslint": "^8.1.0",
"jest": "^27.2.4",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"nock": "^13.0.2",
"node-notifier": "^10.0.0",
"rimraf": "^5.0.7",
"stream-buffers": "^3.0.0",
"tmp": "0.2.3",
"ts-jest": "^27.0.5",
"ts-jest": "^29.2.4",
"typescript": "^4.4.3"
}
}
9 changes: 6 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import yargs from 'yargs';
import { downloadRelease } from './downloadRelease';
import { GithubRelease, GithubReleaseAsset } from './interfaces';
import { hideBin } from 'yargs/helpers';
import { downloadRelease } from './downloadRelease.js';
import { GithubRelease, GithubReleaseAsset } from './interfaces.js';

const command = yargs
const command = await yargs(hideBin(process.argv))
.alias('h', 'help')
.alias('v', 'version')
.option('prerelease', {
description: 'download prerelease',
type: 'boolean',
Expand Down
10 changes: 5 additions & 5 deletions src/download.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import http from 'http';
import https from 'https';
import { Writable } from 'stream';
import URL from 'url';
import http from 'node:http';
import https from 'node:https';
import { Writable } from 'node:stream';
import URL from 'node:url';

const { GITHUB_TOKEN } = process.env;

function getRequestOptions(urlString: string) {
const url = URL.parse(urlString);
const headers: Record<string, string> = {
Accept: 'application/octet-stream',
UserAgent: '@terascope/fetch-github-release',
'User-Agent': '@terascope/fetch-github-release',
};

if (GITHUB_TOKEN) {
Expand Down
17 changes: 8 additions & 9 deletions src/downloadRelease.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import os from 'os';
import fs from 'fs';
import path from 'path';
import os from 'node:os';
import fs from 'node:fs';
import path from 'node:path';
import extract from 'extract-zip';
import { getReleases } from './getReleases';
import { getLatest } from './getLatest';
import { download } from './download';
import { rpad } from './rpad';
import MultiProgress from 'multi-progress';
import { getReleases } from './getReleases.js';
import { getLatest } from './getLatest.js';
import { download } from './download.js';
import { rpad } from './rpad.js';
import { GithubRelease, GithubReleaseAsset } from './interfaces';

function pass() {
return true;
}

const MultiProgress = require('multi-progress');

/**
* Download a specific github release
* @param user The name of the github user or organization
Expand Down
2 changes: 1 addition & 1 deletion src/getLatest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GithubRelease, GithubReleaseAsset } from './interfaces';
import { GithubRelease, GithubReleaseAsset } from './interfaces.js';

function pass() {
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/getReleases.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import got, { OptionsOfJSONResponseBody } from 'got';
import { GithubRelease } from './interfaces';
import { GithubRelease } from './interfaces.js';

const { GITHUB_TOKEN } = process.env;

Expand All @@ -8,7 +8,7 @@ export async function getReleases(user: string, repo: string): Promise<GithubRel

const requestConfig: OptionsOfJSONResponseBody = {
headers: {
UserAgent: '@terascope/fetch-github-release'
'User-Agent': '@terascope/fetch-github-release'
} as Record<string, string>,
responseType: 'json'
};
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { downloadRelease } from './downloadRelease';
import { HTTPError } from './getReleases';
import { downloadRelease } from './downloadRelease.js';
import { HTTPError } from './getReleases.js';

export { downloadRelease, HTTPError };
5 changes: 3 additions & 2 deletions test/download-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { jest } from '@jest/globals';
import nock from 'nock';
import streamBuffers from 'stream-buffers';
import { download } from '../src/download';
import { nockServer, fileTxt } from './utils/nockServer';
import { download } from '../src/download.js';
import { nockServer, fileTxt } from './utils/nockServer.js';

describe('#download()', () => {
beforeEach(nockServer);
Expand Down
10 changes: 5 additions & 5 deletions test/downloadRelease-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import nock from 'nock';
import tmp from 'tmp';
import { downloadRelease } from '../src/downloadRelease';
import { nockServer, fileTxt, fileZip } from './utils/nockServer';
import { GithubReleaseAsset } from '../src/interfaces';
import { downloadRelease } from '../src/downloadRelease.js';
import { nockServer, fileTxt, fileZip } from './utils/nockServer.js';
import { GithubReleaseAsset } from '../src/interfaces.js';

describe('#downloadRelease()', () => {
let tmpobj: tmp.DirResult;
Expand Down
6 changes: 3 additions & 3 deletions test/extract-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import tmp from 'tmp';
import extract from 'extract-zip';
import { fileZip, fileTxt } from './utils/nockServer';
import { fileZip, fileTxt } from './utils/nockServer.js';

describe('#extract()', () => {
let tmpobj: tmp.DirResult;
Expand Down
4 changes: 2 additions & 2 deletions test/getLatest-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'jest-extended';
import { getLatest } from '../src/getLatest';
import { releasesJson } from './utils/nockServer';
import { getLatest } from '../src/getLatest.js';
import { releasesJson } from './utils/nockServer.js';

describe('#getLatest()', () => {
it('gets the latest release', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/getReleases-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nock from 'nock';
import { getReleases } from '../src/getReleases';
import { nockServer, releasesJson } from './utils/nockServer';
import { getReleases } from '../src/getReleases.js';
import { nockServer, releasesJson } from './utils/nockServer.js';

describe('#getReleases()', () => {
beforeEach(nockServer);
Expand Down
2 changes: 1 addition & 1 deletion test/index-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'jest-extended';
import { downloadRelease } from '../src';
import { downloadRelease } from '../src/index.js';

describe('fetch-github-release', () => {
it('should expose a function', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/rpad-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rpad } from '../src/rpad';
import { rpad } from '../src/rpad.js';

describe('#rpad()', () => {
it('adds right padding to a string', () => {
Expand Down
12 changes: 7 additions & 5 deletions test/utils/nockServer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import nock from 'nock';
import { fileURLToPath } from 'node:url';

const dirname = path.dirname(fileURLToPath(import.meta.url));
export const releasesJson = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '../fixtures/releases.json'), 'utf8')
fs.readFileSync(path.resolve(dirname, '../fixtures/releases.json'), 'utf8')
);
export const fileTxt = fs.readFileSync(path.resolve(__dirname, '../fixtures/file.txt'), 'utf8');
export const fileZip = fs.readFileSync(path.resolve(__dirname, '../fixtures/file.zip'));
export const fileTxt = fs.readFileSync(path.resolve(dirname, '../fixtures/file.txt'), 'utf8');
export const fileZip = fs.readFileSync(path.resolve(dirname, '../fixtures/file.zip'));

export function nockServer(): void {
nock('https://api.github.com')
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "dist",
"module": "commonjs",
"module": "ESNext",
"moduleResolution": "node",
"target": "es2019",
"target": "ESNext",
"skipLibCheck": true,
"experimentalDecorators": true,
"declaration": true,
Expand All @@ -16,7 +16,8 @@
"noImplicitReturns": true,
"preserveConstEnums": true,
"esModuleInterop": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["jest", "jest-extended"]
},
"include": [
"src/**/*",
Expand Down
Loading

0 comments on commit 8be5fc9

Please sign in to comment.