Skip to content

Commit

Permalink
feat: Create ESM-only packages (BREAKING) (#688)
Browse files Browse the repository at this point in the history
BREAKING CHANGES:
- All packages are now ESM-only.
  • Loading branch information
ffflorian authored Aug 13, 2024
1 parent ce916fa commit 6ada581
Show file tree
Hide file tree
Showing 131 changed files with 332 additions and 643 deletions.
3 changes: 0 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ updates:
- dependency-name: '@types/node'
versions:
- '> 22.x'
- dependency-name: 'parse-url'
versions:
- '> 8.x'
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
Expand Down
13 changes: 0 additions & 13 deletions bin/generate-hybrid-package-json.sh

This file was deleted.

2 changes: 1 addition & 1 deletion packages/auto-approver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Automatically approve all GitHub PRs which match a specific pattern.

## 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.
ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.

Run `yarn global add auto-approver` or `npm i -g auto-approver`.

Expand Down
17 changes: 4 additions & 13 deletions packages/auto-approver/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "Florian Imdahl <git@ffflorian.de>",
"bin": "dist/cjs/cli.js",
"bin": "dist/cli.js",
"dependencies": {
"axios": "1.7.3",
"commander": "12.1.0",
Expand All @@ -18,12 +18,7 @@
"engines": {
"node": ">= 18.0"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"exports": "./dist/index.js",
"files": [
"dist"
],
Expand All @@ -32,17 +27,13 @@
"typescript"
],
"license": "GPL-3.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/index.js",
"name": "auto-approver",
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/auto-approver",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist",
"dist": "yarn clean && yarn build",
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
"start": "node --loader ts-node/esm src/cli.ts",
"test": "vitest run"
},
Expand Down
11 changes: 8 additions & 3 deletions packages/auto-approver/src/AutoApprover.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import axios, {AxiosError, AxiosInstance} from 'axios';
import logdown from 'logdown';
import {createRequire} from 'module';

interface PackageJson {
bin: Record<string, string>;
version: string;
}

const require = createRequire(import.meta.url);
const {bin, version: toolVersion}: PackageJson = require('../package.json');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../package.json');

const {bin, version: toolVersion}: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const toolName = Object.keys(bin)[0];

/** @see https://docs.github.com/en/rest/reference/pulls#get-a-pull-request */
Expand Down
13 changes: 9 additions & 4 deletions packages/auto-approver/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node

import fs from 'node:fs';
import path from 'node:path';
import readline from 'node:readline';
import {fileURLToPath} from 'node:url';
import {program as commander} from 'commander';
import {cosmiconfigSync} from 'cosmiconfig';
import logdown from 'logdown';
import readline from 'readline';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);

import {ApproverConfig, AutoApprover, Repository} from './AutoApprover.js';
import {pluralize} from './util.js';
Expand All @@ -23,7 +24,11 @@ interface PackageJson {
version: string;
}

const {bin, description, version}: PackageJson = require('../package.json');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../package.json');

const {bin, description, version}: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

commander
.name(Object.keys(bin)[0])
Expand Down
10 changes: 0 additions & 10 deletions packages/auto-approver/tsconfig.cjs.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/auto-approver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist/esm",
"outDir": "dist",
"rootDir": "src",
"target": "ES2018"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/crates-updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Check your [Rust packages](https://crates.io) for updates.

## 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.
ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.

Run `yarn global add crates-updater` or `npm i -g crates-updater`.

Expand Down
19 changes: 5 additions & 14 deletions packages/crates-updater/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"author": "Florian Imdahl <git@ffflorian.de>",
"bin": {
"crates-updater": "dist/cjs/cli.js",
"update-crates": "dist/cjs/cli.js"
"crates-updater": "dist/cli.js",
"update-crates": "dist/cli.js"
},
"dependencies": {
"commander": "12.1.0",
Expand All @@ -17,12 +17,7 @@
"engines": {
"node": ">= 18.0"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"exports": "./dist/index.js",
"files": [
"dist"
],
Expand All @@ -33,17 +28,13 @@
"cli"
],
"license": "GPL-3.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/index.js",
"name": "crates-updater",
"repository": "https://github.com/ffflorian/tree/node-packages/crates-updater",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist",
"dist": "yarn clean && yarn build",
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
"start": "node --loader ts-node/esm src/cli.ts"
},
"type": "module",
Expand Down
10 changes: 7 additions & 3 deletions packages/crates-updater/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {program as commander} from 'commander';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);

import * as CratesUpdater from './CratesUpdater.js';

Expand All @@ -11,8 +12,11 @@ interface PackageJson {
description: string;
version: string;
}
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../package.json');

const {bin, description, version}: PackageJson = require('../package.json');
const {bin, description, version}: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

commander
.name(Object.keys(bin)[0])
Expand Down
10 changes: 0 additions & 10 deletions packages/crates-updater/tsconfig.cjs.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/crates-updater/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist/esm",
"outDir": "dist",
"rootDir": "src",
"target": "ES2018"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/double-linked-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A linked list in which every element knows about its predecessor and its success

## 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.
ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.

Run `yarn add @ffflorian/doublelinkedlist` or `npm i @ffflorian/doublelinkedlist`.

Expand Down
15 changes: 3 additions & 12 deletions packages/double-linked-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,19 @@
"engines": {
"node": ">= 18.0"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"exports": "./dist/index.js",
"files": [
"dist"
],
"license": "GPL-3.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/index.js",
"name": "@ffflorian/doublelinkedlist",
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/double-linked-list",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:docs": "typedoc && npx touch docs/.nojekyll",
"build:esm": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist",
"dist": "yarn clean && yarn build",
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
"test": "vitest run"
},
"type": "module",
Expand Down
10 changes: 0 additions & 10 deletions packages/double-linked-list/tsconfig.cjs.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/double-linked-list/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist/esm",
"outDir": "dist",
"rootDir": "src",
"target": "ES2018"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-icon-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Based on https://github.com/jaretburkett/electron-icon-maker.

## 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.
ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.

Run `yarn global add @ffflorian/electron-icon-generator` or `npm i -g @ffflorian/electron-icon-generator`

Expand Down
17 changes: 4 additions & 13 deletions packages/electron-icon-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "Florian Imdahl <git@ffflorian.de>",
"bin": "dist/cjs/index.js",
"bin": "dist/index.js",
"dependencies": {
"commander": "12.1.0",
"fs-extra": "11.2.0",
Expand All @@ -16,12 +16,7 @@
"engines": {
"node": ">= 18.0"
},
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"exports": "./dist/index.js",
"files": [
"dist"
],
Expand All @@ -33,17 +28,13 @@
"ico"
],
"license": "GPL-3.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/index.js",
"name": "@ffflorian/electron-icon-generator",
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/electron-icon-generator",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"clean": "rimraf dist",
"dist": "yarn clean && yarn build",
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
"start": "node --loader ts-node/esm src/cli.ts",
"test": "exit 0"
},
Expand Down
11 changes: 8 additions & 3 deletions packages/electron-icon-generator/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {program as commander} from 'commander';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);

import {IconGenerator} from './index.js';

Expand All @@ -12,7 +13,11 @@ interface PackageJson {
version: string;
}

const {bin, description, version}: PackageJson = require('../package.json');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../package.json');

const {bin, description, version}: PackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

commander
.description(description)
Expand Down
Loading

0 comments on commit 6ada581

Please sign in to comment.