@sortlist/cli 0.59.0 → 0.60.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.js CHANGED
@@ -1148,6 +1148,26 @@ function browserCandidates({ platform, env, home }) {
1148
1148
  function isSandboxedPackage(browserPath) {
1149
1149
  return /^\/(snap|var\/lib\/flatpak|var\/lib\/snapd)\//.test(browserPath);
1150
1150
  }
1151
+ function launchesSandboxedPackage(script) {
1152
+ return script.startsWith("#!") && /\/snap\/bin\/|\bflatpak run\b/.test(script);
1153
+ }
1154
+ function isSandboxed(browserPath) {
1155
+ const real = realPath(browserPath);
1156
+ return isSandboxedPackage(browserPath) || isSandboxedPackage(real) || launchesSandboxedPackage(leadingText(real));
1157
+ }
1158
+ function leadingText(file) {
1159
+ let descriptor = null;
1160
+ try {
1161
+ descriptor = fs6.openSync(file, "r");
1162
+ const buffer = Buffer.alloc(16384);
1163
+ const length = fs6.readSync(descriptor, buffer, 0, buffer.length, 0);
1164
+ return buffer.subarray(0, length).toString("latin1");
1165
+ } catch {
1166
+ return "";
1167
+ } finally {
1168
+ if (descriptor !== null) fs6.closeSync(descriptor);
1169
+ }
1170
+ }
1151
1171
  function installedBrowsers(current = { platform: process.platform, env: process.env, home: os4.homedir() }) {
1152
1172
  const exists = (file) => fs6.existsSync(file);
1153
1173
  const playwrightCaches = [
@@ -1160,10 +1180,10 @@ function installedBrowsers(current = { platform: process.platform, env: process.
1160
1180
  ...browserCandidates(current),
1161
1181
  ...playwrightCaches.flatMap((cache) => playwrightChromes(cache, exists))
1162
1182
  ].filter((candidate) => candidate != null && candidate !== "" && exists(candidate));
1163
- const resolved2 = [...new Set(candidates)].map((candidate) => ({ candidate, real: realPath(candidate) }));
1183
+ const resolved2 = [...new Set(candidates)].map((candidate) => ({ candidate, sandboxed: isSandboxed(candidate) }));
1164
1184
  return {
1165
- usable: resolved2.filter(({ real }) => !isSandboxedPackage(real)).map(({ candidate }) => candidate),
1166
- sandboxed: resolved2.filter(({ real }) => isSandboxedPackage(real)).map(({ candidate }) => candidate)
1185
+ usable: resolved2.filter(({ sandboxed }) => !sandboxed).map(({ candidate }) => candidate),
1186
+ sandboxed: resolved2.filter(({ sandboxed }) => sandboxed).map(({ candidate }) => candidate)
1167
1187
  };
1168
1188
  }
1169
1189
  function realPath(file) {
@@ -1247,7 +1267,7 @@ async function launch(browsers) {
1247
1267
  browser.on("error", () => {
1248
1268
  });
1249
1269
  const port = await debuggingPort(profile);
1250
- if (port != null) return { browser, profile, port };
1270
+ if (port != null) return { browser, browserPath, profile, port };
1251
1271
  await stopBrowser(browser, profile);
1252
1272
  }
1253
1273
  return null;
@@ -1255,13 +1275,13 @@ async function launch(browsers) {
1255
1275
  async function captureLinkedinSession(options) {
1256
1276
  const launched = await launch(options.browsers);
1257
1277
  if (launched == null) return { kind: "no-browser" };
1258
- const { browser, profile, port } = launched;
1278
+ const { browser, browserPath, profile, port } = launched;
1259
1279
  let connection = null;
1260
1280
  let linkedinCookies = 0;
1261
1281
  try {
1262
1282
  const version = await (await fetch(`http://127.0.0.1:${port}/json/version`)).json();
1263
1283
  connection = await connectDevtools(version.webSocketDebuggerUrl);
1264
- options.onOpened();
1284
+ options.onOpened(browserPath);
1265
1285
  const deadline = Date.now() + options.timeoutSeconds * 1e3;
1266
1286
  while (Date.now() < deadline) {
1267
1287
  await sleep(2e3);
@@ -1357,9 +1377,9 @@ var connectLinkedinCommand = new Command2("connect-linkedin").summary("Sign a Li
1357
1377
  const outcome = await captureLinkedinSession({
1358
1378
  browsers: usable,
1359
1379
  timeoutSeconds: (Number.isFinite(timeoutMinutes) && timeoutMinutes > 0 ? timeoutMinutes : 10) * 60,
1360
- onOpened: () => {
1380
+ onOpened: (browserPath) => {
1361
1381
  info(
1362
- `A browser window is open on linkedin.com/login. Sign in there (waiting up to ${timeoutMinutes} minutes).`
1382
+ `A ${browserPath} window is open on linkedin.com/login. Sign in there (waiting up to ${timeoutMinutes} minutes).`
1363
1383
  );
1364
1384
  }
1365
1385
  });