@alma-cdk/construct-library 0.0.13 → 0.0.15

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.
@@ -2,12 +2,239 @@
2
2
  * Fetches the pnpm-workspace JSON schema from SchemaStore and generates a .d.ts file.
3
3
  * Run via: pnpm exec ts-node scripts/generate-pnpm-workspace-types.ts
4
4
  */
5
- import { writeFileSync } from "fs";
6
- import { compile } from "json-schema-to-typescript";
7
- import { join } from "path";
5
+ import { writeFileSync } from 'fs';
6
+ import { compile } from 'json-schema-to-typescript';
7
+ import { join } from 'path';
8
8
 
9
- const SCHEMA_URL = "https://json.schemastore.org/pnpm-workspace.json";
10
- const OUTPUT_FILE = "AlmaCdkConstructLibrary/pnpm-workspace-schema.d.ts";
9
+ const SCHEMA_URL = 'https://json.schemastore.org/pnpm-workspace.json';
10
+ const OUTPUT_FILE = 'src/pnpm-workspace-schema.d.ts';
11
+
12
+ function addReadonlyToFields(typeDefinitions: string): string {
13
+ return typeDefinitions
14
+ .split('\n')
15
+ .map((line) =>
16
+ line
17
+ .replace(/^(\s+)(?!readonly\b)(\[[^\]]+\]:)/, '$1readonly $2')
18
+ .replace(
19
+ /^(\s+)(?!readonly\b)((?:["'][^"']+["']|[A-Za-z_$][\w$]*)\??:)/,
20
+ '$1readonly $2',
21
+ ),
22
+ )
23
+ .join('\n');
24
+ }
25
+
26
+ function makeJsiiCompatible(typeDefinitions: string): string {
27
+ return typeDefinitions
28
+ .replace(
29
+ ` readonly catalogs?: {
30
+ readonly [k: string]: Catalog;
31
+ } | null;`,
32
+ ' readonly catalogs?: Record<string, Catalog>;',
33
+ )
34
+ .replace(' readonly overrides?: {};', ' readonly overrides?: Record<string, string>;')
35
+ .replace(
36
+ ` readonly packageExtensions?: {
37
+ /**
38
+ * This interface was referenced by \`undefined\`'s JSON-Schema definition
39
+ * via the \`patternProperty\` "^.+$".
40
+ */
41
+ readonly [k: string]: {
42
+ readonly dependencies?: Dependency1;
43
+ readonly optionalDependencies?: OptionalDependency;
44
+ readonly peerDependencies?: PeerDependency;
45
+ readonly peerDependenciesMeta?: PeerDependencyMeta;
46
+ };
47
+ };`,
48
+ ' readonly packageExtensions?: Record<string, PackageExtension>;',
49
+ )
50
+ .replace(
51
+ ` readonly peerDependencyRules?: {
52
+ /**
53
+ * pnpm will not print warnings about missing peer dependencies from this list.
54
+ */
55
+ readonly ignoreMissing?: string[];
56
+ /**
57
+ * Unmet peer dependency warnings will not be printed for peer dependencies of the specified range.
58
+ */
59
+ readonly allowedVersions?: {};
60
+ /**
61
+ * Any peer dependency matching the pattern will be resolved from any version, regardless of the range specified in "peerDependencies".
62
+ */
63
+ readonly allowAny?: string[];
64
+ };`,
65
+ ' readonly peerDependencyRules?: PeerDependencyRules;',
66
+ )
67
+ .replace(
68
+ ` readonly allowedDeprecatedVersions?: {
69
+ readonly [k: string]: string;
70
+ };`,
71
+ ' readonly allowedDeprecatedVersions?: Record<string, string>;',
72
+ )
73
+ .replace(
74
+ ` readonly patchedDependencies?: {
75
+ readonly [k: string]: string;
76
+ };`,
77
+ ' readonly patchedDependencies?: Record<string, string>;',
78
+ )
79
+ .replace(
80
+ ` readonly updateConfig?: {
81
+ /**
82
+ * A list of packages that should be ignored when running "pnpm outdated" or "pnpm update --latest".
83
+ */
84
+ readonly ignoreDependencies?: string[];
85
+ };`,
86
+ ' readonly updateConfig?: UpdateConfig;',
87
+ )
88
+ .replace(
89
+ ' readonly configDependencies?: {};',
90
+ ' readonly configDependencies?: Record<string, string>;',
91
+ )
92
+ .replace(
93
+ ` readonly auditConfig?: {
94
+ /**
95
+ * A list of CVE IDs that will be ignored by "pnpm audit".
96
+ */
97
+ readonly ignoreCves?: string[];
98
+ /**
99
+ * A list of GHSA Codes that will be ignored by "pnpm audit".
100
+ */
101
+ readonly ignoreGhsas?: string[];
102
+ };`,
103
+ ' readonly auditConfig?: AuditConfig;',
104
+ )
105
+ .replace(
106
+ ` readonly supportedArchitectures?: {
107
+ readonly os?: string[];
108
+ readonly cpu?: string[];
109
+ readonly libc?: string[];
110
+ };`,
111
+ ' readonly supportedArchitectures?: SupportedArchitectures;',
112
+ )
113
+ .replace(
114
+ ` readonly executionEnv?: {
115
+ /**
116
+ * Specifies which exact Node.js version should be used for the project's runtime.
117
+ */
118
+ readonly nodeVersion?: string;
119
+ };`,
120
+ ' readonly executionEnv?: ExecutionEnv;',
121
+ )
122
+ .replace(
123
+ ' readonly mergeGitBranchLockfilesBranchPattern?: unknown[] | null;',
124
+ ' readonly mergeGitBranchLockfilesBranchPattern?: string[];',
125
+ )
126
+ .replace(
127
+ ' readonly allowBuilds?: {};',
128
+ ' readonly allowBuilds?: Record<string, boolean>;',
129
+ )
130
+ .replace(
131
+ `export type Dependency = {
132
+ readonly [k: string]: string;
133
+ } | null;`,
134
+ 'export type Dependency = Record<string, string>;',
135
+ )
136
+ .replace(
137
+ `/**
138
+ * Define dependency version ranges as reusable constants,
139
+ * for later reference in package.json files.
140
+ * This (singular) field creates a catalog named default.
141
+ *
142
+ */
143
+ export interface Catalog {
144
+ readonly [k: string]: string;
145
+ }
146
+ /**
147
+ * Dependencies are specified with a simple hash of package name to version range.
148
+ * The version range is a string which has one or more space-separated descriptors.
149
+ * Dependencies can also be identified with a tarball or git URL.
150
+ *
151
+ */
152
+ export interface Dependency1 {
153
+ readonly [k: string]: string;
154
+ }
155
+ /**
156
+ * Specifies dependencies that are optional for your project. These dependencies are attempted to be installed during the npm install process, but if they fail to install, the installation process will not fail.
157
+ */
158
+ export interface OptionalDependency {
159
+ readonly [k: string]: string;
160
+ }
161
+ /**
162
+ * Specifies dependencies that are required by the package but are expected to be provided by the consumer of the package.
163
+ */
164
+ export interface PeerDependency {
165
+ readonly [k: string]: string;
166
+ }
167
+ /**
168
+ * When a user installs your package, warnings are emitted if packages specified in "peerDependencies" are not already installed. The "peerDependenciesMeta" field serves to provide more information on how your peer dependencies are utilized. Most commonly, it allows peer dependencies to be marked as optional. Metadata for this field is specified with a simple hash of the package name to a metadata object.
169
+ */
170
+ export interface PeerDependencyMeta {
171
+ readonly [k: string]: {
172
+ /**
173
+ * Specifies that this peer dependency is optional and should not be installed automatically.
174
+ */
175
+ readonly optional?: boolean;
176
+ readonly [k: string]: unknown;
177
+ };
178
+ }
179
+ `,
180
+ `/**
181
+ * Define dependency version ranges as reusable constants,
182
+ * for later reference in package.json files.
183
+ * This (singular) field creates a catalog named default.
184
+ *
185
+ */
186
+ export type Catalog = Record<string, string>;
187
+ /**
188
+ * Dependencies are specified with a simple hash of package name to version range.
189
+ * The version range is a string which has one or more space-separated descriptors.
190
+ * Dependencies can also be identified with a tarball or git URL.
191
+ *
192
+ */
193
+ export type Dependency1 = Record<string, string>;
194
+ /**
195
+ * Specifies dependencies that are optional for your project. These dependencies are attempted to be installed during the npm install process, but if they fail to install, the installation process will not fail.
196
+ */
197
+ export type OptionalDependency = Record<string, string>;
198
+ /**
199
+ * Specifies dependencies that are required by the package but are expected to be provided by the consumer of the package.
200
+ */
201
+ export type PeerDependency = Record<string, string>;
202
+ export interface PackageExtension {
203
+ readonly dependencies?: Dependency1;
204
+ readonly optionalDependencies?: OptionalDependency;
205
+ readonly peerDependencies?: PeerDependency;
206
+ readonly peerDependenciesMeta?: PeerDependencyMeta;
207
+ }
208
+ export interface PeerDependencyRules {
209
+ readonly ignoreMissing?: string[];
210
+ readonly allowedVersions?: Record<string, string>;
211
+ readonly allowAny?: string[];
212
+ }
213
+ export interface UpdateConfig {
214
+ readonly ignoreDependencies?: string[];
215
+ }
216
+ export interface AuditConfig {
217
+ readonly ignoreCves?: string[];
218
+ readonly ignoreGhsas?: string[];
219
+ }
220
+ export interface SupportedArchitectures {
221
+ readonly os?: string[];
222
+ readonly cpu?: string[];
223
+ readonly libc?: string[];
224
+ }
225
+ export interface ExecutionEnv {
226
+ readonly nodeVersion?: string;
227
+ }
228
+ export interface PeerDependencyMetaValue {
229
+ readonly optional?: boolean;
230
+ }
231
+ /**
232
+ * When a user installs your package, warnings are emitted if packages specified in "peerDependencies" are not already installed. The "peerDependenciesMeta" field serves to provide more information on how your peer dependencies are utilized. Most commonly, it allows peer dependencies to be marked as optional. Metadata for this field is specified with a simple hash of the package name to a metadata object.
233
+ */
234
+ export type PeerDependencyMeta = Record<string, PeerDependencyMetaValue>;
235
+ `,
236
+ );
237
+ }
11
238
 
12
239
  async function main(): Promise<void> {
13
240
  const res = await fetch(SCHEMA_URL);
@@ -15,15 +242,17 @@ async function main(): Promise<void> {
15
242
  throw new Error(`Failed to fetch schema: ${res.status} ${res.statusText}`);
16
243
  }
17
244
  const schema = (await res.json()) as object;
18
- const ts = await compile(schema, "PnpmWorkspace", {
245
+ const ts = await compile(schema, 'PnpmWorkspaceSpecification', {
19
246
  bannerComment: `/**
20
247
  * TypeScript definitions for pnpm-workspace.yaml (JSON Schema from ${SCHEMA_URL})
21
248
  * DO NOT EDIT BY HAND. Run \`pnpm run generate:pnpm-workspace-types\` to regenerate.
22
249
  */`,
23
250
  additionalProperties: false,
24
251
  });
252
+ const readonlyTs = addReadonlyToFields(ts);
253
+ const jsiiCompatibleTs = makeJsiiCompatible(readonlyTs);
25
254
  const outPath = join(process.cwd(), OUTPUT_FILE);
26
- writeFileSync(outPath, ts, "utf8");
255
+ writeFileSync(outPath, jsiiCompatibleTs, 'utf8');
27
256
  console.log(`Wrote ${outPath}`);
28
257
  }
29
258