piral-cli 0.14.2 → 0.14.3-beta.3295

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 (47) hide show
  1. package/lib/apps/build-pilet.d.ts +6 -2
  2. package/lib/apps/build-pilet.js +86 -39
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/debug-pilet.d.ts +2 -2
  5. package/lib/apps/publish-pilet.d.ts +1 -1
  6. package/lib/apps/publish-pilet.js +21 -14
  7. package/lib/apps/publish-pilet.js.map +1 -1
  8. package/lib/commands.js +7 -2
  9. package/lib/commands.js.map +1 -1
  10. package/lib/common/compatibility.js +4 -0
  11. package/lib/common/compatibility.js.map +1 -1
  12. package/lib/common/index.d.ts +1 -0
  13. package/lib/common/index.js +1 -0
  14. package/lib/common/index.js.map +1 -1
  15. package/lib/common/npm.d.ts +2 -1
  16. package/lib/common/npm.js +34 -8
  17. package/lib/common/npm.js.map +1 -1
  18. package/lib/common/spec.d.ts +29 -0
  19. package/lib/common/spec.js +57 -0
  20. package/lib/common/spec.js.map +1 -0
  21. package/lib/helpers.d.ts +3 -2
  22. package/lib/helpers.js +3 -2
  23. package/lib/helpers.js.map +1 -1
  24. package/lib/injectors/pilet.d.ts +2 -2
  25. package/lib/injectors/pilet.js +32 -74
  26. package/lib/injectors/pilet.js.map +1 -1
  27. package/lib/messages.d.ts +14 -1
  28. package/lib/messages.js +23 -3
  29. package/lib/messages.js.map +1 -1
  30. package/lib/rules/pilet-uses-latest-piral.js +17 -8
  31. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  32. package/lib/types/public.d.ts +1 -0
  33. package/package.json +2 -2
  34. package/src/apps/build-pilet.ts +135 -47
  35. package/src/apps/debug-pilet.ts +2 -2
  36. package/src/apps/publish-pilet.ts +22 -15
  37. package/src/commands.ts +9 -3
  38. package/src/common/compatibility.ts +6 -0
  39. package/src/common/index.ts +1 -0
  40. package/src/common/io.ts +2 -2
  41. package/src/common/npm.ts +44 -11
  42. package/src/common/spec.ts +58 -0
  43. package/src/helpers.ts +10 -2
  44. package/src/injectors/pilet.ts +31 -78
  45. package/src/messages.ts +22 -2
  46. package/src/rules/pilet-uses-latest-piral.ts +21 -11
  47. package/src/types/public.ts +2 -0
@@ -3,8 +3,8 @@ import { join } from 'path';
3
3
  import { EventEmitter } from 'events';
4
4
  import { readFileSync, existsSync, statSync } from 'fs';
5
5
  import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
6
- import { computeHash, computeIntegrity } from '../common/hash';
7
6
  import { log } from '../common/log';
7
+ import { getPiletSpecMeta } from '../common/spec';
8
8
  import { axios, mime } from '../external';
9
9
  import { Bundler } from '../types';
10
10
 
@@ -26,62 +26,6 @@ interface PiletMetadata {
26
26
  [key: string]: unknown;
27
27
  }
28
28
 
29
- const checkV1 = /^\/\/\s*@pilet\s+v:1\s*\(([A-Za-z0-9\_\:\-]+)\)/;
30
- const checkV2 = /^\/\/\s*@pilet\s+v:2\s*(?:\(([A-Za-z0-9\_\:\-]+),\s*(.*)\))?/;
31
-
32
- function getDependencies(deps: string, basePath: string) {
33
- try {
34
- const depMap = JSON.parse(deps);
35
-
36
- if (depMap && typeof depMap === 'object') {
37
- return Object.keys(depMap).reduce((obj, depName) => {
38
- const depUrl = depMap[depName];
39
-
40
- if (typeof depUrl === 'string') {
41
- const url = new URL(depUrl, basePath);
42
- obj[depName] = url.href;
43
- }
44
-
45
- return obj;
46
- }, {});
47
- }
48
- } catch {}
49
-
50
- return {};
51
- }
52
-
53
- function getPiletSpecMeta(target: string, basePath: string) {
54
- if (existsSync(target) && statSync(target).isFile()) {
55
- const content = readFileSync(target, 'utf8');
56
-
57
- if (checkV1.test(content)) {
58
- // uses single argument; requireRef (required)
59
- const [, requireRef] = checkV1.exec(content);
60
- return {
61
- spec: 'v1',
62
- requireRef,
63
- integrity: computeIntegrity(content),
64
- };
65
- } else if (checkV2.test(content)) {
66
- // uses two arguments; requireRef and dependencies as JSON (required)
67
- const [, requireRef, plainDependencies] = checkV2.exec(content);
68
- return {
69
- spec: 'v2',
70
- requireRef,
71
- dependencies: getDependencies(plainDependencies, basePath),
72
- };
73
- } else {
74
- return {
75
- spec: 'v0',
76
- hash: computeHash(content),
77
- noCache: true,
78
- };
79
- }
80
- }
81
-
82
- return {};
83
- }
84
-
85
29
  function fillPiletMeta(pilet: Pilet, basePath: string) {
86
30
  const { root, bundler } = pilet;
87
31
  const def = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
@@ -100,6 +44,24 @@ function fillPiletMeta(pilet: Pilet, basePath: string) {
100
44
  return JSON.stringify(meta);
101
45
  }
102
46
 
47
+ async function loadFeed(feed: string) {
48
+ try {
49
+ const response = await axios.default.get<{ items?: Array<PiletMetadata> } | Array<PiletMetadata> | PiletMetadata>(
50
+ feed,
51
+ );
52
+
53
+ if (Array.isArray(response.data)) {
54
+ return response.data;
55
+ } else if (Array.isArray(response.data?.items)) {
56
+ return response.data.items;
57
+ } else {
58
+ return [response.data];
59
+ }
60
+ } catch (e) {
61
+ log('generalWarning_0001', `Couldn't load feed at ${feed}.`);
62
+ }
63
+ }
64
+
103
65
  export default class PiletInjector implements KrasInjector {
104
66
  public config: PiletInjectorConfig;
105
67
  private piletApi: string;
@@ -165,35 +127,26 @@ export default class PiletInjector implements KrasInjector {
165
127
  return JSON.stringify(mergedPilets);
166
128
  }
167
129
 
168
- async loadRemoteFeed(feed?: string): Promise<Array<PiletMetadata>> {
130
+ async loadRemoteFeed(feed?: string | Array<string>): Promise<Array<Array<PiletMetadata>>> {
169
131
  if (feed) {
170
- try {
171
- const response = await axios.default.get<{ items?: Array<PiletMetadata> } | Array<PiletMetadata> | PiletMetadata>(feed);
172
-
173
- if (Array.isArray(response.data)) {
174
- return response.data;
175
- } else if (Array.isArray(response.data?.items)) {
176
- return response.data.items;
177
- } else {
178
- return [response.data];
179
- }
180
- } catch (e) {
181
- log('generalWarning_0001', `Couldn't load feed at ${feed}.`);
182
- }
132
+ const feeds = Array.isArray(feed) ? feed : [feed];
133
+ return await Promise.all(feeds.map(loadFeed));
183
134
  }
184
-
185
135
  }
186
136
 
187
- mergePilets(localPilets: Array<PiletMetadata>, remotePilets: Array<PiletMetadata>) {
188
- if (!remotePilets) {
137
+ mergePilets(localPilets: Array<PiletMetadata>, remoteFeeds: Array<Array<PiletMetadata>>) {
138
+ if (!remoteFeeds) {
189
139
  return localPilets;
190
140
  }
191
141
 
192
142
  const names = localPilets.map((pilet) => pilet.name);
193
- const merged = [
194
- ...localPilets,
195
- ...remotePilets.filter((pilet) => pilet.name !== undefined && !names.includes(pilet.name)),
196
- ];
143
+ const merged = [...localPilets];
144
+
145
+ for (const remotePilets of remoteFeeds) {
146
+ const newPilets = remotePilets.filter((pilet) => pilet.name !== undefined && !names.includes(pilet.name));
147
+ names.push(...newPilets.map((p) => p.name));
148
+ merged.push(...newPilets);
149
+ }
197
150
 
198
151
  return merged;
199
152
  }
package/src/messages.ts CHANGED
@@ -1026,8 +1026,8 @@ export function missingPiletFeedUrl_0060(): QuickMessage {
1026
1026
  * Using multiple commands is preferred if you use custom options, otherwise
1027
1027
  * just go for the single command.
1028
1028
  */
1029
- export function missingPiletTarball_0061(source: string): QuickMessage {
1030
- return [LogLevels.error, '0061', `No files found using pattern "${source}".`];
1029
+ export function missingPiletTarball_0061(sources: Array<string>): QuickMessage {
1030
+ return [LogLevels.error, '0061', `No files found using pattern "${sources.join('", "')}".`];
1031
1031
  }
1032
1032
 
1033
1033
  /**
@@ -1842,6 +1842,26 @@ export function toolingIncompatible_0101(piralVersion: string, cliVersion: strin
1842
1842
  ];
1843
1843
  }
1844
1844
 
1845
+ /**
1846
+ * @kind Info
1847
+ *
1848
+ * @summary
1849
+ * The Piral CLI could not detect the tooling version used by the app shell. Therefore, it may be incompatible to the
1850
+ * currently used version of the piral-cli. Keep an eye on weird errors.
1851
+ *
1852
+ * @abstract
1853
+ * The emulator contains a special section to inform the Piral CLI about the used version of the tooling. This is
1854
+ * important to detect potential alignment or incompatibilities. The used version of the emulator does not contain
1855
+ * this information and therefore may be incompatible.
1856
+ */
1857
+ export function appShellMaybeIncompatible_0102(cliVersion: string): QuickMessage {
1858
+ return [
1859
+ LogLevels.info,
1860
+ '0100',
1861
+ `The Piral instance's CLI version is unknown and may be incompatible to the used version (${cliVersion}).`,
1862
+ ];
1863
+ }
1864
+
1845
1865
  /**
1846
1866
  * @kind Error
1847
1867
  *
@@ -1,4 +1,4 @@
1
- import { findLatestVersion } from '../common';
1
+ import { isMonorepoPackageRef, findLatestVersion } from '../common';
2
2
  import { PiletRuleContext } from '../types';
3
3
 
4
4
  export type Options = 'suggest' | 'required' | 'ignore';
@@ -13,17 +13,27 @@ export default async function (context: PiletRuleContext, options: Options = 'su
13
13
  const isfixed = demanded.startsWith('git+') || demanded.startsWith('file:');
14
14
 
15
15
  if (!isfixed) {
16
- const latestVersion = await findLatestVersion(name);
16
+ const isMonorepoRef = await isMonorepoPackageRef(name, context.root);
17
17
 
18
- if (version !== latestVersion) {
19
- const notify = options === 'required' ? context.error : context.warning;
20
- notify(
21
- `
22
- The used version of "${name}" is outdated.
23
- Expected: v${latestVersion}.
24
- Received: v${version}.
25
- `,
26
- );
18
+ // either we are not in a monorepo or the app shell is not part of the monorepo
19
+ if (!isMonorepoRef) {
20
+ const latestVersion = await findLatestVersion(name).catch((err) => {
21
+ context.warning(`
22
+ The used version of "${name}" could not be determined: ${err}.
23
+ `);
24
+ return version;
25
+ });
26
+
27
+ if (version !== latestVersion) {
28
+ const notify = options === 'required' ? context.error : context.warning;
29
+ notify(
30
+ `
31
+ The used version of "${name}" is outdated.
32
+ Expected: v${latestVersion}.
33
+ Received: v${version}.
34
+ `,
35
+ );
36
+ }
27
37
  }
28
38
  }
29
39
  }
@@ -217,6 +217,8 @@ export type PiletPublishSource = 'local' | 'npm' | 'remote';
217
217
 
218
218
  export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';
219
219
 
220
+ export type PiletBuildType = 'default' | 'standalone';
221
+
220
222
  export type PackageType = 'registry' | 'file' | 'git';
221
223
 
222
224
  export type NpmClientType = 'npm' | 'yarn' | 'pnpm';