@tsplc/config 0.2.17 → 0.2.18

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.
@@ -1,245 +1,268 @@
1
1
  import { z } from "zod";
2
+ import { nanosecondsPattern } from "./compiler.ts";
2
3
 
3
4
  export const commandArgumentSchema = z
4
- .string()
5
- .refine((value) => value.trim().length > 0, "Command arguments must not be empty")
6
- .refine(
7
- (value) => !/["\r\n\0]/.test(value),
8
- "Command arguments must not contain quotes, line breaks, or null bytes",
9
- );
5
+ .string()
6
+ .refine(
7
+ (value) => value.trim().length > 0,
8
+ "Command arguments must not be empty",
9
+ )
10
+ .refine(
11
+ (value) => !/["\r\n\0]/.test(value),
12
+ "Command arguments must not contain quotes, line breaks, or null bytes",
13
+ );
10
14
  // CODESYS startup and project loading can each take several minutes.
11
15
  export const codesysTimeouts = {
12
- build: 20 * 60 * 1000,
13
- hostCommand: 15_000,
14
- runtime: 60_000,
15
- startup: 20 * 60 * 1000,
16
- stop: 10_000,
17
- terminate: 5000,
16
+ build: 20 * 60 * 1000,
17
+ hostCommand: 15_000,
18
+ runtime: 60_000,
19
+ startup: 20 * 60 * 1000,
20
+ stop: 10_000,
21
+ terminate: 5000,
18
22
  };
19
23
 
20
24
  const positiveMilliseconds = z.number().int().positive();
21
25
  const pathSchema = z.string().trim().nonempty();
26
+ export const tcpPort = z.number().int().min(1).max(65535);
27
+ /** A SHA-256 digest as lowercase hex, the form `node:crypto` writes. */
28
+ export const sha256Digest = z.string().regex(/^[a-f0-9]{64}$/);
29
+ /** The name of an environment variable a credential is read from, so the config never holds it. */
30
+ export const envName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
22
31
  const wineSchema = z.strictObject({
23
- prefix: pathSchema,
24
- binary: pathSchema.default("wine"),
25
- pathBinary: pathSchema.default("winepath"),
26
- debug: z.string().default("-all"),
27
- nativeExit: z.boolean().default(false),
32
+ prefix: pathSchema,
33
+ binary: pathSchema.default("wine"),
34
+ pathBinary: pathSchema.default("winepath"),
35
+ debug: z.string().default("-all"),
36
+ nativeExit: z.boolean().default(false),
28
37
  });
29
38
  export const localCodesysSchema = z.strictObject({
30
- executable: commandArgumentSchema,
31
- profile: commandArgumentSchema,
32
- wine: wineSchema.optional(),
33
- commandProcessor: pathSchema.default("cmd.exe"),
39
+ executable: commandArgumentSchema,
40
+ profile: commandArgumentSchema,
41
+ wine: wineSchema.optional(),
42
+ commandProcessor: pathSchema.default("cmd.exe"),
34
43
  });
35
44
 
36
45
  // `tsplc configure` builds this tag; every project compiles with it.
37
46
  export const dockerImage = "tsplc-build:latest";
38
47
  export const containerCodesys = {
39
- executable: "/tmp/codesys-wine/drive_c/CODESYS-3.5.22.30/CODESYS/Common/CODESYS.exe",
40
- profile: "CODESYS V3.5 SP22 Patch 3",
41
- wine: { prefix: "/tmp/codesys-wine", nativeExit: true },
48
+ executable:
49
+ "/tmp/codesys-wine/drive_c/CODESYS-3.5.22.30/CODESYS/Common/CODESYS.exe",
50
+ profile: "CODESYS V3.5 SP22 Patch 3",
51
+ wine: { prefix: "/tmp/codesys-wine", nativeExit: true },
42
52
  };
43
- const iecName = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
53
+ export const iecName = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/);
54
+ export const taskPriority = z.number().int().min(0).max(31);
44
55
  export const cyclicTasksSchema = z
45
- .array(
46
- z.strictObject({
47
- name: iecName,
48
- intervalNanoseconds: z
49
- .string()
50
- .regex(/^[1-9][0-9]*$/)
51
- .refine((value) => {
52
- if (!/^[1-9][0-9]*$/.test(value)) {
53
- return false;
54
- }
55
- const ns = BigInt(value);
56
- return ns % 1_000_000n === 0n && ns <= 4_294_967_295_000_000n;
57
- }, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
58
- priority: z.number().int().min(0).max(31),
59
- programs: z.array(iecName).nonempty(),
60
- }),
61
- )
62
- .nonempty()
63
- .superRefine((tasks, context) => {
64
- const names = new Set<string>(),
65
- programs = new Set<string>();
66
- tasks.forEach((task, index) => {
67
- if (names.has(task.name.toLowerCase())) {
68
- context.addIssue({
69
- code: "custom",
70
- path: [index, "name"],
71
- message: "Task names must be unique",
72
- });
73
- }
74
- names.add(task.name.toLowerCase());
75
- task.programs.forEach((program, position) => {
76
- if (programs.has(program.toLowerCase())) {
77
- context.addIssue({
78
- code: "custom",
79
- path: [index, "programs", position],
80
- message: "A program can be scheduled only once",
81
- });
82
- }
83
- programs.add(program.toLowerCase());
84
- });
85
- });
86
- });
56
+ .array(
57
+ z.strictObject({
58
+ name: iecName,
59
+ intervalNanoseconds: z
60
+ .string()
61
+ .regex(nanosecondsPattern)
62
+ .refine((value) => {
63
+ // zod runs this refinement even when the pattern fails, and BigInt throws on a non-integer.
64
+ if (!nanosecondsPattern.test(value)) {
65
+ return false;
66
+ }
67
+ const ns = BigInt(value);
68
+ return ns % 1_000_000n === 0n && ns <= 4_294_967_295_000_000n;
69
+ }, "Cyclic tasks require an exact positive TIME interval in milliseconds"),
70
+ priority: taskPriority,
71
+ programs: z.array(iecName).nonempty(),
72
+ }),
73
+ )
74
+ .nonempty()
75
+ .superRefine((tasks, context) => {
76
+ const names = new Set<string>();
77
+ const programs = new Set<string>();
78
+ tasks.forEach((task, index) => {
79
+ if (names.has(task.name.toLowerCase())) {
80
+ context.addIssue({
81
+ code: "custom",
82
+ path: [index, "name"],
83
+ message: "Task names must be unique",
84
+ });
85
+ }
86
+ names.add(task.name.toLowerCase());
87
+ task.programs.forEach((program, position) => {
88
+ if (programs.has(program.toLowerCase())) {
89
+ context.addIssue({
90
+ code: "custom",
91
+ path: [index, "programs", position],
92
+ message: "A program can be scheduled only once",
93
+ });
94
+ }
95
+ programs.add(program.toLowerCase());
96
+ });
97
+ });
98
+ });
87
99
  export type CyclicTask = z.infer<typeof cyclicTasksSchema>[number];
88
100
  /** `inverted` reads a BOOL input as its opposite; `shared` lets several bindings read one input. */
89
101
  export const ioBindingOptions = {
90
- inverted: z.boolean().optional(),
91
- shared: z.boolean().optional(),
102
+ inverted: z.boolean().optional(),
103
+ shared: z.boolean().optional(),
92
104
  };
93
105
  /** A process-image address in CODESYS byte addressing, with an optional IEC type. */
94
106
  export const directIoBindingSchema = z.strictObject({
95
- address: z.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
96
- type: z.string().optional(),
97
- ...ioBindingOptions,
107
+ address: z.string().regex(/^%[IQ](?:X\d+\.[0-7]|[BWD]\d+)$/),
108
+ type: z.string().optional(),
109
+ ...ioBindingOptions,
98
110
  });
99
111
  /** The controller's Ethernet interface; omitted settings keep the CODESYS defaults. */
100
112
  export const ethernetSchema = z.strictObject({
101
- interface: z.string().nonempty().optional(),
102
- address: z.ipv4().optional(),
103
- subnet: z.ipv4().optional(),
104
- gateway: z.ipv4().optional(),
113
+ interface: z.string().nonempty().optional(),
114
+ address: z.ipv4().optional(),
115
+ subnet: z.ipv4().optional(),
116
+ gateway: z.ipv4().optional(),
105
117
  });
118
+ /** The byte where a device's input or output assembly starts in the process image. */
119
+ export const assemblyAddress = z.string().regex(/^%[IQ]B\d+$/);
106
120
  const processImageSchema = z.strictObject({
107
- address: z.string().regex(/^%[IQ]B\d+$/),
108
- size: z.number().int().positive(),
121
+ address: assemblyAddress,
122
+ size: z.number().int().positive(),
109
123
  });
124
+ /** A bit or byte channel of a generated device tree. */
125
+ const channelAddress = z.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/);
110
126
  /**
111
127
  * An EtherNet/IP scanner tree generated from EDS files. Each adapter's EDS is
112
128
  * already reduced to its selected connection and raw byte assemblies, so every
113
129
  * payload byte becomes one channel pinned at its region's address plus offset.
114
130
  */
115
131
  export const deviceTreeSchema = z.strictObject({
116
- ethernet: ethernetSchema.default({}),
117
- devices: z
118
- .array(
119
- z.strictObject({
120
- name: iecName,
121
- eds: z.string().nonempty(),
122
- address: z.ipv4().optional(),
123
- rpiMicroseconds: z.number().int().positive().optional(),
124
- inputs: processImageSchema.optional(),
125
- outputs: processImageSchema.optional(),
126
- // Registers written over Modbus TCP at the adapter's address, with their pinned channels.
127
- modbus: z
128
- .strictObject({
129
- port: z.number().int().positive(),
130
- registers: z.array(
131
- z.strictObject({
132
- name: iecName,
133
- offset: z.number().int().nonnegative(),
134
- value: z.string().regex(/^%QW\d+$/),
135
- write: z.string().regex(/^%QX\d+\.[0-7]$/),
136
- status: z.string().regex(/^%IB\d+$/),
137
- requests: z.string().regex(/^%ID\d+$/),
138
- }),
139
- ),
140
- })
141
- .optional(),
142
- // Channel comments name the logical IO bound at a pinned byte or bit.
143
- comments: z
144
- .array(
145
- z.strictObject({
146
- address: z.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/),
147
- text: z.string().nonempty(),
148
- }),
149
- )
150
- .default([]),
151
- }),
152
- )
153
- .nonempty(),
154
- // Variables mapped to pinned bit or byte channels, relative to the application.
155
- mappings: z
156
- .array(
157
- z.strictObject({
158
- address: z.string().regex(/^%[IQ](?:X\d+\.[0-7]|B\d+)$/),
159
- variable: z.string().nonempty(),
160
- }),
161
- )
162
- .default([]),
132
+ ethernet: ethernetSchema.default({}),
133
+ devices: z
134
+ .array(
135
+ z.strictObject({
136
+ name: iecName,
137
+ eds: z.string().nonempty(),
138
+ address: z.ipv4().optional(),
139
+ rpiMicroseconds: z.number().int().positive().optional(),
140
+ inputs: processImageSchema.optional(),
141
+ outputs: processImageSchema.optional(),
142
+ // Registers written over Modbus TCP at the adapter's address, with their pinned channels.
143
+ modbus: z
144
+ .strictObject({
145
+ port: tcpPort,
146
+ registers: z.array(
147
+ z.strictObject({
148
+ name: iecName,
149
+ offset: z.number().int().nonnegative(),
150
+ value: z.string().regex(/^%QW\d+$/),
151
+ write: z.string().regex(/^%QX\d+\.[0-7]$/),
152
+ status: z.string().regex(/^%IB\d+$/),
153
+ requests: z.string().regex(/^%ID\d+$/),
154
+ }),
155
+ ),
156
+ })
157
+ .optional(),
158
+ // Channel comments name the logical IO bound at a pinned byte or bit.
159
+ comments: z
160
+ .array(
161
+ z.strictObject({
162
+ address: channelAddress,
163
+ text: z.string().nonempty(),
164
+ }),
165
+ )
166
+ .default([]),
167
+ }),
168
+ )
169
+ .nonempty(),
170
+ // Variables mapped to pinned bit or byte channels, relative to the application.
171
+ mappings: z
172
+ .array(
173
+ z.strictObject({
174
+ address: channelAddress,
175
+ variable: z.string().nonempty(),
176
+ }),
177
+ )
178
+ .default([]),
163
179
  });
164
180
  export type DeviceTree = z.input<typeof deviceTreeSchema>;
181
+ /** A device or library version as CODESYS repositories spell it: four numbers. */
182
+ export const fourPartVersion = z.string().regex(/^\d+\.\d+\.\d+\.\d+$/);
165
183
  /** A controller's device repository identity, as CODESYS shows it under Device > Information. */
166
184
  export const controllerSchema = z.strictObject({
167
- type: z.number().int().positive(),
168
- id: z.string().regex(/^[0-9A-F]{4} [0-9A-F]{4}$/),
169
- version: z.string().regex(/^\d+\.\d+\.\d+\.\d+$/),
185
+ type: z.number().int().positive(),
186
+ id: z.string().regex(/^[0-9A-F]{4} [0-9A-F]{4}$/),
187
+ version: fourPartVersion,
170
188
  });
171
189
  export type Controller = z.infer<typeof controllerSchema>;
172
190
  /** A controller the build image carries, named instead of spelled as its repository identity. */
173
- export const controllerTargetSchema = controllerSchema.pick({ version: true }).extend({
174
- target: z.enum(["linux-sl", "virtual-linux-arm64-sl"]),
175
- });
191
+ export const controllerTargetSchema = controllerSchema
192
+ .pick({ version: true })
193
+ .extend({
194
+ target: z.enum(["linux-sl", "virtual-linux-arm64-sl"]),
195
+ });
176
196
  export const controllerDevices = {
177
- "linux-sl": { type: 4102, id: "0000 0005" },
178
- "virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" },
179
- } satisfies Record<z.infer<typeof controllerTargetSchema>["target"], Omit<Controller, "version">>;
197
+ "linux-sl": { type: 4102, id: "0000 0005" },
198
+ "virtual-linux-arm64-sl": { type: 4096, id: "0000 1008" },
199
+ } satisfies Record<
200
+ z.infer<typeof controllerTargetSchema>["target"],
201
+ Omit<Controller, "version">
202
+ >;
180
203
  export const configSchema = z.strictObject({
181
- io: z.record(z.string(), directIoBindingSchema).optional(),
182
- deviceTree: deviceTreeSchema.optional(),
183
- // Replaces the template's controller; the build image must carry its description.
184
- controller: controllerSchema.optional(),
185
- libraryReferences: z.array(z.string().nonempty()).default([]),
186
- libraries: z
187
- .array(
188
- z.strictObject({
189
- title: z.string(),
190
- company: z.string().optional(),
191
- version: z.string().optional(),
192
- namespace: z.string().optional(),
193
- path: pathSchema,
194
- sha256: z.string().regex(/^[a-f0-9]{64}$/),
195
- url: z.string().optional(),
196
- }),
197
- )
198
- .optional(),
199
- docker: z
200
- .strictObject({
201
- cpuSet: z
202
- .string()
203
- .regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/)
204
- .optional(),
205
- })
206
- .optional(),
207
- template: pathSchema.optional(),
208
- sourceDir: pathSchema.default("src"),
209
- entry: pathSchema.default("src/Main.st"),
210
- outDir: pathSchema.default("build"),
211
- task: z.string().nonempty().default("MainTask"),
212
- tasks: cyclicTasksSchema.optional(),
213
- removeObjects: z.array(z.string().nonempty()).default([]),
214
- symbols: z.boolean().default(false),
215
- online: z
216
- .strictObject({
217
- network: pathSchema.default("bridge"),
218
- gateway: z.strictObject({
219
- host: pathSchema,
220
- port: z.number().int().min(1).max(65535).default(1217),
221
- }),
222
- device: z.strictObject({
223
- host: pathSchema,
224
- port: z.number().int().min(1).max(65535).default(11740),
225
- }),
226
- credentials: z
227
- .strictObject({
228
- usernameEnv: z.string().regex(/^[A-Za-z_][A-Za-z_0-9]*$/),
229
- passwordEnv: z.string().regex(/^[A-Za-z_][A-Za-z_0-9]*$/),
230
- })
231
- .optional(),
232
- })
233
- .optional(),
234
- timeouts: z
235
- .strictObject({
236
- startup: positiveMilliseconds.default(codesysTimeouts.startup),
237
- build: positiveMilliseconds.default(codesysTimeouts.build),
238
- stop: positiveMilliseconds.default(codesysTimeouts.stop),
239
- terminate: positiveMilliseconds.default(codesysTimeouts.terminate),
240
- hostCommand: positiveMilliseconds.default(codesysTimeouts.hostCommand),
241
- runtime: positiveMilliseconds.default(codesysTimeouts.runtime),
242
- })
243
- .prefault({}),
204
+ io: z.record(z.string(), directIoBindingSchema).optional(),
205
+ deviceTree: deviceTreeSchema.optional(),
206
+ // Replaces the template's controller; the build image must carry its description.
207
+ controller: controllerSchema.optional(),
208
+ libraryReferences: z.array(z.string().nonempty()).default([]),
209
+ libraries: z
210
+ .array(
211
+ z.strictObject({
212
+ title: z.string(),
213
+ company: z.string().optional(),
214
+ version: z.string().optional(),
215
+ namespace: z.string().optional(),
216
+ path: pathSchema,
217
+ sha256: sha256Digest,
218
+ url: z.string().optional(),
219
+ }),
220
+ )
221
+ .optional(),
222
+ docker: z
223
+ .strictObject({
224
+ cpuSet: z
225
+ .string()
226
+ .regex(/^\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*$/)
227
+ .optional(),
228
+ })
229
+ .optional(),
230
+ template: pathSchema.optional(),
231
+ sourceDir: pathSchema.default("src"),
232
+ entry: pathSchema.default("src/Main.st"),
233
+ outDir: pathSchema.default("build"),
234
+ task: z.string().nonempty().default("MainTask"),
235
+ tasks: cyclicTasksSchema.optional(),
236
+ removeObjects: z.array(z.string().nonempty()).default([]),
237
+ symbols: z.boolean().default(false),
238
+ online: z
239
+ .strictObject({
240
+ network: pathSchema.default("bridge"),
241
+ gateway: z.strictObject({
242
+ host: pathSchema,
243
+ port: tcpPort.default(1217),
244
+ }),
245
+ device: z.strictObject({
246
+ host: pathSchema,
247
+ port: tcpPort.default(11740),
248
+ }),
249
+ credentials: z
250
+ .strictObject({
251
+ usernameEnv: envName,
252
+ passwordEnv: envName,
253
+ })
254
+ .optional(),
255
+ })
256
+ .optional(),
257
+ timeouts: z
258
+ .strictObject({
259
+ startup: positiveMilliseconds.default(codesysTimeouts.startup),
260
+ build: positiveMilliseconds.default(codesysTimeouts.build),
261
+ stop: positiveMilliseconds.default(codesysTimeouts.stop),
262
+ terminate: positiveMilliseconds.default(codesysTimeouts.terminate),
263
+ hostCommand: positiveMilliseconds.default(codesysTimeouts.hostCommand),
264
+ runtime: positiveMilliseconds.default(codesysTimeouts.runtime),
265
+ })
266
+ .prefault({}),
244
267
  });
245
268
  export type CodesysBuildConfig = z.input<typeof configSchema>;
package/src/build.ts CHANGED
@@ -2,79 +2,89 @@ import { dirname, resolve } from "node:path";
2
2
  import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import type { z } from "zod";
4
4
  import {
5
- configSchema,
6
- containerCodesys,
7
- localCodesysSchema,
8
- type CodesysBuildConfig,
5
+ configSchema,
6
+ containerCodesys,
7
+ localCodesysSchema,
8
+ type CodesysBuildConfig,
9
9
  } from "./build-schema.ts";
10
10
  export {
11
- commandArgumentSchema,
12
- codesysTimeouts,
13
- dockerImage,
14
- containerCodesys,
15
- cyclicTasksSchema,
16
- directIoBindingSchema,
17
- ethernetSchema,
18
- deviceTreeSchema,
19
- controllerSchema,
20
- configSchema,
21
- type CyclicTask,
22
- type DeviceTree,
23
- type Controller,
24
- type CodesysBuildConfig,
11
+ commandArgumentSchema,
12
+ codesysTimeouts,
13
+ dockerImage,
14
+ containerCodesys,
15
+ cyclicTasksSchema,
16
+ directIoBindingSchema,
17
+ ethernetSchema,
18
+ deviceTreeSchema,
19
+ controllerSchema,
20
+ configSchema,
21
+ iecName,
22
+ sha256Digest,
23
+ tcpPort,
24
+ type CyclicTask,
25
+ type DeviceTree,
26
+ type Controller,
27
+ type CodesysBuildConfig,
25
28
  } from "./build-schema.ts";
26
29
 
27
30
  export type ResolvedConfig = z.output<typeof configSchema> & {
28
- template: string;
29
- configFile: string;
30
- codesys: z.output<typeof localCodesysSchema>;
31
+ template: string;
32
+ configFile: string;
33
+ codesys: z.output<typeof localCodesysSchema>;
31
34
  };
32
35
 
33
36
  /** Keep config authoring typed; validation and relative path resolution happen at load. */
34
- export const defineBuildConfig = (config: CodesysBuildConfig): CodesysBuildConfig => config;
37
+ export const defineBuildConfig = (
38
+ config: CodesysBuildConfig,
39
+ ): CodesysBuildConfig => config;
35
40
 
36
- export const resolveConfig = (input: unknown, configFile: string): ResolvedConfig => {
37
- const parsed = configSchema.parse(input);
38
- const root = dirname(resolve(configFile));
39
- const codesys = localCodesysSchema.parse(containerCodesys);
40
- return {
41
- ...parsed,
42
- docker: parsed.docker ?? {},
43
- configFile: resolve(configFile),
44
- template: parsed.template
45
- ? resolve(root, parsed.template)
46
- : fileURLToPath(new URL("../templates/default.project", import.meta.url)),
47
- removeObjects: parsed.template ? parsed.removeObjects : ["PLC_PRG", ...parsed.removeObjects],
48
- libraries: parsed.libraries?.map((library) => ({
49
- ...library,
50
- path: resolve(root, library.path),
51
- })),
52
- sourceDir: resolve(root, parsed.sourceDir),
53
- entry: resolve(root, parsed.entry),
54
- outDir: resolve(root, parsed.outDir),
55
- codesys: {
56
- ...codesys,
57
- executable: resolve(root, codesys.executable),
58
- wine: codesys.wine
59
- ? { ...codesys.wine, prefix: resolve(root, codesys.wine.prefix) }
60
- : undefined,
61
- },
62
- };
41
+ export const resolveConfig = (
42
+ input: unknown,
43
+ configFile: string,
44
+ ): ResolvedConfig => {
45
+ const parsed = configSchema.parse(input);
46
+ const root = dirname(resolve(configFile));
47
+ const codesys = localCodesysSchema.parse(containerCodesys);
48
+ return {
49
+ ...parsed,
50
+ docker: parsed.docker ?? {},
51
+ configFile: resolve(configFile),
52
+ template: parsed.template
53
+ ? resolve(root, parsed.template)
54
+ : fileURLToPath(new URL("../templates/default.project", import.meta.url)),
55
+ removeObjects: parsed.template
56
+ ? parsed.removeObjects
57
+ : ["PLC_PRG", ...parsed.removeObjects],
58
+ libraries: parsed.libraries?.map((library) => ({
59
+ ...library,
60
+ path: resolve(root, library.path),
61
+ })),
62
+ sourceDir: resolve(root, parsed.sourceDir),
63
+ entry: resolve(root, parsed.entry),
64
+ outDir: resolve(root, parsed.outDir),
65
+ codesys: {
66
+ ...codesys,
67
+ executable: resolve(root, codesys.executable),
68
+ wine: codesys.wine
69
+ ? { ...codesys.wine, prefix: resolve(root, codesys.wine.prefix) }
70
+ : undefined,
71
+ },
72
+ };
63
73
  };
64
74
 
65
75
  export const loadConfig = async (file = "tsplc.config.ts") => {
66
- const path = resolve(file);
67
- const module = (await import(pathToFileURL(path).href)) as {
68
- config?: unknown;
69
- default?: unknown;
70
- };
71
- if (module.default === undefined && module.config === undefined) {
72
- throw new Error(`${path} must export a default config`);
73
- }
74
- const input = module.default ?? module.config;
75
- if (input && typeof input === "object" && "build" in input) {
76
- const { rawBuildConfig, tsplcConfigSchema } = await import("./schema.ts");
77
- return resolveConfig(rawBuildConfig(tsplcConfigSchema.parse(input)), path);
78
- }
79
- return resolveConfig(input, path);
76
+ const path = resolve(file);
77
+ const module = (await import(pathToFileURL(path).href)) as {
78
+ config?: unknown;
79
+ default?: unknown;
80
+ };
81
+ if (module.default === undefined && module.config === undefined) {
82
+ throw new Error(`${path} must export a default config`);
83
+ }
84
+ const input = module.default ?? module.config;
85
+ if (input && typeof input === "object" && "build" in input) {
86
+ const { rawBuildConfig, tsplcConfigSchema } = await import("./schema.ts");
87
+ return resolveConfig(rawBuildConfig(tsplcConfigSchema.parse(input)), path);
88
+ }
89
+ return resolveConfig(input, path);
80
90
  };