@langri-sha/projen-pnpm-workspace 0.1.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.
package/CHANGELOG.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@langri-sha/projen-pnpm-workspace",
3
+ "entries": [
4
+ {
5
+ "date": "Sat, 15 Jun 2024 09:06:45 GMT",
6
+ "version": "0.1.0",
7
+ "tag": "@langri-sha/projen-pnpm-workspace_v0.1.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "email not defined",
12
+ "package": "@langri-sha/projen-pnpm-workspace",
13
+ "commit": "7ac78ea2d172ae9e30f23d213752297fb8436a88",
14
+ "comment": "chore(deps): fix(deps): update dependency yaml to v2.4.4"
15
+ },
16
+ {
17
+ "author": "email not defined",
18
+ "package": "@langri-sha/projen-pnpm-workspace",
19
+ "commit": "7ac78ea2d172ae9e30f23d213752297fb8436a88",
20
+ "comment": "chore(deps): fix(deps): update dependency yaml to v2.4.5"
21
+ }
22
+ ],
23
+ "minor": [
24
+ {
25
+ "author": "filip.dupanovic@gmail.com",
26
+ "package": "@langri-sha/projen-pnpm-workspace",
27
+ "commit": "7ac78ea2d172ae9e30f23d213752297fb8436a88",
28
+ "comment": "feat(pnpm-workspace): Atomatically add packages"
29
+ },
30
+ {
31
+ "author": "filip.dupanovic@gmail.com",
32
+ "package": "@langri-sha/projen-pnpm-workspace",
33
+ "commit": "7ac78ea2d172ae9e30f23d213752297fb8436a88",
34
+ "comment": "feat(pnpm-workspace): Add support for PNPM workspaces"
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ ]
40
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Change Log - @langri-sha/projen-pnpm-workspace
2
+
3
+ This log was last generated on Sat, 15 Jun 2024 09:06:45 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.1.0
8
+
9
+ Sat, 15 Jun 2024 09:06:45 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - feat(pnpm-workspace): Atomatically add packages (filip.dupanovic@gmail.com)
14
+ - feat(pnpm-workspace): Add support for PNPM workspaces (filip.dupanovic@gmail.com)
15
+
16
+ ### Patches
17
+
18
+ - chore(deps): fix(deps): update dependency yaml to v2.4.4 (email not defined)
19
+ - chore(deps): fix(deps): update dependency yaml to v2.4.5 (email not defined)
package/lib/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { type IResolver, Project, YamlFile } from 'projen';
2
+ /**
3
+ * Options for maintaining a PNPM workspace.
4
+ */
5
+ export interface PnpmWorkspaceOptions {
6
+ /**
7
+ * Name of the workspace configuration file.
8
+ *
9
+ * @default 'pnpm-workspace.yaml'
10
+ */
11
+ filename?: string;
12
+ /**
13
+ * List of package paths.
14
+ */
15
+ packages?: string[];
16
+ }
17
+ export declare class PnpmWorkspace extends YamlFile {
18
+ constructor(project: Project, options?: PnpmWorkspaceOptions);
19
+ preSynthesize(): void;
20
+ protected synthesizeContent(resolver: IResolver): string | undefined;
21
+ addPackages(...packages: string[]): void;
22
+ }
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAc,MAAM,QAAQ,CAAA;AAItE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,oBAAyB;IAYvD,aAAa,IAAI,IAAI;cA4BX,iBAAiB,CAClC,QAAQ,EAAE,SAAS,GAClB,MAAM,GAAG,SAAS;IAsBrB,WAAW,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE;CAKlC"}
package/lib/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import { YamlFile, javascript } from 'projen';
2
+ import YAML from 'yaml';
3
+ import * as path from 'node:path';
4
+ export class PnpmWorkspace extends YamlFile {
5
+ constructor(project, options = {}) {
6
+ const filename = options.filename ?? 'pnpm-workspace.yaml';
7
+ super(project, filename, {
8
+ readonly: true,
9
+ marker: true,
10
+ obj: {
11
+ packages: [...(options.packages ?? [])],
12
+ },
13
+ });
14
+ }
15
+ preSynthesize() {
16
+ const packages = this.project.subprojects
17
+ .map((project) => project.node
18
+ .findAll(1)
19
+ .filter((file) => file instanceof javascript.NodePackage))
20
+ .flat()
21
+ .map((pkg) => path.relative(this.project.outdir, path.dirname(pkg.file.absolutePath)));
22
+ for (const pkg of packages) {
23
+ if (packages
24
+ .filter((other) => other !== pkg)
25
+ .some((other) => path.dirname(other) === path.dirname(pkg))) {
26
+ this.addPackages(path.join(path.dirname(pkg), '*'));
27
+ }
28
+ else {
29
+ this.addPackages(pkg);
30
+ }
31
+ }
32
+ }
33
+ synthesizeContent(resolver) {
34
+ const yaml = super.synthesizeContent(resolver);
35
+ if (!yaml) {
36
+ return;
37
+ }
38
+ const parsed = YAML.parse(yaml);
39
+ parsed.packages = [...new Set(parsed.packages)];
40
+ parsed.packages.sort();
41
+ return [
42
+ ...(this.marker ? [`# ${this.marker}`, ''] : []),
43
+ YAML.stringify(parsed, {
44
+ indent: 2,
45
+ lineWidth: this.lineWidth,
46
+ }),
47
+ ].join('\n');
48
+ }
49
+ addPackages(...packages) {
50
+ for (const pkg of packages) {
51
+ this.addToArray('packages', pkg);
52
+ }
53
+ }
54
+ }
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,QAAQ,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACtE,OAAO,IAAI,MAAM,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,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;YACrD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAEkB,iBAAiB,CAClC,QAAmB;QAEnB,MAAM,IAAI,GAAG,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAA;QAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAM;QACR,CAAC;QAED,MAAM,MAAM,GACV,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAElB,MAAM,CAAC,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC/C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;QAEtB,OAAO;YACL,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;gBACrB,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B,CAAC;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACd,CAAC;IAED,WAAW,CAAC,GAAG,QAAkB;QAC/B,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;CACF"}
package/license ADDED
@@ -0,0 +1,10 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2024 Filip Dupanović <filip.dupanovic@gmail.com> (https://langri-sha.com)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@langri-sha/projen-pnpm-workspace",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "Filip Dupanović",
7
+ "email": "filip.dupanovic@gmail.com",
8
+ "url": "https://langri-sha.com",
9
+ "organization": false
10
+ },
11
+ "type": "module",
12
+ "main": "lib/index.js",
13
+ "scripts": {
14
+ "prepublishOnly": "rm -rf lib; tsc --project tsconfig.build.json"
15
+ },
16
+ "dependencies": {
17
+ "yaml": "2.4.5"
18
+ },
19
+ "devDependencies": {
20
+ "@langri-sha/jest-test": "0.8.0",
21
+ "@langri-sha/tsconfig": "*"
22
+ },
23
+ "peerDependencies": {
24
+ "projen": "^0.82.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "//": "~~ Generated by projen. To modify, edit .projenrc.mts and run \"npx projen\".",
30
+ "types": "lib/index.d.ts"
31
+ }
package/readme ADDED
@@ -0,0 +1 @@
1
+ # @langri-sha/projen-pnpm-workspace
package/src/index.ts ADDED
@@ -0,0 +1,92 @@
1
+ import { type IResolver, Project, YamlFile, javascript } from 'projen'
2
+ import YAML from 'yaml'
3
+ import * as path from 'node:path'
4
+
5
+ /**
6
+ * Options for maintaining a PNPM workspace.
7
+ */
8
+ export interface PnpmWorkspaceOptions {
9
+ /**
10
+ * Name of the workspace configuration file.
11
+ *
12
+ * @default 'pnpm-workspace.yaml'
13
+ */
14
+ filename?: string
15
+
16
+ /**
17
+ * List of package paths.
18
+ */
19
+ packages?: string[]
20
+ }
21
+
22
+ export class PnpmWorkspace extends YamlFile {
23
+ constructor(project: Project, options: PnpmWorkspaceOptions = {}) {
24
+ const filename = options.filename ?? 'pnpm-workspace.yaml'
25
+
26
+ super(project, filename, {
27
+ readonly: true,
28
+ marker: true,
29
+ obj: {
30
+ packages: [...(options.packages ?? [])],
31
+ },
32
+ })
33
+ }
34
+
35
+ override preSynthesize(): void {
36
+ const packages = this.project.subprojects
37
+ .map((project) =>
38
+ project.node
39
+ .findAll(1)
40
+ .filter(
41
+ (file): file is javascript.NodePackage =>
42
+ file instanceof javascript.NodePackage,
43
+ ),
44
+ )
45
+ .flat()
46
+ .map((pkg) =>
47
+ path.relative(this.project.outdir, path.dirname(pkg.file.absolutePath)),
48
+ )
49
+
50
+ for (const pkg of packages) {
51
+ if (
52
+ packages
53
+ .filter((other) => other !== pkg)
54
+ .some((other) => path.dirname(other) === path.dirname(pkg))
55
+ ) {
56
+ this.addPackages(path.join(path.dirname(pkg), '*'))
57
+ } else {
58
+ this.addPackages(pkg)
59
+ }
60
+ }
61
+ }
62
+
63
+ protected override synthesizeContent(
64
+ resolver: IResolver,
65
+ ): string | undefined {
66
+ const yaml = super.synthesizeContent(resolver)
67
+
68
+ if (!yaml) {
69
+ return
70
+ }
71
+
72
+ const parsed: Required<Exclude<PnpmWorkspaceOptions, 'filename'>> =
73
+ YAML.parse(yaml)
74
+
75
+ parsed.packages = [...new Set(parsed.packages)]
76
+ parsed.packages.sort()
77
+
78
+ return [
79
+ ...(this.marker ? [`# ${this.marker}`, ''] : []),
80
+ YAML.stringify(parsed, {
81
+ indent: 2,
82
+ lineWidth: this.lineWidth,
83
+ }),
84
+ ].join('\n')
85
+ }
86
+
87
+ addPackages(...packages: string[]) {
88
+ for (const pkg of packages) {
89
+ this.addToArray('packages', pkg)
90
+ }
91
+ }
92
+ }