Skip to content

Commit 5697930

Browse files
committed
Manual JSON import
Using `import` logs a warning in Node v22. Import it manually by reading the JSON file to avoid this warning.
1 parent 22b2c74 commit 5697930

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env node
2-
require('../dist/cli.js');
2+
import '../dist/cli.js';

src/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const VERSION = require('../package.json').version;
2-
31
import FS from 'node:fs';
42
import Path from 'node:path';
53
import { program } from 'commander';
64
import linguist from './index.js';
75
import { normPath } from './helpers/norm-path.js';
86

7+
const packageJson = JSON.parse(FS.readFileSync(new URL('../package.json', import.meta.url), "utf-8"));
8+
const VERSION = packageJson.version;
9+
910
const colouredMsg = ([r, g, b]: number[], msg: string): string => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
1011
const hexToRgb = (hex: string): number[] => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
1112

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Path from 'node:path';
33
import YAML from 'js-yaml';
44
import ignore, { Ignore } from 'ignore';
55
import commonPrefix from 'common-path-prefix';
6-
import binaryData from 'binary-extensions';
76
import { isBinaryFile } from 'isbinaryfile';
87

98
import walk from './helpers/walk-tree.js';
@@ -15,6 +14,10 @@ import { normPath } from './helpers/norm-path.js';
1514
import * as T from './types.js';
1615
import * as S from './schema.js';
1716

17+
const binaryData = JSON.parse(
18+
FS.readFileSync(new URL('../node_modules/binary-extensions/binary-extensions.json', import.meta.url), "utf-8")
19+
) as string[];
20+
1821
async function analyse(path?: string, opts?: T.Options): Promise<T.Results>
1922
async function analyse(paths?: string[], opts?: T.Options): Promise<T.Results>
2023
async function analyse(rawPaths?: string | string[], opts: T.Options = {}): Promise<T.Results> {

0 commit comments

Comments
 (0)