Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d3b3d70

Browse filesBrowse files
committed
init
0 parents  commit d3b3d70
Copy full SHA for d3b3d70

File tree

Expand file treeCollapse file tree

5 files changed

+260
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+260
-0
lines changed

‎.gitignore

Copy file name to clipboard
+66Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sql
27+
*.sqlite
28+
29+
# OS generated files #
30+
######################
31+
.DS_Store*
32+
ehthumbs.db
33+
Icon?
34+
Thumbs.db
35+
36+
# Node.js #
37+
###########
38+
lib-cov
39+
*.seed
40+
*.log
41+
*.csv
42+
*.dat
43+
*.out
44+
*.pid
45+
*.gz
46+
47+
pids
48+
logs
49+
results
50+
51+
node_modules
52+
npm-debug.log
53+
54+
# Git #
55+
#######
56+
*.orig
57+
*.BASE.*
58+
*.BACKUP.*
59+
*.LOCAL.*
60+
*.REMOTE.*
61+
62+
# Components #
63+
##############
64+
65+
/build
66+
/components

‎Makefile

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BIN = ./node_modules/.bin/
2+
NODE ?= node
3+
4+
clean:
5+
@rm -rf build
6+
7+
test:
8+
@$(NODE) $(BIN)mocha \
9+
--harmony-generators \
10+
--require should \
11+
--reporter spec \
12+
--timeout 10000 \
13+
--bail
14+
15+
.PHONY: test clean

‎README.md

Copy file name to clipboard
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Compnent Flatten
2+
3+
`.flatten()` command in [component-resolver](https://github.com/component/resolver.js). Stored in a separate repo for standalone usage, but tests are included in `resolver.js` for simplicity. Use `npm link` to test.
4+
5+
The purpose of this method is to:
6+
7+
- Flatten the dependency tree into the proper build order. The proper build order is (specifically for CSS):
8+
1. Remotes dependencies
9+
2. Local dependencies
10+
3. Component's files
11+
- Check for multiple versions of a remote dependency
12+
- Check for locals with conflicting names.
13+
14+
## API
15+
16+
```js
17+
var resolver = require('component-resolver');
18+
var flatten = require('flatten');
19+
20+
resolver().getTree(function (err, tree) {
21+
if (err) throw err;
22+
var branches = flatten(tree);
23+
// do stuff with the branches
24+
})
25+
```
26+
27+
### var nodes[] = flatten(tree, [check])
28+
29+
`tree` is the result of `resolver`'s `.tree()` or `.getTree()` methods. If `check` is true, nodes will be populated with:
30+
31+
- `.duplicates` - an object containing remote dependencies with multiple versions
32+
- `.conflicts` - an object containing local dependencies who have the same name
33+
34+
## License
35+
36+
The MIT License (MIT)
37+
38+
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
39+
40+
Permission is hereby granted, free of charge, to any person obtaining a copy
41+
of this software and associated documentation files (the "Software"), to deal
42+
in the Software without restriction, including without limitation the rights
43+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44+
copies of the Software, and to permit persons to whom the Software is
45+
furnished to do so, subject to the following conditions:
46+
47+
The above copyright notice and this permission notice shall be included in
48+
all copies or substantial portions of the Software.
49+
50+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56+
THE SOFTWARE.

‎index.js

Copy file name to clipboard
+97Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var semver = require('semver')
2+
3+
/**
4+
* This probably belongs to a separate repo, but I'm lazy.
5+
*
6+
* returns the tree nodes, not the component.json,
7+
* so you can handle the resolved deps yourself.
8+
*
9+
* If `check` is true, this will check for duplicate dependencies
10+
* as well as locals with the same name.
11+
*
12+
* @param {Object} tree
13+
* @param {Boolean} check
14+
* @return {Array}
15+
* @api public
16+
*/
17+
18+
module.exports = function (tree, check) {
19+
var resolved = []
20+
var deps = {}
21+
var dependencies = []
22+
var locals = []
23+
24+
// duplicate dependencies
25+
var duplicates = {};
26+
// local name conflicts
27+
var conflicts = {};
28+
29+
traverse(tree)
30+
31+
// flatten the dependencies
32+
Object.keys(deps).forEach(function (name) {
33+
var branches = deps[name]
34+
var releases = Object.keys(branches)
35+
// duplicates detected
36+
if (check && releases.length > 1) duplicates[name] = branches;
37+
releases
38+
// non semver releases first
39+
.filter(function (release) {
40+
if (semver.valid(release)) return true
41+
dependencies.push(branches[release])
42+
return false
43+
})
44+
// ascending semver version
45+
.sort(semver.compare)
46+
.forEach(function (release) {
47+
dependencies.push(branches[release])
48+
})
49+
})
50+
51+
// check for duplicate local names
52+
if (check) {
53+
var localnames = {};
54+
locals.forEach(function (local) {
55+
var name = local.name;
56+
(localnames[name] = localnames[name] || [])
57+
.push(local);
58+
});
59+
Object.keys(localnames).forEach(function (name) {
60+
if (localnames[name].length > 1) conflicts[name] = localnames[name];
61+
});
62+
}
63+
64+
var out = dependencies.concat(locals);
65+
if (check) {
66+
out.duplicates = duplicates;
67+
out.conflicts = conflicts;
68+
}
69+
return out;
70+
71+
function traverse(branch) {
72+
if (~resolved.indexOf(branch)) return
73+
resolved.push(branch)
74+
traverseDeps(branch)
75+
traverseLocals(branch)
76+
if (branch.type === 'local') return locals.push(branch)
77+
// group together a component and its duplicate releases
78+
var releases = deps[branch.name] = deps[branch.name] || {}
79+
releases[branch.ref] = branch
80+
}
81+
82+
function traverseDeps(branch) {
83+
var deps = branch.dependencies
84+
if (!deps) return
85+
var names = Object.keys(deps)
86+
for (var i = 0; i < names.length; i++)
87+
traverse(deps[names[i]])
88+
}
89+
90+
function traverseLocals(branch) {
91+
var locals = branch.locals
92+
if (!locals) return
93+
var names = Object.keys(locals)
94+
for (var i = 0; i < names.length; i++)
95+
traverse(locals[names[i]])
96+
}
97+
}

‎package.json

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "component-flatten",
3+
"description": "flatten a resolved component tree",
4+
"version": "0.0.0",
5+
"author": {
6+
"name": "Jonathan Ong",
7+
"email": "me@jongleberry.com",
8+
"url": "http://jongleberry.com",
9+
"twitter": "https://twitter.com/jongleberry"
10+
},
11+
"license": "MIT",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/component/flatten.js.git"
15+
},
16+
"bugs": {
17+
"mail": "me@jongleberry.com",
18+
"url": "https://github.com/component/flatten.js/issues"
19+
},
20+
"dependencies": {
21+
"semver": "^2.2.1"
22+
},
23+
"peerDependencies": {
24+
"component-resolver": "*"
25+
}
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.