Skip to content
This repository was archived by the owner on Sep 11, 2018. It is now read-only.

fix: change bundling to support linked libraries #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ before_script:
branches:
only:
- master
cache:
directories:
- node_modules
notifications:
email:
on_success: never
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ environment:
- nodejs_version: '6'
- nodejs_version: '4'

cache:
- node_modules

install:
- ps: Install-Product node $env:nodejs_version x64
- set CI=true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"eslint-plugin-flowtype-errors": "2.0.2",
"flow-bin": "0.37.4",
"husky": "0.11.9",
"rimraf": "2.5.4",
"xo": "0.17.1"
},
"dependencies": {
Expand Down
6 changes: 2 additions & 4 deletions source/create-bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ function createBundler(options: BrowserifyOptions, context: BundleContext): Bund
if (file in cache) {
return cache[file];
}
if (file.includes('node_modules')) {
return original(file, id, pkg);
}
throw new Error(`Could not resolve ${file} as ${id} from ${context.file.path}`);

return original(file, id, pkg);
};

bundler._mdeps.readFile = readFile.bind(bundler._mdeps);
Expand Down
23 changes: 23 additions & 0 deletions test/fakes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'fs';
import rimraf from 'rimraf';

export function createFakeDir() {
fs.mkdirSync('fakes');
}

export function createFakeModule() {
fs.mkdirSync('node_modules/fake-module');
fs.writeFileSync('node_modules/fake-module/index.js', 'const test = true;\n');
}

export function createLinkedFakeModule() {
fs.mkdirSync('fakes/link-dest');
fs.writeFileSync('fakes/link-dest/index.js', 'const test = true;\n');
fs.linkSync('fakes/link-dest', 'node_modules/linked-fake-module');
}

export function cleanUpFakes() {
rimraf.sync('fakes');
rimraf.sync('node_modules/fake-module');
rimraf.sync('node_modules/linked-fake-module');
}
12 changes: 12 additions & 0 deletions test/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ export const emptyFile = getFile({
dependencies: {}
});

export const fileWithModuleDeps = getFile({
buffer: 'require(\'fake-module\');',
path: 'fakes/index.js',
dependencies: {}
});

export const fileWithLinkedModuleDeps = getFile({
buffer: 'require(\'linked-fake-module\');',
path: 'fakes/index.js',
dependencies: {}
});

export const emptyBufferFile = getFile({
buffer: new Buffer(''),
path: 'empty/index.js',
Expand Down
21 changes: 21 additions & 0 deletions test/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import test from 'ava';
import factory from '../source';
import * as mocks from './mocks';
import {createFakeDir, createFakeModule, createLinkedFakeModule, cleanUpFakes} from './fakes';

test.before('create fake directory', () => {
createFakeDir();
});

test.after.always('clean up fakes', () => {
cleanUpFakes();
});

test('it should export a function as default', t => {
const actual = typeof factory;
Expand Down Expand Up @@ -41,3 +50,15 @@ test('the resolved object should have a buffer key for buffer files', async t =>
const file = await transform(mocks.emptyBufferFile);
t.truthy(Object.prototype.hasOwnProperty.call(file, 'buffer'));
});

test('load module dependencies', async () => {
createFakeModule();
const transform = factory(mocks.application);
await transform(mocks.fileWithModuleDeps);
});

test('load linked module dependencies', async () => {
createLinkedFakeModule();
const transform = factory(mocks.application);
await transform(mocks.fileWithLinkedModuleDeps);
});