1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict';
|
8 |
|
9 | const url = require('url');
|
10 | const File = require('vinyl');
|
11 |
|
12 | Object.defineProperty(File.prototype, 'remotePath', {
|
13 | get() {
|
14 | return this.history[this.history.length - 1];
|
15 | },
|
16 | set(remotePath) {
|
17 | if (typeof remotePath !== 'string') {
|
18 | throw new TypeError('path should be a string.');
|
19 | }
|
20 |
|
21 |
|
22 | if (!/(^\/\/)|(:\/\/)/.test(remotePath)) {
|
23 | this.path = remotePath;
|
24 | return;
|
25 | }
|
26 |
|
27 |
|
28 | const urlObj = url.parse(remotePath);
|
29 | remotePath = `${urlObj.protocol}//${urlObj.host}${urlObj.pathname}`;
|
30 |
|
31 |
|
32 | if (remotePath && remotePath !== this.remotePath) {
|
33 | this.history.push(remotePath);
|
34 | }
|
35 | }
|
36 | });
|
37 |
|
38 | module.exports = File;
|