@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.0
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/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Bounded brace expansion, replaces braces.expand() in WatchHelper#getDirParts
|
|
4
|
+
// (braces: GHSA-vfj7-8cjw-p6xm, no patched release).
|
|
5
|
+
// Supports `{a,b}` alternatives (nested, empty items) and `{x..y[..step]}`
|
|
6
|
+
// numeric (zero padded) and letter ranges, with the results of braces@3.0.3.
|
|
7
|
+
// Brace-free `[...]` / `(...)` chunks (globs, `Program Files (x86)`) pass
|
|
8
|
+
// through as text. Anything else, or past a limit, returns null: the caller
|
|
9
|
+
// then disables glob directory pruning (see VENDORED.md). Never throws.
|
|
10
|
+
|
|
11
|
+
const MAX_PATTERN_LENGTH = 10000;
|
|
12
|
+
const MAX_DEPTH = 10;
|
|
13
|
+
const MAX_EXPANSIONS = 256;
|
|
14
|
+
const MAX_OUTPUT_CHARS = 1e6;
|
|
15
|
+
|
|
16
|
+
// escapes, quotes and `${` follow braces-specific rules
|
|
17
|
+
const UNSUPPORTED_RE = /[\\'"`\u00a0\ufeff]|\$\{/;
|
|
18
|
+
// `[...]` / `(...)` without brace syntax are opaque literal text in braces
|
|
19
|
+
const OPAQUE_RE = /\[[^\][(){},.]*\]|\([^\][(){},.]*\)/g;
|
|
20
|
+
// any other bracket or paren: nested, unbalanced or wrapping brace syntax
|
|
21
|
+
const LEFTOVER_RE = /[[\]()]/;
|
|
22
|
+
const RANGE_RE = /^(-?\d+|[a-zA-Z])\.\.(-?\d+|[a-zA-Z])(?:\.\.(-?\d+))?$/;
|
|
23
|
+
const INT_RE = /^-?\d+$/;
|
|
24
|
+
const DOTS = '..';
|
|
25
|
+
|
|
26
|
+
// fill-range pads when a bound or the step is written with a leading zero
|
|
27
|
+
const isPadded = (str) => /^-?0\d/.test(str);
|
|
28
|
+
|
|
29
|
+
const pad = (str, len) => {
|
|
30
|
+
const dash = str[0] === '-' ? '-' : '';
|
|
31
|
+
return dash + str.slice(dash.length).padStart(len - dash.length, '0');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// `{from..to[..step]}`: string[], null if unsupported or too long
|
|
35
|
+
const fillRange = (from, to, stepStr = '1') => {
|
|
36
|
+
const numeric = INT_RE.test(from) && INT_RE.test(to);
|
|
37
|
+
// digit against letter: braces mixes char codes
|
|
38
|
+
if (!numeric && (INT_RE.test(from) || INT_RE.test(to))) return null;
|
|
39
|
+
const a = numeric ? Number(from) : from.charCodeAt(0);
|
|
40
|
+
const b = numeric ? Number(to) : to.charCodeAt(0);
|
|
41
|
+
const step = Math.abs(Number(stepStr)) || 1;
|
|
42
|
+
if (![a, b, step].every(Number.isSafeInteger)) return null;
|
|
43
|
+
if (Math.floor(Math.abs(b - a) / step) + 1 > MAX_EXPANSIONS) return null;
|
|
44
|
+
const len = numeric && [from, to, stepStr].some(isPadded) ?
|
|
45
|
+
Math.max(from.length, to.length, stepStr.length) : 0;
|
|
46
|
+
const out = [];
|
|
47
|
+
const desc = a > b;
|
|
48
|
+
for (let i = a; desc ? i >= b : i <= b; i += desc ? -step : step) {
|
|
49
|
+
out.push(numeric ? (len ? pad(String(i), len) : String(i)) : String.fromCharCode(i));
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Group tree: {parts: item[][]}, item = string | group. Nesting bounded by MAX_DEPTH
|
|
55
|
+
const scan = (str) => {
|
|
56
|
+
const root = {parts: [[]]};
|
|
57
|
+
const stack = [root];
|
|
58
|
+
for (const ch of str) {
|
|
59
|
+
const top = stack[stack.length - 1];
|
|
60
|
+
const items = top.parts[top.parts.length - 1];
|
|
61
|
+
if (ch === '{') {
|
|
62
|
+
if (stack.length > MAX_DEPTH) return null;
|
|
63
|
+
const group = {parts: [[]]};
|
|
64
|
+
items.push(group);
|
|
65
|
+
stack.push(group);
|
|
66
|
+
} else if (ch === ',' && top !== root) {
|
|
67
|
+
top.parts.push([]);
|
|
68
|
+
} else if (ch === '}') {
|
|
69
|
+
// stray `}`: kept literal by braces
|
|
70
|
+
if (top === root) return null;
|
|
71
|
+
stack.pop();
|
|
72
|
+
} else if (typeof items[items.length - 1] === 'string') {
|
|
73
|
+
items[items.length - 1] += ch;
|
|
74
|
+
} else {
|
|
75
|
+
items.push(ch);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// unclosed `{`: kept literal by braces
|
|
79
|
+
return stack.length === 1 ? root.parts[0] : null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Node: string | {seq: node[]} | {alt: node[]} | {range: string[]}
|
|
83
|
+
const toSeq = (items) => {
|
|
84
|
+
const seq = [];
|
|
85
|
+
for (const item of items) {
|
|
86
|
+
const node = typeof item === 'string' ? item : toGroup(item);
|
|
87
|
+
if (node === null) return null;
|
|
88
|
+
seq.push(node);
|
|
89
|
+
}
|
|
90
|
+
return {seq};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const toGroup = ({parts}) => {
|
|
94
|
+
if (parts.length === 1) {
|
|
95
|
+
// single item braces (`{a}`, `{}`) are literal in braces
|
|
96
|
+
const body = parts[0].length === 1 && typeof parts[0][0] === 'string' ? parts[0][0] : '';
|
|
97
|
+
const m = RANGE_RE.exec(body);
|
|
98
|
+
const range = m && fillRange(m[1], m[2], m[3]);
|
|
99
|
+
return range ? {range} : null;
|
|
100
|
+
}
|
|
101
|
+
const alt = [];
|
|
102
|
+
for (const part of parts) {
|
|
103
|
+
// `..` inside an alternation goes through braces' range state machine
|
|
104
|
+
if (part.some((item) => typeof item === 'string' && item.includes(DOTS))) return null;
|
|
105
|
+
const seq = toSeq(part);
|
|
106
|
+
if (seq === null) return null;
|
|
107
|
+
alt.push(seq);
|
|
108
|
+
}
|
|
109
|
+
return {alt};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Saturating {count, chars} computed before anything is built, null past a limit
|
|
113
|
+
const measure = (node) => {
|
|
114
|
+
let count = 0;
|
|
115
|
+
let chars = 0;
|
|
116
|
+
if (typeof node === 'string') {
|
|
117
|
+
count = 1;
|
|
118
|
+
chars = node.length;
|
|
119
|
+
} else if (node.range) {
|
|
120
|
+
count = node.range.length;
|
|
121
|
+
for (const s of node.range) chars += s.length;
|
|
122
|
+
} else if (node.alt) {
|
|
123
|
+
for (const part of node.alt) {
|
|
124
|
+
const m = measure(part);
|
|
125
|
+
if (m === null) return null;
|
|
126
|
+
count += m.count;
|
|
127
|
+
chars += m.chars;
|
|
128
|
+
// early exit on long alternations, the enclosing seq checks too
|
|
129
|
+
if (count > MAX_EXPANSIONS || chars > MAX_OUTPUT_CHARS) return null;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
count = 1;
|
|
133
|
+
for (const item of node.seq) {
|
|
134
|
+
const m = measure(item);
|
|
135
|
+
if (m === null) return null;
|
|
136
|
+
chars = chars * m.count + m.chars * count;
|
|
137
|
+
count *= m.count;
|
|
138
|
+
if (count > MAX_EXPANSIONS || chars > MAX_OUTPUT_CHARS) return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {count, chars};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Cartesian product, left-major like braces, no dedupe
|
|
145
|
+
const materialize = (node) => {
|
|
146
|
+
if (typeof node === 'string') return [node];
|
|
147
|
+
if (node.range) return node.range;
|
|
148
|
+
if (node.alt) return [].concat(...node.alt.map(materialize));
|
|
149
|
+
let acc = [''];
|
|
150
|
+
for (const item of node.seq) {
|
|
151
|
+
const values = materialize(item);
|
|
152
|
+
const next = [];
|
|
153
|
+
for (const prefix of acc) {
|
|
154
|
+
for (const value of values) next.push(prefix + value);
|
|
155
|
+
}
|
|
156
|
+
acc = next;
|
|
157
|
+
}
|
|
158
|
+
return acc;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {String} str glob
|
|
163
|
+
* @returns {String[]|null} expansions, or null if unsupported / over a limit
|
|
164
|
+
*/
|
|
165
|
+
const expandBraces = (str) => {
|
|
166
|
+
// braces.expand('') is [], nothing to expand anyway
|
|
167
|
+
if (typeof str !== 'string' || !str || str.length > MAX_PATTERN_LENGTH) return null;
|
|
168
|
+
if (UNSUPPORTED_RE.test(str)) return null;
|
|
169
|
+
if (LEFTOVER_RE.test(str.replace(OPAQUE_RE, ''))) return null;
|
|
170
|
+
const items = scan(str);
|
|
171
|
+
const tree = items && toSeq(items);
|
|
172
|
+
if (!tree || measure(tree) === null) return null;
|
|
173
|
+
return materialize(tree);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
module.exports = expandBraces;
|
|
177
|
+
module.exports.MAX_PATTERN_LENGTH = MAX_PATTERN_LENGTH;
|
|
178
|
+
module.exports.MAX_DEPTH = MAX_DEPTH;
|
|
179
|
+
module.exports.MAX_EXPANSIONS = MAX_EXPANSIONS;
|
|
180
|
+
module.exports.MAX_OUTPUT_CHARS = MAX_OUTPUT_CHARS;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {sep} = require('path');
|
|
4
|
+
const {platform} = process;
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
exports.EV_ALL = 'all';
|
|
8
|
+
exports.EV_READY = 'ready';
|
|
9
|
+
exports.EV_ADD = 'add';
|
|
10
|
+
exports.EV_CHANGE = 'change';
|
|
11
|
+
exports.EV_ADD_DIR = 'addDir';
|
|
12
|
+
exports.EV_UNLINK = 'unlink';
|
|
13
|
+
exports.EV_UNLINK_DIR = 'unlinkDir';
|
|
14
|
+
exports.EV_RAW = 'raw';
|
|
15
|
+
exports.EV_ERROR = 'error';
|
|
16
|
+
|
|
17
|
+
exports.STR_DATA = 'data';
|
|
18
|
+
exports.STR_END = 'end';
|
|
19
|
+
exports.STR_CLOSE = 'close';
|
|
20
|
+
|
|
21
|
+
exports.FSEVENT_CREATED = 'created';
|
|
22
|
+
exports.FSEVENT_MODIFIED = 'modified';
|
|
23
|
+
exports.FSEVENT_DELETED = 'deleted';
|
|
24
|
+
exports.FSEVENT_MOVED = 'moved';
|
|
25
|
+
exports.FSEVENT_CLONED = 'cloned';
|
|
26
|
+
exports.FSEVENT_UNKNOWN = 'unknown';
|
|
27
|
+
exports.FSEVENT_FLAG_MUST_SCAN_SUBDIRS = 1;
|
|
28
|
+
exports.FSEVENT_TYPE_FILE = 'file';
|
|
29
|
+
exports.FSEVENT_TYPE_DIRECTORY = 'directory';
|
|
30
|
+
exports.FSEVENT_TYPE_SYMLINK = 'symlink';
|
|
31
|
+
|
|
32
|
+
exports.KEY_LISTENERS = 'listeners';
|
|
33
|
+
exports.KEY_ERR = 'errHandlers';
|
|
34
|
+
exports.KEY_RAW = 'rawEmitters';
|
|
35
|
+
exports.HANDLER_KEYS = [exports.KEY_LISTENERS, exports.KEY_ERR, exports.KEY_RAW];
|
|
36
|
+
|
|
37
|
+
exports.DOT_SLASH = `.${sep}`;
|
|
38
|
+
|
|
39
|
+
exports.BACK_SLASH_RE = /\\/g;
|
|
40
|
+
exports.DOUBLE_SLASH_RE = /\/\//;
|
|
41
|
+
exports.SLASH_OR_BACK_SLASH_RE = /[/\\]/;
|
|
42
|
+
exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
|
43
|
+
exports.REPLACER_RE = /^\.[/\\]/;
|
|
44
|
+
|
|
45
|
+
exports.SLASH = '/';
|
|
46
|
+
exports.SLASH_SLASH = '//';
|
|
47
|
+
exports.BRACE_START = '{';
|
|
48
|
+
exports.BANG = '!';
|
|
49
|
+
exports.ONE_DOT = '.';
|
|
50
|
+
exports.TWO_DOTS = '..';
|
|
51
|
+
exports.STAR = '*';
|
|
52
|
+
exports.GLOBSTAR = '**';
|
|
53
|
+
exports.ROOT_GLOBSTAR = '/**/*';
|
|
54
|
+
exports.SLASH_GLOBSTAR = '/**';
|
|
55
|
+
exports.DIR_SUFFIX = 'Dir';
|
|
56
|
+
exports.ANYMATCH_OPTS = {dot: true};
|
|
57
|
+
exports.STRING_TYPE = 'string';
|
|
58
|
+
exports.FUNCTION_TYPE = 'function';
|
|
59
|
+
exports.EMPTY_STR = '';
|
|
60
|
+
exports.EMPTY_FN = () => {};
|
|
61
|
+
exports.IDENTITY_FN = val => val;
|
|
62
|
+
|
|
63
|
+
exports.isWindows = platform === 'win32';
|
|
64
|
+
exports.isMacos = platform === 'darwin';
|
|
65
|
+
exports.isLinux = platform === 'linux';
|
|
66
|
+
exports.isIBMi = os.type() === 'OS400';
|