Skip to content

Commit

Permalink
feat: export meta object
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 9, 2023
1 parent f8f8ff9 commit 09ebd2a
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 25 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/a11y/keys.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/configs/base.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,6 +31,7 @@ const rules = ruleList.reduce((obj, r) => {
}, {} as { [key: string]: RuleModule })

export = {
meta,
configs,
rules,
processors: {
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 "npm run update"
export const name = "eslint-plugin-astro" as const
export const version = "0.26.2" as const
3 changes: 3 additions & 0 deletions src/processor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -45,4 +46,6 @@ export const processor: Linter.Processor = {
return messages
},
supportsAutofix: true,
// @ts-expect-error -- missing type
meta,
}
3 changes: 3 additions & 0 deletions src/types-for-node.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/utils/rules.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
20 changes: 20 additions & 0 deletions tests/src/meta.ts
Original file line number Diff line number Diff line change
@@ -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)
})
}
})
20 changes: 2 additions & 18 deletions tools/lib/changesets-util.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion tools/update-jsx-a11y-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tools/update-meta.ts
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 5 additions & 1 deletion tools/update-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tools/update-types-for-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tools/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"@eslint-community/*": ["typings/@eslint-community/*"]
},

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

0 comments on commit 09ebd2a

Please sign in to comment.