Skip to content

Commit

Permalink
fix linting and make runnable in more envs
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Oct 25, 2024
1 parent 90e70c1 commit 5ec8613
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export default [
languageOptions: {
globals: {
...globals.mocha,

// cjs globals
require: "readonly",
exports: "readonly",
__filename: "readonly",
},

parser: espree,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Fauna",
"type": "module",
"bin": {
"fauna": "./user-entrypoint.mjs"
"fauna": "./src/user-entrypoint.mjs"
},
"bugs": "https://github.com/fauna/fauna-shell/issues",
"dependencies": {
Expand Down Expand Up @@ -48,7 +48,6 @@
"node": ">=20.0.0"
},
"files": [
"/user-entrypoint.mjs",
"/src"
],
"homepage": "https://github.com/fauna/fauna-shell",
Expand All @@ -61,17 +60,17 @@
"cli"
],
"license": "MPL-2.0",
"main": "./user-entrypoint.mjs",
"main": "./src/user-entrypoint.mjs",
"repository": "fauna/fauna-shell",
"scripts": {
"pretest": "npm run format && npm run lint",
"lint": "eslint . --fix",
"test": "mocha --recursive ./test --require ./test/mmcha-root-hooks.mjs --reporter spec --reporter mocha-junit-reporter",
"test:local": "mocha --recursive ./test --require ./test/mocha-root-hooks.mjs",
"build": "npm run build:app && npm run build:sea",
"build:app": "esbuild --bundle ./user-entrypoint.mjs --platform=node --outfile=./dist/cli.js --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=import_meta_url",
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl",
"build:sea": "./sea/build-sea.sh",
"format": "prettier -w src test package.json prettier.config.js eslint.config.mjs user-entrypoint.mjs"
"format": "prettier -w src test package.json prettier.config.js eslint.config.mjs"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion sea/import-meta-url.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export var import_meta_url = require('url').pathToFileURL(__filename);
export let importMetaUrl = require('url').pathToFileURL(__filename);
2 changes: 1 addition & 1 deletion sea/sea-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "./dist/cli.js",
"main": "./dist/cli.cjs",
"output": "./dist/sea.blob",
"disableExperimentalSEAWarning": true
}
1 change: 0 additions & 1 deletion src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export async function run(argvInput, _container) {
const parseYargs = container.resolve("parseYargs");

try {

builtYargs = buildYargs(argvInput);
await parseYargs(builtYargs);
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/fauna-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default class FaunaClient {
* In order to allow commands to just close their client without having to worry about which
* client they received, adding this noop method here.
*/
static async close() {
// eslint-disable-next-line class-methods-use-this
async close() {
return undefined;
}
}
2 changes: 1 addition & 1 deletion src/lib/logger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function debug(text, component, argv) {
log({
text,
verbosity: 5,

stream: console.log,
component,
formatter: chalk.blue,
Expand Down
10 changes: 9 additions & 1 deletion src/lib/middleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { container } from "../cli.mjs";
import { fixPath } from "../lib/file-util.mjs";
Expand All @@ -21,7 +22,14 @@ export function fixPaths(argv) {
}

export function checkForUpdates(argv) {
const packagePath = path.join(__dirname, "../../package.json");
const __filename = fileURLToPath(import.meta.url);
let __dirname = path.dirname(__filename);
if (__dirname.split(path.sep).pop() === "dist") {
__dirname = path.normalize(path.join(__dirname, ".."));
} else {
__dirname = path.normalize(path.join(__dirname, "../.."));
}
const packagePath = path.join(__dirname, "package.json");
const updateNotifier = container.resolve("updateNotifier");

const notifier = updateNotifier({
Expand Down
4 changes: 2 additions & 2 deletions user-entrypoint.mjs → src/user-entrypoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import { hideBin } from "yargs/helpers";

import { run } from "./src/cli.mjs";
import { setupRealContainer as setupContainer } from "./src/config/setup-container.mjs";
import { run } from "./cli.mjs";
import { setupRealContainer as setupContainer } from "./config/setup-container.mjs";
(async () => {
run(hideBin(process.argv), setupContainer());
})();

0 comments on commit 5ec8613

Please sign in to comment.