mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
Compare commits
3 Commits
shadcn@4.8
...
codex/1065
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f2e6e1c1 | ||
|
|
d63c7813f2 | ||
|
|
5a4abc0ee8 |
5
.changeset/grumpy-moles-ring.md
Normal file
5
.changeset/grumpy-moles-ring.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"shadcn": patch
|
||||
---
|
||||
|
||||
add allowBuilds for pnpm 11
|
||||
@@ -104,6 +104,38 @@ function getInstallArgs(packageManager: string): string[] {
|
||||
}
|
||||
}
|
||||
|
||||
async function getPnpmWorkspacePatterns(pnpmWorkspacePath: string) {
|
||||
if (!fs.existsSync(pnpmWorkspacePath)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const workspaceContent = await fs.readFile(pnpmWorkspacePath, "utf8")
|
||||
const patterns: string[] = []
|
||||
let readingPackages = false
|
||||
|
||||
for (const line of workspaceContent.split("\n")) {
|
||||
if (/^packages:\s*$/.test(line)) {
|
||||
readingPackages = true
|
||||
continue
|
||||
}
|
||||
|
||||
if (readingPackages && /^\S/.test(line)) {
|
||||
readingPackages = false
|
||||
}
|
||||
|
||||
if (!readingPackages) {
|
||||
continue
|
||||
}
|
||||
|
||||
const match = line.match(/^\s*-\s*["']?(.+?)["']?\s*$/)
|
||||
if (match) {
|
||||
patterns.push(match[1])
|
||||
}
|
||||
}
|
||||
|
||||
return patterns
|
||||
}
|
||||
|
||||
// Adapt a pnpm-based monorepo template to the target package manager.
|
||||
async function adaptWorkspaceConfig(
|
||||
projectPath: string,
|
||||
@@ -122,7 +154,9 @@ async function adaptWorkspaceConfig(
|
||||
await fs.remove(lockFilePath)
|
||||
}
|
||||
|
||||
const isMonorepo = fs.existsSync(pnpmWorkspacePath)
|
||||
const hasPnpmWorkspaceConfig = fs.existsSync(pnpmWorkspacePath)
|
||||
const workspacePatterns = await getPnpmWorkspacePatterns(pnpmWorkspacePath)
|
||||
const isMonorepo = workspacePatterns.length > 0
|
||||
|
||||
// Update root package.json: update "packageManager" field for the
|
||||
// target package manager, and add "workspaces" for npm/bun/yarn.
|
||||
@@ -140,18 +174,7 @@ async function adaptWorkspaceConfig(
|
||||
}
|
||||
|
||||
if (isMonorepo) {
|
||||
// Read workspace patterns from pnpm-workspace.yaml.
|
||||
const workspaceContent = await fs.readFile(pnpmWorkspacePath, "utf8")
|
||||
const patterns: string[] = []
|
||||
for (const line of workspaceContent.split("\n")) {
|
||||
const match = line.match(/^\s*-\s*["']?(.+?)["']?\s*$/)
|
||||
if (match) {
|
||||
patterns.push(match[1])
|
||||
}
|
||||
}
|
||||
|
||||
packageJson.workspaces = patterns
|
||||
await fs.remove(pnpmWorkspacePath)
|
||||
packageJson.workspaces = workspacePatterns
|
||||
}
|
||||
|
||||
await fs.writeFile(
|
||||
@@ -160,6 +183,10 @@ async function adaptWorkspaceConfig(
|
||||
)
|
||||
}
|
||||
|
||||
if (hasPnpmWorkspaceConfig) {
|
||||
await fs.remove(pnpmWorkspacePath)
|
||||
}
|
||||
|
||||
// Rewrite workspace: protocol references in nested package.json files.
|
||||
// npm does not support workspace: protocol; bun and yarn do, so only
|
||||
// rewrite for npm monorepo templates.
|
||||
|
||||
@@ -311,6 +311,84 @@ describe("defaultScaffold", () => {
|
||||
expect(written.packageManager).toBe("bun@1.2.0")
|
||||
})
|
||||
|
||||
it("should remove pnpm-only workspace config for non-pnpm templates", async () => {
|
||||
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
|
||||
const s = p.toString()
|
||||
return s.includes("pnpm-workspace.yaml") || s.includes("package.json")
|
||||
})
|
||||
|
||||
vi.mocked(fs.readFile).mockImplementation(((filePath: string) => {
|
||||
if (filePath.includes("pnpm-workspace.yaml")) {
|
||||
return Promise.resolve("allowBuilds:\n esbuild: true\n")
|
||||
}
|
||||
return Promise.resolve(
|
||||
JSON.stringify({ name: "my-app", packageManager: "pnpm@9.0.0" })
|
||||
)
|
||||
}) as any)
|
||||
|
||||
const template = createTestTemplate()
|
||||
|
||||
await template.scaffold({
|
||||
projectPath: "/test/my-app",
|
||||
packageManager: "bun",
|
||||
cwd: "/test",
|
||||
})
|
||||
|
||||
expect(vi.mocked(fs.remove)).toHaveBeenCalledWith(
|
||||
path.join("/test/my-app", "pnpm-workspace.yaml")
|
||||
)
|
||||
|
||||
const writeCalls = vi.mocked(fs.writeFile).mock.calls
|
||||
const adaptCall = writeCalls.find(
|
||||
(call) => call[0] === path.join("/test/my-app", "package.json")
|
||||
)
|
||||
expect(adaptCall).toBeDefined()
|
||||
const written = JSON.parse(adaptCall![1] as string)
|
||||
expect(written.packageManager).toBeUndefined()
|
||||
expect(written.workspaces).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should treat single-app workspace yaml (packages:[] + allowBuilds) as non-monorepo", async () => {
|
||||
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
|
||||
const s = p.toString()
|
||||
return s.includes("pnpm-workspace.yaml") || s.includes("package.json")
|
||||
})
|
||||
|
||||
vi.mocked(fs.readFile).mockImplementation(((filePath: string) => {
|
||||
if (filePath.includes("pnpm-workspace.yaml")) {
|
||||
return Promise.resolve(
|
||||
"packages: []\n\nallowBuilds:\n esbuild: true\n"
|
||||
)
|
||||
}
|
||||
return Promise.resolve(
|
||||
JSON.stringify({ name: "my-app", packageManager: "pnpm@9.0.0" })
|
||||
)
|
||||
}) as any)
|
||||
|
||||
const template = createTestTemplate()
|
||||
|
||||
await template.scaffold({
|
||||
projectPath: "/test/my-app",
|
||||
packageManager: "npm",
|
||||
cwd: "/test",
|
||||
})
|
||||
|
||||
// Inline empty packages array must not be parsed as a monorepo;
|
||||
// the yaml is stripped and no workspaces array is added.
|
||||
expect(vi.mocked(fs.remove)).toHaveBeenCalledWith(
|
||||
path.join("/test/my-app", "pnpm-workspace.yaml")
|
||||
)
|
||||
|
||||
const writeCalls = vi.mocked(fs.writeFile).mock.calls
|
||||
const adaptCall = writeCalls.find(
|
||||
(call) => call[0] === path.join("/test/my-app", "package.json")
|
||||
)
|
||||
expect(adaptCall).toBeDefined()
|
||||
const written = JSON.parse(adaptCall![1] as string)
|
||||
expect(written.packageManager).toBeUndefined()
|
||||
expect(written.workspaces).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should rewrite workspace: protocol refs to * for npm monorepo", async () => {
|
||||
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
|
||||
const s = p.toString()
|
||||
|
||||
6
templates/astro-app/pnpm-workspace.yaml
Normal file
6
templates/astro-app/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
packages: []
|
||||
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
sharp: true
|
||||
msw: false
|
||||
6
templates/next-app/pnpm-workspace.yaml
Normal file
6
templates/next-app/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
packages: []
|
||||
|
||||
allowBuilds:
|
||||
sharp: true
|
||||
unrs-resolver: true
|
||||
msw: false
|
||||
5
templates/react-router-app/pnpm-workspace.yaml
Normal file
5
templates/react-router-app/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
packages: []
|
||||
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
msw: false
|
||||
6
templates/start-app/pnpm-workspace.yaml
Normal file
6
templates/start-app/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
packages: []
|
||||
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
unrs-resolver: true
|
||||
msw: false
|
||||
5
templates/vite-app/pnpm-workspace.yaml
Normal file
5
templates/vite-app/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
packages: []
|
||||
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
msw: false
|
||||
@@ -1,3 +1,6 @@
|
||||
packages:
|
||||
- "apps/*"
|
||||
- "packages/*"
|
||||
|
||||
allowBuilds:
|
||||
esbuild: true
|
||||
|
||||
Reference in New Issue
Block a user