**What** - Move packages for `next` version of admin to core repo **Other** - Since this PR introduces packages that depend on Vite 5, it also introduces @types/node@^20. We have never had a direct dependency on the types package for Node, and as far as I can see that has resulted in us using the types from Node.js@8, as those are a dependency of one of our dependencies. With the introduction of @types/node@^20, two of our packages had TS errors because they were using the NodeJS.Timer type, which was deprecated in Node.js@14. We should add specific @types/node packages to all our packages, but I haven't done so in this PR to keep it as clean as possible. - Q: @olivermrbl I've added the new packages to the ignore list for changeset, is this enough to prevent them from being published?
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { readFileSync } from "fs"
|
|
import glob from "glob"
|
|
import { relative, resolve } from "path"
|
|
import { build as command } from "vite"
|
|
|
|
type BundleArgs = {
|
|
root?: string | undefined
|
|
watch?: boolean | undefined
|
|
}
|
|
|
|
export async function bundle({ watch, root }: BundleArgs) {
|
|
const resolvedRoot = root
|
|
? resolve(process.cwd(), root)
|
|
: resolve(process.cwd(), "src", "admin")
|
|
|
|
const files = glob.sync(`${resolvedRoot}/**/*.{ts,tsx,js,jsx}`)
|
|
|
|
const input: Record<string, string> = {}
|
|
for (const file of files) {
|
|
const relativePath = relative(resolvedRoot, file)
|
|
input[relativePath] = file
|
|
}
|
|
|
|
const packageJson = JSON.parse(
|
|
readFileSync(resolve(process.cwd(), "package.json"), "utf-8")
|
|
)
|
|
const external = [
|
|
...Object.keys(packageJson.dependencies),
|
|
"@medusajs/ui",
|
|
"@medusajs/ui-preset",
|
|
"react",
|
|
"react-dom",
|
|
"react-router-dom",
|
|
"react-hook-form",
|
|
]
|
|
|
|
await command({
|
|
build: {
|
|
watch: watch ? {} : undefined,
|
|
rollupOptions: {
|
|
input: input,
|
|
external: external,
|
|
},
|
|
},
|
|
})
|
|
}
|