@picked/vite-plugin-picked 0.0.1-dev.1789541668638 → 0.0.45

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/esm/index.js CHANGED
@@ -1,782 +1,25 @@
1
- import { existsSync as e } from "node:fs";
2
- import { join as t, resolve as n } from "node:path";
3
- import { createClientHeaders as r, fetchExperienceContent as i, fetchProject as a } from "@picked/delivery-api-client";
4
- import { generate as o } from "@picked/typegen";
5
- import { detectHostEnvironment as s, isTelemetryEnabled as c, isTelemetryForcedOffByEnvironment as l, loadPickedConfig as u, loadResolvedPickedConfig as d } from "@picked/config";
6
- import { appendFile as f, mkdir as p, readFile as m, writeFile as h } from "node:fs/promises";
7
- import { createSpanId as g, createTelemetryEmitter as _, createTraceId as v, toUnixNano as y } from "@picked/telemetry";
8
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/taggedTemplateLiteral.js
9
- function b(e, t) {
10
- return t ||= e.slice(0), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
11
- }
12
- //#endregion
13
- //#region src/launcher.ts
14
- var x, S = ["true", "false"], C = "false";
15
- function w(e) {
16
- let t = e.variants;
17
- return !t || t.length === 0 ? S : t.map((e) => String(e.value));
18
- }
19
- function T(e) {
20
- let t = w(e), n = Math.max(0, t.findIndex((e) => e !== C));
21
- return t.map((e, t) => `<option value="${O(e)}"${t === n ? " selected" : ""}>${D(e)}</option>`).join("");
22
- }
23
- function E(e) {
24
- let t = JSON.stringify(e).replaceAll("<", String.raw`\u003c`), n = e.length > 0 ? e.map((e) => `
25
- <div class="feature-row">
26
- <label>
27
- <input type="checkbox" data-feature-id="${O(e.id)}" checked>
28
- <span class="feature-name">${D(e.name)}</span>
29
- <span class="feature-id">${D(e.id)}</span>
30
- </label>
31
- <select data-value-for="${O(e.id)}">
32
- ${T(e)}
33
- </select>
34
- </div>`).join("") : "<p class=\"text no-features\">No features configured for this project.</p>";
35
- return String.raw(x ||= b([
36
- "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"robots\" content=\"noindex, nofollow\">\n <title>Picked</title>\n <style>\n main {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: grid;\n align-items: center;\n justify-content: center;\n font-family: monospace;\n color: #4A4A4A\n }\n\n .wrap {\n padding-left: 1.5rem;\n padding-right: 1.5rem;\n max-width: 480px;\n width: 100%;\n }\n\n .title {\n font-size: 1.125rem;\n font-weight: 700;\n margin-bottom: 0;\n }\n\n .text {\n margin-top: .5rem;\n font-size: .875rem\n }\n\n .text a {\n color: #4A4A4A;\n text-decoration: none;\n }\n\n .text a:hover {\n cursor: pointer;\n text-decoration: underline\n }\n\n .preview-form {\n margin-top: 2rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n }\n\n .preview-input {\n padding: 0.5rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n font-family: monospace;\n }\n\n .preview-button {\n padding: 0.5rem;\n background: #4A4A4A;\n color: white;\n border: none;\n border-radius: 0;\n cursor: pointer;\n font-family: monospace;\n }\n\n .preview-button:hover {\n opacity: 0.9;\n }\n\n .buttons {\n display: grid;\n gap: 0.5em;\n grid-template-columns: 1fr 1fr;\n }\n\n #copy-status {\n font-size: 1em;\n text-align: right;\n margin-top: 0.5em;\n }\n\n .features-section {\n margin-top: 1.5rem;\n }\n\n .features-label {\n font-weight: 700;\n font-size: .875rem;\n margin-bottom: 0.5rem;\n }\n\n .feature-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.5rem;\n padding: 0.25rem 0;\n }\n\n .feature-row label {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n cursor: pointer;\n min-width: 0;\n flex: 1;\n }\n\n .feature-name {\n font-size: .875rem;\n }\n\n .feature-id {\n font-size: .75rem;\n color: #888;\n }\n\n .feature-row select {\n font-family: monospace;\n font-size: .75rem;\n padding: 0.125rem 0.25rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n background: white;\n flex-shrink: 0;\n }\n\n .no-features {\n color: #888;\n font-style: italic;\n }\n\n .url-history {\n margin-top: 0.5rem;\n font-size: .75rem;\n }\n\n .url-history-item {\n display: flex;\n align-items: center;\n gap: 0.25rem;\n padding: 0.125rem 0;\n }\n\n .url-history-item button {\n background: none;\n border: none;\n cursor: pointer;\n font-family: monospace;\n font-size: .75rem;\n color: #888;\n padding: 0;\n }\n\n .url-history-item button.url-link {\n color: #4A4A4A;\n text-decoration: none;\n text-align: left;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n flex: 1;\n min-width: 0;\n }\n\n .url-history-item button.url-link:hover {\n text-decoration: underline;\n }\n\n .url-history-item button.url-delete:hover {\n color: #b71c1c;\n }\n\n @media (min-width: 640px) {\n .title {\n font-size: 1.25rem\n }\n\n .text {\n font-size: 1rem\n }\n }\n </style>\n</head>\n<body>\n\n<main>\n <div class=\"wrap\">\n <p class=\"title\">Picked</p>\n <p class=\"text\">\n Learn more at\n <a href=\"https://picked.app\">\n https://picked.app\n </a>\n </p>\n <div class=\"preview-form\">\n <input type=\"text\" id=\"url-input\" pattern=\"^(https?://)?.+\" placeholder=\"Enter preview URL\" required\n class=\"preview-input\">\n <div id=\"url-history\" class=\"url-history\"></div>\n <div class=\"features-section\">\n <p class=\"features-label\">Features</p>\n ",
37
- "\n </div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"preview-button\" id=\"copy-btn\">Copy</button>\n <button type=\"button\" class=\"preview-button\" id=\"preview-btn\">Preview</button>\n </div>\n <p class=\"text\" id=\"copy-status\" aria-live=\"polite\" style=\"visibility:hidden;\">\n &nbsp;\n </p>\n </div>\n </div>\n\n <script>\n var FEATURES = ",
38
- ";\n var STORAGE_KEY_URL = 'picked-launcher-url';\n var STORAGE_KEY_HISTORY = 'picked-launcher-history';\n var STORAGE_KEY_SELECTIONS = 'picked-launcher-selections';\n\n function getUrlInput() {\n return document.getElementById('url-input');\n }\n\n // URL history\n function getHistory() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_HISTORY);\n if (!raw) return [];\n var parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch (e) {\n return [];\n }\n }\n\n function saveHistory(history) {\n localStorage.setItem(STORAGE_KEY_HISTORY, JSON.stringify(history));\n }\n\n function addToHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n history.unshift(url);\n if (history.length > 10) history = history.slice(0, 10);\n saveHistory(history);\n renderHistory();\n }\n\n function removeFromHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n saveHistory(history);\n renderHistory();\n }\n\n function renderHistory() {\n var container = document.getElementById('url-history');\n if (!container) return;\n var history = getHistory();\n if (history.length === 0) {\n container.innerHTML = '';\n return;\n }\n container.innerHTML = history.map(function(url) {\n return '<div class=\"url-history-item\">' +\n '<button type=\"button\" class=\"url-link\" data-history-url=\"' + escapeAttr(url) + '\">' + escapeHtml(url) + '</button>' +\n '<button type=\"button\" class=\"url-delete\" data-history-delete=\"' + escapeAttr(url) + '\">x</button>' +\n '</div>';\n }).join('');\n }\n\n // Feature selection persistence\n function getSelections() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_SELECTIONS);\n if (!raw) return {};\n var parsed = JSON.parse(raw);\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch (e) {\n return {};\n }\n }\n\n function saveSelections() {\n var selections = {};\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && select) {\n selections[f.id] = { checked: checkbox.checked, value: select.value };\n }\n });\n localStorage.setItem(STORAGE_KEY_SELECTIONS, JSON.stringify(selections));\n }\n\n function restoreSelections() {\n var selections = getSelections();\n FEATURES.forEach(function(f) {\n var saved = selections[f.id];\n if (!saved) return;\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox) checkbox.checked = saved.checked;\n if (select) select.value = saved.value;\n });\n }\n\n function escapeHtml(str) {\n var div = document.createElement('div');\n div.textContent = str;\n return div.innerHTML;\n }\n\n function escapeAttr(str) {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n\n function buildTargetUrl(inputValue) {\n var value = inputValue;\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n value = 'https://' + value;\n }\n var hostname = window.location.hostname;\n var subdomain = hostname.split('.').length > 2 ? hostname.split('.')[0] : '';\n var target = value;\n var sep = target.includes('?') ? '&' : '?';\n if (subdomain) {\n target = target + sep + 'cvly_env=' + encodeURIComponent(subdomain);\n sep = '&';\n }\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && checkbox.checked && select) {\n target = target + sep + 'picked-feature=' + encodeURIComponent(f.id + ':' + select.value);\n sep = '&';\n }\n });\n return target;\n }\n\n function showCopyStatus(message, success) {\n var el = document.getElementById('copy-status');\n if (!el) return;\n el.textContent = message;\n el.style.visibility = 'visible';\n el.style.color = success ? '#2e7d32' : '#b71c1c';\n setTimeout(function() {\n el.style.visibility = 'hidden';\n }, 2000);\n }\n\n // Init\n window.addEventListener('load', function() {\n var input = getUrlInput();\n var savedUrl = localStorage.getItem(STORAGE_KEY_URL);\n if (savedUrl && input) {\n input.value = savedUrl;\n }\n renderHistory();\n restoreSelections();\n });\n\n // Delegate click events\n document.addEventListener('click', function(e) {\n var target = e.target;\n\n // History URL click\n var historyUrl = target.getAttribute('data-history-url');\n if (historyUrl) {\n var input = getUrlInput();\n if (input) input.value = historyUrl;\n return;\n }\n\n // History delete click\n var deleteUrl = target.getAttribute('data-history-delete');\n if (deleteUrl) {\n removeFromHistory(deleteUrl);\n return;\n }\n });\n\n // Feature change persistence\n document.addEventListener('change', function(e) {\n var target = e.target;\n if (target.getAttribute('data-feature-id') || target.getAttribute('data-value-for')) {\n saveSelections();\n }\n });\n\n // Copy button\n document.getElementById('copy-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n navigator.clipboard.writeText(target).then(function() {\n showCopyStatus('Preview URL copied to clipboard', true);\n });\n });\n\n // Preview button\n document.getElementById('preview-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n window.location.href = target;\n });\n <\/script>\n</main>\n</body>\n</html>"
39
- ], [
40
- "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"robots\" content=\"noindex, nofollow\">\n <title>Picked</title>\n <style>\n main {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: grid;\n align-items: center;\n justify-content: center;\n font-family: monospace;\n color: #4A4A4A\n }\n\n .wrap {\n padding-left: 1.5rem;\n padding-right: 1.5rem;\n max-width: 480px;\n width: 100%;\n }\n\n .title {\n font-size: 1.125rem;\n font-weight: 700;\n margin-bottom: 0;\n }\n\n .text {\n margin-top: .5rem;\n font-size: .875rem\n }\n\n .text a {\n color: #4A4A4A;\n text-decoration: none;\n }\n\n .text a:hover {\n cursor: pointer;\n text-decoration: underline\n }\n\n .preview-form {\n margin-top: 2rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n }\n\n .preview-input {\n padding: 0.5rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n font-family: monospace;\n }\n\n .preview-button {\n padding: 0.5rem;\n background: #4A4A4A;\n color: white;\n border: none;\n border-radius: 0;\n cursor: pointer;\n font-family: monospace;\n }\n\n .preview-button:hover {\n opacity: 0.9;\n }\n\n .buttons {\n display: grid;\n gap: 0.5em;\n grid-template-columns: 1fr 1fr;\n }\n\n #copy-status {\n font-size: 1em;\n text-align: right;\n margin-top: 0.5em;\n }\n\n .features-section {\n margin-top: 1.5rem;\n }\n\n .features-label {\n font-weight: 700;\n font-size: .875rem;\n margin-bottom: 0.5rem;\n }\n\n .feature-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.5rem;\n padding: 0.25rem 0;\n }\n\n .feature-row label {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n cursor: pointer;\n min-width: 0;\n flex: 1;\n }\n\n .feature-name {\n font-size: .875rem;\n }\n\n .feature-id {\n font-size: .75rem;\n color: #888;\n }\n\n .feature-row select {\n font-family: monospace;\n font-size: .75rem;\n padding: 0.125rem 0.25rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n background: white;\n flex-shrink: 0;\n }\n\n .no-features {\n color: #888;\n font-style: italic;\n }\n\n .url-history {\n margin-top: 0.5rem;\n font-size: .75rem;\n }\n\n .url-history-item {\n display: flex;\n align-items: center;\n gap: 0.25rem;\n padding: 0.125rem 0;\n }\n\n .url-history-item button {\n background: none;\n border: none;\n cursor: pointer;\n font-family: monospace;\n font-size: .75rem;\n color: #888;\n padding: 0;\n }\n\n .url-history-item button.url-link {\n color: #4A4A4A;\n text-decoration: none;\n text-align: left;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n flex: 1;\n min-width: 0;\n }\n\n .url-history-item button.url-link:hover {\n text-decoration: underline;\n }\n\n .url-history-item button.url-delete:hover {\n color: #b71c1c;\n }\n\n @media (min-width: 640px) {\n .title {\n font-size: 1.25rem\n }\n\n .text {\n font-size: 1rem\n }\n }\n </style>\n</head>\n<body>\n\n<main>\n <div class=\"wrap\">\n <p class=\"title\">Picked</p>\n <p class=\"text\">\n Learn more at\n <a href=\"https://picked.app\">\n https://picked.app\n </a>\n </p>\n <div class=\"preview-form\">\n <input type=\"text\" id=\"url-input\" pattern=\"^(https?:\\/\\/)?.+\" placeholder=\"Enter preview URL\" required\n class=\"preview-input\">\n <div id=\"url-history\" class=\"url-history\"></div>\n <div class=\"features-section\">\n <p class=\"features-label\">Features</p>\n ",
41
- "\n </div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"preview-button\" id=\"copy-btn\">Copy</button>\n <button type=\"button\" class=\"preview-button\" id=\"preview-btn\">Preview</button>\n </div>\n <p class=\"text\" id=\"copy-status\" aria-live=\"polite\" style=\"visibility:hidden;\">\n &nbsp;\n </p>\n </div>\n </div>\n\n <script>\n var FEATURES = ",
42
- ";\n var STORAGE_KEY_URL = 'picked-launcher-url';\n var STORAGE_KEY_HISTORY = 'picked-launcher-history';\n var STORAGE_KEY_SELECTIONS = 'picked-launcher-selections';\n\n function getUrlInput() {\n return document.getElementById('url-input');\n }\n\n // URL history\n function getHistory() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_HISTORY);\n if (!raw) return [];\n var parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch (e) {\n return [];\n }\n }\n\n function saveHistory(history) {\n localStorage.setItem(STORAGE_KEY_HISTORY, JSON.stringify(history));\n }\n\n function addToHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n history.unshift(url);\n if (history.length > 10) history = history.slice(0, 10);\n saveHistory(history);\n renderHistory();\n }\n\n function removeFromHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n saveHistory(history);\n renderHistory();\n }\n\n function renderHistory() {\n var container = document.getElementById('url-history');\n if (!container) return;\n var history = getHistory();\n if (history.length === 0) {\n container.innerHTML = '';\n return;\n }\n container.innerHTML = history.map(function(url) {\n return '<div class=\"url-history-item\">' +\n '<button type=\"button\" class=\"url-link\" data-history-url=\"' + escapeAttr(url) + '\">' + escapeHtml(url) + '</button>' +\n '<button type=\"button\" class=\"url-delete\" data-history-delete=\"' + escapeAttr(url) + '\">x</button>' +\n '</div>';\n }).join('');\n }\n\n // Feature selection persistence\n function getSelections() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_SELECTIONS);\n if (!raw) return {};\n var parsed = JSON.parse(raw);\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch (e) {\n return {};\n }\n }\n\n function saveSelections() {\n var selections = {};\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && select) {\n selections[f.id] = { checked: checkbox.checked, value: select.value };\n }\n });\n localStorage.setItem(STORAGE_KEY_SELECTIONS, JSON.stringify(selections));\n }\n\n function restoreSelections() {\n var selections = getSelections();\n FEATURES.forEach(function(f) {\n var saved = selections[f.id];\n if (!saved) return;\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox) checkbox.checked = saved.checked;\n if (select) select.value = saved.value;\n });\n }\n\n function escapeHtml(str) {\n var div = document.createElement('div');\n div.textContent = str;\n return div.innerHTML;\n }\n\n function escapeAttr(str) {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n\n function buildTargetUrl(inputValue) {\n var value = inputValue;\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n value = 'https://' + value;\n }\n var hostname = window.location.hostname;\n var subdomain = hostname.split('.').length > 2 ? hostname.split('.')[0] : '';\n var target = value;\n var sep = target.includes('?') ? '&' : '?';\n if (subdomain) {\n target = target + sep + 'cvly_env=' + encodeURIComponent(subdomain);\n sep = '&';\n }\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && checkbox.checked && select) {\n target = target + sep + 'picked-feature=' + encodeURIComponent(f.id + ':' + select.value);\n sep = '&';\n }\n });\n return target;\n }\n\n function showCopyStatus(message, success) {\n var el = document.getElementById('copy-status');\n if (!el) return;\n el.textContent = message;\n el.style.visibility = 'visible';\n el.style.color = success ? '#2e7d32' : '#b71c1c';\n setTimeout(function() {\n el.style.visibility = 'hidden';\n }, 2000);\n }\n\n // Init\n window.addEventListener('load', function() {\n var input = getUrlInput();\n var savedUrl = localStorage.getItem(STORAGE_KEY_URL);\n if (savedUrl && input) {\n input.value = savedUrl;\n }\n renderHistory();\n restoreSelections();\n });\n\n // Delegate click events\n document.addEventListener('click', function(e) {\n var target = e.target;\n\n // History URL click\n var historyUrl = target.getAttribute('data-history-url');\n if (historyUrl) {\n var input = getUrlInput();\n if (input) input.value = historyUrl;\n return;\n }\n\n // History delete click\n var deleteUrl = target.getAttribute('data-history-delete');\n if (deleteUrl) {\n removeFromHistory(deleteUrl);\n return;\n }\n });\n\n // Feature change persistence\n document.addEventListener('change', function(e) {\n var target = e.target;\n if (target.getAttribute('data-feature-id') || target.getAttribute('data-value-for')) {\n saveSelections();\n }\n });\n\n // Copy button\n document.getElementById('copy-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n navigator.clipboard.writeText(target).then(function() {\n showCopyStatus('Preview URL copied to clipboard', true);\n });\n });\n\n // Preview button\n document.getElementById('preview-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n window.location.href = target;\n });\n <\/script>\n</main>\n</body>\n</html>"
43
- ]), n, t);
44
- }
45
- function D(e) {
46
- return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
47
- }
48
- function O(e) {
49
- return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
50
- }
51
- //#endregion
52
- //#region src/log.ts
53
- var k = "picked", ee = "\x1B[0m";
54
- function te() {
55
- let e = process.env.NO_COLOR;
56
- return e === "1" || e === "true";
57
- }
58
- function A(e) {
59
- return (t) => te() ? t : `${e}${t}${ee}`;
60
- }
61
- var j = [
62
- "debug",
63
- "info",
64
- "warn",
65
- "error",
66
- "silent"
67
- ], M = {
68
- debug: {
69
- color: A("\x1B[2m"),
70
- log: console.debug,
71
- enabled: !1
72
- },
73
- info: {
74
- color: A("\x1B[36m"),
75
- log: console.log,
76
- enabled: !0
77
- },
78
- warn: {
79
- color: A("\x1B[33m"),
80
- log: console.warn,
81
- enabled: !0
82
- },
83
- error: {
84
- color: A("\x1B[31m"),
85
- log: console.error,
86
- enabled: !0
87
- },
88
- silent: {
89
- log: () => {},
90
- enabled: !1
91
- }
1
+ import { fetchProject as t } from "@picked/client/plugins/dynamic-experiences";
2
+ import { createLogger as f } from "vite";
3
+ const i = "https://api.picked.app", n = "__PICKED_PROJECT_CONFIG__";
4
+ function d(c) {
5
+ const r = c.apiUrl ?? i, e = f("info", { prefix: "[picked]" });
6
+ return {
7
+ name: "picked",
8
+ config: async () => {
9
+ e.info(`Fetching project config for "${c.projectId}" from ${r}`);
10
+ const o = await t(r, c.projectId);
11
+ if (!o) {
12
+ e.warn(`Failed to fetch project config for "${c.projectId}"`);
13
+ return;
14
+ }
15
+ return e.info(`Project config fetched successfully for "${c.projectId}"`), {
16
+ define: {
17
+ [n]: JSON.stringify(o)
18
+ }
19
+ };
20
+ }
21
+ };
22
+ }
23
+ export {
24
+ d as picked
92
25
  };
93
- function ne(e, t) {
94
- return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${k}:${t}` : k}] ${e}`;
95
- }
96
- function N(e, t, n, r) {
97
- if (!e.enabled) return;
98
- let i = ne(t, r);
99
- e.log(e.color ? e.color(i) : i), n !== void 0 && e.log(n);
100
- }
101
- function P(e) {
102
- let t = M[e], n = /* @__PURE__ */ new Set();
103
- return Object.assign((e, n, r) => {
104
- N(t, e, n, r);
105
- }, { once(e, r, i) {
106
- !t.enabled || n.has(e) || (n.add(e), N(t, e, r, i));
107
- } });
108
- }
109
- function re(e) {
110
- let t = j.indexOf(e);
111
- if (t === -1) {
112
- N(M.error, `invalid log level: ${e}`);
113
- return;
114
- }
115
- for (let [e, n] of j.entries()) M[n].enabled = e >= t;
116
- }
117
- var F = A("\x1B[34m"), ie = A("\x1B[36m");
118
- function ae() {
119
- let e = [
120
- ` ${F("_")} ${ie("_")} _ _ _`,
121
- `${F("(_)")} ${ie("(_)")} _ __(_)__| |_____ __| |`,
122
- ` ${F("_")} ${F("_")} | '_ \\ / _| / / -_) _\` |`,
123
- `${F("(_)")} ${F("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
124
- " |_|\n "
125
- ];
126
- console.log(e.join("\n"));
127
- }
128
- var I = {
129
- banner: ae,
130
- debug: P("debug"),
131
- info: P("info"),
132
- warn: P("warn"),
133
- error: P("error"),
134
- setLevel: re
135
- };
136
- //#endregion
137
- //#region src/middleware.ts
138
- function oe(e) {
139
- return (t, n, r) => {
140
- if (t.method !== "GET") {
141
- r();
142
- return;
143
- }
144
- let i = (t.url ?? "").split("?")[0];
145
- if (i !== "/" && i !== "/index.html") {
146
- r();
147
- return;
148
- }
149
- let a = e();
150
- n.setHeader("Content-Type", "text/html"), n.statusCode = 200, n.end(a);
151
- };
152
- }
153
- //#endregion
154
- //#region src/gitignore.ts
155
- var L = ".picked/";
156
- async function se(n, r) {
157
- if (r) return;
158
- let i = t(n, ".gitignore");
159
- if (!e(i)) {
160
- await h(i, `${L}
161
- `);
162
- return;
163
- }
164
- let a = await m(i, "utf8");
165
- if (ce(a)) return;
166
- let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${L}
167
- `;
168
- await f(i, o);
169
- }
170
- function ce(e) {
171
- return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === L || e === ".picked");
172
- }
173
- //#endregion
174
- //#region src/retry.ts
175
- var R = 6, le = 5e3;
176
- function z(e) {
177
- let t;
178
- try {
179
- t = new URL(e).hostname;
180
- } catch {
181
- return !1;
182
- }
183
- return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "[::1]" || t !== "api.picked.app" && t.endsWith(".picked.app");
184
- }
185
- function ue(e) {
186
- return new Promise((t) => {
187
- setTimeout(t, e);
188
- });
189
- }
190
- async function B(e, t) {
191
- let n = null, r = null;
192
- try {
193
- n = await e();
194
- } catch (e) {
195
- r = e;
196
- }
197
- if (n !== null) return n;
198
- for (let i = 1; i <= R; i++) {
199
- let a = le * 2 ** (i - 1);
200
- t(i, R, a), await ue(a), r = null;
201
- try {
202
- n = await e();
203
- } catch (e) {
204
- r = e;
205
- }
206
- if (n !== null) return n;
207
- }
208
- if (r !== null) throw r;
209
- return null;
210
- }
211
- //#endregion
212
- //#region src/util.ts
213
- function V(e) {
214
- return Array.isArray(e) ? e : [];
215
- }
216
- function de(e) {
217
- let t = e.variants, n = (t ?? []).reduce((e, t) => e + t.weight, 0);
218
- return !t || t.length === 0 || n === 0 ? `${e.weight.toString()}%` : t.map((e) => {
219
- let t = Math.round(100 * e.weight / n);
220
- return `${String(e.value)} ${t.toString()}%`;
221
- }).join(", ");
222
- }
223
- //#endregion
224
- //#region src/prefetch.ts
225
- var H = 2;
226
- function U(e) {
227
- let n = t(e, ".picked");
228
- return {
229
- pickedDir: n,
230
- manifestPath: t(n, "manifest.json"),
231
- projectConfigPath: t(n, "project-config.json"),
232
- experiencesDir: t(n, "experiences")
233
- };
234
- }
235
- async function fe(t) {
236
- if (!e(t)) return null;
237
- try {
238
- let e = await m(t, "utf8"), n = JSON.parse(e);
239
- return pe(n) ? n : null;
240
- } catch {
241
- return null;
242
- }
243
- }
244
- function pe(e) {
245
- return !(typeof e != "object" || !e || !("version" in e) || typeof e.version != "number" || !("projectVersionId" in e) || typeof e.projectVersionId != "string" || !("workspaceId" in e) || typeof e.workspaceId != "string" || !("experiences" in e) || !Array.isArray(e.experiences));
246
- }
247
- function me(e) {
248
- let t = /* @__PURE__ */ new Set();
249
- for (let n of V(e.steps)) n.layoutContentId && t.add(n.id);
250
- if (t.size === 0) return [];
251
- let n = [];
252
- for (let r of V(e.experiences)) V(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
253
- return n;
254
- }
255
- async function he(n) {
256
- let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = U(a), u = await ge(r, i, o, s), d = me(u);
257
- if (await p(l.experiencesDir, { recursive: !0 }), await h(l.projectConfigPath, JSON.stringify(u, null, 2)), c) {
258
- let t = await fe(l.manifestPath);
259
- if (t?.version === H && t.projectVersionId === u.versionId && t.workspaceId === u.workspaceId) {
260
- let n = W(l, d);
261
- if (Object.values(n).every((t) => e(t))) return {
262
- config: u,
263
- manifest: t,
264
- experienceContentPaths: n
265
- };
266
- I.info("a manifest-referenced content file is missing; refetching every experience");
267
- }
268
- }
269
- let f = (/* @__PURE__ */ new Date()).toISOString(), m = [];
270
- for (let e of d) {
271
- let n = await _e(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
272
- await h(a, JSON.stringify(n, null, 2)), m.push({
273
- id: e,
274
- fetchedAt: f
275
- });
276
- }
277
- let g = {
278
- version: H,
279
- fetchedAt: f,
280
- projectVersionId: u.versionId,
281
- workspaceId: u.workspaceId,
282
- projectId: u.id,
283
- experiences: m
284
- };
285
- return await h(l.manifestPath, JSON.stringify(g, null, 2)), {
286
- config: u,
287
- manifest: g,
288
- experienceContentPaths: W(l, d)
289
- };
290
- }
291
- function W(e, n) {
292
- let r = {};
293
- for (let i of n) r[i] = t(e.experiencesDir, `${i}.json`);
294
- return r;
295
- }
296
- async function ge(e, t, n, r) {
297
- let i = () => a(e, t, {
298
- headers: n,
299
- previewToken: r
300
- }), o;
301
- try {
302
- o = z(e) ? await B(i, (e, t, n) => {
303
- I.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
304
- }) : await i();
305
- } catch (n) {
306
- throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${G(n)}`);
307
- }
308
- if (!o) throw Error(`[picked] Build-time fetch of project config returned no usable response for "${t}" at ${e}. Confirm the API is reachable and the project ID is correct.`);
309
- return o;
310
- }
311
- async function _e(e, t, n, r, a) {
312
- let o;
313
- try {
314
- o = await i(e, t, n, {
315
- headers: r,
316
- previewToken: a
317
- });
318
- } catch (t) {
319
- throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${G(t)}`);
320
- }
321
- if (!o) throw Error(`[picked] Build-time fetch of content for experience "${n}" returned no usable response. Confirm the experience id exists and the API is reachable.`);
322
- return o;
323
- }
324
- function G(e) {
325
- if (e instanceof Error) return e.message;
326
- if (typeof e == "string") return e;
327
- try {
328
- return JSON.stringify(e);
329
- } catch {
330
- return "unknown error";
331
- }
332
- }
333
- //#endregion
334
- //#region src/telemetry.ts
335
- var ve = /* @__PURE__ */ new Set(["resolveId", "load"]);
336
- function ye(e = v()) {
337
- let t = g(), n = Date.now(), r = [], i = /* @__PURE__ */ new Map();
338
- return {
339
- record: (n, a) => {
340
- if (ve.has(n)) {
341
- let e = i.get(n) ?? {
342
- calls: 0,
343
- totalMs: 0
344
- };
345
- i.set(n, {
346
- calls: e.calls + 1,
347
- totalMs: e.totalMs + a
348
- });
349
- return;
350
- }
351
- let o = Date.now();
352
- r.push({
353
- name: `picked.vite.${n}`,
354
- traceId: e,
355
- spanId: g(),
356
- parentSpanId: t,
357
- startTimeUnixNano: y(o - a),
358
- endTimeUnixNano: y(o),
359
- attributes: { "picked.vite.hook": n },
360
- status: "ok"
361
- });
362
- },
363
- flush: async (a) => {
364
- let o = {};
365
- for (let [e, t] of i) o[`picked.vite.${e}.calls`] = t.calls, o[`picked.vite.${e}.total_ms`] = Math.round(t.totalMs);
366
- let c = s();
367
- r.push({
368
- name: "picked.vite.build",
369
- traceId: e,
370
- spanId: t,
371
- startTimeUnixNano: y(n),
372
- endTimeUnixNano: y(Date.now()),
373
- attributes: {
374
- "picked.env.provider": c.provider,
375
- "picked.env.ci": c.ci,
376
- ...a,
377
- ...o
378
- },
379
- status: "ok"
380
- });
381
- try {
382
- let e = _({
383
- resource: { "service.name": "picked-vite-plugin" },
384
- headers: { "Picked-Telemetry": "vite-plugin" },
385
- maxBatchSize: r.length
386
- });
387
- for (let t of r) e.record(t);
388
- await e.flush();
389
- } catch {}
390
- }
391
- };
392
- }
393
- function be(e) {
394
- return typeof e == "object" && !!e && "then" in e;
395
- }
396
- function K(e, t, n) {
397
- return function(...r) {
398
- let i = performance.now(), a = () => {
399
- n.record(e, performance.now() - i);
400
- }, o = t.apply(this, r);
401
- return be(o) ? Promise.resolve(o).then(a, a) : a(), o;
402
- };
403
- }
404
- function q(e) {
405
- return typeof e == "function";
406
- }
407
- function xe(e, t) {
408
- if (!e) return t;
409
- for (let [n, r] of Object.entries(t)) if (n !== "name") {
410
- if (q(r)) {
411
- Reflect.set(t, n, K(n, r, e));
412
- continue;
413
- }
414
- typeof r == "object" && r && "handler" in r && q(r.handler) && Reflect.set(r, "handler", K(n, r.handler, e));
415
- }
416
- return t;
417
- }
418
- //#endregion
419
- //#region src/virtual-module/api.ts
420
- function Se() {
421
- return "export const manifestMetadata = {\n mode: 'api',\n fetchedAt: null,\n projectVersionId: null,\n workspaceId: null,\n}\n";
422
- }
423
- //#endregion
424
- //#region src/virtual-module/build.ts
425
- function Ce(e) {
426
- let { projectConfigPath: t, experienceContentPaths: n, manifestMetadata: r } = e, i = (e) => JSON.stringify(e), a = Object.entries(n).map(([e, t]) => ` ${JSON.stringify(e)}: () => import(${i(t)}).then((m) => m.default ?? m),`).join("\n");
427
- return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
428
- import projectConfigJson from ${i(t)}
429
-
430
- const experienceImporters = {
431
- ${a}
432
- }
433
-
434
- export const projectConfig = projectConfigJson
435
-
436
- export async function experienceContent(experience, _options) {
437
- const id = typeof experience === 'string' ? experience : experience?.id
438
- if (!id) return null
439
- const importer = experienceImporters[id]
440
- if (!importer) return null
441
- try {
442
- return await importer()
443
- } catch {
444
- return null
445
- }
446
- }
447
-
448
- export const manifestMetadata = ${JSON.stringify(r)}
449
-
450
- registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
451
- `;
452
- }
453
- //#endregion
454
- //#region src/virtual-module/dev.ts
455
- function we(e) {
456
- let { apiUrl: t, projectId: n, projectConfig: r, previewToken: i } = e, a = r ? "import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'" : "import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'", o = r ? `export const projectConfig = ${JSON.stringify(r)}` : "export const projectConfig = await fetchProject(apiUrl, projectId, { previewToken: previewToken ?? undefined })", s = r ? "\nregisterPickedBundle({ projectConfig, experienceContent, manifestMetadata })\n" : "";
457
- return `${a}
458
-
459
- const apiUrl = ${JSON.stringify(t)}
460
- const projectId = ${JSON.stringify(n)}
461
- const previewToken = ${JSON.stringify(i ?? null)}
462
-
463
- ${o}
464
-
465
- export async function experienceContent(experience, options) {
466
- const id = typeof experience === 'string' ? experience : experience?.id
467
- if (!id) return null
468
- return await fetchExperienceContent(apiUrl, projectId, id, { previewToken: previewToken ?? undefined, ...options })
469
- }
470
-
471
- export const manifestMetadata = {
472
- mode: 'dev',
473
- fetchedAt: null,
474
- projectVersionId: projectConfig?.versionId ?? null,
475
- workspaceId: projectConfig?.workspaceId ?? null,
476
- }
477
- ${s}`;
478
- }
479
- //#endregion
480
- //#region src/index.ts
481
- var Te = 5;
482
- function J(e, t, n) {
483
- if (t.length === 0) return;
484
- if (t.length > Te) {
485
- console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
486
- return;
487
- }
488
- let r = n.map((e) => Math.max(e.header.length, ...t.map((t) => e.value(t).length))), i = (e, t) => e.padEnd(r[t] ?? e.length), a = ` ${n.map((e, t) => i(e.header, t)).join(" ")}`, o = ` ${r.map((e) => "─".repeat(e)).join(" ")}`, s = t.map((e) => ` ${n.map((t, n) => i(t.value(e), n)).join(" ")}`);
489
- console.log([
490
- "",
491
- ` ${e}:`,
492
- "",
493
- a,
494
- o,
495
- ...s,
496
- ""
497
- ].join("\n"));
498
- }
499
- function Ee(e, t) {
500
- t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
501
- }
502
- var De = [
503
- {
504
- header: "Name",
505
- value: (e) => e.name
506
- },
507
- {
508
- header: "ID",
509
- value: (e) => e.id
510
- },
511
- {
512
- header: "Status",
513
- value: (e) => e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m"
514
- },
515
- {
516
- header: "Split",
517
- value: (e) => de(e)
518
- },
519
- {
520
- header: "Ver",
521
- value: (e) => `v${e.version.toString()}`
522
- }
523
- ], Oe = [
524
- {
525
- header: "Name",
526
- value: (e) => e.name
527
- },
528
- {
529
- header: "Key",
530
- value: (e) => e.key
531
- },
532
- {
533
- header: "Component",
534
- value: (e) => e.componentName
535
- },
536
- {
537
- header: "Nodes",
538
- value: (e) => e.nodes.length.toString()
539
- },
540
- {
541
- header: "Targets",
542
- value: (e) => e.targets.length.toString()
543
- }
544
- ], ke = [
545
- {
546
- header: "Name",
547
- value: (e) => e.name
548
- },
549
- {
550
- header: "Key",
551
- value: (e) => e.key
552
- },
553
- {
554
- header: "Fields",
555
- value: (e) => (e.fieldIds?.length ?? 0).toString()
556
- }
557
- ], Ae = [
558
- {
559
- header: "Name",
560
- value: (e) => e.name
561
- },
562
- {
563
- header: "Key",
564
- value: (e) => e.key
565
- },
566
- {
567
- header: "Type",
568
- value: (e) => e.type
569
- },
570
- {
571
- header: "Required",
572
- value: (e) => e.required ? "yes" : "no"
573
- }
574
- ], je = [{
575
- header: "Name",
576
- value: (e) => e.name
577
- }, {
578
- header: "Key",
579
- value: (e) => e.key
580
- }];
581
- function Me() {
582
- return "0.0.1-dev.1789541668638";
583
- }
584
- var Ne = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
585
- function Pe(e) {
586
- for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
587
- }
588
- function Fe(e, t) {
589
- return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
590
- }
591
- async function Ie(e) {
592
- try {
593
- let t = await o({
594
- config: e,
595
- onWarn: (e) => {
596
- I.warn(e);
597
- }
598
- });
599
- I.info(`generated types at ${t.typesOutput}`);
600
- } catch (e) {
601
- let t = e instanceof Error ? e.message : String(e);
602
- throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
603
- }
604
- }
605
- function Le(e, t, n) {
606
- return e && c(t, n) ? e : null;
607
- }
608
- async function Re(e, t) {
609
- let n = await d(e, t);
610
- if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
611
- return n;
612
- }
613
- function Z(e, t, n) {
614
- if (t !== void 0 && n !== void 0 && t !== n) throw Error(`picked plugin option \`${e}\` is "${t}", and picked.config says "${n}". Remove the plugin option; picked.config is the one place this belongs.`);
615
- }
616
- function ze(e) {
617
- let t = [];
618
- if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
619
- let n = t.length > 1;
620
- I.warn(`picked plugin option${n ? "s" : ""} ${t.join(" and ")} ${n ? "are" : "is"} deprecated, and a future release drops ${n ? "them" : "it"}. Move ${n ? "them" : "it"} to picked.config, which the CLI and the type generator read from too.`);
621
- }
622
- async function Be(e, t) {
623
- let n = await u(e);
624
- n && n.projectId !== t && I.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
625
- }
626
- var Q = /* @__PURE__ */ new Map();
627
- function Ve(e, t, n) {
628
- return JSON.stringify([
629
- e,
630
- t,
631
- n
632
- ]);
633
- }
634
- function He(t = {}) {
635
- let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, s = [], c = process.cwd(), d = "serve", f = "/", p = null, m = !1, h, g, _ = null, v = l() ? null : ye();
636
- return xe(v, {
637
- name: "picked",
638
- config: async (l, f) => {
639
- d = f.command, c = l.root === void 0 ? process.cwd() : n(process.cwd(), l.root);
640
- let { projectId: y, apiUrl: b } = t, x = await u(c);
641
- Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), ze({
642
- projectId: y,
643
- apiUrl: b
644
- }), p = await Re(c, {
645
- projectId: y,
646
- apiUrl: b
647
- });
648
- let { projectId: S, apiUrl: C, previewToken: w } = p;
649
- v = Le(v, p, t.telemetry), I.banner(), o && !m && (m = !0, await Ie(p)), C !== Ne && I.warn(`using custom API URL: ${C}`), await Be(c, S);
650
- let T = r("vite-plugin", Me());
651
- if (i === "api") I.debug("mode is 'api': skipping the project-config prefetch");
652
- else if (f.command === "build") {
653
- let t = Ve(C, S, c);
654
- h = t;
655
- let n = Q.get(t);
656
- n === void 0 && (n = (async () => {
657
- I.info(`prefetching project config + content for "${S}"`);
658
- let t = U(c), n = e(t.pickedDir), r = performance.now(), i = await he({
659
- apiUrl: C,
660
- projectId: S,
661
- projectRoot: c,
662
- headers: T,
663
- previewToken: w ?? void 0
664
- }), a = (performance.now() - r).toFixed(0);
665
- await se(c, n);
666
- let o = i.config;
667
- return $(o, a), {
668
- virtualSource: Ce({
669
- projectConfigPath: t.projectConfigPath,
670
- experienceContentPaths: i.experienceContentPaths,
671
- manifestMetadata: {
672
- mode: "build",
673
- fetchedAt: i.manifest.fetchedAt,
674
- projectVersionId: i.manifest.projectVersionId,
675
- workspaceId: i.manifest.workspaceId
676
- }
677
- }),
678
- features: V(o.features)
679
- };
680
- })(), n.catch(() => Q.delete(t)), Q.set(t, n));
681
- let r = await n;
682
- g = r.virtualSource, s = r.features;
683
- } else if (f.mode === "production") I.debug("skipping the dev project-config fetch for a production serve resolution");
684
- else {
685
- I.info(`fetching project config for "${S}" (dev)`);
686
- let e = performance.now(), t = () => a(C, S, {
687
- headers: T,
688
- previewToken: w ?? void 0
689
- }), n = z(C) ? await B(t, (e, t, n) => {
690
- I.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
691
- }) : await t(), r = (performance.now() - e).toFixed(0);
692
- _ = n, n ? (s = V(n.features), $(n, r)) : I.warn(`failed to fetch project config for "${S}" (${r}ms)`);
693
- }
694
- },
695
- configResolved(e) {
696
- f = e.base;
697
- },
698
- closeBundle() {
699
- h !== void 0 && Q.delete(h), v?.flush({
700
- "picked.vite.command": d,
701
- "picked.data.mode": i,
702
- "picked.source": p?.source ?? "unknown"
703
- });
704
- },
705
- transformIndexHtml: {
706
- order: "post",
707
- handler(e, t) {
708
- if (i === "api" || t.bundle === void 0) return;
709
- let n = Pe(t.bundle);
710
- if (n === void 0) return;
711
- let r = Fe(f, n);
712
- if (!e.includes(`"${r}"`)) return [{
713
- tag: "link",
714
- attrs: {
715
- rel: "modulepreload",
716
- crossorigin: !0,
717
- href: r
718
- },
719
- injectTo: "head"
720
- }];
721
- }
722
- },
723
- resolveId(e) {
724
- if (e === Y) return X;
725
- },
726
- load(e) {
727
- if (e === X) {
728
- if (i === "api") return Se();
729
- if (d === "build") return g;
730
- if (!p) throw Error("picked plugin config hook must run before virtual module load");
731
- return we({
732
- apiUrl: p.apiUrl,
733
- projectId: p.projectId,
734
- projectConfig: _,
735
- previewToken: p.previewToken ?? void 0
736
- });
737
- }
738
- },
739
- configureServer(e) {
740
- if (t.disableLauncher) return;
741
- e.middlewares.use(oe(() => E(s)));
742
- let n = e.printUrls.bind(e);
743
- e.printUrls = () => {
744
- let t = e.resolvedUrls?.local[0];
745
- if (t) {
746
- let e = t.replace(/:(?<port>\d+)\//, (e, t) => `:\x1b[1m${t}\x1b[22m/`);
747
- console.log(` \x1b[32m➜\x1b[0m \x1b[1mPicked\x1b[22m: \x1b[36m${e}\x1b[0m`);
748
- }
749
- n();
750
- };
751
- },
752
- generateBundle: {
753
- order: "post",
754
- handler(e, n) {
755
- if (!t.disableLauncher) {
756
- if ("index.html" in n) {
757
- I.debug("index.html came from the build; skipping the launcher page");
758
- return;
759
- }
760
- this.emitFile({
761
- type: "asset",
762
- fileName: "index.html",
763
- source: E(s)
764
- });
765
- }
766
- }
767
- }
768
- });
769
- }
770
- function $(e, t) {
771
- let n = V(e.features), r = V(e.experiences), i = V(e.steps), a = V(e.fields), o = V(e.conditions), s = V(e.actions), c = JSON.stringify(e).length, l = [
772
- `${n.length.toString()} features`,
773
- `${r.length.toString()} experiences`,
774
- `${i.length.toString()} steps`,
775
- `${a.length.toString()} fields`,
776
- `${o.length.toString()} conditions`,
777
- `${s.length.toString()} actions`
778
- ].join(", ");
779
- I.info(`fetched config in ${t}ms (${l})`), J("Features", n, De), J("Experiences", r, Oe), J("Steps", i, ke), J("Fields", a, Ae), J("Conditions", o, je), Ee("Actions", s), I.debug(`config size: ${c.toString()} bytes`);
780
- }
781
- //#endregion
782
- export { He as picked };