Skip to content

Commit

Permalink
feat(electron-info): Create hybrid module (#83)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
ffflorian and dependabot[bot] authored Apr 9, 2023
1 parent a331830 commit b4a9cd4
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 57 deletions.
7 changes: 6 additions & 1 deletion packages/electron-info/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

# electron-info [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![npm version](https://img.shields.io/npm/v/electron-info.svg?style=flat)](https://www.npmjs.com/package/electron-info)

Get useful data about Electron releases. Uses [electron-releases](https://github.com/electron/releases) in the background.
Get useful data about Electron releases. Uses [electron-releases](https://github.com/electron/releases) in the background.## Prerequisites

- [Node.js](https://nodejs.org) >= 14
- npm (preinstalled) or [yarn](https://classic.yarnpkg.com) < 2

## Installation

ℹ️ This is a hybrid [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) / [ESM](https://nodejs.org/api/esm.html#introduction) module.

Just run `npx electron-info`.

If you'd like to install it permanently, run `yarn global add electron-info` or `npm i -g electron-info`.
Expand Down
32 changes: 20 additions & 12 deletions packages/electron-info/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"author": "Florian Imdahl <git@ffflorian.de>",
"bin": {
"electron-info": "dist/cli.js"
"electron-info": "dist/cjs/cli.js"
},
"dependencies": {
"axios": "1.3.5",
"chalk": "4.1.2",
"chalk": "5.2.0",
"commander": "10.0.0",
"date-fns": "2.29.3",
"logdown": "3.3.1",
Expand All @@ -26,7 +26,13 @@
"uuid": "9.0.0"
},
"engines": {
"node": ">= 10.9"
"node": ">= 14.16"
},
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"files": [
"dist"
Expand All @@ -40,20 +46,22 @@
"typescript"
],
"license": "GPL-3.0",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"name": "electron-info",
"publishConfig": {
"directory": "flattened"
},
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/electron-info",
"scripts": {
"build": "tsc",
"build": "yarn build:cjs && yarn build:mjs && yarn generate:packagejson",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:mjs": "tsc -p tsconfig.json",
"clean": "rimraf dist",
"dist": "yarn clean && yarn build",
"flatten": "node ../publish-flat/dist/cli.js -o flattened",
"postversion": "node ../publish-flat/dist/cli-copy.js -o flattened/package.json version",
"start": "ts-node src/cli.ts -d",
"test": "ts-node -P tsconfig.jasmine.json ../../node_modules/.bin/jasmine"
"flatten": "exit 0",
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
"postversion": "exit 0",
"start": "ts-node-esm src/cli.ts -d",
"test": "ts-node-esm -P tsconfig.jasmine.json ../../node_modules/.bin/jasmine"
},
"type": "module",
"version": "1.18.0"
}
9 changes: 6 additions & 3 deletions packages/electron-info/spec/ElectronInfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
import nock from 'nock';
import * as fs from 'fs-extra';
import * as path from 'path';
import fs from 'fs-extra';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import * as uuid from 'uuid';

import {ElectronInfo, RawReleaseInfo} from '../src/ElectronInfo';
import {ElectronInfo, RawReleaseInfo} from '../src/ElectronInfo.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const tempDir = path.resolve(__dirname, '.temp');
const tempDirDownload = path.resolve(__dirname, '.temp/download');
const mockUrl = 'http://example.com';
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-info/spec/HTTPService.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
import nock from 'nock';

import {HTTPService} from '../src/HTTPService';
import {HTTPService} from '../src/HTTPService.js';

const mockUrl = 'http://example.com';
const FIVE_SECONDS_IN_MILLIS = 5000;
Expand Down
7 changes: 0 additions & 7 deletions packages/electron-info/spec/support/jasmine.json

This file was deleted.

9 changes: 9 additions & 0 deletions packages/electron-info/spec/support/jasmine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config: jasmine.JasmineConfig = {
helpers: ['helpers/**/*.ts'],
random: true,
spec_dir: 'spec',
spec_files: ['**/*test.ts'],
stopSpecOnExpectationFailure: true,
};

export default config;
24 changes: 12 additions & 12 deletions packages/electron-info/src/ElectronInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Chalk, bold as chalkBold} from 'chalk';
import chalk from 'chalk';
import {format as formatDate} from 'date-fns';
import {table as createTable} from 'table';
import logdown from 'logdown';
import * as semver from 'semver';

import {FileService} from './FileService';
import {FileService} from './FileService.js';

export interface RawDeps {
chrome: string;
Expand Down Expand Up @@ -157,27 +157,27 @@ export class ElectronInfo {

private buildRawTables(releases: RawReleaseInfo[], colored?: boolean): string[][][] {
this.logger.log('Building raw tables:', {colored, releasesLength: releases.length});
const coloredOrNot = (text: string, style: Chalk): string => (colored ? style(text) : text);
const coloredOrNot = (text: string, style: typeof chalk): string => (colored ? style(text) : text);

return releases.map(release => {
const electronVersion = `${release.version}${release.prerelease ? ' (prerelease)' : ''}`;
const parsedDate = new Date(release.published_at);
const releaseDate = formatDate(parsedDate, 'yyyy-MM-dd');
const table = [
[coloredOrNot('Electron', chalkBold), electronVersion],
[coloredOrNot('Published on', chalkBold), releaseDate],
[coloredOrNot('Electron', chalk.bold), electronVersion],
[coloredOrNot('Published on', chalk.bold), releaseDate],
];

if (release.deps) {
table.push(
[coloredOrNot(SupportedDependencies.node, chalkBold.red), release.deps.node],
[coloredOrNot(SupportedDependencies.chrome, chalkBold.green), release.deps.chrome],
[coloredOrNot(SupportedDependencies.openssl, chalkBold.blue), release.deps.openssl],
[coloredOrNot(SupportedDependencies.modules, chalkBold.yellow), release.deps.modules],
[coloredOrNot(SupportedDependencies.uv, chalkBold.cyan), release.deps.uv],
[coloredOrNot(SupportedDependencies.node, chalk.bold.red), release.deps.node],
[coloredOrNot(SupportedDependencies.chrome, chalk.bold.green), release.deps.chrome],
[coloredOrNot(SupportedDependencies.openssl, chalk.bold.blue), release.deps.openssl],
[coloredOrNot(SupportedDependencies.modules, chalk.bold.yellow), release.deps.modules],
[coloredOrNot(SupportedDependencies.uv, chalk.bold.cyan), release.deps.uv],
// eslint-disable-next-line no-magic-numbers
[coloredOrNot(SupportedDependencies.v8, chalkBold.rgb(150, 150, 150)), release.deps.v8],
[coloredOrNot(SupportedDependencies.zlib, chalkBold.magenta), release.deps.zlib]
[coloredOrNot(SupportedDependencies.v8, chalk.bold.rgb(150, 150, 150)), release.deps.v8],
[coloredOrNot(SupportedDependencies.zlib, chalk.bold.magenta), release.deps.zlib]
);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/electron-info/src/FileService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {isAfter as isAfterDate, sub as subtractDate} from 'date-fns';
import {constants as fsConstants, promises as fs} from 'fs';
import {constants as fsConstants, promises as fs} from 'node:fs';
import parseUrl from 'parse-url';
import logdown from 'logdown';
import * as os from 'os';
import * as path from 'path';
import os from 'node:os';
import path from 'node:path';

import type {Options, RawReleaseInfo} from './ElectronInfo';
import {HTTPService} from './HTTPService';
import type {Options, RawReleaseInfo} from './ElectronInfo.js';
import {HTTPService} from './HTTPService.js';

export class FileService {
private readonly httpService: HTTPService;
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-info/src/HTTPService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {promises as fs} from 'fs';
import {inspect} from 'util';
import {promises as fs} from 'node:fs';
import {inspect} from 'node:util';
import axios from 'axios';
import logdown from 'logdown';

import type {Options, RawReleaseInfo} from './ElectronInfo';
import type {Options, RawReleaseInfo} from './ElectronInfo.js';

export type HTTPOptions = Pick<Options, 'debug' | 'timeout'>;

Expand Down
6 changes: 3 additions & 3 deletions packages/electron-info/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

import {program as commander} from 'commander';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import {ElectronInfo, RawDeps, SupportedDependencies} from './ElectronInfo';
import {ElectronInfo, RawDeps, SupportedDependencies} from './ElectronInfo.js';

const defaultPackageJsonPath = path.join(__dirname, 'package.json');
const packageJsonPath = fs.existsSync(defaultPackageJsonPath)
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-info/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ElectronInfo';
export * from './ElectronInfo.js';
10 changes: 10 additions & 0 deletions packages/electron-info/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "dist/cjs",
"rootDir": "src",
"module": "es2020",
"esModuleInterop": true
},
"exclude": ["dist", "node_modules", "spec"],
"extends": "../../tsconfig.json"
}
7 changes: 5 additions & 2 deletions packages/electron-info/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"compilerOptions": {
"outDir": "dist",
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "nodenext",
"outDir": "dist/mjs",
"rootDir": "src",
"esModuleInterop": true
"target": "ES2017"
},
"exclude": ["dist", "node_modules", "spec"],
"extends": "../../tsconfig.json"
Expand Down
7 changes: 7 additions & 0 deletions packages/scrabble-cheater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ This is a simple Scrabble cheating tool designed for Andy's [scrabble-bot](https

Of course you shouldn't be using this and I'm not responsible if people call you a cheater.

## Prerequisites

- [Node.js](https://nodejs.org) >= 14
- [yarn](https://classic.yarnpkg.com) < 2

## Setup

ℹ️ This is a hybrid [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) / [ESM](https://nodejs.org/api/esm.html#introduction) module.

```
yarn
yarn dist
Expand Down
19 changes: 12 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2037,13 +2037,10 @@ chalk@4.1.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@4.1.2, chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1:
version "4.1.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chalk@5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.2.0.tgz#249623b7d66869c673699fb66d65723e54dfcfb3"
integrity sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==

chalk@^2.0.0, chalk@^2.3.0:
version "2.4.2"
Expand All @@ -2054,6 +2051,14 @@ chalk@^2.0.0, chalk@^2.3.0:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1:
version "4.1.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chardet@^0.7.0:
version "0.7.0"
resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
Expand Down

0 comments on commit b4a9cd4

Please sign in to comment.