Skip to content

Commit

Permalink
chore(scripts): Use paths instead of version in packed tgz files
Browse files Browse the repository at this point in the history
  • Loading branch information
attitude committed Oct 27, 2023
1 parent 1f97891 commit 9df335b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { join } from 'path'
throw e
}

await bumpVersion(dir, LOCAL_REF)
await bumpVersion(dir, outDirPath, LOCAL_REF)
await npmPack(dir, outDirPath)

try {
Expand All @@ -58,8 +58,8 @@ import { join } from 'path'
process.exit(1)
})

async function bumpVersion(directory: string, localRef: string) {
console.log(`Bumping version for ${directory} ...`)
async function bumpVersion(directory: string, targetDirectory: string, localRef: string) {
console.log(`Bumping version for ${directory} to ${targetDirectory} ...`)
const packageJsonPath = join(directory, 'package.json')

const packageJsonContent = await fs.readFile(packageJsonPath, 'utf8')
Expand All @@ -80,7 +80,7 @@ async function bumpVersion(directory: string, localRef: string) {
if (packageJson[dependencyType]) {
for (const dependencyName of Object.keys(packageJson[dependencyType])) {
if (dependencyName.startsWith('@contember/') && packageJson[dependencyType][dependencyName].startsWith('workspace:')) {
packageJson[dependencyType][dependencyName] = localRef
packageJson[dependencyType][dependencyName] = asLocalTgzPath(targetDirectory, dependencyName, localRef)
}
}
}
Expand All @@ -90,6 +90,10 @@ async function bumpVersion(directory: string, localRef: string) {
console.log(`Version bumped successfully for ${directory}!`)
}

function asLocalTgzPath(targetDirectory: string, dependencyName: string, version: string) {
return `file:${targetDirectory}/${dependencyName.substring(1).replace(/[^\w]/, '-')}-${version}.tgz`
}

async function npmPack(directory: string, destinationPath: string) {
console.log(`Packaging ${directory} ... ${destinationPath}`)

Expand Down

0 comments on commit 9df335b

Please sign in to comment.