-
Notifications
You must be signed in to change notification settings - Fork 319
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
Support single file component (VueJS) #122
Comments
Thanks for contributing! This is an interesting case. It looks like an html parser (or a naive regex if possible) could be used to grab the imports out of inlined script tags. This could be made part of precinct for a .vue extension, but it would be nice to plug that in as a config from madge instead of precinct ballooning for all new frameworks. This isn't a trivial change, but possible. |
Maybe you can implement an interface for extracting js code for any extension and add option like --extract-from-extension vue and madge will search for file with name extractor-vue.js module.exports = function (contents, callback) {
callback("text", contents.match(/something/));
// in case of referring files like using src attribute
callback("refer", "./referred-file.js");
} and call the interface, maybe you can create extractors directory in the repo which have predefined extractors for popular frameworks. I forgot to indicate in previous comment that the script tag may refer to another file using the src attribute so the return of the interface maybe text or reference It's just an idea maybe you have a good one. |
I asked in Vue support about how to get script contents and they replied there are vue-template-compiler const compiler = require('vue-template-compiler')
const output = compiler.parseComponent(`<script>import file from './file'</script>`, {pad: 'line'});
console.log("output.script", output.script);
/*
output.script { type: 'script',
content: 'import file from \'./file\'',
start: 8,
attrs: {},
end: 33 }
*/ So now we can get the contents of the script tag and src attribute if it exists. I think make an interface for madge to handle files with custom extensions is a good idea we can make one extractor madge-extractor.js file and it should handle multiple extension module.exports = (extension, contents, callback) => {
let isReference = false
if (extension === "vue") {
const compiler = require('vue-template-compiler')
const output = compiler.parseComponent(contents, {pad: 'line'})
if(output.script){
isReference = output.script.attrs.src;
if(!isReference)
contents = output.script.content
}
}
/* callback(isReference?, reference|contents) */
callback(isReference, isReference ? isReference : contents);
} madge app.js --extensions js,vue --extractor madge-extractor.js |
Thanks for digging into this. Can regular components have the .vue extension or only these special template files? If only the special case applies, then the path forward is similar to how we want to add TypeScript support #64. You need the code you wrote in precinct. You may not need to modify filing-cabinet since it defaults to an es6 resolver. Although, if you're using webpack, you may or may not (on mobile, sorry I can't verify) need to support the additional .vue extension in the config for enhanced-resolve. I'm open to reviewing PRs for the effort. A good first step is to hack precinct and maybe filing-cabinet within madge's node_modules (or npm link if you're saavy) to get a proof of concept together. |
Sounds like a good time to pick up the extension/plugin support again :) How about something like how the webpack loaders work? Would that be suitable for precinct @mrjoelkemp? See https://webpack.js.org/concepts/loaders/ |
That sounds good. Would madge be the supplier of the html detective and partial-resolver (like the resolvers in filing-cabinet)? Or would you pass that off to users of madge to supply their own detective/resolver combo (i.e., language pack)? |
Is it fine to have the most recently registered language pack win in the case of conflicts (i.e., when folks override an existing file extension's language pack)? Or should it get chained (like a linked list within a hashmap) on conflicts (where every registered language pack for that extension gets run on the original source? |
Just a bump here to ask about progress. Madge is a pretty exciting project, but my repo has a mix of vue and JSX files. |
I just wrote a small script, which replaces all vue files and their imports with js) ATTENTIONThis script edits and deletes original files, i just use git to bring changes back |
@Enity If I could upvote you more, I def would. Thanks for your quick and dirty script =) It helped me handoff a mess of a Vue app to another Dev. Cheers! Also, love this project. It's incredible! |
any news? |
I create a polyfill for vue project. gist: https://gist.github.com/songlairui/287eaac29cda65cd5f1f7471b6661503 |
FYI, Nuxt.js just released the Components Module which I anticipate will grow in popularity. Whoever takes up this issue should keep that in mind. |
any news? |
Three years passed, has any progress...? |
@reuwi please feel free to submit a PR. |
I think it's a good way then @Enity's method, finally,I found madge add precinct to dependencies since 3.9.x,but not use it ,the reason is when dependency-tree require(precinct) and then polyfill require(precinct) ,these are two 'instance' of precinct. I had to use By the way,Madge is great tools for check project's file relations, and why does madge add precinct dependence, madge dependence dependency-tree has depend on precinct yet? @pahen @mrjoelkemp Thanks a lot! |
I needed this feature and implemented the support for Vue, I can create PRs soon |
I created a new detective vue package to handle vue single file components https://github.com/Havunen/detective-vue2 Created PR to node-precinct dependents/node-precinct#112 Support for vue single file components to node-filing-cabinet dependents/node-filing-cabinet#111 Then new version of precinct and node-filing-cabinet needs to be published and possibly bump the dependencies here: https://github.com/dependents/node-dependency-tree Then finally PR could be created to add support to Madge |
@mrjoelkemp can you review the PRs please, it would be nice for madge to support vue files 😀 |
This is way out of scope, but a tree-sitter parser would be more robust and able to handle all of kinds of alternate syntaxes, such as vue, svelte, tsx and non-js files such as html, pug, postcss and mixed variants such as svelte-pug, vue-scss-typescript. |
Any news? This addition will be really useful. I'm running madge 6.1.0 |
Is this still active? |
Madge has dependencies to these packages which have pending PRs |
For vue3, Enity's script needed some changes due to typescript support such as <script lang="ts"> <script setup lang="ts"> <script lang="tsx"> and the advent of .ts files. And need to handle cases where the vue file does not contain <script> tags. |
thats not work for me , I change 2
result: thats work |
就得是这个啊,靓仔,非常希望这个能力可以支持进去,因为当前vue已经非常热门了。 |
@pahen 麻烦看看这个哈 |
Just ran into this case, would really appreciate introduce .vue support. Is this still active? |
Support for vue single file components have been implemented!
Now we just need to bump madge dependencies |
@Havunen Are there any blockers for updating the dependencies? It seems like something fast and easy |
Anxiously waiting VUE file support. Currently .vue files are found, but no dependency is extracted from the |
@crystalfp which version of |
Don't have any detective-vue2 anywhere. No, even reinstalling it the |
Installing |
Does someone can share some mokey patch of Madge to support Vue SFC? Maybe some one could create a PR/Fork to support Vue SFC? |
The vue support has landed to master branch but it is not released to npm. @pahen Could you create a new release so this old issue could be closed. |
Release v8.0.0 now :) |
I'm using VueJS and single file components (.vue files) which have dependencies but madge shows that .vue files has no deps.
The file structure is like that
The text was updated successfully, but these errors were encountered: