piral-cli 0.15.0-beta.4630 → 0.15.0-beta.4670

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.
Files changed (56) hide show
  1. package/README.md +17 -0
  2. package/lib/apps/build-pilet.js +6 -5
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/build-piral.js +7 -6
  5. package/lib/apps/build-piral.js.map +1 -1
  6. package/lib/apps/debug-pilet.js +130 -109
  7. package/lib/apps/debug-pilet.js.map +1 -1
  8. package/lib/apps/debug-piral.js +58 -52
  9. package/lib/apps/debug-piral.js.map +1 -1
  10. package/lib/apps/publish-pilet.js +3 -3
  11. package/lib/apps/publish-pilet.js.map +1 -1
  12. package/lib/apps/upgrade-pilet.js +5 -8
  13. package/lib/apps/upgrade-pilet.js.map +1 -1
  14. package/lib/build/run-build-pilet.js +4 -4
  15. package/lib/build/run-build-pilet.js.map +1 -1
  16. package/lib/build/run-build-piral.js +3 -3
  17. package/lib/build/run-build-piral.js.map +1 -1
  18. package/lib/build/run-debug-mono-piral.js +3 -3
  19. package/lib/build/run-debug-mono-piral.js.map +1 -1
  20. package/lib/build/run-debug-pilet.js +4 -4
  21. package/lib/build/run-debug-pilet.js.map +1 -1
  22. package/lib/build/run-debug-piral.js +3 -3
  23. package/lib/build/run-debug-piral.js.map +1 -1
  24. package/lib/common/declaration.js +2 -0
  25. package/lib/common/declaration.js.map +1 -1
  26. package/lib/common/envs.js +7 -4
  27. package/lib/common/envs.js.map +1 -1
  28. package/lib/common/index.d.ts +2 -0
  29. package/lib/common/index.js +2 -0
  30. package/lib/common/index.js.map +1 -1
  31. package/lib/common/package.d.ts +0 -4
  32. package/lib/common/package.js +5 -7
  33. package/lib/common/package.js.map +1 -1
  34. package/lib/common/watcher.d.ts +5 -0
  35. package/lib/common/watcher.js +21 -0
  36. package/lib/common/watcher.js.map +1 -0
  37. package/lib/external/index.js +274 -274
  38. package/lib/types/public.d.ts +7 -7
  39. package/package.json +3 -3
  40. package/src/apps/build-pilet.ts +7 -5
  41. package/src/apps/build-piral.ts +7 -6
  42. package/src/apps/debug-pilet.ts +179 -146
  43. package/src/apps/debug-piral.ts +69 -61
  44. package/src/apps/publish-pilet.ts +3 -3
  45. package/src/apps/upgrade-pilet.ts +7 -9
  46. package/src/build/run-build-pilet.ts +4 -4
  47. package/src/build/run-build-piral.ts +3 -3
  48. package/src/build/run-debug-mono-piral.ts +3 -3
  49. package/src/build/run-debug-pilet.ts +5 -4
  50. package/src/build/run-debug-piral.ts +3 -3
  51. package/src/common/declaration.ts +2 -0
  52. package/src/common/envs.ts +6 -4
  53. package/src/common/index.ts +2 -0
  54. package/src/common/package.ts +5 -5
  55. package/src/common/watcher.ts +24 -0
  56. package/src/types/public.ts +7 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "0.15.0-beta.4630",
3
+ "version": "0.15.0-beta.4670",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -73,10 +73,10 @@
73
73
  "dependencies": {
74
74
  "chalk": "^2.4.2",
75
75
  "dets": "^0.12.0",
76
- "kras": "^0.15.0",
76
+ "kras": "^0.15.1",
77
77
  "rimraf": "^3.0.0",
78
78
  "typescript": "^4.7.3",
79
79
  "yargs": "^15.4.1"
80
80
  },
81
- "gitHead": "08aea96af9587e73b1a6c4eb108f94f285186b10"
81
+ "gitHead": "ffd8707600e028a55258028d394b76fe3a0cd175"
82
82
  }
@@ -212,8 +212,8 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
212
212
  targetDir,
213
213
  app,
214
214
  );
215
- const piral = apps[0].appPackage.name;
216
- const externals = combinePiletExternals([piral], peerDependencies, peerModules, importmap);
215
+ const piralInstances = apps.map(m => m.appPackage.name);
216
+ const externals = combinePiletExternals(piralInstances, peerDependencies, peerModules, importmap);
217
217
  const dest = resolve(root, target);
218
218
  const outDir = dirname(dest);
219
219
  const outFile = basename(dest);
@@ -230,7 +230,7 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
230
230
  await callPiletBuild(
231
231
  {
232
232
  root,
233
- piral,
233
+ piralInstances,
234
234
  optimizeModules,
235
235
  sourceMaps,
236
236
  contentHash,
@@ -282,7 +282,9 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
282
282
  const distDir = dirname(resolve(fullBase, target));
283
283
  const outDir = resolve(distDir, 'standalone');
284
284
  const { apps, root } = pilets[0];
285
+
285
286
  const { appPackage, appFile } = apps[0];
287
+ const piralInstances = [appPackage.name];
286
288
  const isEmulator = checkAppShellPackage(appPackage);
287
289
 
288
290
  logInfo('Building standalone solution ...');
@@ -306,7 +308,7 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
306
308
  await callPiralBuild(
307
309
  {
308
310
  root,
309
- piral: appPackage.name,
311
+ piralInstances,
310
312
  emulator: false,
311
313
  standalone: true,
312
314
  optimizeModules: false,
@@ -331,7 +333,7 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
331
333
  await callPiralBuild(
332
334
  {
333
335
  root,
334
- piral: appPackage.name,
336
+ piralInstances,
335
337
  emulator: false,
336
338
  standalone: true,
337
339
  optimizeModules: false,
@@ -156,6 +156,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
156
156
  progress('Reading configuration ...');
157
157
  const entryFiles = await retrievePiralRoot(fullBase, entry);
158
158
  const { name, root, ignored, externals, scripts } = await retrievePiletsInfo(entryFiles);
159
+ const piralInstances = [name];
159
160
  const dest = getDestination(entryFiles, resolve(fullBase, target));
160
161
 
161
162
  await checkCliCompatibility(root);
@@ -174,7 +175,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
174
175
  // since we create this anyway let's just pretend we want to have it clean!
175
176
  await removeDirectory(targetDir);
176
177
 
177
- await hooks.beforeBuild?.({ root, publicUrl: emulatorPublicUrl, externals, entryFiles, targetDir, name });
178
+ await hooks.beforeBuild?.({ root, publicUrl: emulatorPublicUrl, externals, entryFiles, targetDir, piralInstances });
178
179
 
179
180
  logInfo(`Bundle ${emulatorName} ...`);
180
181
  const {
@@ -184,7 +185,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
184
185
  } = await callPiralBuild(
185
186
  {
186
187
  root,
187
- piral: name,
188
+ piralInstances,
188
189
  emulator: true,
189
190
  standalone: false,
190
191
  optimizeModules,
@@ -209,7 +210,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
209
210
  externals,
210
211
  entryFiles,
211
212
  targetDir,
212
- name,
213
+ piralInstances,
213
214
  hash,
214
215
  outDir,
215
216
  outFile,
@@ -246,7 +247,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
246
247
 
247
248
  logInfo(`Bundle ${releaseName} ...`);
248
249
 
249
- await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name });
250
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, piralInstances });
250
251
 
251
252
  const {
252
253
  dir: outDir,
@@ -255,7 +256,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
255
256
  } = await callPiralBuild(
256
257
  {
257
258
  root,
258
- piral: name,
259
+ piralInstances,
259
260
  emulator: false,
260
261
  standalone: false,
261
262
  optimizeModules,
@@ -274,7 +275,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
274
275
  bundlerName,
275
276
  );
276
277
 
277
- await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name, outDir, outFile, hash });
278
+ await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, targetDir, piralInstances, outDir, outFile, hash });
278
279
 
279
280
  await runLifecycle(root, scripts, 'piral:postbuild');
280
281
  await runLifecycle(root, scripts, `piral:postbuild-${releaseName}`);
@@ -1,7 +1,7 @@
1
1
  import { join, dirname, resolve, relative, basename } from 'path';
2
- import { readKrasConfig, krasrc, buildKrasWithCli, defaultConfig } from 'kras';
2
+ import { readKrasConfig, krasrc, buildKrasWithCli } from 'kras';
3
3
  import { callDebugPiralFromMonoRepo, callPiletDebug } from '../bundler';
4
- import { LogLevels, PiletSchemaVersion } from '../types';
4
+ import { AppDefinition, LogLevels, PiletSchemaVersion } from '../types';
5
5
  import {
6
6
  checkExistingDirectory,
7
7
  retrievePiletData,
@@ -22,6 +22,7 @@ import {
22
22
  createInitialKrasConfig,
23
23
  getAvailablePort,
24
24
  combinePiletExternals,
25
+ watcherTask,
25
26
  } from '../common';
26
27
 
27
28
  export interface DebugPiletOptions {
@@ -133,46 +134,60 @@ export const debugPiletDefaults: DebugPiletOptions = {
133
134
  concurrency: cpuCount,
134
135
  };
135
136
 
136
- const injectorName = resolve(__dirname, '../injectors/pilet.js');
137
-
138
137
  interface AppInfo {
139
- emulator: boolean;
140
- appFile: string;
138
+ apps: Array<AppDefinition>;
139
+ root: string;
140
+ mocks: string;
141
141
  publicUrl: string;
142
- appVersion: string;
143
142
  externals: Array<string>;
144
- piral: string;
145
143
  }
146
144
 
147
- async function getOrMakeAppDir({ emulator, piral, appFile, publicUrl }: AppInfo, logLevel: LogLevels) {
148
- if (!emulator) {
149
- const { externals, root, ignored } = await retrievePiletsInfo(appFile);
150
- const { dir } = await callDebugPiralFromMonoRepo({
151
- root,
152
- optimizeModules: false,
153
- publicUrl,
154
- ignored,
155
- externals,
156
- piral,
157
- entryFiles: appFile,
158
- logLevel,
159
- _: {},
160
- });
161
- return dir;
162
- }
163
-
164
- return dirname(appFile);
145
+ function getOrMakeApps({ apps, publicUrl }: AppInfo, logLevel: LogLevels) {
146
+ return Promise.all(
147
+ apps.map(async ({ emulator, appFile, appPackage }) => {
148
+ if (!emulator) {
149
+ const piralInstances = [appPackage.name];
150
+ const { externals, root, ignored } = await retrievePiletsInfo(appFile);
151
+ const { dir } = await callDebugPiralFromMonoRepo({
152
+ root,
153
+ optimizeModules: false,
154
+ publicUrl,
155
+ ignored,
156
+ externals,
157
+ piralInstances,
158
+ entryFiles: appFile,
159
+ logLevel,
160
+ _: {},
161
+ });
162
+ return dir;
163
+ }
164
+
165
+ return dirname(appFile);
166
+ }),
167
+ );
165
168
  }
166
169
 
167
170
  function checkSanity(pilets: Array<AppInfo>) {
168
171
  for (let i = 1; i < pilets.length; i++) {
169
172
  const previous = pilets[i - 1];
170
173
  const current = pilets[i];
171
-
172
- if (previous.piral !== current.piral) {
173
- return log('piletMultiDebugAppShellDifferent_0301', previous.piral, current.piral);
174
- } else if (previous.appVersion !== current.appVersion) {
175
- return log('piletMultiDebugAppShellVersions_0302', previous.appVersion, current.appVersion);
174
+ const previousInstances = previous.apps;
175
+ const currentInstances = current.apps;
176
+ const previousInstancesNames = previousInstances
177
+ .map((m) => m.appPackage.name)
178
+ .sort()
179
+ .join(', ');
180
+ const currentInstancesNames = currentInstances
181
+ .map((m) => m.appPackage.name)
182
+ .sort()
183
+ .join(', ');
184
+ const previousInstancesVersions = previousInstances.map((m) => m.appPackage.version).join(', ');
185
+ const currentInstancesVersions = currentInstances.map((m) => m.appPackage.version).join(', ');
186
+
187
+ if (previousInstancesNames !== currentInstancesNames) {
188
+ return log('piletMultiDebugAppShellDifferent_0301', previousInstancesNames, currentInstancesNames);
189
+ } else if (previousInstancesVersions !== currentInstancesVersions) {
190
+ return log('piletMultiDebugAppShellVersions_0302', previousInstancesVersions, currentInstancesVersions);
176
191
  } else if (previous.externals.length !== current.externals.length) {
177
192
  return log('piletMultiDebugExternalsDifferent_0303', previous.externals, current.externals);
178
193
  } else if (previous.externals.some((m) => !current.externals.includes(m))) {
@@ -202,130 +217,148 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
202
217
  } = options;
203
218
  const publicUrl = normalizePublicUrl(originalPublicUrl);
204
219
  const fullBase = resolve(process.cwd(), baseDir);
220
+ const port = await getAvailablePort(originalPort);
205
221
  setLogLevel(logLevel);
206
222
 
207
223
  await hooks.onBegin?.({ options, fullBase });
208
- progress('Reading configuration ...');
209
- const api = `${publicUrl}${config.piletApi.replace(/^\/+/, '')}`;
210
- const entryList = Array.isArray(entry) ? entry : [entry];
211
- const multi = entryList.length > 1 || entryList[0].indexOf('*') !== -1;
212
- log('generalDebug_0003', `Looking for (${multi ? 'multi' : 'single'}) "${entryList.join('", "')}" in "${fullBase}".`);
213
-
214
- const allEntries = await matchAnyPilet(fullBase, entryList);
215
- const maxListeners = Math.max(2 + allEntries.length * 2, 16);
216
- log('generalDebug_0003', `Found the following entries: ${allEntries.join(', ')}`);
217
-
218
- if (allEntries.length === 0) {
219
- fail('entryFileMissing_0077');
220
- }
221
224
 
222
- process.stderr.setMaxListeners(maxListeners);
223
- process.stdout.setMaxListeners(maxListeners);
224
- process.stdin.setMaxListeners(maxListeners);
225
-
226
- const pilets = await concurrentWorkers(allEntries, concurrency, async (entryModule) => {
227
- const targetDir = dirname(entryModule);
228
- const { peerDependencies, peerModules, root, apps, ignored, importmap } = await retrievePiletData(targetDir, app);
229
- const { appPackage, appFile, emulator } = apps[0];
230
- const piral = appPackage.name;
231
- const externals = combinePiletExternals([piral], peerDependencies, peerModules, importmap);
232
- const mocks = join(targetDir, 'mocks');
233
- const dest = resolve(root, target);
234
- const outDir = dirname(dest);
235
- const outFile = basename(dest);
236
- const mocksExists = await checkExistingDirectory(mocks);
237
-
238
- await hooks.beforeBuild?.({ root, publicUrl, importmap, entryModule, schemaVersion });
239
-
240
- const bundler = await callPiletDebug(
241
- {
242
- root,
243
- piral,
244
- optimizeModules,
245
- hmr,
246
- externals,
247
- targetDir,
248
- importmap,
249
- outFile,
250
- outDir,
251
- entryModule: `./${relative(root, entryModule)}`,
252
- logLevel,
253
- version: schemaVersion,
254
- ignored,
255
- _,
256
- },
257
- bundlerName,
225
+ await watcherTask(async (watcherContext) => {
226
+ progress('Reading configuration ...');
227
+ const api = `${publicUrl}${config.piletApi.replace(/^\/+/, '')}`;
228
+ const entryList = Array.isArray(entry) ? entry : [entry];
229
+ const multi = entryList.length > 1 || entryList[0].indexOf('*') !== -1;
230
+ log(
231
+ 'generalDebug_0003',
232
+ `Looking for (${multi ? 'multi' : 'single'}) "${entryList.join('", "')}" in "${fullBase}".`,
258
233
  );
259
234
 
260
- bundler.on((args) => {
261
- hooks.afterBuild?.({ ...args, root, publicUrl, importmap, entryModule, schemaVersion, bundler, outFile, outDir });
262
- });
235
+ const allEntries = await matchAnyPilet(fullBase, entryList);
236
+ const maxListeners = Math.max(2 + allEntries.length * 2, 16);
237
+ log('generalDebug_0003', `Found the following entries: ${allEntries.join(', ')}`);
263
238
 
264
- return {
265
- emulator,
266
- appFile,
267
- publicUrl,
268
- appVersion: appPackage.version,
269
- externals,
270
- piral: appPackage.name,
271
- bundler,
272
- mocks: mocksExists ? mocks : undefined,
273
- root,
274
- };
275
- });
239
+ if (allEntries.length === 0) {
240
+ fail('entryFileMissing_0077');
241
+ }
276
242
 
277
- // sanity check see #250
278
- checkSanity(pilets);
279
-
280
- await hooks.beforeApp?.({ appInstanceDir, pilets });
281
- const appDir = appInstanceDir || (await getOrMakeAppDir(pilets[0], logLevel));
282
- const appRoot = dirname(await findFile(appDir, 'package.json'));
283
- await hooks.afterApp?.({ appInstanceDir, pilets });
284
-
285
- Promise.all(pilets.map((p) => p.bundler.ready())).then(() => logDone(`Ready!`));
286
-
287
- const sources = pilets.map((m) => m.mocks).filter(Boolean);
288
- const baseMocks = resolve(fullBase, 'mocks');
289
- const krasBaseConfig = resolve(fullBase, krasrc);
290
- const krasRootConfig = resolve(appRoot, krasrc);
291
- const initial = createInitialKrasConfig(baseMocks, sources, { [api]: '' }, feed);
292
- const required = {
293
- injectors: {
294
- piral: {
295
- active: false,
296
- },
297
- pilet: {
298
- active: true,
299
- pilets,
300
- app: appDir,
243
+ process.stderr.setMaxListeners(maxListeners);
244
+ process.stdout.setMaxListeners(maxListeners);
245
+ process.stdin.setMaxListeners(maxListeners);
246
+
247
+ const pilets = await concurrentWorkers(allEntries, concurrency, async (entryModule) => {
248
+ const targetDir = dirname(entryModule);
249
+ const { peerDependencies, peerModules, root, apps, ignored, importmap } = await retrievePiletData(targetDir, app);
250
+ const piralInstances = apps.map((m) => m.appPackage.name);
251
+ const externals = combinePiletExternals(piralInstances, peerDependencies, peerModules, importmap);
252
+ const mocks = join(targetDir, 'mocks');
253
+ const dest = resolve(root, target);
254
+ const outDir = dirname(dest);
255
+ const outFile = basename(dest);
256
+ const mocksExists = await checkExistingDirectory(mocks);
257
+
258
+ await hooks.beforeBuild?.({ root, publicUrl, importmap, entryModule, schemaVersion });
259
+
260
+ const bundler = await callPiletDebug(
261
+ {
262
+ root,
263
+ piralInstances,
264
+ optimizeModules,
265
+ hmr,
266
+ externals,
267
+ targetDir,
268
+ importmap,
269
+ outFile,
270
+ outDir,
271
+ entryModule: `./${relative(root, entryModule)}`,
272
+ logLevel,
273
+ version: schemaVersion,
274
+ ignored,
275
+ _,
276
+ },
277
+ bundlerName,
278
+ );
279
+
280
+ bundler.on((args) => {
281
+ hooks.afterBuild?.({
282
+ ...args,
283
+ root,
284
+ publicUrl,
285
+ importmap,
286
+ entryModule,
287
+ schemaVersion,
288
+ bundler,
289
+ outFile,
290
+ outDir,
291
+ });
292
+ });
293
+
294
+ return {
295
+ apps,
301
296
  publicUrl,
302
- handle: ['/', api],
303
- api,
304
- },
305
- },
306
- };
307
- const configs = [krasBaseConfig, ...pilets.map((p) => resolve(p.root, krasrc)), krasRootConfig];
308
- const port = await getAvailablePort(originalPort);
309
- const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
310
-
311
- log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
312
-
313
- const krasServer = buildKrasWithCli(krasConfig);
314
- krasServer.setMaxListeners(maxListeners);
315
- krasServer.removeAllListeners('open');
316
- krasServer.on(
317
- 'open',
318
- notifyServerOnline(
319
- pilets.map((p) => p.bundler),
320
- publicUrl,
321
- krasConfig.api,
322
- ),
323
- );
297
+ externals,
298
+ bundler,
299
+ mocks: mocksExists ? mocks : undefined,
300
+ root,
301
+ };
302
+ });
303
+
304
+ // sanity check see #250
305
+ checkSanity(pilets);
306
+
307
+ await hooks.beforeApp?.({ appInstanceDir, pilets });
308
+ const appDirs = [appInstanceDir] || (await getOrMakeApps(pilets[0], logLevel));
309
+
310
+ await Promise.all(
311
+ appDirs.map(async (appDir) => {
312
+ const appRoot = dirname(await findFile(appDir, 'package.json'));
313
+ await hooks.afterApp?.({ appInstanceDir, pilets });
314
+
315
+ Promise.all(pilets.map((p) => p.bundler.ready())).then(() => logDone(`Ready!`));
316
+
317
+ const sources = pilets.map((m) => m.mocks).filter(Boolean);
318
+ const baseMocks = resolve(fullBase, 'mocks');
319
+ const krasBaseConfig = resolve(fullBase, krasrc);
320
+ const krasRootConfig = resolve(appRoot, krasrc);
321
+ const initial = createInitialKrasConfig(baseMocks, sources, { [api]: '' }, feed);
322
+ const required = {
323
+ injectors: {
324
+ piral: {
325
+ active: false,
326
+ },
327
+ pilet: {
328
+ active: true,
329
+ pilets,
330
+ app: appDir,
331
+ publicUrl,
332
+ handle: ['/', api],
333
+ api,
334
+ },
335
+ },
336
+ };
337
+ const configs = [krasBaseConfig, ...pilets.map((p) => resolve(p.root, krasrc)), krasRootConfig];
338
+ const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
339
+
340
+ log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
341
+
342
+ const krasServer = buildKrasWithCli(krasConfig);
343
+ krasServer.setMaxListeners(maxListeners);
344
+ krasServer.removeAllListeners('open');
345
+ krasServer.on(
346
+ 'open',
347
+ notifyServerOnline(
348
+ pilets.map((p) => p.bundler),
349
+ publicUrl,
350
+ krasConfig.api,
351
+ ),
352
+ );
353
+
354
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
355
+ await krasServer.start();
356
+ openBrowser(open, port, publicUrl, !!krasConfig.ssl);
357
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
358
+ await new Promise((resolve) => krasServer.on('close', resolve));
359
+ }),
360
+ );
361
+ });
324
362
 
325
- await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
326
- await krasServer.start();
327
- openBrowser(open, port, publicUrl, !!krasConfig.ssl);
328
- await hooks.afterOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
329
- await new Promise((resolve) => krasServer.on('close', resolve));
330
363
  await hooks.onEnd?.({});
331
364
  }
@@ -18,6 +18,7 @@ import {
18
18
  createInitialKrasConfig,
19
19
  getAvailablePort,
20
20
  checkExistingDirectory,
21
+ watcherTask,
21
22
  } from '../common';
22
23
 
23
24
  export interface DebugPiralOptions {
@@ -118,76 +119,83 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
118
119
  } = options;
119
120
  const publicUrl = normalizePublicUrl(originalPublicUrl);
120
121
  const fullBase = resolve(process.cwd(), baseDir);
122
+ const port = await getAvailablePort(originalPort);
121
123
  setLogLevel(logLevel);
122
124
 
123
125
  await hooks.onBegin?.({ options, fullBase });
124
- progress('Reading configuration ...');
125
- const entryFiles = await retrievePiralRoot(fullBase, entry);
126
- const targetDir = dirname(entryFiles);
127
- const { externals, name, root, ignored } = await retrievePiletsInfo(entryFiles);
128
- const dest = getDestination(entryFiles, resolve(fullBase, target));
129
-
130
- await checkCliCompatibility(root);
131
-
132
- await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, name });
133
-
134
- const bundler = await callPiralDebug(
135
- {
136
- root,
137
- piral: name,
138
- optimizeModules,
139
- hmr,
140
- externals,
141
- publicUrl,
142
- entryFiles,
143
- logLevel,
144
- ignored,
145
- ...dest,
146
- _,
147
- },
148
- bundlerName,
149
- );
150
-
151
- bundler.ready().then(() => logDone(`Ready!`));
152
-
153
- bundler.on((args) => {
154
- hooks.afterBuild?.({ ...args, root, publicUrl, externals, entryFiles, name, bundler, ...dest });
155
- });
156
126
 
157
- const krasBaseConfig = resolve(fullBase, krasrc);
158
- const krasRootConfig = resolve(root, krasrc);
159
- const mocks = join(targetDir, 'mocks');
160
- const baseMocks = resolve(fullBase, 'mocks');
161
- const mocksExist = await checkExistingDirectory(mocks);
162
- const sources = [mocksExist ? mocks : undefined].filter(Boolean);
163
- const initial = createInitialKrasConfig(baseMocks, sources);
164
- const required = {
165
- injectors: {
166
- piral: {
167
- active: true,
168
- handle: ['/'],
169
- feed,
127
+ await watcherTask(async (watcherContext) => {
128
+ progress('Reading configuration ...');
129
+ const entryFiles = await retrievePiralRoot(fullBase, entry);
130
+ const targetDir = dirname(entryFiles);
131
+ const { externals, name, root, ignored } = await retrievePiletsInfo(entryFiles);
132
+ const piralInstances = [name];
133
+ const dest = getDestination(entryFiles, resolve(fullBase, target));
134
+
135
+ await checkCliCompatibility(root);
136
+
137
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, piralInstances });
138
+
139
+ const bundler = await callPiralDebug(
140
+ {
141
+ root,
142
+ piralInstances,
143
+ optimizeModules,
144
+ hmr,
145
+ externals,
170
146
  publicUrl,
171
- bundler,
147
+ entryFiles,
148
+ logLevel,
149
+ ignored,
150
+ ...dest,
151
+ _,
172
152
  },
173
- pilet: {
174
- active: false,
153
+ bundlerName,
154
+ );
155
+
156
+ bundler.ready().then(() => logDone(`Ready!`));
157
+
158
+ bundler.on((args) => {
159
+ hooks.afterBuild?.({ ...args, root, publicUrl, externals, entryFiles, piralInstances, bundler, ...dest });
160
+ });
161
+
162
+ const krasBaseConfig = resolve(fullBase, krasrc);
163
+ const krasRootConfig = resolve(root, krasrc);
164
+ const mocks = join(targetDir, 'mocks');
165
+ const baseMocks = resolve(fullBase, 'mocks');
166
+
167
+
168
+ const mocksExist = await checkExistingDirectory(mocks);
169
+ const sources = [mocksExist ? mocks : undefined].filter(Boolean);
170
+ const initial = createInitialKrasConfig(baseMocks, sources);
171
+ const required = {
172
+ injectors: {
173
+ piral: {
174
+ active: true,
175
+ handle: ['/'],
176
+ feed,
177
+ publicUrl,
178
+ bundler,
179
+ },
180
+ pilet: {
181
+ active: false,
182
+ },
175
183
  },
176
- },
177
- };
178
- const port = await getAvailablePort(originalPort);
179
- const krasConfig = readKrasConfig({ port, initial, required }, krasBaseConfig, krasRootConfig);
184
+ };
185
+ const krasConfig = readKrasConfig({ port, initial, required }, krasBaseConfig, krasRootConfig);
180
186
 
181
- log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
187
+ log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
182
188
 
183
- const krasServer = buildKrasWithCli(krasConfig);
184
- krasServer.removeAllListeners('open');
185
- krasServer.on('open', notifyServerOnline([bundler], publicUrl, krasConfig.api));
189
+ const krasServer = buildKrasWithCli(krasConfig);
190
+ krasServer.removeAllListeners('open');
191
+ krasServer.on('open', notifyServerOnline([bundler], publicUrl, krasConfig.api));
192
+
193
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, publicUrl });
194
+ await krasServer.start();
195
+ openBrowser(open, port, publicUrl, !!krasConfig.ssl);
196
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port, publicUrl });
197
+ await new Promise((resolve) => krasServer.on('close', resolve));
198
+ });
186
199
 
187
- await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, publicUrl });
188
- await krasServer.start();
189
- openBrowser(open, port, publicUrl, !!krasConfig.ssl);
190
- await hooks.afterOnline?.({ krasServer, krasConfig, open, port, publicUrl });
191
- await new Promise((resolve) => krasServer.on('close', resolve));
192
200
  await hooks.onEnd?.({});
193
201
  }