Skip to content

Due to repair problems caused by Gulp require cache in the watch can …#5

Closed
aemoe wants to merge 2 commits intoposthtml:masterfrom
aemoe:master
Closed

Due to repair problems caused by Gulp require cache in the watch can …#5
aemoe wants to merge 2 commits intoposthtml:masterfrom
aemoe:master

Conversation

@aemoe
Copy link
Copy Markdown

@aemoe aemoe commented Aug 22, 2016

Thanks for the author, thank you for your code.
When I use a gulp when using the watch mode, because of caching issues require cache, and update the json time, can not be read to json modified files, so I can not do it automatically updates results, so modified the code I hope you fixed.

@maltsev
Copy link
Copy Markdown
Member

maltsev commented Aug 22, 2016

Thank you for your PR! Unfortunately, I cannot merge it as it's yet, because it's inefficient to invalidate the cache by each tree.match() iteration. I think it'd be better to purge the cache once before running tree.match(). Can you make the proper changes?

@aemoe
Copy link
Copy Markdown
Author

aemoe commented Aug 23, 2016

@maltsev thank you for your advise,i will try to find a better way that delete the cache of require.When I find, I will commit again.

@aemoe
Copy link
Copy Markdown
Author

aemoe commented Aug 23, 2016

@maltsev See also,yesterday I use an other way to resolve this bug, it use Node file stream. Cause of the file load every times, the cache will refresh. Shortly after,i will submit.
What do you think that this way whether to resolve this bug?
thx~ ~

@aemoe
Copy link
Copy Markdown
Author

aemoe commented Aug 23, 2016

IMG
fixed~ ~ test all pass~

@maltsev
Copy link
Copy Markdown
Member

maltsev commented Aug 24, 2016

The issue is still here: by each iteration a file with CSS modules is being re-read and re-parsed. I was thinking about using some simple cache. Something like this:

var cssModulesCache = {};
function getCssModules(cssModulesPath) {
    var fullPath = require.resolve(cssModulesPath);
    if (! cssModulesCache[fullPath]) {
        delete require.cache[fullPath];
        cssModulesCache[fullPath] = require(fullPath);
    }

    return cssModulesCache[fullPath];
}

// To purge the cache insert cssModulesCache = {}; before the tree.match()

maltsev added a commit that referenced this pull request Aug 28, 2016
It'd allow running the plugin in gulp watch and other similar tools,
where files with CSS modules might change between runs.

Related issue: #5
@maltsev
Copy link
Copy Markdown
Member

maltsev commented Aug 28, 2016

I fixed this bug and published the new version. @aemoe please check if everything works fine for you.

@maltsev maltsev closed this Aug 28, 2016
@aemoe
Copy link
Copy Markdown
Author

aemoe commented Aug 28, 2016

thank for fixed this bug~

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.

2 participants