Skip to content

Commit

Permalink
refactor: hide node warnings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kanadgupta committed Sep 12, 2023
1 parent 618b29e commit eeeabd9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/lib/configstore.ts
Original file line number Diff line number Diff line change
@@ -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(
/**
Expand Down
6 changes: 4 additions & 2 deletions src/lib/getPkgVersion.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
5 changes: 3 additions & 2 deletions src/lib/readmeAPIFetch.ts
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down

0 comments on commit eeeabd9

Please sign in to comment.