Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

## [1.0.3-dev.10] - 2018-07-09

- fix error "Cannot read property push of undefined" when a resolver throws an exception
- fix the resolver for an unknown extension

## [1.0.3-dev.9] - 2018-07-06

- bug fix - on Linux module path (require('a.js')) is resolved as relative path (require('./a.js'))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bit-javascript",
"version": "1.0.3-dev.9",
"version": "1.0.3-dev.10",
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "eslint src && flow check || true",
Expand Down
15 changes: 3 additions & 12 deletions src/dependency-builder/build-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,8 @@ function mergeMissingToTree(missingGroups, tree: Tree) {
function mergeErrorsToTree(baseDir, errors, tree: Tree) {
if (R.isEmpty(errors)) return;
Object.keys(errors).forEach((file) => {
const relativeFile = processPath(file, {}, baseDir);
if (tree[relativeFile]) tree[relativeFile].error = errors[file];
else tree[relativeFile] = { error: errors[file] };
if (tree[file]) tree[file].error = errors[file];
else tree[file] = { error: errors[file] };
});
}

Expand All @@ -361,13 +360,6 @@ function groupBySupportedFiles(filePaths: string[]) {
return R.groupBy(supportCriteria, filePaths);
}

function mergeUnsupportedFilesToTree(baseDir, unsupportedFiles: string[], tree: Tree) {
unsupportedFiles.forEach((file) => {
const relativeFile = processPath(file, {}, baseDir);
tree[relativeFile] = {};
});
}

/**
* Function for fetching dependency tree of file or dir
* @param baseDir working directory
Expand All @@ -394,14 +386,13 @@ export async function getDependencyTree({
resolveConfig: resolveConfigAbsolute
};
const { supportedFiles, unsupportedFiles } = groupBySupportedFiles(filePaths);
const { madgeTree, skipped, pathMap, errors } = generateTree(supportedFiles, config);
const { madgeTree, skipped, pathMap, errors } = generateTree(supportedFiles, unsupportedFiles, config);
const tree: Tree = groupDependencyTree(madgeTree, baseDir, bindingPrefix);
const { missingGroups, foundPackages } = groupMissing(skipped, baseDir, consumerPath, bindingPrefix);

if (foundPackages) mergeManuallyFoundPackagesToTree(foundPackages, missingGroups, tree);
if (errors) mergeErrorsToTree(baseDir, errors, tree);
if (missingGroups) mergeMissingToTree(missingGroups, tree);
if (unsupportedFiles) mergeUnsupportedFilesToTree(baseDir, unsupportedFiles, tree);
if (pathMap) updateTreeWithPathMap(tree, pathMap, baseDir);

return { tree };
Expand Down
3 changes: 2 additions & 1 deletion src/dependency-builder/filing-cabinet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ module.exports = function cabinet(options: Options) {

const getResolverResults = () => {
// old resolver are not getting an object parameter
if (resolver.name === 'resolveDependencyPath' || ext === '.styl') {
if (resolver.length > 1) {
// check whether the 'resolver' function gets more than one parameter
// $FlowFixMe
return resolver(partial, filename, directory);
}
Expand Down
12 changes: 12 additions & 0 deletions src/dependency-builder/filing-cabinet/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ describe('filing-cabinet', () => {
});
});

describe('unrecognized extension', () => {
it('uses a generic resolve for unsupported file extensions', () => {
const result = cabinet({
partial: './bar',
filename: 'barbazim/foo.baz',
directory: 'barbazim/'
});

assert.equal(result, path.normalize(`${mockRootDir}/barbazim/bar.baz`));
});
});

describe('.register', () => {
it('registers a custom resolver for a given extension', () => {
const stub = sinon.stub().returns('foo.foobar');
Expand Down
23 changes: 19 additions & 4 deletions src/dependency-builder/generate-tree-madge.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function convertTree(depTree, tree, pathCache, baseDir) {
* @param config
* @return {Object}
*/
export default function generateTree(files = [], config) {
export default function generateTree(files = [], unsupportedFiles = [], config) {
const depTree = {};
const visited = {};
const nonExistent = {};
Expand Down Expand Up @@ -159,13 +159,28 @@ export default function generateTree(files = [], config) {
});

let tree = convertTree(depTree, {}, pathCache, config.baseDir);
for (const npmKey in npmPaths) {
const id = processPath(npmKey, pathCache, config.baseDir);

unsupportedFiles.forEach((file) => {
const relativeFile = processPath(file, pathCache, config.baseDir);
if (!tree[relativeFile]) tree[relativeFile] = [];
});

// rename errors keys from absolute paths to relative paths
Object.keys(errors).forEach((file) => {
const relativeFile = processPath(file, pathCache, config.baseDir);
if (relativeFile !== file) {
errors[relativeFile] = errors[file];
delete errors[file];
}
});

Object.keys(npmPaths).forEach((npmKey) => {
const id = processPath(npmKey, pathCache, config.baseDir);
if (!tree[id] && errors[id]) return; // if a file has errors, it won't be in the tree object but in the errors object
npmPaths[npmKey].forEach((npmPath) => {
tree[id].push(processPath(npmPath, pathCache, config.baseDir));
});
}
});

if (config.excludeRegExp) {
tree = exclude(tree, config.excludeRegExp);
Expand Down