Comments (4)
mmh could it be possible to take the content
and format it without a super huge dependency instead (or even none)? this way users don't have to think about it, they pass their file content badly formatted and we do it for them?
from astro-integration-kit.
Misunderstanding: Related to this issue #65 about generating virtual module import/exports, if AIK generates import/exports it could also generate types for the module which would require a way to buffer lines/types and compile into a string for addDts
+1 for having this functionality native to addDts
or AIK in general it would make it a lot easier to generate good clean looking types (and do so dynamically)
I have a small implementation for something similar here to get an idea on how to do something like this without a package. I originally authored this as a plugin for AIK but had to move away from defineIntegration
for more control over typing. This is what my API looked while I had a plugin:
"astro:config:setup": ({ createDtsBuffer }) => {
const {
createLineBuffer,
addLinesToDts,
addLinesToDtsInterface,
addLinesToDtsNamespace,
addLinesToDtsModule,
writeDtsBuffer,
} = createDtsBuffer("my-integration")
// Add lines to .d.ts file
addLinesToDts(`
type ThemeName = "${themeName}";
type ThemeConfig = NonNullable<Parameters<typeof import("${entrypoint}").default>[0]>["config"]
`)
// Add lines for virtual module 'my-module'
addLinesToDtsModule(
"my-module",
Object.entries(objectModule)
.map(([name, entrypoint]) => `export const "${camelCase(name)}": typeof import("${resolveImport(entrypoint)}").default;`)
);
// Create your own line buffer (useful for generating nested types like objects inside interfaces)
const typeBuffer = createLineBuffer()
typeBuffer.add(Object.entries(objectModule).map(() => ...))
// Using the line buffer
addLinesToDtsInterface(
"SomeInterface",
typeBuffer.lines
)
// Compile buffer into a string and write to .d.ts file
writeDtsBuffer()
}
(This is just an example of how I solved this, not necessarily a suggestion for a full AIK API)
from astro-integration-kit.
@florian-lefebvre Yeah I'd be up for both! There are times when you want to dynamically create dts content or virtual module content and a helper like FileFactory
or the far, far superior createLineBuffer
@BryceRussell mentioned is a handy way to do it.
That being said we can definitely run the content pass into addDts
through unindent
and then at least then the user doesn't have to worry about that for one off-files or whatever and still gets neat af files
from astro-integration-kit.
That one sounds interesting, idk if it has support for TS https://github.com/benjamn/recast
EDIT: it has support for it by specifying a specific parser
from astro-integration-kit.
Related Issues (20)
- Options setup type is incorrect
- TS quirk for third-party plugins HOT 1
- [feature] Warn (or fail) when adding a Vite plugin that is already present HOT 9
- update defineOption to use zod
- After adding from npm, the type is not identified. HOT 6
- Adding Astro Qwik to the showcase. HOT 4
- injectDevRoute HOT 1
- addVirtualImport should accept an array or a series of imports that can all live in one virtual export just like starlight HOT 13
- optionsSchema: allow refine, transform etc
- Automate `pnpm lint:fix` HOT 2
- update addVirtualImports to allow specifiying ssr
- React typing required for type validation even when not used HOT 3
- Support new "astro:db:setup" hook HOT 10
- Util that can create and read files from a hidden folder in the user's project HOT 2
- The `addVitePlugin` example code in the docs does not work. HOT 3
- `addIntegration` shows type error. HOT 3
- AIK v0.7 upgrade on `Astro-Gists` causes Vite to throw a fit
- Expected `name` field on `addVirtualImports` HOT 1
- Typing for AstroDB after semver 0.9 seems to have broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from astro-integration-kit.