Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

fix es6 with dynamic import to not show as missing dependencies #96

Merged
merged 2 commits into from
Apr 17, 2019
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

## [2.0.5-dev.1] - 2019-03-10
## [2.0.5-dev.2] - 2019-04-17

- fix es6 with dynamic import to not show as missing dependencies

## [2.0.5-dev.1] - 2019-04-16

- improve performance by lazy load all external packages and internal files

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": "2.0.5-dev.1",
"version": "2.0.5-dev.2",
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "eslint src && flow check || true",
Expand Down
19 changes: 19 additions & 0 deletions src/dependency-builder/dependency-tree/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,23 @@ describe('dependencyTree', function () {
expect(dependencies).to.be.ok;
});
});
describe('files with dynamic import', () => {
it('should not', () => {
mockfs({
[`${__dirname}/dynamic`]: {
'foo.js': 'const a = "./b"; import(a); require(a);'
}
});
const directory = path.normalize(`${__dirname}/dynamic`);
const filename = path.normalize(`${directory}/foo.js`);
const visited = {};

dependencyTree({
filename,
directory,
visited
});
expect(visited[filename].missing).to.be.undefined;
});
});
});
4 changes: 3 additions & 1 deletion src/dependency-builder/detectives/detective-es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ module.exports = function (src) {
}
break;
case 'CallExpression':
if (node.callee.type === 'Import' && node.arguments.length) {
if (node.callee.type === 'Import' && node.arguments.length && node.arguments[0].value) {
addDependency(node.arguments[0].value);
}
if (
node.callee.type === 'Identifier' && // taken from detective-cjs
node.callee.name === 'require' &&
node.arguments[0].value &&
node.arguments &&
node.arguments.length &&
(node.arguments[0].type === 'Literal' || node.arguments[0].type === 'StringLiteral')
Expand All @@ -88,6 +89,7 @@ module.exports = function (src) {
node.object.callee.name === 'require' &&
node.object.arguments &&
node.object.arguments.length &&
node.object.arguments[0].value &&
(node.object.arguments[0].type === 'Literal' || node.object.arguments[0].type === 'StringLiteral')
) {
const depValue = node.object.arguments[0].value;
Expand Down