From 7c097550b962ae8899fcdb03627cd9b52945dbe8 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Thu, 21 Nov 2024 17:01:20 +0100 Subject: [PATCH] Switch to named exports (#77) * Switch to named exports Refs #59 * Update yarn.lock * Fix broken test * Update .changeset/tender-gifts-battle.md * Fix formatting --------- Co-authored-by: Kevin van Zonneveld --- .changeset/tender-gifts-battle.md | 20 +++++++++++++++++++ packages/abbr/src/abbr.test.ts | 2 +- packages/abbr/src/abbr.ts | 2 +- packages/analyze-step/src/analyzeStep.test.ts | 2 +- packages/analyze-step/src/analyzeStep.ts | 6 +++--- packages/file-exists/src/fileExists.test.ts | 2 +- packages/file-exists/src/fileExists.ts | 4 ++-- .../src/formatDurationMs.test.ts | 2 +- .../src/formatDurationMs.ts | 2 +- .../has-property/src/has-property.test.ts | 2 +- packages/has-property/src/has-property.ts | 2 +- packages/post/src/post.ts | 4 ++-- packages/pr/src/pr.test.ts | 2 +- packages/pr/src/pr.ts | 2 +- packages/prd/src/prd.test.ts | 2 +- packages/prd/src/prd.ts | 4 ++-- .../prettier-bytes/src/prettierBytes.test.ts | 2 +- packages/prettier-bytes/src/prettierBytes.ts | 2 +- packages/slugify/src/slugify.test.ts | 2 +- packages/slugify/src/slugify.ts | 2 +- .../sort-assembly/src/sortAssembly.test.ts | 2 +- packages/sort-assembly/src/sortAssembly.ts | 8 ++++---- .../src/sortObjectByPrio.test.ts | 2 +- .../src/sortObjectByPrio.ts | 7 ++----- packages/sort-object/src/sortObject.test.ts | 2 +- packages/sort-object/src/sortObject.ts | 2 +- .../src/sortResultMeta.test.ts | 2 +- .../sort-result-meta/src/sortResultMeta.ts | 4 ++-- packages/sort-result/src/sortResult.test.ts | 2 +- packages/sort-result/src/sortResult.ts | 6 +++--- .../trigger-pager/src/triggerPager.test.ts | 2 +- packages/trigger-pager/src/triggerPager.ts | 6 ++---- template-package/replaceMe.test.ts | 6 ++++-- template-package/replaceMe.ts | 2 +- tsconfig.base.json | 1 - 35 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 .changeset/tender-gifts-battle.md diff --git a/.changeset/tender-gifts-battle.md b/.changeset/tender-gifts-battle.md new file mode 100644 index 0000000..01b954c --- /dev/null +++ b/.changeset/tender-gifts-battle.md @@ -0,0 +1,20 @@ +--- +"@transloadit/sort-object-by-prio": major +"@transloadit/format-duration-ms": major +"@transloadit/sort-result-meta": major +"@transloadit/prettier-bytes": major +"@transloadit/sort-assembly": major +"@transloadit/trigger-pager": major +"@transloadit/analyze-step": major +"@transloadit/has-property": major +"@transloadit/file-exists": major +"@transloadit/sort-object": major +"@transloadit/sort-result": major +"@transloadit/slugify": major +"@transloadit/abbr": major +"@transloadit/post": major +"@transloadit/prd": major +"@transloadit/pr": major +--- + +Switch to named exports diff --git a/packages/abbr/src/abbr.test.ts b/packages/abbr/src/abbr.test.ts index 02573bf..429fc7c 100644 --- a/packages/abbr/src/abbr.test.ts +++ b/packages/abbr/src/abbr.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import abbr from './abbr' +import { abbr } from './abbr' describe('abbr', () => { test('main', async () => { diff --git a/packages/abbr/src/abbr.ts b/packages/abbr/src/abbr.ts index 55b0312..7e5723e 100644 --- a/packages/abbr/src/abbr.ts +++ b/packages/abbr/src/abbr.ts @@ -1,4 +1,4 @@ -export = function abbr(str: string, maxLength = 55, divider = `[...]`): string { +export function abbr(str: string, maxLength = 55, divider = `[...]`): string { if (str !== `${str}`) { return str } diff --git a/packages/analyze-step/src/analyzeStep.test.ts b/packages/analyze-step/src/analyzeStep.test.ts index cd2a3b8..51b75fd 100644 --- a/packages/analyze-step/src/analyzeStep.test.ts +++ b/packages/analyze-step/src/analyzeStep.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import analyzeStep from './analyzeStep' +import { analyzeStep } from './analyzeStep' const ROBOTS = { '/image/resize': { diff --git a/packages/analyze-step/src/analyzeStep.ts b/packages/analyze-step/src/analyzeStep.ts index a89f7f9..cc69374 100644 --- a/packages/analyze-step/src/analyzeStep.ts +++ b/packages/analyze-step/src/analyzeStep.ts @@ -1,5 +1,5 @@ -import formatDurationMs = require('@transloadit/format-duration-ms') -import prettierBytes = require('@transloadit/prettier-bytes') +import { formatDurationMs } from '@transloadit/format-duration-ms' +import { prettierBytes } from '@transloadit/prettier-bytes' import inflect = require('inflection') import JSONPath = require('jsonpath-plus') import clone = require('lodash/clone') @@ -323,7 +323,7 @@ type StepData = { type Step = FileFilterStep & StepWithDimensions & PresetStep & FormatStep & StepData -export = function humanize(step: Step, robots: Robots, extrameta: ExtraMeta = {}): string { +export function analyzeStep(step: Step, robots: Robots, extrameta: ExtraMeta = {}): string { let str = `` const robotName = step.robot diff --git a/packages/file-exists/src/fileExists.test.ts b/packages/file-exists/src/fileExists.test.ts index a77c442..7355b40 100644 --- a/packages/file-exists/src/fileExists.test.ts +++ b/packages/file-exists/src/fileExists.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import fileExists from './fileExists' +import { fileExists } from './fileExists' describe('fileExists', () => { test('main', async () => { diff --git a/packages/file-exists/src/fileExists.ts b/packages/file-exists/src/fileExists.ts index 0423afe..f8b9445 100644 --- a/packages/file-exists/src/fileExists.ts +++ b/packages/file-exists/src/fileExists.ts @@ -1,6 +1,6 @@ -import fs = require('node:fs') +import fs from 'node:fs' -export = function fileExists(path: string): Promise { +export function fileExists(path: string): Promise { return new Promise((resolve) => { fs.access(path, fs.constants.F_OK, (err) => { resolve(!err) diff --git a/packages/format-duration-ms/src/formatDurationMs.test.ts b/packages/format-duration-ms/src/formatDurationMs.test.ts index 95b2872..1ea68e3 100644 --- a/packages/format-duration-ms/src/formatDurationMs.test.ts +++ b/packages/format-duration-ms/src/formatDurationMs.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import formatDurationMs from './formatDurationMs' +import { formatDurationMs } from './formatDurationMs' describe('formatDurationMs', () => { test('main', async () => { diff --git a/packages/format-duration-ms/src/formatDurationMs.ts b/packages/format-duration-ms/src/formatDurationMs.ts index 680cc20..ecec92f 100644 --- a/packages/format-duration-ms/src/formatDurationMs.ts +++ b/packages/format-duration-ms/src/formatDurationMs.ts @@ -1,6 +1,6 @@ import prettyMS = require('pretty-ms') -export = function formatDurationMs(ms: number): string { +export function formatDurationMs(ms: number): string { let human = prettyMS(ms) human = human.replace(/(\d+)\.\d+s/g, '$1s') diff --git a/packages/has-property/src/has-property.test.ts b/packages/has-property/src/has-property.test.ts index 44820d3..b770356 100644 --- a/packages/has-property/src/has-property.test.ts +++ b/packages/has-property/src/has-property.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { test } from 'node:test' -import hasProperty from './has-property' +import { hasProperty } from './has-property' test('hasProperty', () => { assert.ok(hasProperty({ foo: 'bar' }, 'foo')) diff --git a/packages/has-property/src/has-property.ts b/packages/has-property/src/has-property.ts index b1f8c54..c700172 100644 --- a/packages/has-property/src/has-property.ts +++ b/packages/has-property/src/has-property.ts @@ -1,4 +1,4 @@ -export = function hasProperty( +export function hasProperty( obj: unknown, key: K | null | undefined, ): obj is Record { diff --git a/packages/post/src/post.ts b/packages/post/src/post.ts index f08d62d..c87b0ef 100644 --- a/packages/post/src/post.ts +++ b/packages/post/src/post.ts @@ -3,8 +3,8 @@ import fs = require('node:fs/promises') import inquirer = require('inquirer') import openInEditor = require('open-in-editor') -import fileExists = require('@transloadit/file-exists') -import slugify = require('@transloadit/slugify') +import { fileExists } from '@transloadit/file-exists' +import { slugify } from '@transloadit/slugify' import title = require('title') async function post(): Promise { diff --git a/packages/pr/src/pr.test.ts b/packages/pr/src/pr.test.ts index da92562..49f6988 100644 --- a/packages/pr/src/pr.test.ts +++ b/packages/pr/src/pr.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import pr from './pr' +import { pr } from './pr' describe('pr', () => { test('main', async () => { diff --git a/packages/pr/src/pr.ts b/packages/pr/src/pr.ts index f8dd450..07a73e4 100644 --- a/packages/pr/src/pr.ts +++ b/packages/pr/src/pr.ts @@ -1,6 +1,6 @@ import util = require('node:util') -export = function pr(...args: T[]): T[] { +export function pr(...args: T[]): T[] { for (const arg of args) { console.log(util.inspect(arg, false, null, true)) } diff --git a/packages/prd/src/prd.test.ts b/packages/prd/src/prd.test.ts index 45e64a1..2214780 100644 --- a/packages/prd/src/prd.test.ts +++ b/packages/prd/src/prd.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, mock, test } from 'node:test' -import prd from './prd' +import { prd } from './prd' describe('prd', () => { test('main', async () => { diff --git a/packages/prd/src/prd.ts b/packages/prd/src/prd.ts index c3c3328..365a641 100644 --- a/packages/prd/src/prd.ts +++ b/packages/prd/src/prd.ts @@ -1,6 +1,6 @@ -import pr = require('@transloadit/pr') +import { pr } from '@transloadit/pr' -export = function prd(...args: T[]): void { +export function prd(...args: T[]): void { pr(...args) const err = new Error('Halt via prd') console.error(err) diff --git a/packages/prettier-bytes/src/prettierBytes.test.ts b/packages/prettier-bytes/src/prettierBytes.test.ts index 941f328..a12b07b 100644 --- a/packages/prettier-bytes/src/prettierBytes.test.ts +++ b/packages/prettier-bytes/src/prettierBytes.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, it } from 'node:test' -import prettierBytes from './prettierBytes' +import { prettierBytes } from './prettierBytes' const testData = [ [2, '2 B'], diff --git a/packages/prettier-bytes/src/prettierBytes.ts b/packages/prettier-bytes/src/prettierBytes.ts index aa4fdf1..f363b81 100644 --- a/packages/prettier-bytes/src/prettierBytes.ts +++ b/packages/prettier-bytes/src/prettierBytes.ts @@ -1,7 +1,7 @@ // Adapted from https://github.com/Flet/prettier-bytes/ // Changing 1000 bytes to 1024, so we can keep uppercase KB vs kB // ISC License (c) Dan Flettre https://github.com/Flet/prettier-bytes/blob/master/LICENSE -export = function prettierBytes(input: number): string { +export function prettierBytes(input: number): string { if (typeof input !== 'number' || Number.isNaN(input)) { throw new TypeError(`Expected a number, got ${typeof input}`) } diff --git a/packages/slugify/src/slugify.test.ts b/packages/slugify/src/slugify.test.ts index 96e423a..5372dbb 100644 --- a/packages/slugify/src/slugify.test.ts +++ b/packages/slugify/src/slugify.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import slugify from './slugify' +import { slugify } from './slugify' describe('slugify', () => { test('main', async () => { diff --git a/packages/slugify/src/slugify.ts b/packages/slugify/src/slugify.ts index d41bbca..2818e9a 100644 --- a/packages/slugify/src/slugify.ts +++ b/packages/slugify/src/slugify.ts @@ -1,4 +1,4 @@ -export = function slugify(str: string): string { +export function slugify(str: string): string { if (!str || str !== `${str}`) return str return str diff --git a/packages/sort-assembly/src/sortAssembly.test.ts b/packages/sort-assembly/src/sortAssembly.test.ts index 4932cf3..5f75508 100644 --- a/packages/sort-assembly/src/sortAssembly.test.ts +++ b/packages/sort-assembly/src/sortAssembly.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import sortAssembly from './sortAssembly' +import { sortAssembly } from './sortAssembly' describe('sortAssembly', () => { test('main', () => { diff --git a/packages/sort-assembly/src/sortAssembly.ts b/packages/sort-assembly/src/sortAssembly.ts index 149dd7f..b8ae86e 100644 --- a/packages/sort-assembly/src/sortAssembly.ts +++ b/packages/sort-assembly/src/sortAssembly.ts @@ -1,8 +1,8 @@ -import sortObjectByPrio = require('@transloadit/sort-object-by-prio') -import sortResult = require('@transloadit/sort-result') -import hasProperty = require('@transloadit/has-property') +import { sortObjectByPrio } from '@transloadit/sort-object-by-prio' +import { sortResult } from '@transloadit/sort-result' +import { hasProperty } from '@transloadit/has-property' -export = function sortAssembly>(assembly: T): T { +export function sortAssembly>(assembly: T): T { const sorted = sortObjectByPrio(assembly, { _: ['assembly_id', 'ok', 'message', 'warnings', 'error'], z: ['uploads', 'results'], diff --git a/packages/sort-object-by-prio/src/sortObjectByPrio.test.ts b/packages/sort-object-by-prio/src/sortObjectByPrio.test.ts index d3a13dc..2aa8acf 100644 --- a/packages/sort-object-by-prio/src/sortObjectByPrio.test.ts +++ b/packages/sort-object-by-prio/src/sortObjectByPrio.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import sortObjectByPrio from './sortObjectByPrio' +import { sortObjectByPrio } from './sortObjectByPrio' describe('sortObjectByPrio', () => { test('main', () => { diff --git a/packages/sort-object-by-prio/src/sortObjectByPrio.ts b/packages/sort-object-by-prio/src/sortObjectByPrio.ts index fba32cc..b05f157 100644 --- a/packages/sort-object-by-prio/src/sortObjectByPrio.ts +++ b/packages/sort-object-by-prio/src/sortObjectByPrio.ts @@ -1,11 +1,8 @@ -import sortObject = require('@transloadit/sort-object') +import { sortObject } from '@transloadit/sort-object' type Prefixes = Record -export = function sortObjectByPrio>( - obj: T, - prefixes: Prefixes, -): T { +export function sortObjectByPrio>(obj: T, prefixes: Prefixes): T { return sortObject(obj, (argA: string, argB: string) => { let a = argA let b = argB diff --git a/packages/sort-object/src/sortObject.test.ts b/packages/sort-object/src/sortObject.test.ts index 5b5ea9e..bdc79e0 100644 --- a/packages/sort-object/src/sortObject.test.ts +++ b/packages/sort-object/src/sortObject.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import sortObject from './sortObject' +import { sortObject } from './sortObject' describe('sortObject', () => { test('main', () => { diff --git a/packages/sort-object/src/sortObject.ts b/packages/sort-object/src/sortObject.ts index a3d130d..79c6432 100644 --- a/packages/sort-object/src/sortObject.ts +++ b/packages/sort-object/src/sortObject.ts @@ -1,4 +1,4 @@ -export = function sortObject>( +export function sortObject>( obj: T, sortFunc?: (a: string, b: string) => number, ): T { diff --git a/packages/sort-result-meta/src/sortResultMeta.test.ts b/packages/sort-result-meta/src/sortResultMeta.test.ts index 5a4f882..62d867d 100644 --- a/packages/sort-result-meta/src/sortResultMeta.test.ts +++ b/packages/sort-result-meta/src/sortResultMeta.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import sortResultMeta from './sortResultMeta' +import { sortResultMeta } from './sortResultMeta' describe('sortResultMeta', () => { test('main', () => { diff --git a/packages/sort-result-meta/src/sortResultMeta.ts b/packages/sort-result-meta/src/sortResultMeta.ts index bcff994..791657a 100644 --- a/packages/sort-result-meta/src/sortResultMeta.ts +++ b/packages/sort-result-meta/src/sortResultMeta.ts @@ -1,4 +1,4 @@ -import sortObjectByPrio = require('@transloadit/sort-object-by-prio') +import { sortObjectByPrio } from '@transloadit/sort-object-by-prio' // using interface here instead of type causes Meta to not be assignable to the generic type // of sortObjectByPrio @@ -12,7 +12,7 @@ function isObject(obj: unknown): obj is Record { ) } -export = function sortResultMeta(meta: T): T { +export function sortResultMeta(meta: T): T { if (meta.faces) { for (let i = 0; i < meta.faces.length; i++) { const el = meta.faces[i] diff --git a/packages/sort-result/src/sortResult.test.ts b/packages/sort-result/src/sortResult.test.ts index 32439e9..4fb47a3 100644 --- a/packages/sort-result/src/sortResult.test.ts +++ b/packages/sort-result/src/sortResult.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert' import { describe, test } from 'node:test' -import sortResult from './sortResult' +import { sortResult } from './sortResult' describe('sortResult', () => { test('main', () => { diff --git a/packages/sort-result/src/sortResult.ts b/packages/sort-result/src/sortResult.ts index 98c831d..704ce60 100644 --- a/packages/sort-result/src/sortResult.ts +++ b/packages/sort-result/src/sortResult.ts @@ -1,7 +1,7 @@ -import sortObjectByPrio = require('@transloadit/sort-object-by-prio') -import sortResultMeta = require('@transloadit/sort-result-meta') +import { sortObjectByPrio } from '@transloadit/sort-object-by-prio' +import { sortResultMeta } from '@transloadit/sort-result-meta' -export = function sortResult(result: T): T { +export function sortResult(result: T): T { const sorted = sortObjectByPrio(result, { _: ['id'], z: ['meta'], diff --git a/packages/trigger-pager/src/triggerPager.test.ts b/packages/trigger-pager/src/triggerPager.test.ts index 5bec873..bf42543 100644 --- a/packages/trigger-pager/src/triggerPager.test.ts +++ b/packages/trigger-pager/src/triggerPager.test.ts @@ -32,7 +32,7 @@ mockRequire('@pagerduty/pdjs', () => { return { api: () => ({ post: mockPost }) } }) -const triggerPager = require('./triggerPager') +const { triggerPager } = require('./triggerPager') const LOREM_LONG = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. diff --git a/packages/trigger-pager/src/triggerPager.ts b/packages/trigger-pager/src/triggerPager.ts index f467ae4..6f03a2e 100644 --- a/packages/trigger-pager/src/triggerPager.ts +++ b/packages/trigger-pager/src/triggerPager.ts @@ -13,7 +13,7 @@ interface TriggerPagerOptions { urgency?: 'low' | 'high' } -const triggerPager = async ({ +export async function triggerPager({ description, from = 'tim.koschuetzki@transloadit.com', incidentKey, @@ -21,7 +21,7 @@ const triggerPager = async ({ title = incidentKey, token, urgency = 'high', -}: TriggerPagerOptions): Promise => { +}: TriggerPagerOptions): Promise { const res = await pagerduty.api({ token }).post('/incidents', { headers: { from, @@ -57,5 +57,3 @@ const triggerPager = async ({ } } } - -export = triggerPager diff --git a/template-package/replaceMe.test.ts b/template-package/replaceMe.test.ts index 3257b55..5040ee9 100644 --- a/template-package/replaceMe.test.ts +++ b/template-package/replaceMe.test.ts @@ -1,7 +1,9 @@ -import replaceMe from './replaceMe' +import assert from 'node:assert' +import { describe, test } from 'node:test' +import { replaceMe } from './replaceMe' describe('replaceMe', () => { test('main', async () => { - expect(replaceMe('foo')).toBe('bar') + assert.equal(replaceMe('foo'), 'bar') }) }) diff --git a/template-package/replaceMe.ts b/template-package/replaceMe.ts index 096e87a..7b0b2bd 100644 --- a/template-package/replaceMe.ts +++ b/template-package/replaceMe.ts @@ -1,3 +1,3 @@ -export default function replaceMe(arg: string) { +export function replaceMe(arg: string) { return arg } diff --git a/tsconfig.base.json b/tsconfig.base.json index 2c8919d..8b1bf9f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "esModuleInterop": true, "lib": ["ES2023"], "target": "es2022", "module": "nodenext",