-
Notifications
You must be signed in to change notification settings - Fork 47
the proof of concept about the new plugins API #56
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
Open
mightyaleksey
wants to merge
11
commits into
css-modules:master
Choose a base branch
from
mightyaleksey:proof-of-concept
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b96a97
the proof of concept about the new plugins API
mightyaleksey 16a8b53
arrow functions removed
mightyaleksey 6f10cfd
removing destructuring assignment
mightyaleksey 6981591
caching fixed
mightyaleksey 62acb51
Revert "caching fixed"
mightyaleksey cf6c22e
Revert "removing destructuring assignment"
mightyaleksey 358a375
Revert "arrow functions removed"
mightyaleksey 20f1cbe
Revert "the proof of concept about the new plugins API"
mightyaleksey dba5e2c
the new version
mightyaleksey 156df0c
added processor options
mightyaleksey ba498cf
test fix
mightyaleksey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var postcss = require('postcss'); | ||
var genericNames = require('generic-names'); | ||
var path = require('path'); | ||
|
||
var Values = require('postcss-modules-values'); | ||
var LocalByDefault = require('postcss-modules-local-by-default'); | ||
var ExtractImports = require('postcss-modules-extract-imports'); | ||
var Scope = require('postcss-modules-scope'); | ||
var Parser = require('postcss-modules-parser'); | ||
|
||
/** | ||
* @param {array} options.append | ||
* @param {array} options.prepend | ||
* @param {array} options.use | ||
* @param {function} options.createImportedName | ||
* @param {function|string} options.generateScopedName | ||
* @param {string} options.mode | ||
* @param {string} options.rootDir | ||
* @param {function} fetch | ||
* @return {object} | ||
*/ | ||
module.exports = function extractor(options, fetch) { | ||
options = options || {}; | ||
var append = options.append; | ||
var prepend = options.prepend; | ||
var createImportedName = options.createImportedName; | ||
var generateScopedName = options.generateScopedName; | ||
var mode = options.mode; | ||
var use = options.use; | ||
var context = options.rootDir || process.cwd(); | ||
|
||
var scopedName; | ||
if (generateScopedName) { | ||
scopedName = typeof generateScopedName !== 'function' | ||
? genericNames(generateScopedName || '[name]__[local]___[hash:base64:5]', {context: context}) | ||
: function (local, filename, css) { | ||
// had to wrap that function cause i didn't expected, | ||
// that generateShortName() and generateLongName() functions | ||
// use the fake path to file (relative to rootDir) | ||
// which result in the generated class names | ||
return generateScopedName(local, filename, css, context); | ||
}; | ||
} else { | ||
// small fallback | ||
scopedName = function (local, filename) { | ||
return Scope.generateScopedName(local, path.relative(context, filename)); | ||
} | ||
} | ||
|
||
var plugins; | ||
if (use) { | ||
plugins = use; | ||
} else { | ||
plugins = (prepend || []) | ||
.concat([ | ||
Values, | ||
mode | ||
? new LocalByDefault({mode: mode}) | ||
: LocalByDefault, | ||
createImportedName | ||
? new ExtractImports({createImportedName: createImportedName}) | ||
: ExtractImports, | ||
new Scope({generateScopedName: scopedName}), | ||
], append || []); | ||
} | ||
|
||
plugins = plugins.concat(new Parser({fetch: fetch})); | ||
|
||
return postcss(plugins); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
._cool_styles_styles__foo { | ||
._node_modules_cool_styles_styles__foo { | ||
color: #F00; | ||
} | ||
|
||
._styles__foo { | ||
background: black; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
._styles_2__bar { | ||
background: #BAA; | ||
} | ||
|
||
._styles_1__foo { | ||
color: #F00; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to move that file to the public module