diff --git a/.changeset/olive-birds-sort.md b/.changeset/olive-birds-sort.md new file mode 100644 index 00000000..df259b78 --- /dev/null +++ b/.changeset/olive-birds-sort.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: export meta object diff --git a/.env-cmdrc b/.env-cmdrc new file mode 100644 index 00000000..db5ffa1e --- /dev/null +++ b/.env-cmdrc @@ -0,0 +1,5 @@ +{ + "version-ci": { + "IN_VERSION_CI_SCRIPT": "true" + } +} diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index d880c770..642c14d8 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -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" diff --git a/package.json b/package.json index 9b0c65fe..ccbe72ef 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" @@ -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", diff --git a/src/index.ts b/src/index.ts index ac6f1405..f60afaf4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/src/meta.ts b/src/meta.ts new file mode 100644 index 00000000..6f67df36 --- /dev/null +++ b/src/meta.ts @@ -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; diff --git a/tests/src/meta.ts b/tests/src/meta.ts new file mode 100644 index 00000000..72e0622b --- /dev/null +++ b/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: "svelte-eslint-parser", + version, +}; + +describe("Test for meta object", () => { + it("A parser should have a meta object.", () => { + assert.deepStrictEqual(parser.meta, expectedMeta); + }); +}); diff --git a/tools/lib/changesets-util.ts b/tools/lib/changesets-util.ts new file mode 100644 index 00000000..11cdab28 --- /dev/null +++ b/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 { + const releasePlan = await getReleasePlan(path.resolve(__dirname, "../..")); + + return releasePlan.releases.find( + ({ name }) => name === "svelte-eslint-parser" + )!.newVersion; +} diff --git a/tools/update-meta.ts b/tools/update-meta.ts new file mode 100644 index 00000000..12ae96fb --- /dev/null +++ b/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 "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; +} diff --git a/tsconfig.json b/tsconfig.json index cb3978fa..86011a28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "esModuleInterop": true, + "resolveJsonModule": true, "skipLibCheck": true },