Skip to content

Commit

Permalink
fix: make dependencies work good
Browse files Browse the repository at this point in the history
  • Loading branch information
tefkah committed Sep 21, 2023
1 parent b8a0331 commit 7cfc422
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions libs/plugins/better-nx-tsc/src/executors/publishable/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,45 @@ function getNonTestDependencies(context: ExecutorContext) {
)
}

function correctBadNxScopeDep(deps: [dep: string, version: unknown][]) {
const correctedDeps = deps.map(([dep, version]) => {
const stringVersion = String(version)
console.log(dep, stringVersion)
if (/@\w+/.test(dep)) {
const match = stringVersion.match(/(.*?)@((?:\d+|\.)+)/)
console.log({ match })
const depNextName = match?.[1]
const depVersion = match?.[2]

const newDep = [`${dep}/${depNextName}`, `^${depVersion}`]

return newDep
}
return [dep, version]
})

return correctedDeps
}

function updatePackageJson(packageJson: any, nonTestDependencies: Set<string>, distDir: string) {
const dependencies = packageJson.dependencies ?? {}
const devDependencies = packageJson.devDependencies ?? {}
console.log(packageJson)

const newDependencies = Object.fromEntries(
Object.entries(dependencies).filter(([dep]) => nonTestDependencies.has(dep)),
console.log(nonTestDependencies)
const newDependencies = Object.entries(dependencies).filter(([dep]) =>
nonTestDependencies.has(dep),
)
const newDevDependencies = Object.fromEntries(
Object.entries(devDependencies).filter(([dep]) => nonTestDependencies.has(dep)),

const newDevDependencies = Object.entries(devDependencies).filter(([dep]) =>
nonTestDependencies.has(dep),
)
console.log(newDependencies)

return {
...packageJson,
dependencies: newDependencies,
devDependencies: newDevDependencies,
dependencies: Object.fromEntries(correctBadNxScopeDep(newDependencies)),
devDependencies: Object.fromEntries(correctBadNxScopeDep(newDevDependencies)),
}
}

Expand Down Expand Up @@ -97,6 +121,7 @@ export default async function runExecutor(
nonTestDependencies,
distDir,
)
console.log(newPackageJson)

if (JSON.stringify(newPackageJson) === JSON.stringify(packageJson)) {
console.log('No changes to package.json')
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"inputs": ["production", "^production"]
},
"make-publishable": {
"dependsOn": ["^build", "lint"],
"dependsOn": ["build", "^build", "lint"],
"inputs": ["production", "^production"],
"executor": "better-nx-tsc:publishable"
},
Expand Down

0 comments on commit 7cfc422

Please sign in to comment.