Skip to content

Commit 170f816

Browse files
authored
feat: export meta object (#467)
1 parent 5197597 commit 170f816

19 files changed

+132
-26
lines changed

.changeset/wicked-ways-leave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-svelte": minor
3+
---
4+
5+
feat: export meta object

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"sveltejs"
2727
],
2828
"scripts": {
29-
"build": "yarn build:ts",
29+
"build": "yarn build:meta && yarn build:ts",
30+
"build:meta": "yarn ts ./tools/update-meta.ts",
3031
"build:ts": "tsc --project ./tsconfig.build.json",
3132
"clean": "rimraf .nyc_output lib coverage build .svelte-kit svelte.config-dist.js",
3233
"cover": "nyc --reporter=lcov yarn test",

src/configs/base.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
export = {
25
plugins: ["svelte"],
36
overrides: [

src/configs/prettier.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
import path from "path"
25
const base = require.resolve("./base")
36
const baseExtend =

src/configs/recommended.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
import path from "path"
25
const base = require.resolve("./base")
36
const baseExtend =

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import recommended from "./configs/recommended"
55
import prettier from "./configs/prettier"
66
import all from "./configs/all"
77
import * as processor from "./processor"
8+
import * as meta from "./meta"
89

910
const configs = {
1011
base,
@@ -19,6 +20,7 @@ const rules = ruleList.reduce((obj, r) => {
1920
}, {} as { [key: string]: RuleModule })
2021

2122
export = {
23+
meta,
2224
configs,
2325
rules,
2426
processors: {

src/meta.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
4+
export const name = "eslint-plugin-svelte" as const
5+
export const version = "2.27.4" as const

src/processor/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Linter } from "eslint"
22
import type { Shared } from "../shared"
33
import { beginShared, terminateShared } from "../shared"
4+
export * as meta from "../meta"
45

56
/** preprocess */
67
export function preprocess(code: string, filename: string): string[] {

src/types-for-node.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
//
25
// The information here can be calculated by calculating the type,
36
// but is pre-defined to avoid the computational cost.

src/utils/rules.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
import type { RuleModule } from "../types"
25
import typescriptEslintNoUnnecessaryCondition from "../rules/@typescript-eslint/no-unnecessary-condition"
36
import blockLang from "../rules/block-lang"

tests/src/meta.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from "assert"
2+
import plugin from "../../src"
3+
import { version } from "../../package.json"
4+
const expectedMeta = {
5+
name: "eslint-plugin-svelte",
6+
version,
7+
}
8+
9+
describe("Test for meta object", () => {
10+
it("A plugin should have a meta object.", () => {
11+
assert.strictEqual(plugin.meta.name, expectedMeta.name)
12+
assert.strictEqual(typeof plugin.meta.version, "string")
13+
})
14+
15+
for (const [name, processor] of Object.entries(plugin.processors)) {
16+
it(`"${name}" processor should have a meta object.`, () => {
17+
assert.strictEqual(processor.meta.name, expectedMeta.name)
18+
assert.strictEqual(typeof processor.meta.version, "string")
19+
})
20+
}
21+
})

tools/lib/changesets-util.ts

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
import assembleReleasePlan from "@changesets/assemble-release-plan"
2-
import readChangesets from "@changesets/read"
3-
import { read } from "@changesets/config"
4-
import { getPackages } from "@manypkg/get-packages"
5-
import { readPreState } from "@changesets/pre"
1+
import getReleasePlan from "@changesets/get-release-plan"
62
import path from "path"
73

8-
const root = path.resolve(__dirname, "../..")
9-
104
/** Get new version string from changesets */
115
export async function getNewVersion(): Promise<string> {
12-
const packages = await getPackages(root)
13-
const preState = await readPreState(root)
14-
const config = await read(root, packages)
15-
const changesets = await readChangesets(root)
16-
17-
const releasePlan = assembleReleasePlan(
18-
changesets,
19-
packages,
20-
config,
21-
preState,
22-
)
6+
const releasePlan = await getReleasePlan(path.resolve(__dirname, "../.."))
237

248
return releasePlan.releases.find(
259
({ name }) => name === "eslint-plugin-svelte",

tools/update-meta.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import fs from "fs"
2+
import path from "path"
3+
import { ESLint } from "eslint"
4+
import { name, version } from "../package.json"
5+
import { getNewVersion } from "./lib/changesets-util"
6+
7+
const META_PATH = path.join(__dirname, "../src/meta.ts")
8+
9+
void main()
10+
11+
/** main */
12+
async function main() {
13+
if (!fs.existsSync(META_PATH)) {
14+
fs.writeFileSync(META_PATH, "", "utf8")
15+
}
16+
const eslint = new ESLint({ fix: true })
17+
const [result] = await eslint.lintText(
18+
`/*
19+
* IMPORTANT!
20+
* This file has been automatically generated,
21+
* in order to update its content execute "yarn update"
22+
*/
23+
export const name = ${JSON.stringify(name)} as const;
24+
export const version = ${JSON.stringify(await getVersion())} as const;
25+
`,
26+
{ filePath: META_PATH },
27+
)
28+
fs.writeFileSync(META_PATH, result.output!, "utf8")
29+
}
30+
31+
/** Get version */
32+
function getVersion() {
33+
// eslint-disable-next-line no-process-env -- ignore
34+
if (process.env.IN_VERSION_CI_SCRIPT) {
35+
return getNewVersion()
36+
}
37+
return version
38+
}

tools/update-rules.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ function toIdentifier(str: string) {
2121
return camelCase(clean)
2222
}
2323

24-
const content = `
24+
const content = `/*
25+
* IMPORTANT!
26+
* This file has been automatically generated,
27+
* in order to update its content execute "yarn update"
28+
*/
2529
import type { RuleModule } from "../types"
2630
${rules
2731
.map(

tools/update-rulesets.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import path from "path"
22
import fs from "fs"
33
import { rules } from "./lib/load-rules"
44

5-
const baseContent = `export = {
5+
const baseContent = `/*
6+
* IMPORTANT!
7+
* This file has been automatically generated,
8+
* in order to update its content execute "yarn update"
9+
*/
10+
export = {
611
plugins: ["svelte"],
712
overrides: [
813
{
@@ -37,7 +42,12 @@ const baseFilePath = path.resolve(__dirname, "../src/configs/base.ts")
3742
// Update file.
3843
fs.writeFileSync(baseFilePath, baseContent)
3944

40-
const recommendedContent = `import path from "path"
45+
const recommendedContent = `/*
46+
* IMPORTANT!
47+
* This file has been automatically generated,
48+
* in order to update its content execute "yarn update"
49+
*/
50+
import path from "path"
4151
const base = require.resolve("./base")
4252
const baseExtend =
4353
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base
@@ -64,7 +74,12 @@ const recommendedFilePath = path.resolve(
6474
// Update file.
6575
fs.writeFileSync(recommendedFilePath, recommendedContent)
6676

67-
const prettierContent = `import path from "path"
77+
const prettierContent = `/*
78+
* IMPORTANT!
79+
* This file has been automatically generated,
80+
* in order to update its content execute "yarn update"
81+
*/
82+
import path from "path"
6883
const base = require.resolve("./base")
6984
const baseExtend =
7085
path.extname(\`\${base}\`) === ".ts" ? "plugin:svelte/base" : base

tools/update-types-for-node.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const svelteNodeNames = Object.keys(visitorKeys).filter(
2525
)
2626

2727
const estreeCode = [
28-
`//
28+
`/*
29+
* IMPORTANT!
30+
* This file has been automatically generated,
31+
* in order to update its content execute "yarn update"
32+
*/
33+
//
2934
// Replace type information to use "@typescript-eslint/types" instead of "estree".
3035
//
3136
@@ -38,7 +43,12 @@ export type Statement = TSESTree.Statement
3843
export type Pattern = TSESTree.Pattern`,
3944
]
4045
const typesForNodeCode = [
41-
`//
46+
`/*
47+
* IMPORTANT!
48+
* This file has been automatically generated,
49+
* in order to update its content execute "yarn update"
50+
*/
51+
//
4252
// The information here can be calculated by calculating the type,
4353
// but is pre-defined to avoid the computational cost.
4454
//

tools/update.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import "./update-docs"
44
import "./update-readme"
55
import "./update-docs-rules-index"
66
import "./update-types-for-node"
7+
import "./update-meta"

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"paths": {
2020
"*": ["typings/*"]
2121
},
22-
"skipLibCheck": true
22+
"skipLibCheck": true,
23+
"resolveJsonModule": true
2324
},
2425
"include": [
2526
"src/**/*",

typings/estree/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT!
2+
// This file has been automatically generated,
3+
// in order to update its content execute "yarn update"
14
//
25
// Replace type information to use "@typescript-eslint/types" instead of "estree".
36
//

0 commit comments

Comments
 (0)