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

ignore import/require from CDN (http/https) #99

Merged
merged 3 commits into from
May 18, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

## [2.0.7] - 2019-05-17

- ignore import/require from CDN (http/https)

## [2.0.6] - 2019-05-16

- fix identification of link files to take into account not only the `import` statements but also `export`
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.6",
"version": "2.0.7",
"scripts": {
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "eslint src && flow check || true",
Expand Down
11 changes: 11 additions & 0 deletions src/dependency-builder/dependency-tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ module.exports._getDependencies = function (config) {
return resolvedDependencies;

function processDependency(dependency) {
if (isHttp(dependency)) {
debug(`skipping an http dependency: ${dependency}`);
return;
}
const cabinetParams = {
partial: dependency,
filename: config.filename,
Expand Down Expand Up @@ -228,3 +232,10 @@ function traverse(config) {
});
}
}

/**
* whether the dependency is from CDN. (http/https)
*/
function isHttp(dependency) {
return Boolean(dependency.startsWith('http://') || dependency.startsWith('https://'));
}
36 changes: 35 additions & 1 deletion src/dependency-builder/dependency-tree/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ describe('dependencyTree', function () {
});
});
describe('files with dynamic import', () => {
it('should not', () => {
it('should not show missing dependencies', () => {
mockfs({
[`${__dirname}/dynamic`]: {
'foo.js': 'const a = "./b"; import(a); require(a);'
Expand All @@ -884,4 +884,38 @@ describe('dependencyTree', function () {
expect(visited[filename].missing).to.be.undefined;
});
});
describe('files with import from cdn (http, https)', () => {
it('should not show missing dependencies when importing from https', () => {
mockfs({
[`${__dirname}/cdn`]: {
'foo.js': 'import { a } from "https://unpkg.com";'
}
});
const directory = path.normalize(`${__dirname}/cdn`);
const filename = path.normalize(`${directory}/foo.js`);
const visited = {};
dependencyTree({
filename,
directory,
visited
});
expect(visited[filename].missing).to.be.undefined;
});
it('should not show missing dependencies when importing from http', () => {
mockfs({
[`${__dirname}/cdn`]: {
'bar.js': 'const b = require("http://pkg.com");'
}
});
const directory = path.normalize(`${__dirname}/cdn`);
const filename = path.normalize(`${directory}/bar.js`);
const visited = {};
dependencyTree({
filename,
directory,
visited
});
expect(visited[filename].missing).to.be.undefined;
});
});
});