piral-cli 1.4.0-beta.6247 → 1.4.0-beta.6252

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 (174) hide show
  1. package/lib/api.js +8 -17
  2. package/lib/api.js.map +1 -1
  3. package/lib/apps/add-piral-instance-pilet.js +20 -34
  4. package/lib/apps/add-piral-instance-pilet.js.map +1 -1
  5. package/lib/apps/build-pilet.js +139 -147
  6. package/lib/apps/build-pilet.js.map +1 -1
  7. package/lib/apps/build-piral.js +130 -144
  8. package/lib/apps/build-piral.js.map +1 -1
  9. package/lib/apps/debug-pilet.js +107 -119
  10. package/lib/apps/debug-pilet.js.map +1 -1
  11. package/lib/apps/debug-piral.js +62 -70
  12. package/lib/apps/debug-piral.js.map +1 -1
  13. package/lib/apps/declaration-piral.js +6 -17
  14. package/lib/apps/declaration-piral.js.map +1 -1
  15. package/lib/apps/new-pilet.js +71 -81
  16. package/lib/apps/new-pilet.js.map +1 -1
  17. package/lib/apps/new-piral.js +42 -53
  18. package/lib/apps/new-piral.js.map +1 -1
  19. package/lib/apps/pack-pilet.js +7 -18
  20. package/lib/apps/pack-pilet.js.map +1 -1
  21. package/lib/apps/publish-pilet.js +127 -141
  22. package/lib/apps/publish-pilet.js.map +1 -1
  23. package/lib/apps/publish-piral.js +48 -63
  24. package/lib/apps/publish-piral.js.map +1 -1
  25. package/lib/apps/remove-piral-instance-pilet.js +30 -35
  26. package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
  27. package/lib/apps/run-emulator-piral.js +49 -61
  28. package/lib/apps/run-emulator-piral.js.map +1 -1
  29. package/lib/apps/upgrade-pilet.js +64 -75
  30. package/lib/apps/upgrade-pilet.js.map +1 -1
  31. package/lib/apps/upgrade-piral.js +31 -43
  32. package/lib/apps/upgrade-piral.js.map +1 -1
  33. package/lib/apps/validate-pilet.js +34 -45
  34. package/lib/apps/validate-pilet.js.map +1 -1
  35. package/lib/apps/validate-piral.js +29 -51
  36. package/lib/apps/validate-piral.js.map +1 -1
  37. package/lib/build/bundler-calls.js +12 -3
  38. package/lib/build/bundler-calls.js.map +1 -1
  39. package/lib/build/run-build-pilet.js +5 -14
  40. package/lib/build/run-build-pilet.js.map +1 -1
  41. package/lib/build/run-build-piral.js +5 -14
  42. package/lib/build/run-build-piral.js.map +1 -1
  43. package/lib/build/run-debug-mono-piral.js +5 -14
  44. package/lib/build/run-debug-mono-piral.js.map +1 -1
  45. package/lib/build/run-debug-pilet.js +5 -14
  46. package/lib/build/run-debug-pilet.js.map +1 -1
  47. package/lib/build/run-debug-piral.js +5 -14
  48. package/lib/build/run-debug-piral.js.map +1 -1
  49. package/lib/bundler.js +100 -127
  50. package/lib/bundler.js.map +1 -1
  51. package/lib/commands.js +5 -1
  52. package/lib/commands.js.map +1 -1
  53. package/lib/common/browser.js +13 -26
  54. package/lib/common/browser.js.map +1 -1
  55. package/lib/common/compatibility.js +10 -21
  56. package/lib/common/compatibility.js.map +1 -1
  57. package/lib/common/declaration.js +80 -101
  58. package/lib/common/declaration.js.map +1 -1
  59. package/lib/common/emulator.js +186 -182
  60. package/lib/common/emulator.js.map +1 -1
  61. package/lib/common/http.js +7 -4
  62. package/lib/common/http.js.map +1 -1
  63. package/lib/common/importmap.js +172 -187
  64. package/lib/common/importmap.js.map +1 -1
  65. package/lib/common/injectors.js +4 -1
  66. package/lib/common/injectors.js.map +1 -1
  67. package/lib/common/inspect.js +5 -2
  68. package/lib/common/inspect.js.map +1 -1
  69. package/lib/common/interactive.js +9 -15
  70. package/lib/common/interactive.js.map +1 -1
  71. package/lib/common/io.js +256 -299
  72. package/lib/common/io.js.map +1 -1
  73. package/lib/common/language.js +21 -5
  74. package/lib/common/language.js.map +1 -1
  75. package/lib/common/npm.js +193 -228
  76. package/lib/common/npm.js.map +1 -1
  77. package/lib/common/pack.js +71 -86
  78. package/lib/common/pack.js.map +1 -1
  79. package/lib/common/package.d.ts +1 -2
  80. package/lib/common/package.js +428 -458
  81. package/lib/common/package.js.map +1 -1
  82. package/lib/common/parallel.js +12 -23
  83. package/lib/common/parallel.js.map +1 -1
  84. package/lib/common/patcher.js +54 -71
  85. package/lib/common/patcher.js.map +1 -1
  86. package/lib/common/platform.js +1 -12
  87. package/lib/common/platform.js.map +1 -1
  88. package/lib/common/port.js +11 -24
  89. package/lib/common/port.js.map +1 -1
  90. package/lib/common/rules.js +6 -17
  91. package/lib/common/rules.js.map +1 -1
  92. package/lib/common/scaffold.js +52 -59
  93. package/lib/common/scaffold.js.map +1 -1
  94. package/lib/common/shell.d.ts +2 -2
  95. package/lib/common/shell.js +53 -31
  96. package/lib/common/shell.js.map +1 -1
  97. package/lib/common/spec.js +1 -1
  98. package/lib/common/spec.js.map +1 -1
  99. package/lib/common/template.js +3 -14
  100. package/lib/common/template.js.map +1 -1
  101. package/lib/common/watcher.js +7 -16
  102. package/lib/common/watcher.js.map +1 -1
  103. package/lib/common/website.d.ts +2 -2
  104. package/lib/common/website.js +68 -56
  105. package/lib/common/website.js.map +1 -1
  106. package/lib/injectors/pilet-injector.d.ts +12 -10
  107. package/lib/injectors/pilet-injector.js +123 -87
  108. package/lib/injectors/pilet-injector.js.map +1 -1
  109. package/lib/injectors/piral-injector.d.ts +5 -5
  110. package/lib/injectors/piral-injector.js +32 -14
  111. package/lib/injectors/piral-injector.js.map +1 -1
  112. package/lib/messages.d.ts +81 -0
  113. package/lib/messages.js +94 -1
  114. package/lib/messages.js.map +1 -1
  115. package/lib/npm-clients/bun.js +36 -60
  116. package/lib/npm-clients/bun.js.map +1 -1
  117. package/lib/npm-clients/index.js +10 -21
  118. package/lib/npm-clients/index.js.map +1 -1
  119. package/lib/npm-clients/lerna.js +48 -72
  120. package/lib/npm-clients/lerna.js.map +1 -1
  121. package/lib/npm-clients/npm.js +69 -105
  122. package/lib/npm-clients/npm.js.map +1 -1
  123. package/lib/npm-clients/pnp.js +35 -59
  124. package/lib/npm-clients/pnp.js.map +1 -1
  125. package/lib/npm-clients/pnpm.js +35 -59
  126. package/lib/npm-clients/pnpm.js.map +1 -1
  127. package/lib/npm-clients/rush.js +53 -77
  128. package/lib/npm-clients/rush.js.map +1 -1
  129. package/lib/npm-clients/yarn.js +35 -59
  130. package/lib/npm-clients/yarn.js.map +1 -1
  131. package/lib/platforms/node.js +4 -17
  132. package/lib/platforms/node.js.map +1 -1
  133. package/lib/platforms/web.js +81 -96
  134. package/lib/platforms/web.js.map +1 -1
  135. package/lib/plugin.js +56 -75
  136. package/lib/plugin.js.map +1 -1
  137. package/lib/questionnaire.js +46 -12
  138. package/lib/questionnaire.js.map +1 -1
  139. package/lib/release.js +32 -47
  140. package/lib/release.js.map +1 -1
  141. package/lib/rules/index.js +10 -23
  142. package/lib/rules/index.js.map +1 -1
  143. package/lib/rules/pilet-has-externals-as-peers.js +34 -45
  144. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  145. package/lib/rules/pilet-has-no-self-reference.js +16 -27
  146. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  147. package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
  148. package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
  149. package/lib/rules/pilet-stays-small.js +20 -33
  150. package/lib/rules/pilet-stays-small.js.map +1 -1
  151. package/lib/rules/pilet-uses-latest-piral.js +17 -28
  152. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  153. package/lib/rules/piral-has-valid-devDependencies.js +4 -1
  154. package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
  155. package/lib/runner.js +3 -12
  156. package/lib/runner.js.map +1 -1
  157. package/lib/select.js +21 -32
  158. package/lib/select.js.map +1 -1
  159. package/lib/start.js +6 -17
  160. package/lib/start.js.map +1 -1
  161. package/package.json +2 -2
  162. package/src/apps/add-piral-instance-pilet.ts +1 -16
  163. package/src/apps/build-piral.test.ts +1 -1
  164. package/src/apps/new-pilet.ts +4 -10
  165. package/src/apps/run-emulator-piral.ts +1 -1
  166. package/src/apps/upgrade-pilet.ts +3 -2
  167. package/src/common/package.ts +29 -37
  168. package/src/common/shell.ts +59 -18
  169. package/src/common/website.ts +47 -17
  170. package/src/injectors/pilet-injector.test.ts +4 -4
  171. package/src/injectors/pilet-injector.ts +97 -41
  172. package/src/injectors/piral-injector.test.ts +2 -2
  173. package/src/injectors/piral-injector.ts +31 -20
  174. package/src/messages.ts +93 -0
@@ -1,20 +1,14 @@
1
1
  import { URL } from 'url';
2
2
  import { join } from 'path';
3
3
  import { EventEmitter } from 'events';
4
- import { readFileSync, existsSync, statSync } from 'fs';
5
- import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
4
+ import { readFile, stat, writeFile } from 'fs/promises';
5
+ import { KrasInjector, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
6
6
  import { log } from '../common/log';
7
7
  import { getPiletSpecMeta } from '../common/spec';
8
8
  import { config as commonConfig } from '../common/config';
9
9
  import { axios, mime, jju } from '../external';
10
10
  import { Bundler } from '../types';
11
11
 
12
- interface Pilet {
13
- bundler: Bundler;
14
- root: string;
15
- getMeta(basePath: string): PiletMetadata;
16
- }
17
-
18
12
  export interface PiletInjectorConfig extends KrasInjectorConfig {
19
13
  /**
20
14
  * The pilets to serve.
@@ -54,31 +48,43 @@ export interface PiletInjectorConfig extends KrasInjectorConfig {
54
48
  headers?: Record<string, string>;
55
49
  }
56
50
 
51
+ interface Pilet {
52
+ bundler: Bundler;
53
+ root: string;
54
+ getMeta(basePath: string): PiletMetadata;
55
+ }
56
+
57
57
  interface PiletMetadata {
58
58
  name?: string;
59
59
  config?: Record<string, any>;
60
60
  [key: string]: unknown;
61
61
  }
62
62
 
63
- function getMetaOverride(root: string, metaFile: string) {
63
+ async function getMetaOverride(root: string, metaFile: string) {
64
64
  if (metaFile) {
65
65
  const metaPath = join(root, metaFile);
66
+ const exists = await stat(metaPath).then(
67
+ () => true,
68
+ () => false,
69
+ );
66
70
 
67
- if (existsSync(metaPath)) {
68
- return jju.parse(readFileSync(metaPath, 'utf8'));
71
+ if (exists) {
72
+ const metaContent = await readFile(metaPath, 'utf8');
73
+ return jju.parse(metaContent);
69
74
  }
70
75
  }
71
76
 
72
77
  return undefined;
73
78
  }
74
79
 
75
- function fillPiletMeta(pilet: Pilet, metaFile: string, subPath: string) {
80
+ async function fillPiletMeta(pilet: Pilet, metaFile: string, subPath: string) {
76
81
  const { root, bundler } = pilet;
77
82
  const packagePath = join(root, 'package.json');
78
- const def = jju.parse(readFileSync(packagePath, 'utf8'));
83
+ const jsonContent = await readFile(packagePath, 'utf8');
84
+ const def = jju.parse(jsonContent);
79
85
  const file = bundler.bundle.name.replace(/^[\/\\]/, '');
80
86
  const target = join(bundler.bundle.dir, file);
81
- const metaOverride = getMetaOverride(root, metaFile);
87
+ const metaOverride = await getMetaOverride(root, metaFile);
82
88
 
83
89
  pilet.getMeta = (parentPath) => {
84
90
  const basePath = `${parentPath}${subPath}`;
@@ -96,11 +102,11 @@ function fillPiletMeta(pilet: Pilet, metaFile: string, subPath: string) {
96
102
  };
97
103
  }
98
104
 
105
+ type FeedResponse = { items?: Array<PiletMetadata> } | Array<PiletMetadata> | PiletMetadata;
106
+
99
107
  async function loadFeed(feed: string) {
100
108
  try {
101
- const response = await axios.default.get<{ items?: Array<PiletMetadata> } | Array<PiletMetadata> | PiletMetadata>(
102
- feed,
103
- );
109
+ const response = await axios.default.get<FeedResponse>(feed);
104
110
 
105
111
  if (Array.isArray(response.data)) {
106
112
  return response.data;
@@ -118,16 +124,33 @@ export default class PiletInjector implements KrasInjector {
118
124
  public config: PiletInjectorConfig;
119
125
  private serverConfig: KrasConfiguration;
120
126
  private indexPath: string;
127
+ private proxyInfo?: {
128
+ source: string;
129
+ files: Array<string>;
130
+ date: Date;
131
+ };
121
132
 
122
133
  constructor(config: PiletInjectorConfig, serverConfig: KrasConfiguration, core: EventEmitter) {
123
134
  this.config = config;
124
135
  this.serverConfig = serverConfig;
125
136
 
126
137
  if (this.config.active) {
127
- const { pilets, api, publicUrl, assetUrl } = config;
138
+ const { pilets, api, app, publicUrl, assetUrl } = config;
128
139
  this.indexPath = `${publicUrl}index.html`;
129
140
  const cbs = {};
130
141
 
142
+ if (app.endsWith('/app')) {
143
+ const packageJson = require(`${app}/../package.json`);
144
+
145
+ if (typeof packageJson.piralCLI.source === 'string') {
146
+ this.proxyInfo = {
147
+ source: packageJson.piralCLI.source,
148
+ files: packageJson.files,
149
+ date: new Date(packageJson.piralCLI.timestamp),
150
+ };
151
+ }
152
+ }
153
+
131
154
  core.on('user-connected', (e) => {
132
155
  const baseUrl = assetUrl || e.req.headers.origin;
133
156
 
@@ -144,8 +167,8 @@ export default class PiletInjector implements KrasInjector {
144
167
  });
145
168
 
146
169
  pilets.forEach((p, i) =>
147
- p.bundler.on(() => {
148
- fillPiletMeta(p, config.meta, `/${i}/`);
170
+ p.bundler.on(async () => {
171
+ await fillPiletMeta(p, config.meta, `/${i}/`);
149
172
 
150
173
  for (const id of Object.keys(cbs)) {
151
174
  const { baseUrl, notify } = cbs[id];
@@ -251,7 +274,7 @@ export default class PiletInjector implements KrasInjector {
251
274
  return merged;
252
275
  }
253
276
 
254
- sendContent(content: Buffer | string, type: string, url: string): KrasResponse {
277
+ sendContent(content: Buffer | string, type: string, url: string): KrasResult {
255
278
  const { headers } = this.config;
256
279
 
257
280
  return {
@@ -269,8 +292,8 @@ export default class PiletInjector implements KrasInjector {
269
292
  };
270
293
  }
271
294
 
272
- sendFile(target: string, url: string): KrasResponse {
273
- const content = readFileSync(target);
295
+ async sendFile(target: string, url: string): Promise<KrasResult> {
296
+ const content = await readFile(target);
274
297
  const type = mime.getType(target) ?? 'application/octet-stream';
275
298
  return this.sendContent(content, type, url);
276
299
  }
@@ -281,23 +304,25 @@ export default class PiletInjector implements KrasInjector {
281
304
  const pilet = pilets[+index];
282
305
  const bundler = pilet?.bundler;
283
306
 
307
+ await bundler?.ready();
308
+
284
309
  if (!path) {
285
- await bundler?.ready();
286
310
  const content = await this.getIndexMeta(baseUrl);
287
311
  return this.sendContent(content, 'application/json', url);
288
- } else {
289
- return bundler?.ready().then(() => {
290
- const target = join(bundler.bundle.dir, rest.join('/'));
312
+ } else if (bundler?.bundle) {
313
+ const target = join(bundler.bundle.dir, rest.join('/'));
314
+ const info = await stat(target).catch(() => undefined);
291
315
 
292
- if (existsSync(target) && statSync(target).isFile()) {
293
- return this.sendFile(target, url);
294
- }
295
- });
316
+ if (info && info.isFile()) {
317
+ return await this.sendFile(target, url);
318
+ }
296
319
  }
320
+
321
+ return undefined;
297
322
  }
298
323
 
299
- sendIndexFile(target: string, url: string, baseUrl: string): KrasResponse {
300
- const indexHtml = readFileSync(target, 'utf8');
324
+ async sendIndexFile(target: string, url: string, baseUrl: string): Promise<KrasResult> {
325
+ const indexHtml = await readFile(target, 'utf8');
301
326
 
302
327
  // mechanism to inject server side debug piletApi config into piral emulator
303
328
  const windowInjectionScript = `window['dbg:pilet-api'] = '${this.getPiletApi(baseUrl)}';`;
@@ -308,29 +333,60 @@ export default class PiletInjector implements KrasInjector {
308
333
  return this.sendContent(content, mime.getType(target), url);
309
334
  }
310
335
 
311
- handle(req: KrasRequest): KrasResponse {
336
+ private async shouldLoad(target: string, path: string) {
337
+ if (this.proxyInfo) {
338
+ if (!this.proxyInfo.files.includes(path)) {
339
+ return false;
340
+ }
341
+
342
+ const fileInfo = await stat(target).catch(() => undefined);
343
+
344
+ if (!fileInfo || fileInfo.mtime < this.proxyInfo.date) {
345
+ const url = new URL(path, this.proxyInfo.source);
346
+
347
+ try {
348
+ const response = await axios.default.get(url.href, { responseType: 'arraybuffer' });
349
+ await writeFile(target, response.data);
350
+ } catch (ex) {
351
+ log('generalDebug_0003', `HTTP request for emulator asset retrieval failed: ${ex}`);
352
+ log(
353
+ fileInfo ? 'optionalEmulatorAssetUpdateSkipped_0122' : 'requiredEmulatorAssetDownloadSkipped_0123',
354
+ url.href,
355
+ );
356
+ return !!fileInfo;
357
+ }
358
+ }
359
+
360
+ return true;
361
+ } else {
362
+ const fileInfo = await stat(target).catch(() => undefined);
363
+ return fileInfo && fileInfo.isFile();
364
+ }
365
+ }
366
+
367
+ async handle(req: KrasRequest): Promise<KrasResult> {
312
368
  const { app, api, publicUrl, assetUrl } = this.config;
313
369
  const baseUrl =
314
370
  assetUrl || (req.headers.host ? `${req.encrypted ? 'https' : 'http'}://${req.headers.host}` : undefined);
315
371
 
316
372
  if (!req.target) {
317
373
  if (req.url.startsWith(publicUrl)) {
318
- const path = req.url.substring(publicUrl.length).split('?')[0];
374
+ const path = req.url.substring(publicUrl.length).split('?').shift();
319
375
 
320
376
  if (app) {
321
377
  const target = join(app, path);
322
378
 
323
- if (existsSync(target) && statSync(target).isFile()) {
379
+ if (await this.shouldLoad(target, path)) {
324
380
  if (req.url === this.indexPath) {
325
- return this.sendIndexFile(target, req.url, baseUrl);
381
+ return await this.sendIndexFile(target, req.url, baseUrl);
326
382
  }
327
383
 
328
- return this.sendFile(target, req.url);
384
+ return await this.sendFile(target, req.url);
329
385
  }
330
386
  }
331
387
 
332
388
  if (req.url !== this.indexPath) {
333
- return this.handle({
389
+ return await this.handle({
334
390
  ...req,
335
391
  url: this.indexPath,
336
392
  });
@@ -339,8 +395,8 @@ export default class PiletInjector implements KrasInjector {
339
395
 
340
396
  return undefined;
341
397
  } else if (req.target === api) {
342
- const path = req.url.substring(1).split('?')[0];
343
- return this.sendResponse(path, req.url, baseUrl);
398
+ const path = req.url.substring(1).split('?').shift();
399
+ return await this.sendResponse(path, req.url, baseUrl);
344
400
  }
345
401
  }
346
402
  }
@@ -64,7 +64,7 @@ describe('Piral-CLI piral injector', () => {
64
64
  expect(injector.active).toBeFalsy();
65
65
  });
66
66
 
67
- it('PiralInjector can send reponse and fails with invalid path', () => {
67
+ it('PiralInjector can send reponse and fails with invalid path', async () => {
68
68
  // Arrange
69
69
  const config = {
70
70
  bundler: bundlerMock,
@@ -75,7 +75,7 @@ describe('Piral-CLI piral injector', () => {
75
75
  const injector = new PiralInjector(config, undefined as any, new EventEmitter());
76
76
 
77
77
  // Act
78
- const res = injector.sendResponse('some/nice/invalid/path', 'sometarget.file', 'someDir', 'localhost:1234');
78
+ const res = await injector.sendResponse('some/nice/invalid/path', 'sometarget.file', 'someDir', 'localhost:1234');
79
79
 
80
80
  // Assert
81
81
  expect(res).toBeUndefined();
@@ -1,15 +1,10 @@
1
1
  import { join } from 'path';
2
2
  import { EventEmitter } from 'events';
3
- import { readFileSync, existsSync, statSync } from 'fs';
4
- import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration } from 'kras';
3
+ import { readFile, stat } from 'fs/promises';
4
+ import { KrasInjector, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
5
5
  import { mime } from '../external';
6
6
  import { Bundler } from '../types';
7
7
 
8
- /**
9
- * The maximum amount of retries when sending a response
10
- */
11
- const maxRetrySendResponse = 4;
12
-
13
8
  export interface PiralInjectorConfig extends KrasInjectorConfig {
14
9
  bundler: Bundler;
15
10
  publicUrl: string;
@@ -17,6 +12,20 @@ export interface PiralInjectorConfig extends KrasInjectorConfig {
17
12
  headers?: Record<string, string>;
18
13
  }
19
14
 
15
+ /**
16
+ * The maximum amount of retries when sending a response
17
+ */
18
+ const maxRetrySendResponse = 4;
19
+
20
+ async function isNoFile(target: string) {
21
+ try {
22
+ const info = await stat(target);
23
+ return !info.isFile();
24
+ } catch {
25
+ return true;
26
+ }
27
+ }
28
+
20
29
  export default class PiralInjector implements KrasInjector {
21
30
  public config: PiralInjectorConfig;
22
31
 
@@ -63,7 +72,7 @@ export default class PiralInjector implements KrasInjector {
63
72
 
64
73
  setOptions() {}
65
74
 
66
- sendContent(content: Buffer | string, type: string, url: string): KrasResponse {
75
+ sendContent(content: Buffer | string, type: string, url: string): KrasResult {
67
76
  const { headers } = this.config;
68
77
  return {
69
78
  injector: { name: this.name },
@@ -80,8 +89,8 @@ export default class PiralInjector implements KrasInjector {
80
89
  };
81
90
  }
82
91
 
83
- sendIndexFile(target: string, url: string): KrasResponse {
84
- const indexHtml = readFileSync(target, 'utf8');
92
+ async sendIndexFile(target: string, url: string): Promise<KrasResult> {
93
+ const indexHtml = await readFile(target, 'utf8');
85
94
  const { feed } = this.config;
86
95
 
87
96
  if (feed) {
@@ -96,7 +105,7 @@ export default class PiralInjector implements KrasInjector {
96
105
  return this.sendContent(indexHtml, mime.getType(target), url);
97
106
  }
98
107
 
99
- sendResponse(path: string, target: string, dir: string, url: string, recursionDepth = 0): KrasResponse {
108
+ async sendResponse(path: string, target: string, dir: string, url: string, recursionDepth = 0): Promise<KrasResult> {
100
109
  if (recursionDepth > maxRetrySendResponse) {
101
110
  return undefined;
102
111
  }
@@ -104,17 +113,18 @@ export default class PiralInjector implements KrasInjector {
104
113
  const { bundler } = this.config;
105
114
  const newTarget = join(bundler.bundle.dir, bundler.bundle.name);
106
115
 
107
- if (!path || !existsSync(target) || !statSync(target).isFile()) {
108
- return this.sendResponse(bundler.bundle.name, newTarget, dir, url, recursionDepth + 1);
116
+ if (!path || (await isNoFile(target))) {
117
+ return await this.sendResponse(bundler.bundle.name, newTarget, dir, url, recursionDepth + 1);
109
118
  } else if (target === newTarget) {
110
- return this.sendIndexFile(target, url);
119
+ return await this.sendIndexFile(target, url);
120
+ } else {
121
+ const type = mime.getType(target) ?? 'application/octet-stream';
122
+ const content = await readFile(target);
123
+ return this.sendContent(content, type, url);
111
124
  }
112
-
113
- const type = mime.getType(target) ?? 'application/octet-stream';
114
- return this.sendContent(readFileSync(target), type, url);
115
125
  }
116
126
 
117
- handle(req: KrasRequest): KrasResponse {
127
+ async handle(req: KrasRequest): Promise<KrasResult> {
118
128
  if (!req.target) {
119
129
  const { bundler, publicUrl } = this.config;
120
130
 
@@ -122,8 +132,9 @@ export default class PiralInjector implements KrasInjector {
122
132
  const pathLength = publicUrl.length || 1;
123
133
  const path = req.url.substring(pathLength);
124
134
  const dir = bundler.bundle.dir;
125
- const target = join(dir, path.split('?')[0]);
126
- return bundler.ready().then(() => this.sendResponse(path, target, dir, req.url));
135
+ const target = join(dir, path.split('?').shift());
136
+ await bundler.ready();
137
+ return await this.sendResponse(path, target, dir, req.url);
127
138
  }
128
139
  }
129
140
  }
package/src/messages.ts CHANGED
@@ -2492,6 +2492,99 @@ export function publishFeedMissingVersion_0116(): QuickMessage {
2492
2492
  ];
2493
2493
  }
2494
2494
 
2495
+ /**
2496
+ * @kind Info
2497
+ *
2498
+ * @summary
2499
+ * The remote emulator could not be updated using its given manifest URL.
2500
+ *
2501
+ * @abstract
2502
+ * The remote emulator could not be retrieved from its specified URL. This could be due to a problem with
2503
+ * the network or due to the emulator website not being available right now.
2504
+ *
2505
+ * This is just an informative message. In the current scenario the emulator has been downloaded previously
2506
+ * already. Therefore, only potential updates are blocked due to the error.
2507
+ *
2508
+ * If the error persists please try to access the emulator's URL in your browser. In case this works make
2509
+ * sure that the browser does not have different proxy settings compared ot the rest of your system.
2510
+ *
2511
+ * @see
2512
+ * - [Chrome proxy settings](https://oxylabs.io/resources/integrations/chrome)
2513
+ * - [Firefox proxy settings](https://support.mozilla.org/en-US/kb/connection-settings-firefox)
2514
+ */
2515
+ export function skipEmulatorUpdate_0120(manifestUrl: string): QuickMessage {
2516
+ return [LogLevels.info, '0120', `Failed to retrieve current emulator from "${manifestUrl}". Skipping update.`];
2517
+ }
2518
+
2519
+ /**
2520
+ * @kind Warning
2521
+ *
2522
+ * @summary
2523
+ * The remote emulator could not be updated as the given manifest URL returns a differently named emulator.
2524
+ *
2525
+ * @abstract
2526
+ * When a remote emulator is first installed it will be integrated using its specified name as shell name.
2527
+ * The remote emulator is always auto-updated whenever the Piral CLI is running pilet commands. However,
2528
+ * in case the current emulator manifest has a different name the update will be blocked. In this case a
2529
+ * reinstallation of the emulator is necessary.
2530
+ *
2531
+ * Use "pilet remove-piral-instance" and "pilet add-piral-instance" to remove the old instance (by its given
2532
+ * name) and add the new instance (by the manifest URL).
2533
+ *
2534
+ * @see
2535
+ * - [Chrome proxy settings](https://oxylabs.io/resources/integrations/chrome)
2536
+ * - [Firefox proxy settings](https://support.mozilla.org/en-US/kb/connection-settings-firefox)
2537
+ */
2538
+ export function remoteEmulatorNameChanged_0121(name: string): QuickMessage {
2539
+ return [LogLevels.warning, '0121', `The name of the emulator has changed. Skipping updates for "${name}".`];
2540
+ }
2541
+
2542
+ /**
2543
+ * @kind Info
2544
+ *
2545
+ * @summary
2546
+ * An asset of the remote emulator could not be updated.
2547
+ *
2548
+ * @abstract
2549
+ * The metadata of an remote emulator has been updated, however, one of the asset files could
2550
+ * not be updated. The previously downloaded version of this file will be used as a fallback.
2551
+ *
2552
+ * Using the previously downloaded version of a file might just work, however, for several
2553
+ * reasons this might also break. In any case, if you see this info then any kinds of issues
2554
+ * appearing could potentially be solved by just giving your machine network access again or
2555
+ * waiting for the remote sources to be accessible again.
2556
+ *
2557
+ * @see
2558
+ * - [Chrome proxy settings](https://oxylabs.io/resources/integrations/chrome)
2559
+ * - [Firefox proxy settings](https://support.mozilla.org/en-US/kb/connection-settings-firefox)
2560
+ */
2561
+ export function optionalEmulatorAssetUpdateSkipped_0122(url: string): QuickMessage {
2562
+ return [LogLevels.info, '0122', ``];
2563
+ }
2564
+
2565
+ /**
2566
+ * @kind Warning
2567
+ *
2568
+ * @summary
2569
+ * An asset of the remote emulator could not be downloaded.
2570
+ *
2571
+ * @abstract
2572
+ * The metadata of an remote emulator has been downloaded, however, one of the asset files
2573
+ * could not be downloaded. Consequently, the fallback (index.html) will be used as
2574
+ * replacement in the dev server.
2575
+ *
2576
+ * If you see this warning then any kinds of issues appearing could potentially be solved by
2577
+ * just giving your machine network access again or waiting for the remote sources to be
2578
+ * accessible again.
2579
+ *
2580
+ * @see
2581
+ * - [Chrome proxy settings](https://oxylabs.io/resources/integrations/chrome)
2582
+ * - [Firefox proxy settings](https://support.mozilla.org/en-US/kb/connection-settings-firefox)
2583
+ */
2584
+ export function requiredEmulatorAssetDownloadSkipped_0123(url: string): QuickMessage {
2585
+ return [LogLevels.warning, '0123', ``];
2586
+ }
2587
+
2495
2588
  /**
2496
2589
  * @kind Warning
2497
2590
  *