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

[suggestion] build manta-style code into memory #25

Open
tanhauhau opened this issue Aug 12, 2018 · 6 comments
Open

[suggestion] build manta-style code into memory #25

tanhauhau opened this issue Aug 12, 2018 · 6 comments

Comments

@tanhauhau
Copy link
Collaborator

Can we build manta-style code into memory and eval it in memory instead of build code into .mantastyle-tmp?

@Cryrivers
Copy link
Owner

Cryrivers commented Aug 12, 2018

this was my first thought. but later i found somehow there might be external references in the config file. for example, you might need to import some modules from your projects. then it would be tricky to build it into memory, especially when your files indirectly references something in node_modules.

maybe we could move the temporary folder to /tmp?

@tanhauhau
Copy link
Collaborator Author

hmm. what kind of external references? i guess i need to read/use more manta-style to discover these kinds of "holes".

@Cryrivers
Copy link
Owner

external references as in you import some types from your projects. this is our common scenario as most of our types are in our project.

so TypeScript actually supports in-memory compilation. It provides transpileModule method to have string -> string compilation. However it doesn't support import iirc, you need to resolve import by yourself, that's why we are using the current way.

@Cryrivers
Copy link
Owner

Cryrivers commented Aug 13, 2018

Another "hole" is TypeScript doesn't rename (or maybe i don't know how) variables in the expressions created by the transformer. Say you create such statements:

import MantaStyle from '@manta-style/runtime';
// ...
MantaStyle.doSomething(...);

If our module target is commonjs, then it would be compiled as something like following:

var _a = require('@manta-style/runtime').default;
// ...
MantaStyle.doSomething(...);

MantaStyle here is supposed to be _a but TypeScript won't rename that.

So to solve this problem, i compile config files to ES Module version, then further to commonjs version with Babel.

@tanhauhau
Copy link
Collaborator Author

Probably they are not the same identifier node when you create the statement in the ast.

@Cryrivers
Copy link
Owner

Yep. Sad.

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

No branches or pull requests

2 participants