@sanity/plugin-kit 4.0.19 → 5.0.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.
Files changed (104) hide show
  1. package/assets/inject/semver-workflow/.husky/commit-msg +0 -0
  2. package/assets/inject/semver-workflow/.husky/pre-commit +0 -0
  3. package/assets/inject/ui-workshop/src/__workshop__/props.tsx +2 -1
  4. package/bin/plugin-kit.js +3 -1
  5. package/dist/{_chunks-cjs/cli.js → _chunks-es/index.js} +53 -63
  6. package/dist/_chunks-es/index.js.map +1 -0
  7. package/dist/{_chunks-cjs/init2.js → _chunks-es/init.js} +25 -23
  8. package/dist/_chunks-es/init.js.map +1 -0
  9. package/dist/_chunks-es/init2.js +140 -0
  10. package/dist/_chunks-es/init2.js.map +1 -0
  11. package/{src/cmds/inject.ts → dist/_chunks-es/inject.js} +18 -32
  12. package/dist/{_chunks-cjs → _chunks-es}/inject.js.map +1 -1
  13. package/dist/_chunks-es/link-watch.js +91 -0
  14. package/dist/_chunks-es/link-watch.js.map +1 -0
  15. package/dist/_chunks-es/load-package-config.js +22 -0
  16. package/dist/_chunks-es/load-package-config.js.map +1 -0
  17. package/dist/_chunks-es/package.js +1759 -0
  18. package/dist/_chunks-es/package.js.map +1 -0
  19. package/dist/_chunks-es/package2.js +9 -0
  20. package/dist/_chunks-es/package2.js.map +1 -0
  21. package/dist/{_chunks-cjs → _chunks-es}/ts.js +101 -92
  22. package/dist/_chunks-es/ts.js.map +1 -0
  23. package/dist/_chunks-es/verify-package.js +92 -0
  24. package/dist/_chunks-es/verify-package.js.map +1 -0
  25. package/dist/_chunks-es/verify-studio.js +61 -0
  26. package/dist/_chunks-es/verify-studio.js.map +1 -0
  27. package/dist/_chunks-es/version.js +50 -0
  28. package/dist/_chunks-es/version.js.map +1 -0
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +4 -1
  32. package/dist/index.js.map +1 -1
  33. package/package.json +41 -88
  34. package/LICENSE +0 -21
  35. package/dist/_chunks-cjs/cli.js.map +0 -1
  36. package/dist/_chunks-cjs/init.js +0 -894
  37. package/dist/_chunks-cjs/init.js.map +0 -1
  38. package/dist/_chunks-cjs/init2.js.map +0 -1
  39. package/dist/_chunks-cjs/inject.js +0 -54
  40. package/dist/_chunks-cjs/link-watch.js +0 -84
  41. package/dist/_chunks-cjs/link-watch.js.map +0 -1
  42. package/dist/_chunks-cjs/package.js +0 -1809
  43. package/dist/_chunks-cjs/package.js.map +0 -1
  44. package/dist/_chunks-cjs/package2.js +0 -146
  45. package/dist/_chunks-cjs/package2.js.map +0 -1
  46. package/dist/_chunks-cjs/ts.js.map +0 -1
  47. package/dist/_chunks-cjs/verify-package.js +0 -75
  48. package/dist/_chunks-cjs/verify-package.js.map +0 -1
  49. package/dist/_chunks-cjs/verify-studio.js +0 -57
  50. package/dist/_chunks-cjs/verify-studio.js.map +0 -1
  51. package/dist/_chunks-cjs/version.js +0 -51
  52. package/dist/_chunks-cjs/version.js.map +0 -1
  53. package/dist/cli.d.ts +0 -4
  54. package/dist/cli.js +0 -6
  55. package/dist/cli.js.map +0 -1
  56. package/src/actions/init.ts +0 -95
  57. package/src/actions/inject.ts +0 -399
  58. package/src/actions/link-watch.ts +0 -98
  59. package/src/actions/verify/types.ts +0 -56
  60. package/src/actions/verify/validations.ts +0 -505
  61. package/src/actions/verify/verify-common.ts +0 -93
  62. package/src/actions/verify-package.ts +0 -103
  63. package/src/actions/verify-studio.ts +0 -58
  64. package/src/cli.ts +0 -77
  65. package/src/cmds/index.ts +0 -20
  66. package/src/cmds/init.ts +0 -90
  67. package/src/cmds/link-watch.ts +0 -50
  68. package/src/cmds/verify-package.ts +0 -36
  69. package/src/cmds/verify-studio.ts +0 -36
  70. package/src/cmds/version.ts +0 -67
  71. package/src/configs/banned-packages.ts +0 -27
  72. package/src/configs/buildExtensions.ts +0 -1
  73. package/src/configs/default-source.ts +0 -64
  74. package/src/configs/eslint.ts +0 -51
  75. package/src/configs/forced-package-versions.ts +0 -12
  76. package/src/configs/git.ts +0 -68
  77. package/src/configs/pkg-config.ts +0 -31
  78. package/src/configs/prettier.ts +0 -11
  79. package/src/configs/tsconfig.ts +0 -78
  80. package/src/configs/uselessFiles.ts +0 -29
  81. package/src/constants.ts +0 -15
  82. package/src/dependencies/find.ts +0 -193
  83. package/src/dependencies/import-linter.ts +0 -95
  84. package/src/index.ts +0 -1
  85. package/src/npm/manager.ts +0 -44
  86. package/src/npm/package.ts +0 -427
  87. package/src/npm/publish.ts +0 -9
  88. package/src/npm/resolveLatestVersions.ts +0 -31
  89. package/src/presets/presets.ts +0 -54
  90. package/src/presets/renovatebot.ts +0 -21
  91. package/src/presets/semver-workflow.ts +0 -193
  92. package/src/presets/ui-workshop.ts +0 -97
  93. package/src/presets/ui.ts +0 -67
  94. package/src/sanity/manifest.ts +0 -340
  95. package/src/sharedFlags.ts +0 -14
  96. package/src/util/command-parser.ts +0 -36
  97. package/src/util/errorToUndefined.ts +0 -7
  98. package/src/util/files.ts +0 -260
  99. package/src/util/log.ts +0 -44
  100. package/src/util/prompt.ts +0 -70
  101. package/src/util/readme.ts +0 -93
  102. package/src/util/request.ts +0 -11
  103. package/src/util/ts.ts +0 -13
  104. package/src/util/user.ts +0 -119
@@ -1,1809 +0,0 @@
1
- "use strict";
2
- var fs = require("fs"), path = require("path"), util$1 = require("util"), githubUrlToObject = require("github-url-to-object"), validateNpmPackageName = require("validate-npm-package-name"), _package = require("./package2.js"), pAny = require("p-any"), crypto = require("crypto"), url = require("url"), inquirer = require("inquirer"), cli = require("./cli.js"), pProps = require("p-props"), getLatestVersion = require("get-latest-version"), outdent = require("outdent"), chalk = require("chalk");
3
- function _interopDefaultCompat(e) {
4
- return e && typeof e == "object" && "default" in e ? e : { default: e };
5
- }
6
- var fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), path__default = /* @__PURE__ */ _interopDefaultCompat(path), util__default = /* @__PURE__ */ _interopDefaultCompat(util$1), githubUrlToObject__default = /* @__PURE__ */ _interopDefaultCompat(githubUrlToObject), validateNpmPackageName__default = /* @__PURE__ */ _interopDefaultCompat(validateNpmPackageName), pAny__default = /* @__PURE__ */ _interopDefaultCompat(pAny), crypto__default = /* @__PURE__ */ _interopDefaultCompat(crypto), inquirer__default = /* @__PURE__ */ _interopDefaultCompat(inquirer), pProps__default = /* @__PURE__ */ _interopDefaultCompat(pProps), getLatestVersion__default = /* @__PURE__ */ _interopDefaultCompat(getLatestVersion), outdent__default = /* @__PURE__ */ _interopDefaultCompat(outdent), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk);
7
- const buildExtensions = [".js", ".jsx", ".es6", ".es", ".mjs", ".ts", ".tsx"];
8
- async function prompt(message, options) {
9
- const type = options.choices ? "list" : options.type, result = await inquirer__default.default.prompt([{ ...options, type, message, name: "single" }]);
10
- return result && result.single;
11
- }
12
- prompt.separator = () => new inquirer__default.default.Separator();
13
- function promptForPackageName({ basePath }, defaultVal) {
14
- return prompt("Plugin name (sanity-plugin-...)", {
15
- default: defaultVal || path__default.default.basename(basePath),
16
- filter: (name) => {
17
- const prefixless = name.trim().replace(/^sanity-plugin-/, "");
18
- return name[0] === "@" ? name : `sanity-plugin-${prefixless}`;
19
- },
20
- validate: (name) => {
21
- const valid = validateNpmPackageName__default.default(name);
22
- return valid.errors ? valid.errors[0] : name[0] !== "@" && name.endsWith("plugin") ? `Name shouldn't include "plugin" multiple times (${name})` : !0;
23
- }
24
- });
25
- }
26
- function promptForRepoOrigin(options, defaultVal) {
27
- return prompt("Git repository URL", {
28
- default: defaultVal,
29
- filter: (raw) => {
30
- const url2 = (raw || "").trim(), gh = githubUrlToObject__default.default(url2);
31
- return gh ? `git+ssh://git@github.com/${gh.user}/${gh.repo}.git` : url2;
32
- },
33
- validate: (url$1) => {
34
- if (!url$1)
35
- return !0;
36
- try {
37
- return new url.URL(url$1) ? !0 : "Invalid URL";
38
- } catch {
39
- return "Invalid URL";
40
- }
41
- }
42
- });
43
- }
44
- var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/, ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/, ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/, unicode = {
45
- Space_Separator,
46
- ID_Start,
47
- ID_Continue
48
- }, util = {
49
- isSpaceSeparator(c2) {
50
- return typeof c2 == "string" && unicode.Space_Separator.test(c2);
51
- },
52
- isIdStartChar(c2) {
53
- return typeof c2 == "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 === "$" || c2 === "_" || unicode.ID_Start.test(c2));
54
- },
55
- isIdContinueChar(c2) {
56
- return typeof c2 == "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 >= "0" && c2 <= "9" || c2 === "$" || c2 === "_" || c2 === "\u200C" || c2 === "\u200D" || unicode.ID_Continue.test(c2));
57
- },
58
- isDigit(c2) {
59
- return typeof c2 == "string" && /[0-9]/.test(c2);
60
- },
61
- isHexDigit(c2) {
62
- return typeof c2 == "string" && /[0-9A-Fa-f]/.test(c2);
63
- }
64
- };
65
- let source, parseState, stack, pos, line, column, token, key, root;
66
- var parse = function(text, reviver) {
67
- source = String(text), parseState = "start", stack = [], pos = 0, line = 1, column = 0, token = void 0, key = void 0, root = void 0;
68
- do
69
- token = lex(), parseStates[parseState]();
70
- while (token.type !== "eof");
71
- return typeof reviver == "function" ? internalize({ "": root }, "", reviver) : root;
72
- };
73
- function internalize(holder, name, reviver) {
74
- const value = holder[name];
75
- if (value != null && typeof value == "object")
76
- if (Array.isArray(value))
77
- for (let i = 0; i < value.length; i++) {
78
- const key2 = String(i), replacement = internalize(value, key2, reviver);
79
- replacement === void 0 ? delete value[key2] : Object.defineProperty(value, key2, {
80
- value: replacement,
81
- writable: !0,
82
- enumerable: !0,
83
- configurable: !0
84
- });
85
- }
86
- else
87
- for (const key2 in value) {
88
- const replacement = internalize(value, key2, reviver);
89
- replacement === void 0 ? delete value[key2] : Object.defineProperty(value, key2, {
90
- value: replacement,
91
- writable: !0,
92
- enumerable: !0,
93
- configurable: !0
94
- });
95
- }
96
- return reviver.call(holder, name, value);
97
- }
98
- let lexState, buffer, doubleQuote, sign, c;
99
- function lex() {
100
- for (lexState = "default", buffer = "", doubleQuote = !1, sign = 1; ; ) {
101
- c = peek();
102
- const token2 = lexStates[lexState]();
103
- if (token2)
104
- return token2;
105
- }
106
- }
107
- function peek() {
108
- if (source[pos])
109
- return String.fromCodePoint(source.codePointAt(pos));
110
- }
111
- function read() {
112
- const c2 = peek();
113
- return c2 === `
114
- ` ? (line++, column = 0) : c2 ? column += c2.length : column++, c2 && (pos += c2.length), c2;
115
- }
116
- const lexStates = {
117
- default() {
118
- switch (c) {
119
- case " ":
120
- case "\v":
121
- case "\f":
122
- case " ":
123
- case "\xA0":
124
- case "\uFEFF":
125
- case `
126
- `:
127
- case "\r":
128
- case "\u2028":
129
- case "\u2029":
130
- read();
131
- return;
132
- case "/":
133
- read(), lexState = "comment";
134
- return;
135
- case void 0:
136
- return read(), newToken("eof");
137
- }
138
- if (util.isSpaceSeparator(c)) {
139
- read();
140
- return;
141
- }
142
- return lexStates[parseState]();
143
- },
144
- comment() {
145
- switch (c) {
146
- case "*":
147
- read(), lexState = "multiLineComment";
148
- return;
149
- case "/":
150
- read(), lexState = "singleLineComment";
151
- return;
152
- }
153
- throw invalidChar(read());
154
- },
155
- multiLineComment() {
156
- switch (c) {
157
- case "*":
158
- read(), lexState = "multiLineCommentAsterisk";
159
- return;
160
- case void 0:
161
- throw invalidChar(read());
162
- }
163
- read();
164
- },
165
- multiLineCommentAsterisk() {
166
- switch (c) {
167
- case "*":
168
- read();
169
- return;
170
- case "/":
171
- read(), lexState = "default";
172
- return;
173
- case void 0:
174
- throw invalidChar(read());
175
- }
176
- read(), lexState = "multiLineComment";
177
- },
178
- singleLineComment() {
179
- switch (c) {
180
- case `
181
- `:
182
- case "\r":
183
- case "\u2028":
184
- case "\u2029":
185
- read(), lexState = "default";
186
- return;
187
- case void 0:
188
- return read(), newToken("eof");
189
- }
190
- read();
191
- },
192
- value() {
193
- switch (c) {
194
- case "{":
195
- case "[":
196
- return newToken("punctuator", read());
197
- case "n":
198
- return read(), literal("ull"), newToken("null", null);
199
- case "t":
200
- return read(), literal("rue"), newToken("boolean", !0);
201
- case "f":
202
- return read(), literal("alse"), newToken("boolean", !1);
203
- case "-":
204
- case "+":
205
- read() === "-" && (sign = -1), lexState = "sign";
206
- return;
207
- case ".":
208
- buffer = read(), lexState = "decimalPointLeading";
209
- return;
210
- case "0":
211
- buffer = read(), lexState = "zero";
212
- return;
213
- case "1":
214
- case "2":
215
- case "3":
216
- case "4":
217
- case "5":
218
- case "6":
219
- case "7":
220
- case "8":
221
- case "9":
222
- buffer = read(), lexState = "decimalInteger";
223
- return;
224
- case "I":
225
- return read(), literal("nfinity"), newToken("numeric", 1 / 0);
226
- case "N":
227
- return read(), literal("aN"), newToken("numeric", NaN);
228
- case '"':
229
- case "'":
230
- doubleQuote = read() === '"', buffer = "", lexState = "string";
231
- return;
232
- }
233
- throw invalidChar(read());
234
- },
235
- identifierNameStartEscape() {
236
- if (c !== "u")
237
- throw invalidChar(read());
238
- read();
239
- const u = unicodeEscape();
240
- switch (u) {
241
- case "$":
242
- case "_":
243
- break;
244
- default:
245
- if (!util.isIdStartChar(u))
246
- throw invalidIdentifier();
247
- break;
248
- }
249
- buffer += u, lexState = "identifierName";
250
- },
251
- identifierName() {
252
- switch (c) {
253
- case "$":
254
- case "_":
255
- case "\u200C":
256
- case "\u200D":
257
- buffer += read();
258
- return;
259
- case "\\":
260
- read(), lexState = "identifierNameEscape";
261
- return;
262
- }
263
- if (util.isIdContinueChar(c)) {
264
- buffer += read();
265
- return;
266
- }
267
- return newToken("identifier", buffer);
268
- },
269
- identifierNameEscape() {
270
- if (c !== "u")
271
- throw invalidChar(read());
272
- read();
273
- const u = unicodeEscape();
274
- switch (u) {
275
- case "$":
276
- case "_":
277
- case "\u200C":
278
- case "\u200D":
279
- break;
280
- default:
281
- if (!util.isIdContinueChar(u))
282
- throw invalidIdentifier();
283
- break;
284
- }
285
- buffer += u, lexState = "identifierName";
286
- },
287
- sign() {
288
- switch (c) {
289
- case ".":
290
- buffer = read(), lexState = "decimalPointLeading";
291
- return;
292
- case "0":
293
- buffer = read(), lexState = "zero";
294
- return;
295
- case "1":
296
- case "2":
297
- case "3":
298
- case "4":
299
- case "5":
300
- case "6":
301
- case "7":
302
- case "8":
303
- case "9":
304
- buffer = read(), lexState = "decimalInteger";
305
- return;
306
- case "I":
307
- return read(), literal("nfinity"), newToken("numeric", sign * (1 / 0));
308
- case "N":
309
- return read(), literal("aN"), newToken("numeric", NaN);
310
- }
311
- throw invalidChar(read());
312
- },
313
- zero() {
314
- switch (c) {
315
- case ".":
316
- buffer += read(), lexState = "decimalPoint";
317
- return;
318
- case "e":
319
- case "E":
320
- buffer += read(), lexState = "decimalExponent";
321
- return;
322
- case "x":
323
- case "X":
324
- buffer += read(), lexState = "hexadecimal";
325
- return;
326
- }
327
- return newToken("numeric", sign * 0);
328
- },
329
- decimalInteger() {
330
- switch (c) {
331
- case ".":
332
- buffer += read(), lexState = "decimalPoint";
333
- return;
334
- case "e":
335
- case "E":
336
- buffer += read(), lexState = "decimalExponent";
337
- return;
338
- }
339
- if (util.isDigit(c)) {
340
- buffer += read();
341
- return;
342
- }
343
- return newToken("numeric", sign * Number(buffer));
344
- },
345
- decimalPointLeading() {
346
- if (util.isDigit(c)) {
347
- buffer += read(), lexState = "decimalFraction";
348
- return;
349
- }
350
- throw invalidChar(read());
351
- },
352
- decimalPoint() {
353
- switch (c) {
354
- case "e":
355
- case "E":
356
- buffer += read(), lexState = "decimalExponent";
357
- return;
358
- }
359
- if (util.isDigit(c)) {
360
- buffer += read(), lexState = "decimalFraction";
361
- return;
362
- }
363
- return newToken("numeric", sign * Number(buffer));
364
- },
365
- decimalFraction() {
366
- switch (c) {
367
- case "e":
368
- case "E":
369
- buffer += read(), lexState = "decimalExponent";
370
- return;
371
- }
372
- if (util.isDigit(c)) {
373
- buffer += read();
374
- return;
375
- }
376
- return newToken("numeric", sign * Number(buffer));
377
- },
378
- decimalExponent() {
379
- switch (c) {
380
- case "+":
381
- case "-":
382
- buffer += read(), lexState = "decimalExponentSign";
383
- return;
384
- }
385
- if (util.isDigit(c)) {
386
- buffer += read(), lexState = "decimalExponentInteger";
387
- return;
388
- }
389
- throw invalidChar(read());
390
- },
391
- decimalExponentSign() {
392
- if (util.isDigit(c)) {
393
- buffer += read(), lexState = "decimalExponentInteger";
394
- return;
395
- }
396
- throw invalidChar(read());
397
- },
398
- decimalExponentInteger() {
399
- if (util.isDigit(c)) {
400
- buffer += read();
401
- return;
402
- }
403
- return newToken("numeric", sign * Number(buffer));
404
- },
405
- hexadecimal() {
406
- if (util.isHexDigit(c)) {
407
- buffer += read(), lexState = "hexadecimalInteger";
408
- return;
409
- }
410
- throw invalidChar(read());
411
- },
412
- hexadecimalInteger() {
413
- if (util.isHexDigit(c)) {
414
- buffer += read();
415
- return;
416
- }
417
- return newToken("numeric", sign * Number(buffer));
418
- },
419
- string() {
420
- switch (c) {
421
- case "\\":
422
- read(), buffer += escape();
423
- return;
424
- case '"':
425
- if (doubleQuote)
426
- return read(), newToken("string", buffer);
427
- buffer += read();
428
- return;
429
- case "'":
430
- if (!doubleQuote)
431
- return read(), newToken("string", buffer);
432
- buffer += read();
433
- return;
434
- case `
435
- `:
436
- case "\r":
437
- throw invalidChar(read());
438
- case "\u2028":
439
- case "\u2029":
440
- separatorChar(c);
441
- break;
442
- case void 0:
443
- throw invalidChar(read());
444
- }
445
- buffer += read();
446
- },
447
- start() {
448
- switch (c) {
449
- case "{":
450
- case "[":
451
- return newToken("punctuator", read());
452
- }
453
- lexState = "value";
454
- },
455
- beforePropertyName() {
456
- switch (c) {
457
- case "$":
458
- case "_":
459
- buffer = read(), lexState = "identifierName";
460
- return;
461
- case "\\":
462
- read(), lexState = "identifierNameStartEscape";
463
- return;
464
- case "}":
465
- return newToken("punctuator", read());
466
- case '"':
467
- case "'":
468
- doubleQuote = read() === '"', lexState = "string";
469
- return;
470
- }
471
- if (util.isIdStartChar(c)) {
472
- buffer += read(), lexState = "identifierName";
473
- return;
474
- }
475
- throw invalidChar(read());
476
- },
477
- afterPropertyName() {
478
- if (c === ":")
479
- return newToken("punctuator", read());
480
- throw invalidChar(read());
481
- },
482
- beforePropertyValue() {
483
- lexState = "value";
484
- },
485
- afterPropertyValue() {
486
- switch (c) {
487
- case ",":
488
- case "}":
489
- return newToken("punctuator", read());
490
- }
491
- throw invalidChar(read());
492
- },
493
- beforeArrayValue() {
494
- if (c === "]")
495
- return newToken("punctuator", read());
496
- lexState = "value";
497
- },
498
- afterArrayValue() {
499
- switch (c) {
500
- case ",":
501
- case "]":
502
- return newToken("punctuator", read());
503
- }
504
- throw invalidChar(read());
505
- },
506
- end() {
507
- throw invalidChar(read());
508
- }
509
- };
510
- function newToken(type, value) {
511
- return {
512
- type,
513
- value,
514
- line,
515
- column
516
- };
517
- }
518
- function literal(s) {
519
- for (const c2 of s) {
520
- if (peek() !== c2)
521
- throw invalidChar(read());
522
- read();
523
- }
524
- }
525
- function escape() {
526
- switch (peek()) {
527
- case "b":
528
- return read(), "\b";
529
- case "f":
530
- return read(), "\f";
531
- case "n":
532
- return read(), `
533
- `;
534
- case "r":
535
- return read(), "\r";
536
- case "t":
537
- return read(), " ";
538
- case "v":
539
- return read(), "\v";
540
- case "0":
541
- if (read(), util.isDigit(peek()))
542
- throw invalidChar(read());
543
- return "\0";
544
- case "x":
545
- return read(), hexEscape();
546
- case "u":
547
- return read(), unicodeEscape();
548
- case `
549
- `:
550
- case "\u2028":
551
- case "\u2029":
552
- return read(), "";
553
- case "\r":
554
- return read(), peek() === `
555
- ` && read(), "";
556
- case "1":
557
- case "2":
558
- case "3":
559
- case "4":
560
- case "5":
561
- case "6":
562
- case "7":
563
- case "8":
564
- case "9":
565
- throw invalidChar(read());
566
- case void 0:
567
- throw invalidChar(read());
568
- }
569
- return read();
570
- }
571
- function hexEscape() {
572
- let buffer2 = "", c2 = peek();
573
- if (!util.isHexDigit(c2) || (buffer2 += read(), c2 = peek(), !util.isHexDigit(c2)))
574
- throw invalidChar(read());
575
- return buffer2 += read(), String.fromCodePoint(parseInt(buffer2, 16));
576
- }
577
- function unicodeEscape() {
578
- let buffer2 = "", count = 4;
579
- for (; count-- > 0; ) {
580
- const c2 = peek();
581
- if (!util.isHexDigit(c2))
582
- throw invalidChar(read());
583
- buffer2 += read();
584
- }
585
- return String.fromCodePoint(parseInt(buffer2, 16));
586
- }
587
- const parseStates = {
588
- start() {
589
- if (token.type === "eof")
590
- throw invalidEOF();
591
- push();
592
- },
593
- beforePropertyName() {
594
- switch (token.type) {
595
- case "identifier":
596
- case "string":
597
- key = token.value, parseState = "afterPropertyName";
598
- return;
599
- case "punctuator":
600
- pop();
601
- return;
602
- case "eof":
603
- throw invalidEOF();
604
- }
605
- },
606
- afterPropertyName() {
607
- if (token.type === "eof")
608
- throw invalidEOF();
609
- parseState = "beforePropertyValue";
610
- },
611
- beforePropertyValue() {
612
- if (token.type === "eof")
613
- throw invalidEOF();
614
- push();
615
- },
616
- beforeArrayValue() {
617
- if (token.type === "eof")
618
- throw invalidEOF();
619
- if (token.type === "punctuator" && token.value === "]") {
620
- pop();
621
- return;
622
- }
623
- push();
624
- },
625
- afterPropertyValue() {
626
- if (token.type === "eof")
627
- throw invalidEOF();
628
- switch (token.value) {
629
- case ",":
630
- parseState = "beforePropertyName";
631
- return;
632
- case "}":
633
- pop();
634
- }
635
- },
636
- afterArrayValue() {
637
- if (token.type === "eof")
638
- throw invalidEOF();
639
- switch (token.value) {
640
- case ",":
641
- parseState = "beforeArrayValue";
642
- return;
643
- case "]":
644
- pop();
645
- }
646
- },
647
- end() {
648
- }
649
- };
650
- function push() {
651
- let value;
652
- switch (token.type) {
653
- case "punctuator":
654
- switch (token.value) {
655
- case "{":
656
- value = {};
657
- break;
658
- case "[":
659
- value = [];
660
- break;
661
- }
662
- break;
663
- case "null":
664
- case "boolean":
665
- case "numeric":
666
- case "string":
667
- value = token.value;
668
- break;
669
- }
670
- if (root === void 0)
671
- root = value;
672
- else {
673
- const parent = stack[stack.length - 1];
674
- Array.isArray(parent) ? parent.push(value) : Object.defineProperty(parent, key, {
675
- value,
676
- writable: !0,
677
- enumerable: !0,
678
- configurable: !0
679
- });
680
- }
681
- if (value !== null && typeof value == "object")
682
- stack.push(value), Array.isArray(value) ? parseState = "beforeArrayValue" : parseState = "beforePropertyName";
683
- else {
684
- const current = stack[stack.length - 1];
685
- current == null ? parseState = "end" : Array.isArray(current) ? parseState = "afterArrayValue" : parseState = "afterPropertyValue";
686
- }
687
- }
688
- function pop() {
689
- stack.pop();
690
- const current = stack[stack.length - 1];
691
- current == null ? parseState = "end" : Array.isArray(current) ? parseState = "afterArrayValue" : parseState = "afterPropertyValue";
692
- }
693
- function invalidChar(c2) {
694
- return syntaxError(c2 === void 0 ? `JSON5: invalid end of input at ${line}:${column}` : `JSON5: invalid character '${formatChar(c2)}' at ${line}:${column}`);
695
- }
696
- function invalidEOF() {
697
- return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
698
- }
699
- function invalidIdentifier() {
700
- return column -= 5, syntaxError(`JSON5: invalid identifier character at ${line}:${column}`);
701
- }
702
- function separatorChar(c2) {
703
- console.warn(`JSON5: '${formatChar(c2)}' in strings is not valid ECMAScript; consider escaping`);
704
- }
705
- function formatChar(c2) {
706
- const replacements = {
707
- "'": "\\'",
708
- '"': '\\"',
709
- "\\": "\\\\",
710
- "\b": "\\b",
711
- "\f": "\\f",
712
- "\n": "\\n",
713
- "\r": "\\r",
714
- " ": "\\t",
715
- "\v": "\\v",
716
- "\0": "\\0",
717
- "\u2028": "\\u2028",
718
- "\u2029": "\\u2029"
719
- };
720
- if (replacements[c2])
721
- return replacements[c2];
722
- if (c2 < " ") {
723
- const hexString = c2.charCodeAt(0).toString(16);
724
- return "\\x" + ("00" + hexString).substring(hexString.length);
725
- }
726
- return c2;
727
- }
728
- function syntaxError(message) {
729
- const err = new SyntaxError(message);
730
- return err.lineNumber = line, err.columnNumber = column, err;
731
- }
732
- var stringify = function(value, replacer, space) {
733
- const stack2 = [];
734
- let indent = "", propertyList, replacerFunc, gap = "", quote;
735
- if (replacer != null && typeof replacer == "object" && !Array.isArray(replacer) && (space = replacer.space, quote = replacer.quote, replacer = replacer.replacer), typeof replacer == "function")
736
- replacerFunc = replacer;
737
- else if (Array.isArray(replacer)) {
738
- propertyList = [];
739
- for (const v of replacer) {
740
- let item;
741
- typeof v == "string" ? item = v : (typeof v == "number" || v instanceof String || v instanceof Number) && (item = String(v)), item !== void 0 && propertyList.indexOf(item) < 0 && propertyList.push(item);
742
- }
743
- }
744
- return space instanceof Number ? space = Number(space) : space instanceof String && (space = String(space)), typeof space == "number" ? space > 0 && (space = Math.min(10, Math.floor(space)), gap = " ".substr(0, space)) : typeof space == "string" && (gap = space.substr(0, 10)), serializeProperty("", { "": value });
745
- function serializeProperty(key2, holder) {
746
- let value2 = holder[key2];
747
- switch (value2 != null && (typeof value2.toJSON5 == "function" ? value2 = value2.toJSON5(key2) : typeof value2.toJSON == "function" && (value2 = value2.toJSON(key2))), replacerFunc && (value2 = replacerFunc.call(holder, key2, value2)), value2 instanceof Number ? value2 = Number(value2) : value2 instanceof String ? value2 = String(value2) : value2 instanceof Boolean && (value2 = value2.valueOf()), value2) {
748
- case null:
749
- return "null";
750
- case !0:
751
- return "true";
752
- case !1:
753
- return "false";
754
- }
755
- if (typeof value2 == "string")
756
- return quoteString(value2);
757
- if (typeof value2 == "number")
758
- return String(value2);
759
- if (typeof value2 == "object")
760
- return Array.isArray(value2) ? serializeArray(value2) : serializeObject(value2);
761
- }
762
- function quoteString(value2) {
763
- const quotes = {
764
- "'": 0.1,
765
- '"': 0.2
766
- }, replacements = {
767
- "'": "\\'",
768
- '"': '\\"',
769
- "\\": "\\\\",
770
- "\b": "\\b",
771
- "\f": "\\f",
772
- "\n": "\\n",
773
- "\r": "\\r",
774
- " ": "\\t",
775
- "\v": "\\v",
776
- "\0": "\\0",
777
- "\u2028": "\\u2028",
778
- "\u2029": "\\u2029"
779
- };
780
- let product = "";
781
- for (let i = 0; i < value2.length; i++) {
782
- const c2 = value2[i];
783
- switch (c2) {
784
- case "'":
785
- case '"':
786
- quotes[c2]++, product += c2;
787
- continue;
788
- case "\0":
789
- if (util.isDigit(value2[i + 1])) {
790
- product += "\\x00";
791
- continue;
792
- }
793
- }
794
- if (replacements[c2]) {
795
- product += replacements[c2];
796
- continue;
797
- }
798
- if (c2 < " ") {
799
- let hexString = c2.charCodeAt(0).toString(16);
800
- product += "\\x" + ("00" + hexString).substring(hexString.length);
801
- continue;
802
- }
803
- product += c2;
804
- }
805
- const quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
806
- return product = product.replace(new RegExp(quoteChar, "g"), replacements[quoteChar]), quoteChar + product + quoteChar;
807
- }
808
- function serializeObject(value2) {
809
- if (stack2.indexOf(value2) >= 0)
810
- throw TypeError("Converting circular structure to JSON5");
811
- stack2.push(value2);
812
- let stepback = indent;
813
- indent = indent + gap;
814
- let keys = propertyList || Object.keys(value2), partial = [];
815
- for (const key2 of keys) {
816
- const propertyString = serializeProperty(key2, value2);
817
- if (propertyString !== void 0) {
818
- let member = serializeKey(key2) + ":";
819
- gap !== "" && (member += " "), member += propertyString, partial.push(member);
820
- }
821
- }
822
- let final;
823
- if (partial.length === 0)
824
- final = "{}";
825
- else {
826
- let properties;
827
- if (gap === "")
828
- properties = partial.join(","), final = "{" + properties + "}";
829
- else {
830
- let separator = `,
831
- ` + indent;
832
- properties = partial.join(separator), final = `{
833
- ` + indent + properties + `,
834
- ` + stepback + "}";
835
- }
836
- }
837
- return stack2.pop(), indent = stepback, final;
838
- }
839
- function serializeKey(key2) {
840
- if (key2.length === 0)
841
- return quoteString(key2);
842
- const firstChar = String.fromCodePoint(key2.codePointAt(0));
843
- if (!util.isIdStartChar(firstChar))
844
- return quoteString(key2);
845
- for (let i = firstChar.length; i < key2.length; i++)
846
- if (!util.isIdContinueChar(String.fromCodePoint(key2.codePointAt(i))))
847
- return quoteString(key2);
848
- return key2;
849
- }
850
- function serializeArray(value2) {
851
- if (stack2.indexOf(value2) >= 0)
852
- throw TypeError("Converting circular structure to JSON5");
853
- stack2.push(value2);
854
- let stepback = indent;
855
- indent = indent + gap;
856
- let partial = [];
857
- for (let i = 0; i < value2.length; i++) {
858
- const propertyString = serializeProperty(String(i), value2);
859
- partial.push(propertyString !== void 0 ? propertyString : "null");
860
- }
861
- let final;
862
- if (partial.length === 0)
863
- final = "[]";
864
- else if (gap === "")
865
- final = "[" + partial.join(",") + "]";
866
- else {
867
- let separator = `,
868
- ` + indent, properties = partial.join(separator);
869
- final = `[
870
- ` + indent + properties + `,
871
- ` + stepback + "]";
872
- }
873
- return stack2.pop(), indent = stepback, final;
874
- }
875
- };
876
- const JSON5 = {
877
- parse,
878
- stringify
879
- };
880
- var lib = JSON5;
881
- const stat$1 = util__default.default.promisify(fs__default.default.stat), mkdir = util__default.default.promisify(fs__default.default.mkdir), readdir = util__default.default.promisify(fs__default.default.readdir), copyFile = util__default.default.promisify(fs__default.default.copyFile), readFile$2 = util__default.default.promisify(fs__default.default.readFile), writeFile = util__default.default.promisify(fs__default.default.writeFile);
882
- function hasSourceEquivalent(compiledFile, paths) {
883
- if (!paths.source)
884
- return fileExists(
885
- path__default.default.isAbsolute(compiledFile) ? compiledFile : path__default.default.resolve(paths.basePath, compiledFile)
886
- );
887
- const baseDir = path__default.default.dirname(compiledFile.replace(paths.compiled, paths.source)), baseName = path__default.default.basename(compiledFile, path__default.default.extname(compiledFile)), pathStub = path__default.default.join(baseDir, baseName);
888
- return buildCandidateExists(pathStub);
889
- }
890
- async function hasSourceFile(filePath, paths) {
891
- if (!paths?.source)
892
- return fileExists(
893
- path__default.default.isAbsolute(filePath) ? filePath : path__default.default.resolve(paths?.basePath ?? "", filePath)
894
- );
895
- const pathStub = path__default.default.isAbsolute(filePath) ? filePath : path__default.default.resolve(paths.source, filePath);
896
- return await fileExists(pathStub) ? !0 : buildCandidateExists(pathStub);
897
- }
898
- function hasCompiledFile(filePath, paths) {
899
- if (!paths?.compiled)
900
- return fileExists(
901
- path__default.default.isAbsolute(filePath) ? filePath : path__default.default.resolve(paths?.basePath ?? "", filePath)
902
- );
903
- const absPath = path__default.default.isAbsolute(filePath) ? filePath : path__default.default.resolve(paths.compiled, filePath), withExt = path__default.default.extname(absPath) === "" ? `${absPath}.js` : absPath;
904
- return fileExists(withExt);
905
- }
906
- function buildCandidateExists(pathStub) {
907
- const candidates = buildExtensions.map((extCandidate) => `${pathStub}${extCandidate}`);
908
- return pAny__default.default(candidates.map((candidate) => stat$1(candidate))).then(() => !0).catch(() => !1);
909
- }
910
- function fileExists(filePath) {
911
- return stat$1(filePath).then(() => !0).catch(() => !1);
912
- }
913
- async function readJsonFile(filePath) {
914
- const content = await readFile$2(filePath, "utf8");
915
- return JSON.parse(content);
916
- }
917
- function writeJsonFile(filePath, content) {
918
- const data = JSON.stringify(content, null, 2) + `
919
- `;
920
- return writeFile(filePath, data, { encoding: "utf8" });
921
- }
922
- async function writeFileWithOverwritePrompt(filePath, content, options) {
923
- const { default: defaultVal, force = !1, ...writeOptions } = options, printablePath = filePath.startsWith(process.cwd()) ? path__default.default.relative(process.cwd(), filePath) : filePath;
924
- return await fileEqualsData(filePath, content) || !force && await fileExists(filePath) && !await prompt(`File "${printablePath}" already exists. Overwrite?`, {
925
- type: "confirm",
926
- default: defaultVal
927
- }) ? !1 : (await writeFile(filePath, content, writeOptions), !0);
928
- }
929
- async function copyFileWithOverwritePrompt(from, to, flags) {
930
- const printablePath = to.startsWith(process.cwd()) ? path__default.default.relative(process.cwd(), to) : to;
931
- return await filesAreEqual(from, to) || (await ensureDirectoryExists(to), !flags.force && await fileExists(to) && !await prompt(`File "${printablePath}" already exists. Overwrite?`, {
932
- type: "confirm",
933
- default: !1
934
- })) ? !1 : (await copyFile(from, to), !0);
935
- }
936
- async function ensureDirectoryExists(filePath) {
937
- const dirname = path__default.default.dirname(filePath);
938
- if (await fileExists(dirname))
939
- return !0;
940
- await ensureDirectoryExists(dirname), await mkdir(dirname);
941
- }
942
- async function fileEqualsData(filePath, content) {
943
- const contentHash = crypto__default.default.createHash("sha1").update(content).digest("hex"), remoteHash = await getFileHash(filePath);
944
- return contentHash === remoteHash;
945
- }
946
- async function filesAreEqual(file1, file2) {
947
- const [hash1, hash2] = await Promise.all([getFileHash(file1, !1), getFileHash(file2)]);
948
- return hash1 === hash2;
949
- }
950
- function getFileHash(filePath, allowMissing = !0) {
951
- return new Promise((resolve, reject) => {
952
- const hash = crypto__default.default.createHash("sha1"), stream = fs__default.default.createReadStream(filePath);
953
- stream.on("error", (err) => {
954
- err.code === "ENOENT" && allowMissing ? resolve(null) : reject(err);
955
- }), stream.on("end", () => resolve(hash.digest("hex"))), stream.on("data", (chunk) => hash.update(chunk));
956
- });
957
- }
958
- async function ensureDir(dirPath) {
959
- try {
960
- await mkdir(dirPath);
961
- } catch (err) {
962
- if (err.code !== "EEXIST")
963
- throw err;
964
- }
965
- }
966
- async function isEmptyish(dirPath) {
967
- const ignoredFiles = [".git", ".gitignore", "license", "readme.md"];
968
- return (await readdir(dirPath).catch(() => [])).filter((file) => !ignoredFiles.includes(file.toLowerCase())).length === 0;
969
- }
970
- async function readFileContent({
971
- filename,
972
- basePath
973
- }) {
974
- const filepath = path__default.default.normalize(path__default.default.join(basePath, filename));
975
- try {
976
- return await readFile$2(filepath, "utf8");
977
- } catch (err) {
978
- if (err.code === "ENOENT") {
979
- cli.log.debug(`No ${filename} file found.`);
980
- return;
981
- }
982
- throw new Error(`Failed to read "${filepath}": ${err.message}`);
983
- }
984
- }
985
- async function readJson5File({
986
- filename,
987
- basePath
988
- }) {
989
- const content = await readFileContent({ filename, basePath });
990
- if (content)
991
- return parseJson5(content, filename);
992
- }
993
- function parseJson5(content, errorKey) {
994
- try {
995
- return lib.parse(content);
996
- } catch (err) {
997
- throw new Error(`Error parsing "${errorKey}": ${err.message}`);
998
- }
999
- }
1000
- function errorToUndefined(err) {
1001
- if (err instanceof TypeError)
1002
- throw err;
1003
- }
1004
- const stat = util__default.default.promisify(fs__default.default.stat), readFile$1 = util__default.default.promisify(fs__default.default.readFile), allowedPartProps = ["name", "implements", "path", "description"], disallowedPluginProps = ["api", "project", "plugins", "env"];
1005
- async function getPaths(options) {
1006
- const { basePath } = options, manifest = await readManifest(options);
1007
- return manifest.paths ? absolutifyPaths(manifest.paths, basePath) : null;
1008
- }
1009
- function absolutifyPaths(paths, basePath) {
1010
- const getPath = (relative) => relative ? path__default.default.resolve(path__default.default.join(basePath, relative)) : void 0;
1011
- return paths ? {
1012
- basePath,
1013
- compiled: getPath(paths.compiled),
1014
- source: getPath(paths.source)
1015
- } : { basePath };
1016
- }
1017
- async function readManifest(options) {
1018
- const { basePath, validate = !0 } = options, manifestPath = path__default.default.normalize(path__default.default.join(basePath, "sanity.json"));
1019
- let content;
1020
- try {
1021
- content = await readFile$1(manifestPath, "utf8");
1022
- } catch (err) {
1023
- throw err.code === "ENOENT" ? new Error(
1024
- `No sanity.json found. sanity.json is required for plugins to function. Use \`${_package.pkg.binname} init\` for a new plugin, or create an empty \`sanity.json\` with an empty object (\`{}\`) for existing ones.`
1025
- ) : new Error(`Failed to read "${manifestPath}": ${err.message}`);
1026
- }
1027
- let parsed;
1028
- try {
1029
- parsed = JSON.parse(content);
1030
- } catch (err) {
1031
- throw new Error(`Error parsing "${manifestPath}": ${err.message}`);
1032
- }
1033
- return validate && await validateManifest(parsed, options), parsed;
1034
- }
1035
- async function validateManifest(manifest, opts) {
1036
- const options = { isPlugin: !0, ...opts };
1037
- if (!isObject$1(manifest))
1038
- throw new Error("Invalid sanity.json: Root must be an object");
1039
- if (options.isPlugin ? await validatePluginManifest(manifest, options) : await validateProjectManifest(manifest), "root" in manifest && typeof manifest.root != "boolean")
1040
- throw new Error('Invalid sanity.json: "root" property must be a boolean if declared');
1041
- await validateParts(manifest, {
1042
- ...options,
1043
- paths: absolutifyPaths(manifest.paths, options.basePath)
1044
- });
1045
- }
1046
- function validateProjectManifest(manifest) {
1047
- if ("paths" in manifest)
1048
- throw new Error('Invalid sanity.json: "paths" property has no meaning in a project manifest');
1049
- }
1050
- async function validatePluginManifest(manifest, options) {
1051
- const disallowed = Object.keys(manifest).filter((key2) => disallowedPluginProps.includes(key2)).map((key2) => `"${key2}"`);
1052
- if (disallowed.length > 0) {
1053
- const plural = disallowed.length > 1 ? "s" : "", joined = disallowed.join(", ");
1054
- throw new Error(
1055
- `Invalid sanity.json: Key${plural} ${joined} ${plural ? "are" : "is"} not allowed in a plugin manifest`
1056
- );
1057
- }
1058
- if (manifest.root)
1059
- throw new Error('Invalid sanity.json: "root" cannot be truthy in a plugin manifest');
1060
- await validatePaths$1(manifest, options);
1061
- }
1062
- async function validatePaths$1(manifest, options) {
1063
- if (!("paths" in manifest))
1064
- return;
1065
- if (!isObject$1(manifest.paths))
1066
- throw new Error('Invalid sanity.json: "paths" must be an object if declared');
1067
- if (typeof manifest.paths.compiled != "string")
1068
- throw new Error(
1069
- 'Invalid sanity.json: "paths" must have a (string) "compiled" property if declared'
1070
- );
1071
- if (typeof manifest.paths.source != "string")
1072
- throw new Error(
1073
- 'Invalid sanity.json: "paths" must have a (string) "source" property if declared'
1074
- );
1075
- const sourcePath = path__default.default.resolve(options.basePath, manifest.paths.source);
1076
- let srcStats;
1077
- try {
1078
- srcStats = await stat(sourcePath);
1079
- } catch (err) {
1080
- if (err.code === "ENOENT")
1081
- throw new Error(`sanity.json references "source" path which does not exist: "${sourcePath}"`);
1082
- }
1083
- if (!srcStats?.isDirectory())
1084
- throw new Error(
1085
- `sanity.json references "source" path which is not a directory: "${sourcePath}"`
1086
- );
1087
- }
1088
- async function validateParts(manifest, options) {
1089
- if (!("parts" in manifest))
1090
- return;
1091
- if (!Array.isArray(manifest.parts))
1092
- throw new Error('Invalid sanity.json: "parts" must be an array if declared');
1093
- let i = 0;
1094
- for (const part of manifest.parts)
1095
- await validatePart(part, i, options), i++;
1096
- }
1097
- async function validatePart(part, index, options) {
1098
- if (!isObject$1(part))
1099
- throw new Error(`Invalid sanity.json: "parts[${index}]" must be an object`);
1100
- validateAllowedPartKeys(part, index), validatePartStringValues(part, index), validatePartNames(part, index, options), await validatePartFiles(part, index, options);
1101
- }
1102
- async function validatePartFiles(part, index, options) {
1103
- const { verifyCompiledParts, verifySourceParts, paths } = options;
1104
- if (!part?.path)
1105
- return;
1106
- const ext = path__default.default.extname(part.path);
1107
- if (paths?.source && ext && ext !== ".js" && buildExtensions.includes(ext))
1108
- throw new Error(
1109
- `Invalid sanity.json: Part path has extension which is not applicable after compiling. ${ext} becomes .js after compiling. Specify filename without extension (${path__default.default.basename(
1110
- part.path
1111
- )}) (parts[${index}])`
1112
- );
1113
- if (!verifySourceParts && !verifyCompiledParts)
1114
- return;
1115
- const [srcExists, outDirExists] = await Promise.all([
1116
- hasSourceFile(part.path, paths),
1117
- verifyCompiledParts && hasCompiledFile(part.path, paths)
1118
- ]);
1119
- if (!srcExists)
1120
- throw new Error(
1121
- `Invalid sanity.json: Part path references file that does not exist in source directory (${paths?.source || paths?.basePath}) (parts[${index}])`
1122
- );
1123
- if (verifyCompiledParts && !outDirExists)
1124
- throw new Error(
1125
- `Invalid sanity.json: Part path references file ("${part.path}") that does not exist in compiled directory (${paths?.compiled}) (parts[${index}])`
1126
- );
1127
- }
1128
- function validatePartNames(part, index, options) {
1129
- const pluginName = options.pluginName ? options.pluginName.replace(/^sanity-plugin-/, "") : "";
1130
- if (!part?.name || !part?.name?.startsWith(`part:${pluginName}/`))
1131
- throw new Error(
1132
- `Invalid sanity.json: "name" must be prefixed with "part:${pluginName}/" - got "${part?.name}" (parts[${index}])`
1133
- );
1134
- if (!part?.implements?.startsWith("part:"))
1135
- throw new Error(
1136
- `Invalid sanity.json: "implements" must be prefixed with "part:" - got "${part?.implements}" (parts[${index}])`
1137
- );
1138
- }
1139
- function validateAllowedPartKeys(part, index) {
1140
- const disallowed = Object.keys(part).filter((key2) => !allowedPartProps.includes(key2)).map((key2) => `"${key2}"`);
1141
- if (disallowed.length > 0) {
1142
- const plural = disallowed.length > 1 ? "s" : "", joined = disallowed.join(", ");
1143
- throw new Error(
1144
- `Invalid sanity.json: Key${plural} ${joined} ${plural ? "are" : "is"} not allowed in a part declaration (parts[${index}])`
1145
- );
1146
- }
1147
- }
1148
- function validatePartStringValues(part, index) {
1149
- const nonStrings = Object.keys(part).filter((key2) => typeof part[key2] != "string").map((key2) => `"${key2}"`);
1150
- if (nonStrings.length > 0) {
1151
- const plural = nonStrings.length > 1 ? "s" : "", joined = nonStrings.join(", ");
1152
- throw new Error(
1153
- `Invalid sanity.json: Key${plural} ${joined} should be of type string (parts[${index}])`
1154
- );
1155
- }
1156
- }
1157
- function isObject$1(obj) {
1158
- return !Array.isArray(obj) && obj !== null && typeof obj == "object";
1159
- }
1160
- async function hasSanityJson(basePath) {
1161
- const file = await readJsonFile(path__default.default.join(basePath, "sanity.json")).catch(
1162
- errorToUndefined
1163
- );
1164
- return { exists: !!file, isRoot: !!(file && file.root) };
1165
- }
1166
- async function findStudioV3Config(basePath) {
1167
- const jsFile = "sanity.config.js";
1168
- if (await fileExists(path__default.default.join(basePath, jsFile)))
1169
- return { v3ConfigFile: jsFile };
1170
- const tsFile = "sanity.config.ts";
1171
- return { v3ConfigFile: await fileExists(path__default.default.join(basePath, tsFile)) ? tsFile : void 0 };
1172
- }
1173
- const lockedDependencies = {
1174
- "styled-components": "^6.1",
1175
- eslint: "^8.57.0"
1176
- };
1177
- function resolveLatestVersions(packages) {
1178
- const versions = {};
1179
- for (const pkgName of packages)
1180
- versions[pkgName] = pkgName in lockedDependencies ? lockedDependencies[pkgName] : "latest";
1181
- return pProps__default.default(
1182
- versions,
1183
- async (range, pkgName) => {
1184
- const version = await getLatestVersion__default.default(pkgName, { range });
1185
- if (!version)
1186
- throw new Error(`Found no version for ${pkgName}`);
1187
- return rangeify(version);
1188
- },
1189
- { concurrency: 8 }
1190
- );
1191
- }
1192
- function rangeify(version) {
1193
- return `^${version}`;
1194
- }
1195
- const mergedPackages = [
1196
- "@sanity/base",
1197
- "@sanity/core",
1198
- "@sanity/types",
1199
- "@sanity/data-aspects",
1200
- "@sanity/default-layout",
1201
- "@sanity/default-login",
1202
- "@sanity/desk-tool",
1203
- "@sanity/field",
1204
- "@sanity/form-builder",
1205
- "@sanity/initial-value-templates",
1206
- "@sanity/language-filter",
1207
- "@sanity/production-preview",
1208
- "@sanity/react-hooks",
1209
- "@sanity/resolver",
1210
- "@sanity/state-router",
1211
- "@sanity/structure",
1212
- "@sanity/studio-hints"
1213
- ].sort(), deprecatedDevDeps = [
1214
- "tsdx",
1215
- "sanipack",
1216
- "parcel",
1217
- "@parcel/packager-ts",
1218
- "@parcel/transformer-typescript-types"
1219
- ], expectedScripts = {
1220
- build: "plugin-kit verify-package --silent && pkg-utils build --strict --check --clean",
1221
- watch: "pkg-utils watch --strict",
1222
- "link-watch": "plugin-kit link-watch",
1223
- prepublishOnly: "npm run build"
1224
- };
1225
- function filesWithSuffixes(fileBases, suffixes) {
1226
- return fileBases.flatMap((file) => suffixes.map((suffix) => `${file}.${suffix}`));
1227
- }
1228
- function validateNodeEngine(packageJson) {
1229
- const nodeVersionRange = ">=18";
1230
- if (!packageJson.engines?.node?.startsWith(nodeVersionRange))
1231
- return [
1232
- outdent__default.default`
1233
- Expected package.json to contain engines.node: ">=18" to ensure Studio compatible builds,
1234
- but it was: ${packageJson.engines?.node}
1235
-
1236
- Please add the following to package.json:
1237
-
1238
- "engines": {
1239
- "node": "${nodeVersionRange}"
1240
- }`.trimStart()
1241
- ];
1242
- }
1243
- function validateScripts(packageJson) {
1244
- const errors = [], divergentScripts = Object.entries(expectedScripts).filter(([key2, expectedCommand]) => {
1245
- const command = packageJson.scripts?.[key2];
1246
- return !command || !command.includes(expectedCommand);
1247
- });
1248
- return divergentScripts.length && errors.push(
1249
- outdent__default.default`
1250
- The following script commands did not contain expected defaults: ${divergentScripts.map(([key2]) => key2).join(", ")}
1251
-
1252
- This checks for that the commands-strings includes these terms.
1253
-
1254
- Please add the following to your package.json "scripts":
1255
-
1256
- ${divergentScripts.map(([key2, value]) => `"${key2}": "${value}"`).join(`,
1257
- `)}
1258
- `.trimStart()
1259
- ), errors;
1260
- }
1261
- async function validateTsConfig(ts, options) {
1262
- const { basePath, outDir, tsconfig } = options, errors = [], wrongEntries = Object.entries({
1263
- target: "esnext",
1264
- jsx: "preserve",
1265
- module: "preserve",
1266
- rootDir: ".",
1267
- outDir,
1268
- noEmit: !0
1269
- }).filter(([key2, value]) => {
1270
- let option = ts.options[key2];
1271
- return key2 === "rootDir" && typeof option == "string" && (option = path__default.default.relative(basePath, option) || "."), key2 === "outDir" && typeof option == "string" && (option = path__default.default.relative(basePath, option) || "."), key2 === "target" && option === 99 && (option = "esnext"), key2 === "module" && option === 200 && (option = "preserve"), key2 === "jsx" && option === 1 && (option = "preserve"), typeof value == "string" && typeof option == "string" ? value.toLowerCase() !== option?.toLowerCase() : value !== option;
1272
- });
1273
- if (wrongEntries.length) {
1274
- const expectedOutput = wrongEntries.map(([key2, value]) => `"${key2}": ${typeof value == "string" ? `"${value}"` : value},`).join(`
1275
- `);
1276
- errors.push(
1277
- outdent__default.default`
1278
- Recommended ${tsconfig} compilerOptions missing:
1279
-
1280
- The following fields had unexpected values: [${wrongEntries.map(([key2]) => key2).join(", ")}]
1281
- Expected to find these values:
1282
- ${expectedOutput}
1283
-
1284
- Please update your ${tsconfig} accordingly.
1285
- `.trimStart()
1286
- );
1287
- }
1288
- return errors;
1289
- }
1290
- function validatePkgUtilsDependency({ devDependencies }) {
1291
- return devDependencies?.["@sanity/pkg-utils"] ? [] : [
1292
- outdent__default.default`
1293
- package.json does not list @sanity/pkg-utils as a devDependency.
1294
- @sanity/pkg-utils replaced parcel as the recommended build tool in @sanity/plugin-kit 2.0.0
1295
-
1296
- Please add it by running 'npm install --save-dev @sanity/pkg-utils'.
1297
- `.trimStart()
1298
- ];
1299
- }
1300
- function validateSanityDependencies(packageJson) {
1301
- const { dependencies, devDependencies, peerDependencies } = packageJson, allDependencies = { ...dependencies, ...devDependencies, ...peerDependencies }, illegalDeps = Object.keys(allDependencies).filter((dep) => mergedPackages.includes(dep)), unique = [...new Set(illegalDeps).values()];
1302
- return unique.length ? [
1303
- outdent__default.default`
1304
- package.json depends on "@sanity/*" packages that have moved into "sanity" package.
1305
-
1306
- The following dependencies should be replaced with "sanity":
1307
- - ${unique.join(`
1308
- - `)}
1309
-
1310
- Refer to the reference docs to find replacement imports:
1311
- ${cli.urls.refDocs}
1312
- `.trimStart()
1313
- ] : [];
1314
- }
1315
- function validateDeprecatedDependencies(packageJson) {
1316
- const { dependencies, devDependencies, peerDependencies } = packageJson, allDependencies = { ...dependencies, ...devDependencies, ...peerDependencies }, illegalDeps = Object.keys(allDependencies).filter((dep) => deprecatedDevDeps.includes(dep)), unique = [...new Set(illegalDeps).values()];
1317
- return unique.length ? [
1318
- outdent__default.default`
1319
- package.json contains deprecated dependencies that should be removed:
1320
- - ${unique.join(`
1321
- - `)}
1322
- `.trimStart()
1323
- ] : [];
1324
- }
1325
- async function validateBabelConfig({ basePath }) {
1326
- const filenames = [".babelrc", ...filesWithSuffixes([".babelrc", "babel.config"], ["json", "js", "cjs", "mjs"])], babelFiles = [];
1327
- for (const filename of filenames) {
1328
- const filepath = path__default.default.normalize(path__default.default.join(basePath, filename));
1329
- await fileExists(filepath) && babelFiles.push(filename);
1330
- }
1331
- return babelFiles.length ? [
1332
- outdent__default.default`
1333
- Found babel-config file: [${babelFiles.join(
1334
- ", "
1335
- )}]. When using default @sanity/plugin-kit build command,
1336
- this is probably not needed.
1337
-
1338
- Delete the file, or disable this check.
1339
- `.trimStart()
1340
- ] : [];
1341
- }
1342
- async function validateStudioConfig({ basePath }) {
1343
- const suffixes = ["ts", "js", "tsx", "jsx"], filenames = filesWithSuffixes(["sanity.config", "sanity.cli"], suffixes), files = {};
1344
- for (const filename of filenames) {
1345
- const filepath = path__default.default.normalize(path__default.default.join(basePath, filename));
1346
- files[filename] = await fileExists(filepath);
1347
- }
1348
- const sanityJson = await readJson5File({ basePath, filename: "sanity.json" }), hasConfigFile = (fileBase) => filesWithSuffixes([fileBase], suffixes).some((filename) => files[filename]), hasCliConfig = hasConfigFile("sanity.cli"), hasStudioConfig = hasConfigFile("sanity.config"), errors = [];
1349
- if (sanityJson) {
1350
- const info = [
1351
- outdent__default.default`
1352
- Found sanity.json. This file is not used by Sanity Studio V3.
1353
-
1354
- Please consult the Studio V3 migration guide:
1355
- ${cli.urls.migrationGuideStudio}
1356
- It will detail how to convert sanity.json to sanity.config.ts (or .js) and sanity.cli.ts (or .js) equivalents.
1357
- `.trimStart(),
1358
- sanityJson.plugins?.length && outdent__default.default`
1359
- For V3 versions and alternatives to V2 plugins, please refer to the Sanity Exchange:
1360
- ${cli.urls.sanityExchange}
1361
- `.trimStart()
1362
- ].filter((s) => !!s);
1363
- errors.push(info.join(`
1364
-
1365
- `));
1366
- }
1367
- return hasCliConfig || errors.push(
1368
- outdent__default.default`
1369
- sanity.cli.(${suffixes.join(
1370
- " | "
1371
- )}) missing. Please create a file named sanity.cli.ts with the following content:
1372
-
1373
- ${chalk__default.default.green(
1374
- outdent__default.default`
1375
- import {createCliConfig} from 'sanity/cli'
1376
-
1377
- export default createCliConfig({
1378
- api: {
1379
- projectId: '${sanityJson?.api?.projectId ?? "project-id"}',
1380
- dataset: '${sanityJson?.api?.dataset ?? "dataset"}',
1381
- }
1382
- })`
1383
- )}
1384
-
1385
- Make sure to replace the projectId and dataset fields with your own.
1386
-
1387
- For more, see ${cli.urls.migrationGuideStudio}
1388
- `.trimStart()
1389
- ), hasStudioConfig || errors.push(
1390
- outdent__default.default`
1391
- sanity.config.(${suffixes.join(
1392
- " | "
1393
- )}) missing. At a minimum sanity.config.ts should contain:
1394
-
1395
- ${chalk__default.default.green(
1396
- outdent__default.default`
1397
- import { defineConfig } from "sanity"
1398
- import { deskTool } from "sanity/desk"
1399
-
1400
- export default defineConfig({
1401
- name: "default",
1402
-
1403
- projectId: '${sanityJson?.api?.projectId ?? "project-id"}',
1404
- dataset: '${sanityJson?.api?.dataset ?? "dataset"}',
1405
-
1406
- plugins: [
1407
- deskTool(),
1408
- ],
1409
-
1410
- schema: {
1411
- types: [
1412
- /* put your v2 schema-types here */
1413
- ],
1414
- },
1415
- })`
1416
- ).trimStart()}
1417
-
1418
- Make sure to replace the projectId and dataset fields with your own.
1419
-
1420
- For more, see ${cli.urls.migrationGuideStudio}
1421
- `.trimStart()
1422
- ), errors.length ? [errors.join(`
1423
-
1424
- ---
1425
-
1426
- `)] : [];
1427
- }
1428
- async function validatePluginSanityJson({
1429
- basePath,
1430
- packageJson
1431
- }) {
1432
- const sanityJson = await readJson5File({ basePath, filename: "sanity.json" }), expectedDefaults = {
1433
- parts: [
1434
- {
1435
- implements: "part:@sanity/base/sanity-root",
1436
- path: "./v2-incompatible.js"
1437
- }
1438
- ]
1439
- }, hasSinglePart = sanityJson && Object.keys(sanityJson).length === 1 && sanityJson?.parts && sanityJson.parts.length === 1, firstPart = hasSinglePart ? sanityJson?.parts?.[0] : void 0, correctImplements = firstPart?.implements === expectedDefaults.parts[0].implements, pathExists = firstPart?.path && await fileExists(path__default.default.normalize(path__default.default.join(basePath, firstPart.path))), hasDependency = !!packageJson.dependencies?.[cli.incompatiblePluginPackage];
1440
- if (!(sanityJson && hasSinglePart && correctImplements && pathExists && hasDependency)) {
1441
- const errors = [
1442
- sanityJson ? null : "sanity.json does not exist",
1443
- hasSinglePart ? null : 'sanity.json should have exactly one entry in "parts", but did not.',
1444
- correctImplements ? null : `The part should implement ${expectedDefaults.parts[0].implements}, but did not.`,
1445
- firstPart?.path && !pathExists ? `The file in "path", ${firstPart?.path}, does not exist.` : null,
1446
- hasDependency ? null : outdent__default.default`
1447
- package.json should have ${cli.incompatiblePluginPackage} as a dependency, but did not.
1448
- Install it with: npm install --save ${cli.incompatiblePluginPackage}
1449
- `.trimStart()
1450
- ].filter((e) => !!e);
1451
- return [
1452
- outdent__default.default`
1453
- Invalid sanity.json. It is used for compatibility checking in V2 studios:
1454
-
1455
- - ${errors.join(`
1456
- - `)}
1457
-
1458
- sanity.json will only be used when incorrectly installing a v3 plugin in a v2 Studio.
1459
-
1460
- This check ensures that sanity.json conforms with the usage section of
1461
- ${cli.urls.incompatiblePlugin}
1462
- `.trimStart()
1463
- ];
1464
- }
1465
- return [];
1466
- }
1467
- function validatePackageName$1(packageJson) {
1468
- const valid = validateNpmPackageName__default.default(
1469
- packageJson.name
1470
- );
1471
- if (!valid.validForNewPackages)
1472
- return [`Invalid package.json: "name" is invalid: ${valid.errors.join(", ")}`];
1473
- if (!packageJson.name?.startsWith("@") && !packageJson.name?.startsWith("sanity-plugin-"))
1474
- return [
1475
- 'Invalid package.json: "name" should be prefixed with "sanity-plugin-" (or scoped - @your-company/plugin-name)'
1476
- ];
1477
- }
1478
- async function validateSrcIndexFile(basePath) {
1479
- const paths = ["index.js", "index.ts"].map((p) => path__default.default.join("src", p)), allowedIndexFiles = paths.map((file) => path__default.default.join(basePath, file));
1480
- let hasIndex = !1;
1481
- for (const indexFile of allowedIndexFiles)
1482
- hasIndex = hasIndex || await fileExists(indexFile);
1483
- return hasIndex ? [] : [
1484
- outdent__default.default`
1485
- Expected one of [${paths.join(", ")}] to exist.
1486
-
1487
- @sanity/pkg-utils expects a non-jsx file to be the source entry-point for the plugin.
1488
- If you currently have JSX in your index file, extract it into a separate file and import it.
1489
- `
1490
- ];
1491
- }
1492
- async function disallowDuplicateConfig({
1493
- basePath,
1494
- pkgJson,
1495
- configKey,
1496
- files
1497
- }) {
1498
- const found = [];
1499
- for (const file of files) {
1500
- const filePath = path__default.default.join(basePath, file);
1501
- await fileExists(filePath) && found.push(file);
1502
- }
1503
- return found.length > 1 ? [
1504
- outdent__default.default`
1505
- Found multiple config files that serve the same purpose: [${found.join(", ")}].
1506
-
1507
- There should be at most one of these files. Delete the rest.
1508
- `
1509
- ] : found.length && pkgJson[configKey] ? [
1510
- outdent__default.default`
1511
- package.json contains ${configKey}, but there also exists a config file that serves the same purpose.
1512
- Config file: ${found.join("")}]
1513
-
1514
- Either delete the file or remove ${configKey} entry from package.json.
1515
- `
1516
- ] : [];
1517
- }
1518
- async function disallowDuplicateEslintConfig(basePath, pkgJson) {
1519
- return disallowDuplicateConfig({
1520
- basePath,
1521
- pkgJson,
1522
- configKey: "eslint",
1523
- files: [
1524
- ".eslintrc",
1525
- ".eslintrc.js",
1526
- ".eslintrc.cjs",
1527
- ".eslintrc.yaml",
1528
- ".eslintrc.yml",
1529
- ".eslintrc.json"
1530
- ]
1531
- });
1532
- }
1533
- async function disallowDuplicatePrettierConfig(basePath, pkgJson) {
1534
- return disallowDuplicateConfig({
1535
- basePath,
1536
- pkgJson,
1537
- configKey: "prettier",
1538
- files: [
1539
- ".prettierrc",
1540
- ".prettierrc.json5",
1541
- ".prettierrc.json",
1542
- ".prettierrc.yaml",
1543
- ".prettierrc.yml",
1544
- ".prettierrc.js",
1545
- ".prettierrc.cjs",
1546
- ".prettier.config,js",
1547
- ".prettier.config.cjs",
1548
- ".prettierrc.toml"
1549
- ]
1550
- });
1551
- }
1552
- const forcedPackageVersions = {}, forcedDevPackageVersions = forcedPackageVersions, forcedPeerPackageVersions = {
1553
- react: "^18",
1554
- "react-dom": "^18",
1555
- "@types/react": "^18",
1556
- "@types/react-dom": "^18",
1557
- sanity: "^3",
1558
- "styled-components": "^5.2"
1559
- }, defaultDependencies = [cli.incompatiblePluginPackage], defaultDevDependencies = [
1560
- "sanity",
1561
- // peer dependencies of `sanity`
1562
- "react",
1563
- "react-dom",
1564
- "styled-components"
1565
- ], defaultPeerDependencies = ["react", "sanity"], readFile = util__default.default.promisify(fs__default.default.readFile), pathKeys = ["main", "module", "browser", "types"];
1566
- async function getPackage(opts) {
1567
- const options = { flags: {}, ...opts };
1568
- validateOptions(options);
1569
- const { basePath, validate = !0 } = options, manifestPath = path__default.default.normalize(path__default.default.join(basePath, "package.json"));
1570
- let content;
1571
- try {
1572
- content = await readFile(manifestPath, "utf8");
1573
- } catch (err) {
1574
- throw err.code === "ENOENT" ? new Error(
1575
- `No package.json found. package.json is required to publish to npm. Use \`${cli.cliName} init\` for a new plugin, or \`npm init\` for an existing one`
1576
- ) : new Error(`Failed to read "${manifestPath}": ${err.message}`);
1577
- }
1578
- let parsed;
1579
- try {
1580
- parsed = JSON.parse(content);
1581
- } catch (err) {
1582
- throw new Error(`Error parsing "${manifestPath}": ${err.message}`);
1583
- }
1584
- if (!isObject(parsed))
1585
- throw new Error("Invalid package.json: Root must be an object");
1586
- return validate && await validatePackage(parsed, options), parsed;
1587
- }
1588
- async function validatePackage(manifest, opts) {
1589
- validateOptions(opts);
1590
- const options = { isPlugin: !0, ...opts };
1591
- options.isPlugin && await validatePluginPackage(manifest, options), validateLockFiles(options);
1592
- }
1593
- function validateOptions(opts) {
1594
- const options = opts || {};
1595
- if (!isObject(options))
1596
- throw new Error("Options must be an object");
1597
- if (typeof options.basePath != "string")
1598
- throw new Error('"options.basePath" must be a string (path to plugin base path)');
1599
- }
1600
- async function validatePluginPackage(manifest, options) {
1601
- validatePackageName(manifest), await validatePaths(manifest, options);
1602
- }
1603
- function validatePackageName(manifest) {
1604
- if (typeof manifest.name != "string")
1605
- throw new Error('Invalid package.json: "name" must be a string');
1606
- const valid = validateNpmPackageName__default.default(
1607
- manifest.name
1608
- );
1609
- if (!valid.validForNewPackages)
1610
- throw new Error(`Invalid package.json: "name" is invalid: ${valid.errors.join(", ")}`);
1611
- if (manifest.name[0] !== "@" && !manifest.name.startsWith("sanity-plugin-"))
1612
- throw new Error(
1613
- 'Invalid package.json: "name" should be prefixed with "sanity-plugin-" (or scoped - @your-company/plugin-name)'
1614
- );
1615
- }
1616
- async function validatePaths(manifest, options) {
1617
- const paths = await getPaths({
1618
- ...options,
1619
- pluginName: manifest.name ?? "unknown",
1620
- verifySourceParts: !1,
1621
- verifyCompiledParts: !1
1622
- }), abs = (file) => path__default.default.isAbsolute(file) ? file : path__default.default.resolve(path__default.default.join(options.basePath, file)), exists = (file) => fs__default.default.existsSync(abs(file)), willExist = (file) => paths && hasSourceEquivalent(abs(file), paths), withinSourceDir = (file) => paths?.source && abs(file).startsWith(paths.source), withinTargetDir = (file) => paths?.compiled && abs(file).startsWith(paths.compiled);
1623
- for (const key2 of pathKeys) {
1624
- if (!(key2 in manifest))
1625
- continue;
1626
- const manifestValue = manifest[key2];
1627
- if (typeof manifestValue != "string")
1628
- throw new Error(`Invalid package.json: "${key2}" must be a string if defined`);
1629
- if (!options?.flags?.allowSourceTarget && paths && withinSourceDir(manifestValue))
1630
- throw new Error(
1631
- `Invalid package.json: "${key2}" points to file within source (uncompiled) directory. Use --allow-source-target if you really want to do this.`
1632
- );
1633
- if (exists(manifestValue) && paths && withinTargetDir(manifestValue) && !await willExist(manifestValue))
1634
- throw new Error(
1635
- `Invalid package.json: "${key2}" points to file that will not exist after compiling`
1636
- );
1637
- if (!exists(manifestValue) && !await willExist(manifestValue)) {
1638
- if (!paths)
1639
- throw new Error(`Invalid package.json: "${key2}" points to file that does not exist`);
1640
- const inOutDir = paths.compiled && !abs(manifestValue).startsWith(paths.compiled);
1641
- throw new Error(
1642
- inOutDir ? `Invalid package.json: "${key2}" points to file that does not exist, and "paths" is not configured to compile to this location` : `Invalid package.json: "${key2}" points to file that does not exist, and no equivalent is found in source directory`
1643
- );
1644
- }
1645
- }
1646
- }
1647
- function isObject(obj) {
1648
- return !Array.isArray(obj) && obj !== null && typeof obj == "object";
1649
- }
1650
- function validateLockFiles(options) {
1651
- const npm = fs__default.default.existsSync(path__default.default.join(options.basePath, "package-lock.json")), yarn = fs__default.default.existsSync(path__default.default.join(options.basePath, "yarn.lock"));
1652
- if (npm && yarn)
1653
- throw new Error("Invalid plugin: contains both package-lock.json and yarn.lock");
1654
- }
1655
- async function writePackageJson(data, options) {
1656
- const { user, pluginName, license, description, pkg: prevPkg, gitOrigin } = data, {
1657
- outDir,
1658
- peerDependencies: addPeers,
1659
- dependencies: addDeps,
1660
- devDependencies: addDevDeps
1661
- } = options, { flags } = options, prev = prevPkg || {}, usePrettier = flags.prettier !== !1, useEslint = flags.eslint !== !1, useTypescript = flags.eslint !== !1, newDevDependencies = [cli.cliName, "@sanity/pkg-utils"];
1662
- useTypescript && (cli.log.debug("Using TypeScript. Adding to dev dependencies."), newDevDependencies.push("@types/react", "typescript")), usePrettier && (cli.log.debug("Using prettier. Adding to dev dependencies."), newDevDependencies.push("prettier", "prettier-plugin-packagejson")), useEslint && (cli.log.debug("Using eslint. Adding to dev dependencies."), newDevDependencies.push(
1663
- "eslint",
1664
- "eslint-config-sanity",
1665
- "eslint-plugin-react",
1666
- "eslint-plugin-react-hooks"
1667
- ), usePrettier && newDevDependencies.push("eslint-config-prettier", "eslint-plugin-prettier"), useTypescript && newDevDependencies.push("@typescript-eslint/eslint-plugin", "@typescript-eslint/parser")), cli.log.debug("Resolving latest versions for %s", newDevDependencies.join(", "));
1668
- const dependencies = forceDependencyVersions(
1669
- {
1670
- ...prev.dependencies || {},
1671
- ...addDeps || {},
1672
- ...await resolveLatestVersions(defaultDependencies)
1673
- },
1674
- forcedPackageVersions
1675
- ), devDependencies = forceDependencyVersions(
1676
- {
1677
- ...addDevDeps || {},
1678
- ...prev.devDependencies || {},
1679
- ...await resolveLatestVersions([...newDevDependencies, ...defaultDevDependencies])
1680
- },
1681
- forcedDevPackageVersions
1682
- ), peerDependencies = forceDependencyVersions(
1683
- {
1684
- ...prev.peerDependencies || {},
1685
- ...addPeers || {},
1686
- ...await resolveLatestVersions(defaultPeerDependencies)
1687
- },
1688
- forcedPeerPackageVersions
1689
- ), source2 = flags.typescript ? "./src/index.ts" : "./src/index.js", files = [outDir, "sanity.json", "src", "v2-incompatible.js"];
1690
- files.sort();
1691
- const forcedOrder = {
1692
- name: pluginName,
1693
- version: prev.version ?? "1.0.0",
1694
- description: description || "",
1695
- keywords: prev.keywords ?? ["sanity", "sanity-plugin"],
1696
- ...urlsFromOrigin(gitOrigin),
1697
- ...repoFromOrigin(gitOrigin),
1698
- license: license ? license.id : "UNLICENSED",
1699
- author: user?.email ? `${user.name} <${user.email}>` : user?.name,
1700
- sideEffects: !1,
1701
- type: "commonjs",
1702
- exports: {
1703
- ".": {
1704
- source: source2,
1705
- import: `./${outDir}/index.mjs`,
1706
- default: `./${outDir}/index.js`
1707
- },
1708
- "./package.json": "./package.json"
1709
- },
1710
- main: `./${outDir}/index.js`,
1711
- ...flags.typescript ? { types: `./${outDir}/index.d.ts` } : {},
1712
- files,
1713
- scripts: { ...prev.scripts },
1714
- dependencies: sortKeys(dependencies),
1715
- devDependencies: sortKeys(devDependencies),
1716
- peerDependencies: sortKeys(peerDependencies),
1717
- engines: {
1718
- node: ">=18"
1719
- }
1720
- }, manifest = {
1721
- ...forcedOrder,
1722
- // Use already configured values by default (if not otherwise specified)
1723
- ...prev || {},
1724
- // We're de-declaring properties because of key order in package.json
1725
- ...forcedOrder
1726
- }, differs = JSON.stringify(prev) !== JSON.stringify(manifest);
1727
- return cli.log.debug("Does manifest differ? %s", differs ? "yes" : "no"), differs && await writePackageJsonDirect(manifest, options), differs ? manifest : prev;
1728
- }
1729
- function urlsFromOrigin(gitOrigin) {
1730
- const details = githubUrlToObject__default.default(gitOrigin);
1731
- return details ? {
1732
- homepage: `https://github.com/${details.user}/${details.repo}#readme`,
1733
- bugs: {
1734
- url: `https://github.com/${details.user}/${details.repo}/issues`
1735
- }
1736
- } : {};
1737
- }
1738
- function repoFromOrigin(gitOrigin) {
1739
- return console.log(gitOrigin), gitOrigin ? {
1740
- repository: {
1741
- type: "git",
1742
- url: gitOrigin
1743
- }
1744
- } : {};
1745
- }
1746
- function addScript(cmd, existing) {
1747
- return existing && existing.includes(cmd) ? existing : cmd;
1748
- }
1749
- async function addPackageJsonScripts(manifest, options, updateScripts) {
1750
- const originalScripts = manifest.scripts || {}, scripts = updateScripts({ ...originalScripts }), differs = Object.keys(scripts).some((key2) => scripts[key2] !== originalScripts[key2]);
1751
- return differs && await writePackageJsonDirect({ ...manifest, scripts }, options), differs;
1752
- }
1753
- async function writePackageJsonDirect(manifest, { basePath }) {
1754
- await writeJsonFile(path__default.default.join(basePath, "package.json"), manifest);
1755
- }
1756
- async function addBuildScripts(manifest, options) {
1757
- return options.flags.scripts ? addPackageJsonScripts(manifest, options, (scripts) => (scripts.build = addScript(expectedScripts.build, scripts.build), scripts.format = addScript("prettier --write --cache --ignore-unknown .", scripts.format), scripts["link-watch"] = addScript(expectedScripts["link-watch"], scripts["link-watch"]), scripts.lint = addScript("eslint .", scripts.lint), scripts.prepublishOnly = addScript(expectedScripts.prepublishOnly, scripts.prepublishOnly), scripts.watch = addScript(expectedScripts.watch, scripts.watch), scripts)) : !1;
1758
- }
1759
- function sortKeys(unordered) {
1760
- return Object.keys(unordered).sort().reduce((obj, key2) => (obj[key2] = unordered[key2], obj), {});
1761
- }
1762
- function forceDependencyVersions(deps, versions = forcedPackageVersions) {
1763
- const entries = Object.entries(deps).map((entry) => {
1764
- const [pkg] = entry, forceVersion = versions[pkg];
1765
- return forceVersion ? [pkg, forceVersion] : entry;
1766
- });
1767
- return Object.fromEntries(entries);
1768
- }
1769
- exports.addBuildScripts = addBuildScripts;
1770
- exports.addPackageJsonScripts = addPackageJsonScripts;
1771
- exports.addScript = addScript;
1772
- exports.copyFileWithOverwritePrompt = copyFileWithOverwritePrompt;
1773
- exports.disallowDuplicateEslintConfig = disallowDuplicateEslintConfig;
1774
- exports.disallowDuplicatePrettierConfig = disallowDuplicatePrettierConfig;
1775
- exports.ensureDir = ensureDir;
1776
- exports.errorToUndefined = errorToUndefined;
1777
- exports.fileExists = fileExists;
1778
- exports.findStudioV3Config = findStudioV3Config;
1779
- exports.forceDependencyVersions = forceDependencyVersions;
1780
- exports.forcedDevPackageVersions = forcedDevPackageVersions;
1781
- exports.forcedPackageVersions = forcedPackageVersions;
1782
- exports.getPackage = getPackage;
1783
- exports.hasSanityJson = hasSanityJson;
1784
- exports.isEmptyish = isEmptyish;
1785
- exports.mergedPackages = mergedPackages;
1786
- exports.mkdir = mkdir;
1787
- exports.prompt = prompt;
1788
- exports.promptForPackageName = promptForPackageName;
1789
- exports.promptForRepoOrigin = promptForRepoOrigin;
1790
- exports.readFile = readFile$2;
1791
- exports.readJsonFile = readJsonFile;
1792
- exports.resolveLatestVersions = resolveLatestVersions;
1793
- exports.sortKeys = sortKeys;
1794
- exports.validateBabelConfig = validateBabelConfig;
1795
- exports.validateDeprecatedDependencies = validateDeprecatedDependencies;
1796
- exports.validateNodeEngine = validateNodeEngine;
1797
- exports.validatePackageName = validatePackageName$1;
1798
- exports.validatePkgUtilsDependency = validatePkgUtilsDependency;
1799
- exports.validatePluginSanityJson = validatePluginSanityJson;
1800
- exports.validateSanityDependencies = validateSanityDependencies;
1801
- exports.validateScripts = validateScripts;
1802
- exports.validateSrcIndexFile = validateSrcIndexFile;
1803
- exports.validateStudioConfig = validateStudioConfig;
1804
- exports.validateTsConfig = validateTsConfig;
1805
- exports.writeFile = writeFile;
1806
- exports.writeFileWithOverwritePrompt = writeFileWithOverwritePrompt;
1807
- exports.writePackageJson = writePackageJson;
1808
- exports.writePackageJsonDirect = writePackageJsonDirect;
1809
- //# sourceMappingURL=package.js.map