Skip to content

Commit 16166b1

Browse files
manuel3108Copilotjycouet
authored
chore: update esrap (#620)
* chore: update `esrap` * use esrap pkg.pr.new * fix `svelte-kit` adapter addon * remove useless comment * fix eslint * fix eslint * add changed tests * thats ok too * those are ok as well * fix last failing test * update esrap * adapt to new api * improvements * cleanup * remove useless comment * Update packages/core/tooling/index.ts Co-authored-by: Copilot <[email protected]> * re-add quote style * using esrap 2.2.1 * simplifying? * good enough? * simplify * add & remove * api? * manual snapshot review OK --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: jycouet <[email protected]>
1 parent 721bf85 commit 16166b1

File tree

25 files changed

+241
-138
lines changed

25 files changed

+241
-138
lines changed

packages/addons/eslint/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default defineAddon({
5353
});
5454

5555
sv.file(files.eslintConfig, (content) => {
56-
const { ast, generateCode } = parseScript(content);
56+
const { ast, comments, generateCode } = parseScript(content);
5757

5858
const eslintConfigs: Array<AstTypes.Expression | AstTypes.SpreadElement> = [];
5959
imports.addDefault(ast, { from: './svelte.config.js', as: 'svelteConfig' });
@@ -85,18 +85,16 @@ export default defineAddon({
8585
if (rules.properties[0].type !== 'Property') {
8686
throw new Error('rules.properties[0].type !== "Property"');
8787
}
88-
rules.properties[0].key.leadingComments = [
89-
{
90-
type: 'Line',
91-
value:
92-
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.'
93-
},
94-
{
95-
type: 'Line',
96-
value:
97-
' see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors'
98-
}
99-
];
88+
comments.add(rules.properties[0].key, {
89+
type: 'Line',
90+
value:
91+
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.'
92+
});
93+
comments.add(rules.properties[0].key, {
94+
type: 'Line',
95+
value:
96+
' see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors'
97+
});
10098

10199
const globalsConfig = object.create({
102100
languageOptions: {
@@ -153,7 +151,9 @@ export default defineAddon({
153151

154152
// type annotate config
155153
if (!typescript)
156-
common.addJsDocTypeComment(astNode, { type: "import('eslint').Linter.Config[]" });
154+
common.addJsDocTypeComment(astNode, comments, {
155+
type: "import('eslint').Linter.Config[]"
156+
});
157157

158158
if (typescript) imports.addDefault(ast, { from: 'typescript-eslint', as: 'ts' });
159159
imports.addDefault(ast, { from: 'globals', as: 'globals' });

packages/addons/sveltekit-adapter/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default defineAddon({
4949
sv.devDependency(adapter.package, adapter.version);
5050

5151
sv.file(files.svelteConfig, (content) => {
52-
const { ast, generateCode } = parseScript(content);
52+
const { ast, comments, generateCode } = parseScript(content);
5353

5454
// finds any existing adapter's import declaration
5555
const importDecls = ast.body.filter((n) => n.type === 'ImportDeclaration');
@@ -86,8 +86,15 @@ export default defineAddon({
8686
if (adapter.package !== '@sveltejs/adapter-auto') {
8787
const fallback = object.create({});
8888
const cfgKitValue = object.property(config, { name: 'kit', fallback });
89-
const cfgAdapter = object.propertyNode(cfgKitValue, { name: 'adapter', fallback });
90-
cfgAdapter.leadingComments = [];
89+
90+
// removes any existing adapter auto comments
91+
comments.remove(
92+
(c) =>
93+
c.loc &&
94+
cfgKitValue.loc &&
95+
c.loc.start.line >= cfgKitValue.loc.start.line &&
96+
c.loc.end.line <= cfgKitValue.loc.end.line
97+
);
9198
}
9299

93100
return generateCode();
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { defineConfig } from '@playwright/test';
22

33
export default defineConfig({
4-
webServer: {
5-
command: 'npm run build && npm run preview',
6-
port: 4173
7-
},
4+
webServer: { command: 'npm run build && npm run preview', port: 4173 },
85
testDir: 'e2e'
96
});

packages/cli/tests/snapshots/create-with-all-addons/src/app.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ declare global {
66
user: import('$lib/server/auth').SessionValidationResult['user'];
77
session: import('$lib/server/auth').SessionValidationResult['session']
88
}
9-
} // interface Error {}
10-
// interface Locals {}
11-
} // interface PageData {}
12-
// interface PageState {}
139

14-
// interface Platform {}
10+
// interface Error {}
11+
// interface Locals {}
12+
// interface PageData {}
13+
// interface PageState {}
14+
// interface Platform {}
15+
}
16+
}
17+
1518
export {};

packages/cli/tests/snapshots/create-with-all-addons/src/hooks.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const handleAuth: Handle = async ({ event, resolve }) => {
1717
if (!sessionToken) {
1818
event.locals.user = null;
1919
event.locals.session = null;
20+
2021
return resolve(event);
2122
}
2223

@@ -30,6 +31,7 @@ const handleAuth: Handle = async ({ event, resolve }) => {
3031

3132
event.locals.user = user;
3233
event.locals.session = session;
34+
3335
return resolve(event);
3436
};
3537

packages/cli/tests/snapshots/create-with-all-addons/svelte.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config = {
77
// Consult https://svelte.dev/docs/kit/integrations
88
// for more information about preprocessors
99
preprocess: [vitePreprocess(), mdsvex()],
10+
1011
kit: { adapter: adapter() },
1112
extensions: ['.svelte', '.svx']
1213
};

packages/cli/tests/snapshots/create-with-all-addons/vite.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,33 @@ export default defineConfig({
1010
tailwindcss(),
1111
sveltekit(),
1212
devtoolsJson(),
13-
paraglideVitePlugin({
14-
project: './project.inlang',
15-
outdir: './src/lib/paraglide'
16-
})
13+
paraglideVitePlugin({ project: './project.inlang', outdir: './src/lib/paraglide' })
1714
],
15+
1816
test: {
1917
expect: { requireAssertions: true },
18+
2019
projects: [
2120
{
2221
extends: './vite.config.ts',
22+
2323
test: {
2424
name: 'client',
25+
2526
browser: {
2627
enabled: true,
2728
provider: playwright(),
2829
instances: [{ browser: 'chromium', headless: true }]
2930
},
31+
3032
include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
3133
exclude: ['src/lib/server/**']
3234
}
3335
},
36+
3437
{
3538
extends: './vite.config.ts',
39+
3640
test: {
3741
name: 'server',
3842
environment: 'node',

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"dom-serializer": "^2.0.0",
3535
"domhandler": "^5.0.3",
3636
"domutils": "^3.2.2",
37-
"esrap": "^1.4.9",
37+
"esrap": "^2.2.1",
3838
"htmlparser2": "^9.1.0",
3939
"magic-string": "^0.30.21",
4040
"picocolors": "^1.1.1",
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { common, type AstTypes } from '@sveltejs/cli-core/js';
1+
import { common, type Comments, type AstTypes } from '@sveltejs/cli-core/js';
22

3-
export function run(ast: AstTypes.Program): void {
3+
export function run(ast: AstTypes.Program, comments: Comments): void {
44
const functionDeclaration = ast.body[0] as AstTypes.FunctionDeclaration;
55

6-
common.addJsDocComment(functionDeclaration, {
6+
common.addJsDocComment(functionDeclaration, comments, {
7+
params: { 'import("$lib/paraglide/runtime").AvailableLanguageTag': 'newLanguage' }
8+
});
9+
10+
// Adding 2 times the same comment should not add it twice!
11+
common.addJsDocComment(functionDeclaration, comments, {
712
params: { 'import("$lib/paraglide/runtime").AvailableLanguageTag': 'newLanguage' }
813
});
914
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/** @type {number} */
2-
const foo = 42;
1+
/** @type {number} */ const foo = 42;

0 commit comments

Comments
 (0)