Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack/loader-utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 331ad5067d9a1a7b8d646692e6959639969210d1
Choose a base ref
...
head repository: webpack/loader-utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d9f4e23cf411d8556f8bac2d3bf05a6e0103b568
Choose a head ref
  • 5 commits
  • 11 files changed
  • 3 contributors

Commits on Mar 17, 2020

  1. Copy the full SHA
    c78786d View commit details
  2. chore: minimum required Node.js version is 8.9.0 (#166)

    BREAKING CHANGE: minimum required `Node.js` version is `8.9.0`
    evilebottnawi authored Mar 17, 2020
    Copy the full SHA
    c937e8c View commit details
  3. refactor: the getOptions method returns empty object on empty query (

    …#167)
    
    BREAKING CHANGE: the `getOptions` method returns empty object on empty query
    evilebottnawi authored Mar 17, 2020
    Copy the full SHA
    b595cfb View commit details
  4. Copy the full SHA
    865dc03 View commit details
  5. chore(release): 2.0.0

    alexander-akait committed Mar 17, 2020
    Copy the full SHA
    d9f4e23 View commit details
Showing with 2,344 additions and 1,880 deletions.
  1. +0 −7 .travis.yml
  2. +10 −1 CHANGELOG.md
  3. +6 −6 README.md
  4. +0 −3 appveyor.yml
  5. +1 −1 lib/getHashDigest.js
  6. +1 −1 lib/getOptions.js
  7. +1 −0 lib/parseQuery.js
  8. +9 −9 package.json
  9. +75 −57 test/getOptions.test.js
  10. +20 −20 test/interpolateName.test.js
  11. +2,221 −1,775 yarn.lock
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -16,13 +16,6 @@ matrix:
- node_js: '12'
script: yarn pretest
env: CI=pretest
# Yarn doesn't support node@4
# - node_js: '4'
# script: yarn test:ci
# env: CI=tests 4
- node_js: '6'
script: yarn test:ci
env: CI=tests 6
- node_js: '8'
script: yarn test:ci
env: CI=tests 8
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Change Log
# Changelog

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.

## [2.0.0](https://github.com/webpack/loader-utils/compare/v1.4.0...v2.0.0) (2020-03-17)


### ⚠ BREAKING CHANGES

* minimum required `Node.js` version is `8.9.0` ([#166](https://github.com/webpack/loader-utils/issues/166)) ([c937e8c](https://github.com/webpack/loader-utils/commit/c937e8c77231b42018be616b784a6b45eac86f8a))
* the `getOptions` method returns empty object on empty query ([#167](https://github.com/webpack/loader-utils/issues/167)) ([b595cfb](https://github.com/webpack/loader-utils/commit/b595cfba022d3f04f3d310dd570b0253e461605b))
* Use `md4` by default

<a name="1.4.0"></a>
# [1.4.0](https://github.com/webpack/loader-utils/compare/v1.3.0...v1.4.0) (2020-02-19)

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -180,14 +180,14 @@ The following tokens are replaced in the `name` parameter:
* `[query]` the queryof the resource, i.e. `?foo=bar`
* `[emoji]` a random emoji representation of `options.content`
* `[emoji:<length>]` same as above, but with a customizable number of emojis
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash)
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* and `length` the length in chars
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash)
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* and `length` the length in chars
* `[N]` the N-th match obtained from matching the current file name against `options.regExp`
@@ -229,7 +229,7 @@ loaderUtils.interpolateName(loaderContext, "[emoji:4]", { content: ... });
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.png"
loaderUtils.interpolateName(loaderContext, "[sha512:hash:base64:7].[ext]", { content: ... });
// => 2BKDTjl.png
// use sha512 hash instead of md5 and with only 7 chars of base64
// use sha512 hash instead of md4 and with only 7 chars of base64

// loaderContext.resourcePath = "/absolute/path/to/app/img/myself.png"
// loaderContext.query.name =
@@ -266,7 +266,7 @@ const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, max
```

* `buffer` the content that should be hashed
* `hashType` one of `sha1`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* `maxLength` the maximum length in chars

3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -2,9 +2,6 @@

environment:
matrix:
# Yarn doesn't support node@4
# - nodejs_version: 4
- nodejs_version: 6
- nodejs_version: 8
- nodejs_version: 10
- nodejs_version: 12
2 changes: 1 addition & 1 deletion lib/getHashDigest.js
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ function encodeBufferToBase(buffer, base) {
}

function getHashDigest(buffer, hashType, digestType, maxLength) {
hashType = hashType || 'md5';
hashType = hashType || 'md4';
maxLength = maxLength || 9999;

const hash = require('crypto').createHash(hashType);
2 changes: 1 addition & 1 deletion lib/getOptions.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ function getOptions(loaderContext) {

if (!query || typeof query !== 'object') {
// Not object-like queries are not supported.
return null;
return {};
}

return query;
1 change: 1 addition & 0 deletions lib/parseQuery.js
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ function parseQuery(query) {
let name = arg.substr(0, idx);
let value = decodeURIComponent(arg.substr(idx + 1));

// eslint-disable-next-line no-prototype-builtins
if (specialValues.hasOwnProperty(value)) {
value = specialValues[value];
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "loader-utils",
"version": "1.4.0",
"version": "2.0.0",
"author": "Tobias Koppers @sokra",
"description": "utils for webpack loaders",
"dependencies": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^1.0.1"
"json5": "^2.1.2"
},
"scripts": {
"lint": "eslint lib test",
@@ -21,16 +21,16 @@
"url": "https://github.com/webpack/loader-utils.git"
},
"engines": {
"node": ">=4.0.0"
"node": ">=8.9.0"
},
"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.11.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"jest": "^21.2.1",
"coveralls": "^3.0.9",
"eslint": "^6.8.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"standard-version": "^4.0.0"
"standard-version": "^7.1.0"
},
"main": "lib/index.js",
"files": [
132 changes: 75 additions & 57 deletions test/getOptions.test.js
Original file line number Diff line number Diff line change
@@ -3,62 +3,80 @@
const loaderUtils = require('../lib');

describe('getOptions()', () => {
describe('when loaderContext.query is a string with length > 0', () => {
it('should call parseQuery() and return its result', () => {
expect(
loaderUtils.getOptions({
query: '?something=getOptions_cannot_parse',
})
).toEqual({ something: 'getOptions_cannot_parse' });
});
});
describe('when loaderContext.query is an empty string', () => {
it('should return null', () => {
expect(
loaderUtils.getOptions({
query: '',
})
).toEqual(null);
});
});
describe('when loaderContext.query is an object', () => {
it('should just return it', () => {
const query = {};
expect(
loaderUtils.getOptions({
query,
})
).toEqual(query);
});
});
describe('when loaderContext.query is an array', () => {
it('should just return it', () => {
const query = [];
expect(loaderUtils.getOptions({ query })).toEqual(query);
});
});
describe('when loaderContext.query is anything else', () => {
it('should return null', () => {
expect(
loaderUtils.getOptions({
query: undefined,
})
).toEqual(null);
expect(
loaderUtils.getOptions({
query: null,
})
).toEqual(null);
expect(
loaderUtils.getOptions({
query: 1,
})
).toEqual(null);
expect(
loaderUtils.getOptions({
query: 0,
})
).toEqual(null);
});
it('should work', () => {
expect(
loaderUtils.getOptions({
query: true,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: false,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: null,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: undefined,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: 1,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: 0,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: -0,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: -1,
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: '',
})
).toEqual({});
expect(
loaderUtils.getOptions({
query: '?something=getOptions_cannot_parse',
})
).toEqual({ something: 'getOptions_cannot_parse' });

const query1 = {};

expect(
loaderUtils.getOptions({
query: query1,
})
).toEqual(query1);

const query2 = { foo: { bar: 'baz' } };

expect(
loaderUtils.getOptions({
query: query2,
})
).toEqual(query2);

const query3 = [];

expect(loaderUtils.getOptions({ query: query3 })).toEqual(query3);

const query4 = [1, true, 'foobar'];

expect(loaderUtils.getOptions({ query: query4 })).toEqual(query4);
});
});
Loading