MapleLeaf 🍁M
Convex Community17mo ago
12 replies
MapleLeaf 🍁

Add clear and explicit way to exclude files from bundle

I found support-communityignore files in convex folder but making a new thread specifically because this is a feature request

I keep getting the need to exclude bundled files from time to time. In particular, I have a file with testing helpers that fails to compile because
convex-test
uses
crypto
:

import { convexTest, type TestConvexForDataModel } from "convex-test"
import type { DataModel, Id } from "../_generated/dataModel"
import schema from "../schema.ts"

export function createConvexTest() {
    return convexTest(schema, import.meta.glob("../**/*.ts"))
}

export async function createConvexTestWithIdentity(
    convex = createConvexTest(),
    { name = `maple_${crypto.randomUUID()}` } = {},
): Promise<TestConvexForDataModel<DataModel>> {
    const userId = await convex.run(async (ctx) => {
        return await ctx.db.insert("users", {})
    })

    return convex.withIdentity({
        name,
        subject: userId as Id<"users">,
    })
}

✘ [ERROR] Could not resolve "crypto"

    node_modules/.pnpm/convex-test@0.0.33_convex@1.16.6_react-dom@19.0.0-rc-1631855f-20241023_react@19.0.0-rc-163185_i2jgw5baye66ar2rtytco6tjiq/node_modules/convex-test/dist/index.js:5:27:
      5 │ import { createHash } from "crypto";
        ╵                            ~~~~~~~~

  The package "crypto" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


I renamed the file
lib/test.nobundle.ts
to work around it.

While the heuristic of "exclude if multiple dots in path" accounts for a lot, it feels a little... flimsy? or something like that

For example, you might want a file that has multiple dots in the path to be included; I tried to name a file
something.node.ts
as a companion to
something.ts
which includes the node actions, while the main file just has queries and mutations. I was confused for a hot minute why that wasn't included. I worked around it, but at the time, I didn't realize this rule was the cause.

I would prefer one of these alternatives, in order of preference:
-
"exclude"
or
"ignore"
config in convex.json
- a filename convention, like I did here
-
"use nobundle"
or
"use exclude"
or some other kind of file directive

Specifically with the file config, it would have the default of excluding
.test.
files or whatever else, and maybe you could add a special sigil for that, which I've seen in some config formats:
{ "exclude": ["$DEFAULT_EXCLUDES", "**/*.util.ts"] }
Was this page helpful?