Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to ESM #48

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
}

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

Expand Down Expand Up @@ -67,9 +67,9 @@
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

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 @@
humanDescr = humanDescr.replace('wi2th', 'with')
}

collection[type].push(humanDescr)
collection[type]?.push(humanDescr)
lastTemplate = template
}
}
Expand Down Expand Up @@ -211,11 +211,11 @@

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 @@
}

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 @@
}

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

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

if (str.match(/^webp/i)) {
Expand All @@ -302,16 +306,16 @@
Partial<PresetStep> &
Partial<FormatStep> & {
// using any until we can put some effort into Assembly/Template/Robot types
[key: string]: any

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

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

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

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
}

export default function humanize(step: Step, robots: Robots, extrameta: ExtraMeta = {}): string {
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 @@
}
}

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 @@
}
}

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 @@
}
}

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
2 changes: 1 addition & 1 deletion packages/enrich-tweet/src/enrichTweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function enrichTweet(
): Promise<string | undefined> {
if (!tweet) return

let text = tweet.full_text
let text = tweet.full_text ?? ''

// Expand URLs
if (tweet.entities && tweet.entities.urls.length) {
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 @@ -18,7 +18,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
7 changes: 2 additions & 5 deletions packages/prettier-bytes/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/prettier-bytes"
},
"type": "module",
"main": "dist/prettierBytes.js",
"typings": "dist/prettierBytes.d.ts",
"types": "dist/prettierBytes.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/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
7 changes: 2 additions & 5 deletions packages/sort-assembly/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/sort-assembly"
},
"type": "module",
"main": "dist/sortAssembly.js",
"typings": "dist/sortAssembly.d.ts",
"types": "dist/sortAssembly.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
Loading
Loading