From eeeabd950d56bf93c7430ce903d395541642f575 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 12 Sep 2023 17:26:11 -0500 Subject: [PATCH] refactor: hide node warnings taken from here: https://www.stefanjudis.com/snippets/how-to-import-json-files-in-es-modules-node-js/#option-1%3A-read-and-parse-json-files-yourself this is the best way i could think of to avoid the experimental import assertions --- src/cli.ts | 6 ++++-- src/index.ts | 3 ++- src/lib/configstore.ts | 4 +++- src/lib/getPkgVersion.ts | 6 ++++-- src/lib/readmeAPIFetch.ts | 5 +++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 98c912674..9afb28816 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,14 +1,16 @@ #! /usr/bin/env node +import { readFile } from 'node:fs/promises'; + import * as core from '@actions/core'; import chalk from 'chalk'; import updateNotifier from 'update-notifier-cjs'; -import pkg from '../package.json' assert { type: 'json' }; - import { isGHA } from './lib/isCI.js'; import rdme from './index.js'; +const pkg = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' })); + updateNotifier({ pkg }).notify(); rdme(process.argv.slice(2)) diff --git a/src/index.ts b/src/index.ts index e32839d7f..a8f7f88a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ /* eslint-disable import/first, import/order, no-underscore-dangle */ +import { readFile } from 'node:fs/promises'; import path from 'node:path'; import chalk from 'chalk'; @@ -20,7 +21,7 @@ import config from 'config'; process.env.NODE_CONFIG_DIR = configDir; -import pkg from '../package.json' assert { type: 'json' }; +const pkg = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' })); const { version } = pkg; diff --git a/src/lib/configstore.ts b/src/lib/configstore.ts index c5508b444..3f7b83ed2 100644 --- a/src/lib/configstore.ts +++ b/src/lib/configstore.ts @@ -1,6 +1,8 @@ +import { readFile } from 'node:fs/promises'; + import Configstore from 'configstore'; -import pkg from '../../package.json' assert { type: 'json' }; +const pkg = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' })); const configstore = new Configstore( /** diff --git a/src/lib/getPkgVersion.ts b/src/lib/getPkgVersion.ts index 0e2fce95d..aeccb66c6 100644 --- a/src/lib/getPkgVersion.ts +++ b/src/lib/getPkgVersion.ts @@ -1,11 +1,13 @@ +import { readFile } from 'node:fs/promises'; + // eslint-disable-next-line no-restricted-imports import fetch from 'node-fetch'; import semver from 'semver'; -import pkg from '../../package.json' assert { type: 'json' }; - import { error } from './logger.js'; +const pkg = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' })); + const registryUrl = 'https://registry.npmjs.com/rdme'; /** diff --git a/src/lib/readmeAPIFetch.ts b/src/lib/readmeAPIFetch.ts index 22e626df5..06152cbc3 100644 --- a/src/lib/readmeAPIFetch.ts +++ b/src/lib/readmeAPIFetch.ts @@ -1,19 +1,20 @@ import type { SpecFileType } from './prepareOas.js'; import type { RequestInit, Response } from 'node-fetch'; +import { readFile } from 'node:fs/promises'; import path from 'node:path'; import config from 'config'; import mime from 'mime-types'; import nodeFetch, { Headers } from 'node-fetch'; // eslint-disable-line no-restricted-imports -import pkg from '../../package.json' assert { type: 'json' }; - import APIError from './apiError.js'; import { git } from './createGHA/index.js'; import isCI, { ciName, isGHA } from './isCI.js'; import { debug, warn } from './logger.js'; +const pkg = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), { encoding: 'utf-8' })); + const SUCCESS_NO_CONTENT = 204; /**