uni-run 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arg-helper.cjs +29 -18
- package/dist/arg-helper.d.cts +29 -15
- package/dist/arg-helper.d.mts +29 -15
- package/dist/arg-helper.mjs +29 -18
- package/dist/arg.d.cts +54 -30
- package/dist/arg.d.mts +54 -30
- package/dist/execution/index.cjs +53 -29
- package/dist/execution/index.d.cts +3 -1
- package/dist/execution/index.d.mts +3 -1
- package/dist/execution/index.mjs +53 -29
- package/dist/execution/watcher.cjs +16 -20
- package/dist/execution/watcher.d.cts +1 -1
- package/dist/execution/watcher.d.mts +1 -1
- package/dist/execution/watcher.mjs +16 -20
- package/dist/utils/debounce.d.cts +1 -1
- package/dist/utils/debounce.d.mts +1 -1
- package/package.json +8 -9
package/dist/arg.d.mts
CHANGED
|
@@ -22,8 +22,8 @@ export declare const app: NoArg<"uni-run", {
|
|
|
22
22
|
};
|
|
23
23
|
readonly trailingArguments: "--";
|
|
24
24
|
readonly flags: {
|
|
25
|
-
readonly
|
|
26
|
-
aliases: ["
|
|
25
|
+
readonly 'key-reload': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
26
|
+
aliases: ["k"];
|
|
27
27
|
required: true;
|
|
28
28
|
default: true;
|
|
29
29
|
description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
|
|
@@ -32,18 +32,12 @@ export declare const app: NoArg<"uni-run", {
|
|
|
32
32
|
aliases: ["w"];
|
|
33
33
|
required: true;
|
|
34
34
|
default: true;
|
|
35
|
-
description: "Watch for changes";
|
|
35
|
+
description: "Watch for file changes and reload the script";
|
|
36
36
|
}>;
|
|
37
|
-
readonly
|
|
37
|
+
readonly exit: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
38
38
|
required: true;
|
|
39
39
|
default: false;
|
|
40
|
-
description: "
|
|
41
|
-
}>;
|
|
42
|
-
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
43
|
-
aliases: ["c"];
|
|
44
|
-
required: true;
|
|
45
|
-
default: true;
|
|
46
|
-
description: "Clear the console before running the script";
|
|
40
|
+
description: "Exit after code execution, disabling `watch` and `reloadKey`";
|
|
47
41
|
}>;
|
|
48
42
|
readonly delay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
|
|
49
43
|
aliases: ["d"];
|
|
@@ -58,22 +52,35 @@ export declare const app: NoArg<"uni-run", {
|
|
|
58
52
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
59
53
|
description: "Looks for changes only of the given extensions";
|
|
60
54
|
}>;
|
|
55
|
+
readonly focus: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
56
|
+
aliases: ["f"];
|
|
57
|
+
required: true;
|
|
58
|
+
default: never[];
|
|
59
|
+
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
60
|
+
description: "Only watch the given items. `chokidar` syntax";
|
|
61
|
+
}>;
|
|
61
62
|
readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
62
63
|
aliases: ["ig"];
|
|
63
64
|
required: true;
|
|
64
65
|
default: never[];
|
|
65
66
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
66
|
-
description: "
|
|
67
|
+
description: "Exclude the given items. `gitignore` syntax";
|
|
67
68
|
}>;
|
|
68
69
|
readonly bench: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
69
70
|
aliases: ["b"];
|
|
70
71
|
description: "Calculate the execution time";
|
|
71
72
|
}>;
|
|
72
|
-
readonly
|
|
73
|
+
readonly 'bench-prefix': import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
73
74
|
aliases: ["bp"];
|
|
74
75
|
minLength: 1;
|
|
75
76
|
description: "The prefix to show before the execution time";
|
|
76
77
|
}>;
|
|
78
|
+
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
79
|
+
aliases: ["c"];
|
|
80
|
+
required: true;
|
|
81
|
+
default: true;
|
|
82
|
+
description: "Clear the console before running the script";
|
|
83
|
+
}>;
|
|
77
84
|
readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
78
85
|
required: true;
|
|
79
86
|
default: string;
|
|
@@ -84,6 +91,11 @@ export declare const app: NoArg<"uni-run", {
|
|
|
84
91
|
default: false;
|
|
85
92
|
description: "Run the script in a shell for more low-level control";
|
|
86
93
|
}>;
|
|
94
|
+
readonly 'safe-stdin': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
95
|
+
required: true;
|
|
96
|
+
default: false;
|
|
97
|
+
description: "Disable raw mode for stdin (useful for some scripts)";
|
|
98
|
+
}>;
|
|
87
99
|
readonly info: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
88
100
|
required: true;
|
|
89
101
|
default: false;
|
|
@@ -100,7 +112,7 @@ export declare const app: NoArg<"uni-run", {
|
|
|
100
112
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
101
113
|
description: "Environment variables";
|
|
102
114
|
}>;
|
|
103
|
-
readonly
|
|
115
|
+
readonly 'node-dev': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
104
116
|
required: true;
|
|
105
117
|
default: false;
|
|
106
118
|
description: "Set NODE_ENV to \"development\"";
|
|
@@ -108,7 +120,7 @@ export declare const app: NoArg<"uni-run", {
|
|
|
108
120
|
readonly tsn: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
109
121
|
required: true;
|
|
110
122
|
default: false;
|
|
111
|
-
description: "Run the script with ts-node";
|
|
123
|
+
description: "Run the script with ts-node (TypeScript)";
|
|
112
124
|
}>;
|
|
113
125
|
};
|
|
114
126
|
readonly customRenderHelp: {
|
|
@@ -133,8 +145,8 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
133
145
|
};
|
|
134
146
|
readonly trailingArguments: "--";
|
|
135
147
|
readonly flags: {
|
|
136
|
-
readonly
|
|
137
|
-
aliases: ["
|
|
148
|
+
readonly 'key-reload': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
149
|
+
aliases: ["k"];
|
|
138
150
|
required: true;
|
|
139
151
|
default: true;
|
|
140
152
|
description: "Reload the page when pressing 'Ctrl+R' or 'F5'";
|
|
@@ -143,18 +155,12 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
143
155
|
aliases: ["w"];
|
|
144
156
|
required: true;
|
|
145
157
|
default: true;
|
|
146
|
-
description: "Watch for changes";
|
|
158
|
+
description: "Watch for file changes and reload the script";
|
|
147
159
|
}>;
|
|
148
|
-
readonly
|
|
160
|
+
readonly exit: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
149
161
|
required: true;
|
|
150
162
|
default: false;
|
|
151
|
-
description: "
|
|
152
|
-
}>;
|
|
153
|
-
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
154
|
-
aliases: ["c"];
|
|
155
|
-
required: true;
|
|
156
|
-
default: true;
|
|
157
|
-
description: "Clear the console before running the script";
|
|
163
|
+
description: "Exit after code execution, disabling `watch` and `reloadKey`";
|
|
158
164
|
}>;
|
|
159
165
|
readonly delay: import("noarg/dist/schema/TypeNumber.cjs").TypeNumber<{
|
|
160
166
|
aliases: ["d"];
|
|
@@ -169,22 +175,35 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
169
175
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
170
176
|
description: "Looks for changes only of the given extensions";
|
|
171
177
|
}>;
|
|
178
|
+
readonly focus: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
179
|
+
aliases: ["f"];
|
|
180
|
+
required: true;
|
|
181
|
+
default: never[];
|
|
182
|
+
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
183
|
+
description: "Only watch the given items. `chokidar` syntax";
|
|
184
|
+
}>;
|
|
172
185
|
readonly ignore: import("noarg/dist/schema/TypeArray.cjs").TypeArray<{
|
|
173
186
|
aliases: ["ig"];
|
|
174
187
|
required: true;
|
|
175
188
|
default: never[];
|
|
176
189
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
177
|
-
description: "
|
|
190
|
+
description: "Exclude the given items. `gitignore` syntax";
|
|
178
191
|
}>;
|
|
179
192
|
readonly bench: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
180
193
|
aliases: ["b"];
|
|
181
194
|
description: "Calculate the execution time";
|
|
182
195
|
}>;
|
|
183
|
-
readonly
|
|
196
|
+
readonly 'bench-prefix': import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
184
197
|
aliases: ["bp"];
|
|
185
198
|
minLength: 1;
|
|
186
199
|
description: "The prefix to show before the execution time";
|
|
187
200
|
}>;
|
|
201
|
+
readonly clear: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
202
|
+
aliases: ["c"];
|
|
203
|
+
required: true;
|
|
204
|
+
default: true;
|
|
205
|
+
description: "Clear the console before running the script";
|
|
206
|
+
}>;
|
|
188
207
|
readonly cwd: import("noarg/dist/schema/TypeString.cjs").TypeString<{
|
|
189
208
|
required: true;
|
|
190
209
|
default: string;
|
|
@@ -195,6 +214,11 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
195
214
|
default: false;
|
|
196
215
|
description: "Run the script in a shell for more low-level control";
|
|
197
216
|
}>;
|
|
217
|
+
readonly 'safe-stdin': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
218
|
+
required: true;
|
|
219
|
+
default: false;
|
|
220
|
+
description: "Disable raw mode for stdin (useful for some scripts)";
|
|
221
|
+
}>;
|
|
198
222
|
readonly info: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
199
223
|
required: true;
|
|
200
224
|
default: false;
|
|
@@ -211,7 +235,7 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
211
235
|
schema: import("noarg/dist/schema/TypeString.cjs").TypeString<{}>;
|
|
212
236
|
description: "Environment variables";
|
|
213
237
|
}>;
|
|
214
|
-
readonly
|
|
238
|
+
readonly 'node-dev': import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
215
239
|
required: true;
|
|
216
240
|
default: false;
|
|
217
241
|
description: "Set NODE_ENV to \"development\"";
|
|
@@ -219,7 +243,7 @@ export declare const exec: import("noarg/dist/NoArg/NoArgProgram.cjs").NoArgProg
|
|
|
219
243
|
readonly tsn: import("noarg/dist/schema/TypeBoolean.cjs").TypeBoolean<{
|
|
220
244
|
required: true;
|
|
221
245
|
default: false;
|
|
222
|
-
description: "Run the script with ts-node";
|
|
246
|
+
description: "Run the script with ts-node (TypeScript)";
|
|
223
247
|
}>;
|
|
224
248
|
};
|
|
225
249
|
readonly customRenderHelp: {
|
package/dist/execution/index.cjs
CHANGED
|
@@ -42,8 +42,9 @@ class Execution {
|
|
|
42
42
|
this.child = null;
|
|
43
43
|
this.benchMarkText = colors_1.default.dim.blue('> Execution time');
|
|
44
44
|
this.isBenchmarkRunning = false;
|
|
45
|
+
this.isExecutionExecutedAnyTime = false;
|
|
45
46
|
this.setup();
|
|
46
|
-
this.
|
|
47
|
+
this.startProcess();
|
|
47
48
|
}
|
|
48
49
|
setup() {
|
|
49
50
|
var _a, _b;
|
|
@@ -53,60 +54,48 @@ class Execution {
|
|
|
53
54
|
}
|
|
54
55
|
if (this.options.keystrokeReload) {
|
|
55
56
|
readline.emitKeypressEvents(process.stdin);
|
|
56
|
-
|
|
57
|
+
if (!this.options.stdinSafeMode) {
|
|
58
|
+
(_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
|
|
59
|
+
}
|
|
57
60
|
process.stdin.on('keypress', (_, key) => {
|
|
58
61
|
if (key.name === 'f5' || (key.ctrl && key.name === 'r')) {
|
|
59
|
-
return this.
|
|
62
|
+
return this.startProcess();
|
|
60
63
|
}
|
|
61
64
|
if (key.ctrl && key.name === 'c') {
|
|
62
65
|
this.killProcess();
|
|
63
|
-
|
|
66
|
+
process.exit(0);
|
|
64
67
|
}
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
if (this.options.watch) {
|
|
68
|
-
(0, watcher_1.default)(this.options.cwd, {
|
|
71
|
+
(0, watcher_1.default)(this.options.cwd, this.options.watchFocus, () => this.startProcess(), {
|
|
69
72
|
ignore: this.options.watchIgnore,
|
|
70
73
|
debounceDelay: this.options.watchDelay,
|
|
71
74
|
extensions: new Set(this.options.watchExtensions),
|
|
72
|
-
}
|
|
75
|
+
});
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
startProcess() {
|
|
76
79
|
this.killProcess();
|
|
77
80
|
this.clearBeforeStart();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (this.options.benchmark) {
|
|
82
|
-
if (this.isBenchmarkRunning) {
|
|
83
|
-
console.timeEnd(this.benchMarkText);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.isBenchmarkRunning = true;
|
|
87
|
-
}
|
|
88
|
-
console.time(this.benchMarkText);
|
|
89
|
-
}
|
|
81
|
+
this.renderInfoLogs();
|
|
82
|
+
const controller = new AbortController();
|
|
83
|
+
this.isExecutionExecutedAnyTime = true;
|
|
90
84
|
this.child = (0, cross_spawn_1.spawn)(this.command, this.args, {
|
|
91
85
|
stdio: 'inherit',
|
|
92
86
|
argv0: this.command,
|
|
93
87
|
cwd: this.options.cwd,
|
|
94
88
|
shell: this.options.shell,
|
|
95
89
|
env: Object.assign({}, this.options.env),
|
|
90
|
+
signal: controller.signal,
|
|
96
91
|
});
|
|
97
|
-
this.child.on('error', console.error);
|
|
98
92
|
this.child.on('exit', (code) => {
|
|
99
93
|
if (code && code > 0) {
|
|
100
94
|
console.log(colors_1.default.red(`Process exited with code: ${colors_1.default.yellow(String(code))}`));
|
|
101
95
|
}
|
|
102
|
-
if (this.
|
|
103
|
-
this.isBenchmarkRunning = false;
|
|
96
|
+
if (this.isBenchmarkRunning) {
|
|
104
97
|
console.timeEnd(this.benchMarkText);
|
|
105
|
-
|
|
106
|
-
if (this.options.watch && this.options.showInfo) {
|
|
107
|
-
console.log(colors_1.default.dim.blue('> Watching for extensions:'), colors_1.default.dim(this.options.watchExtensions
|
|
108
|
-
.map((ext) => colors_1.default.yellow(ext))
|
|
109
|
-
.join(', ') || colors_1.default.yellow('*')));
|
|
98
|
+
this.isBenchmarkRunning = false;
|
|
110
99
|
}
|
|
111
100
|
if (this.options.keystrokeReload) {
|
|
112
101
|
console.log(colors_1.default.blue.dim(`> Press ${colors_1.default.yellow('F5')} or ${colors_1.default.yellow('^R')} to reload...`));
|
|
@@ -117,8 +106,9 @@ class Execution {
|
|
|
117
106
|
if (!this.child)
|
|
118
107
|
return;
|
|
119
108
|
this.child.removeAllListeners();
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
const isKilled = (0, kill_process_1.default)(this.child);
|
|
110
|
+
if (!isKilled) {
|
|
111
|
+
console.error(colors_1.default.bgRed('ERROR:'), colors_1.default.red('Failed to kill the previous process'));
|
|
122
112
|
}
|
|
123
113
|
this.child = null;
|
|
124
114
|
}
|
|
@@ -128,5 +118,39 @@ class Execution {
|
|
|
128
118
|
console.clear();
|
|
129
119
|
}
|
|
130
120
|
}
|
|
121
|
+
renderInfoLogs() {
|
|
122
|
+
if (this.options.showInfo && !this.isExecutionExecutedAnyTime) {
|
|
123
|
+
if (this.options.watch) {
|
|
124
|
+
console.log(colors_1.default.dim.bgGreen('INFO:'), colors_1.default.green('Watching for extensions:'), colors_1.default.dim(this.options.watchExtensions
|
|
125
|
+
.map((ext) => colors_1.default.reset(ext))
|
|
126
|
+
.join(', ') || colors_1.default.yellow('*')));
|
|
127
|
+
}
|
|
128
|
+
if (this.options.watchFocus.length) {
|
|
129
|
+
console.log(colors_1.default.dim.bgGreen('INFO:'), colors_1.default.green('Watching target:'), colors_1.default.dim(this.options.watchFocus
|
|
130
|
+
.map((ext) => colors_1.default.reset(ext))
|
|
131
|
+
.join(', ') || colors_1.default.yellow('*')));
|
|
132
|
+
}
|
|
133
|
+
if (this.options.watchIgnore.length) {
|
|
134
|
+
console.log(colors_1.default.dim.bgGreen('INFO:'), colors_1.default.green('Watching ignore:'), colors_1.default.dim(this.options.watchIgnore
|
|
135
|
+
.map((ext) => colors_1.default.reset(ext))
|
|
136
|
+
.join(', ') || colors_1.default.yellow('*')));
|
|
137
|
+
}
|
|
138
|
+
if (this.options.shell) {
|
|
139
|
+
console.log(colors_1.default.dim.bgGreen('INFO:'), colors_1.default.green('SHELL mode enabled'));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (this.options.showTime) {
|
|
143
|
+
console.log(colors_1.default.dim.bgGreen('TIME:'), colors_1.default.green(new Date().toLocaleString()));
|
|
144
|
+
}
|
|
145
|
+
if (this.options.benchmark) {
|
|
146
|
+
if (this.isBenchmarkRunning) {
|
|
147
|
+
console.timeEnd(this.benchMarkText);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.isBenchmarkRunning = true;
|
|
151
|
+
}
|
|
152
|
+
console.time(this.benchMarkText);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
131
155
|
}
|
|
132
156
|
exports.default = Execution;
|
|
@@ -6,10 +6,12 @@ export default class Execution {
|
|
|
6
6
|
private child;
|
|
7
7
|
private benchMarkText;
|
|
8
8
|
private isBenchmarkRunning;
|
|
9
|
+
private isExecutionExecutedAnyTime;
|
|
9
10
|
static start([command, ...args]: string[], options: ExecuteOptions): Execution;
|
|
10
11
|
constructor(command: string, args: string[], options: ExecuteOptions);
|
|
11
12
|
private setup;
|
|
12
|
-
private
|
|
13
|
+
private startProcess;
|
|
13
14
|
private killProcess;
|
|
14
15
|
private clearBeforeStart;
|
|
16
|
+
private renderInfoLogs;
|
|
15
17
|
}
|
|
@@ -6,10 +6,12 @@ export default class Execution {
|
|
|
6
6
|
private child;
|
|
7
7
|
private benchMarkText;
|
|
8
8
|
private isBenchmarkRunning;
|
|
9
|
+
private isExecutionExecutedAnyTime;
|
|
9
10
|
static start([command, ...args]: string[], options: ExecuteOptions): Execution;
|
|
10
11
|
constructor(command: string, args: string[], options: ExecuteOptions);
|
|
11
12
|
private setup;
|
|
12
|
-
private
|
|
13
|
+
private startProcess;
|
|
13
14
|
private killProcess;
|
|
14
15
|
private clearBeforeStart;
|
|
16
|
+
private renderInfoLogs;
|
|
15
17
|
}
|
package/dist/execution/index.mjs
CHANGED
|
@@ -14,8 +14,9 @@ export default class Execution {
|
|
|
14
14
|
this.child = null;
|
|
15
15
|
this.benchMarkText = colors.dim.blue('> Execution time');
|
|
16
16
|
this.isBenchmarkRunning = false;
|
|
17
|
+
this.isExecutionExecutedAnyTime = false;
|
|
17
18
|
this.setup();
|
|
18
|
-
this.
|
|
19
|
+
this.startProcess();
|
|
19
20
|
}
|
|
20
21
|
setup() {
|
|
21
22
|
var _a, _b;
|
|
@@ -25,60 +26,48 @@ export default class Execution {
|
|
|
25
26
|
}
|
|
26
27
|
if (this.options.keystrokeReload) {
|
|
27
28
|
readline.emitKeypressEvents(process.stdin);
|
|
28
|
-
|
|
29
|
+
if (!this.options.stdinSafeMode) {
|
|
30
|
+
(_b = (_a = process.stdin).setRawMode) === null || _b === void 0 ? void 0 : _b.call(_a, true);
|
|
31
|
+
}
|
|
29
32
|
process.stdin.on('keypress', (_, key) => {
|
|
30
33
|
if (key.name === 'f5' || (key.ctrl && key.name === 'r')) {
|
|
31
|
-
return this.
|
|
34
|
+
return this.startProcess();
|
|
32
35
|
}
|
|
33
36
|
if (key.ctrl && key.name === 'c') {
|
|
34
37
|
this.killProcess();
|
|
35
|
-
|
|
38
|
+
process.exit(0);
|
|
36
39
|
}
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
if (this.options.watch) {
|
|
40
|
-
watcher(this.options.cwd, {
|
|
43
|
+
watcher(this.options.cwd, this.options.watchFocus, () => this.startProcess(), {
|
|
41
44
|
ignore: this.options.watchIgnore,
|
|
42
45
|
debounceDelay: this.options.watchDelay,
|
|
43
46
|
extensions: new Set(this.options.watchExtensions),
|
|
44
|
-
}
|
|
47
|
+
});
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
startProcess() {
|
|
48
51
|
this.killProcess();
|
|
49
52
|
this.clearBeforeStart();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (this.options.benchmark) {
|
|
54
|
-
if (this.isBenchmarkRunning) {
|
|
55
|
-
console.timeEnd(this.benchMarkText);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
this.isBenchmarkRunning = true;
|
|
59
|
-
}
|
|
60
|
-
console.time(this.benchMarkText);
|
|
61
|
-
}
|
|
53
|
+
this.renderInfoLogs();
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
this.isExecutionExecutedAnyTime = true;
|
|
62
56
|
this.child = spawn(this.command, this.args, {
|
|
63
57
|
stdio: 'inherit',
|
|
64
58
|
argv0: this.command,
|
|
65
59
|
cwd: this.options.cwd,
|
|
66
60
|
shell: this.options.shell,
|
|
67
61
|
env: Object.assign({}, this.options.env),
|
|
62
|
+
signal: controller.signal,
|
|
68
63
|
});
|
|
69
|
-
this.child.on('error', console.error);
|
|
70
64
|
this.child.on('exit', (code) => {
|
|
71
65
|
if (code && code > 0) {
|
|
72
66
|
console.log(colors.red(`Process exited with code: ${colors.yellow(String(code))}`));
|
|
73
67
|
}
|
|
74
|
-
if (this.
|
|
75
|
-
this.isBenchmarkRunning = false;
|
|
68
|
+
if (this.isBenchmarkRunning) {
|
|
76
69
|
console.timeEnd(this.benchMarkText);
|
|
77
|
-
|
|
78
|
-
if (this.options.watch && this.options.showInfo) {
|
|
79
|
-
console.log(colors.dim.blue('> Watching for extensions:'), colors.dim(this.options.watchExtensions
|
|
80
|
-
.map((ext) => colors.yellow(ext))
|
|
81
|
-
.join(', ') || colors.yellow('*')));
|
|
70
|
+
this.isBenchmarkRunning = false;
|
|
82
71
|
}
|
|
83
72
|
if (this.options.keystrokeReload) {
|
|
84
73
|
console.log(colors.blue.dim(`> Press ${colors.yellow('F5')} or ${colors.yellow('^R')} to reload...`));
|
|
@@ -89,8 +78,9 @@ export default class Execution {
|
|
|
89
78
|
if (!this.child)
|
|
90
79
|
return;
|
|
91
80
|
this.child.removeAllListeners();
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
const isKilled = killProcess(this.child);
|
|
82
|
+
if (!isKilled) {
|
|
83
|
+
console.error(colors.bgRed('ERROR:'), colors.red('Failed to kill the previous process'));
|
|
94
84
|
}
|
|
95
85
|
this.child = null;
|
|
96
86
|
}
|
|
@@ -100,4 +90,38 @@ export default class Execution {
|
|
|
100
90
|
console.clear();
|
|
101
91
|
}
|
|
102
92
|
}
|
|
93
|
+
renderInfoLogs() {
|
|
94
|
+
if (this.options.showInfo && !this.isExecutionExecutedAnyTime) {
|
|
95
|
+
if (this.options.watch) {
|
|
96
|
+
console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching for extensions:'), colors.dim(this.options.watchExtensions
|
|
97
|
+
.map((ext) => colors.reset(ext))
|
|
98
|
+
.join(', ') || colors.yellow('*')));
|
|
99
|
+
}
|
|
100
|
+
if (this.options.watchFocus.length) {
|
|
101
|
+
console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching target:'), colors.dim(this.options.watchFocus
|
|
102
|
+
.map((ext) => colors.reset(ext))
|
|
103
|
+
.join(', ') || colors.yellow('*')));
|
|
104
|
+
}
|
|
105
|
+
if (this.options.watchIgnore.length) {
|
|
106
|
+
console.log(colors.dim.bgGreen('INFO:'), colors.green('Watching ignore:'), colors.dim(this.options.watchIgnore
|
|
107
|
+
.map((ext) => colors.reset(ext))
|
|
108
|
+
.join(', ') || colors.yellow('*')));
|
|
109
|
+
}
|
|
110
|
+
if (this.options.shell) {
|
|
111
|
+
console.log(colors.dim.bgGreen('INFO:'), colors.green('SHELL mode enabled'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (this.options.showTime) {
|
|
115
|
+
console.log(colors.dim.bgGreen('TIME:'), colors.green(new Date().toLocaleString()));
|
|
116
|
+
}
|
|
117
|
+
if (this.options.benchmark) {
|
|
118
|
+
if (this.isBenchmarkRunning) {
|
|
119
|
+
console.timeEnd(this.benchMarkText);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.isBenchmarkRunning = true;
|
|
123
|
+
}
|
|
124
|
+
console.time(this.benchMarkText);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
103
127
|
}
|
|
@@ -31,20 +31,22 @@ const path = __importStar(require("path"));
|
|
|
31
31
|
const gitignore_1 = __importDefault(require("./gitignore.cjs"));
|
|
32
32
|
const chokidar = __importStar(require("chokidar"));
|
|
33
33
|
const debounce_1 = require("../utils/debounce.cjs");
|
|
34
|
-
function default_1(
|
|
35
|
-
const ig = (0, gitignore_1.default)(
|
|
34
|
+
function default_1(cwd, targets, callback, options) {
|
|
35
|
+
const ig = (0, gitignore_1.default)(cwd, options.ignore);
|
|
36
36
|
const debounce = (0, debounce_1.createDebounce)(options.debounceDelay);
|
|
37
|
-
const watcher = chokidar.watch(
|
|
37
|
+
const watcher = chokidar.watch(targets, {
|
|
38
38
|
ignored: (filePath) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (options.extensions.size) {
|
|
45
|
-
const ext = path.extname(relativePath).slice(1);
|
|
46
|
-
if (ext && !options.extensions.has(ext))
|
|
39
|
+
for (const target of targets) {
|
|
40
|
+
const relativePath = path.relative(target, filePath);
|
|
41
|
+
if (!relativePath)
|
|
42
|
+
return false;
|
|
43
|
+
if (ig.ignores(relativePath))
|
|
47
44
|
return true;
|
|
45
|
+
if (options.extensions.size) {
|
|
46
|
+
const ext = path.extname(relativePath).slice(1);
|
|
47
|
+
if (ext && !options.extensions.has(ext))
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
51
|
return false;
|
|
50
52
|
},
|
|
@@ -52,13 +54,7 @@ function default_1(dir, options, callback) {
|
|
|
52
54
|
ignoreInitial: true,
|
|
53
55
|
persistent: true,
|
|
54
56
|
});
|
|
55
|
-
watcher.on('add', (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
watcher.on('change', (event) => {
|
|
59
|
-
debounce(() => callback());
|
|
60
|
-
});
|
|
61
|
-
watcher.on('unlink', () => {
|
|
62
|
-
debounce(() => callback());
|
|
63
|
-
});
|
|
57
|
+
watcher.on('add', () => debounce(() => callback()));
|
|
58
|
+
watcher.on('change', () => debounce(() => callback()));
|
|
59
|
+
watcher.on('unlink', () => debounce(() => callback()));
|
|
64
60
|
}
|
|
@@ -3,4 +3,4 @@ export type WatcherOptions = {
|
|
|
3
3
|
extensions: Set<string>;
|
|
4
4
|
debounceDelay: number;
|
|
5
5
|
};
|
|
6
|
-
export default function (
|
|
6
|
+
export default function (cwd: string, targets: string | string[], callback: () => void, options: WatcherOptions): void;
|
|
@@ -3,4 +3,4 @@ export type WatcherOptions = {
|
|
|
3
3
|
extensions: Set<string>;
|
|
4
4
|
debounceDelay: number;
|
|
5
5
|
};
|
|
6
|
-
export default function (
|
|
6
|
+
export default function (cwd: string, targets: string | string[], callback: () => void, options: WatcherOptions): void;
|
|
@@ -2,20 +2,22 @@ import * as path from "path";
|
|
|
2
2
|
import gitignore from "./gitignore.mjs";
|
|
3
3
|
import * as chokidar from "chokidar";
|
|
4
4
|
import { createDebounce } from "../utils/debounce.mjs";
|
|
5
|
-
export default function (
|
|
6
|
-
const ig = gitignore(
|
|
5
|
+
export default function (cwd, targets, callback, options) {
|
|
6
|
+
const ig = gitignore(cwd, options.ignore);
|
|
7
7
|
const debounce = createDebounce(options.debounceDelay);
|
|
8
|
-
const watcher = chokidar.watch(
|
|
8
|
+
const watcher = chokidar.watch(targets, {
|
|
9
9
|
ignored: (filePath) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (options.extensions.size) {
|
|
16
|
-
const ext = path.extname(relativePath).slice(1);
|
|
17
|
-
if (ext && !options.extensions.has(ext))
|
|
10
|
+
for (const target of targets) {
|
|
11
|
+
const relativePath = path.relative(target, filePath);
|
|
12
|
+
if (!relativePath)
|
|
13
|
+
return false;
|
|
14
|
+
if (ig.ignores(relativePath))
|
|
18
15
|
return true;
|
|
16
|
+
if (options.extensions.size) {
|
|
17
|
+
const ext = path.extname(relativePath).slice(1);
|
|
18
|
+
if (ext && !options.extensions.has(ext))
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
return false;
|
|
21
23
|
},
|
|
@@ -23,13 +25,7 @@ export default function (dir, options, callback) {
|
|
|
23
25
|
ignoreInitial: true,
|
|
24
26
|
persistent: true,
|
|
25
27
|
});
|
|
26
|
-
watcher.on('add', (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
watcher.on('change', (event) => {
|
|
30
|
-
debounce(() => callback());
|
|
31
|
-
});
|
|
32
|
-
watcher.on('unlink', () => {
|
|
33
|
-
debounce(() => callback());
|
|
34
|
-
});
|
|
28
|
+
watcher.on('add', () => debounce(() => callback()));
|
|
29
|
+
watcher.on('change', () => debounce(() => callback()));
|
|
30
|
+
watcher.on('unlink', () => debounce(() => callback()));
|
|
35
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createDebounce(delay: number): (fn:
|
|
1
|
+
export declare function createDebounce(delay: number): (fn: () => void) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createDebounce(delay: number): (fn:
|
|
1
|
+
export declare function createDebounce(delay: number): (fn: () => void) => void;
|