Skip to content

Commit 9e7f0f7

Browse files
feat(builder): set sourceRoot and declarationDir on package tsconfig.json files
- throw error when detecting circular dependencies between packages - fix unpublish command
1 parent 6f1e4d1 commit 9e7f0f7

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

builder/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dandi/builder",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"scripts": {
55
"build": "tsc --outDir dist",
66
"postbuild": "cp package.json dist/builder/"

builder/src/builder-project.ts

+4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ export class BuilderProject implements BuilderConfig, BuilderProjectOptions {
340340
}, info.buildTsConfig.include)
341341
}
342342
info.buildTsConfig.exclude = ['node_modules', '**/*.spec.ts']
343+
info.buildTsConfig.compilerOptions = {
344+
sourceRoot: '../../',
345+
declarationDir: relative(info.path, info.outPath),
346+
}
343347
await this.util.writeJson(info.buildTsConfigPath, info.buildTsConfig)
344348

345349
return info

builder/src/builder.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class Builder {
6464
license: this.project.mainPkg.license,
6565
module: 'index.js',
6666
main: 'index.js',
67+
types: 'index.d.ts',
6768
})
6869

6970
// replace versions for configured scopes
@@ -88,7 +89,12 @@ export class Builder {
8889
await this.copyProjectFile(info, this.project.licenseFile)
8990
}
9091

91-
private async copyPackageFile(info: PackageInfo, packageFileName: string, skipIfNotExists = false): Promise<void> {
92+
private async copyPackageFile(
93+
info: PackageInfo,
94+
packageFileName: string,
95+
skipIfNotExists = false,
96+
relativeTargetPath?: string,
97+
): Promise<void> {
9298
try {
9399
const sourcePath = resolve(info.path, packageFileName)
94100
if (!(await pathExists(sourcePath))) {
@@ -97,7 +103,8 @@ export class Builder {
97103
}
98104
throw new Error(`${sourcePath} does not exist`)
99105
}
100-
await copy(sourcePath, resolve(info.outPath, packageFileName))
106+
const targetPath = relativeTargetPath ? resolve(info.outPath, relativeTargetPath) : info.outPath
107+
await copy(sourcePath, resolve(targetPath, packageFileName))
101108
} catch (err) {
102109
this.logger.error('Error copying package file', info.name, packageFileName, err)
103110
throw err
@@ -118,7 +125,7 @@ export class Builder {
118125
return
119126
}
120127
try {
121-
await Promise.all(info.manifest.map(this.copyPackageFile.bind(this, info)))
128+
await Promise.all(info.manifest.map((filePath) => this.copyPackageFile(info, filePath, false)))
122129
} catch (err) {
123130
this.logger.error('Error copying manifest files', info.name)
124131
throw err

builder/src/publisher.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export class Publisher {
3838

3939
if (state.remaining.length) {
4040
const remainingNames = state.remaining.map((info) => info.fullName)
41-
throw new Error(`Unable to publish packages due to possible circular dependencies: ${remainingNames.join(', ')}`)
41+
throw new Error(
42+
`Unable to publish packages due to possible circular dependencies: ${remainingNames.join(', ')}`,
43+
)
4244
}
4345
}
4446

@@ -54,7 +56,8 @@ export class Publisher {
5456
if (registry) {
5557
unpublishArgs.push('--registry', registry)
5658
}
57-
return this.util.spawn('yarn', unpublishArgs)
59+
// yarn does not have an 'unpublish' command
60+
return this.util.spawn('npm', unpublishArgs)
5861
}),
5962
)
6063
}
@@ -88,7 +91,8 @@ export class Publisher {
8891

8992
private findClearedPackages(state: PublishState): PackageInfo[] {
9093
return state.remaining.filter(
91-
(info) => !info.projectDependencies.length || info.projectDependencies.every((dep) => state.published.has(dep)),
94+
(info) =>
95+
!info.projectDependencies.length || info.projectDependencies.every((dep) => state.published.has(dep)),
9296
)
9397
}
9498

builder/src/ts-config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export interface TsConfigCompilerOptions {
22
composite?: boolean
33
baseUrl?: string
4-
paths: { [path: string]: string[] }
4+
paths?: { [path: string]: string[] }
5+
declarationDir?: string
6+
rootDir?: string
57
outDir?: string
8+
sourceRoot?: string
69
}
710

811
export interface TsConfigProjectReference {

0 commit comments

Comments
 (0)