10000 run `check` command on `all-addon` test · Issue #344 · sveltejs/cli · GitHub
[go: up one dir, main page]

Skip to content

run check command on all-addon test #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
manuel3108 opened this issue Dec 3, 2024 · 17 comments · May be fixed by #569
Open

run check command on all-addon test #344

manuel3108 opened this issue Dec 3, 2024 · 17 comments · May be fixed by #569
Labels
enhancement New feature or request pkg:add sv add

Comments

@manuel3108
Copy link
Member

This should prevent stuff like #341 to happen again

@manuel3108 manuel3108 added enhancement New feature or request pkg:add sv add labels Dec 3, 2024
@AdrianGonz97
Copy link
Member

Adding check to the all-addon test wouldn't have helped in this scenario. This is an upstream issue that was introduced yesterday. See: #341 (comment)

@manuel3108
Copy link
Member Author

Ok, still think this would be a reasonable enhancement

@brettearle
Copy link
Contributor

Would you want it to run 'tsc' before the alladdons test kicks off proper since it is a long running test?

@manuel3108
Copy link
Member Author
manuel3108 commented May 3, 2025

I don't understand how running the typescript compiler is related to this, can you explain?

Edit: Do you potentially want to build the types of the "all-addon" test with that command? That should in theory already be handled by the build command that should be executed before.

@brettearle
Copy link
Contributor

I don't understand how running the typescript compiler is related to this, can you explain?

I was down the wrong rabbit hole. Thought this was to do with type mismatching. With type mismatch in #341 I thought short circuiting with tsc was the aim before bogging down in e2e tests.

@brettearle
Copy link
Contributor

Is it the script 'check' inside the test output that needs to be run?

@manuel3108
Copy link
Member Author

Is it the script 'check' inside the test output that needs to be run?

Yeah, that's what I was thinking about. But I remember this logged a bunch an of errors in the past, but it might be better now that #380. But I'm not convinced this is currently feasibly, as it might require us to go down the svelte/compiler road #94

@brettearle
Copy link
Contributor
brettearle commented May 7, 2025

I ran it manually from a test out put for all addons. No errors or warnings.

> kit-ts@0.0.1 check .../cli/.test-output/addons/all-addons/-754882197_1
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json


====================================
Loading svelte-check in workspace: .../cli/.test-output/addons/all-addons/-754882197_1
Getting Svelte diagnostics...

====================================
svelte-check found 0 errors and 0 warnings

@manuel3108
Copy link
Member Author

That's perfect, apparently I misremember. Then we should probably only change that test to execute the check command and bail if errors occur.

@brettearle
Copy link
Contributor

Sounds good I'll have a look in my next session

@brettearle
Copy link
Contributor

19 Errors occur on check within the JS test output. TS test output passes check. This means this check cmd doesn't work out of the box for users using JS instead of TS.

Do these need fixing and this check to pass on js? if so how do you want to go about it, as in issue per one, checklist etc?

Initial thoughts would be to add jsdoc or update the jsconfig.json, am open to ideas if there is a better way forward here?

====================================
Loading svelte-check in workspace: /home/brett/7_open_source/cli/.test-output/addons/all-addons/-754882197_0
Getting Svelte diagnostics...

.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/+page.server.js:5:20
Error: Property 'user' does not exist on type 'Locals'.
export const load = async (event) => {
        if (!event.locals.user) {
                return redirect(302, '/demo/lucia/login');


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/+page.server.js:8:30
Error: Property 'user' does not exist on type 'Locals'.
        }
        return { user: event.locals.user };
};


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/+page.server.js:13:21
Error: Property 'session' does not exist on type 'Locals'.
        logout: async (event) => {
                if (!event.locals.session) {
                        return fail(401);


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/+page.server.js:16:45
Error: Property 'session' does not exist on type 'Locals'.
                }
                await auth.invalidateSession(event.locals.session.id);
                auth.deleteSessionTokenCookie(event);


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:10:19
Error: Property 'user' does not exist on type 'Locals'.
export const load = async (event) => {
        if (event.locals.user) {
                return redirect(302, '/demo/lucia');


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:32:11
Error: No overload matches this call.
  Overload 1 of 3, '(left: SQLiteColumn<{ name: "username"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, { ...; }>, right: string | SQLWrapper): SQL<...>', gave the following error.
    Argument of type 'FormDataEntryValue | null' is not assignable to parameter of type 'string | SQLWrapper'.
      Type 'null' is not assignable to type 'string | SQLWrapper'.
  Overload 2 of 3, '(left: Aliased<string | File | null>, right: string | SQLWrapper | File | null): SQL<unknown>', gave the following error.
    Argument of type 'SQLiteColumn<{ name: "username"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, { ...; }>' is not assignable to parameter of type 'Aliased<string | File | null>'.
      Type 'SQLiteColumn<{ name: "username"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, { ...; }>' is missing the following properties from type 'Aliased<string | File | null>': sql, fieldAlias
  Overload 3 of 3, '(left: never, right: unknown): SQL<unknown>', gave the following error.
    Argument of type 'SQLiteColumn<{ name: "username"; tableName: "user"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, { ...; }>' is not assignable to parameter of type 'never'.
                        .from(table.user)
                        .where(eq(table.user.username, username));



.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:39:65
Error: Argument of type 'FormDataEntryValue | null' is not assignable to parameter of type 'string | Uint8Array<ArrayBufferLike>'.
  Type 'null' is not assignable to type 'string | Uint8Array<ArrayBufferLike>'.

                const validPassword = await verify(existingUser.passwordHash, password, {
                        memoryCost: 19456,


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:68:35
Error: Argument of type 'FormDataEntryValue | null' is not assignable to parameter of type 'string | Uint8Array<ArrayBufferLike>'.
  Type 'null' is not assignable to type 'string | Uint8Array<ArrayBufferLike>'.
                const userId = generateUserId();
                const passwordHash = await hash(password, {
                        // recommended minimum parameters


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:77:32
Error: No overload matches this call.
  Overload 1 of 2, '(value: { id: string | SQL<unknown> | Placeholder<string, any>; username: string | SQL<unknown> | Placeholder<string, any>; passwordHash: string | SQL<unknown> | Placeholder<...>; age?: number | ... 3 more ... | undefined; }): SQLiteInsertBase<...>', gave the following error.
    Type 'FormDataEntryValue | null' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
      Type 'null' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
  Overload 2 of 2, '(values: { id: string | SQL<unknown> | Placeholder<string, any>; username: string | SQL<unknown> | Placeholder<string, any>; passwordHash: string | SQL<unknown> | Placeholder<...>; age?: number | ... 3 more ... | undefined; }[]): SQLiteInsertBase<...>', gave the following error.
    Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; username: string | SQL<unknown> | Placeholder<string, any>; passwordHash: string | SQL<unknown> | Placeholder<...>; age?: number | ... 3 more ... | undefined; }[]'.
                try {
                        await db.insert(table.user).values({ id: userId, username, passwordHash });



.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:96:27
Error: Parameter 'username' implicitly has an 'any' type.

function validateUsername(username) {
        return (


.../cli/.test-output/addons/all-addons/-754882197_0/src/routes/demo/lucia/login/+page.server.js:105:27
Error: Parameter 'password' implicitly has an 'any' type.

function validatePassword(password) {
        return (


.../cli/.test-output/addons/all-addons/-754882197_0/src/hooks.server.js:5:28
Error: Binding element 'event' implicitly has an 'any' type.

const handleParaglide = ({ event, resolve }) => paraglideMiddleware(event.request, ({ request, locale }) => {
        event.request = request;


.../cli/.test-output/addons/all-addons/-754882197_0/src/hooks.server.js:5:35
Error: Binding element 'resolve' implicitly has an 'any' type.

const handleParaglide = ({ event, resolve }) => paraglideMiddleware(event.request, ({ request, locale }) => {
        event.request = request;


.../cli/.test-output/addons/all-addons/-754882197_0/src/hooks.server.js:9:26
Error: Binding element 'html' implicitly has an 'any' type.
        return resolve(event, {
                transformPageChunk: ({ html }) => html.replace('%paraglide.lang%', locale)
        });


.../cli/.test-output/addons/all-addons/-754882197_0/src/hooks.server.js:13:29
Error: Binding element 'event' implicitly has an 'any' type.

const handleAuth = async ({ event, resolve }) => {
        const sessionToken = event.cookies.get(auth.sessionCookieName);


.../cli/.test-output/addons/all-addons/-754882197_0/src/hooks.server.js:13:36
Error: Binding element 'resolve' implicitly has an 'any' type.

const handleAuth = async ({ event, resolve }) => {
        const sessionToken = event.cookies.get(auth.sessionCookieName);


.../cli/.test-output/addons/all-addons/-754882197_0/src/stories/Page.svelte:10:6
Error: Type 'null' is not assignable to type '{ name: string; } | undefined'. (js)
  <Header
    {user}
    onLogin={() => (user = { name: 'Jane Doe' })}


.../cli/.test-output/addons/all-addons/-754882197_0/src/stories/Page.svelte:11:21
Error: Type '{ name: string; }' is not assignable to type 'null'. (js)
    {user}
    onLogin={() => (user = { name: 'Jane Doe' })}
    onLogout={() => (user = null)}


.../cli/.test-output/addons/all-addons/-754882197_0/src/stories/Page.svelte:13:29
Error: Type '{ name: string; }' is not assignable to type 'null'. (js)
    onLogout={() => (user = null)}
    onCreateAccount={() => (user = { name: 'Jane Doe' })}
  />

@brettearle
Copy link
Contributor

The story book errors are solved by aligning the story book templates upstream. See storybookjs/storybook#31450

@brettearle
Copy link
Contributor
brettearle commented May 12, 2025

Jsdoc solves the rest with type comments in:
hooks.server.js
.../demo/lucia/+page.server.js
.../demo/lucia/login/+page.server.js

and will need to extend the type of locals in app.d.ts for lucia after adding jsdoc comments for the js version.
Suggestion to remove the if typescript from function below in ../packages/addons/lucia/index.ts line 344

if (typescript) {
	sv.file('src/app.d.ts', (content) => {
		const { ast, generateCode } = parseScript(content);

		const locals = js.kit.addGlobalAppInterface(ast, 'Locals');
		if (!locals) {
			throw new Error('Failed detecting `locals` interface in `src/app.d.ts`');
		}

		const user = locals.body.body.find((prop) => js.common.hasTypeProp('user', prop));
		const session = locals.body.body.find((prop) => js.common.hasTypeProp('session', prop));

		if (!user) {
			locals.body.body.push(createLuciaType('user'));
		}
		if (!session) {
			locals.body.body.push(createLuciaType('session'));
		}
		return generateCode();
	});
}

@brettearle
Copy link
Contributor

@manuel3108 I have a prototype returning 0 errors and warnings from check after these changes. Happy for me to start proper PR process?

@manuel3108
Copy link
Member Author

Absolutely, would love to see what you had to change!

@brettearle
Copy link
Contributor

With the hooks file ast, it is only paraglide and Lucia that writes to it. Ben did mention making more just into strings #557. These currently use the ast and to solve this the way I planned I need jsdoc comment for svelte type per hook function. Currently it seems I can only add this comment to top of the file as ast.common puts it there?
Is there a way to place comments precisely with ast? First time using it

@manuel3108
Copy link
Member Author

What about this method? Should be viable on nearly every AST node i think

function addComment(node: AstTypes.Node, comment: AstTypes.Comment) {

@brettearle brettearle linked a pull request May 19, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:add sv add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0