Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit e73131f

Browse files
revert(index): context takes precedence over issuer.context (options.useRelativePath) (#260)
This reverts commit 3b071f5
1 parent d27b04c commit e73131f

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

src/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable
2+
multiline-ternary,
3+
*/
14
import path from 'path';
25
import loaderUtils from 'loader-utils';
36
import validateOptions from 'schema-utils';
@@ -31,13 +34,15 @@ export default function loader(content) {
3134
if (options.useRelativePath) {
3235
const filePath = this.resourcePath;
3336

34-
const issuerContext = context || (
35-
this._module &&
36-
this._module.issuer &&
37-
this._module.issuer.context
38-
);
37+
const issuer = options.context
38+
? context
39+
: (
40+
this._module &&
41+
this._module.issuer &&
42+
this._module.issuer.context
43+
);
3944

40-
const relativeUrl = issuerContext && path.relative(issuerContext, filePath)
45+
const relativeUrl = issuer && path.relative(issuer, filePath)
4146
.split(path.sep)
4247
.join('/');
4348

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* eslint-disable */
2-
import png from './nested/file.png';
2+
import png from './assets/file.png';
33

44
export default png;
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Options useRelativePath \`false\` 1`] = `
3+
exports[`Options useRelativePath {Boolean} - \`false\` 1`] = `
44
Object {
55
"assets": Array [
66
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
@@ -9,29 +9,29 @@ Object {
99
}
1010
`;
1111

12-
exports[`Options useRelativePath \`true\` 1`] = `
12+
exports[`Options useRelativePath {Boolean} - \`true\` 1`] = `
1313
Object {
1414
"assets": Array [
15-
"nested/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
15+
"assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
1616
],
17-
"source": "module.exports = __webpack_public_path__ + \\"nested/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
17+
"source": "module.exports = __webpack_public_path__ + \\"assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
1818
}
1919
`;
2020

21-
exports[`Options useRelativePath \`true\` with absolute \`context\` 1`] = `
21+
exports[`Options useRelativePath {Boolean} - \`true\` with absolute \`context\` 1`] = `
2222
Object {
2323
"assets": Array [
24-
"file-loader/test/fixtures/nested/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
24+
"file-loader/test/fixtures/nested/assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
2525
],
26-
"source": "module.exports = __webpack_public_path__ + \\"file-loader/test/fixtures/nested/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
26+
"source": "module.exports = __webpack_public_path__ + \\"file-loader/test/fixtures/nested/assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
2727
}
2828
`;
2929

30-
exports[`Options useRelativePath \`true\` with relative \`context\` 1`] = `
30+
exports[`Options useRelativePath {Boolean} - \`true\` with relative \`context\` 1`] = `
3131
Object {
3232
"assets": Array [
33-
"9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
33+
"assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png",
3434
],
35-
"source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
35+
"source": "module.exports = __webpack_public_path__ + \\"assets/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";",
3636
}
3737
`;

test/options/useRelativePath.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import webpack from '../helpers/compiler';
55

66
describe('Options', () => {
77
describe('useRelativePath', () => {
8-
test('`false`', async () => {
8+
test('{Boolean} - `false`', async () => {
99
const config = {
1010
loader: {
1111
test: /(png|jpg|svg)/,
@@ -15,13 +15,13 @@ describe('Options', () => {
1515
},
1616
};
1717

18-
const stats = await webpack('fixture-nested.js', config);
18+
const stats = await webpack('nested/fixture.js', config);
1919
const { assets, source } = stats.toJson().modules[1];
2020

2121
expect({ assets, source }).toMatchSnapshot();
2222
});
2323

24-
test('`true`', async () => {
24+
test('{Boolean} - `true`', async () => {
2525
const config = {
2626
loader: {
2727
test: /(png|jpg|svg)/,
@@ -31,13 +31,13 @@ describe('Options', () => {
3131
},
3232
};
3333

34-
const stats = await webpack('fixture-nested.js', config);
34+
const stats = await webpack('nested/fixture.js', config);
3535
const { assets, source } = stats.toJson().modules[1];
3636

3737
expect({ assets, source }).toMatchSnapshot();
3838
});
3939

40-
test('`true` with relative `context`', async () => {
40+
test('{Boolean} - `true` with relative `context`', async () => {
4141
const config = {
4242
loader: {
4343
test: /(png|jpg|svg)/,
@@ -48,13 +48,13 @@ describe('Options', () => {
4848
},
4949
};
5050

51-
const stats = await webpack('fixture-nested.js', config);
51+
const stats = await webpack('nested/fixture.js', config);
5252
const { assets, source } = stats.toJson().modules[1];
5353

5454
expect({ assets, source }).toMatchSnapshot();
5555
});
5656

57-
test('`true` with absolute `context`', async () => {
57+
test('{Boolean} - `true` with absolute `context`', async () => {
5858
const config = {
5959
loader: {
6060
test: /(png|jpg|svg)/,
@@ -65,7 +65,7 @@ describe('Options', () => {
6565
},
6666
};
6767

68-
const stats = await webpack('fixture-nested.js', config);
68+
const stats = await webpack('nested/fixture.js', config);
6969
const { assets, source } = stats.toJson().modules[1];
7070

7171
expect({ assets, source }).toMatchSnapshot();

0 commit comments

Comments
 (0)