diff --git a/package.json b/package.json index b711281..9c865b4 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,6 @@ }, "engines": { "node": ">= 18.12.0" - } + }, + "type": "module" } diff --git a/src/build.js b/src/build.js index 011c21f..4bd7bba 100644 --- a/src/build.js +++ b/src/build.js @@ -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 }) {