Skip to content

Commit

Permalink
fix: correctly replace require.main
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Jan 28, 2024
1 parent 10f7cf0 commit dd51c74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 };
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 };

0 comments on commit dd51c74

Please sign in to comment.