@langri-sha/projen-project 0.8.1 → 0.10.0

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.
@@ -0,0 +1,50 @@
1
+ import * as fs from 'node:fs'
2
+ import { Project, javascript } from 'projen'
3
+
4
+ /**
5
+ * Options for configuring Node.js packages.
6
+ */
7
+ export interface NodePackageOptions extends javascript.NodePackageOptions {
8
+ peerDependenciesMeta?: Record<string, { optional?: boolean }>
9
+ type?: 'commonjs' | 'module'
10
+ }
11
+
12
+ /**
13
+ * Custom Node.js package manager that preserves package.
14
+ */
15
+ export class NodePackage extends javascript.NodePackage {
16
+ constructor(project: Project, options?: NodePackageOptions) {
17
+ super(project, options)
18
+
19
+ this.addVersion(this.#getPackageJson()?.version ?? '0.0.0')
20
+
21
+ if (options?.type) {
22
+ this.addField('type', options.type)
23
+ }
24
+
25
+ if (options?.peerDependenciesMeta) {
26
+ this.addField('peerDependenciesMeta', options.peerDependenciesMeta)
27
+ }
28
+
29
+ // Reset, so we can run `pnpx projen` on CI after Renovate upgrades.
30
+ this.project.tasks
31
+ .tryFind('install:ci')
32
+ ?.reset(this.project.tasks.tryFind('install')?.steps[0]?.exec)
33
+ }
34
+
35
+ #getPackageJson() {
36
+ try {
37
+ return JSON.parse(fs.readFileSync(this.file.absolutePath, 'utf-8'))
38
+ } catch (_) {
39
+ return undefined
40
+ }
41
+ }
42
+
43
+ override postSynthesize(): void {
44
+ if (this.project.parent) {
45
+ return
46
+ }
47
+
48
+ super.postSynthesize()
49
+ }
50
+ }
@@ -17,7 +17,14 @@ export class ProjenrcFile extends BaseProjenrcFile {
17
17
  ) {
18
18
  super(project)
19
19
 
20
+ if (project.parent) {
21
+ this.filePath = ProjenrcFile.of(project.parent)?.filePath ?? filename
22
+
23
+ return
24
+ }
25
+
20
26
  this.filePath = filename
27
+
21
28
  this.project.defaultTask?.exec(
22
29
  `node --loader ts-node/esm/transpile-only ${filename}`,
23
30
  )