Skip to content

Commit 4597c3b

Browse files
committed
fix(esm): use import.meta in ESM instead of __dirname
1 parent cd27142 commit 4597c3b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/bin/index.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/usr/bin/env node
22
import fs from 'fs';
33
import path from 'path';
4+
import * as url from 'url';
45

5-
import c from 'ansi-colors';
6-
import glob from 'fast-glob';
6+
import { bold, red, green, dim } from 'ansi-colors';
7+
import { glob } from 'fast-glob';
78
// eslint-disable-next-line import/order -- what the actual heck, this rule bounces
89
import parser from 'yargs-parser';
910

1011
import type { OpenAPITSOptions } from 'openapi-typescript';
1112

1213
import { generate } from '../index.js';
1314

15+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
16+
1417
/** print error message */
1518
export function error(msg: string) {
16-
console.error(c.red(` ✘ ${msg}`)); // eslint-disable-line no-console
19+
console.error(red(` ✘ ${msg}`)); // eslint-disable-line no-console
1720
}
1821

1922
const HELP = `Usage
@@ -136,9 +139,7 @@ async function generateSchema(pathToSpec: string | typeof process.stdin) {
136139
const timeEnd = process.hrtime(timeStart);
137140
const time = timeEnd[0] + Math.round(timeEnd[1] / 1e6);
138141
console.log(
139-
`🚀 ${c.green(`${pathToSpec}${c.bold(outputFilePath.toString())}`)} ${c.dim(
140-
`[${time}ms]`,
141-
)}`,
142+
`🚀 ${green(`${pathToSpec}${bold(outputFilePath.toString())}`)} ${dim(`[${time}ms]`)}`,
142143
);
143144
} else {
144145
process.stdout.write(result);
@@ -166,7 +167,7 @@ async function main() {
166167
const outputDir = new URL('.', outputFile);
167168

168169
if (output === OUTPUT_FILE)
169-
console.info(`✨ ${c.bold(`openapi-typescript ${packageJSON.version}`)}`); // only log if we’re NOT writing to stdout
170+
console.info(`✨ ${bold(`openapi-typescript ${packageJSON.version}`)}`); // only log if we’re NOT writing to stdout
170171

171172
const pathToSpec = flags._[0] as string;
172173

0 commit comments

Comments
 (0)