Skip to content

Commit d361d39

Browse files
committed
feat!: change the plugin into an ESM-only package
1 parent 4c130da commit d361d39

File tree

207 files changed

+835
-1095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+835
-1095
lines changed

.env-cmdrc.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

.env-cmdrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": {
3+
"IN_VERSION_SCRIPT": "true"
4+
},
5+
"version-ci": {
6+
"IN_VERSION_CI_SCRIPT": "true"
7+
},
8+
"debug": {
9+
"DEBUG": "eslint-plugin-svelte*"
10+
},
11+
"update-fixtures": {
12+
"UPDATE_FIXTURES": "true"
13+
}
14+
}

packages/eslint-plugin-svelte/.env-cmdrc.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": {
3+
"IN_VERSION_SCRIPT": "true"
4+
},
5+
"version-ci": {
6+
"IN_VERSION_CI_SCRIPT": "true"
7+
},
8+
"debug": {
9+
"DEBUG": "eslint-plugin-svelte*"
10+
},
11+
"update-fixtures": {
12+
"UPDATE_FIXTURES": "true"
13+
}
14+
}

packages/eslint-plugin-svelte/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"engines": {
1111
"node": "^18.20.4 || ^20.18.0 || >=22.10.0"
1212
},
13-
"type": "commonjs",
13+
"type": "module",
1414
"main": "lib/index.js",
1515
"files": [
1616
"lib"
@@ -40,7 +40,7 @@
4040
"test": "pnpm run mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
4141
"test:debug": "env-cmd -e debug pnpm run test",
4242
"test:update-fixtures": "env-cmd -e update-fixtures pnpm run test",
43-
"ts": "node -r esbuild-register",
43+
"ts": "node --import tsx/esm",
4444
"typecov": "type-coverage",
4545
"update": "pnpm run ts ./tools/update.ts",
4646
"version": "env-cmd -e version pnpm run update",
@@ -63,7 +63,7 @@
6363
"known-css-properties": "^0.35.0",
6464
"postcss": "^8.4.49",
6565
"postcss-load-config": "^3.1.4",
66-
"postcss-safe-parser": "^7.0.0",
66+
"postcss-safe-parser": "^6.0.0",
6767
"postcss-selector-parser": "^7.0.0",
6868
"semver": "^7.6.3",
6969
"svelte-eslint-parser": "^1.0.0-next.1"
@@ -86,7 +86,6 @@
8686
"acorn": "^8.14.0",
8787
"assert": "^2.1.0",
8888
"esbuild": "^0.24.0",
89-
"esbuild-register": "^3.6.0",
9089
"eslint-scope": "^8.2.0",
9190
"eslint-typegen": "^0.3.2",
9291
"eslint-visitor-keys": "^4.2.0",
@@ -100,6 +99,7 @@
10099
"stylus": "^0.64.0",
101100
"svelte": "^5.2.9",
102101
"svelte-i18n": "^4.0.1",
102+
"tsx": "^4.19.2",
103103
"type-coverage": "^2.29.7",
104104
"yaml": "^2.6.1"
105105
},

packages/eslint-plugin-svelte/src/configs/all.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/eslint-plugin-svelte/src/configs/base.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/eslint-plugin-svelte/src/configs/flat/all.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Linter } from 'eslint';
2-
import { rules } from '../../utils/rules';
3-
import base from './base';
2+
import { rules } from '../../utils/rules.js';
3+
import base from './base.js';
44
const config: Linter.Config[] = [
55
...base,
66
{

packages/eslint-plugin-svelte/src/configs/flat/base.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
44
import type { ESLint, Linter } from 'eslint';
5+
import * as parser from 'svelte-eslint-parser';
6+
let pluginObject: ESLint.Plugin | null = null;
7+
export function setPluginObject(plugin: ESLint.Plugin): void {
8+
pluginObject = plugin;
9+
}
510
const config: Linter.Config[] = [
611
{
712
name: 'svelte:base:setup-plugin',
813
plugins: {
914
get svelte(): ESLint.Plugin {
10-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
11-
return require('../../index');
15+
return pluginObject!;
1216
}
1317
}
1418
},
1519
{
1620
name: 'svelte:base:setup-for-svelte',
1721
files: ['*.svelte', '**/*.svelte'],
1822
languageOptions: {
19-
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
20-
parser: require('svelte-eslint-parser')
23+
parser
2124
},
2225
rules: {
2326
// ESLint core rules known to cause problems with `.svelte`.

packages/eslint-plugin-svelte/src/configs/flat/prettier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
44
import type { Linter } from 'eslint';
5-
import base from './base';
5+
import base from './base.js';
66
const config: Linter.Config[] = [
77
...base,
88
{

packages/eslint-plugin-svelte/src/configs/flat/recommended.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
44
import type { Linter } from 'eslint';
5-
import base from './base';
5+
import base from './base.js';
66
const config: Linter.Config[] = [
77
...base,
88
{

packages/eslint-plugin-svelte/src/configs/prettier.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/eslint-plugin-svelte/src/configs/recommended.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
import './rule-types';
2-
import type { RuleModule } from './types';
3-
import { rules as ruleList } from './utils/rules';
4-
import base from './configs/base';
5-
import recommended from './configs/recommended';
6-
import prettier from './configs/prettier';
7-
import all from './configs/all';
8-
import flatBase from './configs/flat/base';
9-
import flatRecommended from './configs/flat/recommended';
10-
import flatPrettier from './configs/flat/prettier';
11-
import flatAll from './configs/flat/all';
12-
import * as processor from './processor';
13-
import * as meta from './meta';
2+
import type { RuleModule } from './types.js';
3+
import { rules as ruleList } from './utils/rules.js';
4+
import base, { setPluginObject } from './configs/flat/base.js';
5+
import recommended from './configs/flat/recommended.js';
6+
import prettier from './configs/flat/prettier.js';
7+
import all from './configs/flat/all.js';
8+
import * as processor from './processor/index.js';
9+
import * as meta from './meta.js';
1410

15-
const configs = {
11+
export const configs = {
1612
base,
1713
recommended,
1814
prettier,
1915
all,
20-
'flat/base': flatBase,
21-
'flat/recommended': flatRecommended,
22-
'flat/prettier': flatPrettier,
23-
'flat/all': flatAll
16+
// For backward compatibility
17+
'flat/base': base,
18+
'flat/recommended': recommended,
19+
'flat/prettier': prettier,
20+
'flat/all': all
2421
};
2522

26-
const rules = ruleList.reduce(
23+
export const rules = ruleList.reduce(
2724
(obj, r) => {
2825
obj[r.meta.docs.ruleName] = r;
2926
return obj;
3027
},
3128
{} as { [key: string]: RuleModule }
3229
);
3330

34-
export = {
35-
meta,
36-
configs,
31+
export { meta };
32+
export const processors = {
33+
'.svelte': processor,
34+
svelte: processor
35+
};
36+
37+
const plugin = {
3738
rules,
38-
processors: {
39-
'.svelte': processor,
40-
svelte: processor
41-
}
39+
configs,
40+
meta,
41+
processors
4242
};
43+
setPluginObject(plugin as never);
44+
export default plugin;

packages/eslint-plugin-svelte/src/processor/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Linter } from 'eslint';
2-
import type { Shared } from '../shared';
3-
import { beginShared, terminateShared } from '../shared';
4-
export * as meta from '../meta';
2+
import type { Shared } from '../shared/index.js';
3+
import { beginShared, terminateShared } from '../shared/index.js';
4+
export * as meta from '../meta.js';
55

66
/** preprocess */
77
export function preprocess(code: string, filename: string): string[] {

packages/eslint-plugin-svelte/src/rules/@typescript-eslint/no-unnecessary-condition.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
44
import type { TSESTree } from '@typescript-eslint/types';
55
import type { AST } from 'svelte-eslint-parser';
6-
import { createRule } from '../../utils';
6+
import { createRule } from '../../utils/index.js';
77
import {
88
isFalsyType,
99
getConstrainedTypeAtLocation,
@@ -20,9 +20,9 @@ import {
2020
getTypeOfPropertyOfType,
2121
getTypeName,
2222
isTupleType
23-
} from '../../utils/ts-utils';
24-
import type { TS, TSTools } from '../../utils/ts-utils';
25-
import { getSourceCode } from '../../utils/compat';
23+
} from '../../utils/ts-utils/index.js';
24+
import type { TS, TSTools } from '../../utils/ts-utils/index.js';
25+
import { getSourceCode } from '../../utils/compat.js';
2626

2727
/**
2828
* Returns all types of a union type or an array containing `type` itself if it's no union type.

packages/eslint-plugin-svelte/src/rules/block-lang.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createRule } from '../utils';
2-
import { getLangValue } from '../utils/ast-utils';
1+
import { createRule } from '../utils/index.js';
2+
import { getLangValue } from '../utils/ast-utils.js';
33
import type { SvelteScriptElement, SvelteStyleElement } from 'svelte-eslint-parser/lib/ast';
4-
import { getSourceCode } from '../utils/compat';
4+
import { getSourceCode } from '../utils/compat.js';
55

66
export default createRule('block-lang', {
77
meta: {

0 commit comments

Comments
 (0)