Skip to content
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

Plugin tries to look for dir in node_modules/.bin/ when relative path is specified #2

Open
Bewinxed opened this issue Mar 11, 2024 · 6 comments

Comments

@Bewinxed
Copy link
Contributor

Bewinxed commented Mar 11, 2024

I am using Elysia in a sveltekit project, with the svelte-adapter-bun adapter.

Here's the Repo
https://github.com/Bewinxed/elysiakit

I am initiating it like so:

export const app = new Elysia({})
	.use(
		autoload({
			prefix,
			dir: "./routes",
			types: {
				output: "/src/lib/elysia/route-types.ts",
			},
		}),
	)
	.use(
		swagger({
			path: `${prefix}/docs`,
		}),
	)
	.onRequest(({ request, set }) => {
		// FIX: For elysia-autoload, using swagger and elysia-autoload together causes double prefix, so we remove it
		if (request.url.includes(`${prefix}${prefix}`)) {
			set.redirect = request.url.replace(`${prefix}${prefix}`, prefix);
			return request;
		}
	});

here's my tsconfig

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"lib": [
			"ESNext"
		  ],
		  "module": "ESNext",
		  "target": "ESNext",
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"moduleResolution": "Bundler",
		"allowSyntheticDefaultImports": true,
		"noEmit": true,
		"paths": { "/*": ["./*"] }
	},
	"include": [
		"src"
	]
	// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
	//
	// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
	// from the referenced tsconfig.json - TypeScript does not merge them in
}

I run my project like bunx --bun vite

but when the plugin is loaded, the process.argv[1] resolves to /root/dev/elysiakit/node_modules/.bin/routes

/root/dev/elysiakit
22 | const TYPES_OUTPUT_DEFAULT = "./routes-types.ts";
23 | const TYPES_TYPENAME_DEFAULT = "Routes";
24 | async function autoload({ pattern, dir, prefix, schema, types, } = {}) {
25 |     const directoryPath = (0, utils_1.getPath)(dir || "./routes");
26 |     if (!(0, node_fs_1.existsSync)(directoryPath))
27 |         throw new Error(`Directory ${directoryPath} doesn't exists`);
                   ^
error: Directory /root/dev/elysiakit/node_modules/.bin/routes doesn't exists
      at /root/dev/elysiakit/node_modules/elysia-autoload/dist/index.js:27:15
      at autoload (/root/dev/elysiakit/node_modules/elysia-autoload/dist/index.js:24:27)
error: script "dev" exited with code 1

Any idea why this is happening?

@kravetsone
Copy link
Owner

maybe it cause because

if (isAbsolute(process.argv[1])) return join(process.argv[1], "..", dir);
...

bunx --bun vite is executed by node_modules/.bin/vite

any idea how to solve it?

send me yours argv

console.log(process.argv);

@Bewinxed
Copy link
Contributor Author

Bewinxed commented Mar 11, 2024

The output is

[ "/root/.bun/bin/bun", "/root/dev/elysiakit/node_modules/.bin/vite" ]

@kravetsone
Copy link
Owner

The output is

[ "/root/.bun/bin/bun", "/root/dev/elysiakit/node_modules/.bin/vite" ]

and send me import.meta.path

@kravetsone
Copy link
Owner

// FIX: For elysia-autoload, using swagger and elysia-autoload together causes double prefix, so we remove it
		if (request.url.includes(`${prefix}${prefix}`)) {
			set.redirect = request.url.replace(`${prefix}${prefix}`, prefix);
			return request;
		}

can you tell more about it? double slash in / route is fixed now with 405dad6

@Bewinxed
Copy link
Contributor Author

// FIX: For elysia-autoload, using swagger and elysia-autoload together causes double prefix, so we remove it
		if (request.url.includes(`${prefix}${prefix}`)) {
			set.redirect = request.url.replace(`${prefix}${prefix}`, prefix);
			return request;
		}

can you tell more about it? double slash in / route is fixed now with 405dad6

I opened another issue for this here

The output is

[ "/root/.bun/bin/bun", "/root/dev/elysiakit/node_modules/.bin/vite" ]

and send me import.meta.path

import meta inside utils.js /root/dev/elysiakit/node_modules/elysia-autoload/dist/utils.js
import meta inside src/elysia/backend.ts undefined

@kravetsone
Copy link
Owner

import meta inside src/elysia/backend.ts undefined

hmm... thats strange

but you can use absolute import for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants