Skip to content

Commit

Permalink
chore: move dev-aliases into @repo/dev-aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 25, 2024
1 parent 8b509f7 commit 2180d0f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
32 changes: 0 additions & 32 deletions dev/aliases.cjs

This file was deleted.

33 changes: 33 additions & 0 deletions packages/@repo/dev-aliases/dev-aliases.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable tsdoc/syntax */

// NOTE: THIS FILE NEEDS TO REMAIN COMMONJS
// It can be converted to ESM/TS when we either not use jest anymore, or node/jest runner natively supports ESM (including with import.meta etc).

/**
* The path mappings/aliases used by various tools in the monorepo to map imported modules to
* source files in order to speed up rebuilding and avoid having a separate watcher process to build
* from `src` to `lib`.
*
* This file is currently read by:
* - Vite when running the dev server (only when running in this monorepo)
* - jest when running test suite
*
* @type Record<string, string>
*/
const devAliases = {
// NOTE: do not use regex in the module expressions,
// because they will be escaped by the jest config
'@sanity/block-tools': '@sanity/block-tools/src',
'@sanity/diff': '@sanity/diff/src',
'@sanity/cli': '@sanity/cli/src',
'@sanity/mutator': '@sanity/mutator/src',
'@sanity/schema': '@sanity/schema/src/_exports',
'@sanity/migrate': '@sanity/migrate/src/_exports',
'@sanity/types': '@sanity/types/src',
'@sanity/util': '@sanity/util/src/_exports',
'@sanity/vision': '@sanity/vision/src',
'sanity': 'sanity/src/_exports',
'groq': 'groq/src/_exports.mts',
}

module.exports = devAliases
11 changes: 11 additions & 0 deletions packages/@repo/dev-aliases/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@repo/dev-aliases",
"version": "3.57.4",
"private": true,
"description": "Dev aliases for the sanity monorepo",
"type": "module",
"exports": {
".": "./dev-aliases.cjs"
},
"main": "./dev-aliases.cjs"
}
18 changes: 18 additions & 0 deletions packages/@repo/dev-aliases/vite.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import devAliases from './dev-aliases.cjs'

import {dirname, resolve} from 'node:path'

const PACKAGES_PATH = resolve(getDirname(import.meta.url), '..', '..')

function getDirname(importMetaUrl) {
return dirname(importMetaUrl.replace('file://', ''))
}

export function getViteAliases() {
return Object.fromEntries(
Object.entries(devAliases).map(([packageName, aliasPath]) => [
packageName,
resolve(PACKAGES_PATH, aliasPath),
]),
)
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// Until what's in dev/, scripts. and test/ is in workspaces it's necessary to type check them from the root
"extends": "@repo/tsconfig/base.json",
"include": ["./dev/aliases.cjs", "./scripts", "./test"],
"include": ["./scripts", "./test"],
"files": [],
"compilerOptions": {
"rootDir": "."
Expand Down

0 comments on commit 2180d0f

Please sign in to comment.