mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
Improved DX when editing packages
This commit is contained in:
parent
debcc8c343
commit
1fb20ca2c9
@ -66,10 +66,10 @@ function withCommerceConfig(nextConfig = {}) {
|
|||||||
// -> /node_modules/[name]/dist/index.js
|
// -> /node_modules/[name]/dist/index.js
|
||||||
const absolutePath = require.resolve(provider)
|
const absolutePath = require.resolve(provider)
|
||||||
// but we want references to go to the real path in /packages instead
|
// but we want references to go to the real path in /packages instead
|
||||||
// -> packages/[name]/dist/index.js
|
// -> packages/[name]/dist
|
||||||
const relativePath = path.relative(process.cwd(), absolutePath)
|
const distPath = path.join(path.relative(process.cwd(), absolutePath), '..')
|
||||||
// -> /packages/[name]/src
|
// -> /packages/[name]/src
|
||||||
const modulePath = path.join(relativePath, '../../src')
|
const modulePath = path.join(distPath, '../src')
|
||||||
|
|
||||||
tsconfig.compilerOptions.paths['@framework'] = [`${modulePath}`]
|
tsconfig.compilerOptions.paths['@framework'] = [`${modulePath}`]
|
||||||
tsconfig.compilerOptions.paths['@framework/*'] = [`${modulePath}/*`]
|
tsconfig.compilerOptions.paths['@framework/*'] = [`${modulePath}/*`]
|
||||||
@ -78,6 +78,25 @@ function withCommerceConfig(nextConfig = {}) {
|
|||||||
tsconfigPath,
|
tsconfigPath,
|
||||||
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
|
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const webpack = config.webpack
|
||||||
|
|
||||||
|
// To improve the DX of using references, we'll switch from `src` to `dist`
|
||||||
|
// only for webpack so imports resolve correctly but typechecking goes to `src`
|
||||||
|
config.webpack = (cfg, options) => {
|
||||||
|
if (Array.isArray(cfg.resolve.plugins)) {
|
||||||
|
const jsconfigPaths = cfg.resolve.plugins.find(
|
||||||
|
(plugin) => plugin.constructor.name === 'JsConfigPathsPlugin'
|
||||||
|
)
|
||||||
|
|
||||||
|
if (jsconfigPaths) {
|
||||||
|
jsconfigPaths.paths['@framework'] = [distPath]
|
||||||
|
jsconfigPaths.paths['@framework/*'] = [`${distPath}/*`]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return webpack ? webpack(cfg, options) : cfg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return core.withCommerceConfig(config)
|
return core.withCommerceConfig(config)
|
||||||
|
@ -11,7 +11,7 @@ import type { Product } from '@commerce/types/product'
|
|||||||
import usePrice from '@framework/product/use-price'
|
import usePrice from '@framework/product/use-price'
|
||||||
import useAddItem from '@framework/cart/use-add-item'
|
import useAddItem from '@framework/cart/use-add-item'
|
||||||
import useRemoveItem from '@framework/wishlist/use-remove-item'
|
import useRemoveItem from '@framework/wishlist/use-remove-item'
|
||||||
import { Wishlist } from '@commerce/types/wishlist'
|
import type { Wishlist } from '@commerce/types/wishlist'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
item: Wishlist
|
item: Wishlist
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
"@config/*": ["config/*"],
|
"@config/*": ["config/*"],
|
||||||
"@assets/*": ["assets/*"],
|
"@assets/*": ["assets/*"],
|
||||||
"@components/*": ["components/*"],
|
"@components/*": ["components/*"],
|
||||||
"@commerce": ["framework/commerce"],
|
"@commerce": ["../packages/commerce/src"],
|
||||||
"@commerce/*": ["framework/commerce/*"],
|
"@commerce/*": ["../packages/commerce/src/*"],
|
||||||
"@framework": ["../packages/local/src"],
|
"@framework": ["../packages/local/src"],
|
||||||
"@framework/*": ["../packages/local/src/*"]
|
"@framework/*": ["../packages/local/src/*"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user