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

feat: dynamic imports support 🎉 #413

Merged
merged 5 commits into from
Feb 6, 2025
Merged

feat: dynamic imports support 🎉 #413

merged 5 commits into from
Feb 6, 2025

Conversation

ieedan
Copy link
Owner

@ieedan ieedan commented Feb 6, 2025

Fixes #412

With this PR jsrepo now supports detecting dependencies through the import(...) syntax in TypeScript and Svelte files.

Previously if you tried to do something like:

// these get resolved
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
import { createHighlighterCore } from 'shiki/core';

// nothing else does

const bundledLanguages = {
    bash: () => import('@shikijs/langs/bash'),
};

/** The languages configured for the highlighter */
type SupportedLanguage = keyof typeof bundledLanguages;

/** A preloaded highlighter instance. */
const highlighter = createHighlighterCore({
    themes: [
        import('@shikijs/themes/github-light-default'),
        import('@shikijs/themes/github-dark-default')
    ],
    langs: Object.entries(bundledLanguages).map(([_, lang]) => lang),
    engine: createJavaScriptRegexEngine()
});

In this case shiki is resolved correctly but @shiki/langs and @shiki/themes are not. Meaning this example will break your users when they install this code.

Why only Svelte and Typescript (.(js|ts|jsx|tsx))?

Currently with the way that vue structures it's AST it's not very straightforward to walk to get nested nodes. So for the time being this will only work for Svelte and Typescript. If you know of a way to make this work in Vue let me know!

@ieedan ieedan self-assigned this Feb 6, 2025
Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: e6570d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jsrepo Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jsrepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 6, 2025 2:22pm

Copy link

pkg-pr-new bot commented Feb 6, 2025

Open in Stackblitzprojectregistry

npm i https://pkg.pr.new/ieedan/jsrepo@413

commit: e6570d9

@ieedan ieedan changed the title feat: typescript/svelte dynamic imports support 🎉 feat: dynamic imports support 🎉 Feb 6, 2025
@ieedan ieedan merged commit 34e7ef3 into main Feb 6, 2025
5 checks passed
@ieedan ieedan deleted the dynamic-imports branch February 6, 2025 14:30
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

Successfully merging this pull request may close these issues.

feat: Detect dependencies from dynamic imports
1 participant