From abf47479bb6102b5275d5a0df3d525498eeb38d6 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Mon, 2 Oct 2023 00:14:12 +0000 Subject: [PATCH] refactor: esm got is esm only since v12 --- package.json | 3 ++- src/build.js | 19 ++++++++++--------- src/script.js | 7 +++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4b63142..5e9d7f5 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,6 @@ }, "engines": { "node": ">= 14.15.0" - } + }, + "type": "module" } diff --git a/src/build.js b/src/build.js index 53de0e1..b8bd7a5 100644 --- a/src/build.js +++ b/src/build.js @@ -2,14 +2,15 @@ // for deployment outside of GitLab CI, e.g. Cloudflare Pages and Netlify -const { stream: gotStream } = require('got') -const got = require('got') -const unzip = require('extract-zip') -const { join } = require('path') -const { mkdir } = require('fs/promises') -const { createWriteStream } = require('fs') -const { pipeline } = require('stream/promises') +import got from 'got' +import unzip from 'extract-zip' +import { dirname, join } from 'node:path' +import { mkdir } 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 rootPath = join(__dirname, '..') const tmpPath = join(rootPath, 'tmp') const publicPath = join(rootPath, 'public') @@ -35,7 +36,7 @@ const f = async () => { console.log(`Downloading artifacts.zip from "${artifactsUrl}"`) try { await pipeline( - gotStream(artifactsUrl), + got.stream(artifactsUrl), createWriteStream(zipPath) ) await pipelineStatus(pipelineUrl) @@ -50,7 +51,7 @@ const f = async () => { try { await pipeline( - gotStream(ghMirror), + got.stream(ghMirror), createWriteStream(zipPath) ) } catch ({ message }) { diff --git a/src/script.js b/src/script.js index a012f15..6eafed3 100644 --- a/src/script.js +++ b/src/script.js @@ -1,7 +1,10 @@ 'use strict' -const { join } = require('path') -const { readFile, rm, writeFile } = require('fs/promises') +import { dirname, join } from 'node:path' +import { readFile, rm, writeFile } from 'node:fs/promises' +import { fileURLToPath } from 'node:url' + +const __dirname = dirname(fileURLToPath(import.meta.url)) const { parse } = JSON const f = async () => {