Skip to content

Commit 962f22f

Browse files
dominikgbluwy
andauthored
refactor: switch from .ts to .js with jsdoc (#655)
* refactor: move types to .d.ts files in preparation of ts-to-jsdoc * wip: convert ts to jsdoc * wip: ts to jsdoc * wip: ts to jsdoc conversion * wip: finished jsdoc conversion, renamed .d.ts files to avoid collisions, added .js ext to imports * test: add small wait for inspector icon to become visible to avoid flakiness in tests * wip: move internal types into src/types, improve index.d.ts * wip: move unit tests out of src dir and update filters * chore: switch to eslint-plugin-n to get rid of some errors * refactor: update jsdoc syntax (#656) --------- Co-authored-by: Bjorn Lu <[email protected]>
1 parent 6c79960 commit 962f22f

Some content is hidden

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

65 files changed

+1360
-972
lines changed

.eslintrc.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
root: true,
33
extends: [
44
'eslint:recommended',
5-
'plugin:node/recommended',
5+
'plugin:n/recommended',
66
'plugin:@typescript-eslint/eslint-recommended',
77
'prettier'
88
],
@@ -24,42 +24,40 @@ module.exports = {
2424
rules: {
2525
'no-console': 'off',
2626
'no-debugger': 'error',
27-
'node/no-missing-import': [
27+
'n/no-missing-import': [
2828
'error',
2929
{
30-
allowModules: ['types', 'estree', 'testUtils', '@sveltejs/vite-plugin-svelte'],
31-
tryExtensions: ['.ts', '.js', '.jsx', '.tsx']
30+
allowModules: ['types', 'estree', 'testUtils', '@sveltejs/vite-plugin-svelte', 'svelte']
3231
}
3332
],
34-
'node/no-missing-require': [
33+
'n/no-missing-require': [
3534
'error',
3635
{
3736
// for try-catching yarn pnp
38-
allowModules: ['pnpapi'],
39-
tryExtensions: ['.ts', '.js', '.jsx', '.tsx']
37+
allowModules: ['pnpapi']
4038
}
4139
],
4240

43-
'node/no-extraneous-import': [
41+
'n/no-extraneous-import': [
4442
'error',
4543
{
4644
allowModules: ['vite']
4745
}
4846
],
49-
'node/no-extraneous-require': [
47+
'n/no-extraneous-require': [
5048
'error',
5149
{
5250
allowModules: ['vite']
5351
}
5452
],
55-
'node/no-deprecated-api': 'off',
53+
'n/no-deprecated-api': 'off',
5654
'no-restricted-properties': [
5755
'error',
5856
{ property: 'substr', message: 'Use .slice instead of .substr.' }
5957
],
60-
'node/no-unpublished-import': 'off',
61-
'node/no-unpublished-require': 'off',
62-
'node/no-unsupported-features/es-syntax': 'off',
58+
'n/no-unpublished-import': 'off',
59+
'n/no-unpublished-require': 'off',
60+
'n/no-unsupported-features/es-syntax': 'off',
6361
'no-process-exit': 'off'
6462
},
6563
overrides: [
@@ -84,8 +82,8 @@ module.exports = {
8482
{
8583
files: ['packages/e2e-tests/**', 'packages/playground/**'],
8684
rules: {
87-
'node/no-extraneous-import': 'off',
88-
'node/no-extraneous-require': 'off',
85+
'n/no-extraneous-import': 'off',
86+
'n/no-extraneous-require': 'off',
8987
'no-unused-vars': 'off'
9088
},
9189
env: {
@@ -96,7 +94,7 @@ module.exports = {
9694
files: ['packages/e2e-tests/**/vite.config.js', 'packages/playground/**'],
9795
rules: {
9896
'no-unused-vars': 'off',
99-
'node/no-missing-require': 'off'
97+
'n/no-missing-require': 'off'
10098
}
10199
},
102100
{
@@ -112,7 +110,7 @@ module.exports = {
112110
'import/no-duplicates': 'off',
113111
'import/no-mutable-exports': 'off',
114112
'import/no-unresolved': 'off',
115-
'node/no-missing-import': 'off' // doesn't work with typescript's "import from 'src/foo.js'" for src/foo.ts
113+
'n/no-missing-import': 'off' // doesn't work with typescript's "import from 'src/foo.js'" for src/foo.ts
116114
}
117115
},
118116
{
@@ -124,10 +122,10 @@ module.exports = {
124122
'no-unused-labels': 'off',
125123
'no-console': 'off',
126124
'padded-blocks': 'off',
127-
'node/no-missing-import': 'off',
128-
'node/no-extraneous-require': 'off',
125+
'n/no-missing-import': 'off',
126+
'n/no-extraneous-require': 'off',
129127
'import/no-unresolved': 'off',
130-
'node/no-missing-require': 'off'
128+
'n/no-missing-require': 'off'
131129
}
132130
},
133131
{
@@ -138,10 +136,10 @@ module.exports = {
138136
'no-unused-labels': 'off',
139137
'no-console': 'off',
140138
'padded-blocks': 'off',
141-
'node/no-missing-import': 'off',
142-
'node/no-extraneous-require': 'off',
139+
'n/no-missing-import': 'off',
140+
'n/no-extraneous-require': 'off',
143141
'import/no-unresolved': 'off',
144-
'node/no-missing-require': 'off'
142+
'n/no-missing-require': 'off'
145143
}
146144
},
147145
{
@@ -152,18 +150,24 @@ module.exports = {
152150
browser: true
153151
},
154152
rules: {
155-
'node/no-extraneous-import': 'off',
156-
'node/no-missing-import': 'off',
157-
'node/no-unused-import': 'off'
153+
'n/no-extraneous-import': 'off',
154+
'n/no-missing-import': 'off',
155+
'n/no-unused-import': 'off'
158156
}
159157
},
160158
{
161159
files: ['packages/playground/kit-demo-app/src/**'],
162160
rules: {
163161
/* required because $app and $lib are not known */
164-
'node/no-missing-import': 'off',
162+
'n/no-missing-import': 'off',
165163
/* required because URL wasn't in node8 */
166-
'node/no-unsupported-features/node-builtins': 'off'
164+
'n/no-unsupported-features/node-builtins': 'off'
165+
}
166+
},
167+
{
168+
files: ['**/*.d.ts'],
169+
rules: {
170+
'no-unused-vars': 'off'
167171
}
168172
}
169173
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"eslint-config-prettier": "^8.8.0",
3232
"eslint-plugin-html": "^7.1.0",
3333
"eslint-plugin-markdown": "^3.0.0",
34-
"eslint-plugin-node": "^11.1.0",
34+
"eslint-plugin-n": "^16.0.0",
3535
"eslint-plugin-prettier": "^4.2.1",
3636
"eslint-plugin-svelte3": "^4.0.0",
3737
"execa": "^7.1.1",

packages/e2e-tests/hmr/src/components/DynamicImport.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
// eslint-disable-next-line node/no-missing-import
32
import asset from '/src/assets/dynamic.png';
43
const importedAsset = asset;
54
const label = 'dynamic-import';

packages/e2e-tests/hmr/src/components/StaticImport.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
// eslint-disable-next-line node/no-missing-import
32
import asset from '/src/assets/static.png';
43
const importedAsset = asset;
54
const label = 'static-import';

packages/e2e-tests/inspector-kit/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line node/no-missing-import
21
import { sveltekit } from '@sveltejs/kit/vite';
32

43
/** @type {import('vite').UserConfig} */

packages/e2e-tests/kit-node/src/routes/+page.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/** @type {import('./$types').PageLoad} */
22
export async function load() {
3-
// eslint-disable-next-line node/no-unsupported-features/es-builtins
43
if (globalThis?.window) {
54
// delay load on client so we can test hydration with playwright
65
return new Promise((resolve) =>

packages/e2e-tests/kit-node/src/routes/+page.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<script>
22
import { onMount } from 'svelte';
33
import { addMessages, init, _ } from 'svelte-i18n';
4-
// eslint-disable-next-line node/no-missing-import
54
import Counter from '$lib/Counter.svelte';
6-
// eslint-disable-next-line node/no-missing-import
75
import Child from '$lib/Child.svelte';
86
import { setSomeContext } from 'e2e-test-dep-svelte-api-only';
97
export let data = {};

packages/e2e-tests/kit-node/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line node/no-missing-import
21
import { sveltekit } from '@sveltejs/kit/vite';
32
import { transformValidation } from 'e2e-test-dep-vite-plugins';
43

packages/e2e-tests/preprocess-with-vite/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import App from './App.svelte';
2-
import { Hello } from './types';
2+
import { Hello } from './types.js';
33

44
const hello: Hello = 'Hello';
55

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
// eslint-disable-next-line prefer-const
21
import './someother.css';
32
export const foo: string = 'green';

packages/e2e-tests/testUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
browserLogs,
1717
e2eServer,
1818
waitForViteConnect
19-
} from './vitestSetup';
19+
} from './vitestSetup.js';
2020

21-
export * from './vitestSetup';
21+
export * from './vitestSetup.js';
2222

2323
export const hmrUpdateTimeout = 10000;
2424

packages/e2e-tests/ts-type-import/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Test } from './lib';
2-
import { test } from './lib';
1+
import type { Test } from './lib.js';
2+
import { test } from './lib.js';
33
import App from './App.svelte';
44

55
main();

packages/e2e-tests/vite-ssr-esm/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
2020

2121
const manifest = isProd
2222
? // @ts-ignore
23-
// eslint-disable-next-line node/no-missing-require
23+
2424
JSON.parse(fs.readFileSync(resolve('dist/client/ssr-manifest.json'), 'utf-8'))
2525
: {};
2626

@@ -103,6 +103,7 @@ createServer().then(({ app }) => {
103103
console.log('ssr server closed');
104104
});
105105
} finally {
106+
// eslint-disable-next-line n/no-process-exit
106107
process.exit(0);
107108
}
108109
};

packages/e2e-tests/vite-ssr-esm/src/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import Foo from './components/Foo.svelte';
33
import logo from './assets/logo.png';
4-
// eslint-disable-next-line node/no-missing-import
4+
55
import { esm } from 'e2e-test-dep-esm-only';
66
export let world = 'world'; // edit world and save to see hmr update
77
export let foo = 'foo';

packages/e2e-tests/vite-ssr-esm/src/entry-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import App from './App.svelte';
2-
// eslint-disable-next-line node/no-missing-import
2+
33
import { esm } from 'e2e-test-dep-esm-only';
44
console.log(esm());
55

packages/e2e-tests/vite-ssr-esm/src/entry-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import App from './App.svelte';
2-
// eslint-disable-next-line node/no-missing-import
2+
33
import { esm } from 'e2e-test-dep-esm-only';
44
import decamelize from 'decamelize';
55

packages/e2e-tests/vite-ssr/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
1717

1818
const manifest = isProd
1919
? // @ts-ignore
20-
// eslint-disable-next-line node/no-missing-require
20+
// eslint-disable-next-line n/no-missing-require
2121
require('./dist/client/ssr-manifest.json')
2222
: {};
2323

@@ -66,7 +66,7 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
6666
} else {
6767
template = indexProd;
6868
// @ts-ignore
69-
// eslint-disable-next-line node/no-missing-require
69+
// eslint-disable-next-line n/no-missing-require
7070
render = require('./dist/server/entry-server.js').render;
7171
}
7272
const rendered = await render(req.originalUrl, manifest);
@@ -101,6 +101,7 @@ createServer().then(({ app }) => {
101101
console.log('ssr server closed');
102102
});
103103
} finally {
104+
// eslint-disable-next-line n/no-process-exit
104105
process.exit(0);
105106
}
106107
};

packages/e2e-tests/vite-ssr/src/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import Foo from './components/Foo.svelte';
33
import logo from './assets/logo.png';
4-
// eslint-disable-next-line node/no-missing-import
4+
55
import { esm } from 'e2e-test-dep-esm-only';
66
export let world = 'world'; // edit world and save to see hmr update
77
export let foo = 'foo';

packages/e2e-tests/vite-ssr/src/entry-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import App from './App.svelte';
2-
// eslint-disable-next-line node/no-missing-import
2+
33
import { esm } from 'e2e-test-dep-esm-only';
44
console.log(esm());
55

packages/e2e-tests/vite-ssr/src/entry-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import App from './App.svelte';
2-
// eslint-disable-next-line node/no-missing-import
2+
33
import { esm } from 'e2e-test-dep-esm-only';
44
console.log(esm());
55

packages/e2e-tests/vite-ssr/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { defineConfig } = require('vite');
22

33
module.exports = defineConfig(async ({ command, mode }) => {
4-
//eslint-disable-next-line node/no-missing-import
54
const { svelte } = await import('@sveltejs/vite-plugin-svelte');
65
return {
76
plugins: [

packages/e2e-tests/vitestSetup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export async function waitForViteConnect(page: Page, timeoutMS = 5000) {
222222
let timerId;
223223
let pageConsoleListener;
224224
const timeoutPromise = new Promise(
225-
// eslint-disable-next-line no-unused-vars
226225
(_, reject) =>
227226
(timerId = setTimeout(() => {
228227
reject(`vite client not connected after ${timeoutMS}ms. url: ${page.url()}`);

packages/playground/big-component-library-kit/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//eslint-disable-next-line node/no-missing-import
21
import { sveltekit } from '@sveltejs/kit/vite';
32

43
/** @type {import('vite').UserConfig} */

packages/playground/big-component-library-vite-ssr/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ app.use('*', async (req, res) => {
4646
render = (await vite.ssrLoadModule('/src/entry-server.js')).render;
4747
} else {
4848
template = templateHtml;
49-
//eslint-disable-next-line node/no-missing-import
49+
//eslint-disable-next-line n/no-missing-import
5050
render = (await import('./dist/server/entry-server.js')).render;
5151
}
5252

packages/playground/kit-demo-app/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line node/no-missing-import
21
import { sveltekit } from '@sveltejs/kit/vite';
32

43
/** @type {import('vite').UserConfig} */

packages/vite-plugin-svelte-inspector/src/runtime/Inspector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
// do not use TS here so that this component works in non-ts projects too
33
import { onMount } from 'svelte';
4-
// eslint-disable-next-line node/no-missing-import
4+
55
import options from 'virtual:svelte-inspector-options';
66
const toggle_combo = options.toggleKeyCombo?.toLowerCase().split('-');
77
const nav_keys = Object.values(options.navKeys).map((k) => k.toLowerCase());

packages/vite-plugin-svelte-inspector/src/runtime/load-inspector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// eslint-disable-next-line node/no-missing-import
1+
// eslint-disable-next-line n/no-missing-import
22
import Inspector from 'virtual:svelte-inspector-path:Inspector.svelte';
33

44
function create_inspector_host() {

packages/vite-plugin-svelte/src/utils/__tests__/compile.spec.ts renamed to packages/vite-plugin-svelte/__tests__/compile.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from 'vitest';
2-
import { createCompileSvelte } from '../compile';
3-
import { ResolvedOptions } from '../options';
4-
const options: ResolvedOptions = {
2+
import { createCompileSvelte } from '../src/utils/compile.js';
3+
/** @type {import('../../types/options.d.ts').ResolvedOptions} */
4+
const options = {
55
compilerOptions: {
66
dev: false,
77
format: 'esm',
@@ -32,7 +32,7 @@ describe('createCompileSvelte', () => {
3232
const output = await compileSvelte(
3333
{
3434
cssId: 'svelte-xxxxx',
35-
query: undefined,
35+
query: {},
3636
raw: false,
3737
ssr: false,
3838
timestamp: Date.now(),

0 commit comments

Comments
 (0)