@botpress/cli 0.0.2
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/build.ts +12 -0
- package/dist/app/api-utils.js +105 -0
- package/dist/app/base.js +35 -0
- package/dist/app/cache.js +95 -0
- package/dist/app/errors.js +145 -0
- package/dist/app/esbuild.js +89 -0
- package/dist/app/generator/action.js +76 -0
- package/dist/app/generator/channel.js +51 -0
- package/dist/app/generator/configuration.js +40 -0
- package/dist/app/generator/const.js +31 -0
- package/dist/app/generator/event.js +47 -0
- package/dist/app/generator/index.js +83 -0
- package/dist/app/generator/integration-impl.js +147 -0
- package/dist/app/generator/integration-instance.js +85 -0
- package/dist/app/generator/message.js +47 -0
- package/dist/app/generator/module.js +115 -0
- package/dist/app/generator/strings.js +38 -0
- package/dist/app/generator/typings.js +16 -0
- package/dist/app/index.js +68 -0
- package/dist/app/integration-ref.js +61 -0
- package/dist/app/project.js +502 -0
- package/dist/app/typings.js +16 -0
- package/dist/app/user.js +198 -0
- package/dist/config.js +245 -0
- package/dist/const.js +87 -0
- package/dist/index.js +276 -0
- package/dist/index.js.map +7 -0
- package/dist/init.js +45 -0
- package/dist/init.js.map +7 -0
- package/dist/logger/base-logger.js +159 -0
- package/dist/logger/index.js +79 -0
- package/dist/paths.js +69 -0
- package/dist/requires.js +49 -0
- package/dist/type-utils.js +16 -0
- package/dist/worker/child-entrypoint.js +61 -0
- package/dist/worker/config.js +58 -0
- package/dist/worker/index.js +55 -0
- package/dist/worker/is-child.js +52 -0
- package/dist/worker/listen-child.js +89 -0
- package/init.js +1 -0
- package/package.json +54 -0
- package/readme.md +24 -0
package/dist/init.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var import_module = __toESM(require("module"));
|
|
21
|
+
var import_path = __toESM(require("path"));
|
|
22
|
+
const DEFAULT_DIRNAME = ".botpress";
|
|
23
|
+
const getOutDir = () => {
|
|
24
|
+
const { BP_OUTDIR } = process.env;
|
|
25
|
+
if (!BP_OUTDIR) {
|
|
26
|
+
return import_path.default.join(process.cwd(), DEFAULT_DIRNAME);
|
|
27
|
+
}
|
|
28
|
+
if (import_path.default.isAbsolute(BP_OUTDIR)) {
|
|
29
|
+
return BP_OUTDIR;
|
|
30
|
+
}
|
|
31
|
+
return import_path.default.join(process.cwd(), BP_OUTDIR);
|
|
32
|
+
};
|
|
33
|
+
const outDirPath = getOutDir();
|
|
34
|
+
const outDirName = import_path.default.basename(outDirPath);
|
|
35
|
+
const originalRequire = import_module.default.prototype.require;
|
|
36
|
+
const rewire = function(mod) {
|
|
37
|
+
const importParts = mod.split("/");
|
|
38
|
+
if (importParts[0] === outDirName) {
|
|
39
|
+
const newMod = importParts.slice(1).join("/");
|
|
40
|
+
const fullpath = import_path.default.join(outDirPath, newMod);
|
|
41
|
+
return originalRequire.apply(this, [fullpath]);
|
|
42
|
+
}
|
|
43
|
+
return originalRequire.apply(this, [mod]);
|
|
44
|
+
};
|
|
45
|
+
import_module.default.prototype.require = rewire;
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/init.ts"],
|
|
4
|
+
"sourcesContent": ["import Module from 'module'\nimport pathlib from 'path'\n\nconst DEFAULT_DIRNAME = '.botpress'\n\nconst getOutDir = () => {\n const { BP_OUTDIR } = process.env\n if (!BP_OUTDIR) {\n return pathlib.join(process.cwd(), DEFAULT_DIRNAME)\n }\n if (pathlib.isAbsolute(BP_OUTDIR)) {\n return BP_OUTDIR\n }\n return pathlib.join(process.cwd(), BP_OUTDIR)\n}\n\nconst outDirPath = getOutDir()\nconst outDirName = pathlib.basename(outDirPath)\nconst originalRequire = Module.prototype.require\n\nconst rewire = function (this: NodeRequire, mod: string) {\n const importParts = mod.split('/')\n\n if (importParts[0] === outDirName) {\n const newMod = importParts.slice(1).join('/')\n const fullpath = pathlib.join(outDirPath, newMod)\n return originalRequire.apply(this, [fullpath])\n }\n\n return originalRequire.apply(this, [mod])\n} as NodeRequire\n\nModule.prototype.require = rewire\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAAmB,qBACnBC,EAAoB,mBAEdC,EAAkB,YAElBC,EAAY,IAAM,CACtB,GAAM,CAAE,UAAAC,CAAU,EAAI,QAAQ,IAC9B,OAAKA,EAGD,EAAAC,QAAQ,WAAWD,CAAS,EACvBA,EAEF,EAAAC,QAAQ,KAAK,QAAQ,IAAI,EAAGD,CAAS,EALnC,EAAAC,QAAQ,KAAK,QAAQ,IAAI,EAAGH,CAAe,CAMtD,EAEMI,EAAaH,EAAU,EACvBI,EAAa,EAAAF,QAAQ,SAASC,CAAU,EACxCE,EAAkB,EAAAC,QAAO,UAAU,QAEnCC,EAAS,SAA6BC,EAAa,CACvD,IAAMC,EAAcD,EAAI,MAAM,GAAG,EAEjC,GAAIC,EAAY,KAAOL,EAAY,CACjC,IAAMM,EAASD,EAAY,MAAM,CAAC,EAAE,KAAK,GAAG,EACtCE,EAAW,EAAAT,QAAQ,KAAKC,EAAYO,CAAM,EAChD,OAAOL,EAAgB,MAAM,KAAM,CAACM,CAAQ,CAAC,CAC/C,CAEA,OAAON,EAAgB,MAAM,KAAM,CAACG,CAAG,CAAC,CAC1C,EAEA,EAAAF,QAAO,UAAU,QAAUC",
|
|
6
|
+
"names": ["import_module", "import_path", "DEFAULT_DIRNAME", "getOutDir", "BP_OUTDIR", "pathlib", "outDirPath", "outDirName", "originalRequire", "Module", "rewire", "mod", "importParts", "newMod", "fullpath"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var base_logger_exports = {};
|
|
26
|
+
__export(base_logger_exports, {
|
|
27
|
+
BaseLogger: () => BaseLogger
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(base_logger_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var import_lodash = __toESM(require("lodash"));
|
|
32
|
+
var import_util = __toESM(require("util"));
|
|
33
|
+
const DEFAULT_OPTIONS = { verbose: false };
|
|
34
|
+
const NO_COLOR = (str) => str;
|
|
35
|
+
const PINK = [255, 100, 255];
|
|
36
|
+
const ORANGE = [255, 165, 0];
|
|
37
|
+
const PURPLE = [128, 0, 128];
|
|
38
|
+
const BG_COLORS = {
|
|
39
|
+
blue: import_chalk.default.bgBlueBright,
|
|
40
|
+
green: import_chalk.default.bgGreenBright,
|
|
41
|
+
yellow: import_chalk.default.bgYellowBright,
|
|
42
|
+
red: import_chalk.default.bgRedBright,
|
|
43
|
+
white: import_chalk.default.bgWhite,
|
|
44
|
+
pink: (str) => import_chalk.default.bgRgb(...PINK)(str),
|
|
45
|
+
orange: (str) => import_chalk.default.bgRgb(...ORANGE)(str),
|
|
46
|
+
purple: (str) => import_chalk.default.bgRgb(...PURPLE)(str)
|
|
47
|
+
};
|
|
48
|
+
const FG_COLORS = {
|
|
49
|
+
blue: import_chalk.default.blueBright,
|
|
50
|
+
green: import_chalk.default.green,
|
|
51
|
+
yellow: import_chalk.default.yellowBright,
|
|
52
|
+
red: import_chalk.default.red,
|
|
53
|
+
white: import_chalk.default.white,
|
|
54
|
+
pink: (str) => import_chalk.default.rgb(...PINK)(str),
|
|
55
|
+
orange: (str) => import_chalk.default.rgb(...ORANGE)(str),
|
|
56
|
+
purple: (str) => import_chalk.default.rgb(...PURPLE)(str)
|
|
57
|
+
};
|
|
58
|
+
const checkmark = {
|
|
59
|
+
default: "\u2713",
|
|
60
|
+
windows: "\u221A",
|
|
61
|
+
mac: "\u2714"
|
|
62
|
+
};
|
|
63
|
+
const cross = {
|
|
64
|
+
default: "\xD7",
|
|
65
|
+
mac: "\u2716"
|
|
66
|
+
};
|
|
67
|
+
const danger = { default: "\u26A0" };
|
|
68
|
+
const circle = { default: "\u25CB" };
|
|
69
|
+
const disc = { default: "\u25CF" };
|
|
70
|
+
const space = { default: " " };
|
|
71
|
+
const renderers = {
|
|
72
|
+
"\u2713": checkmark,
|
|
73
|
+
"\xD7": cross,
|
|
74
|
+
"\u26A0": danger,
|
|
75
|
+
"\u25CB": circle,
|
|
76
|
+
"\u25CF": disc,
|
|
77
|
+
" ": space
|
|
78
|
+
};
|
|
79
|
+
class BaseLogger {
|
|
80
|
+
opts;
|
|
81
|
+
constructor(opts = {}) {
|
|
82
|
+
this.opts = { ...DEFAULT_OPTIONS, ...opts };
|
|
83
|
+
}
|
|
84
|
+
log(message, props = {}) {
|
|
85
|
+
if (this.opts.json) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const prefix = this._resolvePrefix(props.prefix);
|
|
89
|
+
this.print(message, { ...props, prefix });
|
|
90
|
+
}
|
|
91
|
+
json(data, opts = { depth: Infinity }) {
|
|
92
|
+
if (this.opts.json) {
|
|
93
|
+
this.print(JSON.stringify(data, void 0, 2));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const { depth } = opts;
|
|
97
|
+
const msg = import_util.default.inspect(data, { colors: true, depth });
|
|
98
|
+
this.print(msg);
|
|
99
|
+
}
|
|
100
|
+
debug(message, metadata) {
|
|
101
|
+
if (!this.opts.verbose || this.opts.json) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.log(import_chalk.default.grey(message), { metadata, prefix: { symbol: "\u25CF", fg: "blue" } });
|
|
105
|
+
}
|
|
106
|
+
started(message, metadata) {
|
|
107
|
+
if (this.opts.json) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.log(message, { metadata, prefix: { symbol: "\u25CB", fg: "purple" } });
|
|
111
|
+
}
|
|
112
|
+
success(message, metadata) {
|
|
113
|
+
if (this.opts.json) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.log(message, { metadata, prefix: { symbol: "\u2713", fg: "green" } });
|
|
117
|
+
}
|
|
118
|
+
warn(message, metadata) {
|
|
119
|
+
if (this.opts.json) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.log(message, { metadata, prefix: { symbol: "\u26A0", fg: "yellow" } });
|
|
123
|
+
}
|
|
124
|
+
error(message, metadata) {
|
|
125
|
+
if (this.opts.json) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.log(message, { metadata, prefix: { symbol: "\xD7", fg: "red" } });
|
|
129
|
+
}
|
|
130
|
+
_resolvePrefix(prefix) {
|
|
131
|
+
if (!prefix) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (import_lodash.default.isString(prefix)) {
|
|
135
|
+
return prefix;
|
|
136
|
+
}
|
|
137
|
+
const { symbol, fg, bg, indent } = prefix;
|
|
138
|
+
const renderedSymbol = this._renderSymbol(symbol);
|
|
139
|
+
const fgcolor = fg ? FG_COLORS[fg] : NO_COLOR;
|
|
140
|
+
const bgcolor = bg ? BG_COLORS[bg] : NO_COLOR;
|
|
141
|
+
const indentStr = indent ? " ".repeat(indent) : "";
|
|
142
|
+
const symbolStr = fgcolor(bgcolor(renderedSymbol));
|
|
143
|
+
return `${indentStr}${symbolStr}`;
|
|
144
|
+
}
|
|
145
|
+
_renderSymbol(symbol) {
|
|
146
|
+
const renderer = renderers[symbol];
|
|
147
|
+
if (process.platform === "win32") {
|
|
148
|
+
return renderer.windows || renderer.default;
|
|
149
|
+
} else if (process.platform === "darwin") {
|
|
150
|
+
return renderer.mac || renderer.default;
|
|
151
|
+
} else {
|
|
152
|
+
return renderer.default;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
+
0 && (module.exports = {
|
|
158
|
+
BaseLogger
|
|
159
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var logger_exports = {};
|
|
20
|
+
__export(logger_exports, {
|
|
21
|
+
Logger: () => Logger
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(logger_exports);
|
|
24
|
+
var import_readline = require("readline");
|
|
25
|
+
var import_base_logger = require("./base-logger");
|
|
26
|
+
class Logger extends import_base_logger.BaseLogger {
|
|
27
|
+
_previousLine;
|
|
28
|
+
print(message, props = {}) {
|
|
29
|
+
this.cleanup();
|
|
30
|
+
const { metadata, prefix } = props;
|
|
31
|
+
if (prefix) {
|
|
32
|
+
console.log(prefix, message, metadata ?? "");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(message, metadata ?? "");
|
|
36
|
+
}
|
|
37
|
+
line() {
|
|
38
|
+
this.cleanup();
|
|
39
|
+
const currentLine = new SingleLineLogger({ ...this.opts });
|
|
40
|
+
this._previousLine = currentLine;
|
|
41
|
+
return currentLine;
|
|
42
|
+
}
|
|
43
|
+
cleanup() {
|
|
44
|
+
if (this._previousLine) {
|
|
45
|
+
this._previousLine.commit();
|
|
46
|
+
this._previousLine = void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class SingleLineLogger extends import_base_logger.BaseLogger {
|
|
51
|
+
_commited = false;
|
|
52
|
+
constructor(opts) {
|
|
53
|
+
super(opts);
|
|
54
|
+
}
|
|
55
|
+
commit() {
|
|
56
|
+
if (this._commited) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._commited = true;
|
|
60
|
+
console.log();
|
|
61
|
+
}
|
|
62
|
+
print(message, props = {}) {
|
|
63
|
+
if (this._commited) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
(0, import_readline.clearLine)(process.stdout, 0);
|
|
67
|
+
const { metadata, prefix } = props;
|
|
68
|
+
(0, import_readline.cursorTo)(process.stdout, 0);
|
|
69
|
+
if (prefix) {
|
|
70
|
+
process.stdout.write(`${prefix} ${message} ${metadata ?? ""}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
process.stdout.write(`${message} ${metadata ?? ""}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
Logger
|
|
79
|
+
});
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var paths_exports = {};
|
|
26
|
+
__export(paths_exports, {
|
|
27
|
+
absoluteFrom: () => absoluteFrom,
|
|
28
|
+
cwd: () => cwd,
|
|
29
|
+
isAbsolute: () => isAbsolute,
|
|
30
|
+
isPath: () => isPath,
|
|
31
|
+
relativeFrom: () => relativeFrom,
|
|
32
|
+
rmExtension: () => rmExtension,
|
|
33
|
+
toUnix: () => toUnix
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(paths_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
const cwd = () => process.cwd();
|
|
38
|
+
const isAbsolute = (path) => import_path.default.isAbsolute(path);
|
|
39
|
+
const isPath = (path) => isAbsolute(path) || path.startsWith(".");
|
|
40
|
+
const rmExtension = (filename) => filename.replace(/\.[^/.]+$/, "");
|
|
41
|
+
const toUnix = (path) => path.split(import_path.default.sep).join(import_path.default.posix.sep);
|
|
42
|
+
const absoluteFrom = (rootdir, target) => {
|
|
43
|
+
if (isAbsolute(target)) {
|
|
44
|
+
return target;
|
|
45
|
+
}
|
|
46
|
+
return import_path.default.join(rootdir, target);
|
|
47
|
+
};
|
|
48
|
+
const relativeFrom = (rootdir, target) => {
|
|
49
|
+
let absPath;
|
|
50
|
+
if (isAbsolute(target)) {
|
|
51
|
+
absPath = target;
|
|
52
|
+
} else {
|
|
53
|
+
absPath = import_path.default.resolve(import_path.default.join(rootdir, target));
|
|
54
|
+
}
|
|
55
|
+
if (!absPath.startsWith(rootdir)) {
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
return absPath.slice(rootdir.length + 1);
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
absoluteFrom,
|
|
63
|
+
cwd,
|
|
64
|
+
isAbsolute,
|
|
65
|
+
isPath,
|
|
66
|
+
relativeFrom,
|
|
67
|
+
rmExtension,
|
|
68
|
+
toUnix
|
|
69
|
+
});
|
package/dist/requires.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var requires_exports = {};
|
|
26
|
+
__export(requires_exports, {
|
|
27
|
+
requireJsCode: () => requireJsCode,
|
|
28
|
+
requireJsFile: () => requireJsFile
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(requires_exports);
|
|
31
|
+
var import_module = __toESM(require("module"));
|
|
32
|
+
var import_path = __toESM(require("path"));
|
|
33
|
+
const requireJsFile = (path) => {
|
|
34
|
+
return require(path);
|
|
35
|
+
};
|
|
36
|
+
const requireJsCode = (code) => {
|
|
37
|
+
const filedir = "tmp";
|
|
38
|
+
const filename = `${Date.now()}.js`;
|
|
39
|
+
const fileid = import_path.default.join(filedir, filename);
|
|
40
|
+
const m = new import_module.default(fileid);
|
|
41
|
+
m.filename = filename;
|
|
42
|
+
m._compile(code, filename);
|
|
43
|
+
return m.exports;
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
requireJsCode,
|
|
48
|
+
requireJsFile
|
|
49
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var type_utils_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(type_utils_exports);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var child_entrypoint_exports = {};
|
|
26
|
+
__export(child_entrypoint_exports, {
|
|
27
|
+
ENTRY_POINT: () => ENTRY_POINT
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(child_entrypoint_exports);
|
|
30
|
+
var import_readline = __toESM(require("readline"));
|
|
31
|
+
var requireutils = __toESM(require("../requires"));
|
|
32
|
+
var import_config = require("./config");
|
|
33
|
+
var import_is_child = require("./is-child");
|
|
34
|
+
const ENTRY_POINT = __filename;
|
|
35
|
+
const childProcessEntrypoint = async (_props) => {
|
|
36
|
+
const config = (0, import_config.getConfigFromEnv)();
|
|
37
|
+
import_readline.default.emitKeypressEvents(process.stdin);
|
|
38
|
+
process.stdin.on("keypress", (_, key) => {
|
|
39
|
+
if (key && key.ctrl && key.name === "c") {
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
if (key && key.name === "escape") {
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
process.stdin.setRawMode(true);
|
|
47
|
+
process.stdin.resume();
|
|
48
|
+
if (config.type === "code") {
|
|
49
|
+
await requireutils.requireJsCode(config.code);
|
|
50
|
+
}
|
|
51
|
+
if (config.type === "file") {
|
|
52
|
+
await requireutils.requireJsFile(config.file);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (import_is_child.processProps.type === "child") {
|
|
56
|
+
void childProcessEntrypoint(import_is_child.processProps);
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
ENTRY_POINT
|
|
61
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var config_exports = {};
|
|
26
|
+
__export(config_exports, {
|
|
27
|
+
CONFIG_ENV_KEY: () => CONFIG_ENV_KEY,
|
|
28
|
+
configSchema: () => configSchema,
|
|
29
|
+
getConfigFromEnv: () => getConfigFromEnv
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(config_exports);
|
|
32
|
+
var import_zod = __toESM(require("zod"));
|
|
33
|
+
const CONFIG_ENV_KEY = "CHILD_PROCESS_CONFIGURATION";
|
|
34
|
+
const configSchema = import_zod.default.union([
|
|
35
|
+
import_zod.default.object({
|
|
36
|
+
type: import_zod.default.literal("code"),
|
|
37
|
+
code: import_zod.default.string(),
|
|
38
|
+
env: import_zod.default.record(import_zod.default.string(), import_zod.default.string()).optional()
|
|
39
|
+
}),
|
|
40
|
+
import_zod.default.object({
|
|
41
|
+
type: import_zod.default.literal("file"),
|
|
42
|
+
file: import_zod.default.string(),
|
|
43
|
+
env: import_zod.default.record(import_zod.default.string(), import_zod.default.string()).optional()
|
|
44
|
+
})
|
|
45
|
+
]);
|
|
46
|
+
const getConfigFromEnv = () => {
|
|
47
|
+
const config = process.env[CONFIG_ENV_KEY];
|
|
48
|
+
if (!config) {
|
|
49
|
+
throw new Error(`Config variable ${CONFIG_ENV_KEY} was not set`);
|
|
50
|
+
}
|
|
51
|
+
return configSchema.parse(JSON.parse(config));
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
CONFIG_ENV_KEY,
|
|
56
|
+
configSchema,
|
|
57
|
+
getConfigFromEnv
|
|
58
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var worker_exports = {};
|
|
26
|
+
__export(worker_exports, {
|
|
27
|
+
Config: () => import_config2.Config,
|
|
28
|
+
spawnChildProcess: () => spawnChildProcess
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(worker_exports);
|
|
31
|
+
var childProcess = __toESM(require("child_process"));
|
|
32
|
+
var import_child_entrypoint = require("./child-entrypoint");
|
|
33
|
+
var import_config = require("./config");
|
|
34
|
+
var import_is_child = require("./is-child");
|
|
35
|
+
var import_listen_child = require("./listen-child");
|
|
36
|
+
var import_config2 = require("./config");
|
|
37
|
+
const spawnChildProcess = async (config, logger) => {
|
|
38
|
+
if (import_is_child.isChildProcess) {
|
|
39
|
+
throw new Error("Cannot spawn child process from child process");
|
|
40
|
+
}
|
|
41
|
+
const child = childProcess.fork(import_child_entrypoint.ENTRY_POINT, [], {
|
|
42
|
+
stdio: "inherit",
|
|
43
|
+
env: {
|
|
44
|
+
[import_is_child.CHILD_ENV_KEY]: import_is_child.CHILD_ENV_VALUE,
|
|
45
|
+
[import_config.CONFIG_ENV_KEY]: JSON.stringify(config),
|
|
46
|
+
...config.env
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return (0, import_listen_child.listenChild)(child, logger);
|
|
50
|
+
};
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
Config,
|
|
54
|
+
spawnChildProcess
|
|
55
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var is_child_exports = {};
|
|
20
|
+
__export(is_child_exports, {
|
|
21
|
+
CHILD_ENV_KEY: () => CHILD_ENV_KEY,
|
|
22
|
+
CHILD_ENV_VALUE: () => CHILD_ENV_VALUE,
|
|
23
|
+
isChildProcess: () => isChildProcess,
|
|
24
|
+
processProps: () => processProps
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(is_child_exports);
|
|
27
|
+
const CHILD_ENV_KEY = "IS_CHILD";
|
|
28
|
+
const CHILD_ENV_VALUE = "true";
|
|
29
|
+
const getProcessProps = () => {
|
|
30
|
+
const type = process.env[CHILD_ENV_KEY] === CHILD_ENV_VALUE ? "child" : "main";
|
|
31
|
+
if (type === "main") {
|
|
32
|
+
return {
|
|
33
|
+
type
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (!process.send) {
|
|
37
|
+
throw new Error(`Please do not use variable ${CHILD_ENV_KEY} manually`);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type,
|
|
41
|
+
sendMessage: process.send
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const processProps = getProcessProps();
|
|
45
|
+
const isChildProcess = processProps.type === "child";
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
CHILD_ENV_KEY,
|
|
49
|
+
CHILD_ENV_VALUE,
|
|
50
|
+
isChildProcess,
|
|
51
|
+
processProps
|
|
52
|
+
});
|