sitevision-cli 0.1.1 → 0.1.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.
|
@@ -4,16 +4,8 @@
|
|
|
4
4
|
* Handles webpack compilation for Sitevision apps.
|
|
5
5
|
* Dynamically loads webpack from the target project's node_modules.
|
|
6
6
|
*/
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
8
7
|
import type { BuildOptions, BuildResult } from '../types/index.js';
|
|
9
|
-
|
|
10
|
-
* Events emitted by WebpackRunner:
|
|
11
|
-
* - 'compile': Emitted when compilation starts
|
|
12
|
-
* - 'done': Emitted when compilation completes successfully
|
|
13
|
-
* - 'error': Emitted when compilation fails
|
|
14
|
-
* - 'warning': Emitted when compilation has warnings
|
|
15
|
-
*/
|
|
16
|
-
export declare class WebpackRunner extends EventEmitter {
|
|
8
|
+
export declare class WebpackRunner {
|
|
17
9
|
private projectRoot;
|
|
18
10
|
private options;
|
|
19
11
|
private webpack;
|
|
@@ -7,21 +7,12 @@
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import { createRequire } from 'module';
|
|
10
|
-
import { EventEmitter } from 'events';
|
|
11
10
|
import { copyChunksToResources } from './zip.js';
|
|
12
11
|
// =============================================================================
|
|
13
12
|
// WEBPACK RUNNER CLASS
|
|
14
13
|
// =============================================================================
|
|
15
|
-
|
|
16
|
-
* Events emitted by WebpackRunner:
|
|
17
|
-
* - 'compile': Emitted when compilation starts
|
|
18
|
-
* - 'done': Emitted when compilation completes successfully
|
|
19
|
-
* - 'error': Emitted when compilation fails
|
|
20
|
-
* - 'warning': Emitted when compilation has warnings
|
|
21
|
-
*/
|
|
22
|
-
export class WebpackRunner extends EventEmitter {
|
|
14
|
+
export class WebpackRunner {
|
|
23
15
|
constructor(projectRoot, options) {
|
|
24
|
-
super();
|
|
25
16
|
Object.defineProperty(this, "projectRoot", {
|
|
26
17
|
enumerable: true,
|
|
27
18
|
configurable: true,
|
|
@@ -151,17 +142,14 @@ export class WebpackRunner extends EventEmitter {
|
|
|
151
142
|
throw new Error('Webpack not initialized');
|
|
152
143
|
}
|
|
153
144
|
return new Promise((resolve, reject) => {
|
|
154
|
-
this.emit('compile');
|
|
155
145
|
this.compiler = this.webpack(this.config);
|
|
156
146
|
this.compiler.run((err, stats) => {
|
|
157
147
|
if (err) {
|
|
158
|
-
this.emit('error', err);
|
|
159
148
|
reject(err);
|
|
160
149
|
return;
|
|
161
150
|
}
|
|
162
151
|
if (!stats) {
|
|
163
152
|
const error = new Error('No stats returned from webpack');
|
|
164
|
-
this.emit('error', error);
|
|
165
153
|
reject(error);
|
|
166
154
|
return;
|
|
167
155
|
}
|
|
@@ -176,13 +164,6 @@ export class WebpackRunner extends EventEmitter {
|
|
|
176
164
|
console.warn('Warning: Failed to copy chunks:', chunkError);
|
|
177
165
|
}
|
|
178
166
|
}
|
|
179
|
-
if (stats.hasErrors()) {
|
|
180
|
-
this.emit('error', new Error(stats.toString({ colors: false })));
|
|
181
|
-
}
|
|
182
|
-
else if (stats.hasWarnings()) {
|
|
183
|
-
this.emit('warning', stats.toString({ colors: false }));
|
|
184
|
-
}
|
|
185
|
-
this.emit('done', result);
|
|
186
167
|
resolve(result);
|
|
187
168
|
});
|
|
188
169
|
});
|
|
@@ -204,7 +185,6 @@ export class WebpackRunner extends EventEmitter {
|
|
|
204
185
|
ignored: ['**/dist/**', '**/build/**', '**/node_modules/**'],
|
|
205
186
|
}, (err, stats) => {
|
|
206
187
|
if (err) {
|
|
207
|
-
this.emit('error', err);
|
|
208
188
|
callback?.({
|
|
209
189
|
success: false,
|
|
210
190
|
errors: [err.message],
|
|
@@ -224,13 +204,6 @@ export class WebpackRunner extends EventEmitter {
|
|
|
224
204
|
console.warn('Warning: Failed to copy chunks:', chunkError);
|
|
225
205
|
}
|
|
226
206
|
}
|
|
227
|
-
if (stats.hasErrors()) {
|
|
228
|
-
this.emit('error', new Error(stats.toString({ colors: false })));
|
|
229
|
-
}
|
|
230
|
-
else if (stats.hasWarnings()) {
|
|
231
|
-
this.emit('warning', stats.toString({ colors: false }));
|
|
232
|
-
}
|
|
233
|
-
this.emit('done', result);
|
|
234
207
|
callback?.(result);
|
|
235
208
|
});
|
|
236
209
|
// Resolve immediately - watch continues in background
|