piral-cli 1.4.0-beta.6250 → 1.4.0-beta.6253

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 (163) 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 -31
  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 -82
  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 -76
  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.js +428 -448
  80. package/lib/common/package.js.map +1 -1
  81. package/lib/common/parallel.js +12 -23
  82. package/lib/common/parallel.js.map +1 -1
  83. package/lib/common/patcher.js +54 -71
  84. package/lib/common/patcher.js.map +1 -1
  85. package/lib/common/platform.js +1 -12
  86. package/lib/common/platform.js.map +1 -1
  87. package/lib/common/port.js +11 -24
  88. package/lib/common/port.js.map +1 -1
  89. package/lib/common/rules.js +6 -17
  90. package/lib/common/rules.js.map +1 -1
  91. package/lib/common/scaffold.js +52 -59
  92. package/lib/common/scaffold.js.map +1 -1
  93. package/lib/common/shell.js +50 -58
  94. package/lib/common/shell.js.map +1 -1
  95. package/lib/common/spec.js +1 -1
  96. package/lib/common/spec.js.map +1 -1
  97. package/lib/common/template.js +3 -14
  98. package/lib/common/template.js.map +1 -1
  99. package/lib/common/watcher.js +7 -16
  100. package/lib/common/watcher.js.map +1 -1
  101. package/lib/common/website.d.ts +5 -1
  102. package/lib/common/website.js +71 -57
  103. package/lib/common/website.js.map +1 -1
  104. package/lib/injectors/pilet-injector.js +138 -145
  105. package/lib/injectors/pilet-injector.js.map +1 -1
  106. package/lib/injectors/piral-injector.js +55 -67
  107. package/lib/injectors/piral-injector.js.map +1 -1
  108. package/lib/messages.d.ts +81 -0
  109. package/lib/messages.js +94 -1
  110. package/lib/messages.js.map +1 -1
  111. package/lib/npm-clients/bun.js +36 -60
  112. package/lib/npm-clients/bun.js.map +1 -1
  113. package/lib/npm-clients/index.js +10 -21
  114. package/lib/npm-clients/index.js.map +1 -1
  115. package/lib/npm-clients/lerna.js +48 -72
  116. package/lib/npm-clients/lerna.js.map +1 -1
  117. package/lib/npm-clients/npm.js +69 -105
  118. package/lib/npm-clients/npm.js.map +1 -1
  119. package/lib/npm-clients/pnp.js +35 -59
  120. package/lib/npm-clients/pnp.js.map +1 -1
  121. package/lib/npm-clients/pnpm.js +35 -59
  122. package/lib/npm-clients/pnpm.js.map +1 -1
  123. package/lib/npm-clients/rush.js +53 -77
  124. package/lib/npm-clients/rush.js.map +1 -1
  125. package/lib/npm-clients/yarn.js +35 -59
  126. package/lib/npm-clients/yarn.js.map +1 -1
  127. package/lib/platforms/node.js +4 -17
  128. package/lib/platforms/node.js.map +1 -1
  129. package/lib/platforms/web.js +81 -96
  130. package/lib/platforms/web.js.map +1 -1
  131. package/lib/plugin.js +56 -75
  132. package/lib/plugin.js.map +1 -1
  133. package/lib/questionnaire.js +46 -12
  134. package/lib/questionnaire.js.map +1 -1
  135. package/lib/release.js +32 -47
  136. package/lib/release.js.map +1 -1
  137. package/lib/rules/index.js +10 -23
  138. package/lib/rules/index.js.map +1 -1
  139. package/lib/rules/pilet-has-externals-as-peers.js +34 -45
  140. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  141. package/lib/rules/pilet-has-no-self-reference.js +16 -27
  142. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  143. package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
  144. package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
  145. package/lib/rules/pilet-stays-small.js +20 -33
  146. package/lib/rules/pilet-stays-small.js.map +1 -1
  147. package/lib/rules/pilet-uses-latest-piral.js +17 -28
  148. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  149. package/lib/rules/piral-has-valid-devDependencies.js +4 -1
  150. package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
  151. package/lib/runner.js +3 -12
  152. package/lib/runner.js.map +1 -1
  153. package/lib/select.js +21 -32
  154. package/lib/select.js.map +1 -1
  155. package/lib/start.js +6 -17
  156. package/lib/start.js.map +1 -1
  157. package/package.json +2 -2
  158. package/src/apps/build-piral.test.ts +1 -1
  159. package/src/common/package.ts +23 -17
  160. package/src/common/shell.ts +2 -1
  161. package/src/common/website.ts +47 -16
  162. package/src/injectors/pilet-injector.ts +12 -2
  163. package/src/messages.ts +93 -0
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.retrievePiletData = exports.findPiletRoot = exports.combinePiletExternals = exports.checkAppShellPackage = exports.patchPiletPackage = exports.isValidDependency = exports.validateSharedDependencies = exports.retrievePiletsInfo = exports.retrieveExternals = exports.flattenExternals = exports.findPackageVersion = exports.findDependencyVersion = exports.retrievePiralRoot = exports.getPiletsInfo = exports.copyPiralFiles = exports.copyScaffoldingFiles = exports.getFileStats = exports.getPiralPackage = exports.patchPiralPackage = exports.readPiralPackage = exports.findPiralInstances = exports.findPiralInstance = exports.getPiralPath = void 0;
24
4
  const path_1 = require("path");
@@ -40,40 +20,38 @@ const language_2 = require("./language");
40
20
  const constants_1 = require("./constants");
41
21
  const constants_2 = require("./constants");
42
22
  const external_1 = require("../external");
43
- function appendBundler(devDependencies, bundler, proposedVersion) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (bundler && bundler !== 'none') {
46
- if (isValidDependency(bundler)) {
47
- const sep = bundler.indexOf('@', 1);
48
- const hasVersion = sep !== -1;
49
- const proposedName = bundler.substring(0, hasVersion ? sep : bundler.length);
50
- const givenVersion = hasVersion ? bundler.substring(sep + 1) : proposedVersion;
51
- const name = constants_1.bundlerNames.includes(proposedName) ? `piral-cli-${bundler}` : proposedName;
52
- const versions = new Set([
53
- givenVersion,
54
- givenVersion.includes('-beta.') && 'next',
55
- givenVersion.includes('-alpha.') && 'canary',
56
- givenVersion.includes('.') && givenVersion.split('.').slice(0, 2).join('.'),
57
- 'latest',
58
- ]);
59
- for (const version of versions) {
60
- if (version) {
61
- const isAvailable = yield (0, npm_2.findSpecificVersion)(name, version);
62
- // only if something was returned we know that the version exists; so we can take it.
63
- if (isAvailable) {
64
- devDependencies[name] = version;
65
- return;
66
- }
23
+ async function appendBundler(devDependencies, bundler, proposedVersion) {
24
+ if (bundler && bundler !== 'none') {
25
+ if (isValidDependency(bundler)) {
26
+ const sep = bundler.indexOf('@', 1);
27
+ const hasVersion = sep !== -1;
28
+ const proposedName = bundler.substring(0, hasVersion ? sep : bundler.length);
29
+ const givenVersion = hasVersion ? bundler.substring(sep + 1) : proposedVersion;
30
+ const name = constants_1.bundlerNames.includes(proposedName) ? `piral-cli-${bundler}` : proposedName;
31
+ const versions = new Set([
32
+ givenVersion,
33
+ givenVersion.includes('-beta.') && 'next',
34
+ givenVersion.includes('-alpha.') && 'canary',
35
+ givenVersion.includes('.') && givenVersion.split('.').slice(0, 2).join('.'),
36
+ 'latest',
37
+ ]);
38
+ for (const version of versions) {
39
+ if (version) {
40
+ const isAvailable = await (0, npm_2.findSpecificVersion)(name, version);
41
+ // only if something was returned we know that the version exists; so we can take it.
42
+ if (isAvailable) {
43
+ devDependencies[name] = version;
44
+ return;
67
45
  }
68
46
  }
69
- (0, log_1.log)('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
70
- }
71
- else {
72
- //Error case - print warning and ignore
73
- (0, log_1.log)('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
74
47
  }
48
+ (0, log_1.log)('generalWarning_0001', `Could not find a valid version for the provided bundler "${bundler}".'`);
75
49
  }
76
- });
50
+ else {
51
+ //Error case - print warning and ignore
52
+ (0, log_1.log)('generalWarning_0001', `The provided bundler name "${bundler}" does not refer to a valid package name.'`);
53
+ }
54
+ }
77
55
  }
78
56
  function getDependencyVersion(name, devDependencies, allDependencies) {
79
57
  const version = devDependencies[name];
@@ -84,47 +62,45 @@ function getDependencyVersion(name, devDependencies, allDependencies) {
84
62
  return selected || 'latest';
85
63
  }
86
64
  const globPatternStartIndicators = ['*', '?', '[', '!(', '?(', '+(', '@('];
87
- function getMatchingFiles(source, target, file) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const { from, to, deep = true } = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
90
- const sourcePath = (0, path_1.resolve)(source, from);
91
- const targetPath = (0, path_1.resolve)(target, to);
92
- const isDirectory = yield (0, io_1.checkIsDirectory)(sourcePath);
93
- if (isDirectory) {
94
- (0, log_1.log)('generalDebug_0003', `Matching in directory "${sourcePath}".`);
95
- const pattern = deep ? '**/*' : '*';
96
- const files = yield (0, io_1.matchFiles)(sourcePath, pattern);
97
- return files.map((file) => ({
98
- sourcePath: file,
99
- targetPath: (0, path_1.resolve)(targetPath, (0, path_1.relative)(sourcePath, file)),
100
- }));
101
- }
102
- else if (globPatternStartIndicators.some((m) => from.indexOf(m) !== -1)) {
103
- (0, log_1.log)('generalDebug_0003', `Matching using glob "${sourcePath}".`);
104
- const files = yield (0, io_1.matchFiles)(source, from);
105
- const parts = sourcePath.split('/');
106
- for (let i = 0; i < parts.length; i++) {
107
- const part = parts[i];
108
- if (globPatternStartIndicators.some((m) => part.indexOf(m) !== -1)) {
109
- parts.splice(i, parts.length - i);
110
- break;
111
- }
65
+ async function getMatchingFiles(source, target, file) {
66
+ const { from, to, deep = true } = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
67
+ const sourcePath = (0, path_1.resolve)(source, from);
68
+ const targetPath = (0, path_1.resolve)(target, to);
69
+ const isDirectory = await (0, io_1.checkIsDirectory)(sourcePath);
70
+ if (isDirectory) {
71
+ (0, log_1.log)('generalDebug_0003', `Matching in directory "${sourcePath}".`);
72
+ const pattern = deep ? '**/*' : '*';
73
+ const files = await (0, io_1.matchFiles)(sourcePath, pattern);
74
+ return files.map((file) => ({
75
+ sourcePath: file,
76
+ targetPath: (0, path_1.resolve)(targetPath, (0, path_1.relative)(sourcePath, file)),
77
+ }));
78
+ }
79
+ else if (globPatternStartIndicators.some((m) => from.indexOf(m) !== -1)) {
80
+ (0, log_1.log)('generalDebug_0003', `Matching using glob "${sourcePath}".`);
81
+ const files = await (0, io_1.matchFiles)(source, from);
82
+ const parts = sourcePath.split('/');
83
+ for (let i = 0; i < parts.length; i++) {
84
+ const part = parts[i];
85
+ if (globPatternStartIndicators.some((m) => part.indexOf(m) !== -1)) {
86
+ parts.splice(i, parts.length - i);
87
+ break;
112
88
  }
113
- const relRoot = parts.join('/');
114
- const tarRoot = (0, path_1.resolve)(target, to);
115
- return files.map((file) => ({
116
- sourcePath: file,
117
- targetPath: (0, path_1.resolve)(tarRoot, (0, path_1.relative)(relRoot, file)),
118
- }));
119
89
  }
120
- (0, log_1.log)('generalDebug_0003', `Assume direct path source "${sourcePath}".`);
121
- return [
122
- {
123
- sourcePath,
124
- targetPath,
125
- },
126
- ];
127
- });
90
+ const relRoot = parts.join('/');
91
+ const tarRoot = (0, path_1.resolve)(target, to);
92
+ return files.map((file) => ({
93
+ sourcePath: file,
94
+ targetPath: (0, path_1.resolve)(tarRoot, (0, path_1.relative)(relRoot, file)),
95
+ }));
96
+ }
97
+ (0, log_1.log)('generalDebug_0003', `Assume direct path source "${sourcePath}".`);
98
+ return [
99
+ {
100
+ sourcePath,
101
+ targetPath,
102
+ },
103
+ ];
128
104
  }
129
105
  function getPiralPath(root, name) {
130
106
  const path = (0, npm_2.findPackageRoot)(name, root);
@@ -134,50 +110,52 @@ function getPiralPath(root, name) {
134
110
  return (0, path_1.dirname)(path);
135
111
  }
136
112
  exports.getPiralPath = getPiralPath;
137
- function findPiralInstance(proposedApp, rootDir, details) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const path = (0, npm_2.findPackageRoot)(proposedApp, rootDir);
140
- if (path) {
141
- (0, log_1.log)('generalDebug_0003', `Following the app package in "${path}" ...`);
142
- const root = (0, path_1.dirname)(path);
143
- const appPackage = yield (0, io_2.readJson)(root, (0, path_1.basename)(path));
144
- const relPath = appPackage && appPackage.app;
145
- appPackage.app = relPath && (0, path_1.resolve)(root, relPath);
146
- appPackage.root = root;
147
- appPackage.port = (details === null || details === void 0 ? void 0 : details.port) || 0;
148
- return appPackage;
149
- }
150
- else if (details === null || details === void 0 ? void 0 : details.url) {
151
- const { url } = details, rest = __rest(details, ["url"]);
152
- (0, log_1.log)('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
153
- yield (0, website_1.scaffoldFromEmulatorWebsite)(rootDir, url);
154
- return yield findPiralInstance(proposedApp, rootDir, rest);
113
+ async function loadPiralInstance(root, details) {
114
+ (0, log_1.log)('generalDebug_0003', `Following the app package in "${root}" ...`);
115
+ const appPackage = await (0, io_2.readJson)(root, constants_1.packageJson);
116
+ const relPath = appPackage.app;
117
+ appPackage.app = relPath && (0, path_1.resolve)(root, relPath);
118
+ appPackage.root = root;
119
+ appPackage.port = details?.port || 0;
120
+ return appPackage;
121
+ }
122
+ async function findPiralInstance(proposedApp, rootDir, details) {
123
+ const path = (0, npm_2.findPackageRoot)(proposedApp, rootDir);
124
+ const url = details?.url;
125
+ if (path) {
126
+ const root = (0, path_1.dirname)(path);
127
+ if (url) {
128
+ (0, log_1.log)('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
129
+ await (0, website_1.updateFromEmulatorWebsite)(root, url);
155
130
  }
156
- (0, log_1.fail)('appInstanceNotFound_0010', proposedApp);
157
- });
131
+ return await loadPiralInstance(root, details);
132
+ }
133
+ else if (url) {
134
+ (0, log_1.log)('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
135
+ const emulator = await (0, website_1.scaffoldFromEmulatorWebsite)(rootDir, url);
136
+ return await loadPiralInstance(emulator.path, details);
137
+ }
138
+ (0, log_1.fail)('appInstanceNotFound_0010', proposedApp);
158
139
  }
159
140
  exports.findPiralInstance = findPiralInstance;
160
- function findPiralInstances(proposedApps, piletPackage, piletDefinition, rootDir) {
161
- var _a;
162
- return __awaiter(this, void 0, void 0, function* () {
163
- if (proposedApps) {
164
- // do nothing
165
- }
166
- else if (piletDefinition) {
167
- const availableApps = Object.keys(piletDefinition.piralInstances || {});
168
- proposedApps = availableApps.filter((m) => piletDefinition.piralInstances[m].selected);
169
- if (proposedApps.length === 0) {
170
- proposedApps = availableApps.slice(0, 1);
171
- }
172
- }
173
- else {
174
- proposedApps = [(_a = piletPackage.piral) === null || _a === void 0 ? void 0 : _a.name].filter(Boolean);
175
- }
176
- if (proposedApps.length > 0) {
177
- return Promise.all(proposedApps.map((proposedApp) => { var _a; return findPiralInstance(proposedApp, rootDir, (_a = piletDefinition === null || piletDefinition === void 0 ? void 0 : piletDefinition.piralInstances) === null || _a === void 0 ? void 0 : _a[proposedApp]); }));
141
+ async function findPiralInstances(proposedApps, piletPackage, piletDefinition, rootDir) {
142
+ if (proposedApps) {
143
+ // do nothing
144
+ }
145
+ else if (piletDefinition) {
146
+ const availableApps = Object.keys(piletDefinition.piralInstances || {});
147
+ proposedApps = availableApps.filter((m) => piletDefinition.piralInstances[m].selected);
148
+ if (proposedApps.length === 0) {
149
+ proposedApps = availableApps.slice(0, 1);
178
150
  }
179
- return [];
180
- });
151
+ }
152
+ else {
153
+ proposedApps = [piletPackage.piral?.name].filter(Boolean);
154
+ }
155
+ if (proposedApps.length > 0) {
156
+ return Promise.all(proposedApps.map((proposedApp) => findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp])));
157
+ }
158
+ return [];
181
159
  }
182
160
  exports.findPiralInstances = findPiralInstances;
183
161
  function readPiralPackage(root, name) {
@@ -186,133 +164,128 @@ function readPiralPackage(root, name) {
186
164
  return (0, io_2.readJson)(path, constants_1.packageJson);
187
165
  }
188
166
  exports.readPiralPackage = readPiralPackage;
189
- function patchPiralPackage(root, app, data, version, bundler) {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- (0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
192
- const pkg = yield getPiralPackage(app, data, version, bundler);
193
- yield (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
194
- (0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
195
- yield (0, io_2.updateExistingJson)(root, constants_2.piralJson, {
196
- $schema: constants_1.piralJsonSchemaUrl,
197
- pilets: getPiletsInfo({}),
198
- });
199
- (0, log_1.log)('generalDebug_0003', `Succesfully patched the pilet.json.`);
167
+ async function patchPiralPackage(root, app, data, version, bundler) {
168
+ (0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
169
+ const pkg = await getPiralPackage(app, data, version, bundler);
170
+ await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
171
+ (0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
172
+ await (0, io_2.updateExistingJson)(root, constants_2.piralJson, {
173
+ $schema: constants_1.piralJsonSchemaUrl,
174
+ pilets: getPiletsInfo({}),
200
175
  });
176
+ (0, log_1.log)('generalDebug_0003', `Succesfully patched the pilet.json.`);
201
177
  }
202
178
  exports.patchPiralPackage = patchPiralPackage;
203
- function getPiralPackage(app, data, version, bundler) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- const framework = data.packageName;
206
- const devDependencies = Object.assign(Object.assign({}, (0, language_1.getDevDependencies)(data.language, (0, language_2.getDevDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion))), { 'piral-cli': `${version}` });
207
- const dependencies = Object.assign(Object.assign({}, (0, language_2.getFrameworkDependencies)(framework, version)), (0, language_1.getDependencies)(data.language, (0, language_1.getDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)));
208
- yield appendBundler(devDependencies, bundler, version);
179
+ async function getPiralPackage(app, data, version, bundler) {
180
+ const framework = data.packageName;
181
+ const devDependencies = {
182
+ ...(0, language_1.getDevDependencies)(data.language, (0, language_2.getDevDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
183
+ 'piral-cli': `${version}`,
184
+ };
185
+ const dependencies = {
186
+ ...(0, language_2.getFrameworkDependencies)(framework, version),
187
+ ...(0, language_1.getDependencies)(data.language, (0, language_1.getDependencyPackages)(framework, data.reactVersion, data.reactRouterVersion)),
188
+ };
189
+ await appendBundler(devDependencies, bundler, version);
190
+ return {
191
+ app,
192
+ scripts: {
193
+ start: 'piral debug',
194
+ build: 'piral build',
195
+ postinstall: 'piral declaration',
196
+ },
197
+ types: 'dist/index.d.ts',
198
+ importmap: {
199
+ imports: {},
200
+ inherit: [
201
+ 'piral-base',
202
+ framework !== 'piral-base' && 'piral-core',
203
+ framework === 'piral' && 'piral', // this we take only if we selected piral
204
+ ].filter(Boolean),
205
+ },
206
+ dependencies,
207
+ devDependencies,
208
+ };
209
+ }
210
+ exports.getPiralPackage = getPiralPackage;
211
+ async function getAvailableFiles(root, name, dirName, fileMap) {
212
+ const source = getPiralPath(root, name);
213
+ const tgz = `${dirName}.tar`;
214
+ (0, log_1.log)('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
215
+ const exists = await (0, io_2.checkExists)((0, path_1.resolve)(source, tgz));
216
+ if (exists) {
217
+ await (0, archive_1.unpackTarball)(source, tgz);
218
+ }
219
+ (0, log_1.log)('generalDebug_0003', `Get matching files from "${source}".`);
220
+ const base = (0, path_1.resolve)(source, dirName);
221
+ const files = await (0, io_1.matchFiles)(base, '**/*');
222
+ return files.map((file) => ({
223
+ sourcePath: file,
224
+ targetPath: (0, path_1.resolve)(root, (0, path_1.relative)(base, file)),
225
+ }));
226
+ }
227
+ async function getFileStats(root, name, fileMap = []) {
228
+ const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
229
+ return await Promise.all(files.map(async (file) => {
230
+ const { sourcePath, targetPath } = file;
231
+ const sourceHash = await (0, io_1.getHash)(sourcePath);
232
+ (0, log_1.log)('generalDebug_0003', `Obtained hash from "${sourcePath}": ${sourceHash}`);
233
+ const targetHash = await (0, io_1.getHash)(targetPath);
234
+ (0, log_1.log)('generalDebug_0003', `Obtained hash from "${targetPath}": ${targetHash}`);
209
235
  return {
210
- app,
211
- scripts: {
212
- start: 'piral debug',
213
- build: 'piral build',
214
- postinstall: 'piral declaration',
215
- },
216
- types: 'dist/index.d.ts',
217
- importmap: {
218
- imports: {},
219
- inherit: [
220
- 'piral-base',
221
- framework !== 'piral-base' && 'piral-core',
222
- framework === 'piral' && 'piral', // this we take only if we selected piral
223
- ].filter(Boolean),
224
- },
225
- dependencies,
226
- devDependencies,
236
+ path: targetPath,
237
+ hash: targetHash,
238
+ changed: sourceHash !== targetHash,
227
239
  };
228
- });
240
+ }));
229
241
  }
230
- exports.getPiralPackage = getPiralPackage;
231
- function getAvailableFiles(root, name, dirName, fileMap) {
232
- return __awaiter(this, void 0, void 0, function* () {
233
- const source = getPiralPath(root, name);
234
- const tgz = `${dirName}.tar`;
235
- (0, log_1.log)('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
236
- const exists = yield (0, io_2.checkExists)((0, path_1.resolve)(source, tgz));
242
+ exports.getFileStats = getFileStats;
243
+ async function copyFiles(subfiles, forceOverwrite, originalFiles, variables) {
244
+ for (const subfile of subfiles) {
245
+ const { sourcePath, targetPath } = subfile;
246
+ const exists = await (0, io_2.checkExists)(sourcePath);
237
247
  if (exists) {
238
- yield (0, archive_1.unpackTarball)(source, tgz);
248
+ const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
249
+ const force = overwrite ? enums_1.ForceOverwrite.yes : forceOverwrite;
250
+ await (0, io_2.copy)(sourcePath, targetPath, force);
239
251
  }
240
- (0, log_1.log)('generalDebug_0003', `Get matching files from "${source}".`);
241
- const base = (0, path_1.resolve)(source, dirName);
242
- const files = yield (0, io_1.matchFiles)(base, '**/*');
243
- return files.map((file) => ({
244
- sourcePath: file,
245
- targetPath: (0, path_1.resolve)(root, (0, path_1.relative)(base, file)),
246
- }));
247
- });
248
- }
249
- function getFileStats(root, name, fileMap = []) {
250
- return __awaiter(this, void 0, void 0, function* () {
251
- const files = yield getAvailableFiles(root, name, constants_1.filesTar, fileMap);
252
- return yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
253
- const { sourcePath, targetPath } = file;
254
- const sourceHash = yield (0, io_1.getHash)(sourcePath);
255
- (0, log_1.log)('generalDebug_0003', `Obtained hash from "${sourcePath}": ${sourceHash}`);
256
- const targetHash = yield (0, io_1.getHash)(targetPath);
257
- (0, log_1.log)('generalDebug_0003', `Obtained hash from "${targetPath}": ${targetHash}`);
258
- return {
259
- path: targetPath,
260
- hash: targetHash,
261
- changed: sourceHash !== targetHash,
262
- };
263
- })));
264
- });
265
- }
266
- exports.getFileStats = getFileStats;
267
- function copyFiles(subfiles, forceOverwrite, originalFiles, variables) {
268
- return __awaiter(this, void 0, void 0, function* () {
269
- for (const subfile of subfiles) {
270
- const { sourcePath, targetPath } = subfile;
271
- const exists = yield (0, io_2.checkExists)(sourcePath);
272
- if (exists) {
273
- const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
274
- const force = overwrite ? enums_1.ForceOverwrite.yes : forceOverwrite;
275
- yield (0, io_2.copy)(sourcePath, targetPath, force);
276
- }
277
- else {
278
- (0, log_1.fail)('cannotFindFile_0046', sourcePath);
279
- }
252
+ else {
253
+ (0, log_1.fail)('cannotFindFile_0046', sourcePath);
280
254
  }
281
- });
255
+ }
282
256
  }
283
- function copyScaffoldingFiles(source, target, files, piralInfo, variables) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- (0, log_1.log)('generalDebug_0003', `Copying the scaffolding files ...`);
286
- const allFiles = [];
287
- for (const file of files) {
288
- const subfiles = yield getMatchingFiles(source, target, file);
289
- allFiles.push(...subfiles);
290
- }
291
- if (piralInfo) {
292
- yield extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
293
- }
294
- yield copyFiles(allFiles, enums_1.ForceOverwrite.yes, [], variables);
295
- });
257
+ async function copyScaffoldingFiles(source, target, files, piralInfo, variables) {
258
+ (0, log_1.log)('generalDebug_0003', `Copying the scaffolding files ...`);
259
+ const allFiles = [];
260
+ for (const file of files) {
261
+ const subfiles = await getMatchingFiles(source, target, file);
262
+ allFiles.push(...subfiles);
263
+ }
264
+ if (piralInfo) {
265
+ await extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
266
+ }
267
+ await copyFiles(allFiles, enums_1.ForceOverwrite.yes, [], variables);
296
268
  }
297
269
  exports.copyScaffoldingFiles = copyScaffoldingFiles;
298
- function extendPackageOverridesFromTemplateFragment(root, piralInfo, files) {
299
- return __awaiter(this, void 0, void 0, function* () {
300
- const packageTarget = (0, path_1.resolve)(root, constants_1.packageJson);
301
- for (let i = files.length; i--;) {
302
- const file = files[i];
303
- if (file.targetPath === packageTarget) {
304
- const fragment = yield (0, io_2.readJson)((0, path_1.dirname)(file.sourcePath), (0, path_1.basename)(file.sourcePath));
305
- files.splice(i, 1);
306
- if (!piralInfo.pilets) {
307
- piralInfo.pilets = {};
308
- }
309
- if (!piralInfo.pilets.packageOverrides) {
310
- piralInfo.pilets.packageOverrides = {};
311
- }
312
- piralInfo.pilets.packageOverrides = Object.assign(Object.assign({}, piralInfo.pilets.packageOverrides), fragment);
270
+ async function extendPackageOverridesFromTemplateFragment(root, piralInfo, files) {
271
+ const packageTarget = (0, path_1.resolve)(root, constants_1.packageJson);
272
+ for (let i = files.length; i--;) {
273
+ const file = files[i];
274
+ if (file.targetPath === packageTarget) {
275
+ const fragment = await (0, io_2.readJson)((0, path_1.dirname)(file.sourcePath), (0, path_1.basename)(file.sourcePath));
276
+ files.splice(i, 1);
277
+ if (!piralInfo.pilets) {
278
+ piralInfo.pilets = {};
313
279
  }
280
+ if (!piralInfo.pilets.packageOverrides) {
281
+ piralInfo.pilets.packageOverrides = {};
282
+ }
283
+ piralInfo.pilets.packageOverrides = {
284
+ ...piralInfo.pilets.packageOverrides,
285
+ ...fragment,
286
+ };
314
287
  }
315
- });
288
+ }
316
289
  }
317
290
  function isTemplateFileLocation(item) {
318
291
  return typeof item === 'object';
@@ -322,24 +295,22 @@ function tryFindPackageVersion(packageName) {
322
295
  const { version } = require(`${packageName}/${constants_1.packageJson}`);
323
296
  return version;
324
297
  }
325
- catch (_a) {
298
+ catch {
326
299
  return undefined;
327
300
  }
328
301
  }
329
- function copyPiralFiles(root, name, piralInfo, forceOverwrite, variables, originalFiles) {
330
- return __awaiter(this, void 0, void 0, function* () {
331
- (0, log_1.log)('generalDebug_0003', `Copying the Piral files ...`);
332
- const { files: _files } = getPiletsInfo(piralInfo);
333
- const fileMap = _files.filter(isTemplateFileLocation);
334
- const files = yield getAvailableFiles(root, name, constants_1.filesTar, fileMap);
335
- if (originalFiles === undefined) {
336
- const initialFiles = yield getAvailableFiles(root, name, constants_1.filesOnceTar, fileMap);
337
- files.push(...initialFiles);
338
- originalFiles = [];
339
- }
340
- yield extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
341
- yield copyFiles(files, forceOverwrite, originalFiles, variables);
342
- });
302
+ async function copyPiralFiles(root, name, piralInfo, forceOverwrite, variables, originalFiles) {
303
+ (0, log_1.log)('generalDebug_0003', `Copying the Piral files ...`);
304
+ const { files: _files } = getPiletsInfo(piralInfo);
305
+ const fileMap = _files.filter(isTemplateFileLocation);
306
+ const files = await getAvailableFiles(root, name, constants_1.filesTar, fileMap);
307
+ if (originalFiles === undefined) {
308
+ const initialFiles = await getAvailableFiles(root, name, constants_1.filesOnceTar, fileMap);
309
+ files.push(...initialFiles);
310
+ originalFiles = [];
311
+ }
312
+ await extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
313
+ await copyFiles(files, forceOverwrite, originalFiles, variables);
343
314
  }
344
315
  exports.copyPiralFiles = copyPiralFiles;
345
316
  function getPiletsInfo(piralInfo) {
@@ -358,27 +329,25 @@ function getPiletsInfo(piralInfo) {
358
329
  };
359
330
  }
360
331
  exports.getPiletsInfo = getPiletsInfo;
361
- function retrievePiralRoot(baseDir, entry) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- const rootDir = (0, path_1.join)(baseDir, entry);
364
- (0, log_1.log)('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
365
- if (!constants_2.declarationEntryExtensions.includes((0, path_1.extname)(rootDir).toLowerCase())) {
366
- const packageName = (0, path_1.basename)(rootDir) === constants_1.packageJson ? rootDir : (0, path_1.join)(rootDir, constants_1.packageJson);
367
- (0, log_1.log)('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
368
- const exists = yield (0, io_2.checkExists)(packageName);
369
- if (!exists) {
370
- (0, log_1.fail)('entryPointMissing_0070', rootDir);
371
- }
372
- const { app } = require(packageName);
373
- if (!app) {
374
- (0, log_1.fail)('entryPointMissing_0071');
375
- }
376
- (0, log_1.log)('generalDebug_0003', `Found app entry point in "${app}".`);
377
- return (0, path_1.join)((0, path_1.dirname)(packageName), app);
332
+ async function retrievePiralRoot(baseDir, entry) {
333
+ const rootDir = (0, path_1.join)(baseDir, entry);
334
+ (0, log_1.log)('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
335
+ if (!constants_2.declarationEntryExtensions.includes((0, path_1.extname)(rootDir).toLowerCase())) {
336
+ const packageName = (0, path_1.basename)(rootDir) === constants_1.packageJson ? rootDir : (0, path_1.join)(rootDir, constants_1.packageJson);
337
+ (0, log_1.log)('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
338
+ const exists = await (0, io_2.checkExists)(packageName);
339
+ if (!exists) {
340
+ (0, log_1.fail)('entryPointMissing_0070', rootDir);
378
341
  }
379
- (0, log_1.log)('generalDebug_0003', `Found app entry point in "${rootDir}".`);
380
- return rootDir;
381
- });
342
+ const { app } = require(packageName);
343
+ if (!app) {
344
+ (0, log_1.fail)('entryPointMissing_0071');
345
+ }
346
+ (0, log_1.log)('generalDebug_0003', `Found app entry point in "${app}".`);
347
+ return (0, path_1.join)((0, path_1.dirname)(packageName), app);
348
+ }
349
+ (0, log_1.log)('generalDebug_0003', `Found app entry point in "${rootDir}".`);
350
+ return rootDir;
382
351
  }
383
352
  exports.retrievePiralRoot = retrievePiralRoot;
384
353
  function checkArrayOrUndefined(obj, key) {
@@ -391,57 +360,52 @@ function checkArrayOrUndefined(obj, key) {
391
360
  }
392
361
  return undefined;
393
362
  }
394
- function findDependencyVersion(pckg, rootPath, dependency) {
395
- var _a;
396
- return __awaiter(this, void 0, void 0, function* () {
397
- const { devDependencies = {}, dependencies = {} } = pckg;
398
- const packageName = dependency.name;
399
- const desiredVersion = (_a = dependencies[packageName]) !== null && _a !== void 0 ? _a : devDependencies[packageName];
400
- const [parent] = dependency.parents || [];
401
- if (desiredVersion) {
402
- if ((0, npm_1.isNpmPackage)(desiredVersion)) {
403
- return desiredVersion;
404
- }
405
- else if ((0, npm_1.isGitPackage)(desiredVersion)) {
406
- return (0, npm_1.makeGitUrl)(desiredVersion);
407
- }
408
- else if ((0, npm_1.isLocalPackage)(rootPath, desiredVersion)) {
409
- return (0, npm_1.makeFilePath)(rootPath, desiredVersion);
410
- }
363
+ async function findDependencyVersion(pckg, rootPath, dependency) {
364
+ const { devDependencies = {}, dependencies = {} } = pckg;
365
+ const packageName = dependency.name;
366
+ const desiredVersion = dependencies[packageName] ?? devDependencies[packageName];
367
+ const [parent] = dependency.parents || [];
368
+ if (desiredVersion) {
369
+ if ((0, npm_1.isNpmPackage)(desiredVersion)) {
370
+ return desiredVersion;
411
371
  }
412
- if (parent) {
413
- // in case the dependency came from another package (= parent)
414
- // we should start the lookup in its directory (pnpm issue)
415
- const parentPath = (0, npm_1.tryResolvePackage)(parent, rootPath);
416
- if (parentPath) {
417
- rootPath = (0, path_1.dirname)(parentPath);
418
- }
372
+ else if ((0, npm_1.isGitPackage)(desiredVersion)) {
373
+ return (0, npm_1.makeGitUrl)(desiredVersion);
419
374
  }
420
- const version = yield findPackageVersion(rootPath, packageName);
421
- if (dependency.alias) {
422
- return (0, npm_2.makeNpmAlias)(dependency.alias, version);
375
+ else if ((0, npm_1.isLocalPackage)(rootPath, desiredVersion)) {
376
+ return (0, npm_1.makeFilePath)(rootPath, desiredVersion);
423
377
  }
424
- return version;
425
- });
378
+ }
379
+ if (parent) {
380
+ // in case the dependency came from another package (= parent)
381
+ // we should start the lookup in its directory (pnpm issue)
382
+ const parentPath = (0, npm_1.tryResolvePackage)(parent, rootPath);
383
+ if (parentPath) {
384
+ rootPath = (0, path_1.dirname)(parentPath);
385
+ }
386
+ }
387
+ const version = await findPackageVersion(rootPath, packageName);
388
+ if (dependency.alias) {
389
+ return (0, npm_2.makeNpmAlias)(dependency.alias, version);
390
+ }
391
+ return version;
426
392
  }
427
393
  exports.findDependencyVersion = findDependencyVersion;
428
- function findPackageVersion(rootPath, packageName) {
429
- return __awaiter(this, void 0, void 0, function* () {
430
- const packages = Array.isArray(packageName) ? packageName : [packageName];
431
- for (const pckg of packages) {
432
- try {
433
- (0, log_1.log)('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
434
- const moduleName = (0, external_1.getModulePath)(rootPath, pckg);
435
- const packageJsonPath = yield (0, io_2.findFile)(moduleName, constants_1.packageJson);
436
- const root = (0, path_1.dirname)(packageJsonPath);
437
- const { version } = yield (0, io_2.readJson)(root, constants_1.packageJson);
438
- return version;
439
- }
440
- catch (_a) { }
394
+ async function findPackageVersion(rootPath, packageName) {
395
+ const packages = Array.isArray(packageName) ? packageName : [packageName];
396
+ for (const pckg of packages) {
397
+ try {
398
+ (0, log_1.log)('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
399
+ const moduleName = (0, external_1.getModulePath)(rootPath, pckg);
400
+ const packageJsonPath = await (0, io_2.findFile)(moduleName, constants_1.packageJson);
401
+ const root = (0, path_1.dirname)(packageJsonPath);
402
+ const { version } = await (0, io_2.readJson)(root, constants_1.packageJson);
403
+ return version;
441
404
  }
442
- (0, log_1.log)('cannotResolveDependency_0053', packages, rootPath);
443
- return 'latest';
444
- });
405
+ catch { }
406
+ }
407
+ (0, log_1.log)('cannotResolveDependency_0053', packages, rootPath);
408
+ return 'latest';
445
409
  }
446
410
  exports.findPackageVersion = findPackageVersion;
447
411
  function flattenExternals(dependencies, disableAsync = false) {
@@ -449,51 +413,61 @@ function flattenExternals(dependencies, disableAsync = false) {
449
413
  return dependencies.map(getName).filter(utils_1.onlyUnique);
450
414
  }
451
415
  exports.flattenExternals = flattenExternals;
452
- function retrieveExternals(root, packageInfo) {
453
- var _a;
454
- return __awaiter(this, void 0, void 0, function* () {
455
- const importmap = yield (0, importmap_1.readImportmap)(root, packageInfo, 'exact', 'host');
456
- if (importmap.length === 0) {
457
- const allDeps = Object.assign(Object.assign({}, packageInfo.devDependencies), packageInfo.dependencies);
458
- const deps = (_a = packageInfo.pilets) === null || _a === void 0 ? void 0 : _a.externals;
459
- const externals = yield (0, npm_2.makeExternals)(root, allDeps, deps);
460
- return externals.map((ext) => ({
461
- id: ext,
462
- name: ext,
463
- entry: ext,
464
- type: 'local',
465
- ref: undefined,
466
- requireId: ext,
467
- }));
468
- }
469
- return importmap;
470
- });
416
+ async function retrieveExternals(root, packageInfo) {
417
+ const importmap = await (0, importmap_1.readImportmap)(root, packageInfo, 'exact', 'host');
418
+ if (importmap.length === 0) {
419
+ const allDeps = {
420
+ ...packageInfo.devDependencies,
421
+ ...packageInfo.dependencies,
422
+ };
423
+ const deps = packageInfo.pilets?.externals;
424
+ const externals = await (0, npm_2.makeExternals)(root, allDeps, deps);
425
+ return externals.map((ext) => ({
426
+ id: ext,
427
+ name: ext,
428
+ entry: ext,
429
+ type: 'local',
430
+ ref: undefined,
431
+ requireId: ext,
432
+ }));
433
+ }
434
+ return importmap;
471
435
  }
472
436
  exports.retrieveExternals = retrieveExternals;
473
- function retrievePiletsInfo(entryFile) {
474
- return __awaiter(this, void 0, void 0, function* () {
475
- const exists = yield (0, io_2.checkExists)(entryFile);
476
- if (!exists) {
477
- (0, log_1.fail)('entryPointDoesNotExist_0073', entryFile);
478
- }
479
- const packageJsonPath = yield (0, io_2.findFile)(entryFile, constants_1.packageJson);
480
- if (!packageJsonPath) {
481
- (0, log_1.fail)('packageJsonMissing_0074');
482
- }
483
- const root = (0, path_1.dirname)(packageJsonPath);
484
- const packageInfo = yield (0, io_2.readJson)(root, constants_1.packageJson);
485
- const piralJsonPkg = yield (0, io_2.readJson)(root, constants_2.piralJson);
486
- const pilets = Object.assign(Object.assign({}, getPiletsInfo(packageInfo)), piralJsonPkg.pilets);
487
- const externals = yield retrieveExternals(root, packageInfo);
488
- const dependencies = {
489
- std: packageInfo.dependencies || {},
490
- dev: packageInfo.devDependencies || {},
491
- peer: packageInfo.peerDependencies || {},
492
- };
493
- const framework = constants_2.frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
494
- return Object.assign(Object.assign({}, pilets), { externals, name: packageInfo.name, version: packageInfo.version, framework,
495
- dependencies, scripts: packageInfo.scripts, ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'), root });
496
- });
437
+ async function retrievePiletsInfo(entryFile) {
438
+ const exists = await (0, io_2.checkExists)(entryFile);
439
+ if (!exists) {
440
+ (0, log_1.fail)('entryPointDoesNotExist_0073', entryFile);
441
+ }
442
+ const packageJsonPath = await (0, io_2.findFile)(entryFile, constants_1.packageJson);
443
+ if (!packageJsonPath) {
444
+ (0, log_1.fail)('packageJsonMissing_0074');
445
+ }
446
+ const root = (0, path_1.dirname)(packageJsonPath);
447
+ const packageInfo = await (0, io_2.readJson)(root, constants_1.packageJson);
448
+ const piralJsonPkg = await (0, io_2.readJson)(root, constants_2.piralJson);
449
+ const pilets = {
450
+ ...getPiletsInfo(packageInfo),
451
+ ...piralJsonPkg.pilets,
452
+ };
453
+ const externals = await retrieveExternals(root, packageInfo);
454
+ const dependencies = {
455
+ std: packageInfo.dependencies || {},
456
+ dev: packageInfo.devDependencies || {},
457
+ peer: packageInfo.peerDependencies || {},
458
+ };
459
+ const framework = constants_2.frameworkLibs.find((lib) => lib in dependencies.std || lib in dependencies.dev);
460
+ return {
461
+ ...pilets,
462
+ externals,
463
+ name: packageInfo.name,
464
+ version: packageInfo.version,
465
+ framework,
466
+ dependencies,
467
+ scripts: packageInfo.scripts,
468
+ ignored: checkArrayOrUndefined(packageInfo, 'preservedDependencies'),
469
+ root,
470
+ };
497
471
  }
498
472
  exports.retrievePiletsInfo = retrievePiletsInfo;
499
473
  // This is an ugly workaround for having *some* packages that
@@ -518,55 +492,65 @@ function isValidDependency(name) {
518
492
  return name.indexOf('/') === -1 || (name.indexOf('@') === 0 && name.split('/').length < 3);
519
493
  }
520
494
  exports.isValidDependency = isValidDependency;
521
- function patchPiletPackage(root, piralInfo, fromEmulator, newInfo) {
522
- return __awaiter(this, void 0, void 0, function* () {
523
- (0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
524
- const pkg = yield getPiletPackage(root, piralInfo, fromEmulator, newInfo);
525
- yield (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
526
- (0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
527
- });
495
+ async function patchPiletPackage(root, piralInfo, fromEmulator, newInfo) {
496
+ (0, log_1.log)('generalDebug_0003', `Patching the ${constants_1.packageJson} in "${root}" ...`);
497
+ const pkg = await getPiletPackage(root, piralInfo, fromEmulator, newInfo);
498
+ await (0, io_2.updateExistingJson)(root, constants_1.packageJson, pkg);
499
+ (0, log_1.log)('generalDebug_0003', `Succesfully patched the ${constants_1.packageJson}.`);
528
500
  }
529
501
  exports.patchPiletPackage = patchPiletPackage;
530
- function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
531
- return __awaiter(this, void 0, void 0, function* () {
532
- const { piralCLI = { version: info_1.cliVersion } } = piralInfo;
533
- const _a = getPiletsInfo(piralInfo), { packageOverrides } = _a, info = __rest(_a, ["packageOverrides"]);
534
- const existingData = newInfo ? {} : yield (0, io_2.readJson)(root, constants_1.packageJson);
535
- const piralDependencies = Object.assign(Object.assign({}, piralInfo.devDependencies), piralInfo.dependencies);
536
- const toolVersion = piralCLI.version;
537
- const typeDependencies = newInfo ? (0, language_1.getDevDependencies)(newInfo.language) : {};
538
- const scripts = newInfo
539
- ? Object.assign({ start: 'pilet debug', build: 'pilet build', upgrade: 'pilet upgrade' }, info.scripts) : info.scripts;
540
- const allExternals = yield (0, npm_2.makePiletExternals)(root, piralDependencies, fromEmulator, piralInfo);
541
- const devDependencies = Object.assign(Object.assign(Object.assign(Object.assign({}, Object.keys(typeDependencies).reduce((deps, name) => {
502
+ async function getPiletPackage(root, piralInfo, fromEmulator, newInfo) {
503
+ const { piralCLI = { version: info_1.cliVersion } } = piralInfo;
504
+ const { packageOverrides, ...info } = getPiletsInfo(piralInfo);
505
+ const existingData = newInfo ? {} : await (0, io_2.readJson)(root, constants_1.packageJson);
506
+ const piralDependencies = {
507
+ ...piralInfo.devDependencies,
508
+ ...piralInfo.dependencies,
509
+ };
510
+ const toolVersion = piralCLI.version;
511
+ const typeDependencies = newInfo ? (0, language_1.getDevDependencies)(newInfo.language) : {};
512
+ const scripts = newInfo
513
+ ? {
514
+ start: 'pilet debug',
515
+ build: 'pilet build',
516
+ upgrade: 'pilet upgrade',
517
+ ...info.scripts,
518
+ }
519
+ : info.scripts;
520
+ const allExternals = await (0, npm_2.makePiletExternals)(root, piralDependencies, fromEmulator, piralInfo);
521
+ const devDependencies = {
522
+ ...Object.keys(typeDependencies).reduce((deps, name) => {
542
523
  deps[name] = piralDependencies[name] || typeDependencies[name];
543
524
  return deps;
544
- }, {})), Object.keys(info.devDependencies).reduce((deps, name) => {
525
+ }, {}),
526
+ ...Object.keys(info.devDependencies).reduce((deps, name) => {
545
527
  deps[name] = getDependencyVersion(name, info.devDependencies, piralDependencies);
546
528
  return deps;
547
- }, {})), allExternals.filter(isValidDependency).reduce((deps, name) => {
529
+ }, {}),
530
+ ...allExternals.filter(isValidDependency).reduce((deps, name) => {
548
531
  const existingDeps = existingData.devDependencies;
549
532
  const shouldSpecify = newInfo || (existingDeps && name in existingDeps);
550
533
  if (shouldSpecify) {
551
534
  deps[name] = piralDependencies[name] || tryFindPackageVersion(name) || 'latest';
552
535
  }
553
536
  return deps;
554
- }, {})), { ['piral-cli']: toolVersion });
555
- const dependencies = {
556
- ['piral-cli']: undefined,
557
- };
558
- if (newInfo) {
559
- yield appendBundler(devDependencies, newInfo.bundler, toolVersion);
560
- }
561
- return (0, merge_1.deepMerge)(packageOverrides, {
562
- importmap: {
563
- imports: {},
564
- inherit: [],
565
- },
566
- devDependencies,
567
- dependencies,
568
- scripts,
569
- });
537
+ }, {}),
538
+ ['piral-cli']: toolVersion,
539
+ };
540
+ const dependencies = {
541
+ ['piral-cli']: undefined,
542
+ };
543
+ if (newInfo) {
544
+ await appendBundler(devDependencies, newInfo.bundler, toolVersion);
545
+ }
546
+ return (0, merge_1.deepMerge)(packageOverrides, {
547
+ importmap: {
548
+ imports: {},
549
+ inherit: [],
550
+ },
551
+ devDependencies,
552
+ dependencies,
553
+ scripts,
570
554
  });
571
555
  }
572
556
  /**
@@ -602,55 +586,51 @@ function combinePiletExternals(appShells, peerDependencies, peerModules, importm
602
586
  return externals;
603
587
  }
604
588
  exports.combinePiletExternals = combinePiletExternals;
605
- function findPiletRoot(proposedRoot) {
606
- return __awaiter(this, void 0, void 0, function* () {
607
- const packageJsonPath = yield (0, io_2.findFile)(proposedRoot, constants_1.packageJson);
608
- if (!packageJsonPath) {
609
- (0, log_1.fail)('packageJsonMissing_0075');
610
- }
611
- return (0, path_1.dirname)(packageJsonPath);
612
- });
589
+ async function findPiletRoot(proposedRoot) {
590
+ const packageJsonPath = await (0, io_2.findFile)(proposedRoot, constants_1.packageJson);
591
+ if (!packageJsonPath) {
592
+ (0, log_1.fail)('packageJsonMissing_0075');
593
+ }
594
+ return (0, path_1.dirname)(packageJsonPath);
613
595
  }
614
596
  exports.findPiletRoot = findPiletRoot;
615
- function retrievePiletData(target, app) {
616
- return __awaiter(this, void 0, void 0, function* () {
617
- const piletJsonPath = yield (0, io_2.findFile)(target, constants_2.piletJson);
618
- const proposedRoot = piletJsonPath ? (0, path_1.dirname)(piletJsonPath) : target;
619
- const root = yield findPiletRoot(proposedRoot);
620
- const piletPackage = yield (0, io_2.readJson)(root, constants_1.packageJson);
621
- const piletDefinition = piletJsonPath && (yield (0, io_2.readJson)(proposedRoot, constants_2.piletJson));
622
- const appPackages = yield findPiralInstances(app && [app], piletPackage, piletDefinition, root);
623
- const apps = [];
624
- for (const appPackage of appPackages) {
625
- const appFile = appPackage === null || appPackage === void 0 ? void 0 : appPackage.app;
626
- const appRoot = appPackage === null || appPackage === void 0 ? void 0 : appPackage.root;
627
- const appPort = appPackage === null || appPackage === void 0 ? void 0 : appPackage.port;
628
- if (!appFile || !appRoot) {
629
- (0, log_1.fail)('appInstanceInvalid_0011');
630
- }
631
- const emulator = checkAppShellPackage(appPackage);
632
- apps.push({
633
- appPackage,
634
- appFile,
635
- appRoot,
636
- emulator,
637
- appPort,
638
- });
597
+ async function retrievePiletData(target, app) {
598
+ const piletJsonPath = await (0, io_2.findFile)(target, constants_2.piletJson);
599
+ const proposedRoot = piletJsonPath ? (0, path_1.dirname)(piletJsonPath) : target;
600
+ const root = await findPiletRoot(proposedRoot);
601
+ const piletPackage = await (0, io_2.readJson)(root, constants_1.packageJson);
602
+ const piletDefinition = piletJsonPath && (await (0, io_2.readJson)(proposedRoot, constants_2.piletJson));
603
+ const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
604
+ const apps = [];
605
+ for (const appPackage of appPackages) {
606
+ const appFile = appPackage?.app;
607
+ const appRoot = appPackage?.root;
608
+ const appPort = appPackage?.port;
609
+ if (!appFile || !appRoot) {
610
+ (0, log_1.fail)('appInstanceInvalid_0011');
639
611
  }
640
- const importmap = yield (0, importmap_1.readImportmap)(root, piletPackage, piletDefinition === null || piletDefinition === void 0 ? void 0 : piletDefinition.importmapVersions, 'remote');
641
- return {
642
- dependencies: piletPackage.dependencies || {},
643
- devDependencies: piletPackage.devDependencies || {},
644
- peerDependencies: piletPackage.peerDependencies || {},
645
- peerModules: piletPackage.peerModules || [],
646
- ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
647
- schema: piletDefinition === null || piletDefinition === void 0 ? void 0 : piletDefinition.schemaVersion,
648
- importmap,
649
- apps,
650
- piletPackage,
651
- root,
652
- };
653
- });
612
+ const emulator = checkAppShellPackage(appPackage);
613
+ apps.push({
614
+ appPackage,
615
+ appFile,
616
+ appRoot,
617
+ emulator,
618
+ appPort,
619
+ });
620
+ }
621
+ const importmap = await (0, importmap_1.readImportmap)(root, piletPackage, piletDefinition?.importmapVersions, 'remote');
622
+ return {
623
+ dependencies: piletPackage.dependencies || {},
624
+ devDependencies: piletPackage.devDependencies || {},
625
+ peerDependencies: piletPackage.peerDependencies || {},
626
+ peerModules: piletPackage.peerModules || [],
627
+ ignored: checkArrayOrUndefined(piletPackage, 'preservedDependencies'),
628
+ schema: piletDefinition?.schemaVersion,
629
+ importmap,
630
+ apps,
631
+ piletPackage,
632
+ root,
633
+ };
654
634
  }
655
635
  exports.retrievePiletData = retrievePiletData;
656
636
  //# sourceMappingURL=package.js.map