UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const stream_1 = tslib_1.__importDefault(require("stream"));
5const humanize_list_1 = tslib_1.__importDefault(require("humanize-list"));
6const plugin_error_1 = tslib_1.__importDefault(require("plugin-error"));
7const PLUGIN_NAME = 'duplicates';
8function vinylAssertFiles() {
9 const foundPaths = new Set();
10 const duplicatePaths = new Set();
11 return new stream_1.default.Transform({
12 objectMode: true,
13 transform(file, _, cb) {
14 if (!file.isNull()) {
15 if (foundPaths.has(file.relative)) {
16 duplicatePaths.add(file.relative);
17 }
18 else {
19 foundPaths.add(file.relative);
20 }
21 }
22 cb(undefined, file);
23 },
24 flush(cb) {
25 if (duplicatePaths.size !== 0) {
26 this.emit('error', new plugin_error_1.default(PLUGIN_NAME, `One or more files in the build output were duplicates: ${humanize_list_1.default([...duplicatePaths])}`));
27 }
28 cb();
29 },
30 });
31}
32exports.default = vinylAssertFiles;