@openpolicy/vite 0.0.3 → 0.0.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAC;AAM1E,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErE;AAED,wBAAsB,gBAAgB,CACrC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAE,GACrB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAmClE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAC;AAK1E,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErE;AAED,wBAAsB,gBAAgB,CACrC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAE,GACrB,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAoClE"}
package/dist/index.js CHANGED
@@ -258,329 +258,9 @@ function compilePolicy(input, options) {
258
258
  }
259
259
  }
260
260
 
261
- // node:path
262
- function assertPath(path) {
263
- if (typeof path !== "string")
264
- throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
265
- }
266
- function normalizeStringPosix(path, allowAboveRoot) {
267
- var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
268
- for (var i = 0;i <= path.length; ++i) {
269
- if (i < path.length)
270
- code = path.charCodeAt(i);
271
- else if (code === 47)
272
- break;
273
- else
274
- code = 47;
275
- if (code === 47) {
276
- if (lastSlash === i - 1 || dots === 1)
277
- ;
278
- else if (lastSlash !== i - 1 && dots === 2) {
279
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
280
- if (res.length > 2) {
281
- var lastSlashIndex = res.lastIndexOf("/");
282
- if (lastSlashIndex !== res.length - 1) {
283
- if (lastSlashIndex === -1)
284
- res = "", lastSegmentLength = 0;
285
- else
286
- res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
287
- lastSlash = i, dots = 0;
288
- continue;
289
- }
290
- } else if (res.length === 2 || res.length === 1) {
291
- res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
292
- continue;
293
- }
294
- }
295
- if (allowAboveRoot) {
296
- if (res.length > 0)
297
- res += "/..";
298
- else
299
- res = "..";
300
- lastSegmentLength = 2;
301
- }
302
- } else {
303
- if (res.length > 0)
304
- res += "/" + path.slice(lastSlash + 1, i);
305
- else
306
- res = path.slice(lastSlash + 1, i);
307
- lastSegmentLength = i - lastSlash - 1;
308
- }
309
- lastSlash = i, dots = 0;
310
- } else if (code === 46 && dots !== -1)
311
- ++dots;
312
- else
313
- dots = -1;
314
- }
315
- return res;
316
- }
317
- function _format(sep, pathObject) {
318
- var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
319
- if (!dir)
320
- return base;
321
- if (dir === pathObject.root)
322
- return dir + base;
323
- return dir + sep + base;
324
- }
325
- function resolve() {
326
- var resolvedPath = "", resolvedAbsolute = false, cwd;
327
- for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
328
- var path;
329
- if (i >= 0)
330
- path = arguments[i];
331
- else {
332
- if (cwd === undefined)
333
- cwd = process.cwd();
334
- path = cwd;
335
- }
336
- if (assertPath(path), path.length === 0)
337
- continue;
338
- resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
339
- }
340
- if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
341
- if (resolvedPath.length > 0)
342
- return "/" + resolvedPath;
343
- else
344
- return "/";
345
- else if (resolvedPath.length > 0)
346
- return resolvedPath;
347
- else
348
- return ".";
349
- }
350
- function normalize(path) {
351
- if (assertPath(path), path.length === 0)
352
- return ".";
353
- var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
354
- if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
355
- path = ".";
356
- if (path.length > 0 && trailingSeparator)
357
- path += "/";
358
- if (isAbsolute)
359
- return "/" + path;
360
- return path;
361
- }
362
- function isAbsolute(path) {
363
- return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
364
- }
365
- function join() {
366
- if (arguments.length === 0)
367
- return ".";
368
- var joined;
369
- for (var i = 0;i < arguments.length; ++i) {
370
- var arg = arguments[i];
371
- if (assertPath(arg), arg.length > 0)
372
- if (joined === undefined)
373
- joined = arg;
374
- else
375
- joined += "/" + arg;
376
- }
377
- if (joined === undefined)
378
- return ".";
379
- return normalize(joined);
380
- }
381
- function relative(from, to) {
382
- if (assertPath(from), assertPath(to), from === to)
383
- return "";
384
- if (from = resolve(from), to = resolve(to), from === to)
385
- return "";
386
- var fromStart = 1;
387
- for (;fromStart < from.length; ++fromStart)
388
- if (from.charCodeAt(fromStart) !== 47)
389
- break;
390
- var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
391
- for (;toStart < to.length; ++toStart)
392
- if (to.charCodeAt(toStart) !== 47)
393
- break;
394
- var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
395
- for (;i <= length; ++i) {
396
- if (i === length) {
397
- if (toLen > length) {
398
- if (to.charCodeAt(toStart + i) === 47)
399
- return to.slice(toStart + i + 1);
400
- else if (i === 0)
401
- return to.slice(toStart + i);
402
- } else if (fromLen > length) {
403
- if (from.charCodeAt(fromStart + i) === 47)
404
- lastCommonSep = i;
405
- else if (i === 0)
406
- lastCommonSep = 0;
407
- }
408
- break;
409
- }
410
- var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
411
- if (fromCode !== toCode)
412
- break;
413
- else if (fromCode === 47)
414
- lastCommonSep = i;
415
- }
416
- var out = "";
417
- for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
418
- if (i === fromEnd || from.charCodeAt(i) === 47)
419
- if (out.length === 0)
420
- out += "..";
421
- else
422
- out += "/..";
423
- if (out.length > 0)
424
- return out + to.slice(toStart + lastCommonSep);
425
- else {
426
- if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
427
- ++toStart;
428
- return to.slice(toStart);
429
- }
430
- }
431
- function _makeLong(path) {
432
- return path;
433
- }
434
- function dirname(path) {
435
- if (assertPath(path), path.length === 0)
436
- return ".";
437
- var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
438
- for (var i = path.length - 1;i >= 1; --i)
439
- if (code = path.charCodeAt(i), code === 47) {
440
- if (!matchedSlash) {
441
- end = i;
442
- break;
443
- }
444
- } else
445
- matchedSlash = false;
446
- if (end === -1)
447
- return hasRoot ? "/" : ".";
448
- if (hasRoot && end === 1)
449
- return "//";
450
- return path.slice(0, end);
451
- }
452
- function basename(path, ext) {
453
- if (ext !== undefined && typeof ext !== "string")
454
- throw new TypeError('"ext" argument must be a string');
455
- assertPath(path);
456
- var start = 0, end = -1, matchedSlash = true, i;
457
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
458
- if (ext.length === path.length && ext === path)
459
- return "";
460
- var extIdx = ext.length - 1, firstNonSlashEnd = -1;
461
- for (i = path.length - 1;i >= 0; --i) {
462
- var code = path.charCodeAt(i);
463
- if (code === 47) {
464
- if (!matchedSlash) {
465
- start = i + 1;
466
- break;
467
- }
468
- } else {
469
- if (firstNonSlashEnd === -1)
470
- matchedSlash = false, firstNonSlashEnd = i + 1;
471
- if (extIdx >= 0)
472
- if (code === ext.charCodeAt(extIdx)) {
473
- if (--extIdx === -1)
474
- end = i;
475
- } else
476
- extIdx = -1, end = firstNonSlashEnd;
477
- }
478
- }
479
- if (start === end)
480
- end = firstNonSlashEnd;
481
- else if (end === -1)
482
- end = path.length;
483
- return path.slice(start, end);
484
- } else {
485
- for (i = path.length - 1;i >= 0; --i)
486
- if (path.charCodeAt(i) === 47) {
487
- if (!matchedSlash) {
488
- start = i + 1;
489
- break;
490
- }
491
- } else if (end === -1)
492
- matchedSlash = false, end = i + 1;
493
- if (end === -1)
494
- return "";
495
- return path.slice(start, end);
496
- }
497
- }
498
- function extname(path) {
499
- assertPath(path);
500
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
501
- for (var i = path.length - 1;i >= 0; --i) {
502
- var code = path.charCodeAt(i);
503
- if (code === 47) {
504
- if (!matchedSlash) {
505
- startPart = i + 1;
506
- break;
507
- }
508
- continue;
509
- }
510
- if (end === -1)
511
- matchedSlash = false, end = i + 1;
512
- if (code === 46) {
513
- if (startDot === -1)
514
- startDot = i;
515
- else if (preDotState !== 1)
516
- preDotState = 1;
517
- } else if (startDot !== -1)
518
- preDotState = -1;
519
- }
520
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
521
- return "";
522
- return path.slice(startDot, end);
523
- }
524
- function format(pathObject) {
525
- if (pathObject === null || typeof pathObject !== "object")
526
- throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
527
- return _format("/", pathObject);
528
- }
529
- function parse(path) {
530
- assertPath(path);
531
- var ret = { root: "", dir: "", base: "", ext: "", name: "" };
532
- if (path.length === 0)
533
- return ret;
534
- var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
535
- if (isAbsolute2)
536
- ret.root = "/", start = 1;
537
- else
538
- start = 0;
539
- var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
540
- for (;i >= start; --i) {
541
- if (code = path.charCodeAt(i), code === 47) {
542
- if (!matchedSlash) {
543
- startPart = i + 1;
544
- break;
545
- }
546
- continue;
547
- }
548
- if (end === -1)
549
- matchedSlash = false, end = i + 1;
550
- if (code === 46) {
551
- if (startDot === -1)
552
- startDot = i;
553
- else if (preDotState !== 1)
554
- preDotState = 1;
555
- } else if (startDot !== -1)
556
- preDotState = -1;
557
- }
558
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
559
- if (end !== -1)
560
- if (startPart === 0 && isAbsolute2)
561
- ret.base = ret.name = path.slice(1, end);
562
- else
563
- ret.base = ret.name = path.slice(startPart, end);
564
- } else {
565
- if (startPart === 0 && isAbsolute2)
566
- ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
567
- else
568
- ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
569
- ret.ext = path.slice(startDot, end);
570
- }
571
- if (startPart > 0)
572
- ret.dir = path.slice(0, startPart - 1);
573
- else if (isAbsolute2)
574
- ret.dir = "/";
575
- return ret;
576
- }
577
- var sep = "/";
578
- var delimiter = ":";
579
- var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
580
-
581
261
  // src/index.ts
582
- var {existsSync} = (() => ({}));
583
- var {writeFile, mkdir} = (() => ({}));
262
+ import { resolve, join } from "node:path";
263
+ import { writeFile, mkdir, access } from "node:fs/promises";
584
264
  var SCAFFOLD_TEMPLATE = `import { definePrivacyPolicy } from "@openpolicy/sdk";
585
265
 
586
266
  export default definePrivacyPolicy({
@@ -638,7 +318,8 @@ function openPolicy(options = {}) {
638
318
  resolvedOutDir = resolve(config.root, options.outDir ?? "public/policies");
639
319
  },
640
320
  async buildStart() {
641
- if (!existsSync(resolvedConfigPath)) {
321
+ const configExists = await access(resolvedConfigPath).then(() => true, () => false);
322
+ if (!configExists) {
642
323
  await writeScaffold(resolvedConfigPath);
643
324
  console.log(`[openpolicy] Scaffolded config at ${resolvedConfigPath}`);
644
325
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpolicy/vite",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "Vite plugin for compiling OpenPolicy privacy policy documents at build time",
6
6
  "license": "MIT",
@@ -14,18 +14,14 @@
14
14
  "README.md"
15
15
  ],
16
16
  "exports": {
17
- ".": "./src/index.ts"
18
- },
19
- "publishConfig": {
20
- "exports": {
21
- ".": {
22
- "import": "./dist/index.js",
23
- "types": "./dist/index.d.ts"
24
- }
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
25
20
  }
26
21
  },
27
22
  "scripts": {
28
- "build": "bun build ./src/index.ts --outdir dist && tsc --emitDeclarationOnly",
23
+ "dev": "bun build ./src/index.ts --outdir dist --watch",
24
+ "build": "bun build ./src/index.ts --outdir dist --target node && tsc --emitDeclarationOnly",
29
25
  "check-types": "tsc --noEmit",
30
26
  "test": "bun test"
31
27
  },