Skip to content

Commit

Permalink
Switch to named exports (#77)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
remcohaszing and kvz authored Nov 21, 2024
1 parent 103ac3c commit 7c09755
Show file tree
Hide file tree
Showing 35 changed files with 69 additions and 53 deletions.
20 changes: 20 additions & 0 deletions .changeset/tender-gifts-battle.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/abbr/src/abbr.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/abbr/src/abbr.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/analyze-step/src/analyzeStep.test.ts
Original file line number Diff line number Diff line change
@@ -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': {
Expand Down
6 changes: 3 additions & 3 deletions packages/analyze-step/src/analyzeStep.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/file-exists/src/fileExists.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/file-exists/src/fileExists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs = require('node:fs')
import fs from 'node:fs'

export = function fileExists(path: string): Promise<boolean> {
export function fileExists(path: string): Promise<boolean> {
return new Promise((resolve) => {
fs.access(path, fs.constants.F_OK, (err) => {
resolve(!err)
Expand Down
2 changes: 1 addition & 1 deletion packages/format-duration-ms/src/formatDurationMs.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/format-duration-ms/src/formatDurationMs.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/has-property/src/has-property.test.ts
Original file line number Diff line number Diff line change
@@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion packages/has-property/src/has-property.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export = function hasProperty<K extends PropertyKey>(
export function hasProperty<K extends PropertyKey>(
obj: unknown,
key: K | null | undefined,
): obj is Record<K, unknown> {
Expand Down
4 changes: 2 additions & 2 deletions packages/post/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/pr/src/pr.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/pr/src/pr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import util = require('node:util')

export = function pr<T>(...args: T[]): T[] {
export function pr<T>(...args: T[]): T[] {
for (const arg of args) {
console.log(util.inspect(arg, false, null, true))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/prd/src/prd.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/prd/src/prd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pr = require('@transloadit/pr')
import { pr } from '@transloadit/pr'

export = function prd<T>(...args: T[]): void {
export function prd<T>(...args: T[]): void {
pr(...args)
const err = new Error('Halt via prd')
console.error(err)
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-bytes/src/prettierBytes.test.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion packages/prettier-bytes/src/prettierBytes.ts
Original file line number Diff line number Diff line change
@@ -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}`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/slugify/src/slugify.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/slugify/src/slugify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export = function slugify(str: string): string {
export function slugify(str: string): string {
if (!str || str !== `${str}`) return str

return str
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-assembly/src/sortAssembly.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/sort-assembly/src/sortAssembly.ts
Original file line number Diff line number Diff line change
@@ -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<T extends Record<string, unknown>>(assembly: T): T {
export function sortAssembly<T extends Record<string, unknown>>(assembly: T): T {
const sorted = sortObjectByPrio(assembly, {
_: ['assembly_id', 'ok', 'message', 'warnings', 'error'],
z: ['uploads', 'results'],
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-object-by-prio/src/sortObjectByPrio.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/sort-object-by-prio/src/sortObjectByPrio.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sortObject = require('@transloadit/sort-object')
import { sortObject } from '@transloadit/sort-object'

type Prefixes = Record<string, (string | RegExp)[]>

export = function sortObjectByPrio<T extends Record<string, unknown>>(
obj: T,
prefixes: Prefixes,
): T {
export function sortObjectByPrio<T extends Record<string, unknown>>(obj: T, prefixes: Prefixes): T {
return sortObject(obj, (argA: string, argB: string) => {
let a = argA
let b = argB
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-object/src/sortObject.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-object/src/sortObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export = function sortObject<T extends Record<string, unknown>>(
export function sortObject<T extends Record<string, unknown>>(
obj: T,
sortFunc?: (a: string, b: string) => number,
): T {
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-result-meta/src/sortResultMeta.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sort-result-meta/src/sortResultMeta.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,7 +12,7 @@ function isObject(obj: unknown): obj is Record<string, unknown> {
)
}

export = function sortResultMeta<T extends Meta>(meta: T): T {
export function sortResultMeta<T extends Meta>(meta: T): T {
if (meta.faces) {
for (let i = 0; i < meta.faces.length; i++) {
const el = meta.faces[i]
Expand Down
2 changes: 1 addition & 1 deletion packages/sort-result/src/sortResult.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sort-result/src/sortResult.ts
Original file line number Diff line number Diff line change
@@ -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<T extends { meta?: unknown }>(result: T): T {
export function sortResult<T extends { meta?: unknown }>(result: T): T {
const sorted = sortObjectByPrio(result, {
_: ['id'],
z: ['meta'],
Expand Down
2 changes: 1 addition & 1 deletion packages/trigger-pager/src/triggerPager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions packages/trigger-pager/src/triggerPager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface TriggerPagerOptions {
urgency?: 'low' | 'high'
}

const triggerPager = async ({
export async function triggerPager({
description,
from = '[email protected]',
incidentKey,
serviceId,
title = incidentKey,
token,
urgency = 'high',
}: TriggerPagerOptions): Promise<void> => {
}: TriggerPagerOptions): Promise<void> {
const res = await pagerduty.api({ token }).post('/incidents', {
headers: {
from,
Expand Down Expand Up @@ -57,5 +57,3 @@ const triggerPager = async ({
}
}
}

export = triggerPager
6 changes: 4 additions & 2 deletions template-package/replaceMe.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
2 changes: 1 addition & 1 deletion template-package/replaceMe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function replaceMe(arg: string) {
export function replaceMe(arg: string) {
return arg
}
1 change: 0 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"esModuleInterop": true,
"lib": ["ES2023"],
"target": "es2022",
"module": "nodenext",
Expand Down

0 comments on commit 7c09755

Please sign in to comment.