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: a5602addda0c5e98e70d067b8dd050d5e4153f1d
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: ba4f0d0912b84d974a80ce8a5d2eae69841cd36b
Choose a head ref

Commits on Mar 16, 2017

  1. chore(CHANGELOG.md): Clean up

    jhnns committed Mar 16, 2017
    Copy the full SHA
    07aea65 View commit details

Commits on Mar 21, 2017

  1. Update README

    Replace clone-deep with clone since clone-deep does not copy properties from the prototype chain. This can be a problem with plugin instances, see webpack-contrib/less-loader#181 (comment)
    jhnns authored Mar 21, 2017
    Copy the full SHA
    52fbc35 View commit details

Commits on Mar 24, 2017

  1. fix: Empty urls are not rewritten to relative requests

    Prior to this commit, `urlToRequest` rewrote an empty URL `''` to `'./'` which is correct from a theoretical point of view since CSS files do not distinguish between relative paths starting with ./ or not (like CommonJS does). However, an empty URL is most likely an error which webpack should warn about. If we rewrite the empty string to ./, webpack won't warn against this anymore because requiring ./ is valid.
    
    Related discussion: #80
    darrenscerri authored and jhnns committed Mar 24, 2017
    Copy the full SHA
    0f6cb90 View commit details
  2. fix: Do not rewrite actual URLs that start with http://, https:// or …

    …just //
    
    Prior to this commit, an actual URL starting with a protocol like`https://` would have been rewritten to `./https://` which is clearly undesired. Although webpack can't resolve remote module requests anyway (those starting with http:// and such) and thus will throw an error, it is still correct to leave these kind of URLs untouched by the loader-utils.
    
    Related discussion: #79
    japgolly authored and jhnns committed Mar 24, 2017
    Copy the full SHA
    fface50 View commit details

Commits on Jun 27, 2017

  1. Have a violent reaction when out of emoji

    Failing explicitly is better than silently starting to return empty strings.
    asmundg committed Jun 27, 2017
    Copy the full SHA
    298ecfe View commit details

Commits on Jun 28, 2017

  1. Copy the full SHA
    4ac2bab View commit details

Commits on Jun 30, 2017

  1. Linter cleanup

    asmundg committed Jun 30, 2017
    Copy the full SHA
    22b6213 View commit details

Commits on Jul 10, 2017

  1. Copy the full SHA
    3027175 View commit details
  2. Copy the full SHA
    0ad430a View commit details
  3. Fixes nitpick formatting

    rsms committed Jul 10, 2017
    Copy the full SHA
    3cd3889 View commit details

Commits on Aug 30, 2017

  1. Fix demonstrated usage of Object.assign in README

    What the current README suggests would override provided options with the default options:
    
    ```js
    Object.assign({}, {option: "provided"}, {option: "someDefault"}) // => {option: "someDefault"}
    ```
    
    I imagine this is the opposite of what was intended.
    
    BTW, thanks for Webpack! I love it.
    zacharyvoase authored Aug 30, 2017
    Copy the full SHA
    c12aa6f View commit details

Commits on Sep 22, 2017

  1. Fix URLs for web extension protocols for edge and firefox wrongly det…

    …ected as requests
    Guillaume Flandre committed Sep 22, 2017
    Copy the full SHA
    d8a9bdc View commit details

Commits on Sep 28, 2017

  1. Copy the full SHA
    eb641cc View commit details

Commits on Oct 20, 2017

  1. Merge pull request #91 from asmundg/explode-when-out-of-emoji

    Have a violent reaction when out of emoji
    sokra authored Oct 20, 2017
    Copy the full SHA
    8b7834a View commit details
  2. Merge pull request #100 from embrace-io/master

    Parse string for emoji count before use.
    sokra authored Oct 20, 2017
    Copy the full SHA
    a18d1a4 View commit details
  3. Merge pull request #98 from gflandre/fix-web-extensions-protocols

    Fix URLs for web extension protocols for edge and firefox wrongly detected as requests
    sokra authored Oct 20, 2017
    Copy the full SHA
    5f11a9f View commit details
  4. Merge pull request #96 from zacharyvoase/patch-1

    Fix demonstrated usage of Object.assign in README
    sokra authored Oct 20, 2017
    Copy the full SHA
    5854d87 View commit details
  5. Merge pull request #94 from rsms/fix-hash-regex

    Fixes "[hash]" token regex in interpolateString to capture any hash algorithm name
    sokra authored Oct 20, 2017
    Copy the full SHA
    67499ff View commit details

Commits on Dec 21, 2018

  1. Copy the full SHA
    083187a View commit details
  2. Copy the full SHA
    822f518 View commit details
  3. Copy the full SHA
    dd9326b View commit details
  4. Copy the full SHA
    47e2e02 View commit details
  5. Copy the full SHA
    ac05880 View commit details
  6. Copy the full SHA
    ad3c359 View commit details
  7. ci: test on windows

    alexander-akait committed Dec 21, 2018
    Copy the full SHA
    7485ded View commit details
  8. ci: test on windows

    evilebottnawi authored Dec 21, 2018
    Copy the full SHA
    6fb379f View commit details

Commits on Dec 24, 2018

  1. Copy the full SHA
    6982934 View commit details
  2. Copy the full SHA
    3b6b8ff View commit details
  3. Copy the full SHA
    ad3a6b2 View commit details
  4. Copy the full SHA
    db92b11 View commit details
  5. chore(deps): update

    alexander-akait committed Dec 24, 2018
    Copy the full SHA
    914c09f View commit details
  6. chore(deps): update

    evilebottnawi authored Dec 24, 2018
    Copy the full SHA
    0f2b227 View commit details
  7. Copy the full SHA
    3a854ba View commit details
  8. Copy the full SHA
    c17d9cd View commit details
  9. test: more (#132)

    evilebottnawi authored Dec 24, 2018
    Copy the full SHA
    c5c7322 View commit details
  10. Copy the full SHA
    ba4f0d0 View commit details
15 changes: 4 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
root = true

[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 233

[*.json]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[test/cases/parsing/bom/bomfile.{css,js}]
charset = utf-8-bom

[*.md]
insert_final_newline = true
trim_trailing_whitespace = false
84 changes: 30 additions & 54 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
{
"root": true,
"plugins": ["node"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true
},
"rules": {
"quotes": ["error", "double"],
"no-undef": "error",
"no-extra-semi": "error",
"semi": "error",
"no-template-curly-in-string": "error",
"no-caller": "error",
"yoda": "error",
"eqeqeq": "error",
"global-require": "off",
"brace-style": "error",
"eol-last": "error",
"indent": ["error", "tab", { "SwitchCase": 1 }],
"no-extra-bind": "warn",
"no-empty": "off",
"no-multiple-empty-lines": "error",
"no-multi-spaces": "error",
"no-process-exit": "warn",
"space-in-parens": "error",
"no-trailing-spaces": "error",
"no-use-before-define": "off",
"no-unused-vars": ["error", {"args": "none"}],
"key-spacing": "error",
"space-infix-ops": "error",
"no-unsafe-negation": "error",
"no-loop-func": "warn",
"space-before-function-paren": ["error", "never"],
"space-before-blocks": "error",
"object-curly-spacing": ["error", "always"],
"keyword-spacing": ["error", {
"after": false,
"overrides": {
"try": {"after": true},
"else": {"after": true},
"throw": {"after": true},
"case": {"after": true},
"return": {"after": true},
"finally": {"after": true},
"do": {"after": true}
}
}],
"no-console": "off",
"valid-jsdoc": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"object-shorthand": "error"
}
"root": true,
"plugins": ["node", "prettier"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true
},
"rules": {
"no-template-curly-in-string": "error",
"no-caller": "error",
"yoda": "error",
"eqeqeq": "error",
"no-extra-bind": "error",
"no-process-exit": "error",
"no-loop-func": "error",
"no-console": "off",
"valid-jsdoc": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-arrow-callback": "error",
"object-shorthand": "error",

"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
]
}
}
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
42 changes: 36 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
sudo: false

git:
depth: 10

branches:
only:
- master

language: node_js
node_js:
- "4"
- "6"
- "7"
script: npm run travis

after_success: cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose && rm -rf ./coverage
cache: yarn

matrix:
include:
- node_js: '11'
script: yarn pretest
env: CI=pretest
- 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
- node_js: '10'
script: yarn test:ci
env: CI=tests 10
- node_js: '11'
script: yarn test:ci
env: CI=coverage 11

before_install:
- yarn install --ignore-engines

after_success:
- if [ "$CI" = "coverage" ]; then cat ./.coverage/lcov.info | ./node_modules/.bin/coveralls --verbose && rm -rf ./coverage; fi
26 changes: 20 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,17 +2,31 @@

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="1.1.0"></a>
# [1.1.0](https://github.com/webpack/loader-utils/compare/v1.0.4...v1.1.0) (2017-03-16)
<a name="1.2.0"></a>
# [1.2.0](https://github.com/webpack/loader-utils/compare/v1.1.0...v1.2.0) (2018-12-24)


### Features

* **automatic-release:** Generation of automatic release ([7484d13](https://github.com/webpack/loader-utils/commit/7484d13))
* **parseQuery:** export parseQuery ([ddf64e4](https://github.com/webpack/loader-utils/commit/ddf64e4))
* **interpolateName:** support `[contenthash]`

### Fixes

* **urlToRequest:** empty urls are not rewritten to relative requests
* **urlToRequest:** don't rewrite absolute urls
* **isUrlRequest:** ignore all url with `extension` (like `moz-extension:`, `ms-browser-extension:` and etc)
* **isUrlRequest:** ignore `about:blank`
* **interpolateName:** failing explicitly when ran out of emoji
* **interpolateName:** `[hash]` token regex in interpolate string to capture any hash algorithm name
* **interpolateName:** parse string for emoji count before use

# 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="1.1.0"></a>
# [1.1.0](https://github.com/webpack/loader-utils/compare/v1.0.4...v1.1.0) (2017-03-16)


### Features

* **automatic-release:** Generation of automatic release ([7484d13](https://github.com/webpack/loader-utils/commit/7484d13))
* **parseQuery:** export parseQuery ([ddf64e4](https://github.com/webpack/loader-utils/commit/ddf64e4))
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,16 +23,16 @@ If you pass it on to another library, make sure to make a *deep copy* of it:
```javascript
const options = Object.assign(
{},
loaderUtils.getOptions(this), // it is safe to pass null to Object.assign()
defaultOptions
defaultOptions,
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
);
// don't forget nested objects or arrays
options.obj = Object.assign({}, options.obj);
options.arr = options.arr.slice();
someLibrary(options);
```

[clone-deep](https://www.npmjs.com/package/clone-deep) is a good library to make a deep copy of the options.
[clone](https://www.npmjs.com/package/clone) is a good library to make a deep copy of the options.

#### Options as query strings

@@ -164,20 +164,31 @@ The following tokens are replaced in the `name` parameter:
* `[folder]` the folder of the resource is in.
* `[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)
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `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)
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `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`

In loader context `[hash]` and `[contenthash]` are the same, but we recommend using `[contenthash]` for avoid misleading.

Examples

``` javascript
// loaderContext.resourcePath = "/app/js/javascript.js"
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext]", { content: ... });
// => js/9473fdd0d880a43c21b7778d34872157.script.js

// loaderContext.resourcePath = "/app/js/javascript.js"
loaderUtils.interpolateName(loaderContext, "js/[contenthash].script.[ext]", { content: ... });
// => js/9473fdd0d880a43c21b7778d34872157.script.js

// loaderContext.resourcePath = "/app/page.html"
loaderUtils.interpolateName(loaderContext, "html-[hash:6].html", { content: ... });
// => html-9473fd.html
32 changes: 32 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# https://www.appveyor.com/docs/appveyor-yml

environment:
matrix:
- nodejs_version: 4
- nodejs_version: 6
- nodejs_version: 8
- nodejs_version: 10
- nodejs_version: 11

clone_depth: 10

version: '{build}'
build: off
deploy: off

branches:
only:
- master

install:
- ps: Install-Product node $env:nodejs_version
- yarn install --ignore-engines

cache:
- node_modules -> appveyor.yml,package.json,yarn.lock
- '%LOCALAPPDATA%\Yarn -> appveyor.yml,package.json,yarn.lock'

test_script:
- node --version
- npm --version
- cmd: 'yarn test:ci'
19 changes: 11 additions & 8 deletions lib/getCurrentRequest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";
'use strict';

function getCurrentRequest(loaderContext) {
if(loaderContext.currentRequest)
return loaderContext.currentRequest;
const request = loaderContext.loaders
.slice(loaderContext.loaderIndex)
.map(obj => obj.request)
.concat([loaderContext.resource]);
return request.join("!");
if (loaderContext.currentRequest) {
return loaderContext.currentRequest;
}

const request = loaderContext.loaders
.slice(loaderContext.loaderIndex)
.map((obj) => obj.request)
.concat([loaderContext.resource]);

return request.join('!');
}

module.exports = getCurrentRequest;
Loading