innetjs 3.1.1 → 3.2.1
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/_virtual/_rollup-plugin-process-env.js +1 -1
- package/_virtual/_rollup-plugin-process-env.mjs +1 -1
- package/bin/innet +91 -7
- package/index.d.ts +3 -2
- package/index.js +87 -4
- package/index.mjs +87 -4
- package/package.json +3 -3
package/bin/innet
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var commander = require('commander');
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
+
var codeFrame = require('@babel/code-frame');
|
|
6
7
|
var logger = require('@cantinc/logger');
|
|
7
8
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
8
9
|
var eslint = require('@rollup/plugin-eslint');
|
|
@@ -167,6 +168,71 @@ function getNpmTag(version) {
|
|
|
167
168
|
const match = version.match(NPM_TAG);
|
|
168
169
|
return match ? match[1] : 'latest';
|
|
169
170
|
}
|
|
171
|
+
function printErrorWithFrame(output, deep = 0, hide = false) {
|
|
172
|
+
var _a, _b, _c, _d, _e;
|
|
173
|
+
if (!output)
|
|
174
|
+
return '';
|
|
175
|
+
const input = output.split('\n');
|
|
176
|
+
const start = input.findIndex(line => line.trim().startsWith(deep ? '[cause]: Error:' : 'Error:'));
|
|
177
|
+
if (!~start)
|
|
178
|
+
return output;
|
|
179
|
+
const inputFrame = input.slice(0, start);
|
|
180
|
+
const end = input.slice(start + 1).findIndex(line => line.trim().startsWith('[cause]: Error:'));
|
|
181
|
+
const inputBody = input.slice(start, ~end ? start + end - 1 : undefined);
|
|
182
|
+
const inputCauses = ~end ? input.slice(start + end - 1) : [];
|
|
183
|
+
const bodyStackStart = inputBody.findIndex(line => line.trim().startsWith('at '));
|
|
184
|
+
const bodyText = ~bodyStackStart ? inputBody.slice(0, bodyStackStart).join('\n') : inputBody.join('\n');
|
|
185
|
+
const bodyStack = ~bodyStackStart ? inputBody.slice(bodyStackStart) : [];
|
|
186
|
+
const filePathWithNumber = bodyStack.length ? (_a = bodyStack[0].match(/\(([^(]+)\)$/)) === null || _a === void 0 ? void 0 : _a[1] : undefined;
|
|
187
|
+
const splitFilePath = (_b = filePathWithNumber === null || filePathWithNumber === void 0 ? void 0 : filePathWithNumber.split(':')) !== null && _b !== void 0 ? _b : [];
|
|
188
|
+
const filePath = (_c = splitFilePath[0]) === null || _c === void 0 ? void 0 : _c.trim();
|
|
189
|
+
const line = Number((_d = splitFilePath[1]) !== null && _d !== void 0 ? _d : 1);
|
|
190
|
+
const column = Number((_e = splitFilePath[2]) !== null && _e !== void 0 ? _e : 1);
|
|
191
|
+
let frame = '';
|
|
192
|
+
if (filePath && !filePath.includes('node_modules')) {
|
|
193
|
+
try {
|
|
194
|
+
const source = fs__default["default"].readFileSync(filePath, 'utf8');
|
|
195
|
+
frame = codeFrame.codeFrameColumns(source, { start: { line, column } }, { highlightCode: true });
|
|
196
|
+
}
|
|
197
|
+
catch (e) { }
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
frame = inputFrame.join('\n');
|
|
201
|
+
}
|
|
202
|
+
const title = bodyText.trim();
|
|
203
|
+
const baseOffset = ' '.repeat(2);
|
|
204
|
+
const offset = baseOffset.repeat(deep);
|
|
205
|
+
const titleOffset = offset + baseOffset + baseOffset;
|
|
206
|
+
let hiddenCount = 0;
|
|
207
|
+
let collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
208
|
+
const stack = hide
|
|
209
|
+
? bodyStack.slice(1).reduce((cur, line) => {
|
|
210
|
+
if (line.includes('node_modules')) {
|
|
211
|
+
if (cur.at(-1) === collapse) {
|
|
212
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
213
|
+
return [
|
|
214
|
+
...cur.slice(0, -1),
|
|
215
|
+
collapse,
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
219
|
+
return [...cur, collapse];
|
|
220
|
+
}
|
|
221
|
+
hiddenCount = 0;
|
|
222
|
+
collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
223
|
+
return [...cur, line];
|
|
224
|
+
}, [])
|
|
225
|
+
: bodyStack.slice(1);
|
|
226
|
+
return [
|
|
227
|
+
chalk__default["default"].red(`${titleOffset}${title}`),
|
|
228
|
+
bodyStack[0],
|
|
229
|
+
frame && `${offset}${frame.replaceAll('\n', `\n${offset}`)}`,
|
|
230
|
+
...stack
|
|
231
|
+
.filter(line => line.trim() !== '}')
|
|
232
|
+
.map(line => line.includes('node_modules') ? chalk__default["default"].gray(line) : line),
|
|
233
|
+
printErrorWithFrame(inputCauses.join('\n'), deep + 1, hide),
|
|
234
|
+
].filter(Boolean).join('\n');
|
|
235
|
+
}
|
|
170
236
|
const scriptExtensions = ['ts', 'js', 'tsx', 'jsx'];
|
|
171
237
|
const indexExt = scriptExtensions.join(',');
|
|
172
238
|
class InnetJS {
|
|
@@ -359,7 +425,7 @@ class InnetJS {
|
|
|
359
425
|
}
|
|
360
426
|
});
|
|
361
427
|
}
|
|
362
|
-
start({ node = false, inject = false, error = false, index = 'index', } = {}) {
|
|
428
|
+
start({ node = false, inject = false, error = false, usualConsoleOutput = false, index = 'index', } = {}) {
|
|
363
429
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
364
430
|
const pkg = yield this.getPackage();
|
|
365
431
|
const input = glob__default["default"].sync(`src/${index}.{${indexExt}}`);
|
|
@@ -411,7 +477,7 @@ class InnetJS {
|
|
|
411
477
|
options.plugins.push(pluginNodeResolve.nodeResolve(), string({
|
|
412
478
|
include: '**/*.*',
|
|
413
479
|
exclude: stringExcludeNode,
|
|
414
|
-
}), this.createServer(input));
|
|
480
|
+
}), this.createServer(input, error, usualConsoleOutput));
|
|
415
481
|
}
|
|
416
482
|
else {
|
|
417
483
|
const key = path__default["default"].basename(this.sslKey) !== this.sslKey
|
|
@@ -804,17 +870,34 @@ class InnetJS {
|
|
|
804
870
|
}),
|
|
805
871
|
};
|
|
806
872
|
}
|
|
807
|
-
createServer(input) {
|
|
873
|
+
createServer(input, error = false, usualConsoleOutput = false) {
|
|
808
874
|
const apps = {};
|
|
809
875
|
return {
|
|
810
876
|
name: 'server',
|
|
811
877
|
writeBundle: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
812
878
|
var _a;
|
|
813
879
|
for (const file of input) {
|
|
880
|
+
let stderrBuffer = '';
|
|
814
881
|
const { name } = path__default["default"].parse(file);
|
|
815
882
|
(_a = apps[name]) === null || _a === void 0 ? void 0 : _a.kill();
|
|
816
883
|
const filePath = path__default["default"].resolve(this.devBuildFolder, `${name}.js`);
|
|
817
|
-
|
|
884
|
+
if (usualConsoleOutput) {
|
|
885
|
+
apps[name] = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const child = spawn('node', ['-r', 'source-map-support/register', filePath], {
|
|
889
|
+
stdio: ['inherit', 'inherit'],
|
|
890
|
+
});
|
|
891
|
+
apps[name] = child;
|
|
892
|
+
child.stderr.on('data', (chunk) => {
|
|
893
|
+
stderrBuffer += chunk.toString();
|
|
894
|
+
});
|
|
895
|
+
child.on('close', (code) => {
|
|
896
|
+
if (code !== 0 && stderrBuffer) {
|
|
897
|
+
console.error(printErrorWithFrame(stderrBuffer, 0, !error));
|
|
898
|
+
stderrBuffer = '';
|
|
899
|
+
}
|
|
900
|
+
});
|
|
818
901
|
}
|
|
819
902
|
}),
|
|
820
903
|
};
|
|
@@ -822,7 +905,7 @@ class InnetJS {
|
|
|
822
905
|
}
|
|
823
906
|
|
|
824
907
|
(function () {
|
|
825
|
-
const env = {"__INNETJS__PACKAGE_VERSION":"3.
|
|
908
|
+
const env = {"__INNETJS__PACKAGE_VERSION":"3.2.1"};
|
|
826
909
|
if (typeof process === 'undefined') {
|
|
827
910
|
globalThis.process = { env: env };
|
|
828
911
|
} else if (process.env) {
|
|
@@ -867,11 +950,12 @@ commander.program
|
|
|
867
950
|
.command('start')
|
|
868
951
|
.description('Start development with innet boilerplate')
|
|
869
952
|
.option('-n, --node', 'Start development for Node.js')
|
|
953
|
+
.option('-uco, --usual-console-output', 'Removes custom error output (code-frame, colors...)')
|
|
870
954
|
.option('-in, --inject', 'Injects script element into index.html')
|
|
871
955
|
.option('-i, --index <index>', 'Root index file name', 'index')
|
|
872
956
|
.addOption(errorOption)
|
|
873
|
-
.action(({ error, node, index, inject }) => {
|
|
874
|
-
innetJS.start({ node, error, index, inject }).catch(e => {
|
|
957
|
+
.action(({ error, node, index, inject, usualConsoleOutput }) => {
|
|
958
|
+
innetJS.start({ node, error, index, inject, usualConsoleOutput }).catch(e => {
|
|
875
959
|
if (error) {
|
|
876
960
|
console.error(e);
|
|
877
961
|
process.exit(1);
|
package/index.d.ts
CHANGED
|
@@ -62,10 +62,11 @@ export declare class InnetJS {
|
|
|
62
62
|
inject?: boolean;
|
|
63
63
|
index?: string;
|
|
64
64
|
}): Promise<void>;
|
|
65
|
-
start({ node, inject, error, index, }?: {
|
|
65
|
+
start({ node, inject, error, usualConsoleOutput, index, }?: {
|
|
66
66
|
node?: boolean;
|
|
67
67
|
inject?: boolean;
|
|
68
68
|
error?: boolean;
|
|
69
|
+
usualConsoleOutput?: boolean;
|
|
69
70
|
index?: string;
|
|
70
71
|
}): Promise<void>;
|
|
71
72
|
run(file: any, { config, exposeGc }?: {
|
|
@@ -79,5 +80,5 @@ export declare class InnetJS {
|
|
|
79
80
|
increaseVersion(release: string): Promise<void>;
|
|
80
81
|
getPackage(): Promise<Record<string, any>>;
|
|
81
82
|
createClient(key: any, cert: any, pkg: any, index: string, inject: boolean): rollup.Plugin;
|
|
82
|
-
createServer(input: string[]): rollup.Plugin;
|
|
83
|
+
createServer(input: string[], error?: boolean, usualConsoleOutput?: boolean): rollup.Plugin;
|
|
83
84
|
}
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
require('./_virtual/_rollup-plugin-process-env.js');
|
|
6
6
|
var tslib = require('tslib');
|
|
7
|
+
var codeFrame = require('@babel/code-frame');
|
|
7
8
|
var logger = require('@cantinc/logger');
|
|
8
9
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
9
10
|
var eslint = require('@rollup/plugin-eslint');
|
|
@@ -95,6 +96,71 @@ function getNpmTag(version) {
|
|
|
95
96
|
const match = version.match(NPM_TAG);
|
|
96
97
|
return match ? match[1] : 'latest';
|
|
97
98
|
}
|
|
99
|
+
function printErrorWithFrame(output, deep = 0, hide = false) {
|
|
100
|
+
var _a, _b, _c, _d, _e;
|
|
101
|
+
if (!output)
|
|
102
|
+
return '';
|
|
103
|
+
const input = output.split('\n');
|
|
104
|
+
const start = input.findIndex(line => line.trim().startsWith(deep ? '[cause]: Error:' : 'Error:'));
|
|
105
|
+
if (!~start)
|
|
106
|
+
return output;
|
|
107
|
+
const inputFrame = input.slice(0, start);
|
|
108
|
+
const end = input.slice(start + 1).findIndex(line => line.trim().startsWith('[cause]: Error:'));
|
|
109
|
+
const inputBody = input.slice(start, ~end ? start + end - 1 : undefined);
|
|
110
|
+
const inputCauses = ~end ? input.slice(start + end - 1) : [];
|
|
111
|
+
const bodyStackStart = inputBody.findIndex(line => line.trim().startsWith('at '));
|
|
112
|
+
const bodyText = ~bodyStackStart ? inputBody.slice(0, bodyStackStart).join('\n') : inputBody.join('\n');
|
|
113
|
+
const bodyStack = ~bodyStackStart ? inputBody.slice(bodyStackStart) : [];
|
|
114
|
+
const filePathWithNumber = bodyStack.length ? (_a = bodyStack[0].match(/\(([^(]+)\)$/)) === null || _a === void 0 ? void 0 : _a[1] : undefined;
|
|
115
|
+
const splitFilePath = (_b = filePathWithNumber === null || filePathWithNumber === void 0 ? void 0 : filePathWithNumber.split(':')) !== null && _b !== void 0 ? _b : [];
|
|
116
|
+
const filePath = (_c = splitFilePath[0]) === null || _c === void 0 ? void 0 : _c.trim();
|
|
117
|
+
const line = Number((_d = splitFilePath[1]) !== null && _d !== void 0 ? _d : 1);
|
|
118
|
+
const column = Number((_e = splitFilePath[2]) !== null && _e !== void 0 ? _e : 1);
|
|
119
|
+
let frame = '';
|
|
120
|
+
if (filePath && !filePath.includes('node_modules')) {
|
|
121
|
+
try {
|
|
122
|
+
const source = fs__default["default"].readFileSync(filePath, 'utf8');
|
|
123
|
+
frame = codeFrame.codeFrameColumns(source, { start: { line, column } }, { highlightCode: true });
|
|
124
|
+
}
|
|
125
|
+
catch (e) { }
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
frame = inputFrame.join('\n');
|
|
129
|
+
}
|
|
130
|
+
const title = bodyText.trim();
|
|
131
|
+
const baseOffset = ' '.repeat(2);
|
|
132
|
+
const offset = baseOffset.repeat(deep);
|
|
133
|
+
const titleOffset = offset + baseOffset + baseOffset;
|
|
134
|
+
let hiddenCount = 0;
|
|
135
|
+
let collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
136
|
+
const stack = hide
|
|
137
|
+
? bodyStack.slice(1).reduce((cur, line) => {
|
|
138
|
+
if (line.includes('node_modules')) {
|
|
139
|
+
if (cur.at(-1) === collapse) {
|
|
140
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
141
|
+
return [
|
|
142
|
+
...cur.slice(0, -1),
|
|
143
|
+
collapse,
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
147
|
+
return [...cur, collapse];
|
|
148
|
+
}
|
|
149
|
+
hiddenCount = 0;
|
|
150
|
+
collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
151
|
+
return [...cur, line];
|
|
152
|
+
}, [])
|
|
153
|
+
: bodyStack.slice(1);
|
|
154
|
+
return [
|
|
155
|
+
chalk__default["default"].red(`${titleOffset}${title}`),
|
|
156
|
+
bodyStack[0],
|
|
157
|
+
frame && `${offset}${frame.replaceAll('\n', `\n${offset}`)}`,
|
|
158
|
+
...stack
|
|
159
|
+
.filter(line => line.trim() !== '}')
|
|
160
|
+
.map(line => line.includes('node_modules') ? chalk__default["default"].gray(line) : line),
|
|
161
|
+
printErrorWithFrame(inputCauses.join('\n'), deep + 1, hide),
|
|
162
|
+
].filter(Boolean).join('\n');
|
|
163
|
+
}
|
|
98
164
|
const scriptExtensions = ['ts', 'js', 'tsx', 'jsx'];
|
|
99
165
|
const indexExt = scriptExtensions.join(',');
|
|
100
166
|
class InnetJS {
|
|
@@ -287,7 +353,7 @@ class InnetJS {
|
|
|
287
353
|
}
|
|
288
354
|
});
|
|
289
355
|
}
|
|
290
|
-
start({ node = false, inject = false, error = false, index = 'index', } = {}) {
|
|
356
|
+
start({ node = false, inject = false, error = false, usualConsoleOutput = false, index = 'index', } = {}) {
|
|
291
357
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
292
358
|
const pkg = yield this.getPackage();
|
|
293
359
|
const input = glob__default["default"].sync(`src/${index}.{${indexExt}}`);
|
|
@@ -339,7 +405,7 @@ class InnetJS {
|
|
|
339
405
|
options.plugins.push(pluginNodeResolve.nodeResolve(), string({
|
|
340
406
|
include: '**/*.*',
|
|
341
407
|
exclude: constants.stringExcludeNode,
|
|
342
|
-
}), this.createServer(input));
|
|
408
|
+
}), this.createServer(input, error, usualConsoleOutput));
|
|
343
409
|
}
|
|
344
410
|
else {
|
|
345
411
|
const key = path__default["default"].basename(this.sslKey) !== this.sslKey
|
|
@@ -732,17 +798,34 @@ class InnetJS {
|
|
|
732
798
|
}),
|
|
733
799
|
};
|
|
734
800
|
}
|
|
735
|
-
createServer(input) {
|
|
801
|
+
createServer(input, error = false, usualConsoleOutput = false) {
|
|
736
802
|
const apps = {};
|
|
737
803
|
return {
|
|
738
804
|
name: 'server',
|
|
739
805
|
writeBundle: () => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
740
806
|
var _a;
|
|
741
807
|
for (const file of input) {
|
|
808
|
+
let stderrBuffer = '';
|
|
742
809
|
const { name } = path__default["default"].parse(file);
|
|
743
810
|
(_a = apps[name]) === null || _a === void 0 ? void 0 : _a.kill();
|
|
744
811
|
const filePath = path__default["default"].resolve(this.devBuildFolder, `${name}.js`);
|
|
745
|
-
|
|
812
|
+
if (usualConsoleOutput) {
|
|
813
|
+
apps[name] = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const child = spawn('node', ['-r', 'source-map-support/register', filePath], {
|
|
817
|
+
stdio: ['inherit', 'inherit'],
|
|
818
|
+
});
|
|
819
|
+
apps[name] = child;
|
|
820
|
+
child.stderr.on('data', (chunk) => {
|
|
821
|
+
stderrBuffer += chunk.toString();
|
|
822
|
+
});
|
|
823
|
+
child.on('close', (code) => {
|
|
824
|
+
if (code !== 0 && stderrBuffer) {
|
|
825
|
+
console.error(printErrorWithFrame(stderrBuffer, 0, !error));
|
|
826
|
+
stderrBuffer = '';
|
|
827
|
+
}
|
|
828
|
+
});
|
|
746
829
|
}
|
|
747
830
|
}),
|
|
748
831
|
};
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './_virtual/_rollup-plugin-process-env.mjs';
|
|
2
2
|
import { __awaiter } from 'tslib';
|
|
3
|
+
import { codeFrameColumns } from '@babel/code-frame';
|
|
3
4
|
import logger from '@cantinc/logger';
|
|
4
5
|
import commonjs from '@rollup/plugin-commonjs';
|
|
5
6
|
import eslint from '@rollup/plugin-eslint';
|
|
@@ -58,6 +59,71 @@ function getNpmTag(version) {
|
|
|
58
59
|
const match = version.match(NPM_TAG);
|
|
59
60
|
return match ? match[1] : 'latest';
|
|
60
61
|
}
|
|
62
|
+
function printErrorWithFrame(output, deep = 0, hide = false) {
|
|
63
|
+
var _a, _b, _c, _d, _e;
|
|
64
|
+
if (!output)
|
|
65
|
+
return '';
|
|
66
|
+
const input = output.split('\n');
|
|
67
|
+
const start = input.findIndex(line => line.trim().startsWith(deep ? '[cause]: Error:' : 'Error:'));
|
|
68
|
+
if (!~start)
|
|
69
|
+
return output;
|
|
70
|
+
const inputFrame = input.slice(0, start);
|
|
71
|
+
const end = input.slice(start + 1).findIndex(line => line.trim().startsWith('[cause]: Error:'));
|
|
72
|
+
const inputBody = input.slice(start, ~end ? start + end - 1 : undefined);
|
|
73
|
+
const inputCauses = ~end ? input.slice(start + end - 1) : [];
|
|
74
|
+
const bodyStackStart = inputBody.findIndex(line => line.trim().startsWith('at '));
|
|
75
|
+
const bodyText = ~bodyStackStart ? inputBody.slice(0, bodyStackStart).join('\n') : inputBody.join('\n');
|
|
76
|
+
const bodyStack = ~bodyStackStart ? inputBody.slice(bodyStackStart) : [];
|
|
77
|
+
const filePathWithNumber = bodyStack.length ? (_a = bodyStack[0].match(/\(([^(]+)\)$/)) === null || _a === void 0 ? void 0 : _a[1] : undefined;
|
|
78
|
+
const splitFilePath = (_b = filePathWithNumber === null || filePathWithNumber === void 0 ? void 0 : filePathWithNumber.split(':')) !== null && _b !== void 0 ? _b : [];
|
|
79
|
+
const filePath = (_c = splitFilePath[0]) === null || _c === void 0 ? void 0 : _c.trim();
|
|
80
|
+
const line = Number((_d = splitFilePath[1]) !== null && _d !== void 0 ? _d : 1);
|
|
81
|
+
const column = Number((_e = splitFilePath[2]) !== null && _e !== void 0 ? _e : 1);
|
|
82
|
+
let frame = '';
|
|
83
|
+
if (filePath && !filePath.includes('node_modules')) {
|
|
84
|
+
try {
|
|
85
|
+
const source = fs.readFileSync(filePath, 'utf8');
|
|
86
|
+
frame = codeFrameColumns(source, { start: { line, column } }, { highlightCode: true });
|
|
87
|
+
}
|
|
88
|
+
catch (e) { }
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
frame = inputFrame.join('\n');
|
|
92
|
+
}
|
|
93
|
+
const title = bodyText.trim();
|
|
94
|
+
const baseOffset = ' '.repeat(2);
|
|
95
|
+
const offset = baseOffset.repeat(deep);
|
|
96
|
+
const titleOffset = offset + baseOffset + baseOffset;
|
|
97
|
+
let hiddenCount = 0;
|
|
98
|
+
let collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
99
|
+
const stack = hide
|
|
100
|
+
? bodyStack.slice(1).reduce((cur, line) => {
|
|
101
|
+
if (line.includes('node_modules')) {
|
|
102
|
+
if (cur.at(-1) === collapse) {
|
|
103
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
104
|
+
return [
|
|
105
|
+
...cur.slice(0, -1),
|
|
106
|
+
collapse,
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
collapse = collapse.replace(`${hiddenCount} more`, `${++hiddenCount} more`);
|
|
110
|
+
return [...cur, collapse];
|
|
111
|
+
}
|
|
112
|
+
hiddenCount = 0;
|
|
113
|
+
collapse = titleOffset + 'at ... (0 more node_modules calls)';
|
|
114
|
+
return [...cur, line];
|
|
115
|
+
}, [])
|
|
116
|
+
: bodyStack.slice(1);
|
|
117
|
+
return [
|
|
118
|
+
chalk.red(`${titleOffset}${title}`),
|
|
119
|
+
bodyStack[0],
|
|
120
|
+
frame && `${offset}${frame.replaceAll('\n', `\n${offset}`)}`,
|
|
121
|
+
...stack
|
|
122
|
+
.filter(line => line.trim() !== '}')
|
|
123
|
+
.map(line => line.includes('node_modules') ? chalk.gray(line) : line),
|
|
124
|
+
printErrorWithFrame(inputCauses.join('\n'), deep + 1, hide),
|
|
125
|
+
].filter(Boolean).join('\n');
|
|
126
|
+
}
|
|
61
127
|
const scriptExtensions = ['ts', 'js', 'tsx', 'jsx'];
|
|
62
128
|
const indexExt = scriptExtensions.join(',');
|
|
63
129
|
class InnetJS {
|
|
@@ -250,7 +316,7 @@ class InnetJS {
|
|
|
250
316
|
}
|
|
251
317
|
});
|
|
252
318
|
}
|
|
253
|
-
start({ node = false, inject = false, error = false, index = 'index', } = {}) {
|
|
319
|
+
start({ node = false, inject = false, error = false, usualConsoleOutput = false, index = 'index', } = {}) {
|
|
254
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
255
321
|
const pkg = yield this.getPackage();
|
|
256
322
|
const input = glob.sync(`src/${index}.{${indexExt}}`);
|
|
@@ -302,7 +368,7 @@ class InnetJS {
|
|
|
302
368
|
options.plugins.push(nodeResolve(), string({
|
|
303
369
|
include: '**/*.*',
|
|
304
370
|
exclude: stringExcludeNode,
|
|
305
|
-
}), this.createServer(input));
|
|
371
|
+
}), this.createServer(input, error, usualConsoleOutput));
|
|
306
372
|
}
|
|
307
373
|
else {
|
|
308
374
|
const key = path.basename(this.sslKey) !== this.sslKey
|
|
@@ -695,17 +761,34 @@ class InnetJS {
|
|
|
695
761
|
}),
|
|
696
762
|
};
|
|
697
763
|
}
|
|
698
|
-
createServer(input) {
|
|
764
|
+
createServer(input, error = false, usualConsoleOutput = false) {
|
|
699
765
|
const apps = {};
|
|
700
766
|
return {
|
|
701
767
|
name: 'server',
|
|
702
768
|
writeBundle: () => __awaiter(this, void 0, void 0, function* () {
|
|
703
769
|
var _a;
|
|
704
770
|
for (const file of input) {
|
|
771
|
+
let stderrBuffer = '';
|
|
705
772
|
const { name } = path.parse(file);
|
|
706
773
|
(_a = apps[name]) === null || _a === void 0 ? void 0 : _a.kill();
|
|
707
774
|
const filePath = path.resolve(this.devBuildFolder, `${name}.js`);
|
|
708
|
-
|
|
775
|
+
if (usualConsoleOutput) {
|
|
776
|
+
apps[name] = spawn('node', ['-r', 'source-map-support/register', filePath], { stdio: 'inherit' });
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const child = spawn('node', ['-r', 'source-map-support/register', filePath], {
|
|
780
|
+
stdio: ['inherit', 'inherit'],
|
|
781
|
+
});
|
|
782
|
+
apps[name] = child;
|
|
783
|
+
child.stderr.on('data', (chunk) => {
|
|
784
|
+
stderrBuffer += chunk.toString();
|
|
785
|
+
});
|
|
786
|
+
child.on('close', (code) => {
|
|
787
|
+
if (code !== 0 && stderrBuffer) {
|
|
788
|
+
console.error(printErrorWithFrame(stderrBuffer, 0, !error));
|
|
789
|
+
stderrBuffer = '';
|
|
790
|
+
}
|
|
791
|
+
});
|
|
709
792
|
}
|
|
710
793
|
}),
|
|
711
794
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "innetjs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "CLI for innet boilerplate",
|
|
5
5
|
"homepage": "https://github.com/d8corp/innetjs",
|
|
6
6
|
"author": "Mikhail Lysikov <d8corp@mail.ru>",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"url": "https://github.com/d8corp/innetjs/issues"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@babel/code-frame": "^7.29.0",
|
|
52
53
|
"@cantinc/logger": "^1.1.0",
|
|
53
54
|
"@rollup/plugin-commonjs": "^24.0.1",
|
|
54
55
|
"@rollup/plugin-eslint": "^9.0.1",
|
|
@@ -86,7 +87,6 @@
|
|
|
86
87
|
"rollup-plugin-styles": "^4.0.0",
|
|
87
88
|
"rollup-plugin-terser": "^7.0.2",
|
|
88
89
|
"sass": "^1.55.0",
|
|
89
|
-
"tmp": "^0.2.1"
|
|
90
|
-
"typescript": "^4.8.4"
|
|
90
|
+
"tmp": "^0.2.1"
|
|
91
91
|
}
|
|
92
92
|
}
|