-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge injectify-loader and inject-loader
- Loading branch information
1 parent
41415c5
commit 659852f
Showing
39 changed files
with
4,047 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
'extends': ['airbnb-base'], | ||
'rules': { | ||
'import/no-extraneous-dependencies': 'off', | ||
'import/no-webpack-loader-syntax': 'off', | ||
'import/no-unresolved': 'off', | ||
'import/extensions': 'off', | ||
}, | ||
'env': { | ||
'mocha': true | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
node_modules | ||
yarn.lock | ||
flow-typed | ||
# Logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
tmp/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
sudo: false | ||
before_install: | ||
- curl -o- -L https://yarnpkg.com/install.sh | bash | ||
- export PATH=$HOME/.yarn/bin:$PATH | ||
language: node_js | ||
cache: yarn | ||
node_js: | ||
- "node" | ||
- "6" | ||
- "5" | ||
- 7 | ||
- 6 | ||
- 5 | ||
- 4 | ||
|
||
cache: yarn | ||
|
||
script: | ||
- npm test | ||
- make lint | ||
- make test | ||
- make build-release | ||
- make integration-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
lint: | ||
npm run eslint | ||
|
||
test: | ||
npm run build | ||
npm run build-test | ||
npm run test | ||
|
||
integration-test: | ||
./script/integration_test | ||
|
||
build-release: | ||
npm run build-prod | ||
cp -f ./tmp/index.js ./dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
a() { | ||
return 'a - original'; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
define((require) => { // eslint-disable-line no-undef | ||
const a = require('./a.js'); | ||
const b = require('./b.js'); | ||
|
||
return { | ||
getA() { | ||
return a.a(); | ||
}, | ||
|
||
getB() { | ||
return b(); | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function b() { | ||
return 'b - original'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const a = require('./a.js'); | ||
const b = require('./b.js'); | ||
|
||
module.exports = { | ||
getA() { | ||
return a.a(); | ||
}, | ||
|
||
getB() { | ||
return b(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { a } from './a.js'; | ||
import b from './b.js'; | ||
|
||
export function getA() { | ||
return a(); | ||
} | ||
|
||
export function getB() { | ||
return b(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable global-require */ | ||
|
||
const assert = require('assert'); | ||
|
||
const MODULE_A_STUB = { | ||
a() { | ||
return 'a - stubbed'; | ||
}, | ||
}; | ||
|
||
const MODULE_B_STUB = () => 'b - stubbed'; | ||
|
||
describe('injectify-loader', () => { | ||
const injectors = [ | ||
{ moduleType: 'commonjs', moduleInjector: require('self!./modules/commonjs.js') }, | ||
{ moduleType: 'amd', moduleInjector: require('self!./modules/amd.js') }, | ||
{ moduleType: 'es6', moduleInjector: require('self!./modules/es6.js') }, | ||
]; | ||
|
||
injectors.forEach((injector) => { | ||
describe(`${injector.moduleType} modules`, () => { | ||
it('works when no injections were provided', () => { | ||
const module = injector.moduleInjector(); | ||
|
||
assert.equal(module.getA(), 'a - original'); | ||
assert.equal(module.getB(), 'b - original'); | ||
}); | ||
|
||
it('works when one injection was provided', () => { | ||
const module = injector.moduleInjector({ | ||
'./a.js': MODULE_A_STUB, | ||
}); | ||
|
||
assert.equal(module.getA(), 'a - stubbed'); | ||
assert.equal(module.getB(), 'b - original'); | ||
}); | ||
|
||
it('works when multiple injections were provided', () => { | ||
const module = injector.moduleInjector({ | ||
'./a.js': MODULE_A_STUB, | ||
'./b.js': MODULE_B_STUB, | ||
}); | ||
|
||
assert.equal(module.getA(), 'a - stubbed'); | ||
assert.equal(module.getB(), 'b - stubbed'); | ||
}); | ||
|
||
it('throws an error when invalid dependencies are provided', () => { | ||
const injectInvalidDependencies = () => { | ||
injector.moduleInjector({ | ||
'./b.js': null, | ||
'./c.js': null, | ||
}); | ||
}; | ||
|
||
assert.throws(injectInvalidDependencies, /The following injections are invalid:\n- \.\/c\.js/); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const path = require('path'); | ||
const webpackBlocks = require('@webpack-blocks/webpack2'); | ||
|
||
const ROOT_PATH = path.resolve(__dirname, '..'); | ||
const SOURCE_PATH = path.resolve(ROOT_PATH, 'src'); | ||
const TESTS_PATH = path.resolve(ROOT_PATH, '__tests__'); | ||
const TEMP_PATH = path.resolve(ROOT_PATH, 'tmp'); | ||
|
||
const babelLoader = () => () => ({ | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
include: [ | ||
SOURCE_PATH, | ||
TESTS_PATH, | ||
], | ||
loader: 'babel-loader', | ||
query: { | ||
cacheDirectory: true, | ||
presets: ['es2015'], | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const nodeTarget = () => () => ({ | ||
target: 'node', | ||
}); | ||
|
||
const baseConfig = () => webpackBlocks.group([ | ||
babelLoader(), | ||
nodeTarget(), | ||
]); | ||
|
||
module.exports = { | ||
baseConfig, | ||
SOURCE_PATH, | ||
TESTS_PATH, | ||
TEMP_PATH, | ||
}; |
Oops, something went wrong.