whistle 2.9.5 → 2.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/plugin.js CHANGED
@@ -7,19 +7,22 @@ var getWhistlePath = require('../lib/util/common').getWhistlePath;
7
7
 
8
8
  var CMD_SUFFIX = process.platform === 'win32' ? '.cmd' : '';
9
9
  var WHISTLE_PLUGIN_RE = /^((?:@[\w-]+\/)?whistle\.[a-z\d_-]+)(?:\@([\w.^~*-]*))?$/;
10
- var PLUGIN_PATH = path.join(getWhistlePath(), 'plugins');
11
10
  var CUSTOM_PLUGIN_PATH = path.join(getWhistlePath(), 'custom_plugins');
12
11
  var PACKAGE_JSON = '{"repository":"https://github.com/avwo/whistle","license":"MIT"}';
13
12
  var LICENSE = 'Copyright (c) 2019 avwo';
14
13
  var RESP_URL = 'https://github.com/avwo/whistle';
14
+ var REMOTE_URL_RE = /^\s*((?:git[+@]|github:|https?:\/\/)[^\s]+\/whistle\.[a-z\d_-]+(?:\.git)?)\s*$/i;
15
15
 
16
16
  function getInstallPath(name, dir) {
17
17
  return path.join(dir || CUSTOM_PLUGIN_PATH, name);
18
18
  }
19
19
 
20
- function getPlugins(argv) {
20
+ function getPlugins(argv, isInstall) {
21
21
  return argv.filter(function(name) {
22
- return WHISTLE_PLUGIN_RE.test(name);
22
+ if (WHISTLE_PLUGIN_RE.test(name)) {
23
+ return true;
24
+ }
25
+ return isInstall && REMOTE_URL_RE.test(name);
23
26
  });
24
27
  }
25
28
 
@@ -29,11 +32,6 @@ function removeDir(installPath) {
29
32
  }
30
33
  }
31
34
 
32
- function removeOldPlugin(name) {
33
- removeDir(path.join(PLUGIN_PATH, 'node_modules', name));
34
- removeDir(path.join(PLUGIN_PATH, 'node_modules', getTempName(name)));
35
- }
36
-
37
35
  function getTempName(name) {
38
36
  if (name.indexOf('/') === -1) {
39
37
  return '.' + name;
@@ -59,11 +57,28 @@ function getInstallDir(argv) {
59
57
  return result;
60
58
  }
61
59
 
60
+ function getPluginNameFormDeps(deps) {
61
+ var keys = Object.keys(deps);
62
+ for (var i = 0, len = keys.length; i < len; i++) {
63
+ if (WHISTLE_PLUGIN_RE.test(keys[i])) {
64
+ return RegExp.$1;
65
+ }
66
+ }
67
+ }
68
+
69
+ function getPkgName(name) {
70
+ if (/[/\\](whistle\.[a-z\d_-]+)(?:\.git)?$/.test(name)) {
71
+ return RegExp.$1;
72
+ }
73
+ return name;
74
+ }
75
+
62
76
  function install(cmd, name, argv, ver, pluginsCache, callback) {
63
- argv = argv.slice();
64
- var result = getInstallDir(argv);
77
+ var result = getInstallDir(argv.slice());
78
+ var isPkg = WHISTLE_PLUGIN_RE.test(name);
79
+ var pkgName = isPkg ? name : getPkgName(name);
80
+ var installPath = getInstallPath(getTempName(pkgName), result.dir);
65
81
  argv = result.argv;
66
- var installPath = getInstallPath(getTempName(name), result.dir);
67
82
  fse.ensureDirSync(installPath);
68
83
  fse.emptyDirSync(installPath);
69
84
  var pkgJson = PACKAGE_JSON;
@@ -74,7 +89,7 @@ function install(cmd, name, argv, ver, pluginsCache, callback) {
74
89
  fs.writeFileSync(path.join(installPath, 'LICENSE'), LICENSE);
75
90
  fs.writeFileSync(path.join(installPath, 'README.md'), RESP_URL);
76
91
  argv.unshift('install', name);
77
- pluginsCache[name] = 1;
92
+ pluginsCache[pkgName] = 1;
78
93
  cp.spawn(cmd, argv, {
79
94
  stdio: 'inherit',
80
95
  cwd: installPath
@@ -83,11 +98,22 @@ function install(cmd, name, argv, ver, pluginsCache, callback) {
83
98
  removeDir(installPath);
84
99
  callback();
85
100
  } else {
101
+ if (!isPkg) {
102
+ var deps = fse.readJsonSync(path.join(installPath, 'package.json')).dependencies;
103
+ name = deps && getPluginNameFormDeps(deps);
104
+ }
105
+ if (!name) {
106
+ try {
107
+ removeDir(installPath);
108
+ } catch (e) {}
109
+ return callback();
110
+ }
86
111
  var realPath = getInstallPath(name, result.dir);
87
112
  removeDir(realPath);
88
113
  try {
89
114
  fs.renameSync(installPath, realPath);
90
115
  } catch (e) {
116
+ fse.ensureDirSync(realPath);
91
117
  fse.copySync(installPath, realPath);
92
118
  try {
93
119
  removeDir(installPath);
@@ -125,7 +151,8 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
125
151
  var list = pkg.whistleConfig && (pkg.whistleConfig.peerPluginList || pkg.whistleConfig.peerPlugins);
126
152
  if (Array.isArray(list) && list.length < 16) {
127
153
  list.forEach(function(name) {
128
- if (typeof name === 'string' && WHISTLE_PLUGIN_RE.test(name.trim())) {
154
+ name = typeof name === 'string' ? name.trim() : null;
155
+ if (name && (WHISTLE_PLUGIN_RE.test(name) || REMOTE_URL_RE.test(name))) {
129
156
  name = RegExp.$1;
130
157
  if (peerPlugins.indexOf(name) === -1) {
131
158
  peerPlugins.push(name);
@@ -142,11 +169,11 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
142
169
  }
143
170
  };
144
171
  plugins.forEach(function(name) {
145
- if (WHISTLE_PLUGIN_RE.test(name)) {
172
+ var isPkg = WHISTLE_PLUGIN_RE.test(name);
173
+ if (isPkg || REMOTE_URL_RE.test(name)) {
146
174
  ++count;
147
175
  name = RegExp.$1;
148
176
  var ver = RegExp.$2;
149
- removeOldPlugin(name);
150
177
  install(cmd, name, argv, ver, pluginsCache, callback);
151
178
  }
152
179
  });
@@ -155,7 +182,7 @@ function installPlugins(cmd, plugins, argv, pluginsCache, deep) {
155
182
  exports.getWhistlePath = getWhistlePath;
156
183
 
157
184
  exports.install = function(cmd, argv) {
158
- var plugins = getPlugins(argv);
185
+ var plugins = getPlugins(argv, true);
159
186
  if (!plugins.length) {
160
187
  return;
161
188
  }
@@ -174,7 +201,6 @@ exports.uninstall = function(plugins) {
174
201
  getPlugins(plugins).forEach(function(name) {
175
202
  if (WHISTLE_PLUGIN_RE.test(name)) {
176
203
  name = RegExp.$1;
177
- !result.dir && removeOldPlugin(name);
178
204
  removeDir(getInstallPath(name, result.dir));
179
205
  }
180
206
  });
package/bin/use.js CHANGED
@@ -10,7 +10,7 @@ var error = util.error;
10
10
  var warn = util.warn;
11
11
  var info = util.info;
12
12
  var readConfig = util.readConfig;
13
- var MAX_RULES_LEN = 1024 * 16;
13
+ var MAX_RULES_LEN = 1024 * 256;
14
14
  var DEFAULT_OPTIONS = { host: '127.0.0.1', port: 8899 };
15
15
  var options;
16
16
 
@@ -142,7 +142,7 @@ module.exports = function(filepath, storage, force) {
142
142
  }
143
143
  var rules = getString(result.rules);
144
144
  if (rules.length > MAX_RULES_LEN) {
145
- error('The rules cannot be empty and the size cannot exceed 16k.');
145
+ error('The rules cannot be empty and the size cannot exceed 256k.');
146
146
  return;
147
147
  }
148
148
  var setRules = function() {
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body style="overscroll-behavior-x: none;">
10
10
  <div id="container" class="main"></div>
11
- <script src="js/index.js?v=2.9.5"></script>
11
+ <script src="js/index.js?v=2.9.8"></script>
12
12
  </body>
13
13
  </html>