From dd51c74c57a3573a8e4f22c9d79957a929bc64d4 Mon Sep 17 00:00:00 2001 From: double beep <38133098+double-beep@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:03:41 +0000 Subject: [PATCH] fix: correctly replace `require.main` --- README.md | 2 +- dist/index.js | 7 +++++-- src/index.ts | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0b3c3d..6d5991a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ | Name | @userscripters/generate-readme | | Description | Readme generator parses package.json file and creates a README.md from it | | License | [GPL-3.0-or-later](https://spdx.org/licenses/GPL-3.0-or-later) | -| Version | 3.0.1 | +| Version | 3.0.2 | # Support diff --git a/dist/index.js b/dist/index.js index 26a334f..e09f103 100644 --- a/dist/index.js +++ b/dist/index.js @@ -19,7 +19,8 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -import { pathToFileURL } from "url"; +import { createRequire } from "module"; +import { fileURLToPath } from "url"; import chulk from "chalk"; import { addArg, parseArgs } from "./cli.js"; import { generateReadme, writeReadme } from "./readme.js"; @@ -70,6 +71,8 @@ const run = (args) => __awaiter(void 0, void 0, void 0, function* () { const content = yield generate(options); return content; }); -if (import.meta.url === pathToFileURL(process.argv[1]).href) +const scriptPath = createRequire(import.meta.url).resolve(process.argv[1]); +const modulePath = fileURLToPath(import.meta.url); +if (modulePath === scriptPath) run(process.argv); export { generate }; diff --git a/src/index.ts b/src/index.ts index c354e71..a189b0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import { pathToFileURL } from "url"; +import { createRequire } from "module"; +import { fileURLToPath } from "url"; import chulk from "chalk"; import { addArg, parseArgs } from "./cli.js"; import { generateReadme, writeReadme } from "./readme.js"; @@ -107,6 +108,8 @@ const run = async (args: typeof process.argv) => { return content; }; -if (import.meta.url === pathToFileURL(process.argv[1]).href) run(process.argv); +const scriptPath = createRequire(import.meta.url).resolve(process.argv[1]); +const modulePath = fileURLToPath(import.meta.url); +if (modulePath === scriptPath) run(process.argv); export { generate };