Skip to content

Commit

Permalink
fix: upgrade to @sanity/pkg-utils v5 and use updated ESM best pract…
Browse files Browse the repository at this point in the history
…ices (#5983)

* fix: upgrade to `@sanity/pkg-utils` v5 and use updated ESM best practices

* refactor: remove redundant `--tsconfig tsconfig.lib.json` cli arg

* chore: use import that works in native ESM

* chore: bump `@sanity/pkg-utils`

* fix: lodash imports need to use `from 'lodash'` for rollup to be able to optimize it

* chore(deps): bump nano-pubsub

* chore: write to PKG_VERSION to give pre-releases their own version numbers

* chore: run build as part of publish to use the correct PKG_VERSION

* chore: bump tsdoc

* chore: add prepublishOnly at root to speedup canary publishing

* chore: fix path to `@sanity/vision`

* chore: support types in `/examples` without first running `pnpm build`

---------

Co-authored-by: Bjørge Næss <[email protected]>
  • Loading branch information
stipsan and bjoerge authored Apr 9, 2024
1 parent fce97c7 commit 62a6810
Show file tree
Hide file tree
Showing 199 changed files with 1,337 additions and 1,839 deletions.
8 changes: 7 additions & 1 deletion .depcheckrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"ignores": ["@sanity/eslint-config-studio", "dotenv-flow", "esbuild", "esbuild-register"]
"ignores": [
"@repo/tsconfig",
"@sanity/eslint-config-studio",
"dotenv-flow",
"esbuild",
"esbuild-register"
]
}
18 changes: 11 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const config = {
'*.css',
'*.snap',
'*.md',
'dev/test-studio/sanity.theme.mjs',
'dev/test-studio/workshop/scopes.js',
],
rules: {
'@typescript-eslint/no-var-requires': 'off', // prefer import/no-dynamic-require
Expand All @@ -57,6 +59,7 @@ const config = {
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
'import/default': 'off',
'prettier/prettier': 'error',
'tsdoc/syntax': 'error',
'react-hooks/rules-of-hooks': 'error',
Expand Down Expand Up @@ -191,16 +194,17 @@ const config = {
project: [
'dev/*/tsconfig.json',
'examples/*/tsconfig.json',
'packages/@repo/*/tsconfig.json',
'packages/@sanity/*/tsconfig.json',
'packages/*/tsconfig.json',
],
},
},
'boundaries/include': ['packages/sanity/exports/*.*', 'packages/sanity/src/**/*.*'],
'boundaries/include': ['packages/sanity/src/**/*.*'],
'boundaries/elements': [
{
type: 'sanity',
pattern: ['packages/sanity/exports/index.ts'],
pattern: ['packages/sanity/src/_exports/index.ts'],
mode: 'full',
},
{
Expand All @@ -210,7 +214,7 @@ const config = {
},
{
type: 'sanity/_internal',
pattern: ['packages/sanity/exports/_internal.ts'],
pattern: ['packages/sanity/src/_exports/_internal.ts'],
mode: 'full',
},
{
Expand All @@ -220,7 +224,7 @@ const config = {
},
{
type: 'sanity/cli',
pattern: ['packages/sanity/exports/cli.ts'],
pattern: ['packages/sanity/src/_exports/cli.ts'],
mode: 'full',
},
{
Expand All @@ -230,7 +234,7 @@ const config = {
},
{
type: 'sanity/desk',
pattern: ['packages/sanity/exports/desk.ts'],
pattern: ['packages/sanity/src/_exports/desk.ts'],
mode: 'file',
},
{
Expand All @@ -240,7 +244,7 @@ const config = {
},
{
type: 'sanity/router',
pattern: ['packages/sanity/exports/router.ts'],
pattern: ['packages/sanity/src/_exports/router.ts'],
mode: 'full',
},
{
Expand All @@ -250,7 +254,7 @@ const config = {
},
{
type: 'sanity/structure',
pattern: ['packages/sanity/exports/structure.ts'],
pattern: ['packages/sanity/src/_exports/structure.ts'],
mode: 'file',
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cli-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: pnpm install

- name: Build CLI
run: pnpm build # Needed for CLI tests
run: pnpm build --output-logs=full --log-order=grouped # Needed for CLI tests

- name: Test
id: test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: pnpm install

- name: Build packages
run: pnpm build
run: pnpm build --output-logs=full --log-order=grouped
env:
NODE_OPTIONS: --max_old_space_size=8192

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ct.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Build packages
run: pnpm build
run: pnpm build --output-logs=full --log-order=grouped
- name: Run end-to-end tests
run: pnpm --filter sanity test:ct
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
run: npx playwright install --with-deps

- name: Build CLI
run: pnpm build:cli
run: pnpm build:cli --output-logs=full --log-order=grouped

- name: Build E2E test studio on next
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/etl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: pnpm install

- name: Build packages
run: pnpm build
run: pnpm build --output-logs=full --log-order=grouped
env:
NODE_OPTIONS: --max_old_space_size=8192

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
${{ inputs.version }}
- name: Build
run: pnpm build
run: pnpm build --output-logs=full --log-order=grouped

- name: Publish
run: |
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/typeCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ jobs:
typeCheck:
timeout-minutes: 15
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down Expand Up @@ -41,9 +44,17 @@ jobs:
run: pnpm install

- name: Check type system
# If TypeScript project references is set up properly, `tsc --build` should work right after dependencies
# has been installed, no extra build/compile step required
# Turbo will run type checks on all files in the project
# and ensure that dependencies are built with @sanity/pkg-utils to output dts
# used by other packages as they are type checked
id: typeCheckModules
run: pnpm check:types
run: pnpm check:types --output-logs=full --log-order=grouped
env:
NODE_OPTIONS: --max_old_space_size=8192

- name: Check package.json with @sanity/pkg-utils
# Turbo will ensure `build` is run before each package, as pkg-utils requires
# as it will check if files declared in package.json `main`, `exports`, `types` and more exists
run: pnpm check:package --output-logs=full --log-order=grouped
env:
NODE_OPTIONS: --max_old_space_size=8192
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/packages/*/lib
/packages/*/node_modules

/packages/@repo/*/node_modules
/packages/@sanity/*/coverage
/packages/@sanity/*/lib
/packages/@sanity/*/node_modules
Expand All @@ -31,6 +32,7 @@
/test/v2-studio/dist
/turbo.json
/packages/*/turbo.json
/packages/@repo/*/turbo.json
/packages/@sanity/*/turbo.json
/pnpm-lock.yaml

Expand Down
1 change: 1 addition & 0 deletions dev/.bin/sanity
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path')

require('esbuild-register/dist/node').register({
target: `node${process.version.slice(1)}`,
jsx: 'automatic',
})

// Define the global `__DEV__` flag which is used to
Expand Down
6 changes: 2 additions & 4 deletions dev/aliases.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ const devAliases = {
'@sanity/schema': './packages/@sanity/schema/src/_exports',
'@sanity/migrate': './packages/@sanity/migrate/src/_exports',
'@sanity/types': './packages/@sanity/types/src',
'@sanity/types/parts': './packages/@sanity/types/parts',
'@sanity/util/fs': './packages/@sanity/util/src/fsTools.ts',
'@sanity/util': './packages/@sanity/util/src',
'@sanity/util': './packages/@sanity/util/src/_exports',
'@sanity/vision': './packages/@sanity/vision/src',
sanity: './packages/sanity/exports',
sanity: './packages/sanity/src/_exports',
}

module.exports = devAliases
7 changes: 1 addition & 6 deletions dev/design-studio/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "../tsconfig.dev",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"jsx": "preserve"
},
"references": [{"path": "../../packages/sanity/tsconfig.lib.json"}]
"extends": "../tsconfig.dev"
}
2 changes: 1 addition & 1 deletion dev/embedded-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.23",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.4.2",
"typescript": "5.4.2",
"vite": "^4.5.3"
}
}
6 changes: 2 additions & 4 deletions dev/embedded-studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"module": "Preserve",
"moduleDetection": "force",
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
Expand Down
4 changes: 2 additions & 2 deletions dev/embedded-studio/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"module": "Preserve",
"moduleDetection": "force",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
Expand Down
6 changes: 2 additions & 4 deletions dev/starter-next-studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"module": "Preserve",
"moduleDetection": "force",
"isolatedModules": true,
"jsx": "preserve"
},
Expand Down
4 changes: 1 addition & 3 deletions dev/starter-studio/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "../tsconfig.dev",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"jsx": "preserve"
},
"references": [{"path": "../../packages/sanity/tsconfig.lib.json"}]
}
}
8 changes: 1 addition & 7 deletions dev/strict-studio/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{
"extends": "../tsconfig.dev",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"composite": true,
"jsx": "preserve"
},
"references": [{"path": "../../packages/sanity/tsconfig.lib.json"}]
"extends": "../tsconfig.dev"
}
6 changes: 2 additions & 4 deletions dev/studio-e2e-testing/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"module": "Preserve",
"moduleDetection": "force",
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true
Expand Down
6 changes: 2 additions & 4 deletions dev/test-next-studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"module": "Preserve",
"moduleDetection": "force",
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
Expand Down
3 changes: 0 additions & 3 deletions dev/test-studio/.eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion dev/test-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@sanity/presentation": "1.11.4",
"@sanity/preview-url-secret": "^1.6.1",
"@sanity/react-loader": "^1.8.3",
"@sanity/tsdoc": "1.0.0-alpha.44",
"@sanity/tsdoc": "1.0.13",
"@sanity/types": "workspace:*",
"@sanity/ui": "^2.1.0",
"@sanity/ui-workshop": "^1.0.0",
Expand Down
1 change: 0 additions & 1 deletion dev/test-studio/plugins/router-debug/RouterDebug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function RouterDebug() {
<IntentLink
intent="router-debug-please"
params={{
//@ts-expect-error - todo: we should probably allow arbitrary params
favorite: 'capybara',
}}
>
Expand Down
11 changes: 1 addition & 10 deletions dev/test-studio/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"extends": "../tsconfig.dev",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"isolatedModules": false
},
"references": [
{"path": "../../packages/@sanity/types/tsconfig.lib.json"},
{"path": "../../packages/@sanity/vision/tsconfig.lib.json"},
{"path": "../../packages/sanity/tsconfig.lib.json"},
{"path": "../../packages/@sanity/migrate/tsconfig.lib.json"}
]
}
}
29 changes: 18 additions & 11 deletions dev/tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"extends": "../tsconfig.settings",
"include": ["../packages/@sanity/util/src"],
"extends": "@repo/tsconfig/base.json",
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"rootDir": "..",
"baseUrl": "..",
"outDir": "./.cache/ts",

"paths": {
// Alias to paths required for Sanity CLI to run in dev-mode
"@sanity/mutator": ["./packages/@sanity/mutator/src"],
"@sanity/util/fs": ["./packages/@sanity/util/exports/fs.ts"],
"sanity/_internal": ["./packages/sanity/exports/_internal.ts"],
"sanity/migrate": ["./packages/sanity/exports/migrate.ts"],
"sanity/migrate/mutations": ["./packages/sanity/exports/migrate-mutations.ts"],
"sanity/cli": ["./packages/sanity/exports/cli.ts"]
"@sanity/block-tools": ["./packages/@sanity/block-tools/src/index.ts"],
"@sanity/diff": ["./packages/@sanity/diff/src/index.ts"],
"@sanity/cli": ["./packages/@sanity/cli/src/index.ts"],
"@sanity/codegen": ["./packages/@sanity/codegen/src/_exports/index.ts"],
"@sanity/mutator": ["./packages/@sanity/mutator/src/index.ts"],
"@sanity/portable-text-editor": ["./packages/@sanity/portable-text-editor/src/index.ts"],
"@sanity/schema/*": ["./packages/@sanity/schema/src/_exports/*"],
"@sanity/schema": ["./packages/@sanity/schema/src/_exports/index.ts"],
"@sanity/migrate": ["./packages/@sanity/migrate/src/_exports/index.ts"],
"@sanity/types": ["./packages/@sanity/types/src/index.ts"],
"@sanity/util/*": ["./packages/@sanity/util/src/_exports/*"],
"@sanity/util": ["./packages/@sanity/util/src/_exports/index.ts"],
"@sanity/vision": ["./packages/@sanity/vision/src/index.ts"],
"groq": ["./packages/groq/src/groq.ts"],
"sanity/*": ["./packages/sanity/src/_exports/*"],
"sanity": ["./packages/sanity/src/_exports/index.ts"]
}
}
}
Loading

0 comments on commit 62a6810

Please sign in to comment.