Skip to content

Commit cf9b1f3

Browse files
committed
New point release
- Updated dependencies. - Fixes bug #8 - antlr-format uses deprecated packages (which also includes a file not found error for package.json).
1 parent c32c093 commit cf9b1f3

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

cli/ReadMe.md

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Run the tool with `--help` to have it print its supported parameters. For a deta
3737

3838
## Release Notes
3939

40+
### 1.2.6 - 1.2.8
41+
42+
- Updated dependencies.
43+
- Fixed bug #8 - antlr-format uses deprecated packages (which also includes a file not found error for package.json).
44+
4045
### 1.2.5
4146

4247
- Updated dependencies.

cli/antlr-format.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* Licensed under the MIT License. See License.txt in the project root for license information.
66
*/
77

8-
import process from "process";
9-
import { readFileSync, writeFileSync } from "fs";
8+
import { existsSync, readFileSync, writeFileSync } from "fs";
109
import { glob } from "glob";
10+
import process from "process";
11+
import path from "path";
1112

1213
import { OptionValues, program } from "commander";
1314

@@ -16,8 +17,8 @@ import { CharStream, CommonTokenStream } from "antlr4ng";
1617
import { ANTLRv4Lexer } from "../src/parser/ANTLRv4Lexer.js";
1718
import { IConfigurationDetails, processFormattingOptions } from "./process-options.js";
1819

19-
import { IFormattingOptions } from "../src/types.js";
2020
import { GrammarFormatter } from "../src/GrammarFormatter.js";
21+
import { IFormattingOptions } from "../src/types.js";
2122

2223
interface IAppParameters extends OptionValues {
2324
/** The path to a single source file or a glob pattern for multiple files. */
@@ -53,7 +54,15 @@ const matchBoolean = (value: string): boolean => {
5354
let packageJson: { version: string; };
5455

5556
try {
56-
packageJson = JSON.parse(readFileSync("./package.json", { encoding: "utf8" }));
57+
// Read the package.json file to get the version number. This file is located in the parent directory, when bundled
58+
// and in the same folder if not.
59+
const scriptPath = import.meta.url ? import.meta.url.substring(7) : __filename;
60+
let packagePath = path.join(path.dirname(scriptPath), "package.json");
61+
if (!existsSync(packagePath)) {
62+
packagePath = path.join(path.dirname(scriptPath), "../package.json");
63+
}
64+
65+
packageJson = JSON.parse(readFileSync(packagePath, { encoding: "utf8" }));
5766
} catch (error) {
5867
console.error("Error reading package.json file: " + error.message);
5968
process.exit(1);

cli/package-lock.json

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "antlr-format-cli",
3-
"version": "1.2.5",
3+
"version": "1.2.8",
44
"description": "A cli wrapper for the antlr-format package",
55
"author": "Mike Lischke",
66
"files": [
@@ -28,14 +28,15 @@
2828
"scripts": {
2929
"prepublishOnly": "npm run build",
3030
"build": "esbuild ./antlr-format.ts --main-fields=module,main --bundle --outfile=dist/antlr-format.cjs --platform=node --format=cjs --minify",
31-
"generate-configuration-schema": "./node_modules/.bin/ts-json-schema-generator --path '../src/types.ts' --type 'IConfiguration' > config-schema.json"
31+
"generate-configuration-schema": "./node_modules/.bin/ts-json-schema-generator --path '../src/types.ts' --type 'IConfiguration' > config-schema.json",
32+
"format-version": "antlr-format --version"
3233
},
3334
"dependencies": {
3435
"@readme/better-ajv-errors": "1.6.0",
35-
"ajv": "8.14.0",
36+
"ajv": "8.16.0",
3637
"antlr4ng": "3.0.4",
3738
"commander": "12.1.0",
3839
"glob": "10.4.1",
39-
"ts-json-schema-generator": "2.2.0"
40+
"ts-json-schema-generator": "2.3.0"
4041
}
4142
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"lint": "eslint --ext .ts .",
1515
"build": "tsc && esbuild ./src/index.ts --main-fields=module,main --bundle --outdir=dist --format=esm --packages=external",
1616
"build-watch": "npm run build -- --sourcemap --watch",
17-
"format-grammar-repo": "antlr-format --config tests/config.json -a ../grammars-v4/**/*.g4",
18-
"format-version": "antlr-format --version"
17+
"format-grammar-repo": "antlr-format --config tests/config.json -a ../grammars-v4/**/*.g4"
1918
},
2019
"repository": {
2120
"type": "git",

0 commit comments

Comments
 (0)