Skip to content

Commit 12f8f21

Browse files
committed
Merge branch 'master' of github.com:NetCZ/vue-separate-files-webpack-loader
2 parents fb93ba2 + 5e02fc4 commit 12f8f21

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

src/helper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ exports.createPart = function createPart(settings, options) {
7676
};
7777

7878
exports.createParts = function createParts(options, dirPath, inputFile, fileNames) {
79-
var inputFileName = inputFile.split(options.test)[0];
79+
var inputFileName = new RegExp(`^${ inputFile.split(options.test)[0] }`);
8080
var parts = {},
8181
that = this;
8282

@@ -89,7 +89,7 @@ exports.createParts = function createParts(options, dirPath, inputFile, fileName
8989

9090
if (_.has(parts, settings.tagName) || _.has(parts, settings.fileType)) {
9191
var type = settings.tagName || settings.fileType;
92-
throw new TypeError(`File "${file}" can't be used as "${type}", because it was already defined in "${_.get(parts[type], 'file', null)}".`);
92+
throw new TypeError(`File "${ file }" can't be used as "${ type }", because it was already defined in "${ _.get(parts[type], 'file', null) }".`);
9393
}
9494

9595
parts[settings.tagName || settings.fileType] = that.createPart(settings, options);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
9+
</body>
10+
</html>

test/files/similar-component-names/Component.vue.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
9+
</body>
10+
</html>

test/files/similar-component-names/SimilarComponent.vue.js

Whitespace-only changes.

test/loader.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var twoPartsDir = path.resolve(dir + '/files/two-parts') + path.sep,
1414
emptyDir = path.resolve(dir + '/files/empty') + path.sep,
1515
twoComponentsSameDir = path.resolve(dir + '/files/two-components-same-dir') + path.sep,
1616
twoComponentsDuplicateSameDir = path.resolve(dir + '/files/two-components-duplicate-same-dir') + path.sep,
17-
twoPartsDirCustomScript = path.resolve(dir + '/files/two-parts-custom-script') + path.sep;
17+
twoPartsDirCustomScript = path.resolve(dir + '/files/two-parts-custom-script') + path.sep,
18+
similarComponentNamesDir = path.resolve(dir + '/files/similar-component-names') + path.sep;
1819

1920
beforeEach(function () {
2021
loader = require('../index');
@@ -48,11 +49,11 @@ describe('loader: errors', function () {
4849
});
4950

5051
it('should throw duplication TypeError - multiple components in same directory', function () {
51-
var content = require(duplicateDir + 'Component.vue');
52+
var content = require(twoComponentsDuplicateSameDir + 'SecondComponent.vue');
5253

5354
assert.throws(function () {
54-
loader.apply(_.assign({}, webpack, { context: twoComponentsDuplicateSameDir }), [content, { file: 'Component.vue.js' }]);
55-
}, TypeError, 'File "SecondComponent.vue.html" can\'t be used as "template", because it was already defined in "FirstComponent.vue.html".');
55+
loader.apply(_.assign({}, webpack, { context: twoComponentsDuplicateSameDir }), [content, { file: 'SecondComponent.vue.js' }]);
56+
}, TypeError, 'File "SecondComponent.vue.pug" can\'t be used as "template", because it was already defined in "SecondComponent.vue.html".');
5657
});
5758
});
5859

@@ -257,4 +258,26 @@ describe('loader: success', function () {
257258

258259
assert.strictEqual(result, expected);
259260
});
261+
262+
it('should has two parts even when similar component names occurs - first component', function () {
263+
var content = require(similarComponentNamesDir + 'Component.vue');
264+
265+
var expected = '<template separated src="' + similarComponentNamesDir + 'Component.vue.html" lang="html"></template>' +
266+
'<script separated src="' + similarComponentNamesDir + 'Component.vue.js" lang="js"></script>';
267+
268+
var result = loader.apply(_.assign({}, webpack, { context: similarComponentNamesDir }), [content, { file: 'Component.vue.js' }]);
269+
270+
assert.strictEqual(result, expected);
271+
});
272+
273+
it('should has two parts even when similar component names occurs - second component', function () {
274+
var content = require(similarComponentNamesDir + 'SimilarComponent.vue');
275+
276+
var expected = '<template separated src="' + similarComponentNamesDir + 'SimilarComponent.vue.html" lang="html"></template>' +
277+
'<script separated src="' + similarComponentNamesDir + 'SimilarComponent.vue.js" lang="js"></script>';
278+
279+
var result = loader.apply(_.assign({}, webpack, { context: similarComponentNamesDir }), [content, { file: 'SimilarComponent.vue.js' }]);
280+
281+
assert.strictEqual(result, expected);
282+
});
260283
});

0 commit comments

Comments
 (0)