Skip to content

feat: export meta object #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-birds-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: export meta object
5 changes: 5 additions & 0 deletions .env-cmdrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version-ci": {
"IN_VERSION_CI_SCRIPT": "true"
}
}
2 changes: 2 additions & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
version: yarn version:ci
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
commit: "chore: release svelte-eslint-parser"
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
],
"scripts": {
"benchmark": "yarn ts benchmark/index.ts",
"build": "tsc --project ./tsconfig.build.json",
"build": "yarn build:meta && yarn build:tsc",
"build:meta": "yarn ts ./tools/update-meta.ts",
"build:tsc": "tsc --project ./tsconfig.build.json",
"clean": "rimraf .nyc_output lib coverage",
"cover": "nyc --reporter=lcov yarn test",
"debug": "yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
Expand All @@ -40,7 +42,8 @@
"release": "changeset publish",
"test": "yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
"ts": "node -r esbuild-register",
"update-fixtures": "yarn ts ./tools/update-fixtures.ts"
"update-fixtures": "yarn ts ./tools/update-fixtures.ts",
"version:ci": "env-cmd -e version-ci yarn build:meta && changeset version"
},
"peerDependencies": {
"svelte": "^3.37.0"
Expand Down Expand Up @@ -71,6 +74,7 @@
"@typescript-eslint/parser": "~5.59.0",
"benchmark": "^2.1.4",
"chai": "^4.3.4",
"env-cmd": "^10.1.0",
"esbuild": "^0.17.0",
"esbuild-register": "^3.3.3",
"eslint": "^8.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as AST from "./ast";
import { traverseNodes } from "./traverse";
import { KEYS } from "./visitor-keys";
import { ParseError } from "./errors";
export * as meta from "./meta";
export { name } from "./meta";

export { AST, ParseError };

export const name = "svelte-eslint-parser";

// parser
export { parseForESLint };
// Keys
Expand Down
5 changes: 5 additions & 0 deletions src/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// IMPORTANT!
// This file has been automatically generated,
// in order to update its content execute "yarn build:meta"
export const name = "svelte-eslint-parser" as const;
export const version = "0.27.0" as const;
13 changes: 13 additions & 0 deletions tests/src/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import assert from "assert";
import * as parser from "../../src";
import { version } from "../../package.json";
const expectedMeta = {
name: "svelte-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
Original file line number Diff line number Diff line change
@@ -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 === "svelte-eslint-parser"
)!.newVersion;
}
38 changes: 38 additions & 0 deletions tools/update-meta.ts
Original file line number Diff line number Diff line change
@@ -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 "yarn 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;
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,
"resolveJsonModule": true,

"skipLibCheck": true
},
Expand Down