Skip to content

Commit

Permalink
Revert utility library to CommonJS (fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukiffer committed Apr 15, 2024
1 parent b4b7e6b commit 521e671
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions utils.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { resolve } from 'path';
import { existsSync } from 'fs';
const fs = require('fs');
const path = require('path');

export function findPlugin(plugins, pluginName) {
function findPlugin(plugins, pluginName) {
// plugins can be a string (just the name) or a tuple of string and configuration object
const index = plugins.findIndex(plugin =>
// eslint-disable-next-line comma-dangle
Array.isArray(plugin) ? plugin[0] === pluginName : plugin === pluginName

Check failure on line 7 in utils.cjs

View workflow job for this annotation

GitHub Actions / Validation / Run default linters

Missing trailing comma

Check failure on line 7 in utils.cjs

View workflow job for this annotation

GitHub Actions / Validation / Run default linters

Missing trailing comma
);

Expand All @@ -13,20 +12,24 @@ export function findPlugin(plugins, pluginName) {
}
}

export function findPackageJson() {
if (process.env.npm_package_json && existsSync(process.env.npm_package_json)) {
function findPackageJson() {
if (process.env.npm_package_json && fs.existsSync(process.env.npm_package_json)) {
// from npx
return process.env.npm_package_json;
}

// assume that we are executing in the base of the repo
const packageJson = resolve(process.env.PWD, 'package.json');
if (existsSync(packageJson)) {
const packageJson = path.resolve(process.env.PWD, 'package.json');
if (fs.existsSync(packageJson)) {
return packageJson;
}
}

export function getPackageConfig() {
function getPackageConfig() {
const packageJson = findPackageJson();
return require(packageJson);
}

exports.findPackageJson = findPackageJson;
exports.findPlugin = findPlugin;
exports.getPackageConfig = getPackageConfig;

0 comments on commit 521e671

Please sign in to comment.