@prenta/cli 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +47 -34
- package/CHANGELOG.md +27 -0
- package/dist/commands/chrome.d.ts +74 -0
- package/dist/commands/chrome.d.ts.map +1 -0
- package/dist/commands/chrome.js +274 -0
- package/dist/commands/chrome.js.map +1 -0
- package/dist/commands/upgrade.d.ts +27 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +81 -45
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/workspaces.d.ts +25 -0
- package/dist/utils/workspaces.d.ts.map +1 -0
- package/dist/utils/workspaces.js +143 -0
- package/dist/utils/workspaces.js.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/chrome.test.ts +258 -0
- package/src/__tests__/upgrade-workspaces.test.ts +215 -0
- package/src/commands/chrome.ts +362 -0
- package/src/commands/upgrade.ts +117 -46
- package/src/index.ts +11 -1
- package/src/utils/workspaces.ts +140 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm, writeFile, mkdir } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { defineRegion, field } from '@prenta/core/config'
|
|
5
|
+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
cmsApiBase,
|
|
9
|
+
collectRegions,
|
|
10
|
+
detectSource,
|
|
11
|
+
pullChrome,
|
|
12
|
+
pushChrome,
|
|
13
|
+
repoFromRemote,
|
|
14
|
+
writeChromeTypes,
|
|
15
|
+
} from '../commands/chrome.js'
|
|
16
|
+
|
|
17
|
+
const header = defineRegion('header', {
|
|
18
|
+
component: './src/components/site/Header.astro',
|
|
19
|
+
variants: { default: 'Logo left, menu right', minimal: 'Logo + CTA' },
|
|
20
|
+
fields: {
|
|
21
|
+
logo: field.brand('logo'),
|
|
22
|
+
menu: field.menu({ default: 'main' }),
|
|
23
|
+
cta: field.link({ optional: true }),
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
const footer = defineRegion('footer', {
|
|
27
|
+
component: './src/components/site/Footer.astro',
|
|
28
|
+
variants: { columns: 'Columns' },
|
|
29
|
+
fields: { tone: field.select(['dark', 'light'], { default: 'dark' }) },
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const schemaView = {
|
|
33
|
+
regions: [
|
|
34
|
+
{
|
|
35
|
+
region: 'header',
|
|
36
|
+
component: './src/components/site/Header.astro',
|
|
37
|
+
variants: { default: 'Logo left, menu right', minimal: 'Logo + CTA' },
|
|
38
|
+
fields: { logo: { type: 'brand', key: 'logo' }, cta: { type: 'link', optional: true } },
|
|
39
|
+
source: {
|
|
40
|
+
repo: 'actuate/website',
|
|
41
|
+
branch: 'main',
|
|
42
|
+
commit: 'a41f9c2',
|
|
43
|
+
readAt: '2026-10-20T10:00:00.000Z',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
sync: { status: 'synced', source: null, regions: ['header'], fieldCount: 2 },
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mockFetch(respond: (url: string, init: RequestInit) => Response) {
|
|
51
|
+
return vi.fn(async (input: string | URL | Request, init?: RequestInit) =>
|
|
52
|
+
respond(String(input), init ?? {}),
|
|
53
|
+
) as unknown as typeof fetch
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let dir: string
|
|
57
|
+
|
|
58
|
+
// The commands load the core barrel on first use, which takes a few seconds cold.
|
|
59
|
+
beforeAll(async () => {
|
|
60
|
+
await import('@prenta/core')
|
|
61
|
+
}, 60_000)
|
|
62
|
+
|
|
63
|
+
beforeEach(async () => {
|
|
64
|
+
dir = await mkdtemp(path.join(tmpdir(), 'prenta-chrome-'))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
afterEach(async () => {
|
|
68
|
+
await rm(dir, { recursive: true, force: true })
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('prenta pull chrome', () => {
|
|
72
|
+
it('writes the CMS schema to .prenta/chrome.json', async () => {
|
|
73
|
+
const fetchImpl = mockFetch((url, init) => {
|
|
74
|
+
expect(url).toBe('https://cms.example.com/api/cms/chrome/schema')
|
|
75
|
+
expect(new Headers(init.headers).get('authorization')).toBe('Bearer act_sk_test')
|
|
76
|
+
return new Response(JSON.stringify({ data: schemaView }), { status: 200 })
|
|
77
|
+
})
|
|
78
|
+
const { file } = await pullChrome({
|
|
79
|
+
url: 'https://cms.example.com/',
|
|
80
|
+
key: 'act_sk_test',
|
|
81
|
+
fetch: fetchImpl,
|
|
82
|
+
cwd: dir,
|
|
83
|
+
})
|
|
84
|
+
expect(file).toBe(path.join(dir, '.prenta', 'chrome.json'))
|
|
85
|
+
const written = JSON.parse(await readFile(file, 'utf8'))
|
|
86
|
+
expect(written.regions).toEqual(schemaView.regions)
|
|
87
|
+
expect(written.sync).toEqual(schemaView.sync)
|
|
88
|
+
expect(written.cms).toBe('https://cms.example.com/api/cms')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('reports the CMS error and needs a URL and key', async () => {
|
|
92
|
+
const fetchImpl = mockFetch(
|
|
93
|
+
() =>
|
|
94
|
+
new Response(JSON.stringify({ error: 'API key does not have the chrome scope' }), {
|
|
95
|
+
status: 403,
|
|
96
|
+
}),
|
|
97
|
+
)
|
|
98
|
+
await expect(
|
|
99
|
+
pullChrome({ url: 'https://cms.example.com', key: 'k', fetch: fetchImpl, cwd: dir }),
|
|
100
|
+
).rejects.toThrow(/403.*chrome scope/)
|
|
101
|
+
await expect(pullChrome({ url: undefined, key: 'k', cwd: dir })).rejects.toThrow(
|
|
102
|
+
/PRENTA_CMS_URL/,
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('prenta types', () => {
|
|
108
|
+
it('emits ChromeFields from the pulled schema', async () => {
|
|
109
|
+
await mkdir(path.join(dir, '.prenta'))
|
|
110
|
+
await writeFile(path.join(dir, '.prenta', 'chrome.json'), JSON.stringify(schemaView))
|
|
111
|
+
const { file, source } = await writeChromeTypes({ cwd: dir })
|
|
112
|
+
expect(file).toBe(path.join(dir, '.prenta', 'chrome.d.ts'))
|
|
113
|
+
expect(await readFile(file!, 'utf8')).toBe(source)
|
|
114
|
+
expect(source).toContain('export interface ChromeFields {')
|
|
115
|
+
expect(source).toContain(' cta: ChromeLink | null\n')
|
|
116
|
+
expect(source).toContain('export interface ChromeVariants {')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('prints with --out - and says to pull first when nothing was pulled', async () => {
|
|
120
|
+
await expect(writeChromeTypes({ cwd: dir })).rejects.toThrow(/prenta pull chrome/)
|
|
121
|
+
await mkdir(path.join(dir, '.prenta'))
|
|
122
|
+
await writeFile(path.join(dir, '.prenta', 'chrome.json'), JSON.stringify(schemaView))
|
|
123
|
+
expect((await writeChromeTypes({ cwd: dir, out: '-' })).file).toBeNull()
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('prenta push chrome', () => {
|
|
128
|
+
it('sends every exported region with its source, and reports what the CMS changed', async () => {
|
|
129
|
+
let body: {
|
|
130
|
+
regions: Array<{ region: string; fields: Record<string, unknown> }>
|
|
131
|
+
source: unknown
|
|
132
|
+
} | null = null
|
|
133
|
+
const fetchImpl = mockFetch((url, init) => {
|
|
134
|
+
expect(url).toBe('https://cms.example.com/api/cms/chrome/schema')
|
|
135
|
+
expect(init.method).toBe('PUT')
|
|
136
|
+
body = JSON.parse(String(init.body))
|
|
137
|
+
return new Response(
|
|
138
|
+
JSON.stringify({
|
|
139
|
+
data: {
|
|
140
|
+
regions: [
|
|
141
|
+
{ region: 'header', orphaned: ['tagline'], renamed: [], restored: [], changed: true },
|
|
142
|
+
],
|
|
143
|
+
source: { repo: 'actuate/website', branch: 'main', commit: 'a41f9c2', readAt: 'x' },
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
{ status: 200 },
|
|
147
|
+
)
|
|
148
|
+
})
|
|
149
|
+
const { result } = await pushChrome({
|
|
150
|
+
url: 'https://cms.example.com',
|
|
151
|
+
key: 'act_sk_admin',
|
|
152
|
+
fetch: fetchImpl,
|
|
153
|
+
cwd: dir,
|
|
154
|
+
load: async () => ({ header, footer, default: { collections: {} }, helper: 1 }),
|
|
155
|
+
source: { repo: 'actuate/website', branch: 'main', commit: 'a41f9c2' },
|
|
156
|
+
})
|
|
157
|
+
expect(body!.regions.map((region) => region.region)).toEqual(['header', 'footer'])
|
|
158
|
+
expect(body!.regions[0]!.fields.cta).toEqual({ type: 'link', optional: true })
|
|
159
|
+
expect(body!.source).toEqual({ repo: 'actuate/website', branch: 'main', commit: 'a41f9c2' })
|
|
160
|
+
expect(result?.regions[0]?.orphaned).toEqual(['tagline'])
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('refuses a config with no regions, and sends nothing on --dry-run', async () => {
|
|
164
|
+
await expect(pushChrome({ cwd: dir, load: async () => ({ default: {} }) })).rejects.toThrow(
|
|
165
|
+
/exports no regions/,
|
|
166
|
+
)
|
|
167
|
+
const fetchImpl = vi.fn() as unknown as typeof fetch
|
|
168
|
+
const { payload, result } = await pushChrome({
|
|
169
|
+
cwd: dir,
|
|
170
|
+
dryRun: true,
|
|
171
|
+
fetch: fetchImpl,
|
|
172
|
+
load: async () => ({ header }),
|
|
173
|
+
source: { commit: 'abc' },
|
|
174
|
+
})
|
|
175
|
+
expect(result).toBeNull()
|
|
176
|
+
expect(payload.regions).toHaveLength(1)
|
|
177
|
+
expect(fetchImpl).not.toHaveBeenCalled()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('refuses a region defined twice', async () => {
|
|
181
|
+
await expect(collectRegions({ a: header, b: header })).rejects.toThrow(/header region twice/)
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
describe('source detection', () => {
|
|
186
|
+
it('prefers Vercel, then GitHub Actions, then git', () => {
|
|
187
|
+
const neverGit = () => {
|
|
188
|
+
throw new Error('no git')
|
|
189
|
+
}
|
|
190
|
+
expect(
|
|
191
|
+
detectSource(
|
|
192
|
+
{
|
|
193
|
+
VERCEL_GIT_REPO_OWNER: 'actuate',
|
|
194
|
+
VERCEL_GIT_REPO_SLUG: 'website',
|
|
195
|
+
VERCEL_GIT_COMMIT_REF: 'main',
|
|
196
|
+
VERCEL_GIT_COMMIT_SHA: 'a41f9c2',
|
|
197
|
+
GITHUB_SHA: 'ignored',
|
|
198
|
+
},
|
|
199
|
+
dir,
|
|
200
|
+
neverGit,
|
|
201
|
+
),
|
|
202
|
+
).toEqual({ repo: 'actuate/website', branch: 'main', commit: 'a41f9c2' })
|
|
203
|
+
expect(
|
|
204
|
+
detectSource(
|
|
205
|
+
{ GITHUB_REPOSITORY: 'actuate/website', GITHUB_REF_NAME: 'release', GITHUB_SHA: 'b1' },
|
|
206
|
+
dir,
|
|
207
|
+
neverGit,
|
|
208
|
+
),
|
|
209
|
+
).toEqual({ repo: 'actuate/website', branch: 'release', commit: 'b1' })
|
|
210
|
+
const git = (_file: string, args: string[]) =>
|
|
211
|
+
args[0] === 'remote'
|
|
212
|
+
? 'git@github.com:actuate/website.git\n'
|
|
213
|
+
: args.includes('--abbrev-ref')
|
|
214
|
+
? 'main\n'
|
|
215
|
+
: 'c0ffee\n'
|
|
216
|
+
expect(detectSource({}, dir, git)).toEqual({
|
|
217
|
+
repo: 'actuate/website',
|
|
218
|
+
branch: 'main',
|
|
219
|
+
commit: 'c0ffee',
|
|
220
|
+
})
|
|
221
|
+
expect(detectSource({}, dir, neverGit)).toEqual({ repo: '', branch: '', commit: '' })
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('reads owner/repo from a remote URL', () => {
|
|
225
|
+
expect(repoFromRemote('https://github.com/actuate/website.git')).toBe('actuate/website')
|
|
226
|
+
expect(repoFromRemote('git@github.com:actuate/website')).toBe('actuate/website')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('never keeps credentials from the remote (review)', () => {
|
|
230
|
+
const secret = 'SECRET'
|
|
231
|
+
for (const remote of [
|
|
232
|
+
`https://oauth2:${secret}@git.example.com/site.git`,
|
|
233
|
+
`https://${secret}@github.com/actuate/website.git`,
|
|
234
|
+
`https://user:${secret}@gitlab.example.com/group/sub/site`,
|
|
235
|
+
`user:${secret}@git.example.com:actuate/website.git`,
|
|
236
|
+
]) {
|
|
237
|
+
expect(repoFromRemote(remote)).not.toContain(secret)
|
|
238
|
+
expect(repoFromRemote(remote)).not.toContain('@')
|
|
239
|
+
}
|
|
240
|
+
expect(repoFromRemote(`https://oauth2:${secret}@git.example.com/site.git`)).toBe('site')
|
|
241
|
+
expect(repoFromRemote(`https://${secret}@github.com/actuate/website.git`)).toBe(
|
|
242
|
+
'actuate/website',
|
|
243
|
+
)
|
|
244
|
+
expect(repoFromRemote(`user:${secret}@git.example.com:actuate/website.git`)).toBe(
|
|
245
|
+
'actuate/website',
|
|
246
|
+
)
|
|
247
|
+
const git = () => `https://x-access-token:${secret}@github.com/actuate/website.git\n`
|
|
248
|
+
expect(detectSource({}, dir, git).repo).toBe('actuate/website')
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('takes a CMS URL with or without /api/cms', () => {
|
|
252
|
+
expect(cmsApiBase('https://cms.example.com/')).toBe('https://cms.example.com/api/cms')
|
|
253
|
+
expect(cmsApiBase('https://cms.example.com/api/cms')).toBe('https://cms.example.com/api/cms')
|
|
254
|
+
expect(cmsApiBase('https://cms.example.com/api/cms/v1')).toBe(
|
|
255
|
+
'https://cms.example.com/api/cms/v1',
|
|
256
|
+
)
|
|
257
|
+
})
|
|
258
|
+
})
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
applyUpgrades,
|
|
11
|
+
collectPrentaDependencies,
|
|
12
|
+
planUpgrades,
|
|
13
|
+
readProjectManifests,
|
|
14
|
+
} from '../commands/upgrade.js'
|
|
15
|
+
import {
|
|
16
|
+
detectInstallCommand,
|
|
17
|
+
findEnclosingWorkspaceRoot,
|
|
18
|
+
findWorkspaceManifests,
|
|
19
|
+
parsePnpmWorkspacePackages,
|
|
20
|
+
} from '../utils/workspaces.js'
|
|
21
|
+
|
|
22
|
+
let root: string
|
|
23
|
+
|
|
24
|
+
async function writeJson(path: string, value: unknown, indent: string | number = 2, eol = '\n') {
|
|
25
|
+
await mkdir(join(path, '..'), { recursive: true })
|
|
26
|
+
await writeFile(path, JSON.stringify(value, null, indent).replace(/\n/g, eol) + eol)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
root = await mkdtemp(join(tmpdir(), 'prenta-upgrade-'))
|
|
31
|
+
})
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await rm(root, { recursive: true, force: true })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const TARGETS = {
|
|
37
|
+
'@prenta/admin': '2.11.1',
|
|
38
|
+
'@prenta/core': '8.16.1',
|
|
39
|
+
'@prenta/sections-react': '0.20.1',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('prenta upgrade in an npm workspace (#1096)', () => {
|
|
43
|
+
beforeEach(async () => {
|
|
44
|
+
await writeJson(join(root, 'package.json'), {
|
|
45
|
+
name: 'upchat',
|
|
46
|
+
workspaces: ['site'],
|
|
47
|
+
dependencies: {
|
|
48
|
+
'@prenta/admin': '^2.10.0',
|
|
49
|
+
'@prenta/core': '^8.15.0',
|
|
50
|
+
'@prenta/sections-react': '^0.19.0',
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
await writeJson(
|
|
54
|
+
join(root, 'site', 'package.json'),
|
|
55
|
+
{
|
|
56
|
+
name: 'site',
|
|
57
|
+
dependencies: {
|
|
58
|
+
'@prenta/core': '^8.13.3',
|
|
59
|
+
'@prenta/sections-react': '^0.18.11',
|
|
60
|
+
astro: '^5.0.0',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
4,
|
|
64
|
+
'\r\n',
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('upgrades the workspace manifest too, so every workspace lands on the same versions', async () => {
|
|
69
|
+
const manifests = await readProjectManifests(root)
|
|
70
|
+
const upgrades = planUpgrades(collectPrentaDependencies(manifests), TARGETS)
|
|
71
|
+
await applyUpgrades(upgrades)
|
|
72
|
+
|
|
73
|
+
const rootPkg = JSON.parse(await readFile(join(root, 'package.json'), 'utf-8'))
|
|
74
|
+
const site = JSON.parse(await readFile(join(root, 'site', 'package.json'), 'utf-8'))
|
|
75
|
+
expect(rootPkg.dependencies).toEqual({
|
|
76
|
+
'@prenta/admin': '^2.11.1',
|
|
77
|
+
'@prenta/core': '^8.16.1',
|
|
78
|
+
'@prenta/sections-react': '^0.20.1',
|
|
79
|
+
})
|
|
80
|
+
expect(site.dependencies).toEqual({
|
|
81
|
+
'@prenta/core': '^8.16.1',
|
|
82
|
+
'@prenta/sections-react': '^0.20.1',
|
|
83
|
+
astro: '^5.0.0',
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('keeps each manifest’s indentation and line endings', async () => {
|
|
88
|
+
const manifests = await readProjectManifests(root)
|
|
89
|
+
await applyUpgrades(planUpgrades(collectPrentaDependencies(manifests), TARGETS))
|
|
90
|
+
const raw = await readFile(join(root, 'site', 'package.json'), 'utf-8')
|
|
91
|
+
expect(raw).toContain('\r\n "name": "site"')
|
|
92
|
+
expect(raw.endsWith('}\r\n')).toBe(true)
|
|
93
|
+
expect(raw.replace(/\r\n/g, '')).not.toContain('\n')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('leaves workspace:, tag and file: specs alone', async () => {
|
|
97
|
+
await writeJson(join(root, 'site', 'package.json'), {
|
|
98
|
+
name: 'site',
|
|
99
|
+
dependencies: {
|
|
100
|
+
'@prenta/core': 'workspace:*',
|
|
101
|
+
'@prenta/sections-react': 'latest',
|
|
102
|
+
'@prenta/client': 'file:../client',
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
const deps = collectPrentaDependencies(await readProjectManifests(root))
|
|
106
|
+
expect(deps.map((d) => d.manifest.path)).not.toContain(join(root, 'site', 'package.json'))
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('warns from inside a workspace package', async () => {
|
|
110
|
+
expect(await findEnclosingWorkspaceRoot(join(root, 'site'))).toBe(root)
|
|
111
|
+
expect(await findEnclosingWorkspaceRoot(root)).toBeNull()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('names the install command for the lockfile in use', async () => {
|
|
115
|
+
expect(detectInstallCommand(root)).toBe('npm install')
|
|
116
|
+
await writeFile(join(root, 'pnpm-lock.yaml'), '')
|
|
117
|
+
expect(detectInstallCommand(root)).toBe('pnpm install')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('the prenta CLI', () => {
|
|
122
|
+
const cli = fileURLToPath(new URL('../index.ts', import.meta.url))
|
|
123
|
+
// Resolved here: the fixture directory has no node_modules to find tsx in.
|
|
124
|
+
const tsx = import.meta.resolve('tsx')
|
|
125
|
+
const run = (args: string[], cwd: string) =>
|
|
126
|
+
execFileSync(process.execPath, ['--import', tsx, cli, ...args], { cwd, encoding: 'utf-8' })
|
|
127
|
+
|
|
128
|
+
it('passes `upgrade --version <ver>` to upgrade instead of printing the CLI version', async () => {
|
|
129
|
+
await writeJson(join(root, 'package.json'), {
|
|
130
|
+
workspaces: ['site'],
|
|
131
|
+
dependencies: { '@prenta/core': '^8.15.0' },
|
|
132
|
+
})
|
|
133
|
+
await writeJson(join(root, 'site', 'package.json'), {
|
|
134
|
+
dependencies: { '@prenta/core': '^8.13.3' },
|
|
135
|
+
})
|
|
136
|
+
const out = run(['upgrade', '--version', '9.0.0', '--dry-run'], root)
|
|
137
|
+
expect(out).toMatch(/@prenta\/core\s+site\/package\.json\s+8\.13\.3\s+9\.0\.0/)
|
|
138
|
+
expect(out).toContain('Dry run')
|
|
139
|
+
}, 60_000)
|
|
140
|
+
|
|
141
|
+
it('prints its own package version for `prenta --version`', () => {
|
|
142
|
+
const { version } = JSON.parse(
|
|
143
|
+
readFileSync(new URL('../../package.json', import.meta.url), 'utf-8'),
|
|
144
|
+
) as { version: string }
|
|
145
|
+
expect(run(['--version'], root).trim()).toBe(version)
|
|
146
|
+
}, 60_000)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('workspace discovery', () => {
|
|
150
|
+
it('expands globs, the object form, and negations', async () => {
|
|
151
|
+
await writeJson(join(root, 'package.json'), {
|
|
152
|
+
workspaces: { packages: ['apps/*', 'packages/**', '!packages/private'] },
|
|
153
|
+
})
|
|
154
|
+
for (const dir of [
|
|
155
|
+
'apps/web',
|
|
156
|
+
'apps/docs',
|
|
157
|
+
'packages/a',
|
|
158
|
+
'packages/nested/b',
|
|
159
|
+
'packages/private',
|
|
160
|
+
]) {
|
|
161
|
+
await writeJson(join(root, dir, 'package.json'), { name: dir })
|
|
162
|
+
}
|
|
163
|
+
await mkdir(join(root, 'apps', 'no-manifest'), { recursive: true })
|
|
164
|
+
await writeJson(join(root, 'packages', 'a', 'node_modules', 'x', 'package.json'), { name: 'x' })
|
|
165
|
+
|
|
166
|
+
const found = (await findWorkspaceManifests(root)).map((p) =>
|
|
167
|
+
p.slice(root.length + 1).replace(/\\/g, '/'),
|
|
168
|
+
)
|
|
169
|
+
expect(found).toEqual([
|
|
170
|
+
'apps/docs/package.json',
|
|
171
|
+
'apps/web/package.json',
|
|
172
|
+
'packages/a/package.json',
|
|
173
|
+
'packages/nested/b/package.json',
|
|
174
|
+
])
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('reads pnpm-workspace.yaml', async () => {
|
|
178
|
+
await writeJson(join(root, 'package.json'), { name: 'root' })
|
|
179
|
+
await writeFile(
|
|
180
|
+
join(root, 'pnpm-workspace.yaml'),
|
|
181
|
+
'packages:\n - "apps/*"\n - \'site\' # the public site\ncatalog:\n react: ^19\n',
|
|
182
|
+
)
|
|
183
|
+
await writeJson(join(root, 'apps', 'admin', 'package.json'), { name: 'admin' })
|
|
184
|
+
await writeJson(join(root, 'site', 'package.json'), { name: 'site' })
|
|
185
|
+
expect(
|
|
186
|
+
parsePnpmWorkspacePackages(await readFile(join(root, 'pnpm-workspace.yaml'), 'utf-8')),
|
|
187
|
+
).toEqual(['apps/*', 'site'])
|
|
188
|
+
expect(await findWorkspaceManifests(root)).toHaveLength(2)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('reads pnpm lists at column 0 and flow sequences', () => {
|
|
192
|
+
expect(
|
|
193
|
+
parsePnpmWorkspacePackages(
|
|
194
|
+
'packages:\n- site\n- "apps/*"\nonlyBuiltDependencies:\n- esbuild\n',
|
|
195
|
+
),
|
|
196
|
+
).toEqual(['site', 'apps/*'])
|
|
197
|
+
expect(parsePnpmWorkspacePackages('packages: [site, "apps/*", \'docs\']\n')).toEqual([
|
|
198
|
+
'site',
|
|
199
|
+
'apps/*',
|
|
200
|
+
'docs',
|
|
201
|
+
])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('follows ** to any depth', async () => {
|
|
205
|
+
await writeJson(join(root, 'package.json'), { workspaces: ['packages/**'] })
|
|
206
|
+
const deep = join(root, 'packages', 'a', 'b', 'c', 'd', 'e', 'f', 'g')
|
|
207
|
+
await writeJson(join(deep, 'package.json'), { name: 'deep' })
|
|
208
|
+
expect(await findWorkspaceManifests(root)).toEqual([join(deep, 'package.json')])
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('treats a project without workspaces as a single manifest', async () => {
|
|
212
|
+
await writeJson(join(root, 'package.json'), { dependencies: { '@prenta/core': '^8.0.0' } })
|
|
213
|
+
expect(await readProjectManifests(root)).toHaveLength(1)
|
|
214
|
+
})
|
|
215
|
+
})
|