@sanity/cli-build 0.1.1 → 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.
- package/dist/_exports/_internal/build.d.ts +2418 -0
- package/dist/_exports/_internal/build.js +10 -0
- package/dist/_exports/_internal/build.js.map +1 -0
- package/dist/_exports/_internal/extract.d.ts +120 -0
- package/dist/_exports/_internal/extract.js +9 -0
- package/dist/_exports/_internal/extract.js.map +1 -0
- package/dist/actions/build/buildDebug.js +4 -0
- package/dist/actions/build/buildDebug.js.map +1 -0
- package/dist/actions/build/buildVendorDependencies.js +149 -0
- package/dist/actions/build/buildVendorDependencies.js.map +1 -0
- package/dist/actions/build/checkStudioDependencyVersions.js +155 -0
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -0
- package/dist/actions/build/createExternalFromImportMap.js +11 -0
- package/dist/actions/build/createExternalFromImportMap.js.map +1 -0
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js +13 -0
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js.map +1 -0
- package/dist/actions/build/decorateIndexWithBridgeScript.js +17 -0
- package/dist/actions/build/decorateIndexWithBridgeScript.js.map +1 -0
- package/dist/actions/build/decorateIndexWithStagingScript.js +16 -0
- package/dist/actions/build/decorateIndexWithStagingScript.js.map +1 -0
- package/dist/actions/build/getEntryModule.js +46 -0
- package/dist/actions/build/getEntryModule.js.map +1 -0
- package/dist/actions/build/getPossibleDocumentComponentLocations.js +11 -0
- package/dist/actions/build/getPossibleDocumentComponentLocations.js.map +1 -0
- package/dist/actions/build/getViteConfig.js +204 -0
- package/dist/actions/build/getViteConfig.js.map +1 -0
- package/dist/actions/build/normalizeBasePath.js +9 -0
- package/dist/actions/build/normalizeBasePath.js.map +1 -0
- package/dist/actions/build/renderDocument.js +50 -0
- package/dist/actions/build/renderDocument.js.map +1 -0
- package/dist/actions/build/renderDocument.worker.js +9 -0
- package/dist/actions/build/renderDocument.worker.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +79 -0
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +61 -0
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +165 -0
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js +28 -0
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +178 -0
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js +51 -0
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +41 -0
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +55 -0
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +31 -0
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +30 -0
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +1 -0
- package/dist/actions/build/renderDocumentWorker/types.js +5 -0
- package/dist/actions/build/renderDocumentWorker/types.js.map +1 -0
- package/dist/actions/build/vite/plugin-sanity-build-entries.js +67 -0
- package/dist/actions/build/vite/plugin-sanity-build-entries.js.map +1 -0
- package/dist/actions/build/vite/plugin-sanity-favicons.js +72 -0
- package/dist/actions/build/vite/plugin-sanity-favicons.js.map +1 -0
- package/dist/actions/build/vite/plugin-sanity-runtime-rewrite.js +18 -0
- package/dist/actions/build/vite/plugin-sanity-runtime-rewrite.js.map +1 -0
- package/dist/actions/build/writeSanityRuntime.js +66 -0
- package/dist/actions/build/writeSanityRuntime.js.map +1 -0
- package/dist/actions/schema/extractSanitySchema.worker.js +32 -0
- package/dist/actions/schema/extractSanitySchema.worker.js.map +1 -0
- package/dist/actions/schema/formatSchemaValidation.js +78 -0
- package/dist/actions/schema/formatSchemaValidation.js.map +1 -0
- package/dist/actions/schema/getExtractOptions.js +23 -0
- package/dist/actions/schema/getExtractOptions.js.map +1 -0
- package/dist/actions/schema/matchSchemaPattern.js +21 -0
- package/dist/actions/schema/matchSchemaPattern.js.map +1 -0
- package/dist/actions/schema/runSchemaExtraction.js +39 -0
- package/dist/actions/schema/runSchemaExtraction.js.map +1 -0
- package/dist/actions/schema/types.js +9 -0
- package/dist/actions/schema/types.js.map +1 -0
- package/dist/actions/schema/utils/SchemaExtractionError.js +10 -0
- package/dist/actions/schema/utils/SchemaExtractionError.js.map +1 -0
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js +12 -0
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +1 -0
- package/dist/actions/schema/vite/plugin-schema-extraction.js +201 -0
- package/dist/actions/schema/vite/plugin-schema-extraction.js.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/telemetry/build.telemetry.js +13 -0
- package/dist/telemetry/build.telemetry.js.map +1 -0
- package/dist/telemetry/extractSchema.telemetry.js +18 -0
- package/dist/telemetry/extractSchema.telemetry.js.map +1 -0
- package/package.json +37 -8
- package/dist/_exports/_internal.d.ts +0 -45
- package/dist/_exports/_internal.js +0 -5
- package/dist/_exports/_internal.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const entryModule = `
|
|
2
|
+
// This file is auto-generated on 'sanity dev'
|
|
3
|
+
// Modifications to this file is automatically discarded
|
|
4
|
+
import {renderStudio} from "sanity"
|
|
5
|
+
import studioConfig from %STUDIO_CONFIG_LOCATION%
|
|
6
|
+
|
|
7
|
+
renderStudio(
|
|
8
|
+
document.getElementById("sanity"),
|
|
9
|
+
studioConfig,
|
|
10
|
+
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
|
|
11
|
+
)
|
|
12
|
+
`;
|
|
13
|
+
const noConfigEntryModule = `
|
|
14
|
+
// This file is auto-generated on 'sanity dev'
|
|
15
|
+
// Modifications to this file is automatically discarded
|
|
16
|
+
import {renderStudio} from "sanity"
|
|
17
|
+
|
|
18
|
+
const studioConfig = {missingConfigFile: true}
|
|
19
|
+
|
|
20
|
+
renderStudio(
|
|
21
|
+
document.getElementById("sanity"),
|
|
22
|
+
studioConfig,
|
|
23
|
+
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
|
|
24
|
+
)
|
|
25
|
+
`;
|
|
26
|
+
const appEntryModule = `
|
|
27
|
+
// This file is auto-generated on 'sanity dev'
|
|
28
|
+
// Modifications to this file is automatically discarded
|
|
29
|
+
import {createRoot} from 'react-dom/client'
|
|
30
|
+
import {createElement} from 'react'
|
|
31
|
+
import App from %ENTRY%
|
|
32
|
+
|
|
33
|
+
const root = createRoot(document.getElementById('root'))
|
|
34
|
+
const element = createElement(App)
|
|
35
|
+
root.render(element)
|
|
36
|
+
`;
|
|
37
|
+
export function getEntryModule(options) {
|
|
38
|
+
const { basePath, entry, isApp, reactStrictMode, relativeConfigLocation } = options;
|
|
39
|
+
if (isApp) {
|
|
40
|
+
return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'));
|
|
41
|
+
}
|
|
42
|
+
const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule;
|
|
43
|
+
return sourceModule.replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(Boolean(reactStrictMode))).replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation)).replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=getEntryModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/getEntryModule.ts"],"sourcesContent":["const entryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\nimport studioConfig from %STUDIO_CONFIG_LOCATION%\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst noConfigEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\n\nconst studioConfig = {missingConfigFile: true}\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst appEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {createRoot} from 'react-dom/client'\nimport {createElement} from 'react'\nimport App from %ENTRY%\n\nconst root = createRoot(document.getElementById('root'))\nconst element = createElement(App)\nroot.render(element)\n`\n\nexport function getEntryModule(options: {\n basePath?: string\n entry?: string\n isApp?: boolean\n reactStrictMode: boolean\n relativeConfigLocation: string | null\n}): string {\n const {basePath, entry, isApp, reactStrictMode, relativeConfigLocation} = options\n\n if (isApp) {\n return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'))\n }\n\n const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule\n\n return sourceModule\n .replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(Boolean(reactStrictMode)))\n .replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation))\n .replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'))\n}\n"],"names":["entryModule","noConfigEntryModule","appEntryModule","getEntryModule","options","basePath","entry","isApp","reactStrictMode","relativeConfigLocation","replace","JSON","stringify","sourceModule","Boolean"],"mappings":"AAAA,MAAMA,cAAc,CAAC;;;;;;;;;;;AAWrB,CAAC;AAED,MAAMC,sBAAsB,CAAC;;;;;;;;;;;;AAY7B,CAAC;AAED,MAAMC,iBAAiB,CAAC;;;;;;;;;;AAUxB,CAAC;AAED,OAAO,SAASC,eAAeC,OAM9B;IACC,MAAM,EAACC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,eAAe,EAAEC,sBAAsB,EAAC,GAAGL;IAE1E,IAAIG,OAAO;QACT,OAAOL,eAAeQ,OAAO,CAAC,WAAWC,KAAKC,SAAS,CAACN,SAAS;IACnE;IAEA,MAAMO,eAAeJ,yBAAyBT,cAAcC;IAE5D,OAAOY,aACJH,OAAO,CAAC,8BAA8BC,KAAKC,SAAS,CAACE,QAAQN,mBAC7DE,OAAO,CAAC,4BAA4BC,KAAKC,SAAS,CAACH,yBACnDC,OAAO,CAAC,sBAAsBC,KAAKC,SAAS,CAACP,YAAY;AAC9D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/ export function getPossibleDocumentComponentLocations(rootPath) {
|
|
5
|
+
return [
|
|
6
|
+
path.join(rootPath, '_document.js'),
|
|
7
|
+
path.join(rootPath, '_document.tsx')
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=getPossibleDocumentComponentLocations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/getPossibleDocumentComponentLocations.ts"],"sourcesContent":["import path from 'node:path'\n\n/**\n * @internal\n */\nexport function getPossibleDocumentComponentLocations(rootPath: string): string[] {\n return [path.join(rootPath, '_document.js'), path.join(rootPath, '_document.tsx')]\n}\n"],"names":["path","getPossibleDocumentComponentLocations","rootPath","join"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B;;CAEC,GACD,OAAO,SAASC,sCAAsCC,QAAgB;IACpE,OAAO;QAACF,KAAKG,IAAI,CAACD,UAAU;QAAiBF,KAAKG,IAAI,CAACD,UAAU;KAAiB;AACpF"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { findProjectRoot, getCliTelemetry } from '@sanity/cli-core';
|
|
3
|
+
import viteReact from '@vitejs/plugin-react';
|
|
4
|
+
import debug from 'debug';
|
|
5
|
+
import { mergeConfig } from 'vite';
|
|
6
|
+
import { SANITY_CACHE_DIR } from '../../constants.js';
|
|
7
|
+
import { sanitySchemaExtractionPlugin } from '../schema/vite/plugin-schema-extraction.js';
|
|
8
|
+
import { createExternalFromImportMap } from './createExternalFromImportMap.js';
|
|
9
|
+
import { normalizeBasePath } from './normalizeBasePath.js';
|
|
10
|
+
import { sanityBuildEntries } from './vite/plugin-sanity-build-entries.js';
|
|
11
|
+
import { sanityFaviconsPlugin } from './vite/plugin-sanity-favicons.js';
|
|
12
|
+
import { sanityRuntimeRewritePlugin } from './vite/plugin-sanity-runtime-rewrite.js';
|
|
13
|
+
import { getDefaultFaviconsPath } from './writeFavicons.js';
|
|
14
|
+
/**
|
|
15
|
+
* Get a configuration object for Vite based on the passed options
|
|
16
|
+
*
|
|
17
|
+
* @internal Only meant for consumption inside of Sanity modules, do not depend on this externally
|
|
18
|
+
*/ export async function getViteConfig(options) {
|
|
19
|
+
const { additionalPlugins, autoUpdatesCssUrls, basePath: rawBasePath = '/', cwd, importMap, isApp, minify, mode, outputDir, reactCompiler, schemaExtraction, server, // default to `true` when `mode=development`
|
|
20
|
+
sourceMap = options.mode === 'development' } = options;
|
|
21
|
+
const basePath = normalizeBasePath(rawBasePath);
|
|
22
|
+
const configPath = (await findProjectRoot(cwd)).path;
|
|
23
|
+
const customFaviconsPath = path.join(cwd, 'static');
|
|
24
|
+
const defaultFaviconsPath = await getDefaultFaviconsPath();
|
|
25
|
+
const staticPath = `${basePath}static`;
|
|
26
|
+
const envVars = options.getEnvironmentVariables();
|
|
27
|
+
const viteConfig = {
|
|
28
|
+
base: basePath,
|
|
29
|
+
build: {
|
|
30
|
+
outDir: outputDir || path.resolve(cwd, 'dist'),
|
|
31
|
+
sourcemap: sourceMap
|
|
32
|
+
},
|
|
33
|
+
// Define a custom cache directory so that sanity's vite cache
|
|
34
|
+
// does not conflict with any potential local vite projects
|
|
35
|
+
cacheDir: `${SANITY_CACHE_DIR}/vite`,
|
|
36
|
+
configFile: false,
|
|
37
|
+
define: {
|
|
38
|
+
__SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),
|
|
39
|
+
__SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',
|
|
40
|
+
'process.env.MODE': JSON.stringify(mode),
|
|
41
|
+
'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),
|
|
42
|
+
/**
|
|
43
|
+
* Yes, double negatives are confusing.
|
|
44
|
+
* The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34
|
|
45
|
+
* Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)
|
|
46
|
+
* while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76
|
|
47
|
+
* There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.
|
|
48
|
+
* However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,
|
|
49
|
+
* and there is no longer any reason to use the much slower method in dev mode.
|
|
50
|
+
*/ 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),
|
|
51
|
+
...envVars
|
|
52
|
+
},
|
|
53
|
+
envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',
|
|
54
|
+
logLevel: mode === 'production' ? 'silent' : 'info',
|
|
55
|
+
mode,
|
|
56
|
+
plugins: [
|
|
57
|
+
viteReact(reactCompiler ? {
|
|
58
|
+
babel: {
|
|
59
|
+
generatorOpts: {
|
|
60
|
+
compact: true
|
|
61
|
+
},
|
|
62
|
+
plugins: [
|
|
63
|
+
[
|
|
64
|
+
'babel-plugin-react-compiler',
|
|
65
|
+
reactCompiler
|
|
66
|
+
]
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
} : {}),
|
|
70
|
+
sanityFaviconsPlugin({
|
|
71
|
+
customFaviconsPath,
|
|
72
|
+
defaultFaviconsPath,
|
|
73
|
+
staticUrlPath: staticPath
|
|
74
|
+
}),
|
|
75
|
+
sanityRuntimeRewritePlugin(),
|
|
76
|
+
sanityBuildEntries({
|
|
77
|
+
autoUpdatesCssUrls,
|
|
78
|
+
basePath,
|
|
79
|
+
cwd,
|
|
80
|
+
importMap,
|
|
81
|
+
isApp
|
|
82
|
+
}),
|
|
83
|
+
// Add schema extraction when enabled
|
|
84
|
+
...schemaExtraction?.enabled ? [
|
|
85
|
+
sanitySchemaExtractionPlugin({
|
|
86
|
+
additionalPatterns: schemaExtraction.watchPatterns,
|
|
87
|
+
configPath,
|
|
88
|
+
enforceRequiredFields: schemaExtraction.enforceRequiredFields,
|
|
89
|
+
outputPath: schemaExtraction.path,
|
|
90
|
+
telemetryLogger: getCliTelemetry(),
|
|
91
|
+
workDir: cwd,
|
|
92
|
+
workspaceName: schemaExtraction.workspace
|
|
93
|
+
})
|
|
94
|
+
] : [],
|
|
95
|
+
...additionalPlugins || []
|
|
96
|
+
],
|
|
97
|
+
resolve: {
|
|
98
|
+
dedupe: [
|
|
99
|
+
'react',
|
|
100
|
+
'react-dom',
|
|
101
|
+
'sanity',
|
|
102
|
+
'styled-components'
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
root: cwd,
|
|
106
|
+
server: {
|
|
107
|
+
host: server?.host,
|
|
108
|
+
port: server?.port || 3333,
|
|
109
|
+
// Only enable strict port for studio,
|
|
110
|
+
// since apps can run on any port
|
|
111
|
+
strictPort: isApp ? false : true,
|
|
112
|
+
/**
|
|
113
|
+
* Significantly speed up startup time,
|
|
114
|
+
* and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`
|
|
115
|
+
* types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.
|
|
116
|
+
* This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,
|
|
117
|
+
* and thus avoids frustrating reload loops.
|
|
118
|
+
*/ warmup: {
|
|
119
|
+
clientFiles: [
|
|
120
|
+
'./.sanity/runtime/app.js'
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
if (mode === 'production') {
|
|
126
|
+
viteConfig.build = {
|
|
127
|
+
...viteConfig.build,
|
|
128
|
+
assetsDir: 'static',
|
|
129
|
+
emptyOutDir: false,
|
|
130
|
+
minify: minify ? 'esbuild' : false,
|
|
131
|
+
rollupOptions: {
|
|
132
|
+
external: createExternalFromImportMap(importMap),
|
|
133
|
+
input: {
|
|
134
|
+
sanity: path.join(cwd, '.sanity', 'runtime', 'app.js')
|
|
135
|
+
},
|
|
136
|
+
onwarn: onRollupWarn
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return viteConfig;
|
|
141
|
+
}
|
|
142
|
+
function onRollupWarn(warning, warn) {
|
|
143
|
+
if (suppressUnusedImport(warning)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
warn(warning);
|
|
147
|
+
}
|
|
148
|
+
function suppressUnusedImport(warning) {
|
|
149
|
+
if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false;
|
|
150
|
+
// Suppress:
|
|
151
|
+
// ```
|
|
152
|
+
// "useDebugValue" is imported from external module "react"…
|
|
153
|
+
// ```
|
|
154
|
+
if (warning.names?.includes('useDebugValue')) {
|
|
155
|
+
warning.names = warning.names.filter((n)=>n !== 'useDebugValue');
|
|
156
|
+
if (warning.names.length === 0) return true;
|
|
157
|
+
}
|
|
158
|
+
// If some library does something unexpected, we suppress since it isn't actionable
|
|
159
|
+
if (warning.ids?.every((id)=>id.includes('/node_modules/') || id.includes('\\node_modules\\'))) return true;
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Ensure Sanity entry chunk is always loaded
|
|
164
|
+
*
|
|
165
|
+
* @param config - User-modified configuration
|
|
166
|
+
* @returns Merged configuration
|
|
167
|
+
* @internal
|
|
168
|
+
*/ export async function finalizeViteConfig(config) {
|
|
169
|
+
if (typeof config.build?.rollupOptions?.input !== 'object') {
|
|
170
|
+
throw new TypeError('Vite config must contain `build.rollupOptions.input`, and it must be an object');
|
|
171
|
+
}
|
|
172
|
+
if (!config.root) {
|
|
173
|
+
throw new Error('Vite config must contain `root` property, and must point to the Sanity root directory');
|
|
174
|
+
}
|
|
175
|
+
return mergeConfig(config, {
|
|
176
|
+
build: {
|
|
177
|
+
rollupOptions: {
|
|
178
|
+
input: {
|
|
179
|
+
sanity: path.join(config.root, '.sanity', 'runtime', 'app.js')
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Merge user-provided Vite configuration object or function
|
|
187
|
+
*
|
|
188
|
+
* @param defaultConfig - Default configuration object
|
|
189
|
+
* @param userConfig - User-provided configuration object or function
|
|
190
|
+
* @returns Merged configuration
|
|
191
|
+
* @internal
|
|
192
|
+
*/ export async function extendViteConfigWithUserConfig(env, defaultConfig, userConfig) {
|
|
193
|
+
let config = defaultConfig;
|
|
194
|
+
if (typeof userConfig === 'function') {
|
|
195
|
+
debug('Extending vite config using user-specified function');
|
|
196
|
+
config = await userConfig(config, env);
|
|
197
|
+
} else if (typeof userConfig === 'object') {
|
|
198
|
+
debug('Merging vite config using user-specified object');
|
|
199
|
+
config = mergeConfig(config, userConfig);
|
|
200
|
+
}
|
|
201
|
+
return config;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//# sourceMappingURL=getViteConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/getViteConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {\n type CliConfig,\n findProjectRoot,\n getCliTelemetry,\n type UserViteConfig,\n} from '@sanity/cli-core'\nimport viteReact from '@vitejs/plugin-react'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport debug from 'debug'\nimport {type ConfigEnv, type InlineConfig, mergeConfig, type Plugin, type Rollup} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanitySchemaExtractionPlugin} from '../schema/vite/plugin-schema-extraction.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\nimport {normalizeBasePath} from './normalizeBasePath.js'\nimport {sanityBuildEntries} from './vite/plugin-sanity-build-entries.js'\nimport {sanityFaviconsPlugin} from './vite/plugin-sanity-favicons.js'\nimport {sanityRuntimeRewritePlugin} from './vite/plugin-sanity-runtime-rewrite.js'\nimport {getDefaultFaviconsPath} from './writeFavicons.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\n\n /**\n * Returns the environment variables to be injected into the config.\n */\n getEnvironmentVariables(): Record<string, string>\n\n /**\n * Mode to run vite in - eg development or production\n */\n mode: 'development' | 'production'\n\n reactCompiler: ReactCompilerConfig | undefined\n\n /**\n * Additional plugins when configured, eg. typegen\n */\n additionalPlugins?: Plugin[]\n\n /**\n * CSS URLs for auto-updated packages (loaded via module server)\n */\n autoUpdatesCssUrls?: string[]\n\n /**\n * Base path (eg under where to serve the app - `/studio` or similar)\n * Will be normalized to ensure it starts and ends with a `/`\n */\n basePath?: string\n\n importMap?: {imports?: Record<string, string>}\n\n isApp?: boolean\n\n /**\n * Whether or not to minify the output (only used in `mode: 'production'`)\n */\n minify?: boolean\n\n /**\n * Output directory (eg where to place the built files, if any)\n */\n outputDir?: string\n /**\n * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\n}\n\n/**\n * Get a configuration object for Vite based on the passed options\n *\n * @internal Only meant for consumption inside of Sanity modules, do not depend on this externally\n */\nexport async function getViteConfig(options: ViteOptions): Promise<InlineConfig> {\n const {\n additionalPlugins,\n autoUpdatesCssUrls,\n basePath: rawBasePath = '/',\n cwd,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n server,\n // default to `true` when `mode=development`\n sourceMap = options.mode === 'development',\n } = options\n\n const basePath = normalizeBasePath(rawBasePath)\n\n const configPath = (await findProjectRoot(cwd)).path\n\n const customFaviconsPath = path.join(cwd, 'static')\n const defaultFaviconsPath = await getDefaultFaviconsPath()\n const staticPath = `${basePath}static`\n\n const envVars = options.getEnvironmentVariables()\n\n const viteConfig: InlineConfig = {\n base: basePath,\n build: {\n outDir: outputDir || path.resolve(cwd, 'dist'),\n sourcemap: sourceMap,\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n configFile: false,\n define: {\n __SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),\n __SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',\n 'process.env.MODE': JSON.stringify(mode),\n 'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),\n /**\n * Yes, double negatives are confusing.\n * The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34\n * Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)\n * while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76\n * There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.\n * However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,\n * and there is no longer any reason to use the much slower method in dev mode.\n */\n 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),\n ...envVars,\n },\n envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n logLevel: mode === 'production' ? 'silent' : 'info',\n mode,\n plugins: [\n viteReact(\n reactCompiler\n ? {\n babel: {\n generatorOpts: {compact: true},\n plugins: [['babel-plugin-react-compiler', reactCompiler]],\n },\n }\n : {},\n ),\n sanityFaviconsPlugin({customFaviconsPath, defaultFaviconsPath, staticUrlPath: staticPath}),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdatesCssUrls, basePath, cwd, importMap, isApp}),\n // Add schema extraction when enabled\n ...(schemaExtraction?.enabled\n ? [\n sanitySchemaExtractionPlugin({\n additionalPatterns: schemaExtraction.watchPatterns,\n configPath,\n enforceRequiredFields: schemaExtraction.enforceRequiredFields,\n outputPath: schemaExtraction.path,\n telemetryLogger: getCliTelemetry(),\n workDir: cwd,\n workspaceName: schemaExtraction.workspace,\n }),\n ]\n : []),\n ...(additionalPlugins || []),\n ],\n resolve: {\n dedupe: ['react', 'react-dom', 'sanity', 'styled-components'],\n },\n root: cwd,\n server: {\n host: server?.host,\n port: server?.port || 3333,\n // Only enable strict port for studio,\n // since apps can run on any port\n strictPort: isApp ? false : true,\n\n /**\n * Significantly speed up startup time,\n * and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`\n * types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.\n * This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,\n * and thus avoids frustrating reload loops.\n */\n warmup: {\n clientFiles: ['./.sanity/runtime/app.js'],\n },\n },\n }\n\n if (mode === 'production') {\n viteConfig.build = {\n ...viteConfig.build,\n\n assetsDir: 'static',\n emptyOutDir: false, // Rely on CLI to do this\n minify: minify ? 'esbuild' : false,\n\n rollupOptions: {\n external: createExternalFromImportMap(importMap),\n input: {\n sanity: path.join(cwd, '.sanity', 'runtime', 'app.js'),\n },\n onwarn: onRollupWarn,\n },\n }\n }\n\n return viteConfig\n}\n\nfunction onRollupWarn(warning: Rollup.RollupLog, warn: Rollup.LoggingFunction) {\n if (suppressUnusedImport(warning)) {\n return\n }\n\n warn(warning)\n}\n\nfunction suppressUnusedImport(warning: Rollup.RollupLog & {ids?: string[]}): boolean {\n if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false\n\n // Suppress:\n // ```\n // \"useDebugValue\" is imported from external module \"react\"…\n // ```\n if (warning.names?.includes('useDebugValue')) {\n warning.names = warning.names.filter((n) => n !== 'useDebugValue')\n if (warning.names.length === 0) return true\n }\n\n // If some library does something unexpected, we suppress since it isn't actionable\n if (warning.ids?.every((id) => id.includes('/node_modules/') || id.includes('\\\\node_modules\\\\')))\n return true\n\n return false\n}\n\n/**\n * Ensure Sanity entry chunk is always loaded\n *\n * @param config - User-modified configuration\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(config: InlineConfig): Promise<InlineConfig> {\n if (typeof config.build?.rollupOptions?.input !== 'object') {\n throw new TypeError(\n 'Vite config must contain `build.rollupOptions.input`, and it must be an object',\n )\n }\n\n if (!config.root) {\n throw new Error(\n 'Vite config must contain `root` property, and must point to the Sanity root directory',\n )\n }\n\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n input: {\n sanity: path.join(config.root, '.sanity', 'runtime', 'app.js'),\n },\n },\n },\n })\n}\n\n/**\n * Merge user-provided Vite configuration object or function\n *\n * @param defaultConfig - Default configuration object\n * @param userConfig - User-provided configuration object or function\n * @returns Merged configuration\n * @internal\n */\nexport async function extendViteConfigWithUserConfig(\n env: ConfigEnv,\n defaultConfig: InlineConfig,\n userConfig: UserViteConfig,\n): Promise<InlineConfig> {\n let config = defaultConfig\n\n if (typeof userConfig === 'function') {\n debug('Extending vite config using user-specified function')\n config = await userConfig(config, env)\n } else if (typeof userConfig === 'object') {\n debug('Merging vite config using user-specified object')\n config = mergeConfig(config, userConfig)\n }\n\n return config\n}\n"],"names":["path","findProjectRoot","getCliTelemetry","viteReact","debug","mergeConfig","SANITY_CACHE_DIR","sanitySchemaExtractionPlugin","createExternalFromImportMap","normalizeBasePath","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","getDefaultFaviconsPath","getViteConfig","options","additionalPlugins","autoUpdatesCssUrls","basePath","rawBasePath","cwd","importMap","isApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","getEnvironmentVariables","viteConfig","base","build","outDir","resolve","sourcemap","cacheDir","configFile","define","__SANITY_BUILD_TIMESTAMP__","JSON","stringify","Date","now","__SANITY_STAGING__","process","env","SANITY_INTERNAL_ENV","PKG_BUILD_VERSION","envPrefix","logLevel","plugins","babel","generatorOpts","compact","staticUrlPath","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","dedupe","root","host","port","strictPort","warmup","clientFiles","assetsDir","emptyOutDir","rollupOptions","external","input","sanity","onwarn","onRollupWarn","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","config","TypeError","Error","extendViteConfigWithUserConfig","defaultConfig","userConfig"],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that the given path both starts and ends with a single slash
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/ export function normalizeBasePath(pathName) {
|
|
6
|
+
return `/${pathName}/`.replace(/^\/+/, '/').replace(/\/+$/, '/');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=normalizeBasePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/normalizeBasePath.ts"],"sourcesContent":["/**\n * Ensures that the given path both starts and ends with a single slash\n *\n * @internal\n */\nexport function normalizeBasePath(pathName: string): string {\n return `/${pathName}/`.replace(/^\\/+/, '/').replace(/\\/+$/, '/')\n}\n"],"names":["normalizeBasePath","pathName","replace"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,kBAAkBC,QAAgB;IAChD,OAAO,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC,CAACC,OAAO,CAAC,QAAQ,KAAKA,OAAO,CAAC,QAAQ;AAC9D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { tsxWorkerTask } from '@sanity/cli-core';
|
|
3
|
+
import { buildDebug } from './buildDebug.js';
|
|
4
|
+
const hasWarnedAbout = new Set();
|
|
5
|
+
export async function renderDocument(options) {
|
|
6
|
+
buildDebug('Starting worker thread for %s', import.meta.url);
|
|
7
|
+
try {
|
|
8
|
+
const msg = await tsxWorkerTask(new URL(`renderDocument.worker.js`, import.meta.url), {
|
|
9
|
+
name: 'renderDocument',
|
|
10
|
+
rootPath: options.studioRootPath,
|
|
11
|
+
workerData: {
|
|
12
|
+
...options,
|
|
13
|
+
shouldWarn: true
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (msg.type === 'warning') {
|
|
17
|
+
if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(msg.message)) {
|
|
21
|
+
for (const warning of msg.message){
|
|
22
|
+
ux.warn(warning);
|
|
23
|
+
}
|
|
24
|
+
} else if (msg.message) {
|
|
25
|
+
ux.warn(msg.message);
|
|
26
|
+
}
|
|
27
|
+
if (msg.warnKey) {
|
|
28
|
+
hasWarnedAbout.add(msg.warnKey);
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
if (msg.type === 'error') {
|
|
33
|
+
buildDebug('Error from worker: %s', msg.message || 'Unknown error');
|
|
34
|
+
throw new Error(Array.isArray(msg.message) ? msg.message.join('\n') : msg.message || 'Document rendering worker stopped with an unknown error');
|
|
35
|
+
}
|
|
36
|
+
if (msg.type === 'result') {
|
|
37
|
+
if (!msg.html) {
|
|
38
|
+
throw new Error('Document rendering worker stopped with an unknown error');
|
|
39
|
+
}
|
|
40
|
+
buildDebug('Document HTML rendered, %d bytes', msg.html.length);
|
|
41
|
+
return msg.html;
|
|
42
|
+
}
|
|
43
|
+
throw new Error('Unknown message type');
|
|
44
|
+
} catch (err) {
|
|
45
|
+
buildDebug('Worker errored: %s', err.message);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=renderDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/renderDocument.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {tsxWorkerTask} from '@sanity/cli-core'\n\nimport {buildDebug} from './buildDebug.js'\n\ninterface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n title?: string\n}\n\ninterface RenderDocumentOptions {\n studioRootPath: string\n\n autoUpdatesCssUrls?: string[]\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\nconst hasWarnedAbout = new Set<string>()\n\ninterface RenderDocumentWorkerResult {\n type: 'error' | 'result' | 'warning'\n\n html?: string\n message?: string | string[]\n warnKey?: string\n}\n\nexport async function renderDocument(options: RenderDocumentOptions): Promise<string> {\n buildDebug('Starting worker thread for %s', import.meta.url)\n try {\n const msg = await tsxWorkerTask<RenderDocumentWorkerResult>(\n new URL(`renderDocument.worker.js`, import.meta.url),\n {\n name: 'renderDocument',\n rootPath: options.studioRootPath,\n workerData: {...options, shouldWarn: true},\n },\n )\n\n if (msg.type === 'warning') {\n if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {\n return ''\n }\n\n if (Array.isArray(msg.message)) {\n for (const warning of msg.message) {\n ux.warn(warning)\n }\n } else if (msg.message) {\n ux.warn(msg.message)\n }\n\n if (msg.warnKey) {\n hasWarnedAbout.add(msg.warnKey)\n }\n return ''\n }\n\n if (msg.type === 'error') {\n buildDebug('Error from worker: %s', msg.message || 'Unknown error')\n throw new Error(\n Array.isArray(msg.message)\n ? msg.message.join('\\n')\n : msg.message || 'Document rendering worker stopped with an unknown error',\n )\n }\n\n if (msg.type === 'result') {\n if (!msg.html) {\n throw new Error('Document rendering worker stopped with an unknown error')\n }\n\n buildDebug('Document HTML rendered, %d bytes', msg.html.length)\n return msg.html\n }\n\n throw new Error('Unknown message type')\n } catch (err) {\n buildDebug('Worker errored: %s', err.message)\n throw err\n }\n}\n"],"names":["ux","tsxWorkerTask","buildDebug","hasWarnedAbout","Set","renderDocument","options","url","msg","URL","name","rootPath","studioRootPath","workerData","shouldWarn","type","warnKey","has","Array","isArray","message","warning","warn","add","Error","join","html","length","err"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAAQC,aAAa,QAAO,mBAAkB;AAE9C,SAAQC,UAAU,QAAO,kBAAiB;AAqB1C,MAAMC,iBAAiB,IAAIC;AAU3B,OAAO,eAAeC,eAAeC,OAA8B;IACjEJ,WAAW,iCAAiC,YAAYK,GAAG;IAC3D,IAAI;QACF,MAAMC,MAAM,MAAMP,cAChB,IAAIQ,IAAI,CAAC,wBAAwB,CAAC,EAAE,YAAYF,GAAG,GACnD;YACEG,MAAM;YACNC,UAAUL,QAAQM,cAAc;YAChCC,YAAY;gBAAC,GAAGP,OAAO;gBAAEQ,YAAY;YAAI;QAC3C;QAGF,IAAIN,IAAIO,IAAI,KAAK,WAAW;YAC1B,IAAIP,IAAIQ,OAAO,IAAIb,eAAec,GAAG,CAACT,IAAIQ,OAAO,GAAG;gBAClD,OAAO;YACT;YAEA,IAAIE,MAAMC,OAAO,CAACX,IAAIY,OAAO,GAAG;gBAC9B,KAAK,MAAMC,WAAWb,IAAIY,OAAO,CAAE;oBACjCpB,GAAGsB,IAAI,CAACD;gBACV;YACF,OAAO,IAAIb,IAAIY,OAAO,EAAE;gBACtBpB,GAAGsB,IAAI,CAACd,IAAIY,OAAO;YACrB;YAEA,IAAIZ,IAAIQ,OAAO,EAAE;gBACfb,eAAeoB,GAAG,CAACf,IAAIQ,OAAO;YAChC;YACA,OAAO;QACT;QAEA,IAAIR,IAAIO,IAAI,KAAK,SAAS;YACxBb,WAAW,yBAAyBM,IAAIY,OAAO,IAAI;YACnD,MAAM,IAAII,MACRN,MAAMC,OAAO,CAACX,IAAIY,OAAO,IACrBZ,IAAIY,OAAO,CAACK,IAAI,CAAC,QACjBjB,IAAIY,OAAO,IAAI;QAEvB;QAEA,IAAIZ,IAAIO,IAAI,KAAK,UAAU;YACzB,IAAI,CAACP,IAAIkB,IAAI,EAAE;gBACb,MAAM,IAAIF,MAAM;YAClB;YAEAtB,WAAW,oCAAoCM,IAAIkB,IAAI,CAACC,MAAM;YAC9D,OAAOnB,IAAIkB,IAAI;QACjB;QAEA,MAAM,IAAIF,MAAM;IAClB,EAAE,OAAOI,KAAK;QACZ1B,WAAW,sBAAsB0B,IAAIR,OAAO;QAC5C,MAAMQ;IACR;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { renderDocumentWorker } from './renderDocumentWorker/renderDocumentWorker.js';
|
|
3
|
+
// If we're not in a worker thread, throw an error
|
|
4
|
+
if (!parentPort || !workerData) {
|
|
5
|
+
throw new Error('Must be used as a Worker with a valid options object in worker data');
|
|
6
|
+
}
|
|
7
|
+
renderDocumentWorker(parentPort, workerData);
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=renderDocument.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/renderDocument.worker.ts"],"sourcesContent":["import {parentPort, workerData} from 'node:worker_threads'\n\nimport {renderDocumentWorker} from './renderDocumentWorker/renderDocumentWorker.js'\n\n// If we're not in a worker thread, throw an error\nif (!parentPort || !workerData) {\n throw new Error('Must be used as a Worker with a valid options object in worker data')\n}\n\nrenderDocumentWorker(parentPort, workerData)\n"],"names":["parentPort","workerData","renderDocumentWorker","Error"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAE1D,SAAQC,oBAAoB,QAAO,iDAAgD;AAEnF,kDAAkD;AAClD,IAAI,CAACF,cAAc,CAACC,YAAY;IAC9B,MAAM,IAAIE,MAAM;AAClB;AAEAD,qBAAqBF,YAAYC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { parse as parseHtml } from 'node-html-parser';
|
|
2
|
+
/**
|
|
3
|
+
* This script takes the import map from the `#__imports` script tag,
|
|
4
|
+
* modifies relevant URLs that match the sanity-cdn hostname by replacing
|
|
5
|
+
* the existing timestamp in the sanity-cdn URLs with a new runtime timestamp,
|
|
6
|
+
* and injects the modified import map back into the HTML.
|
|
7
|
+
*
|
|
8
|
+
* It also synchronously creates `<link rel="stylesheet">` tags for each CDN
|
|
9
|
+
* CSS URL with a fresh timestamp.
|
|
10
|
+
*
|
|
11
|
+
* This will be injected into the HTML of the user's bundle.
|
|
12
|
+
*
|
|
13
|
+
* Note that this is in a separate constants file to prevent "Cannot access
|
|
14
|
+
* before initialization" errors.
|
|
15
|
+
*/ const TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT = `<script>
|
|
16
|
+
// auto-generated script to add import map with timestamp
|
|
17
|
+
const importsJson = document.getElementById('__imports')?.textContent;
|
|
18
|
+
const { imports = {}, css = [], ...rest } = importsJson ? JSON.parse(importsJson) : {};
|
|
19
|
+
const importMapEl = document.createElement('script');
|
|
20
|
+
importMapEl.type = 'importmap';
|
|
21
|
+
const newTimestamp = \`/t\${Math.floor(Date.now() / 1000)}\`;
|
|
22
|
+
|
|
23
|
+
function replaceTimestamp(urlStr) {
|
|
24
|
+
try {
|
|
25
|
+
const url = new URL(urlStr);
|
|
26
|
+
if (/^sanity-cdn\\.[a-zA-Z]+$/.test(url.hostname)) {
|
|
27
|
+
url.pathname = url.pathname.replace(/\\/t\\d+/, newTimestamp);
|
|
28
|
+
}
|
|
29
|
+
return url.toString();
|
|
30
|
+
} catch {
|
|
31
|
+
return urlStr;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
importMapEl.textContent = JSON.stringify({
|
|
36
|
+
imports: Object.fromEntries(
|
|
37
|
+
Object.entries(imports).map(([specifier, path]) => [specifier, replaceTimestamp(path)])
|
|
38
|
+
),
|
|
39
|
+
...rest,
|
|
40
|
+
});
|
|
41
|
+
document.head.appendChild(importMapEl);
|
|
42
|
+
|
|
43
|
+
// Creates <link rel="stylesheet"> tags with fresh timestamps.
|
|
44
|
+
for (const cssUrl of css) {
|
|
45
|
+
const linkEl = document.createElement('link');
|
|
46
|
+
linkEl.rel = 'stylesheet';
|
|
47
|
+
linkEl.href = replaceTimestamp(cssUrl);
|
|
48
|
+
document.head.appendChild(linkEl);
|
|
49
|
+
}
|
|
50
|
+
</script>`;
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/ export function addTimestampedImportMapScriptToHtml(html, importMap, autoUpdatesCssUrls) {
|
|
54
|
+
if (!importMap) return html;
|
|
55
|
+
let root = parseHtml(html);
|
|
56
|
+
let htmlEl = root.querySelector('html');
|
|
57
|
+
if (!htmlEl) {
|
|
58
|
+
const oldRoot = root;
|
|
59
|
+
root = parseHtml('<html></html>');
|
|
60
|
+
htmlEl = root.querySelector('html');
|
|
61
|
+
htmlEl.append(oldRoot);
|
|
62
|
+
}
|
|
63
|
+
let headEl = htmlEl.querySelector('head');
|
|
64
|
+
if (!headEl) {
|
|
65
|
+
htmlEl.insertAdjacentHTML('afterbegin', '<head></head>');
|
|
66
|
+
headEl = root.querySelector('head');
|
|
67
|
+
}
|
|
68
|
+
// Include CSS URLs in the __imports JSON so the runtime script can create
|
|
69
|
+
// <link> tags with fresh timestamps synchronously during head parsing.
|
|
70
|
+
const importMapWithCss = autoUpdatesCssUrls && autoUpdatesCssUrls.length > 0 ? {
|
|
71
|
+
...importMap,
|
|
72
|
+
css: autoUpdatesCssUrls
|
|
73
|
+
} : importMap;
|
|
74
|
+
headEl.insertAdjacentHTML('beforeend', `<script type="application/json" id="__imports">${JSON.stringify(importMapWithCss)}</script>`);
|
|
75
|
+
headEl.insertAdjacentHTML('beforeend', TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT);
|
|
76
|
+
return root.outerHTML;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=addTimestampImportMapScriptToHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.ts"],"sourcesContent":["import {parse as parseHtml} from 'node-html-parser'\n\n/**\n * This script takes the import map from the `#__imports` script tag,\n * modifies relevant URLs that match the sanity-cdn hostname by replacing\n * the existing timestamp in the sanity-cdn URLs with a new runtime timestamp,\n * and injects the modified import map back into the HTML.\n *\n * It also synchronously creates `<link rel=\"stylesheet\">` tags for each CDN\n * CSS URL with a fresh timestamp.\n *\n * This will be injected into the HTML of the user's bundle.\n *\n * Note that this is in a separate constants file to prevent \"Cannot access\n * before initialization\" errors.\n */\nconst TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT = `<script>\n // auto-generated script to add import map with timestamp\n const importsJson = document.getElementById('__imports')?.textContent;\n const { imports = {}, css = [], ...rest } = importsJson ? JSON.parse(importsJson) : {};\n const importMapEl = document.createElement('script');\n importMapEl.type = 'importmap';\n const newTimestamp = \\`/t\\${Math.floor(Date.now() / 1000)}\\`;\n\n function replaceTimestamp(urlStr) {\n try {\n const url = new URL(urlStr);\n if (/^sanity-cdn\\\\.[a-zA-Z]+$/.test(url.hostname)) {\n url.pathname = url.pathname.replace(/\\\\/t\\\\d+/, newTimestamp);\n }\n return url.toString();\n } catch {\n return urlStr;\n }\n }\n\n importMapEl.textContent = JSON.stringify({\n imports: Object.fromEntries(\n Object.entries(imports).map(([specifier, path]) => [specifier, replaceTimestamp(path)])\n ),\n ...rest,\n });\n document.head.appendChild(importMapEl);\n\n // Creates <link rel=\"stylesheet\"> tags with fresh timestamps.\n for (const cssUrl of css) {\n const linkEl = document.createElement('link');\n linkEl.rel = 'stylesheet';\n linkEl.href = replaceTimestamp(cssUrl);\n document.head.appendChild(linkEl);\n }\n</script>`\n\n/**\n * @internal\n */\nexport function addTimestampedImportMapScriptToHtml(\n html: string,\n importMap?: {imports?: Record<string, string>},\n autoUpdatesCssUrls?: string[],\n): string {\n if (!importMap) return html\n\n let root = parseHtml(html)\n let htmlEl = root.querySelector('html')\n if (!htmlEl) {\n const oldRoot = root\n root = parseHtml('<html></html>')\n htmlEl = root.querySelector('html')!\n htmlEl.append(oldRoot)\n }\n\n let headEl = htmlEl.querySelector('head')\n\n if (!headEl) {\n htmlEl.insertAdjacentHTML('afterbegin', '<head></head>')\n headEl = root.querySelector('head')!\n }\n\n // Include CSS URLs in the __imports JSON so the runtime script can create\n // <link> tags with fresh timestamps synchronously during head parsing.\n const importMapWithCss =\n autoUpdatesCssUrls && autoUpdatesCssUrls.length > 0\n ? {...importMap, css: autoUpdatesCssUrls}\n : importMap\n\n headEl.insertAdjacentHTML(\n 'beforeend',\n `<script type=\"application/json\" id=\"__imports\">${JSON.stringify(importMapWithCss)}</script>`,\n )\n\n headEl.insertAdjacentHTML('beforeend', TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT)\n return root.outerHTML\n}\n"],"names":["parse","parseHtml","TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT","addTimestampedImportMapScriptToHtml","html","importMap","autoUpdatesCssUrls","root","htmlEl","querySelector","oldRoot","append","headEl","insertAdjacentHTML","importMapWithCss","length","css","JSON","stringify","outerHTML"],"mappings":"AAAA,SAAQA,SAASC,SAAS,QAAO,mBAAkB;AAEnD;;;;;;;;;;;;;CAaC,GACD,MAAMC,wCAAwC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAmCtC,CAAC;AAEV;;CAEC,GACD,OAAO,SAASC,oCACdC,IAAY,EACZC,SAA8C,EAC9CC,kBAA6B;IAE7B,IAAI,CAACD,WAAW,OAAOD;IAEvB,IAAIG,OAAON,UAAUG;IACrB,IAAII,SAASD,KAAKE,aAAa,CAAC;IAChC,IAAI,CAACD,QAAQ;QACX,MAAME,UAAUH;QAChBA,OAAON,UAAU;QACjBO,SAASD,KAAKE,aAAa,CAAC;QAC5BD,OAAOG,MAAM,CAACD;IAChB;IAEA,IAAIE,SAASJ,OAAOC,aAAa,CAAC;IAElC,IAAI,CAACG,QAAQ;QACXJ,OAAOK,kBAAkB,CAAC,cAAc;QACxCD,SAASL,KAAKE,aAAa,CAAC;IAC9B;IAEA,0EAA0E;IAC1E,uEAAuE;IACvE,MAAMK,mBACJR,sBAAsBA,mBAAmBS,MAAM,GAAG,IAC9C;QAAC,GAAGV,SAAS;QAAEW,KAAKV;IAAkB,IACtCD;IAENO,OAAOC,kBAAkB,CACvB,aACA,CAAC,+CAA+C,EAAEI,KAAKC,SAAS,CAACJ,kBAAkB,SAAS,CAAC;IAG/FF,OAAOC,kBAAkB,CAAC,aAAaX;IACvC,OAAOK,KAAKY,SAAS;AACvB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App HTML Document, this is in the _internal package
|
|
3
|
+
* to avoid importing styled-components from sanity package
|
|
4
|
+
*/ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Favicons } from './Favicons.js';
|
|
6
|
+
import { GlobalErrorHandler } from './GlobalErrorHandler.js';
|
|
7
|
+
import { NoJavascript } from './NoJavascript.js';
|
|
8
|
+
const EMPTY_ARRAY = [];
|
|
9
|
+
/**
|
|
10
|
+
* This is the equivalent of DefaultDocument for non-studio apps.
|
|
11
|
+
* @internal
|
|
12
|
+
*/ export function BasicDocument(props) {
|
|
13
|
+
const { css = EMPTY_ARRAY, entryPath, title } = props;
|
|
14
|
+
return /*#__PURE__*/ _jsxs("html", {
|
|
15
|
+
lang: "en",
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ _jsxs("head", {
|
|
18
|
+
children: [
|
|
19
|
+
/*#__PURE__*/ _jsx("meta", {
|
|
20
|
+
charSet: "utf-8"
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ _jsx("meta", {
|
|
23
|
+
content: "width=device-width, initial-scale=1, viewport-fit=cover",
|
|
24
|
+
name: "viewport"
|
|
25
|
+
}),
|
|
26
|
+
/*#__PURE__*/ _jsx("meta", {
|
|
27
|
+
content: "noindex",
|
|
28
|
+
name: "robots"
|
|
29
|
+
}),
|
|
30
|
+
/*#__PURE__*/ _jsx("meta", {
|
|
31
|
+
content: "same-origin",
|
|
32
|
+
name: "referrer"
|
|
33
|
+
}),
|
|
34
|
+
/*#__PURE__*/ _jsx(Favicons, {}),
|
|
35
|
+
/*#__PURE__*/ _jsx("title", {
|
|
36
|
+
children: title || 'Sanity App'
|
|
37
|
+
}),
|
|
38
|
+
/*#__PURE__*/ _jsx(GlobalErrorHandler, {}),
|
|
39
|
+
css.map((href)=>/*#__PURE__*/ _jsx("link", {
|
|
40
|
+
href: href,
|
|
41
|
+
rel: "stylesheet"
|
|
42
|
+
}, href))
|
|
43
|
+
]
|
|
44
|
+
}),
|
|
45
|
+
/*#__PURE__*/ _jsxs("body", {
|
|
46
|
+
children: [
|
|
47
|
+
/*#__PURE__*/ _jsx("div", {
|
|
48
|
+
id: "root"
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ _jsx("script", {
|
|
51
|
+
src: entryPath,
|
|
52
|
+
type: "module"
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ _jsx(NoJavascript, {})
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=BasicDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/BasicDocument.tsx"],"sourcesContent":["/**\n * App HTML Document, this is in the _internal package\n * to avoid importing styled-components from sanity package\n */\n\nimport {type JSX} from 'react'\n\nimport {Favicons} from './Favicons.js'\nimport {GlobalErrorHandler} from './GlobalErrorHandler.js'\nimport {NoJavascript} from './NoJavascript.js'\n\n/**\n * @internal\n */\ninterface BasicDocumentProps {\n entryPath: string\n\n // Currently unused, but kept for potential future use\n basePath?: string\n\n css?: string[]\n title?: string\n}\n\nconst EMPTY_ARRAY: never[] = []\n\n/**\n * This is the equivalent of DefaultDocument for non-studio apps.\n * @internal\n */\nexport function BasicDocument(props: BasicDocumentProps): JSX.Element {\n const {css = EMPTY_ARRAY, entryPath, title} = props\n\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta content=\"width=device-width, initial-scale=1, viewport-fit=cover\" name=\"viewport\" />\n <meta content=\"noindex\" name=\"robots\" />\n <meta content=\"same-origin\" name=\"referrer\" />\n\n <Favicons />\n <title>{title || 'Sanity App'}</title>\n <GlobalErrorHandler />\n\n {css.map((href) => (\n <link href={href} key={href} rel=\"stylesheet\" />\n ))}\n </head>\n <body>\n <div id=\"root\" />\n <script src={entryPath} type=\"module\" />\n <NoJavascript />\n </body>\n </html>\n )\n}\n"],"names":["Favicons","GlobalErrorHandler","NoJavascript","EMPTY_ARRAY","BasicDocument","props","css","entryPath","title","html","lang","head","meta","charSet","content","name","map","href","link","rel","body","div","id","script","src","type"],"mappings":"AAAA;;;CAGC;AAID,SAAQA,QAAQ,QAAO,gBAAe;AACtC,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,YAAY,QAAO,oBAAmB;AAe9C,MAAMC,cAAuB,EAAE;AAE/B;;;CAGC,GACD,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EAACC,MAAMH,WAAW,EAAEI,SAAS,EAAEC,KAAK,EAAC,GAAGH;IAE9C,qBACE,MAACI;QAAKC,MAAK;;0BACT,MAACC;;kCACC,KAACC;wBAAKC,SAAQ;;kCACd,KAACD;wBAAKE,SAAQ;wBAA0DC,MAAK;;kCAC7E,KAACH;wBAAKE,SAAQ;wBAAUC,MAAK;;kCAC7B,KAACH;wBAAKE,SAAQ;wBAAcC,MAAK;;kCAEjC,KAACf;kCACD,KAACQ;kCAAOA,SAAS;;kCACjB,KAACP;oBAEAK,IAAIU,GAAG,CAAC,CAACC,qBACR,KAACC;4BAAKD,MAAMA;4BAAiBE,KAAI;2BAAVF;;;0BAG3B,MAACG;;kCACC,KAACC;wBAAIC,IAAG;;kCACR,KAACC;wBAAOC,KAAKjB;wBAAWkB,MAAK;;kCAC7B,KAACvB;;;;;AAIT"}
|