Repository: ota-meshi/eslint-plugin-astro
Pull request #204 (2023-05-09 00:36:59)

feat: export meta object

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 09ebd2a47fa7e9935fd0513355a0dc5bf567b741

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/ota-meshi/eslint-plugin-astro/new/meta?filename=.changeset/purple-countries-cough.md&value=---%0A%22eslint-plugin-astro%22%3A%20patch%0A---%0A%0Afeat%3A%20export%20meta%20object%0A)



Patch:
diff --git a/.changeset/purple-countries-cough.md b/.changeset/purple-countries-cough.md
new file mode 100644
index 0000000..5046190
--- /dev/null
+++ b/.changeset/purple-countries-cough.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-astro": minor
+---
+
+feat: export meta object
diff --git a/package.json b/package.json
index 02c93e8..0bfa381 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,8 @@
   },
   "scripts": {
     "prebuild": "npm run -s clean",
-    "build": "npm run build:ts",
+    "build": "npm run build:meta && npm run build:ts",
+    "build:meta": "npm run ts -- ./tools/update-meta.ts",
     "build:ts": "tsc --project ./tsconfig.build.json",
     "clean": "rimraf lib .nyc_output dist coverage",
     "test": "npm run mocha -- \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
diff --git a/src/a11y/keys.ts b/src/a11y/keys.ts
index a90facb..879d8b8 100644
--- a/src/a11y/keys.ts
+++ b/src/a11y/keys.ts
@@ -1,3 +1,6 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
 import { getPluginJsxA11y } from "./load"
 
 const plugin = getPluginJsxA11y()
diff --git a/src/configs/base.ts b/src/configs/base.ts
index 00bdd62..10fcea1 100644
--- a/src/configs/base.ts
+++ b/src/configs/base.ts
@@ -1,3 +1,6 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
 import { hasTypescriptEslintParser } from "./has-typescript-eslint-parser"
 
 export = {
diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts
index 067cb84..250a60b 100644
--- a/src/configs/recommended.ts
+++ b/src/configs/recommended.ts
@@ -1,3 +1,6 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
 import path from "path"
 const base = require.resolve("./base")
 const baseExtend =
diff --git a/src/index.ts b/src/index.ts
index 432ade3..25dd078 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,6 +6,7 @@ import base from "./configs/base"
 import recommended from "./configs/recommended"
 import all from "./configs/all"
 import { buildA11yConfigs } from "./a11y"
+import * as meta from "./meta"
 
 const configs = {
   base,
@@ -30,6 +31,7 @@ const rules = ruleList.reduce((obj, r) => {
 }, {} as { [key: string]: RuleModule })
 
 export = {
+  meta,
   configs,
   rules,
   processors: {
diff --git a/src/meta.ts b/src/meta.ts
new file mode 100644
index 0000000..dcdffeb
--- /dev/null
+++ b/src/meta.ts
@@ -0,0 +1,5 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
+export const name = "eslint-plugin-astro" as const
+export const version = "0.26.2" as const
diff --git a/src/processor/index.ts b/src/processor/index.ts
index 33503d0..42db7b6 100644
--- a/src/processor/index.ts
+++ b/src/processor/index.ts
@@ -2,6 +2,7 @@ import type { ParseTemplateResult } from "astro-eslint-parser"
 import { parseTemplate } from "astro-eslint-parser"
 import type { Linter } from "eslint"
 import { beginShared, terminateShared } from "../shared"
+import * as meta from "../meta"
 
 export const processor: Linter.Processor = {
   preprocess(code: string, filename: string) {
@@ -45,4 +46,6 @@ export const processor: Linter.Processor = {
     return messages
   },
   supportsAutofix: true,
+  // @ts-expect-error -- missing type
+  meta,
 }
diff --git a/src/types-for-node.ts b/src/types-for-node.ts
index 2461441..7a18259 100644
--- a/src/types-for-node.ts
+++ b/src/types-for-node.ts
@@ -1,3 +1,6 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
 import type { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/types"
 import type { AST } from "astro-eslint-parser"
 import type * as ESTree from "estree"
diff --git a/src/utils/rules.ts b/src/utils/rules.ts
index fe83fef..ac1fb75 100644
--- a/src/utils/rules.ts
+++ b/src/utils/rules.ts
@@ -1,3 +1,6 @@
+// IMPORTANT!
+// This file has been automatically generated,
+// in order to update its content execute "npm run update"
 import type { RuleModule } from "../types"
 import noConflictSetDirectives from "../rules/no-conflict-set-directives"
 import noDeprecatedAstroCanonicalurl from "../rules/no-deprecated-astro-canonicalurl"
diff --git a/tools/lib/changesets-util.ts b/tools/lib/changesets-util.ts
index 88288f9..fa47cbc 100644
--- a/tools/lib/changesets-util.ts
+++ b/tools/lib/changesets-util.ts
@@ -1,25 +1,9 @@
-import assembleReleasePlan from "@changesets/assemble-release-plan"
-import readChangesets from "@changesets/read"
-import { read } from "@changesets/config"
-import { getPackages } from "@manypkg/get-packages"
-import { readPreState } from "@changesets/pre"
+import getReleasePlan from "@changesets/get-release-plan"
 import path from "path"
 
-const root = path.resolve(__dirname, "../..")
-
 /** Get new version string from changesets */
 export async function getNewVersion(): Promise<string> {
-  const packages = await getPackages(root)
-  const preState = await readPreState(root)
-  const config = await read(root, packages)
-  const changesets = await readChangesets(root)
-
-  const releasePlan = assembleReleasePlan(
-    changesets,
-    packages,
-    config,
-    preState,
-  )
+  const releasePlan = await getReleasePlan(path.resolve(__dirname, "../.."))
 
   return releasePlan.releases.find(
     ({ name }) => name === "eslint-plugin-astro",
diff --git a/tools/update-jsx-a11y-keys.ts b/tools/update-jsx-a11y-keys.ts
index b3b7013..f5f452c 100644
--- a/tools/update-jsx-a11y-keys.ts
+++ b/tools/update-jsx-a11y-keys.ts
@@ -3,7 +3,12 @@ import path from "path"
 import { rules, configs } from "eslint-plugin-jsx-a11y"
 import { formatAndSave } from "./lib/utils"
 
-const content = `import { getPluginJsxA11y } from "./load"
+const content = `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
+import { getPluginJsxA11y } from "./load"
 
 const plugin = getPluginJsxA11y()
 export const a11yRuleKeys = plugin?.rules
diff --git a/tools/update-meta.ts b/tools/update-meta.ts
new file mode 100644
index 0000000..c54e5bc
--- /dev/null
+++ b/tools/update-meta.ts
@@ -0,0 +1,34 @@
+import fs from "fs"
+import path from "path"
+import { name, version } from "../package.json"
+import { getNewVersion } from "./lib/changesets-util"
+import { formatAndSave } from "./lib/utils"
+
+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 code = `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
+export const name = ${JSON.stringify(name)} as const;
+export const version = ${JSON.stringify(await getVersion())} as const;
+`
+  await formatAndSave(META_PATH, code)
+}
+
+/** 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/tools/update-rules.ts b/tools/update-rules.ts
index 4544751..22c3aea 100644
--- a/tools/update-rules.ts
+++ b/tools/update-rules.ts
@@ -9,7 +9,11 @@ function camelCase(str: string) {
   return str.replace(/[-_](\w)/gu, (_, c) => (c ? c.toUpperCase() : ""))
 }
 
-const content = `
+const content = `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
 import type { RuleModule } from "../types"
 ${rules
   .map(
diff --git a/tools/update-rulesets.ts b/tools/update-rulesets.ts
index c0fcdd3..06f5e04 100644
--- a/tools/update-rulesets.ts
+++ b/tools/update-rulesets.ts
@@ -7,7 +7,12 @@ const baseRules = rules.filter(
 )
 void formatAndSave(
   path.resolve(__dirname, "../src/configs/base.ts"),
-  `import { hasTypescriptEslintParser } from "./has-typescript-eslint-parser"
+  `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
+import { hasTypescriptEslintParser } from "./has-typescript-eslint-parser"
 
 export = {
   plugins: ["astro"],
@@ -73,7 +78,12 @@ const recommendedRules = rules.filter(
 
 void formatAndSave(
   path.resolve(__dirname, "../src/configs/recommended.ts"),
-  `import path from "path"
+  `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
+import path from "path"
 const base = require.resolve("./base")
 const baseExtend =
   path.extname(\`\${base}\`) === ".ts" ? "plugin:astro/base" : base
diff --git a/tools/update-types-for-node.ts b/tools/update-types-for-node.ts
index d3392d3..fbfb787 100644
--- a/tools/update-types-for-node.ts
+++ b/tools/update-types-for-node.ts
@@ -25,7 +25,12 @@ const astroNodeNames = Object.keys(visitorKeys).filter(
   (k) => !tsEsNodeNames.includes(k) && !k.startsWith("Experimental"),
 )
 
-let code = `import type { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/types";
+let code = `/*
+ * IMPORTANT!
+ * This file has been automatically generated,
+ * in order to update its content execute "npm run update"
+ */
+import type { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/types";
 import type { AST } from "astro-eslint-parser"
 import type * as ESTree from "estree"
 
diff --git a/tools/update.ts b/tools/update.ts
index 703cf12..441b6cb 100644
--- a/tools/update.ts
+++ b/tools/update.ts
@@ -5,3 +5,4 @@ import "./update-readme"
 import "./update-docs-rules-index"
 import "./update-types-for-node"
 import "./update-jsx-a11y-keys"
+import "./update-meta"
diff --git a/tsconfig.json b/tsconfig.json
index ff829b0..b2711c2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -23,7 +23,8 @@
       "@eslint-community/*": ["typings/@eslint-community/*"]
     },
 
-    "skipLibCheck": true
+    "skipLibCheck": true,
+    "resolveJsonModule": true
   },
   "include": [
     "src/**/*",


Test patch:
diff --git a/tests/src/meta.ts b/tests/src/meta.ts
new file mode 100644
index 0000000..46816aa
--- /dev/null
+++ b/tests/src/meta.ts
@@ -0,0 +1,20 @@
+import assert from "assert"
+import plugin from "../../src"
+import { version } from "../../package.json"
+const expectedMeta = {
+  name: "eslint-plugin-astro",
+  version,
+}
+
+describe("Test for meta object", () => {
+  it("A plugin should have a meta object.", () => {
+    assert.deepStrictEqual(plugin.meta, expectedMeta)
+  })
+
+  for (const [name, processor] of Object.entries(plugin.processors)) {
+    it(`"${name}" processor should have a meta object.`, () => {
+      // @ts-expect-error -- missing type
+      assert.deepStrictEqual(processor.meta, expectedMeta)
+    })
+  }
+})