@picked/vite-plugin-picked 0.0.51-next.11 → 0.0.51-next.2
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/cjs/index.js +2 -2
- package/dist/esm/index.js +27 -121
- package/dist/types/index.d.ts +2 -4
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -4
package/dist/cjs/index.js
CHANGED
|
@@ -857,5 +857,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
857
857
|
</body>
|
|
858
858
|
</html>`]),o,r)}function i(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function a(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}var o=`picked`,s=`\x1B[0m`;function c(){let e=process.env.NO_COLOR;return e===`1`||e===`true`}function l(e){return t=>c()?t:`${e}${t}${s}`}var u=[`debug`,`info`,`warn`,`error`,`silent`],d={debug:{color:l(`\x1B[2m`),log:console.debug,enabled:!1},info:{color:l(`\x1B[36m`),log:console.log,enabled:!0},warn:{color:l(`\x1B[33m`),log:console.warn,enabled:!0},error:{color:l(`\x1B[31m`),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function f(e,t){return`${new Date().toLocaleTimeString()} [${t?`${o}:${t}`:o}] ${e}`}function p(e,t,n,r){if(!e.enabled)return;let i=f(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function m(e){let t=d[e],n=new Set;return Object.assign((e,n,r)=>{p(t,e,n,r)},{once(e,r,i){!t.enabled||n.has(e)||(n.add(e),p(t,e,r,i))}})}function h(e){let t=u.indexOf(e);if(t===-1){p(d.error,`invalid log level: ${e}`);return}for(let[e,n]of u.entries())d[n].enabled=e>=t}var g=l(`\x1B[34m`),_=l(`\x1B[36m`);function v(){let e=[` ${g(`_`)} ${_(`_`)} _ _ _`,`${g(`(_)`)} ${_(`(_)`)} _ __(_)__| |_____ __| |`,` ${g(`_`)} ${g(`_`)} | '_ \\ / _| / / -_) _\` |`,`${g(`(_)`)} ${g(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
|
|
859
859
|
`];console.log(e.join(`
|
|
860
|
-
`))}var y={banner:v,debug:m(`debug`),info:m(`info`),warn:m(`warn`),error:m(`error`),setLevel:h};function b(e){return(t,n,r)=>{if(t.method!==`GET`){r();return}let i=(t.url??``).split(`?`)[0];if(i!==`/`&&i!==`/index.html`){r();return}let a=e();n.setHeader(`Content-Type`,`text/html`),n.statusCode=200,n.end(a)}}
|
|
861
|
-
`))}function
|
|
860
|
+
`))}var y={banner:v,debug:m(`debug`),info:m(`info`),warn:m(`warn`),error:m(`error`),setLevel:h};function b(e){return(t,n,r)=>{if(t.method!==`GET`){r();return}let i=(t.url??``).split(`?`)[0];if(i!==`/`&&i!==`/index.html`){r();return}let a=e();n.setHeader(`Content-Type`,`text/html`),n.statusCode=200,n.end(a)}}function x(e){if(e.length===0)return;let t=Math.max(4,...e.map(e=>e.name.length)),n=Math.max(2,...e.map(e=>e.id.length)),r=` ${`Name`.padEnd(t)} ${`ID`.padEnd(n)} Status Weight Ver`,i=` ${`─`.repeat(t)} ${`─`.repeat(n)} ──────── ────── ───`,a=e.map(e=>{let r=e.enabled?`\x1B[32m enabled\x1B[0m`:`\x1B[2mdisabled\x1B[0m`,i=`${e.weight.toString()}%`.padStart(6),a=`v${e.version.toString()}`;return` ${e.name.padEnd(t)} ${e.id.padEnd(n)} ${r} ${i} ${a}`});console.log([``,` Features:`,``,r,i,...a,``].join(`
|
|
861
|
+
`))}function S(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function C(e){return new Promise(t=>{setTimeout(t,e)})}async function w(t,n,r){let i=await(0,e.fetchProject)(t,n,{headers:r});if(i||!S(t))return i;for(let i=1;i<=O;i++){y.info(`local API not ready, retrying in ${(k/1e3).toString()}s (${i.toString()}/${O.toString()})`),await C(k);let a=await(0,e.fetchProject)(t,n,{headers:r});if(a)return a}return null}function T(){return`0.0.51-next.2`}var E=`https://api.picked.app`,D=`__PICKED_PROJECT_CONFIG__`,O=5,k=2e3;function A(t){let n=t.apiUrl??E,i=[];return{name:`picked`,config:async()=>{y.banner(),y.info(`fetching project config for "${t.projectId}"`),n!==E&&y.warn(`using custom API URL: ${n}`);let r=(0,e.createClientHeaders)(`vite-plugin`,T()),a=performance.now(),o=await w(n,t.projectId,r),s=(performance.now()-a).toFixed(0);if(!o){y.warn(`failed to fetch project config for "${t.projectId}" (${s}ms)`);return}i=o.features;let c=o.features.length,l=o.features.filter(e=>e.enabled).length,u=JSON.stringify(o).length;return y.info(`fetched ${c.toString()} features (${l.toString()} enabled) for "${t.projectId}" in ${s}ms`),x(o.features),y.debug(`config size: ${u.toString()} bytes`),{define:{[D]:JSON.stringify(o)}}},configureServer(e){if(t.disableLauncher)return;e.middlewares.use(b(()=>r(i)));let n=e.printUrls.bind(e);e.printUrls=()=>{let t=e.resolvedUrls?.local[0];if(t){let e=t.replace(/:(?<port>\d+)\//,(e,t)=>`:\x1b[1m${t}\x1b[22m/`);console.log(` \x1b[32m➜\x1b[0m \x1b[1mPicked\x1b[22m: \x1b[36m${e}\x1b[0m`)}n()}},generateBundle(){t.disableLauncher||this.emitFile({type:`asset`,fileName:`index.html`,source:r(i)})}}}exports.picked=A;
|
package/dist/esm/index.js
CHANGED
|
@@ -139,110 +139,23 @@ function x(e) {
|
|
|
139
139
|
}
|
|
140
140
|
//#endregion
|
|
141
141
|
//#region src/index.ts
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (t.length > S) {
|
|
149
|
-
console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
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(" ")}`);
|
|
142
|
+
function S(e) {
|
|
143
|
+
if (e.length === 0) return;
|
|
144
|
+
let t = Math.max(4, ...e.map((e) => e.name.length)), n = Math.max(2, ...e.map((e) => e.id.length)), r = ` ${"Name".padEnd(t)} ${"ID".padEnd(n)} Status Weight Ver`, i = ` ${"─".repeat(t)} ${"─".repeat(n)} ──────── ────── ───`, a = e.map((e) => {
|
|
145
|
+
let r = e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m", i = `${e.weight.toString()}%`.padStart(6), a = `v${e.version.toString()}`;
|
|
146
|
+
return ` ${e.name.padEnd(t)} ${e.id.padEnd(n)} ${r} ${i} ${a}`;
|
|
147
|
+
});
|
|
153
148
|
console.log([
|
|
154
149
|
"",
|
|
155
|
-
|
|
150
|
+
" Features:",
|
|
156
151
|
"",
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
...
|
|
152
|
+
r,
|
|
153
|
+
i,
|
|
154
|
+
...a,
|
|
160
155
|
""
|
|
161
156
|
].join("\n"));
|
|
162
157
|
}
|
|
163
|
-
function
|
|
164
|
-
t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
|
|
165
|
-
}
|
|
166
|
-
var E = [
|
|
167
|
-
{
|
|
168
|
-
header: "Name",
|
|
169
|
-
value: (e) => e.name
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
header: "ID",
|
|
173
|
-
value: (e) => e.id
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
header: "Status",
|
|
177
|
-
value: (e) => e.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m"
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
header: "Weight",
|
|
181
|
-
value: (e) => `${e.weight.toString()}%`.padStart(6)
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
header: "Ver",
|
|
185
|
-
value: (e) => `v${e.version.toString()}`
|
|
186
|
-
}
|
|
187
|
-
], D = [
|
|
188
|
-
{
|
|
189
|
-
header: "Name",
|
|
190
|
-
value: (e) => e.name
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
header: "Key",
|
|
194
|
-
value: (e) => e.key
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
header: "Component",
|
|
198
|
-
value: (e) => e.componentName
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
header: "Nodes",
|
|
202
|
-
value: (e) => e.nodes.length.toString()
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
header: "Targets",
|
|
206
|
-
value: (e) => e.targets.length.toString()
|
|
207
|
-
}
|
|
208
|
-
], O = [
|
|
209
|
-
{
|
|
210
|
-
header: "Name",
|
|
211
|
-
value: (e) => e.name
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
header: "Key",
|
|
215
|
-
value: (e) => e.key
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
header: "Fields",
|
|
219
|
-
value: (e) => e.fieldIds.length.toString()
|
|
220
|
-
}
|
|
221
|
-
], k = [
|
|
222
|
-
{
|
|
223
|
-
header: "Name",
|
|
224
|
-
value: (e) => e.name
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
header: "Key",
|
|
228
|
-
value: (e) => e.key
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
header: "Type",
|
|
232
|
-
value: (e) => e.type
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
header: "Required",
|
|
236
|
-
value: (e) => e.required ? "yes" : "no"
|
|
237
|
-
}
|
|
238
|
-
], A = [{
|
|
239
|
-
header: "Name",
|
|
240
|
-
value: (e) => e.name
|
|
241
|
-
}, {
|
|
242
|
-
header: "Key",
|
|
243
|
-
value: (e) => e.key
|
|
244
|
-
}];
|
|
245
|
-
function j(e) {
|
|
158
|
+
function C(e) {
|
|
246
159
|
try {
|
|
247
160
|
let t = new URL(e).hostname;
|
|
248
161
|
return t === "localhost" || t === "127.0.0.1" || t === "::1";
|
|
@@ -250,46 +163,39 @@ function j(e) {
|
|
|
250
163
|
return !1;
|
|
251
164
|
}
|
|
252
165
|
}
|
|
253
|
-
function
|
|
166
|
+
function w(e) {
|
|
254
167
|
return new Promise((t) => {
|
|
255
168
|
setTimeout(t, e);
|
|
256
169
|
});
|
|
257
170
|
}
|
|
258
|
-
async function
|
|
171
|
+
async function T(e, n, r) {
|
|
259
172
|
let i = await t(e, n, { headers: r });
|
|
260
|
-
if (i || !
|
|
261
|
-
for (let i = 1; i <=
|
|
262
|
-
b.info(`local API not ready, retrying in ${(
|
|
173
|
+
if (i || !C(e)) return i;
|
|
174
|
+
for (let i = 1; i <= k; i++) {
|
|
175
|
+
b.info(`local API not ready, retrying in ${(A / 1e3).toString()}s (${i.toString()}/${k.toString()})`), await w(A);
|
|
263
176
|
let a = await t(e, n, { headers: r });
|
|
264
177
|
if (a) return a;
|
|
265
178
|
}
|
|
266
179
|
return null;
|
|
267
180
|
}
|
|
268
|
-
function
|
|
269
|
-
return "0.0.51-next.
|
|
181
|
+
function E() {
|
|
182
|
+
return "0.0.51-next.2";
|
|
270
183
|
}
|
|
271
|
-
var
|
|
272
|
-
function
|
|
273
|
-
let n = t.apiUrl ??
|
|
184
|
+
var D = "https://api.picked.app", O = "__PICKED_PROJECT_CONFIG__", k = 5, A = 2e3;
|
|
185
|
+
function j(t) {
|
|
186
|
+
let n = t.apiUrl ?? D, r = [];
|
|
274
187
|
return {
|
|
275
188
|
name: "picked",
|
|
276
189
|
config: async () => {
|
|
277
|
-
b.banner(), b.info(`fetching project config for "${t.projectId}"`), n !==
|
|
278
|
-
let i = e("vite-plugin",
|
|
190
|
+
b.banner(), b.info(`fetching project config for "${t.projectId}"`), n !== D && b.warn(`using custom API URL: ${n}`);
|
|
191
|
+
let i = e("vite-plugin", E()), a = performance.now(), o = await T(n, t.projectId, i), s = (performance.now() - a).toFixed(0);
|
|
279
192
|
if (!o) {
|
|
280
193
|
b.warn(`failed to fetch project config for "${t.projectId}" (${s}ms)`);
|
|
281
194
|
return;
|
|
282
195
|
}
|
|
283
|
-
r =
|
|
284
|
-
let c =
|
|
285
|
-
|
|
286
|
-
`${c.length.toString()} experiences`,
|
|
287
|
-
`${l.length.toString()} steps`,
|
|
288
|
-
`${u.length.toString()} fields`,
|
|
289
|
-
`${d.length.toString()} conditions`,
|
|
290
|
-
`${f.length.toString()} actions`
|
|
291
|
-
].join(", ");
|
|
292
|
-
return b.info(`fetched config for "${t.projectId}" in ${s}ms (${m})`), w("Features", r, E), w("Experiences", c, D), w("Steps", l, O), w("Fields", u, k), w("Conditions", d, A), T("Actions", f), b.debug(`config size: ${p.toString()} bytes`), { define: { [I]: JSON.stringify(o) } };
|
|
196
|
+
r = o.features;
|
|
197
|
+
let c = o.features.length, l = o.features.filter((e) => e.enabled).length, u = JSON.stringify(o).length;
|
|
198
|
+
return b.info(`fetched ${c.toString()} features (${l.toString()} enabled) for "${t.projectId}" in ${s}ms`), S(o.features), b.debug(`config size: ${u.toString()} bytes`), { define: { [O]: JSON.stringify(o) } };
|
|
293
199
|
},
|
|
294
200
|
configureServer(e) {
|
|
295
201
|
if (t.disableLauncher) return;
|
|
@@ -314,4 +220,4 @@ function z(t) {
|
|
|
314
220
|
};
|
|
315
221
|
}
|
|
316
222
|
//#endregion
|
|
317
|
-
export {
|
|
223
|
+
export { j as picked };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
export interface PickedPluginOptions {
|
|
3
|
-
/** The Picked project ID
|
|
3
|
+
/** The Picked project ID */
|
|
4
4
|
projectId: string;
|
|
5
|
-
/** Custom API URL (defaults to https://api.picked.app)
|
|
5
|
+
/** Custom API URL (defaults to https://api.picked.app) */
|
|
6
6
|
apiUrl?: string;
|
|
7
7
|
/** Disable the launcher HTML page (dev server + build output). Defaults to false. */
|
|
8
8
|
disableLauncher?: boolean;
|
|
@@ -14,8 +14,6 @@ export interface PickedPluginOptions {
|
|
|
14
14
|
* When a preview token is present at runtime, the SDK will still
|
|
15
15
|
* fetch fresh config from the API, ignoring the build-time value.
|
|
16
16
|
*
|
|
17
|
-
* @param {PickedPluginOptions} options - Plugin configuration.
|
|
18
|
-
* @returns {Plugin} A Vite plugin instance.
|
|
19
17
|
* @example
|
|
20
18
|
* ```typescript
|
|
21
19
|
* import { picked } from '@picked/vite-plugin-picked'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA+ElC,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qFAAqF;IACrF,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAyE3D"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/vite-plugin-picked",
|
|
3
3
|
"description": "Vite plugin for build-time config injection",
|
|
4
|
-
"version": "0.0.51-next.
|
|
4
|
+
"version": "0.0.51-next.2",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@picked/client": "0.0.51-next.
|
|
6
|
+
"@picked/client": "0.0.51-next.2"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@repo/eslint-config": "workspace:*",
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"ignoreDependencies": [
|
|
39
39
|
"@picked/client",
|
|
40
40
|
"@repo/eslint-config",
|
|
41
|
-
"@repo/typescript-config"
|
|
42
|
-
"@vitest/coverage-v8"
|
|
41
|
+
"@repo/typescript-config"
|
|
43
42
|
],
|
|
44
43
|
"ignore": [
|
|
45
44
|
"eslint.config.js"
|