refactor: esm

got is esm only since v12
This commit is contained in:
MDLeom 2023-10-01 09:46:12 +00:00
parent 47d23fc9b2
commit e4eb2bb4a0
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 14 additions and 12 deletions

View File

@ -10,5 +10,6 @@
},
"engines": {
"node": ">= 18.12.0"
}
},
"type": "module"
}

View File

@ -7,15 +7,16 @@
// Instead of using the API, I find it easier to failover to GitHub.
// ref: https://gitlab.com/gitlab-org/gitlab/-/issues/29257
const { stream: gotStream } = require('got')
const got = require('got')
const unzip = require('extract-zip')
const { basename, join } = require('path')
const { mkdir, readdir, rm } = require('fs/promises')
const { createWriteStream } = require('fs')
const { pipeline } = require('stream/promises')
const envVar = process.env
import got from 'got'
import unzip from 'extract-zip'
import { basename, dirname, join } from 'node:path'
import { mkdir, readdir, rm } from 'node:fs/promises'
import { createWriteStream } from 'node:fs'
import { pipeline } from 'node:stream/promises'
import { fileURLToPath } from 'node:url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const envVar = process.env
const rootPath = join(__dirname, '..')
const tmpPath = join(rootPath, 'tmp')
const publicPath = join(rootPath, 'public')
@ -61,7 +62,7 @@ const dl = async (project) => {
console.log(`Downloading ${filename} from "${link}"`)
try {
await pipeline(
gotStream(link),
got.stream(link),
createWriteStream(zipPath)
)
await pipelineStatus(pipelineUrl)
@ -78,7 +79,7 @@ const dl = async (project) => {
try {
await pipeline(
gotStream(mirrorLink),
got.stream(mirrorLink),
createWriteStream(zipPath)
)
} catch ({ message }) {
@ -103,7 +104,7 @@ const oisdDl = async (link, filename) => {
console.log(`Downloading ${filename} from "${link}"`)
try {
await pipeline(
gotStream(link),
got.stream(link),
createWriteStream(txtPath)
)
} catch ({ message }) {