| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,9 +13,13 @@ cache: yarn | |||
| 13 | 13 | ||
| 14 | 14 | matrix: | |
| 15 | 15 | include: | |
| 16 | - - node_js: '11' | ||
| 16 | + - node_js: '12' | ||
| 17 | 17 | script: yarn pretest | |
| 18 | 18 | env: CI=pretest | |
| 19 | + # Yarn doesn't support node@4 | ||
| 20 | + # - node_js: '4' | ||
| 21 | + # script: yarn test:ci | ||
| 22 | + # env: CI=tests 4 | ||
| 19 | 23 | - node_js: '6' | |
| 20 | 24 | script: yarn test:ci | |
| 21 | 25 | env: CI=tests 6 | |
@@ -25,9 +29,12 @@ matrix: | |||
| 25 | 29 | - node_js: '10' | |
| 26 | 30 | script: yarn test:ci | |
| 27 | 31 | env: CI=tests 10 | |
| 28 | - - node_js: '11' | ||
| 32 | + - node_js: '12' | ||
| 29 | 33 | script: yarn test:ci | |
| 30 | - env: CI=coverage 11 | ||
| 34 | + env: CI=coverage 12 | ||
| 35 | + - node_js: '13' | ||
| 36 | + script: yarn test:ci | ||
| 37 | + env: CI=coverage 13 | ||
| 31 | 38 | ||
| 32 | 39 | before_install: | |
| 33 | 40 | - yarn install --ignore-engines | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -176,7 +176,8 @@ The following tokens are replaced in the `name` parameter: | |||
| 176 | 176 | * `[ext]` the extension of the resource | |
| 177 | 177 | * `[name]` the basename of the resource | |
| 178 | 178 | * `[path]` the path of the resource relative to the `context` query parameter or option. | |
| 179 | - * `[folder]` the folder the resource is in. | ||
| 179 | + * `[folder]` the folder the resource is in | ||
| 180 | + * `[query]` the queryof the resource, i.e. `?foo=bar` | ||
| 180 | 181 | * `[emoji]` a random emoji representation of `options.content` | |
| 181 | 182 | * `[emoji:<length>]` same as above, but with a customizable number of emojis | |
| 182 | 183 | * `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash) | |
@@ -200,6 +201,11 @@ Examples | |||
| 200 | 201 | loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext]", { content: ... }); | |
| 201 | 202 | // => js/9473fdd0d880a43c21b7778d34872157.script.js | |
| 202 | 203 | ||
| 204 | + // loaderContext.resourcePath = "/app/js/javascript.js" | ||
| 205 | + // loaderContext.resourceQuery = "?foo=bar" | ||
| 206 | + loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext][query]", { content: ... }); | ||
| 207 | + // => js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar | ||
| 208 | + | ||
| 203 | 209 | // loaderContext.resourcePath = "/app/js/javascript.js" | |
| 204 | 210 | loaderUtils.interpolateName(loaderContext, "js/[contenthash].script.[ext]", { content: ... }); | |
| 205 | 211 | // => js/9473fdd0d880a43c21b7778d34872157.script.js | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,10 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | 3 | environment: | |
| 4 | 4 | matrix: | |
| 5 | + # Yarn doesn't support node@4 | ||
| 6 | + # - nodejs_version: 4 | ||
| 5 | 7 | - nodejs_version: 6 | |
| 6 | 8 | - nodejs_version: 8 | |
| 7 | 9 | - nodejs_version: 10 | |
| 8 | - - nodejs_version: 11 | ||
| 10 | + - nodejs_version: 12 | ||
| 11 | + - nodejs_version: 13 | ||
| 9 | 12 | ||
| 10 | 13 | clone_depth: 10 | |
| 11 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,7 @@ function interpolateName(loaderContext, name, options) { | |||
| 52 | 52 | let basename = 'file'; | |
| 53 | 53 | let directory = ''; | |
| 54 | 54 | let folder = ''; | |
| 55 | + let query = ''; | ||
| 55 | 56 | ||
| 56 | 57 | if (loaderContext.resourcePath) { | |
| 57 | 58 | const parsed = path.parse(loaderContext.resourcePath); | |
@@ -83,6 +84,16 @@ function interpolateName(loaderContext, name, options) { | |||
| 83 | 84 | } | |
| 84 | 85 | } | |
| 85 | 86 | ||
| 87 | + if (loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1) { | ||
| 88 | + query = loaderContext.resourceQuery; | ||
| 89 | + | ||
| 90 | + const hashIdx = query.indexOf('#'); | ||
| 91 | + | ||
| 92 | + if (hashIdx >= 0) { | ||
| 93 | + query = query.substr(0, hashIdx); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 86 | 97 | let url = filename; | |
| 87 | 98 | ||
| 88 | 99 | if (content) { | |
@@ -104,7 +115,8 @@ function interpolateName(loaderContext, name, options) { | |||
| 104 | 115 | .replace(/\[ext\]/gi, () => ext) | |
| 105 | 116 | .replace(/\[name\]/gi, () => basename) | |
| 106 | 117 | .replace(/\[path\]/gi, () => directory) | |
| 107 | - .replace(/\[folder\]/gi, () => folder); | ||
| 118 | + .replace(/\[folder\]/gi, () => folder) | ||
| 119 | + .replace(/\[query\]/gi, () => query); | ||
| 108 | 120 | ||
| 109 | 121 | if (regExp && loaderContext.resourcePath) { | |
| 110 | 122 | const match = loaderContext.resourcePath.match(new RegExp(regExp)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | "description": "utils for webpack loaders", | |
| 6 | 6 | "dependencies": { | |
| 7 | 7 | "big.js": "^5.2.2", | |
| 8 | - "emojis-list": "^2.0.0", | ||
| 8 | + "emojis-list": "^3.0.0", | ||
| 9 | 9 | "json5": "^1.0.1" | |
| 10 | 10 | }, | |
| 11 | 11 | "scripts": { | |
@@ -29,7 +29,7 @@ | |||
| 29 | 29 | "eslint-plugin-node": "^8.0.0", | |
| 30 | 30 | "eslint-plugin-prettier": "^3.0.0", | |
| 31 | 31 | "jest": "^21.2.1", | |
| 32 | - "prettier": "^1.15.3", | ||
| 32 | + "prettier": "^1.19.1", | ||
| 33 | 33 | "standard-version": "^4.0.0" | |
| 34 | 34 | }, | |
| 35 | 35 | "main": "lib/index.js", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,10 +131,58 @@ describe('interpolateName()', () => { | |||
| 131 | 131 | 'test content', | |
| 132 | 132 | 'modal.[md5::base64:20].css', | |
| 133 | 133 | ], | |
| 134 | + [ | ||
| 135 | + '/app/js/javascript.js?foo=bar', | ||
| 136 | + 'js/[hash].script.[ext][query]', | ||
| 137 | + 'test content', | ||
| 138 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar', | ||
| 139 | + ], | ||
| 140 | + [ | ||
| 141 | + '/app/js/javascript.js?foo=bar&bar=baz', | ||
| 142 | + 'js/[hash].script.[ext][query]', | ||
| 143 | + 'test content', | ||
| 144 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar&bar=baz', | ||
| 145 | + ], | ||
| 146 | + [ | ||
| 147 | + '/app/js/javascript.js?foo', | ||
| 148 | + 'js/[hash].script.[ext][query]', | ||
| 149 | + 'test content', | ||
| 150 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo', | ||
| 151 | + ], | ||
| 152 | + [ | ||
| 153 | + '/app/js/javascript.js?', | ||
| 154 | + 'js/[hash].script.[ext][query]', | ||
| 155 | + 'test content', | ||
| 156 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js', | ||
| 157 | + ], | ||
| 158 | + [ | ||
| 159 | + '/app/js/javascript.js?a', | ||
| 160 | + 'js/[hash].script.[ext][query]', | ||
| 161 | + 'test content', | ||
| 162 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js?a', | ||
| 163 | + ], | ||
| 164 | + [ | ||
| 165 | + '/app/js/javascript.js?foo=bar#hash', | ||
| 166 | + 'js/[hash].script.[ext][query]', | ||
| 167 | + 'test content', | ||
| 168 | + 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar', | ||
| 169 | + ], | ||
| 134 | 170 | ].forEach((test) => { | |
| 135 | 171 | it('should interpolate ' + test[0] + ' ' + test[1], () => { | |
| 172 | + let resourcePath = ''; | ||
| 173 | + let resourceQuery = ''; | ||
| 174 | + | ||
| 175 | + const queryIdx = test[0].indexOf('?'); | ||
| 176 | + | ||
| 177 | + if (queryIdx >= 0) { | ||
| 178 | + resourcePath = test[0].substr(0, queryIdx); | ||
| 179 | + resourceQuery = test[0].substr(queryIdx); | ||
| 180 | + } else { | ||
| 181 | + resourcePath = test[0]; | ||
| 182 | + } | ||
| 183 | + | ||
| 136 | 184 | const interpolatedName = loaderUtils.interpolateName( | |
| 137 | - { resourcePath: test[0] }, | ||
| 185 | + { resourcePath, resourceQuery }, | ||
| 138 | 186 | test[1], | |
| 139 | 187 | { content: test[2] } | |
| 140 | 188 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,9 +170,7 @@ describe('stringifyRequest()', () => { | |||
| 170 | 170 | ), | |
| 171 | 171 | }, | |
| 172 | 172 | ].forEach((testCase) => { | |
| 173 | - it(`${testCase.test}. should stringify request ${testCase.request} to ${ | ||
| 174 | - testCase.expected | ||
| 175 | - } inside context ${testCase.context}`, () => { | ||
| 173 | + it(`${testCase.test}. should stringify request ${testCase.request} to ${testCase.expected} inside context ${testCase.context}`, () => { | ||
| 176 | 174 | const relative = path.relative; | |
| 177 | 175 | ||
| 178 | 176 | if (testCase.os) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments