all-package-names 2.0.662 → 2.0.664

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.
@@ -2,6 +2,9 @@
2
2
  "use strict";
3
3
 
4
4
  var _commanderVersion = _interopRequireDefault(require("commander-version"));
5
+
5
6
  var _ = require("../");
7
+
6
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+
7
10
  (0, _commanderVersion["default"])(__dirname).addCommand(_.syncCommand).parse();
package/build/index.js CHANGED
@@ -2,19 +2,27 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.savePath = void 0;
5
+
5
6
  var _path = require("path");
7
+
6
8
  var _load = require("./load");
9
+
7
10
  exports.load = _load.load;
8
11
  exports.LoadOptions = _load.LoadOptions;
9
12
  exports.Save = _load.Save;
13
+
10
14
  var _sync = _interopRequireWildcard(require("./sync"));
15
+
11
16
  exports.syncCommand = _sync["default"];
12
17
  exports.sync = _sync.sync;
13
18
  exports.syncAction = _sync.syncAction;
14
19
  exports.SyncOptions = _sync.SyncOptions;
15
20
  exports.State = _sync.State;
16
21
  exports.StateHook = _sync.StateHook;
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
+
23
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
24
+
25
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
+
19
27
  var savePath = (0, _path.join)(__dirname, "../data/all.json.gz");
20
28
  exports.savePath = savePath;
package/build/load.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Save = {
1
+ export declare type Save = {
2
2
  /**
3
3
  * Index of last package synced
4
4
  */
@@ -12,7 +12,7 @@ export type Save = {
12
12
  */
13
13
  packageNames: string[];
14
14
  };
15
- export type LoadOptions = {
15
+ export declare type LoadOptions = {
16
16
  /**
17
17
  * Maximum milliseconds after a sync to avoid re-syncing
18
18
  */
package/build/load.js CHANGED
@@ -1,31 +1,43 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
+ exports.save = save;
4
5
  exports.isFresh = isFresh;
5
6
  exports.load = load;
6
- exports.save = save;
7
+
7
8
  var _nodeFs = require("node:fs");
9
+
8
10
  var _nodeZlib = require("node:zlib");
11
+
9
12
  var _nodeUtil = require("node:util");
13
+
10
14
  var _nodeStream = require("node:stream");
15
+
11
16
  var _typesJson = require("types-json");
17
+
12
18
  var _ = require("./");
19
+
13
20
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
+
14
22
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
+
15
24
  function isPositiveNumber(value) {
16
25
  return typeof value === "number" && value >= 0;
17
26
  }
27
+
18
28
  function filterStringArray(array) {
19
29
  return array.filter(function (value) {
20
30
  return typeof value === "string";
21
31
  });
22
32
  }
33
+
23
34
  var saveTemplate = {
24
35
  since: 0,
25
36
  timestamp: 0,
26
37
  packageNames: []
27
38
  };
28
39
  var cache;
40
+
29
41
  function readJsonGz(filename) {
30
42
  return new Promise(function (resolve, reject) {
31
43
  var gunzip = (0, _nodeZlib.createGunzip)();
@@ -50,12 +62,15 @@ function readJsonGz(filename) {
50
62
  });
51
63
  });
52
64
  }
65
+
53
66
  function writeJsonGz(_x, _x2) {
54
67
  return _writeJsonGz.apply(this, arguments);
55
68
  }
69
+
56
70
  function _writeJsonGz() {
57
71
  _writeJsonGz = _asyncToGenerator(function* (filename, save) {
58
72
  var readable = _nodeStream.Readable.from([JSON.stringify(save)]);
73
+
59
74
  var gzip = (0, _nodeZlib.createGzip)();
60
75
  var writeStream = (0, _nodeFs.createWriteStream)(filename);
61
76
  var pipe = (0, _nodeUtil.promisify)(_nodeStream.pipeline);
@@ -63,9 +78,11 @@ function _writeJsonGz() {
63
78
  });
64
79
  return _writeJsonGz.apply(this, arguments);
65
80
  }
81
+
66
82
  function save(_x3) {
67
83
  return _save.apply(this, arguments);
68
84
  }
85
+
69
86
  function _save() {
70
87
  _save = _asyncToGenerator(function* (data) {
71
88
  cache = data;
@@ -73,22 +90,28 @@ function _save() {
73
90
  });
74
91
  return _save.apply(this, arguments);
75
92
  }
93
+
76
94
  function isFresh(_ref, maxAge) {
77
95
  var timestamp = _ref.timestamp;
96
+
78
97
  if (maxAge === void 0) {
79
98
  maxAge = 0;
80
99
  }
100
+
81
101
  return timestamp + maxAge > new Date().getTime();
82
102
  }
103
+
83
104
  function load(_x4) {
84
105
  return _load.apply(this, arguments);
85
106
  }
107
+
86
108
  function _load() {
87
109
  _load = _asyncToGenerator(function* (options) {
88
110
  if (cache !== undefined && isFresh(cache, options == null ? void 0 : options.maxAge)) {
89
111
  return Promise.resolve(cache);
90
112
  } else {
91
113
  var data = yield readJsonGz(_.savePath);
114
+
92
115
  if ((0, _typesJson.isJSONObject)(data)) {
93
116
  cache = {
94
117
  since: isPositiveNumber(data.since) ? data.since : saveTemplate.since,
@@ -98,6 +121,7 @@ function _load() {
98
121
  } else {
99
122
  cache = saveTemplate;
100
123
  }
124
+
101
125
  return cache;
102
126
  }
103
127
  });
package/build/sync.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Save, LoadOptions } from "./load";
2
- export type State = {
2
+ export declare type State = {
3
3
  /**
4
4
  * Starting package sync index
5
5
  */
@@ -29,8 +29,8 @@ export type State = {
29
29
  */
30
30
  lastSave: number;
31
31
  };
32
- export type StateHook = (state: State) => void;
33
- export type SyncOptions = {
32
+ export declare type StateHook = (state: State) => void;
33
+ export declare type SyncOptions = {
34
34
  onStart?: StateHook;
35
35
  onData?: StateHook;
36
36
  onEnd?: StateHook;
package/build/sync.js CHANGED
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports["default"] = void 0;
5
4
  exports.sync = sync;
6
5
  exports.syncAction = syncAction;
6
+ exports["default"] = void 0;
7
+
7
8
  var _https = require("https");
9
+
8
10
  var _pLock = require("p-lock");
11
+
9
12
  var _progress = _interopRequireDefault(require("progress"));
13
+
10
14
  var _parseJsonObject = require("parse-json-object");
15
+
11
16
  var _commanderVersion = require("commander-version");
17
+
12
18
  var _load = require("./load");
19
+
13
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
+
14
22
  var getOptions = function getOptions(path) {
15
23
  if (path === void 0) {
16
24
  path = "";
17
25
  }
26
+
18
27
  return {
19
28
  hostname: "replicate.npmjs.com",
20
29
  port: 443,
@@ -22,6 +31,7 @@ var getOptions = function getOptions(path) {
22
31
  method: "GET"
23
32
  };
24
33
  };
34
+
25
35
  function getEnd() {
26
36
  return new Promise(function (resolve) {
27
37
  var data = "";
@@ -32,15 +42,17 @@ function getEnd() {
32
42
  });
33
43
  res.on("end", function () {
34
44
  var _ref = (0, _parseJsonObject.parseJSONObject)(data),
35
- update_seq = _ref.update_seq;
45
+ update_seq = _ref.update_seq;
46
+
36
47
  resolve(update_seq);
37
48
  });
38
49
  }).end();
39
50
  });
40
51
  }
52
+
41
53
  var initialState = function initialState(_ref2, end) {
42
54
  var since = _ref2.since,
43
- packageNames = _ref2.packageNames;
55
+ packageNames = _ref2.packageNames;
44
56
  return {
45
57
  data: "",
46
58
  start: since,
@@ -52,32 +64,41 @@ var initialState = function initialState(_ref2, end) {
52
64
  packageNames: new Set(packageNames)
53
65
  };
54
66
  };
67
+
55
68
  function isChange(item) {
56
69
  return item !== undefined && typeof item.seq === "number" && typeof item.id === "string";
57
70
  }
71
+
58
72
  function pump(state) {
59
73
  while (state.data.indexOf("\n") !== state.data.lastIndexOf("\n")) {
60
74
  var newline = state.data.indexOf("\n", 1);
61
75
  var line = state.data.slice(0, newline);
76
+
62
77
  if (line.endsWith(",")) {
63
78
  line = line.slice(0, line.length - 1);
64
79
  }
80
+
65
81
  var item = (0, _parseJsonObject.parseJSONObject)(line);
82
+
66
83
  if (isChange(item)) {
67
84
  state.index = item.seq;
68
85
  state.packageNames.add(item.id);
69
86
  state.progress = (state.index - state.start) / (state.end - state.start);
70
87
  }
88
+
71
89
  state.data = state.data.slice(newline);
72
90
  }
73
91
  }
92
+
74
93
  var lock = (0, _pLock.getLock)();
94
+
75
95
  function sync(_temp) {
76
96
  var _ref3 = _temp === void 0 ? {} : _temp,
77
- onData = _ref3.onData,
78
- onStart = _ref3.onStart,
79
- onEnd = _ref3.onEnd,
80
- maxAge = _ref3.maxAge;
97
+ onData = _ref3.onData,
98
+ onStart = _ref3.onStart,
99
+ onEnd = _ref3.onEnd,
100
+ maxAge = _ref3.maxAge;
101
+
81
102
  var startTime = new Date().getTime();
82
103
  return new Promise(function (resolve) {
83
104
  lock().then(function (release) {
@@ -90,17 +111,21 @@ function sync(_temp) {
90
111
  } else {
91
112
  getEnd().then(function (end) {
92
113
  var state = initialState(data, end);
114
+
93
115
  if (onStart) {
94
116
  onStart(state);
95
117
  }
118
+
96
119
  (0, _https.request)(getOptions("/_changes?since=" + data.since), function (res) {
97
120
  res.on("data", function (chunk) {
98
121
  state.data += chunk.toString();
99
122
  pump(state);
100
123
  state.elapsed = new Date().getTime() - startTime;
124
+
101
125
  if (onData) {
102
126
  onData(state);
103
127
  }
128
+
104
129
  if (new Date().getTime() - state.lastSave > 60000) {
105
130
  state.lastSave = new Date().getTime();
106
131
  var newSave = {
@@ -115,6 +140,7 @@ function sync(_temp) {
115
140
  if (onEnd) {
116
141
  onEnd(state);
117
142
  }
143
+
118
144
  var newSave = {
119
145
  since: state.index,
120
146
  timestamp: new Date().getTime(),
@@ -132,6 +158,7 @@ function sync(_temp) {
132
158
  });
133
159
  });
134
160
  }
161
+
135
162
  function syncAction(options) {
136
163
  var bar;
137
164
  sync({
@@ -144,6 +171,7 @@ function syncAction(options) {
144
171
  },
145
172
  onData: function onData(state) {
146
173
  var _bar;
174
+
147
175
  (_bar = bar) == null ? void 0 : _bar.update(state.progress);
148
176
  },
149
177
  onEnd: function onEnd(state) {
@@ -154,5 +182,7 @@ function syncAction(options) {
154
182
  maxAge: options == null ? void 0 : options.maxAge
155
183
  });
156
184
  }
185
+
157
186
  var _default = (0, _commanderVersion.createCommand)("sync").description("Sync latest packages from NPM").option("-m --max-age [milliseconds]", "Maximum milliseconds after a sync to avoid re-syncing", parseInt).action(syncAction);
187
+
158
188
  exports["default"] = _default;
package/data/all.json.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "all-package-names",
3
- "version": "2.0.662",
3
+ "version": "2.0.664",
4
4
  "description": "Get all NPM package names",
5
5
  "license": "MIT",
6
6
  "author": {
package/data/.DS_Store DELETED
Binary file