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

Impossible to get dynamically imported files transpiled #116

Open
Aram1d opened this issue Aug 22, 2022 · 0 comments
Open

Impossible to get dynamically imported files transpiled #116

Aram1d opened this issue Aug 22, 2022 · 0 comments

Comments

@Aram1d
Copy link

Aram1d commented Aug 22, 2022

Hi,

I have a TS source code where I use fs.readdir to get a list of files I want to dynamically import.
The following code is an example of how do I import the files.

import { readdir } from "fs/promises";
import { resolve } from "path";

async function* getFiles(dir: string): AsyncIterable<string> {
  const dirents = await readdir(dir, { withFileTypes: true });
  for (const dirent of dirents) {
    const res = resolve(dir, dirent.name);
    if (dirent.isDirectory()) {
      yield* getFiles(res);
    } else {
      yield res;
    }
  }
}

const schemaChunks = [];

for await (const f of getFiles(__dirname + "/schemas")) {
  const match = f.match(/schemas\/.*Schema.ts/);
  if (match)
    schemaChunks.push(
      await import("./" + match[0]).then(({ typeDefs, resolvers }) => ({
        typeDefs,
        resolvers,
      }))
    );
}

Is there any way to force swc to transpile these file, despite the fact swc cannot load get their names, because this information comes at runtime. Can we have a swc config key which can take a glob pattern parameter too force inclusion of some files?

Tanks a lot

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

No branches or pull requests

1 participant