Skip to content

Commit

Permalink
Port to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrttn committed Nov 2, 2023
1 parent b9159b6 commit 7ed1e91
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 148 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"@types/inflection": "^1.13.1",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-transloadit": "^2.0.0",
Expand All @@ -58,6 +58,6 @@
"prettier": "^2.8.6",
"replace-require-with-import": "^2.1.0",
"sucrase": "^3.25.0",
"typescript": "^4.8.2"
"typescript": "^5.2.2"
}
}
7 changes: 2 additions & 5 deletions packages/abbr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/abbr"
},
"type": "module",
"main": "dist/abbr.js",
"typings": "dist/abbr.d.ts",
"types": "dist/abbr.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
7 changes: 2 additions & 5 deletions packages/analyze-step/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/analyze-step"
},
"type": "module",
"main": "dist/analyzeStep.js",
"typings": "dist/analyzeStep.d.ts",
"types": "dist/analyzeStep.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
34 changes: 19 additions & 15 deletions packages/analyze-step/src/analyzeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function humanJoin(array: string[], reduce = true, glueword = 'and'): string {
}
}

if (countedArray.length === 1) {
if (countedArray.length === 1 && typeof countedArray[0] === 'string') {
return countedArray[0]
}

Expand Down Expand Up @@ -67,9 +67,9 @@ function humanFilter(step: FileFilterStep): string {
for (const type of types) {
collection[type] = collection[type] || []
if (typeof step[type] === 'string') {
collection[type].push(`Filter by code evaluation`)
collection[type]?.push(`Filter by code evaluation`)
} else if (step[type] && Array.isArray(step[type])) {
for (const [key, operator, val] of Object.values(step[type])) {
for (const [key, operator, val] of Object.values(step[type]!)) {

Check warning on line 72 in packages/analyze-step/src/analyzeStep.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
const template = clone(templates[operator])
if (!template) {
throw new Error(
Expand Down Expand Up @@ -145,7 +145,7 @@ function humanFilter(step: FileFilterStep): string {
humanDescr = humanDescr.replace('wi2th', 'with')
}

collection[type].push(humanDescr)
collection[type]?.push(humanDescr)
lastTemplate = template
}
}
Expand Down Expand Up @@ -211,11 +211,11 @@ function humanDimensions(step: StepWithDimensions): string {

if ('width' in step && 'height' in step) {
str += ` to ${step.width}×${step.height}`
} else if ('width' in step) {
} else if (step.width) {
str += ` to ${step.width} pixels wide`
} else if ('height' in step) {
} else if (step.height) {
str += ` to ${step.height} pixels high`
} else if ('crop' in step) {
} else if (step.crop) {
str += ` to ${step.crop.x2 - step.crop.x1}×${step.crop.y2 - step.crop.y1} starting at ${
step.crop.x1
}×${step.crop.y1} from the top left`
Expand All @@ -233,6 +233,8 @@ type ExtraMeta = {
}

function humanPreset(step: PresetStep, extrameta: ExtraMeta = {}): string {
if (!step.preset) return ''

let str = inflect.humanize(step.preset.replace(/[-_]/g, ' '))

if (str.match(/^ipad/i)) {
Expand Down Expand Up @@ -278,6 +280,8 @@ type FormatStep = {
}

function humanFormat(step: FormatStep): string {
if (!step.format) return ''

let str = inflect.humanize(step.format.replace(/[-_]/g, ' '))

if (str.match(/^webp/i)) {
Expand Down Expand Up @@ -309,9 +313,9 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
let str = ``

const robot = robots[step.robot]
str = robot.purpose_words
str = robot?.purpose_words ?? ''

if (robot.rname === '/video/encode') {
if (robot?.rname === '/video/encode') {
if (JSON.stringify(step).match(/watermark/)) {
str = `Watermark videos`
} else if (get(step, 'ffmpeg.t') && get(step, 'ffmpeg.ss')) {
Expand Down Expand Up @@ -358,7 +362,7 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/audio/encode') {
if (robot?.rname === '/audio/encode') {
if (has(step, 'ffmpeg.ss') && has(step, 'ffmpeg.t')) {
str = `Take a ${get(step, 'ffmpeg.t')}s clip out of audio at a specified offset`
} else if (
Expand All @@ -382,15 +386,15 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/video/adaptive') {
if (robot?.rname === '/video/adaptive') {
if (step.technique === 'hls') {
str = `Convert videos to HLS`
} else if (step.technique === 'dash') {
str = `Convert videos to MPEG-Dash`
}
}

if (robot.rname === '/video/merge') {
if (robot?.rname === '/video/merge') {
const types = JSONPath({ path: '$..as', json: step })
if (types.length) {
str = `Merge ${humanJoin(types)} to create a new video`
Expand All @@ -399,19 +403,19 @@ export default function humanize(step: Step, robots: Robots, extrameta: ExtraMet
}
}

if (robot.rname === '/file/filter') {
if (robot?.rname === '/file/filter') {
str = humanFilter(step as FileFilterStep)
}

if (robot.rname === '/audio/artwork') {
if (robot?.rname === '/audio/artwork') {
if (get(step, 'method') === 'insert') {
str = `Insert audio artwork`
} else {
str = `Extract audio artwork`
}
}

if (robot.rname === '/image/resize') {
if (robot?.rname === '/image/resize') {
if ('watermark_url' in step) {
str = `Watermark images`
} else if ('sepia' in step) {
Expand Down
7 changes: 2 additions & 5 deletions packages/enrich-tweet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/enrich-tweet"
},
"type": "module",
"main": "dist/enrichTweet.js",
"typings": "dist/enrichTweet.d.ts",
"types": "dist/enrichTweet.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
7 changes: 2 additions & 5 deletions packages/file-exists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/file-exists"
},
"type": "module",
"main": "dist/fileExists.js",
"typings": "dist/fileExists.d.ts",
"types": "dist/fileExists.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
7 changes: 2 additions & 5 deletions packages/format-duration-ms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/format-duration-ms"
},
"type": "module",
"main": "dist/formatDurationMs.js",
"typings": "dist/formatDurationMs.d.ts",
"types": "dist/formatDurationMs.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
7 changes: 2 additions & 5 deletions packages/has-property/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/has-property"
},
"type": "module",
"main": "dist/has-property.js",
"typings": "dist/has-property.d.ts",
"types": "dist/has-property.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
9 changes: 3 additions & 6 deletions packages/post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/post"
},
"bin": "./post.js",
"typings": "dist/post.d.ts",
"type": "module",
"bin": "dist/post.js",
"types": "dist/post.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
4 changes: 3 additions & 1 deletion packages/post/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ async function post(): Promise<void> {
throw new Error(`Dir does not exist: '${postDir.replace(process.cwd(), '.')}'`)
}

const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0].split(' ')[0]
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const mysqlNow = new Date().toISOString().replace('T', ' ').split('.')[0]!.split(' ')[0]!

// eslint-disable-next-line no-unused-vars
const [dateY, datem] = mysqlNow.split('-')
const answers = await inquirer.prompt([
Expand Down
7 changes: 2 additions & 5 deletions packages/pr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/pr"
},
"type": "module",
"main": "dist/pr.js",
"typings": "dist/pr.d.ts",
"types": "dist/pr.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
7 changes: 2 additions & 5 deletions packages/prd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/prd"
},
"type": "module",
"main": "dist/prd.js",
"typings": "dist/prd.d.ts",
"types": "dist/prd.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
3 changes: 2 additions & 1 deletion packages/prettier-bytes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/prettier-bytes"
},
"type": "module",
"main": "dist/prettierBytes.js",
"typings": "dist/prettierBytes.d.ts",
"types": "dist/prettierBytes.d.ts",
"files": [
"dist"
],
Expand Down
7 changes: 2 additions & 5 deletions packages/slugify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/slugify"
},
"type": "module",
"main": "dist/slugify.js",
"typings": "dist/slugify.d.ts",
"types": "dist/slugify.d.ts",
"files": [
"dist"
],
"directories": {
"lib": "dist",
"test": "dist"
},
"scripts": {
"tsc": "tsc --build --clean && tsc --build",
"test": "echo \"Error: run tests from root\" && exit 1"
Expand Down
3 changes: 2 additions & 1 deletion packages/sort-assembly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"url": "git://github.com/transloadit/monolib.git",
"directory": "packages/sort-assembly"
},
"type": "module",
"main": "dist/sortAssembly.js",
"typings": "dist/sortAssembly.d.ts",
"types": "dist/sortAssembly.d.ts",
"files": [
"dist"
],
Expand Down
13 changes: 9 additions & 4 deletions packages/sort-assembly/src/sortAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ export default function sortAssembly<T extends Record<string, unknown>>(assembly
z: ['uploads', 'results'],
})

if ('results' in sorted && typeof sorted.results === 'object') {
if (sorted.results && typeof sorted.results === 'object') {
for (const stepName of Object.keys(sorted.results)) {
if (!hasProperty(sorted.results, stepName)) continue
const result = sorted.results[stepName]
if (!result || typeof result !== 'object') continue
for (const i of Object.keys(result)) {
if (!hasProperty(result, i)) continue
result[i] = sortResult(result[i])
const value = result[i]
if (!value || typeof value !== 'object') continue
result[i] = sortResult(value)
}
}
}

if ('uploads' in sorted) {
if (sorted.uploads) {
for (const i of Object.keys(sorted.uploads)) {
if (!hasProperty(sorted.uploads, i)) continue
sorted.uploads[i] = sortResult(sorted.uploads[i])
const upload = sorted.uploads[i]
if (!upload || typeof upload !== 'object') continue
sorted.uploads[i] = sortResult(upload)
}
}

Expand Down
Loading

0 comments on commit 7ed1e91

Please sign in to comment.