Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vue-macros): override catalog #17

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.1",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"yaml": "^2.5.1"
},
"pnpm": {
"overrides": {
"cookie@<0.7.0": ">=0.7.0"
}
}
}
16 changes: 11 additions & 5 deletions pnpm-lock.yaml

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

18 changes: 16 additions & 2 deletions tests/vue-macros.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { runInRepo } from '../utils.ts'
import { RunOptions } from '../types.ts'
import { Overrides, RunOptions } from '../types.ts'
import YAML from 'yaml'

export async function test(options: RunOptions) {
const overrideVueVersion = '@^3'
await runInRepo({
...options,
repo: 'vue-macros/vue-macros',
branch: 'main',
build: 'build',
test: ['test:ecosystem'],
overrideVueVersion: '@^3',
overrideVueVersion,
patchFiles: {
'pnpm-workspace.yaml': (content: string, overrides: Overrides) => {
const data = YAML.parse(content)
Object.keys(overrides).forEach((key) => {
const pkgName = key.replace(overrideVueVersion, '')
if (data.catalog[pkgName]) {
data.catalog[pkgName] = overrides[key]
}
})
return YAML.stringify(data)
},
},
})
}
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface RunOptions {
beforeInstall?: Task | Task[]
beforeBuild?: Task | Task[]
beforeTest?: Task | Task[]
patchFiles?: Record<string, (content: string) => string>
patchFiles?: Record<string, (content: string, overrides: Overrides) => string>
}

type Task = string | { script: string; args?: string[] } | (() => Promise<any>)
Expand Down
58 changes: 29 additions & 29 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,40 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
)
}

const overrides = options.overrides || {}
const vuePackages = await getVuePackages()

if (options.release) {
// pkg.pr.new support
for (const pkg of vuePackages) {
let version = options.release
if (options.release.startsWith('@')) {
version = `https://pkg.pr.new/${pkg.name}@${options.release.slice(1)}`
}
if (overrides[pkg.name] && overrides[pkg.name] !== version) {
throw new Error(
`conflicting overrides[${pkg.name}]=${
overrides[pkg.name]
} and --release=${
options.release
} config. Use either one or the other`,
)
} else {
overrides[`${pkg.name}${overrideVueVersion}`] = version
}
}
} else {
for (const pkg of vuePackages) {
overrides[pkg.name] ||= pkg.hashedVersion
}
}

if (patchFiles) {
for (const fileName in patchFiles) {
const filePath = path.resolve(dir, fileName)
const patchFn = patchFiles[fileName]
const content = fs.readFileSync(filePath, 'utf-8')
fs.writeFileSync(filePath, patchFn(content))
fs.writeFileSync(filePath, patchFn(content, overrides))
console.log(`patched file: ${fileName}`)
}
}
Expand All @@ -297,36 +325,8 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
await beforeTestCommand?.(pkg.scripts)
await testCommand?.(pkg.scripts)
}
const overrides = options.overrides || {}

const vuePackages = await getVuePackages()

if (options.release) {
// pkg.pr.new support
for (const pkg of vuePackages) {
let version = options.release
if (options.release.startsWith('@')) {
version = `https://pkg.pr.new/${pkg.name}@${options.release.slice(1)}`
}
if (overrides[pkg.name] && overrides[pkg.name] !== version) {
throw new Error(
`conflicting overrides[${pkg.name}]=${
overrides[pkg.name]
} and --release=${
options.release
} config. Use either one or the other`,
)
} else {
overrides[`${pkg.name}${overrideVueVersion}`] = version
}
}
} else {
for (const pkg of vuePackages) {
overrides[pkg.name] ||= pkg.hashedVersion
}
}
await applyPackageOverrides(dir, pkg, overrides)

await beforeBuildCommand?.(pkg.scripts)
await buildCommand?.(pkg.scripts)
if (test) {
Expand Down
Loading