diff --git a/.changeset/purple-countries-cough.md b/.changeset/purple-countries-cough.md new file mode 100644 index 00000000..50461901 --- /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 02c93e83..0bfa381b 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 a90facbb..879d8b8f 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 00bdd626..10fcea17 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 067cb844..250a60b3 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 432ade32..25dd078b 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 00000000..dcdffebf --- /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 33503d00..42db7b6a 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 24614414..7a182598 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 fe83fef6..ac1fb753 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/tests/src/meta.ts b/tests/src/meta.ts new file mode 100644 index 00000000..46816aa3 --- /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) + }) + } +}) diff --git a/tools/lib/changesets-util.ts b/tools/lib/changesets-util.ts index 88288f92..fa47cbc8 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 { - 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 b3b70138..f5f452ca 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 00000000..c54e5bcc --- /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 45447511..22c3aeaf 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 c0fcdd33..06f5e04b 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 d3392d31..fbfb787a 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 703cf12b..441b6cb9 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 ff829b02..b2711c2b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,8 @@ "@eslint-community/*": ["typings/@eslint-community/*"] }, - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true }, "include": [ "src/**/*",