Skip to content

Commit

Permalink
feat: export meta object (#162)
Browse files Browse the repository at this point in the history
* feat: export meta object

* Create strange-humans-enjoy.md
  • Loading branch information
ota-meshi committed May 9, 2023
1 parent f8fc1d8 commit 9afa0c4
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-humans-enjoy.md
@@ -0,0 +1,5 @@
---
"jsonc-eslint-parser": minor
---

feat: export meta object
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -10,8 +10,9 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"scripts": {
"build": "npm run build:ts",
"build:ts": "tsc --project ./tsconfig.build.json",
"build": "npm run build:meta && npm run build:tsc",
"build:meta": "ts-node --transpile-only ./tools/update-meta.ts",
"build:tsc": "tsc --project ./tsconfig.build.json",
"clean": "rimraf .nyc_output lib coverage",
"lint": "eslint . --ext .js,.ts,.json",
"eslint-fix": "eslint . --ext .js,.ts,.json --fix",
Expand All @@ -26,7 +27,7 @@
"benchmark": "ts-node --transpile-only benchmark/index.ts",
"prerelease": "npm run clean && npm run build",
"release": "changeset publish",
"version:ci": "changeset version"
"version:ci": "env-cmd -e version-ci npm run build:meta && changeset version"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -61,6 +62,7 @@
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"benchmark": "^2.1.4",
"env-cmd": "^10.1.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -9,8 +9,8 @@ import {

import type * as AST from "./parser/ast";
import { getVisitorKeys } from "./parser/visitor-keys";

export const name = "jsonc-eslint-parser";
export * as meta from "./meta";
export { name } from "./meta";

// parser
export { parseForESLint };
Expand Down
5 changes: 5 additions & 0 deletions src/meta.ts
@@ -0,0 +1,5 @@
// IMPORTANT!
// This file has been automatically generated,
// in order to update its content execute "npm run build:meta"
export const name = "jsonc-eslint-parser" as const;
export const version = "2.2.0" as const;
13 changes: 13 additions & 0 deletions tests/src/meta.ts
@@ -0,0 +1,13 @@
import assert from "assert";
import * as parser from "../../src";
import { version } from "../../package.json";
const expectedMeta = {
name: "jsonc-eslint-parser",
version,
};

describe("Test for meta object", () => {
it("A parser should have a meta object.", () => {
assert.deepStrictEqual(parser.meta, expectedMeta);
});
});
11 changes: 11 additions & 0 deletions tools/lib/changesets-util.ts
@@ -0,0 +1,11 @@
import getReleasePlan from "@changesets/get-release-plan";
import path from "path";

/** Get new version string from changesets */
export async function getNewVersion(): Promise<string> {
const releasePlan = await getReleasePlan(path.resolve(__dirname, "../.."));

return releasePlan.releases.find(
({ name }) => name === "jsonc-eslint-parser"
)!.newVersion;
}
38 changes: 38 additions & 0 deletions tools/update-meta.ts
@@ -0,0 +1,38 @@
import fs from "fs";
import path from "path";
import { ESLint } from "eslint";
import { name, version } from "../package.json";
import { getNewVersion } from "./lib/changesets-util";

const META_PATH = path.join(__dirname, "../src/meta.ts");

void main();

/** main */
async function main() {
if (!fs.existsSync(META_PATH)) {
fs.writeFileSync(META_PATH, "", "utf8");
}
const eslint = new ESLint({ fix: true });
const [result] = await eslint.lintText(
`/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content execute "npm run build:meta"
*/
export const name = ${JSON.stringify(name)} as const;
export const version = ${JSON.stringify(await getVersion())} as const;
`,
{ filePath: META_PATH }
);
fs.writeFileSync(META_PATH, result.output!);
}

/** Get version */
function getVersion() {
// eslint-disable-next-line no-process-env -- ignore
if (process.env.IN_VERSION_CI_SCRIPT) {
return getNewVersion();
}
return version;
}
5 changes: 4 additions & 1 deletion tsconfig.json
Expand Up @@ -18,7 +18,10 @@
"*": ["typings/*"]
},
"declaration": true,
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true,

"skipLibCheck": true
},
"include": [
"src/**/*",
Expand Down

0 comments on commit 9afa0c4

Please sign in to comment.