@penvhq/launcher 0.14.0 → 0.16.0

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.
package/dist/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
35
35
  DEV_PIN_VERSION: () => DEV_PIN_VERSION,
36
36
  DeclarationMissingError: () => DeclarationMissingError,
37
37
  DeclarationNotSelfContainedError: () => DeclarationNotSelfContainedError,
38
+ DeclarationReservedFieldError: () => DeclarationReservedFieldError,
38
39
  DownloadFailedError: () => DownloadFailedError,
39
40
  DownloadIntegrityError: () => DownloadIntegrityError,
40
41
  ENGINE_BIN: () => ENGINE_BIN,
@@ -87,13 +88,13 @@ __export(src_exports, {
87
88
  launcherUpdateCommand: () => launcherUpdateCommand,
88
89
  nodeSpawner: () => nodeSpawner,
89
90
  packumentUrl: () => packumentUrl,
91
+ readEnvironmentProviders: () => readEnvironmentProviders,
90
92
  readExtensionPackage: () => readExtensionPackage,
91
- readProviderEntries: () => readProviderEntries,
92
93
  readTarball: () => readTarball,
93
94
  releaseEnginePin: () => releaseEnginePin,
94
95
  renderDeclaration: () => renderDeclaration,
95
96
  runLauncher: () => runLauncher,
96
- setProviderType: () => setProviderType,
97
+ setEnvironmentProvider: () => setEnvironmentProvider,
97
98
  tarballUrl: () => tarballUrl,
98
99
  upgrade: () => upgrade,
99
100
  writeDeclaration: () => writeDeclaration
@@ -181,7 +182,7 @@ function readKey(source, index) {
181
182
  const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(index));
182
183
  return match === null ? void 0 : { key: match[0], end: index + match[0].length };
183
184
  }
184
- function typeSlotIn(source, open, close) {
185
+ function providerSlotIn(source, open, close) {
185
186
  let i = skipTrivia(source, open + 1);
186
187
  while (i < close - 1) {
187
188
  const key = readKey(source, i);
@@ -197,7 +198,7 @@ function typeSlotIn(source, open, close) {
197
198
  let valueEnd;
198
199
  if (QUOTES.has(ch)) {
199
200
  valueEnd = skipString(source, valueStart);
200
- if (key.key === "type" && ch !== "`") {
201
+ if (key.key === "provider" && ch !== "`") {
201
202
  return {
202
203
  start: valueStart,
203
204
  end: valueEnd,
@@ -220,8 +221,33 @@ function typeSlotIn(source, open, close) {
220
221
  }
221
222
  return void 0;
222
223
  }
223
- function scan(source) {
224
- const found = /(?:^|[\s{,;])providers\s*:\s*\{/.exec(source);
224
+ function blankComments(source) {
225
+ let out = "";
226
+ let i = 0;
227
+ while (i < source.length) {
228
+ const ch = source.charAt(i);
229
+ if (QUOTES.has(ch)) {
230
+ const end = skipString(source, i);
231
+ out += source.slice(i, end);
232
+ i = end;
233
+ continue;
234
+ }
235
+ if (ch === "/" && (source.charAt(i + 1) === "/" || source.charAt(i + 1) === "*")) {
236
+ const line = source.charAt(i + 1) === "/";
237
+ const found = line ? source.indexOf("\n", i) : source.indexOf("*/", i + 2);
238
+ const end = found === -1 ? source.length : line ? found : found + 2;
239
+ out += source.slice(i, end).replace(/[^\n]/g, " ");
240
+ i = end;
241
+ continue;
242
+ }
243
+ out += ch;
244
+ i += 1;
245
+ }
246
+ return out;
247
+ }
248
+ function scan(raw) {
249
+ const source = blankComments(raw);
250
+ const found = /(?:^|[\s{,;])environments\s*:\s*\{/.exec(source);
225
251
  if (found === null) {
226
252
  return void 0;
227
253
  }
@@ -242,31 +268,42 @@ function scan(source) {
242
268
  return void 0;
243
269
  }
244
270
  const entryOpen = skipTrivia(source, colon + 1);
245
- if (source.charAt(entryOpen) !== "{") {
246
- return void 0;
247
- }
248
- const entryClose = matchBrace(source, entryOpen);
249
- if (entryClose === -1) {
271
+ const ch = source.charAt(entryOpen);
272
+ let entryEnd;
273
+ let slot;
274
+ if (ch === "{") {
275
+ entryEnd = matchBrace(source, entryOpen);
276
+ if (entryEnd === -1) {
277
+ return void 0;
278
+ }
279
+ slot = providerSlotIn(source, entryOpen, entryEnd);
280
+ } else if (QUOTES.has(ch)) {
281
+ entryEnd = skipString(source, entryOpen);
282
+ slot = ch === "`" ? void 0 : {
283
+ start: entryOpen,
284
+ end: entryEnd,
285
+ value: source.slice(entryOpen + 1, entryEnd - 1)
286
+ };
287
+ } else {
250
288
  return void 0;
251
289
  }
252
- const slot = typeSlotIn(source, entryOpen, entryClose);
253
- entries.push({ environment: key.key, type: slot?.value, slot });
254
- i = skipTrivia(source, entryClose);
290
+ entries.push({ environment: key.key, provider: slot?.value, slot });
291
+ i = skipTrivia(source, entryEnd);
255
292
  if (source.charAt(i) === ",") {
256
293
  i = skipTrivia(source, i + 1);
257
294
  }
258
295
  }
259
296
  return entries;
260
297
  }
261
- function readProviderEntries(source) {
262
- return scan(source)?.map(({ environment, type }) => ({ environment, type }));
298
+ function readEnvironmentProviders(source) {
299
+ return scan(source)?.map(({ environment, provider }) => ({ environment, provider }));
263
300
  }
264
- function setProviderType(source, environment, type) {
301
+ function setEnvironmentProvider(source, environment, provider) {
265
302
  const entry = scan(source)?.find((candidate) => candidate.environment === environment);
266
303
  if (entry?.slot === void 0) {
267
304
  return void 0;
268
305
  }
269
- return `${source.slice(0, entry.slot.start)}${JSON.stringify(type)}${source.slice(entry.slot.end)}`;
306
+ return `${source.slice(0, entry.slot.start)}${JSON.stringify(provider)}${source.slice(entry.slot.end)}`;
270
307
  }
271
308
 
272
309
  // src/declaration.ts
@@ -590,6 +627,26 @@ var DeclarationNotSelfContainedError = class extends import_core.PenvError {
590
627
  );
591
628
  }
592
629
  };
630
+ var DeclarationReservedFieldError = class extends import_core.PenvError {
631
+ name = "DeclarationReservedFieldError";
632
+ constructor(name, file, field2) {
633
+ super(
634
+ "PENV_DECLARATION_RESERVED_FIELD",
635
+ `The declaration ${name} ships at \`${file}\` declares \`${field2}\`, which penv owns on every environment entry`,
636
+ `Report it to ${name}. penv reserves ${import_core.RESERVED_ENTRY_FIELDS.map((reserved) => `\`${reserved}\``).join(", ")} inside an \`environments\` entry, so a provider names its own fields in its own vocabulary \u2014 \`project\`, \`path\` \u2014 and leaves those four to penv.`
637
+ );
638
+ }
639
+ };
640
+ var DeclarationShapeUnreadableError = class extends import_core.PenvError {
641
+ name = "DeclarationShapeUnreadableError";
642
+ constructor(name, file, member) {
643
+ super(
644
+ "PENV_DECLARATION_SHAPE_UNREADABLE",
645
+ member === void 0 ? `The declaration ${name} ships at \`${file}\` has a \`ProviderConfigMap\` member penv cannot read` : `The declaration ${name} ships at \`${file}\` writes \`${member}\` as something other than an entry shape`,
646
+ `Report it to ${name}. Each \`ProviderConfigMap\` member is written as its own object literal \u2014 \`"@acme/provider-x": { readonly path: string }\` \u2014 so penv can check it names none of ${import_core.RESERVED_ENTRY_FIELDS.map((reserved) => `\`${reserved}\``).join(", ")}, which it owns on every environment entry.`
647
+ );
648
+ }
649
+ };
593
650
  var EnginePinUnreleasedError = class extends import_core.PenvError {
594
651
  name = "EnginePinUnreleasedError";
595
652
  constructor() {
@@ -646,7 +703,7 @@ var UpgradeUnattendedError = class extends import_core.PenvError {
646
703
  super(
647
704
  "PENV_UPGRADE_UNATTENDED",
648
705
  `Upgrading rewrites ${import_core.MANIFEST_PATH} and package.json, and this run has nobody to decide that`,
649
- `Run \`${UPGRADE_COMMAND} <version> ${YES_FLAG}\` \u2014 unattended, penv moves the pin only to a version you named. In CI, run \`${INSTALL_COMMAND}\`: it installs what the committed manifest already pins.`
706
+ `Run \`${UPGRADE_COMMAND} ${YES_FLAG}\` to take what \`latest\` points at, or \`${UPGRADE_COMMAND} <version> ${YES_FLAG}\` to name one. In CI, run \`${INSTALL_COMMAND}\`: it installs what the committed manifest already pins.`
650
707
  );
651
708
  }
652
709
  };
@@ -720,7 +777,7 @@ function openShape(name) {
720
777
 
721
778
  declare module "${AUGMENTATION_TARGET}" {
722
779
  interface ProviderConfigMap {
723
- ${JSON.stringify(name)}: ProviderConfig & { readonly type: ${JSON.stringify(name)} };
780
+ ${JSON.stringify(name)}: ProviderConfig & { readonly provider: ${JSON.stringify(name)} };
724
781
  }
725
782
  }
726
783
  `;
@@ -738,12 +795,166 @@ function assertSelfContained(name, file, source) {
738
795
  }
739
796
  }
740
797
  }
798
+ function endOfString(source, index) {
799
+ const quote = source.charAt(index);
800
+ let i = index + 1;
801
+ while (i < source.length) {
802
+ const ch = source.charAt(i);
803
+ if (ch === "\\") {
804
+ i += 2;
805
+ continue;
806
+ }
807
+ if (ch === quote) {
808
+ return i + 1;
809
+ }
810
+ i += 1;
811
+ }
812
+ return source.length;
813
+ }
814
+ function withoutComments(source) {
815
+ let out = "";
816
+ let i = 0;
817
+ while (i < source.length) {
818
+ const ch = source.charAt(i);
819
+ if (ch === '"' || ch === "'" || ch === "`") {
820
+ const end = endOfString(source, i);
821
+ out += source.slice(i, end);
822
+ i = end;
823
+ continue;
824
+ }
825
+ if (ch === "/" && (source.charAt(i + 1) === "/" || source.charAt(i + 1) === "*")) {
826
+ const line = source.charAt(i + 1) === "/";
827
+ const end = line ? source.indexOf("\n", i) : source.indexOf("*/", i + 2);
828
+ i = end === -1 ? source.length : line ? end : end + 2;
829
+ out += " ";
830
+ continue;
831
+ }
832
+ out += ch;
833
+ i += 1;
834
+ }
835
+ return out;
836
+ }
837
+ var RESERVED_FIELDS = [...import_core2.RESERVED_ENTRY_FIELDS].sort((a, b) => b.length - a.length);
838
+ var RESERVED_MEMBER = new RegExp(
839
+ `(?:^|[\\s;{,])(?:readonly\\s+)?(["']?)(${RESERVED_FIELDS.join("|")})\\1\\s*\\??\\s*:`
840
+ );
841
+ function endOfBrace(code, open) {
842
+ let depth = 0;
843
+ let i = open;
844
+ while (i < code.length) {
845
+ const ch = code.charAt(i);
846
+ if (ch === '"' || ch === "'" || ch === "`") {
847
+ i = endOfString(code, i);
848
+ continue;
849
+ }
850
+ if (ch === "{" || ch === "[" || ch === "(") {
851
+ depth += 1;
852
+ } else if (ch === "}" || ch === "]" || ch === ")") {
853
+ depth -= 1;
854
+ if (depth === 0) {
855
+ return i + 1;
856
+ }
857
+ }
858
+ i += 1;
859
+ }
860
+ return -1;
861
+ }
862
+ function ownMembers(body) {
863
+ let members = "";
864
+ let depth = 0;
865
+ let i = 0;
866
+ while (i < body.length) {
867
+ const ch = body.charAt(i);
868
+ if (ch === '"' || ch === "'" || ch === "`") {
869
+ const end = endOfString(body, i);
870
+ if (depth === 0) {
871
+ members += body.slice(i, end);
872
+ }
873
+ i = end;
874
+ continue;
875
+ }
876
+ if (ch === "{" || ch === "[" || ch === "(") {
877
+ depth += 1;
878
+ } else if (ch === "}" || ch === "]" || ch === ")") {
879
+ depth -= 1;
880
+ } else if (depth === 0) {
881
+ members += ch;
882
+ i += 1;
883
+ continue;
884
+ }
885
+ if (depth <= 1) {
886
+ members += " ";
887
+ }
888
+ i += 1;
889
+ }
890
+ return members;
891
+ }
892
+ var MEMBER_NAME = /^(?:readonly\s+)?(?:(["'])([^"']*)\1|([A-Za-z_$][\w$]*))\s*\??\s*:/;
893
+ function mapMembers(source) {
894
+ const code = withoutComments(source);
895
+ const map = /interface\s+ProviderConfigMap\s*\{/.exec(code);
896
+ if (map === null) {
897
+ return [];
898
+ }
899
+ const open = map.index + map[0].length - 1;
900
+ const close = endOfBrace(code, open);
901
+ if (close === -1) {
902
+ return { unreadable: void 0 };
903
+ }
904
+ const members = [];
905
+ let i = open + 1;
906
+ for (; ; ) {
907
+ while (/\s|;|,/.test(code.charAt(i))) {
908
+ i += 1;
909
+ }
910
+ if (i >= close - 1) {
911
+ return members;
912
+ }
913
+ const name = MEMBER_NAME.exec(code.slice(i, close - 1));
914
+ if (name === null) {
915
+ return { unreadable: void 0 };
916
+ }
917
+ let value = i + name[0].length;
918
+ while (/\s/.test(code.charAt(value))) {
919
+ value += 1;
920
+ }
921
+ const declared = name[2] ?? name[3] ?? "";
922
+ if (code.charAt(value) !== "{") {
923
+ return { unreadable: declared };
924
+ }
925
+ const end = endOfBrace(code, value);
926
+ if (end === -1) {
927
+ return { unreadable: declared };
928
+ }
929
+ members.push({ name: declared, body: code.slice(value + 1, end - 1) });
930
+ i = end;
931
+ while (/\s/.test(code.charAt(i))) {
932
+ i += 1;
933
+ }
934
+ if (i < close - 1 && code.charAt(i) !== ";" && code.charAt(i) !== ",") {
935
+ return { unreadable: declared };
936
+ }
937
+ }
938
+ }
939
+ function assertEntryShapesAreReadable(name, file, source) {
940
+ const members = mapMembers(source);
941
+ if (!Array.isArray(members)) {
942
+ throw new DeclarationShapeUnreadableError(name, file, members.unreadable);
943
+ }
944
+ for (const member of members) {
945
+ const field2 = RESERVED_MEMBER.exec(ownMembers(member.body))?.[2];
946
+ if (field2 !== void 0) {
947
+ throw new DeclarationReservedFieldError(name, file, field2);
948
+ }
949
+ }
950
+ }
741
951
  function renderDeclaration(subject, shipped) {
742
952
  if (shipped === void 0) {
743
953
  return `${header(subject)}
744
954
  ${openShape(subject.name)}`;
745
955
  }
746
956
  assertSelfContained(subject.name, shipped.file, shipped.source);
957
+ assertEntryShapesAreReadable(subject.name, shipped.file, shipped.source);
747
958
  const body = shipped.source.replace(/^/, "").trimEnd();
748
959
  return `${header(subject)}
749
960
  ${body}
@@ -1240,30 +1451,33 @@ function chooseEnvironments(answer, offered) {
1240
1451
  function quoted(environments) {
1241
1452
  return environments.map((environment) => `\`${environment}\``).join(", ");
1242
1453
  }
1454
+ function blindAdvice(name) {
1455
+ const spec = JSON.stringify(name);
1456
+ return `Point an environment at ${name} in penv.config.ts: \`production: ${spec}\`, or \`production: { provider: ${spec} }\` plus the provider's own fields and a \`keySource\`.`;
1457
+ }
1243
1458
  function configAdvice(name, pointing, unpointed) {
1244
- const add2 = `Add \`type: ${JSON.stringify(name)}\``;
1245
1459
  if (pointing.length === 0) {
1246
- return `${add2} to an environment in penv.config.ts.`;
1460
+ return blindAdvice(name);
1247
1461
  }
1248
- return `${quoted(pointing)} already ${pointing.length === 1 ? "points" : "point"} at ${name}. ${add2} to ${quoted(unpointed)} in penv.config.ts if ${unpointed.length === 1 ? "it" : "they"} should too.`;
1462
+ return `${quoted(pointing)} already ${pointing.length === 1 ? "points" : "point"} at ${name}. Point ${quoted(unpointed)} at it in penv.config.ts if ${unpointed.length === 1 ? "it" : "they"} should too.`;
1249
1463
  }
1250
1464
  async function offerConfigEdit(options, name, ask) {
1251
1465
  const { io, root } = options;
1252
1466
  const configFile = (0, import_core5.findConfigFile)(root);
1253
- const blind = `Add \`type: ${JSON.stringify(name)}\` to an environment in penv.config.ts.`;
1467
+ const blind = blindAdvice(name);
1254
1468
  if (configFile === void 0) {
1255
1469
  io.out(blind);
1256
1470
  return;
1257
1471
  }
1258
1472
  const shown = (0, import_node_path4.relative)(root, configFile).split(import_node_path4.sep).join("/");
1259
1473
  let current = (0, import_node_fs4.readFileSync)(configFile, "utf8");
1260
- const entries = readProviderEntries(current);
1474
+ const entries = readEnvironmentProviders(current);
1261
1475
  if (entries === void 0 || entries.length === 0) {
1262
1476
  io.out(blind);
1263
1477
  return;
1264
1478
  }
1265
- const pointing = entries.filter((entry) => entry.type === name).map((entry) => entry.environment);
1266
- const offered = entries.filter((entry) => entry.type !== name).map((entry) => entry.environment);
1479
+ const pointing = entries.filter((entry) => entry.provider === name).map((entry) => entry.environment);
1480
+ const offered = entries.filter((entry) => entry.provider !== name).map((entry) => entry.environment);
1267
1481
  if (offered.length === 0) {
1268
1482
  return;
1269
1483
  }
@@ -1282,9 +1496,9 @@ async function offerConfigEdit(options, name, ask) {
1282
1496
  return;
1283
1497
  }
1284
1498
  for (const environment of chosen) {
1285
- const next = setProviderType(current, environment, name);
1499
+ const next = setEnvironmentProvider(current, environment, name);
1286
1500
  if (next === void 0) {
1287
- io.out(`Add \`type: ${JSON.stringify(name)}\` to \`${environment}\` in ${shown}.`);
1501
+ io.out(`Add \`provider: ${JSON.stringify(name)}\` to \`${environment}\` in ${shown}.`);
1288
1502
  continue;
1289
1503
  }
1290
1504
  current = next;
@@ -1618,8 +1832,8 @@ var DEV_PIN_INTEGRITY = "sha512-development-build-not-a-published-release";
1618
1832
  var DEV_PIN_VERSION = "0.0.0-dev";
1619
1833
  var BUNDLED_ENGINE_PIN = {
1620
1834
  package: import_core8.ENGINE_PACKAGE,
1621
- version: "0.14.0",
1622
- integrity: "sha512-2EJHq5DSuqyfscjhFZmaszT4dZdYfboJJzyFwTZkJPWdcVZmXODhsqF2xtG+9U/MYojo6rmQzVlHXhVQRnooXg=="
1835
+ version: "0.16.0",
1836
+ integrity: "sha512-DSA07wrSown70tU/9ix9yozJihsQjHFPN3/iXLiH6sS6LYT+/PWBFmVI6C2tH/qaUL2GGh4mgRHL8LGM749C8Q=="
1623
1837
  };
1624
1838
  function assertReleasePin(pin) {
1625
1839
  if (pin.integrity === DEV_PIN_INTEGRITY || pin.version === DEV_PIN_VERSION) {
@@ -1717,7 +1931,7 @@ async function upgrade(options) {
1717
1931
  if (options.noDownload === true) {
1718
1932
  throw new UpgradeNoDownloadError();
1719
1933
  }
1720
- if ((options.ci === true || !io.interactive) && !(request.yes && request.version !== void 0)) {
1934
+ if ((options.ci === true || !io.interactive) && !request.yes) {
1721
1935
  throw new UpgradeUnattendedError();
1722
1936
  }
1723
1937
  const release = await fetchRelease({
@@ -2047,6 +2261,7 @@ async function delegate(options, engine, forwarded, home, cwd) {
2047
2261
  DEV_PIN_VERSION,
2048
2262
  DeclarationMissingError,
2049
2263
  DeclarationNotSelfContainedError,
2264
+ DeclarationReservedFieldError,
2050
2265
  DownloadFailedError,
2051
2266
  DownloadIntegrityError,
2052
2267
  ENGINE_BIN,
@@ -2099,13 +2314,13 @@ async function delegate(options, engine, forwarded, home, cwd) {
2099
2314
  launcherUpdateCommand,
2100
2315
  nodeSpawner,
2101
2316
  packumentUrl,
2317
+ readEnvironmentProviders,
2102
2318
  readExtensionPackage,
2103
- readProviderEntries,
2104
2319
  readTarball,
2105
2320
  releaseEnginePin,
2106
2321
  renderDeclaration,
2107
2322
  runLauncher,
2108
- setProviderType,
2323
+ setEnvironmentProvider,
2109
2324
  tarballUrl,
2110
2325
  upgrade,
2111
2326
  writeDeclaration