Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
25d0bbf
chore: update `esrap`
manuel3108 Jun 28, 2025
c5aa975
Merge remote-tracking branch 'origin/main' into chore/esrap-2
manuel3108 Sep 7, 2025
9394c80
use esrap pkg.pr.new
manuel3108 Oct 26, 2025
79f262e
fix `svelte-kit` adapter addon
manuel3108 Oct 26, 2025
7c0c0d2
remove useless comment
manuel3108 Oct 26, 2025
f41da14
fix eslint
manuel3108 Oct 26, 2025
7307cc4
fix eslint
manuel3108 Oct 26, 2025
6df65fc
add changed tests
manuel3108 Oct 26, 2025
ae78455
thats ok too
manuel3108 Oct 26, 2025
23d569d
Merge branch 'main' into chore/esrap-2
manuel3108 Oct 26, 2025
1982ac4
those are ok as well
manuel3108 Oct 26, 2025
62444cc
fix last failing test
manuel3108 Oct 26, 2025
d871736
Merge branch 'main' into chore/esrap-2
manuel3108 Nov 26, 2025
0b55155
update esrap
manuel3108 Nov 26, 2025
54685d8
adapt to new api
manuel3108 Nov 30, 2025
0e56b56
improvements
manuel3108 Nov 30, 2025
a89a0e9
cleanup
manuel3108 Nov 30, 2025
4efbc25
remove useless comment
manuel3108 Nov 30, 2025
15d3400
Update packages/core/tooling/index.ts
manuel3108 Nov 30, 2025
c3ca656
Merge branch 'chore/esrap-2' of https://github.com/sveltejs/cli into …
manuel3108 Nov 30, 2025
7160300
re-add quote style
manuel3108 Dec 1, 2025
748cc4e
using esrap 2.2.1
jycouet Dec 1, 2025
d7ff4b2
simplifying?
jycouet Dec 1, 2025
9ef38e3
good enough?
jycouet Dec 1, 2025
2e6b85d
simplify
jycouet Dec 2, 2025
8053314
add & remove
jycouet Dec 2, 2025
44d7a85
api?
jycouet Dec 2, 2025
061e94b
Merge branch 'main' of github.com:sveltejs/cli into chore/esrap-2
jycouet Dec 2, 2025
3afb161
manual snapshot review OK
jycouet Dec 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/addons/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineAddon({
});

sv.file(files.eslintConfig, (content) => {
const { ast, generateCode } = parseScript(content);
const { ast, comments, generateCode } = parseScript(content);

const eslintConfigs: Array<AstTypes.Expression | AstTypes.SpreadElement> = [];
imports.addDefault(ast, { from: './svelte.config.js', as: 'svelteConfig' });
Expand Down Expand Up @@ -85,18 +85,16 @@ export default defineAddon({
if (rules.properties[0].type !== 'Property') {
throw new Error('rules.properties[0].type !== "Property"');
}
rules.properties[0].key.leadingComments = [
{
type: 'Line',
value:
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.'
},
{
type: 'Line',
value:
' 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'
}
];
comments.add(rules.properties[0].key, {
type: 'Line',
value:
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.'
});
comments.add(rules.properties[0].key, {
type: 'Line',
value:
' 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'
});

const globalsConfig = object.create({
languageOptions: {
Expand Down Expand Up @@ -153,7 +151,9 @@ export default defineAddon({

// type annotate config
if (!typescript)
common.addJsDocTypeComment(astNode, { type: "import('eslint').Linter.Config[]" });
common.addJsDocTypeComment(astNode, comments, {
type: "import('eslint').Linter.Config[]"
});

if (typescript) imports.addDefault(ast, { from: 'typescript-eslint', as: 'ts' });
imports.addDefault(ast, { from: 'globals', as: 'globals' });
Expand Down
13 changes: 10 additions & 3 deletions packages/addons/sveltekit-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineAddon({
sv.devDependency(adapter.package, adapter.version);

sv.file(files.svelteConfig, (content) => {
const { ast, generateCode } = parseScript(content);
const { ast, comments, generateCode } = parseScript(content);

// finds any existing adapter's import declaration
const importDecls = ast.body.filter((n) => n.type === 'ImportDeclaration');
Expand Down Expand Up @@ -86,8 +86,15 @@ export default defineAddon({
if (adapter.package !== '@sveltejs/adapter-auto') {
const fallback = object.create({});
const cfgKitValue = object.property(config, { name: 'kit', fallback });
const cfgAdapter = object.propertyNode(cfgKitValue, { name: 'adapter', fallback });
cfgAdapter.leadingComments = [];

// removes any existing adapter auto comments
comments.remove(
(c) =>
c.loc &&
cfgKitValue.loc &&
c.loc.start.line >= cfgKitValue.loc.start.line &&
c.loc.end.line <= cfgKitValue.loc.end.line
);
}

Comment thread
manuel3108 marked this conversation as resolved.
return generateCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
webServer: {
command: 'npm run build && npm run preview',
port: 4173
},
webServer: { command: 'npm run build && npm run preview', port: 4173 },
testDir: 'e2e'
});
13 changes: 8 additions & 5 deletions packages/cli/tests/snapshots/create-with-all-addons/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ declare global {
user: import('$lib/server/auth').SessionValidationResult['user'];
session: import('$lib/server/auth').SessionValidationResult['session']
}
} // interface Error {}
// interface Locals {}
} // interface PageData {}
// interface PageState {}

// interface Platform {}
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const handleAuth: Handle = async ({ event, resolve }) => {
if (!sessionToken) {
event.locals.user = null;
event.locals.session = null;

return resolve(event);
}

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

event.locals.user = user;
event.locals.session = session;

return resolve(event);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: [vitePreprocess(), mdsvex()],

kit: { adapter: adapter() },
extensions: ['.svelte', '.svx']
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@ export default defineConfig({
tailwindcss(),
sveltekit(),
devtoolsJson(),
paraglideVitePlugin({
project: './project.inlang',
outdir: './src/lib/paraglide'
})
paraglideVitePlugin({ project: './project.inlang', outdir: './src/lib/paraglide' })
],

test: {
expect: { requireAssertions: true },

projects: [
{
extends: './vite.config.ts',

test: {
name: 'client',

browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: 'chromium', headless: true }]
},

include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
exclude: ['src/lib/server/**']
}
},

{
extends: './vite.config.ts',

test: {
name: 'server',
environment: 'node',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dom-serializer": "^2.0.0",
"domhandler": "^5.0.3",
"domutils": "^3.2.2",
"esrap": "^1.4.9",
"esrap": "^2.2.1",
"htmlparser2": "^9.1.0",
"magic-string": "^0.30.21",
"picocolors": "^1.1.1",
Expand Down
11 changes: 8 additions & 3 deletions packages/core/tests/js/common/jsdoc-comment/run.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { common, type AstTypes } from '@sveltejs/cli-core/js';
import { common, type Comments, type AstTypes } from '@sveltejs/cli-core/js';

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

common.addJsDocComment(functionDeclaration, {
common.addJsDocComment(functionDeclaration, comments, {
params: { 'import("$lib/paraglide/runtime").AvailableLanguageTag': 'newLanguage' }
});

// Adding 2 times the same comment should not add it twice!
common.addJsDocComment(functionDeclaration, comments, {
params: { 'import("$lib/paraglide/runtime").AvailableLanguageTag': 'newLanguage' }
});
}
3 changes: 1 addition & 2 deletions packages/core/tests/js/common/jsdoc-type-comment/output.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/** @type {number} */
const foo = 42;
/** @type {number} */ const foo = 42;
6 changes: 3 additions & 3 deletions packages/core/tests/js/common/jsdoc-type-comment/run.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { common, variables, type AstTypes } from '@sveltejs/cli-core/js';
import { common, variables, type Comments, type AstTypes } from '@sveltejs/cli-core/js';

export function run(ast: AstTypes.Program): void {
export function run(ast: AstTypes.Program, comments: Comments): void {
const declaration = variables.declaration(ast, {
kind: 'const',
name: 'foo',
value: { type: 'Literal', value: 42 }
});

common.addJsDocTypeComment(declaration, {
common.addJsDocTypeComment(declaration, comments, {
type: 'number'
});

Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ for (const categoryDirectory of categoryDirectories) {

const inputFilePath = join(testDirectoryPath, 'input.ts');
const input = fs.existsSync(inputFilePath) ? fs.readFileSync(inputFilePath, 'utf8') : '';
const ast = parseScript(input);
const { ast, comments } = parseScript(input);

// dynamic imports always need to provide the path inline for static analysis
const module = await import(`./${categoryDirectory}/${testName}/run.ts`);
module.run(ast);
module.run(ast, comments);

let output = serializeScript(ast, input);
let output = serializeScript(ast, comments, input);
if (!output.endsWith('\n')) output += '\n';
await expect(output).toMatchFileSnapshot(`${testDirectoryPath}/output.ts`);
});
Expand Down
8 changes: 1 addition & 7 deletions packages/core/tests/js/object/create/output.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
const empty = {};
const created = { foo: 1, bar: 'string' };

// prettier-ignore
const created2 = {
foo: 1,
bar: 'string',
object: { foo: 'hello', nested: { bar: 'world' } },
array: [
123,
'hello',
{ foo: 'bar', bool: true },
[456, '789']
]
array: [123, 'hello', { foo: 'bar', bool: true }, [456, '789']]
};
1 change: 0 additions & 1 deletion packages/core/tests/js/object/create/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ export function run(ast: AstTypes.Program): void {
name: 'created2',
value: createdObject2
});
createdVariable2.leadingComments = [{ type: 'Line', value: ' prettier-ignore' }];
ast.body.push(createdVariable2);
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
const test = { a: { /** a comment */ keep: 'you', b: { c: '007' } } };
const test = {
a: {
/** a comment */
keep: 'you',

b: { c: '007' }
}
};
8 changes: 7 additions & 1 deletion packages/core/tests/js/object/override-property/output.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
const test = { /** a comment */ foo: 2, bar: 'string2', lorem: false };
const test = {
/** a comment */
foo: 2,

bar: 'string2',
lorem: false
};
7 changes: 6 additions & 1 deletion packages/core/tests/js/object/property-node/output.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
const test = { /*a comment updated*/ foo: 1, /*aka: bond, james bond*/ james: '007' };
const test = {
/** a comment */
foo: 1,

james: '007'
};
2 changes: 2 additions & 0 deletions packages/core/tests/js/vite/add-plugin-mode/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
firstPlugin(),

// a default plugin
sveltekit(),

middlePlugin(),
lastPlugin()
]
Expand Down
11 changes: 6 additions & 5 deletions packages/core/tests/js/vite/with-satisfies/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ const config = defineConfig({
plugins: [
// all plugins
examples,

Comment thread
manuel3108 marked this conversation as resolved.
tailwindcss(),
sveltekit(),
kitRoutes(),
myPlugin()
],

resolve: { alias: { $lib, $routes, $scripts, $actions } },
build: {
sourcemap: true,
target: 'esnext',
cssMinify: 'lightningcss'
},
build: { sourcemap: true, target: 'esnext', cssMinify: 'lightningcss' },

css: {
transformer: 'lightningcss',

lightningcss: {
targets: browserslistToTargets(browserslist('defaults, not ie 11'))
}
},

experimental: { enableNativePlugin: true }
}) satisfies UserConfig;

Expand Down
Loading
Loading