Commit f274bf3c authored by Praveen Arimbrathodiyil's avatar Praveen Arimbrathodiyil

Update upstream source from tag 'upstream/0.8.0'

Update to upstream version '0.8.0'
with Debian dir 0aadb569b039f6e1f71541d5762c489b8e3c6cb4
parents ee7f4bcf 0201ba8f
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="0.8.0"></a>
# [0.8.0](https://github.com/webpack-contrib/imports-loader/compare/v0.7.1...v0.8.0) (2018-02-20)
### Features
* allow loading nested objects onto existing libraries ([#45](https://github.com/webpack-contrib/imports-loader/issues/45)) ([44d6f48](https://github.com/webpack-contrib/imports-loader/commit/44d6f48))
......@@ -21,7 +21,7 @@ This is useful for third-party modules that rely on global variables like `$` or
npm install imports-loader
```
<h2 align="center">Usage</h2>
<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2>
Given you have this file `example.js`
......@@ -65,18 +65,16 @@ As always, you should rather configure this in your `webpack.config.js`:
module.exports = {
...
module: {
loaders: [
rules: [
{
test: require.resolve("some-module"),
loader: "imports-loader?this=>window"
use: "imports-loader?this=>window"
}
]
}
};
```
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
<h2 align="center">Typical Use Cases</h2>
### jQuery plugins
......
......@@ -32,7 +32,7 @@ module.exports = function(content, sourceMap) {
if(previous.length === 0) {
imports.push("var " + expr + " = (" + current + " || {});");
} else if(index < names.length-1) {
imports.push(expr + " = {};");
imports.push(expr + " = " + expr + " || {};");
} else {
imports.push(expr + " = " + value + ";");
}
......
This diff is collapsed.
{
"name": "imports-loader",
"version": "0.7.1",
"author": "Tobias Koppers @sokra",
"version": "0.8.0",
"description": "imports loader module for webpack",
"author": "Tobias Koppers @sokra",
"license": "MIT",
"engines": {
"node": ">= 4"
},
"files": [
"index.js"
],
"scripts": {
"test": "mocha",
"travis:test": "npm run -s test"
"travis:test": "npm run -s test",
"release": "standard-version"
},
"dependencies": {
"loader-utils": "^1.0.2",
"source-map": "^0.5.6"
"source-map": "^0.6.1"
},
"devDependencies": {
"mocha": "^3.1.2",
"should": "^11.1.1"
"should": "^11.1.1",
"standard-version": "^4.3.0"
},
"files": [
"index.js"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack/imports-loader.git"
}
"homepage": "https://github.com/webpack-contrib/imports-loader",
"repository": "https://github.com/webpack-contrib/imports-loader",
"bugs": "https://github.com/webpack-contrib/imports-loader/issues"
}
var should = require("should");
var loader = require("../");
var HEADER = "/*** IMPORTS FROM imports-loader ***/\n";
describe("loader", function() {
it("should import nested objects", function() {
loader.call({
query: "?abc.def.ghi=>1"
}, "").should.be.eql(HEADER +
"var abc = (abc || {});\n" +
"abc.def = {};\n" +
"abc.def.ghi = 1;\n\n\n"
);
it("sets a header so the developer can see where imports-loader is being applied", function(){
var generatedCode = loader.call({ query: "?someVariable=>1" });
generatedCode.indexOf("/*** IMPORTS FROM imports-loader ***/\n").should.be.eql(0);
});
it("can set a variable", function(){
var generatedCode = loader.call({ query: "?someVariable=>1" });
eval(generatedCode);;
someVariable.should.be.eql(1);
});
it("can set multiple values", function(){
var generatedCode = loader.call({ query: "?someVariable=>1,anotherVariable=>2" });
eval(generatedCode);;
someVariable.should.be.eql(1);
anotherVariable.should.be.eql(2);
});
it("can set a nested variable", function(){
var generatedCode = loader.call({ query: "?someVariable.someProperty.someSubProperty=>1" });
eval(generatedCode);;
someVariable.someProperty.someSubProperty.should.be.eql(1);
});
describe("loading properties onto an existing variable", function(){
it("preserves the other original properties", function(){
var generatedCode = loader.call({ query: "?someVariable.someProperty=>1" });
var someVariable = { existingProperty: 123 }
eval(generatedCode);;
someVariable.existingProperty.should.be.eql(123);
});
it("sets the new properties", function(){
var generatedCode = loader.call({ query: "?someVariable.someProperty=>1" });
var someVariable = { existingProperty: 123 }
eval(generatedCode);;
someVariable.someProperty.should.be.eql(1);
});
});
it("should import multiple nested objects", function() {
loader.call({
query: "?abc.def.ghi=>1,foo.bar.baz=>2"
}, "").should.be.eql(HEADER +
// First import
"var abc = (abc || {});\n" +
"abc.def = {};\n" +
"abc.def.ghi = 1;\n" +
// Second import
"var foo = (foo || {});\n" +
"foo.bar = {};\n" +
"foo.bar.baz = 2;\n\n\n"
);
describe("loading sub-properties onto an existing property", function(){
it("preserves the other original properties", function(){
var generatedCode = loader.call({ query: "?someVariable.existingProperty.someSubProperty=>1" });
var someVariable = { existingProperty: { existingSubProperty: 123 } }
eval(generatedCode);;
someVariable.existingProperty.existingSubProperty.should.be.eql(123);
});
it("sets the new sub-properties", function(){
var generatedCode = loader.call({ query: "?someVariable.existingProperty.someSubProperty=>1" });
var someVariable = { existingProperty: { existingSubProperty: 123 } }
eval(generatedCode);;
someVariable.existingProperty.someSubProperty.should.be.eql(1);
});
});
});
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment