Skip to content

Commit

Permalink
feat(cli): build user peer-deps (#6742)
Browse files Browse the repository at this point in the history
* feat(cli): build user peer-deps

* chore: remove shared-modules build

* test(cli):  verify build config and `exports` subpaths

* text(cli): add depcheck config for fixture projects

* docs: update comments and test name

* feat: create import map w/ installed sanity version (#6784)

* feat: create import map w/ installed sanity version

* fix: use correct URL
  • Loading branch information
ricokahler committed May 28, 2024
1 parent ce20189 commit 527fffb
Show file tree
Hide file tree
Showing 21 changed files with 742 additions and 144 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"bootstrap": "pnpm install && pnpm build:cli",
"build": "turbo run build --filter='./packages/*' --filter='./packages/@sanity/*'",
"build:bundle": "turbo run build:bundle --filter='./packages/*' --filter='./packages/@sanity/*' --filter='./packages/@repo/shared-modules.bundle'",
"build:bundle": "turbo run build:bundle --filter='./packages/*' --filter='./packages/@sanity/*'",
"build:clean": "lerna run clean",
"build:cli": "turbo run build --filter=@sanity/cli --filter=sanity",
"build:cli-only": "turbo run --filter=@sanity/cli build",
Expand Down
3 changes: 0 additions & 3 deletions packages/@repo/shared-modules.bundle/.depcheckrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/@repo/shared-modules.bundle/.eslintrc.cjs

This file was deleted.

2 changes: 0 additions & 2 deletions packages/@repo/shared-modules.bundle/.gitignore

This file was deleted.

23 changes: 0 additions & 23 deletions packages/@repo/shared-modules.bundle/package.bundle.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/@repo/shared-modules.bundle/package.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignores": ["react", "react-dom", "styled-components"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "prj-with-react-18",
"private": true,
"dependencies": {
"react": "^18.3.0",
"react-dom": "^18.3.0",
"styled-components": "^6.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignores": ["react", "react-dom", "styled-components"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "prj-with-react-19",
"private": true,
"dependencies": {
"react": "19.0.0-rc-f994737d14-20240522",
"react-dom": "19.0.0-rc-f994737d14-20240522",
"styled-components": "^6.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignores": ["react", "react-dom", "styled-components"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "prj-with-styled-components-5",
"private": true,
"dependencies": {
"react": "^18.3.0",
"react-dom": "^18.3.0",
"styled-components": "^5.3.0"
}
}
44 changes: 25 additions & 19 deletions packages/sanity/src/_internal/cli/actions/build/buildAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,10 @@ import {checkStudioDependencyVersions} from '../../util/checkStudioDependencyVer
import {checkRequiredDependencies} from '../../util/checkRequiredDependencies'
import {getTimer} from '../../util/timing'
import {BuildTrace} from './build.telemetry'
import {buildVendorDependencies} from '../../server/buildVendorDependencies'

const rimraf = promisify(rimrafCallback)

// TODO: replace this with a manifest somewhere
const AUTO_UPDATES_IMPORTMAP = {
imports: {
// Shared modules
'react': 'https://api.sanity.work/v1/modules/react/^18',
'react/': 'https://api.sanity.work/v1/modules/react/^18/',
'react-dom': 'https://api.sanity.work/v1/modules/react-dom/^18',
'react-dom/': 'https://api.sanity.work/v1/modules/react-dom/^18/',
'styled-components': 'https://api.sanity.work/v1/modules/styled-components/^6',

// Sanity Modules
'sanity': 'https://api.sanity.work/v1/modules/sanity/^3',
'sanity/': 'https://api.sanity.work/v1/modules/sanity/^3/',
'@sanity/vision': 'https://api.sanity.work/v1/modules/@sanity__vision/^3 ',
},
}

export interface BuildSanityStudioCommandFlags {
'yes'?: boolean
'y'?: boolean
Expand Down Expand Up @@ -65,7 +49,8 @@ export default async function buildSanityStudio(

// If the check resulted in a dependency install, the CLI command will be re-run,
// thus we want to exit early
if ((await checkRequiredDependencies(context)).didInstall) {
const {didInstall, installedSanityVersion} = await checkRequiredDependencies(context)
if (didInstall) {
return {didCompile: false}
}

Expand Down Expand Up @@ -132,6 +117,26 @@ export default async function buildSanityStudio(

const trace = telemetry.trace(BuildTrace)
trace.start()

let importMap

if (enableAutoUpdates) {
const version = encodeURIComponent(`^${installedSanityVersion}`)
const autoUpdatesImports = {
'sanity': `https://api.sanity.work/v1/modules/sanity/default/${version}`,
'sanity/': `https://api.sanity.work/v1/modules/sanity/default/${version}/`,
'@sanity/vision': `https://api.sanity.work/v1/modules/@sanity__vision/default/${version}`,
'@sanity/vision/': `https://api.sanity.work/v1/modules/@sanity__vision/default/${version}/`,
}

importMap = {
imports: {
...(await buildVendorDependencies({cwd: workDir, outputDir})),
...autoUpdatesImports,
},
}
}

try {
timer.start('bundleStudio')

Expand All @@ -142,8 +147,9 @@ export default async function buildSanityStudio(
sourceMap: Boolean(flags['source-maps']),
minify: Boolean(flags.minify),
vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,
importMap: enableAutoUpdates ? AUTO_UPDATES_IMPORTMAP : undefined,
importMap,
})

trace.log({
outputSize: bundle.chunks
.flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))
Expand Down

0 comments on commit 527fffb

Please sign in to comment.