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

Commit daff327

Browse files
authored
ignore import/require from CDN (http/https) (#99)
* ignore dependencies from CDN (import from https/http) * update CHANGELOG * bump version
1 parent 6846907 commit daff327

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [unreleased]
99

10+
## [2.0.7] - 2019-05-17
11+
12+
- ignore import/require from CDN (http/https)
13+
1014
## [2.0.6] - 2019-05-16
1115

1216
- fix identification of link files to take into account not only the `import` statements but also `export`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bit-javascript",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"scripts": {
55
"flow": "flow; test $? -eq 0 -o $? -eq 2",
66
"lint": "eslint src && flow check || true",

src/dependency-builder/dependency-tree/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ module.exports._getDependencies = function (config) {
9494
return resolvedDependencies;
9595

9696
function processDependency(dependency) {
97+
if (isHttp(dependency)) {
98+
debug(`skipping an http dependency: ${dependency}`);
99+
return;
100+
}
97101
const cabinetParams = {
98102
partial: dependency,
99103
filename: config.filename,
@@ -228,3 +232,10 @@ function traverse(config) {
228232
});
229233
}
230234
}
235+
236+
/**
237+
* whether the dependency is from CDN. (http/https)
238+
*/
239+
function isHttp(dependency) {
240+
return Boolean(dependency.startsWith('http://') || dependency.startsWith('https://'));
241+
}

src/dependency-builder/dependency-tree/index.spec.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ describe('dependencyTree', function () {
866866
});
867867
});
868868
describe('files with dynamic import', () => {
869-
it('should not', () => {
869+
it('should not show missing dependencies', () => {
870870
mockfs({
871871
[`${__dirname}/dynamic`]: {
872872
'foo.js': 'const a = "./b"; import(a); require(a);'
@@ -884,4 +884,38 @@ describe('dependencyTree', function () {
884884
expect(visited[filename].missing).to.be.undefined;
885885
});
886886
});
887+
describe('files with import from cdn (http, https)', () => {
888+
it('should not show missing dependencies when importing from https', () => {
889+
mockfs({
890+
[`${__dirname}/cdn`]: {
891+
'foo.js': 'import { a } from "https://unpkg.com";'
892+
}
893+
});
894+
const directory = path.normalize(`${__dirname}/cdn`);
895+
const filename = path.normalize(`${directory}/foo.js`);
896+
const visited = {};
897+
dependencyTree({
898+
filename,
899+
directory,
900+
visited
901+
});
902+
expect(visited[filename].missing).to.be.undefined;
903+
});
904+
it('should not show missing dependencies when importing from http', () => {
905+
mockfs({
906+
[`${__dirname}/cdn`]: {
907+
'bar.js': 'const b = require("http://pkg.com");'
908+
}
909+
});
910+
const directory = path.normalize(`${__dirname}/cdn`);
911+
const filename = path.normalize(`${directory}/bar.js`);
912+
const visited = {};
913+
dependencyTree({
914+
filename,
915+
directory,
916+
visited
917+
});
918+
expect(visited[filename].missing).to.be.undefined;
919+
});
920+
});
887921
});

0 commit comments

Comments
 (0)