@sanity/cli-build 0.1.0 → 0.2.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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_exports/_internal/build.d.ts +2418 -0
  3. package/dist/_exports/_internal/build.js +10 -0
  4. package/dist/_exports/_internal/build.js.map +1 -0
  5. package/dist/_exports/_internal/extract.d.ts +120 -0
  6. package/dist/_exports/_internal/extract.js +9 -0
  7. package/dist/_exports/_internal/extract.js.map +1 -0
  8. package/dist/actions/build/buildDebug.js +4 -0
  9. package/dist/actions/build/buildDebug.js.map +1 -0
  10. package/dist/actions/build/buildVendorDependencies.js +149 -0
  11. package/dist/actions/build/buildVendorDependencies.js.map +1 -0
  12. package/dist/actions/build/checkStudioDependencyVersions.js +155 -0
  13. package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -0
  14. package/dist/actions/build/createExternalFromImportMap.js +11 -0
  15. package/dist/actions/build/createExternalFromImportMap.js.map +1 -0
  16. package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js +13 -0
  17. package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js.map +1 -0
  18. package/dist/actions/build/decorateIndexWithBridgeScript.js +17 -0
  19. package/dist/actions/build/decorateIndexWithBridgeScript.js.map +1 -0
  20. package/dist/actions/build/decorateIndexWithStagingScript.js +16 -0
  21. package/dist/actions/build/decorateIndexWithStagingScript.js.map +1 -0
  22. package/dist/actions/build/getEntryModule.js +46 -0
  23. package/dist/actions/build/getEntryModule.js.map +1 -0
  24. package/dist/actions/build/getPossibleDocumentComponentLocations.js +11 -0
  25. package/dist/actions/build/getPossibleDocumentComponentLocations.js.map +1 -0
  26. package/dist/actions/build/getViteConfig.js +204 -0
  27. package/dist/actions/build/getViteConfig.js.map +1 -0
  28. package/dist/actions/build/normalizeBasePath.js +9 -0
  29. package/dist/actions/build/normalizeBasePath.js.map +1 -0
  30. package/dist/actions/build/renderDocument.js +50 -0
  31. package/dist/actions/build/renderDocument.js.map +1 -0
  32. package/dist/actions/build/renderDocument.worker.js +9 -0
  33. package/dist/actions/build/renderDocument.worker.js.map +1 -0
  34. package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +79 -0
  35. package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +1 -0
  36. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +61 -0
  37. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +1 -0
  38. package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +165 -0
  39. package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +1 -0
  40. package/dist/actions/build/renderDocumentWorker/components/Favicons.js +28 -0
  41. package/dist/actions/build/renderDocumentWorker/components/Favicons.js.map +1 -0
  42. package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +178 -0
  43. package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +1 -0
  44. package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js +51 -0
  45. package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js.map +1 -0
  46. package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +41 -0
  47. package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +1 -0
  48. package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +55 -0
  49. package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +1 -0
  50. package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +31 -0
  51. package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +1 -0
  52. package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +30 -0
  53. package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +1 -0
  54. package/dist/actions/build/renderDocumentWorker/types.js +5 -0
  55. package/dist/actions/build/renderDocumentWorker/types.js.map +1 -0
  56. package/dist/actions/build/vite/plugin-sanity-build-entries.js +67 -0
  57. package/dist/actions/build/vite/plugin-sanity-build-entries.js.map +1 -0
  58. package/dist/actions/build/vite/plugin-sanity-favicons.js +72 -0
  59. package/dist/actions/build/vite/plugin-sanity-favicons.js.map +1 -0
  60. package/dist/actions/build/vite/plugin-sanity-runtime-rewrite.js +18 -0
  61. package/dist/actions/build/vite/plugin-sanity-runtime-rewrite.js.map +1 -0
  62. package/dist/actions/build/writeSanityRuntime.js +66 -0
  63. package/dist/actions/build/writeSanityRuntime.js.map +1 -0
  64. package/dist/actions/schema/extractSanitySchema.worker.js +32 -0
  65. package/dist/actions/schema/extractSanitySchema.worker.js.map +1 -0
  66. package/dist/actions/schema/formatSchemaValidation.js +78 -0
  67. package/dist/actions/schema/formatSchemaValidation.js.map +1 -0
  68. package/dist/actions/schema/getExtractOptions.js +23 -0
  69. package/dist/actions/schema/getExtractOptions.js.map +1 -0
  70. package/dist/actions/schema/matchSchemaPattern.js +21 -0
  71. package/dist/actions/schema/matchSchemaPattern.js.map +1 -0
  72. package/dist/actions/schema/runSchemaExtraction.js +39 -0
  73. package/dist/actions/schema/runSchemaExtraction.js.map +1 -0
  74. package/dist/actions/schema/types.js +9 -0
  75. package/dist/actions/schema/types.js.map +1 -0
  76. package/dist/actions/schema/utils/SchemaExtractionError.js +10 -0
  77. package/dist/actions/schema/utils/SchemaExtractionError.js.map +1 -0
  78. package/dist/actions/schema/utils/extractValidationFromSchemaError.js +12 -0
  79. package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +1 -0
  80. package/dist/actions/schema/vite/plugin-schema-extraction.js +201 -0
  81. package/dist/actions/schema/vite/plugin-schema-extraction.js.map +1 -0
  82. package/dist/constants.js +8 -0
  83. package/dist/constants.js.map +1 -0
  84. package/dist/telemetry/build.telemetry.js +13 -0
  85. package/dist/telemetry/build.telemetry.js.map +1 -0
  86. package/dist/telemetry/extractSchema.telemetry.js +18 -0
  87. package/dist/telemetry/extractSchema.telemetry.js.map +1 -0
  88. package/package.json +58 -29
  89. package/dist/_exports/_internal.d.ts +0 -45
  90. package/dist/_exports/_internal.js +0 -5
  91. package/dist/_exports/_internal.js.map +0 -1
@@ -0,0 +1,165 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Favicons } from './Favicons.js';
3
+ import { GlobalErrorHandler } from './GlobalErrorHandler.js';
4
+ import { NoJavascript } from './NoJavascript.js';
5
+ const globalStyles = `
6
+ @font-face {
7
+ font-family: Inter;
8
+ font-style: normal;
9
+ font-weight: 400;
10
+ font-display: swap;
11
+ src: url("https://studio-static.sanity.io/Inter-Regular.woff2") format("woff2");
12
+ }
13
+ @font-face {
14
+ font-family: Inter;
15
+ font-style: italic;
16
+ font-weight: 400;
17
+ font-display: swap;
18
+ src: url("https://studio-static.sanity.io/Inter-Italic.woff2") format("woff2");
19
+ }
20
+ @font-face {
21
+ font-family: Inter;
22
+ font-style: normal;
23
+ font-weight: 500;
24
+ font-display: swap;
25
+ src: url("https://studio-static.sanity.io/Inter-Medium.woff2") format("woff2");
26
+ }
27
+ @font-face {
28
+ font-family: Inter;
29
+ font-style: italic;
30
+ font-weight: 500;
31
+ font-display: swap;
32
+ src: url("https://studio-static.sanity.io/Inter-MediumItalic.woff2") format("woff2");
33
+ }
34
+ @font-face {
35
+ font-family: Inter;
36
+ font-style: normal;
37
+ font-weight: 600;
38
+ font-display: swap;
39
+ src: url("https://studio-static.sanity.io/Inter-SemiBold.woff2") format("woff2");
40
+ }
41
+ @font-face {
42
+ font-family: Inter;
43
+ font-style: italic;
44
+ font-weight: 600;
45
+ font-display: swap;
46
+ src: url("https://studio-static.sanity.io/Inter-SemiBoldItalic.woff2") format("woff2");
47
+ }
48
+ @font-face {
49
+ font-family: Inter;
50
+ font-style: normal;
51
+ font-weight: 700;
52
+ font-display: swap;
53
+ src: url("https://studio-static.sanity.io/Inter-Bold.woff2") format("woff2");
54
+ }
55
+ @font-face {
56
+ font-family: Inter;
57
+ font-style: italic;
58
+ font-weight: 700;
59
+ font-display: swap;
60
+ src: url("https://studio-static.sanity.io/Inter-BoldItalic.woff2") format("woff2");
61
+ }
62
+ @font-face {
63
+ font-family: Inter;
64
+ font-style: normal;
65
+ font-weight: 800;
66
+ font-display: swap;
67
+ src: url("https://studio-static.sanity.io/Inter-ExtraBold.woff2") format("woff2");
68
+ }
69
+ @font-face {
70
+ font-family: Inter;
71
+ font-style: italic;
72
+ font-weight: 800;
73
+ font-display: swap;
74
+ src: url("https://studio-static.sanity.io/Inter-ExtraBoldItalic.woff2") format("woff2");
75
+ }
76
+ @font-face {
77
+ font-family: Inter;
78
+ font-style: normal;
79
+ font-weight: 900;
80
+ font-display: swap;
81
+ src: url("https://studio-static.sanity.io/Inter-Black.woff2") format("woff2");
82
+ }
83
+ @font-face {
84
+ font-family: Inter;
85
+ font-style: italic;
86
+ font-weight: 900;
87
+ font-display: swap;
88
+ src: url("https://studio-static.sanity.io/Inter-BlackItalic.woff2") format("woff2");
89
+ }
90
+ html {
91
+ @media (prefers-color-scheme: dark) {
92
+ background-color: #13141b;
93
+ }
94
+ @media (prefers-color-scheme: light) {
95
+ background-color: #ffffff;
96
+ }
97
+ }
98
+ html,
99
+ body,
100
+ #sanity {
101
+ height: 100%;
102
+ }
103
+ body {
104
+ margin: 0;
105
+ -webkit-font-smoothing: antialiased;
106
+ }
107
+ `;
108
+ const EMPTY_ARRAY = [];
109
+ /**
110
+ * @internal
111
+ */ export function DefaultDocument(props) {
112
+ const { css = EMPTY_ARRAY, entryPath } = props;
113
+ return /*#__PURE__*/ _jsxs("html", {
114
+ lang: "en",
115
+ children: [
116
+ /*#__PURE__*/ _jsxs("head", {
117
+ children: [
118
+ /*#__PURE__*/ _jsx("meta", {
119
+ charSet: "utf-8"
120
+ }),
121
+ /*#__PURE__*/ _jsx("meta", {
122
+ content: "width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover",
123
+ name: "viewport"
124
+ }),
125
+ /*#__PURE__*/ _jsx("meta", {
126
+ content: "noindex",
127
+ name: "robots"
128
+ }),
129
+ /*#__PURE__*/ _jsx("meta", {
130
+ content: "same-origin",
131
+ name: "referrer"
132
+ }),
133
+ /*#__PURE__*/ _jsx(Favicons, {}),
134
+ /*#__PURE__*/ _jsx("title", {
135
+ children: "Sanity Studio"
136
+ }),
137
+ /*#__PURE__*/ _jsx(GlobalErrorHandler, {}),
138
+ css.map((href)=>/*#__PURE__*/ _jsx("link", {
139
+ href: href,
140
+ rel: "stylesheet"
141
+ }, href)),
142
+ /*#__PURE__*/ _jsx("style", {
143
+ dangerouslySetInnerHTML: {
144
+ __html: globalStyles
145
+ }
146
+ })
147
+ ]
148
+ }),
149
+ /*#__PURE__*/ _jsxs("body", {
150
+ children: [
151
+ /*#__PURE__*/ _jsx("div", {
152
+ id: "sanity"
153
+ }),
154
+ /*#__PURE__*/ _jsx("script", {
155
+ src: entryPath,
156
+ type: "module"
157
+ }),
158
+ /*#__PURE__*/ _jsx(NoJavascript, {})
159
+ ]
160
+ })
161
+ ]
162
+ });
163
+ }
164
+
165
+ //# sourceMappingURL=DefaultDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/DefaultDocument.tsx"],"sourcesContent":["import {Favicons} from './Favicons.js'\nimport {GlobalErrorHandler} from './GlobalErrorHandler.js'\nimport {NoJavascript} from './NoJavascript.js'\n\nconst globalStyles = `\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-Regular.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 400;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-Italic.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-Medium.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 500;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-MediumItalic.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-SemiBold.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 600;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-SemiBoldItalic.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 700;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-Bold.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 700;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-BoldItalic.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 800;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-ExtraBold.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 800;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-ExtraBoldItalic.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: normal;\n font-weight: 900;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-Black.woff2\") format(\"woff2\");\n }\n @font-face {\n font-family: Inter;\n font-style: italic;\n font-weight: 900;\n font-display: swap;\n src: url(\"https://studio-static.sanity.io/Inter-BlackItalic.woff2\") format(\"woff2\");\n }\n html {\n @media (prefers-color-scheme: dark) {\n background-color: #13141b;\n }\n @media (prefers-color-scheme: light) {\n background-color: #ffffff;\n }\n }\n html,\n body,\n #sanity {\n height: 100%;\n }\n body {\n margin: 0;\n -webkit-font-smoothing: antialiased;\n }\n`\n\n/**\n * @hidden\n * @beta\n */\nexport interface DefaultDocumentProps {\n entryPath: string\n\n // Currently unused, but kept for potential future use\n basePath?: string\n\n css?: string[]\n}\n\nconst EMPTY_ARRAY: never[] = []\n\n/**\n * @internal\n */\nexport function DefaultDocument(props: DefaultDocumentProps): React.JSX.Element {\n const {css = EMPTY_ARRAY, entryPath} = props\n\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta\n content=\"width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover\"\n name=\"viewport\"\n />\n <meta content=\"noindex\" name=\"robots\" />\n <meta content=\"same-origin\" name=\"referrer\" />\n\n <Favicons />\n\n <title>Sanity Studio</title>\n\n <GlobalErrorHandler />\n\n {css.map((href) => (\n <link href={href} key={href} rel=\"stylesheet\" />\n ))}\n <style dangerouslySetInnerHTML={{__html: globalStyles}} />\n </head>\n <body>\n <div id=\"sanity\" />\n <script src={entryPath} type=\"module\" />\n <NoJavascript />\n </body>\n </html>\n )\n}\n"],"names":["Favicons","GlobalErrorHandler","NoJavascript","globalStyles","EMPTY_ARRAY","DefaultDocument","props","css","entryPath","html","lang","head","meta","charSet","content","name","title","map","href","link","rel","style","dangerouslySetInnerHTML","__html","body","div","id","script","src","type"],"mappings":";AAAA,SAAQA,QAAQ,QAAO,gBAAe;AACtC,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,YAAY,QAAO,oBAAmB;AAE9C,MAAMC,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGtB,CAAC;AAeD,MAAMC,cAAuB,EAAE;AAE/B;;CAEC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAACC,MAAMH,WAAW,EAAEI,SAAS,EAAC,GAAGF;IAEvC,qBACE,MAACG;QAAKC,MAAK;;0BACT,MAACC;;kCACC,KAACC;wBAAKC,SAAQ;;kCACd,KAACD;wBACCE,SAAQ;wBACRC,MAAK;;kCAEP,KAACH;wBAAKE,SAAQ;wBAAUC,MAAK;;kCAC7B,KAACH;wBAAKE,SAAQ;wBAAcC,MAAK;;kCAEjC,KAACf;kCAED,KAACgB;kCAAM;;kCAEP,KAACf;oBAEAM,IAAIU,GAAG,CAAC,CAACC,qBACR,KAACC;4BAAKD,MAAMA;4BAAiBE,KAAI;2BAAVF;kCAEzB,KAACG;wBAAMC,yBAAyB;4BAACC,QAAQpB;wBAAY;;;;0BAEvD,MAACqB;;kCACC,KAACC;wBAAIC,IAAG;;kCACR,KAACC;wBAAOC,KAAKpB;wBAAWqB,MAAK;;kCAC7B,KAAC3B;;;;;AAIT"}
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ export function Favicons() {
3
+ const base = '/static';
4
+ return /*#__PURE__*/ _jsxs(_Fragment, {
5
+ children: [
6
+ /*#__PURE__*/ _jsx("link", {
7
+ href: `${base}/favicon.ico`,
8
+ rel: "icon",
9
+ sizes: "any"
10
+ }),
11
+ /*#__PURE__*/ _jsx("link", {
12
+ href: `${base}/favicon.svg`,
13
+ rel: "icon",
14
+ type: "image/svg+xml"
15
+ }),
16
+ /*#__PURE__*/ _jsx("link", {
17
+ href: `${base}/apple-touch-icon.png`,
18
+ rel: "apple-touch-icon"
19
+ }),
20
+ /*#__PURE__*/ _jsx("link", {
21
+ href: `${base}/manifest.webmanifest`,
22
+ rel: "manifest"
23
+ })
24
+ ]
25
+ });
26
+ }
27
+
28
+ //# sourceMappingURL=Favicons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/Favicons.tsx"],"sourcesContent":["import {type JSX} from 'react'\n\nexport function Favicons(): JSX.Element {\n const base = '/static'\n return (\n <>\n <link href={`${base}/favicon.ico`} rel=\"icon\" sizes=\"any\" />\n <link href={`${base}/favicon.svg`} rel=\"icon\" type=\"image/svg+xml\" />\n <link href={`${base}/apple-touch-icon.png`} rel=\"apple-touch-icon\" />\n <link href={`${base}/manifest.webmanifest`} rel=\"manifest\" />\n </>\n )\n}\n"],"names":["Favicons","base","link","href","rel","sizes","type"],"mappings":";AAEA,OAAO,SAASA;IACd,MAAMC,OAAO;IACb,qBACE;;0BACE,KAACC;gBAAKC,MAAM,GAAGF,KAAK,YAAY,CAAC;gBAAEG,KAAI;gBAAOC,OAAM;;0BACpD,KAACH;gBAAKC,MAAM,GAAGF,KAAK,YAAY,CAAC;gBAAEG,KAAI;gBAAOE,MAAK;;0BACnD,KAACJ;gBAAKC,MAAM,GAAGF,KAAK,qBAAqB,CAAC;gBAAEG,KAAI;;0BAChD,KAACF;gBAAKC,MAAM,GAAGF,KAAK,qBAAqB,CAAC;gBAAEG,KAAI;;;;AAGtD"}
@@ -0,0 +1,178 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const errorHandlerScript = `
3
+ ;(function () {
4
+ var _caughtErrors = []
5
+
6
+ var errorChannel = (function () {
7
+ var subscribers = []
8
+
9
+ function publish(msg) {
10
+ for (var i = 0; i < subscribers.length; i += 1) {
11
+ subscribers[i](msg)
12
+ }
13
+ }
14
+
15
+ function subscribe(subscriber) {
16
+ subscribers.push(subscriber)
17
+
18
+ return function () {
19
+ var idx = subscribers.indexOf(subscriber)
20
+
21
+ if (idx > -1) {
22
+ subscribers.splice(idx, 1)
23
+ }
24
+ }
25
+ }
26
+
27
+ return {publish, subscribe, subscribers}
28
+ })()
29
+
30
+ // NOTE: Store the error channel instance in the global scope so that the application can
31
+ // access it and subscribe to errors.
32
+ window.__sanityErrorChannel = {
33
+ subscribe: errorChannel.subscribe,
34
+ }
35
+
36
+ function _nextTick(callback) {
37
+ setTimeout(callback, 0)
38
+ }
39
+
40
+ function _handleError(error, params) {
41
+ _nextTick(function () {
42
+ // - If there are error channel subscribers, then we notify them (no console error).
43
+ // - If there are no subscribers, then we log the error to the console and render the error overlay.
44
+ if (errorChannel.subscribers.length) {
45
+ errorChannel.publish({error, params})
46
+ } else {
47
+ console.error(error)
48
+
49
+ _renderErrorOverlay(error, params)
50
+ }
51
+ })
52
+ }
53
+
54
+ var ERROR_BOX_STYLE = [
55
+ 'background: #fff',
56
+ 'border-radius: 6px',
57
+ 'box-sizing: border-box',
58
+ 'color: #121923',
59
+ 'flex: 1',
60
+ "font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue','Liberation Sans',Helvetica,Arial,system-ui,sans-serif",
61
+ 'font-size: 16px',
62
+ 'line-height: 21px',
63
+ 'margin: 0 auto',
64
+ 'max-width: 960px',
65
+ 'max-height: 90dvh',
66
+ 'overflow: auto',
67
+ 'padding: 20px',
68
+ 'width: 100%',
69
+ ].join(';')
70
+
71
+ var ERROR_CODE_STYLE = [
72
+ 'color: #972E2A',
73
+ "font-family: -apple-system-ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace",
74
+ 'font-size: 13px',
75
+ 'line-height: 17px',
76
+ 'margin: 0',
77
+ ].join(';')
78
+
79
+ function _renderErrorOverlay(error, params) {
80
+ var errorElement = document.querySelector('#__sanityError') || document.createElement('div')
81
+ var colno = params.event.colno
82
+ var lineno = params.event.lineno
83
+ var filename = params.event.filename
84
+
85
+ errorElement.id = '__sanityError'
86
+ errorElement.innerHTML = [
87
+ '<div style="' + ERROR_BOX_STYLE + '">',
88
+ '<div style="font-weight: 700;">Uncaught error: ' + error.message + '</div>',
89
+ '<div style="color: #515E72; font-size: 13px; line-height: 17px; margin: 10px 0;">' +
90
+ filename +
91
+ ':' +
92
+ lineno +
93
+ ':' +
94
+ colno +
95
+ '</div>',
96
+ '<pre style="' + ERROR_CODE_STYLE + '">' + error.stack + '</pre>',
97
+ '</div>',
98
+ ].join('')
99
+
100
+ errorElement.style.position = 'fixed'
101
+ errorElement.style.zIndex = 1000000
102
+ errorElement.style.top = 0
103
+ errorElement.style.left = 0
104
+ errorElement.style.right = 0
105
+ errorElement.style.bottom = 0
106
+ errorElement.style.padding = '20px'
107
+ errorElement.style.background = 'rgba(16,17,18,0.66)'
108
+ errorElement.style.display = 'flex'
109
+ errorElement.style.alignItems = 'center'
110
+ errorElement.style.justifyContent = 'center'
111
+
112
+ document.body.appendChild(errorElement)
113
+ }
114
+
115
+ // NOTE:
116
+ // Yes – we're attaching 2 error listeners below 👀
117
+ // This is because React makes the same error throw twice (in development mode).
118
+ // See: https://github.com/facebook/react/issues/10384
119
+
120
+ // Error listener #1
121
+ window.onerror = function (event, source, lineno, colno, error) {
122
+ _nextTick(function () {
123
+ if (_caughtErrors.indexOf(error) !== -1) return
124
+
125
+ _caughtErrors.push(error)
126
+
127
+ _handleError(error, {
128
+ event,
129
+ lineno,
130
+ colno,
131
+ source,
132
+ })
133
+
134
+ _nextTick(function () {
135
+ var idx = _caughtErrors.indexOf(error)
136
+
137
+ if (idx > -1) _caughtErrors.splice(idx, 1)
138
+ })
139
+ })
140
+
141
+ // IMPORTANT: this callback must return \`true\` to prevent the error from being rendered in
142
+ // the browser’s console.
143
+ return true
144
+ }
145
+
146
+ // Error listener #2
147
+ window.addEventListener('error', function (event) {
148
+ if (_caughtErrors.indexOf(event.error) !== -1) return true
149
+
150
+ _caughtErrors.push(event.error)
151
+
152
+ _handleError(event.error, {
153
+ event,
154
+ lineno: event.lineno,
155
+ colno: event.colno,
156
+ })
157
+
158
+ _nextTick(function () {
159
+ _nextTick(function () {
160
+ var idx = _caughtErrors.indexOf(event.error)
161
+
162
+ if (idx > -1) _caughtErrors.splice(idx, 1)
163
+ })
164
+ })
165
+
166
+ return true
167
+ })
168
+ })()
169
+ `;
170
+ /** @internal */ export function GlobalErrorHandler() {
171
+ return /*#__PURE__*/ _jsx("script", {
172
+ dangerouslySetInnerHTML: {
173
+ __html: errorHandlerScript
174
+ }
175
+ });
176
+ }
177
+
178
+ //# sourceMappingURL=GlobalErrorHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/GlobalErrorHandler.tsx"],"sourcesContent":["import {type JSX} from 'react'\n\nconst errorHandlerScript = `\n;(function () {\n var _caughtErrors = []\n\n var errorChannel = (function () {\n var subscribers = []\n\n function publish(msg) {\n for (var i = 0; i < subscribers.length; i += 1) {\n subscribers[i](msg)\n }\n }\n\n function subscribe(subscriber) {\n subscribers.push(subscriber)\n\n return function () {\n var idx = subscribers.indexOf(subscriber)\n\n if (idx > -1) {\n subscribers.splice(idx, 1)\n }\n }\n }\n\n return {publish, subscribe, subscribers}\n })()\n\n // NOTE: Store the error channel instance in the global scope so that the application can\n // access it and subscribe to errors.\n window.__sanityErrorChannel = {\n subscribe: errorChannel.subscribe,\n }\n\n function _nextTick(callback) {\n setTimeout(callback, 0)\n }\n\n function _handleError(error, params) {\n _nextTick(function () {\n // - If there are error channel subscribers, then we notify them (no console error).\n // - If there are no subscribers, then we log the error to the console and render the error overlay.\n if (errorChannel.subscribers.length) {\n errorChannel.publish({error, params})\n } else {\n console.error(error)\n\n _renderErrorOverlay(error, params)\n }\n })\n }\n\n var ERROR_BOX_STYLE = [\n 'background: #fff',\n 'border-radius: 6px',\n 'box-sizing: border-box',\n 'color: #121923',\n 'flex: 1',\n \"font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue','Liberation Sans',Helvetica,Arial,system-ui,sans-serif\",\n 'font-size: 16px',\n 'line-height: 21px',\n 'margin: 0 auto',\n 'max-width: 960px',\n 'max-height: 90dvh',\n 'overflow: auto',\n 'padding: 20px',\n 'width: 100%',\n ].join(';')\n\n var ERROR_CODE_STYLE = [\n 'color: #972E2A',\n \"font-family: -apple-system-ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace\",\n 'font-size: 13px',\n 'line-height: 17px',\n 'margin: 0',\n ].join(';')\n\n function _renderErrorOverlay(error, params) {\n var errorElement = document.querySelector('#__sanityError') || document.createElement('div')\n var colno = params.event.colno\n var lineno = params.event.lineno\n var filename = params.event.filename\n\n errorElement.id = '__sanityError'\n errorElement.innerHTML = [\n '<div style=\"' + ERROR_BOX_STYLE + '\">',\n '<div style=\"font-weight: 700;\">Uncaught error: ' + error.message + '</div>',\n '<div style=\"color: #515E72; font-size: 13px; line-height: 17px; margin: 10px 0;\">' +\n filename +\n ':' +\n lineno +\n ':' +\n colno +\n '</div>',\n '<pre style=\"' + ERROR_CODE_STYLE + '\">' + error.stack + '</pre>',\n '</div>',\n ].join('')\n\n errorElement.style.position = 'fixed'\n errorElement.style.zIndex = 1000000\n errorElement.style.top = 0\n errorElement.style.left = 0\n errorElement.style.right = 0\n errorElement.style.bottom = 0\n errorElement.style.padding = '20px'\n errorElement.style.background = 'rgba(16,17,18,0.66)'\n errorElement.style.display = 'flex'\n errorElement.style.alignItems = 'center'\n errorElement.style.justifyContent = 'center'\n\n document.body.appendChild(errorElement)\n }\n\n // NOTE:\n // Yes – we're attaching 2 error listeners below 👀\n // This is because React makes the same error throw twice (in development mode).\n // See: https://github.com/facebook/react/issues/10384\n\n // Error listener #1\n window.onerror = function (event, source, lineno, colno, error) {\n _nextTick(function () {\n if (_caughtErrors.indexOf(error) !== -1) return\n\n _caughtErrors.push(error)\n\n _handleError(error, {\n event,\n lineno,\n colno,\n source,\n })\n\n _nextTick(function () {\n var idx = _caughtErrors.indexOf(error)\n\n if (idx > -1) _caughtErrors.splice(idx, 1)\n })\n })\n\n // IMPORTANT: this callback must return \\`true\\` to prevent the error from being rendered in\n // the browser’s console.\n return true\n }\n\n // Error listener #2\n window.addEventListener('error', function (event) {\n if (_caughtErrors.indexOf(event.error) !== -1) return true\n\n _caughtErrors.push(event.error)\n\n _handleError(event.error, {\n event,\n lineno: event.lineno,\n colno: event.colno,\n })\n\n _nextTick(function () {\n _nextTick(function () {\n var idx = _caughtErrors.indexOf(event.error)\n\n if (idx > -1) _caughtErrors.splice(idx, 1)\n })\n })\n\n return true\n })\n})()\n`\n\n/** @internal */\nexport function GlobalErrorHandler(): JSX.Element {\n return <script dangerouslySetInnerHTML={{__html: errorHandlerScript}} />\n}\n"],"names":["errorHandlerScript","GlobalErrorHandler","script","dangerouslySetInnerHTML","__html"],"mappings":";AAEA,MAAMA,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuK5B,CAAC;AAED,cAAc,GACd,OAAO,SAASC;IACd,qBAAO,KAACC;QAAOC,yBAAyB;YAACC,QAAQJ;QAAkB;;AACrE"}
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const NoJsStyles = `
3
+ .sanity-app-no-js__root {
4
+ position: absolute;
5
+ top: 0;
6
+ right: 0;
7
+ left: 0;
8
+ bottom: 0;
9
+ background: #fff;
10
+ }
11
+
12
+ .sanity-app-no-js__content {
13
+ position: absolute;
14
+ top: 50%;
15
+ left: 50%;
16
+ transform: translate(-50%, -50%);
17
+ text-align: center;
18
+ font-family: helvetica, arial, sans-serif;
19
+ }
20
+ `;
21
+ /** @internal */ export function NoJavascript() {
22
+ return /*#__PURE__*/ _jsx("noscript", {
23
+ children: /*#__PURE__*/ _jsx("div", {
24
+ className: "sanity-app-no-js__root",
25
+ children: /*#__PURE__*/ _jsxs("div", {
26
+ className: "sanity-app-no-js__content",
27
+ children: [
28
+ /*#__PURE__*/ _jsx("style", {
29
+ type: "text/css",
30
+ children: NoJsStyles
31
+ }),
32
+ /*#__PURE__*/ _jsx("h1", {
33
+ children: "JavaScript disabled"
34
+ }),
35
+ /*#__PURE__*/ _jsxs("p", {
36
+ children: [
37
+ "Please ",
38
+ /*#__PURE__*/ _jsx("a", {
39
+ href: "https://www.enable-javascript.com/",
40
+ children: "enable JavaScript"
41
+ }),
42
+ " in your browser and reload the page to proceed."
43
+ ]
44
+ })
45
+ ]
46
+ })
47
+ })
48
+ });
49
+ }
50
+
51
+ //# sourceMappingURL=NoJavascript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/NoJavascript.tsx"],"sourcesContent":["import {type JSX} from 'react'\n\nconst NoJsStyles = `\n.sanity-app-no-js__root {\n position: absolute;\n top: 0;\n right: 0;\n left: 0;\n bottom: 0;\n background: #fff;\n}\n\n.sanity-app-no-js__content {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n text-align: center;\n font-family: helvetica, arial, sans-serif;\n}\n`\n\n/** @internal */\nexport function NoJavascript(): JSX.Element {\n return (\n <noscript>\n <div className=\"sanity-app-no-js__root\">\n <div className=\"sanity-app-no-js__content\">\n <style type=\"text/css\">{NoJsStyles}</style>\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your\n browser and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n )\n}\n"],"names":["NoJsStyles","NoJavascript","noscript","div","className","style","type","h1","p","a","href"],"mappings":";AAEA,MAAMA,aAAa,CAAC;;;;;;;;;;;;;;;;;;AAkBpB,CAAC;AAED,cAAc,GACd,OAAO,SAASC;IACd,qBACE,KAACC;kBACC,cAAA,KAACC;YAAIC,WAAU;sBACb,cAAA,MAACD;gBAAIC,WAAU;;kCACb,KAACC;wBAAMC,MAAK;kCAAYN;;kCACxB,KAACO;kCAAG;;kCACJ,MAACC;;4BAAE;0CACM,KAACC;gCAAEC,MAAK;0CAAqC;;4BAAqB;;;;;;;AAOrF"}
@@ -0,0 +1,41 @@
1
+ import path from 'node:path';
2
+ import { buildDebug } from '../buildDebug.js';
3
+ import { BasicDocument } from './components/BasicDocument.js';
4
+ import { DefaultDocument } from './components/DefaultDocument.js';
5
+ import { tryLoadDocumentComponent } from './tryLoadDocumentComponent.js';
6
+ /**
7
+ * @internal
8
+ */ export async function getDocumentComponent(parent, studioRootPath, isApp) {
9
+ buildDebug('Loading default document component from `sanity` module');
10
+ const Document = isApp ? BasicDocument : DefaultDocument;
11
+ buildDebug('Attempting to load user-defined document component from %s', studioRootPath);
12
+ const userDefined = await tryLoadDocumentComponent(studioRootPath);
13
+ if (!userDefined) {
14
+ buildDebug('Using default document component');
15
+ return Document;
16
+ }
17
+ buildDebug('Found user defined document component at %s', userDefined.path);
18
+ const DocumentComp = userDefined.component.default || userDefined.component // CommonJS
19
+ ;
20
+ if (typeof DocumentComp === 'function') {
21
+ buildDebug('User defined document component is a function, assuming valid');
22
+ return DocumentComp;
23
+ }
24
+ buildDebug('User defined document component did not have a default export');
25
+ const userExports = Object.keys(userDefined.component).join(', ') || 'None';
26
+ const relativePath = path.relative(process.cwd(), userDefined.path);
27
+ const typeHint = userDefined.component.default === undefined ? '' : ` (type was ${typeof userDefined.component.default})`;
28
+ const warnKey = `${relativePath}/${userDefined.modified}`;
29
+ parent.postMessage({
30
+ message: [
31
+ `${relativePath} did not have a default export that is a React component${typeHint}`,
32
+ `Named exports/properties found: ${userExports}`.trim(),
33
+ `Using default document component from "sanity".`
34
+ ],
35
+ type: 'warning',
36
+ warnKey
37
+ });
38
+ return DefaultDocument;
39
+ }
40
+
41
+ //# sourceMappingURL=getDocumentComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/getDocumentComponent.ts"],"sourcesContent":["import path from 'node:path'\nimport {type MessagePort} from 'node:worker_threads'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {BasicDocument} from './components/BasicDocument.js'\nimport {DefaultDocument} from './components/DefaultDocument.js'\nimport {tryLoadDocumentComponent} from './tryLoadDocumentComponent.js'\n\n/**\n * @internal\n */\nexport async function getDocumentComponent(\n parent: MessagePort,\n studioRootPath: string,\n isApp?: boolean,\n) {\n buildDebug('Loading default document component from `sanity` module')\n\n const Document = isApp ? BasicDocument : DefaultDocument\n\n buildDebug('Attempting to load user-defined document component from %s', studioRootPath)\n const userDefined = await tryLoadDocumentComponent(studioRootPath)\n\n if (!userDefined) {\n buildDebug('Using default document component')\n return Document\n }\n\n buildDebug('Found user defined document component at %s', userDefined.path)\n\n const DocumentComp = userDefined.component.default || userDefined.component // CommonJS\n if (typeof DocumentComp === 'function') {\n buildDebug('User defined document component is a function, assuming valid')\n return DocumentComp\n }\n\n buildDebug('User defined document component did not have a default export')\n const userExports = Object.keys(userDefined.component).join(', ') || 'None'\n const relativePath = path.relative(process.cwd(), userDefined.path)\n const typeHint =\n userDefined.component.default === undefined\n ? ''\n : ` (type was ${typeof userDefined.component.default})`\n\n const warnKey = `${relativePath}/${userDefined.modified}`\n\n parent.postMessage({\n message: [\n `${relativePath} did not have a default export that is a React component${typeHint}`,\n `Named exports/properties found: ${userExports}`.trim(),\n `Using default document component from \"sanity\".`,\n ],\n type: 'warning',\n warnKey,\n })\n\n return DefaultDocument\n}\n"],"names":["path","buildDebug","BasicDocument","DefaultDocument","tryLoadDocumentComponent","getDocumentComponent","parent","studioRootPath","isApp","Document","userDefined","DocumentComp","component","default","userExports","Object","keys","join","relativePath","relative","process","cwd","typeHint","undefined","warnKey","modified","postMessage","message","trim","type"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAG5B,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,aAAa,QAAO,gCAA+B;AAC3D,SAAQC,eAAe,QAAO,kCAAiC;AAC/D,SAAQC,wBAAwB,QAAO,gCAA+B;AAEtE;;CAEC,GACD,OAAO,eAAeC,qBACpBC,MAAmB,EACnBC,cAAsB,EACtBC,KAAe;IAEfP,WAAW;IAEX,MAAMQ,WAAWD,QAAQN,gBAAgBC;IAEzCF,WAAW,8DAA8DM;IACzE,MAAMG,cAAc,MAAMN,yBAAyBG;IAEnD,IAAI,CAACG,aAAa;QAChBT,WAAW;QACX,OAAOQ;IACT;IAEAR,WAAW,+CAA+CS,YAAYV,IAAI;IAE1E,MAAMW,eAAeD,YAAYE,SAAS,CAACC,OAAO,IAAIH,YAAYE,SAAS,CAAC,WAAW;;IACvF,IAAI,OAAOD,iBAAiB,YAAY;QACtCV,WAAW;QACX,OAAOU;IACT;IAEAV,WAAW;IACX,MAAMa,cAAcC,OAAOC,IAAI,CAACN,YAAYE,SAAS,EAAEK,IAAI,CAAC,SAAS;IACrE,MAAMC,eAAelB,KAAKmB,QAAQ,CAACC,QAAQC,GAAG,IAAIX,YAAYV,IAAI;IAClE,MAAMsB,WACJZ,YAAYE,SAAS,CAACC,OAAO,KAAKU,YAC9B,KACA,CAAC,WAAW,EAAE,OAAOb,YAAYE,SAAS,CAACC,OAAO,CAAC,CAAC,CAAC;IAE3D,MAAMW,UAAU,GAAGN,aAAa,CAAC,EAAER,YAAYe,QAAQ,EAAE;IAEzDnB,OAAOoB,WAAW,CAAC;QACjBC,SAAS;YACP,GAAGT,aAAa,wDAAwD,EAAEI,UAAU;YACpF,CAAC,gCAAgC,EAAER,aAAa,CAACc,IAAI;YACrD,CAAC,+CAA+C,CAAC;SAClD;QACDC,MAAM;QACNL;IACF;IAEA,OAAOrB;AACT"}
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { buildDebug } from '../buildDebug.js';
4
+ import { addTimestampedImportMapScriptToHtml } from './addTimestampImportMapScriptToHtml.js';
5
+ import { getDocumentComponent } from './getDocumentComponent.js';
6
+ /**
7
+ * Adds a base path to a URL if necessary, and returns the resulting URL.
8
+ * @param url - The URL to prefix with a base path.
9
+ * @param basePath - The base path to prefix the URL with. Default value is `/`.
10
+ * @returns The resulting URL with the base path.
11
+ * @internal
12
+ */ function _prefixUrlWithBasePath(url, basePath) {
13
+ // Normalize basePath by adding a leading slash if it's missing.
14
+ const normalizedBasePath = basePath.startsWith('/') ? basePath : `/${basePath}`;
15
+ // If the URL starts with a slash, append it to the basePath, removing any trailing slash if present.
16
+ if (url.startsWith('/')) {
17
+ if (normalizedBasePath.endsWith('/')) {
18
+ return `${normalizedBasePath.slice(0, -1)}${url}`;
19
+ }
20
+ return `${normalizedBasePath}${url}`;
21
+ }
22
+ // If the URL doesn't start with a slash, append it to the basePath with a slash in between.
23
+ if (normalizedBasePath.endsWith('/')) {
24
+ return `${normalizedBasePath}${url}`;
25
+ }
26
+ return `${normalizedBasePath}/${url}`;
27
+ }
28
+ /**
29
+ * @internal
30
+ */ export async function getDocumentHtml(parent, studioRootPath, props, importMap, isApp, autoUpdatesCssUrls) {
31
+ const Document = await getDocumentComponent(parent, studioRootPath, isApp);
32
+ const defaultProps = {
33
+ entryPath: './.sanity/runtime/app.js'
34
+ };
35
+ // NOTE: Validate the list of CSS paths so implementers of `_document.tsx` don't have to
36
+ // - If the path is not a full URL, check if it starts with `/`
37
+ // - If not, then prepend a `/` to the string
38
+ const css = props?.css?.map((url)=>{
39
+ try {
40
+ // If the URL is absolute, we don't need to prefix it
41
+ return new URL(url).toString();
42
+ } catch {
43
+ return _prefixUrlWithBasePath(url, props.basePath);
44
+ }
45
+ });
46
+ buildDebug('Rendering document component using React');
47
+ const result = addTimestampedImportMapScriptToHtml(renderToStaticMarkup(/*#__PURE__*/ _jsx(Document, {
48
+ ...defaultProps,
49
+ ...props,
50
+ css: css
51
+ })), importMap, autoUpdatesCssUrls);
52
+ return `<!DOCTYPE html>${result}`;
53
+ }
54
+
55
+ //# sourceMappingURL=getDocumentHtml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/getDocumentHtml.tsx"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {renderToStaticMarkup} from 'react-dom/server'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {addTimestampedImportMapScriptToHtml} from './addTimestampImportMapScriptToHtml.js'\nimport {getDocumentComponent} from './getDocumentComponent.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * Adds a base path to a URL if necessary, and returns the resulting URL.\n * @param url - The URL to prefix with a base path.\n * @param basePath - The base path to prefix the URL with. Default value is `/`.\n * @returns The resulting URL with the base path.\n * @internal\n */\nfunction _prefixUrlWithBasePath(url: string, basePath: string): string {\n // Normalize basePath by adding a leading slash if it's missing.\n const normalizedBasePath = basePath.startsWith('/') ? basePath : `/${basePath}`\n\n // If the URL starts with a slash, append it to the basePath, removing any trailing slash if present.\n if (url.startsWith('/')) {\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath.slice(0, -1)}${url}`\n }\n return `${normalizedBasePath}${url}`\n }\n\n // If the URL doesn't start with a slash, append it to the basePath with a slash in between.\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath}${url}`\n }\n return `${normalizedBasePath}/${url}`\n}\n\n/**\n * @internal\n */\nexport async function getDocumentHtml(\n parent: MessagePort,\n studioRootPath: string,\n props?: DocumentProps,\n importMap?: {imports?: Record<string, string>},\n isApp?: boolean,\n autoUpdatesCssUrls?: string[],\n): Promise<string> {\n const Document = await getDocumentComponent(parent, studioRootPath, isApp)\n\n const defaultProps = {\n entryPath: './.sanity/runtime/app.js',\n }\n\n // NOTE: Validate the list of CSS paths so implementers of `_document.tsx` don't have to\n // - If the path is not a full URL, check if it starts with `/`\n // - If not, then prepend a `/` to the string\n const css = props?.css?.map((url) => {\n try {\n // If the URL is absolute, we don't need to prefix it\n return new URL(url).toString()\n } catch {\n return _prefixUrlWithBasePath(url, props.basePath)\n }\n })\n\n buildDebug('Rendering document component using React')\n const result = addTimestampedImportMapScriptToHtml(\n renderToStaticMarkup(<Document {...defaultProps} {...props} css={css} />),\n importMap,\n autoUpdatesCssUrls,\n )\n\n return `<!DOCTYPE html>${result}`\n}\n"],"names":["renderToStaticMarkup","buildDebug","addTimestampedImportMapScriptToHtml","getDocumentComponent","_prefixUrlWithBasePath","url","basePath","normalizedBasePath","startsWith","endsWith","slice","getDocumentHtml","parent","studioRootPath","props","importMap","isApp","autoUpdatesCssUrls","Document","defaultProps","entryPath","css","map","URL","toString","result"],"mappings":";AAEA,SAAQA,oBAAoB,QAAO,mBAAkB;AAErD,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,mCAAmC,QAAO,yCAAwC;AAC1F,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;CAMC,GACD,SAASC,uBAAuBC,GAAW,EAAEC,QAAgB;IAC3D,gEAAgE;IAChE,MAAMC,qBAAqBD,SAASE,UAAU,CAAC,OAAOF,WAAW,CAAC,CAAC,EAAEA,UAAU;IAE/E,qGAAqG;IACrG,IAAID,IAAIG,UAAU,CAAC,MAAM;QACvB,IAAID,mBAAmBE,QAAQ,CAAC,MAAM;YACpC,OAAO,GAAGF,mBAAmBG,KAAK,CAAC,GAAG,CAAC,KAAKL,KAAK;QACnD;QACA,OAAO,GAAGE,qBAAqBF,KAAK;IACtC;IAEA,4FAA4F;IAC5F,IAAIE,mBAAmBE,QAAQ,CAAC,MAAM;QACpC,OAAO,GAAGF,qBAAqBF,KAAK;IACtC;IACA,OAAO,GAAGE,mBAAmB,CAAC,EAAEF,KAAK;AACvC;AAEA;;CAEC,GACD,OAAO,eAAeM,gBACpBC,MAAmB,EACnBC,cAAsB,EACtBC,KAAqB,EACrBC,SAA8C,EAC9CC,KAAe,EACfC,kBAA6B;IAE7B,MAAMC,WAAW,MAAMf,qBAAqBS,QAAQC,gBAAgBG;IAEpE,MAAMG,eAAe;QACnBC,WAAW;IACb;IAEA,wFAAwF;IACxF,+DAA+D;IAC/D,+CAA+C;IAC/C,MAAMC,MAAMP,OAAOO,KAAKC,IAAI,CAACjB;QAC3B,IAAI;YACF,qDAAqD;YACrD,OAAO,IAAIkB,IAAIlB,KAAKmB,QAAQ;QAC9B,EAAE,OAAM;YACN,OAAOpB,uBAAuBC,KAAKS,MAAMR,QAAQ;QACnD;IACF;IAEAL,WAAW;IACX,MAAMwB,SAASvB,oCACbF,mCAAqB,KAACkB;QAAU,GAAGC,YAAY;QAAG,GAAGL,KAAK;QAAEO,KAAKA;SACjEN,WACAE;IAGF,OAAO,CAAC,eAAe,EAAEQ,QAAQ;AACnC"}
@@ -0,0 +1,31 @@
1
+ import { getDocumentHtml } from './getDocumentHtml.js';
2
+ /**
3
+ * Renders a document in a worker thread
4
+ *
5
+ * @param parent - The parent port to send messages to
6
+ * @param options - The options for the document to render
7
+ * @returns - The rendered document
8
+ */ export async function renderDocumentWorker(parent, options) {
9
+ const { autoUpdatesCssUrls, importMap, isApp, props, studioRootPath } = options;
10
+ if (typeof studioRootPath !== 'string') {
11
+ parent.postMessage({
12
+ message: 'Missing/invalid `studioRootPath` option',
13
+ type: 'error'
14
+ });
15
+ return;
16
+ }
17
+ if (props && typeof props !== 'object') {
18
+ parent.postMessage({
19
+ message: '`props` must be an object if provided',
20
+ type: 'error'
21
+ });
22
+ return;
23
+ }
24
+ const html = await getDocumentHtml(parent, studioRootPath, props, importMap, isApp, autoUpdatesCssUrls);
25
+ parent.postMessage({
26
+ html,
27
+ type: 'result'
28
+ });
29
+ }
30
+
31
+ //# sourceMappingURL=renderDocumentWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/renderDocumentWorker.ts"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {getDocumentHtml} from './getDocumentHtml.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * @internal\n */\nexport interface RenderDocumentWorkerOptions {\n studioRootPath: string\n\n autoUpdatesCssUrls?: string[]\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\n/**\n * Renders a document in a worker thread\n *\n * @param parent - The parent port to send messages to\n * @param options - The options for the document to render\n * @returns - The rendered document\n */\nexport async function renderDocumentWorker(\n parent: MessagePort,\n options: RenderDocumentWorkerOptions,\n) {\n const {autoUpdatesCssUrls, importMap, isApp, props, studioRootPath} = options\n\n if (typeof studioRootPath !== 'string') {\n parent.postMessage({\n message: 'Missing/invalid `studioRootPath` option',\n type: 'error',\n })\n return\n }\n\n if (props && typeof props !== 'object') {\n parent.postMessage({\n message: '`props` must be an object if provided',\n type: 'error',\n })\n return\n }\n\n const html = await getDocumentHtml(\n parent,\n studioRootPath,\n props,\n importMap,\n isApp,\n autoUpdatesCssUrls,\n )\n\n parent.postMessage({\n html,\n type: 'result',\n })\n}\n"],"names":["getDocumentHtml","renderDocumentWorker","parent","options","autoUpdatesCssUrls","importMap","isApp","props","studioRootPath","postMessage","message","type","html"],"mappings":"AAEA,SAAQA,eAAe,QAAO,uBAAsB;AAiBpD;;;;;;CAMC,GACD,OAAO,eAAeC,qBACpBC,MAAmB,EACnBC,OAAoC;IAEpC,MAAM,EAACC,kBAAkB,EAAEC,SAAS,EAAEC,KAAK,EAAEC,KAAK,EAAEC,cAAc,EAAC,GAAGL;IAEtE,IAAI,OAAOK,mBAAmB,UAAU;QACtCN,OAAOO,WAAW,CAAC;YACjBC,SAAS;YACTC,MAAM;QACR;QACA;IACF;IAEA,IAAIJ,SAAS,OAAOA,UAAU,UAAU;QACtCL,OAAOO,WAAW,CAAC;YACjBC,SAAS;YACTC,MAAM;QACR;QACA;IACF;IAEA,MAAMC,OAAO,MAAMZ,gBACjBE,QACAM,gBACAD,OACAF,WACAC,OACAF;IAGFF,OAAOO,WAAW,CAAC;QACjBG;QACAD,MAAM;IACR;AACF"}
@@ -0,0 +1,30 @@
1
+ import fs from 'node:fs';
2
+ import { doImport } from '@sanity/cli-core';
3
+ import { buildDebug } from '../buildDebug.js';
4
+ import { getPossibleDocumentComponentLocations } from '../getPossibleDocumentComponentLocations.js';
5
+ /**
6
+ * @internal
7
+ */ export async function tryLoadDocumentComponent(studioRootPath) {
8
+ const locations = getPossibleDocumentComponentLocations(studioRootPath);
9
+ for (const componentPath of locations){
10
+ buildDebug('Trying to load document component from %s', componentPath);
11
+ try {
12
+ const component = await doImport(componentPath);
13
+ return {
14
+ component,
15
+ modified: Math.floor(fs.statSync(componentPath)?.mtimeMs),
16
+ path: componentPath
17
+ };
18
+ } catch (err) {
19
+ // Allow "not found" errors
20
+ if (err.code !== 'ERR_MODULE_NOT_FOUND') {
21
+ buildDebug('Failed to load document component: %s', err.message);
22
+ throw err;
23
+ }
24
+ buildDebug('Document component not found at %s', componentPath);
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+
30
+ //# sourceMappingURL=tryLoadDocumentComponent.js.map