@sdeverywhere/build 0.3.16 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,44 +1,46 @@
1
- import { ModelSpec as ModelSpec$1 } from '@sdeverywhere/compile';
2
- import { Result } from 'neverthrow';
3
-
1
+ import { Result } from "neverthrow";
2
+ import { ModelSpec as ModelSpec$1 } from "@sdeverywhere/compile";
3
+ //#region src/_shared/log.d.ts
4
4
  type LogLevel = 'error' | 'info' | 'verbose';
5
-
5
+ //#endregion
6
+ //#region src/_shared/mode.d.ts
6
7
  /**
7
8
  * The mode used for the build process, either 'development' for local "dev mode"
8
9
  * (with live reload, etc) or 'production' for generating a production-ready build.
9
10
  */
10
11
  type BuildMode = 'development' | 'production';
11
-
12
+ //#endregion
13
+ //#region src/_shared/model-spec.d.ts
12
14
  /** A variable name as used in the modeling tool. */
13
15
  type VarName = string;
14
16
  /**
15
17
  * Describes a model input variable.
16
18
  */
17
19
  interface InputSpec {
18
- /** The variable name (as used in the modeling tool). */
19
- varName: VarName;
20
- /**
21
- * The stable input identifier. It is recommended to set this to a value (for example, a
22
- * numeric string like what `plugin-config` uses) that is separate from `varName` and is
23
- * stable between two versions of the model. This way, if an input variable is renamed
24
- * between two versions of the model, comparisons can still be performed between the two.
25
- * If a distinct `inputId` is not available, plugins can infer one from `varName`, but
26
- * note that this approach will be less resilient to renames.
27
- */
28
- inputId?: string;
29
- /** The default value for the input. */
30
- defaultValue?: number;
31
- /** The minimum value for the input. */
32
- minValue?: number;
33
- /** The maximum value for the input. */
34
- maxValue?: number;
20
+ /** The variable name (as used in the modeling tool). */
21
+ varName: VarName;
22
+ /**
23
+ * The stable input identifier. It is recommended to set this to a value (for example, a
24
+ * numeric string like what `plugin-config` uses) that is separate from `varName` and is
25
+ * stable between two versions of the model. This way, if an input variable is renamed
26
+ * between two versions of the model, comparisons can still be performed between the two.
27
+ * If a distinct `inputId` is not available, plugins can infer one from `varName`, but
28
+ * note that this approach will be less resilient to renames.
29
+ */
30
+ inputId?: string;
31
+ /** The default value for the input. */
32
+ defaultValue?: number;
33
+ /** The minimum value for the input. */
34
+ minValue?: number;
35
+ /** The maximum value for the input. */
36
+ maxValue?: number;
35
37
  }
36
38
  /**
37
39
  * Describes a model output variable.
38
40
  */
39
41
  interface OutputSpec {
40
- /** The variable name (as used in the modeling tool). */
41
- varName: VarName;
42
+ /** The variable name (as used in the modeling tool). */
43
+ varName: VarName;
42
44
  }
43
45
  /**
44
46
  * The model spec properties that are shared with (and passed through unchanged to) the
@@ -68,29 +70,29 @@ type ResolvedModelSpecProps = Omit<CommonModelSpecProps, 'datFiles' | 'bundleLis
68
70
  * used by the lower-level `sde` commands.
69
71
  */
70
72
  interface ModelSpec extends CommonModelSpecProps {
71
- /**
72
- * The input variables for the model. This can either be a simple array of
73
- * input variable names, or an array of `InputSpec` instances.
74
- *
75
- * The builder requires only variable names for the purposes of generating
76
- * a model, but some plugins may require full `InputSpec` instances.
77
- */
78
- inputs: VarName[] | InputSpec[];
79
- /**
80
- * The output variables for the model. This can either be a simple array of
81
- * output variable names, or an array of `OutputSpec` instances.
82
- */
83
- outputs: VarName[] | OutputSpec[];
84
- /**
85
- * Additional properties to include in the generated `spec.json` file.
86
- *
87
- * @deprecated All properties that are supported in a `spec.json` file are now declared
88
- * directly on this interface, so it is no longer necessary to use this escape hatch.
89
- * Any properties provided here will be merged into the resolved model spec (a property
90
- * that is configured directly on this interface takes precedence over the same property
91
- * provided here), but this property will be removed in a future release.
92
- */
93
- options?: ModelSpec$1;
73
+ /**
74
+ * The input variables for the model. This can either be a simple array of
75
+ * input variable names, or an array of `InputSpec` instances.
76
+ *
77
+ * The builder requires only variable names for the purposes of generating
78
+ * a model, but some plugins may require full `InputSpec` instances.
79
+ */
80
+ inputs: VarName[] | InputSpec[];
81
+ /**
82
+ * The output variables for the model. This can either be a simple array of
83
+ * output variable names, or an array of `OutputSpec` instances.
84
+ */
85
+ outputs: VarName[] | OutputSpec[];
86
+ /**
87
+ * Additional properties to include in the generated `spec.json` file.
88
+ *
89
+ * @deprecated All properties that are supported in a `spec.json` file are now declared
90
+ * directly on this interface, so it is no longer necessary to use this escape hatch.
91
+ * Any properties provided here will be merged into the resolved model spec (a property
92
+ * that is configured directly on this interface takes precedence over the same property
93
+ * provided here), but this property will be removed in a future release.
94
+ */
95
+ options?: ModelSpec$1;
94
96
  }
95
97
  /**
96
98
  * Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
@@ -101,87 +103,88 @@ interface ModelSpec extends CommonModelSpecProps {
101
103
  * functions.
102
104
  */
103
105
  interface ResolvedModelSpec extends ResolvedModelSpecProps {
104
- /**
105
- * The input variable names for the model. This will be defined regardless
106
- * of whether `ModelSpec.inputs` was defined as an array of variable names
107
- * or an array of `InputSpec` instances. (The input variable names are
108
- * derived from the `InputSpec` instances as needed.)
109
- */
110
- inputVarNames: VarName[];
111
- /**
112
- * The input variable specs for the model.
113
- */
114
- inputs: InputSpec[];
115
- /**
116
- * The output variable names for the model. This will be defined regardless
117
- * of whether `ModelSpec.outputs` was defined as an array of variable names
118
- * or an array of `OutputSpec` instances. (The output variable names are
119
- * derived from the `OutputSpec` instances as needed.)
120
- */
121
- outputVarNames: VarName[];
122
- /**
123
- * The output variable specs for the model.
124
- */
125
- outputs: OutputSpec[];
126
- /**
127
- * The dat files that provide the data for exogenous data variables in the
128
- * model.
129
- */
130
- datFiles: NonNullable<ModelSpec$1['datFiles']>;
131
- /**
132
- * Whether to bundle a model listing with the generated model.
133
- *
134
- * When this is true, a model listing will be bundled with the generated
135
- * model to allow the `runtime` package to resolve variables that are
136
- * referenced by name or identifier. This listing will increase the size
137
- * of the generated model, so it is recommended to set this to true only
138
- * if it is needed.
139
- */
140
- bundleListing: boolean;
141
- /**
142
- * Whether to allow constants to be overridden at runtime using `setConstant`.
143
- *
144
- * If false, the generated model will contain a `setConstant` function that
145
- * throws an error, meaning that constants cannot be overridden at runtime.
146
- *
147
- * If true, all constants in the generated model will be available to be
148
- * overridden.
149
- *
150
- * If an array is provided, only those variable names in the array will
151
- * be available to be overridden.
152
- */
153
- customConstants: boolean | VarName[];
154
- /**
155
- * Whether to allow lookups to be overridden at runtime using `setLookup`.
156
- *
157
- * If false, the generated model will contain a `setLookup` function that
158
- * throws an error, meaning that lookups cannot be overridden at runtime.
159
- *
160
- * If true, all lookups in the generated model will be available to be
161
- * overridden.
162
- *
163
- * If an array is provided, only those variable names in the array will
164
- * be available to be overridden.
165
- */
166
- customLookups: boolean | VarName[];
167
- /**
168
- * Whether to allow for capturing the data for arbitrary variables at
169
- * runtime (including variables that are not configured in the `outputs`
170
- * array).
171
- *
172
- * If false, the generated model will contain a `storeOutput` function
173
- * that throws an error, meaning that the data for arbitrary variables
174
- * cannot be captured at runtime.
175
- *
176
- * If true, all variables in the generated model will be available to be
177
- * captured at runtime.
178
- *
179
- * If an array is provided, only those variable names in the array will
180
- * be available to be captured at runtime.
181
- */
182
- customOutputs: boolean | VarName[];
106
+ /**
107
+ * The input variable names for the model. This will be defined regardless
108
+ * of whether `ModelSpec.inputs` was defined as an array of variable names
109
+ * or an array of `InputSpec` instances. (The input variable names are
110
+ * derived from the `InputSpec` instances as needed.)
111
+ */
112
+ inputVarNames: VarName[];
113
+ /**
114
+ * The input variable specs for the model.
115
+ */
116
+ inputs: InputSpec[];
117
+ /**
118
+ * The output variable names for the model. This will be defined regardless
119
+ * of whether `ModelSpec.outputs` was defined as an array of variable names
120
+ * or an array of `OutputSpec` instances. (The output variable names are
121
+ * derived from the `OutputSpec` instances as needed.)
122
+ */
123
+ outputVarNames: VarName[];
124
+ /**
125
+ * The output variable specs for the model.
126
+ */
127
+ outputs: OutputSpec[];
128
+ /**
129
+ * The dat files that provide the data for exogenous data variables in the
130
+ * model.
131
+ */
132
+ datFiles: NonNullable<ModelSpec$1['datFiles']>;
133
+ /**
134
+ * Whether to bundle a model listing with the generated model.
135
+ *
136
+ * When this is true, a model listing will be bundled with the generated
137
+ * model to allow the `runtime` package to resolve variables that are
138
+ * referenced by name or identifier. This listing will increase the size
139
+ * of the generated model, so it is recommended to set this to true only
140
+ * if it is needed.
141
+ */
142
+ bundleListing: boolean;
143
+ /**
144
+ * Whether to allow constants to be overridden at runtime using `setConstant`.
145
+ *
146
+ * If false, the generated model will contain a `setConstant` function that
147
+ * throws an error, meaning that constants cannot be overridden at runtime.
148
+ *
149
+ * If true, all constants in the generated model will be available to be
150
+ * overridden.
151
+ *
152
+ * If an array is provided, only those variable names in the array will
153
+ * be available to be overridden.
154
+ */
155
+ customConstants: boolean | VarName[];
156
+ /**
157
+ * Whether to allow lookups to be overridden at runtime using `setLookup`.
158
+ *
159
+ * If false, the generated model will contain a `setLookup` function that
160
+ * throws an error, meaning that lookups cannot be overridden at runtime.
161
+ *
162
+ * If true, all lookups in the generated model will be available to be
163
+ * overridden.
164
+ *
165
+ * If an array is provided, only those variable names in the array will
166
+ * be available to be overridden.
167
+ */
168
+ customLookups: boolean | VarName[];
169
+ /**
170
+ * Whether to allow for capturing the data for arbitrary variables at
171
+ * runtime (including variables that are not configured in the `outputs`
172
+ * array).
173
+ *
174
+ * If false, the generated model will contain a `storeOutput` function
175
+ * that throws an error, meaning that the data for arbitrary variables
176
+ * cannot be captured at runtime.
177
+ *
178
+ * If true, all variables in the generated model will be available to be
179
+ * captured at runtime.
180
+ *
181
+ * If an array is provided, only those variable names in the array will
182
+ * be available to be captured at runtime.
183
+ */
184
+ customOutputs: boolean | VarName[];
183
185
  }
184
-
186
+ //#endregion
187
+ //#region src/_shared/resolved-config.d.ts
185
188
  /**
186
189
  * The sde configuration derived from a `UserConfig` that has been resolved (i.e.,
187
190
  * paths have been checked). This is the config object that will be passed to
@@ -189,225 +192,229 @@ interface ResolvedModelSpec extends ResolvedModelSpecProps {
189
192
  * access to the `plugins` field of the original config).
190
193
  */
191
194
  interface ResolvedConfig {
192
- /**
193
- * The mode used for the build process, either 'development' or 'production'.
194
- */
195
- mode: BuildMode;
196
- /**
197
- * The absolute path to the project root directory, which has been confirmed to exist.
198
- */
199
- rootDir: string;
200
- /**
201
- * The absolute path to the directory used to prepare the model. This directory has
202
- * been created if it did not previously exist.
203
- */
204
- prepDir: string;
205
- /**
206
- * The mdl files to be built.
207
- */
208
- modelFiles: string[];
209
- /**
210
- * Paths to files that are considered to be inputs to the model build process.
211
- * These can be paths to files or glob patterns (relative to the project directory).
212
- */
213
- modelInputPaths: string[];
214
- /**
215
- * Paths to files that when changed will trigger a rebuild in watch mode. These
216
- * can be paths to files or glob patterns (relative to the project directory).
217
- */
218
- watchPaths: string[];
219
- /**
220
- * The code format to generate. If 'js', the model will be compiled to a JavaScript
221
- * file. If 'c', the model will be compiled to a C file (in which case an additional
222
- * plugin will be needed to convert the C code to a WebAssembly module).
223
- */
224
- genFormat: 'js' | 'c';
225
- /**
226
- * The absolute path to the JSON file that will be written by the build process that
227
- * lists all dimensions and variables in the model.
228
- */
229
- outListingFile?: string;
230
- /**
231
- * The path to the `@sdeverywhere/cli` package. This is currently only used to get
232
- * access to the files in the `src/c` directory.
233
- * @hidden This should be removed once we have tighter integration with the `cli` package.
234
- */
235
- sdeDir: string;
236
- /**
237
- * The path to the `sde` command.
238
- * @hidden This should be removed once we have tighter integration with the `cli` package.
239
- */
240
- sdeCmdPath: string;
195
+ /**
196
+ * The mode used for the build process, either 'development' or 'production'.
197
+ */
198
+ mode: BuildMode;
199
+ /**
200
+ * The absolute path to the project root directory, which has been confirmed to exist.
201
+ */
202
+ rootDir: string;
203
+ /**
204
+ * The absolute path to the directory used to prepare the model. This directory has
205
+ * been created if it did not previously exist.
206
+ */
207
+ prepDir: string;
208
+ /**
209
+ * The mdl files to be built.
210
+ */
211
+ modelFiles: string[];
212
+ /**
213
+ * Paths to files that are considered to be inputs to the model build process.
214
+ * These can be paths to files or glob patterns (relative to the project directory).
215
+ */
216
+ modelInputPaths: string[];
217
+ /**
218
+ * Paths to files that when changed will trigger a rebuild in watch mode. These
219
+ * can be paths to files or glob patterns (relative to the project directory).
220
+ */
221
+ watchPaths: string[];
222
+ /**
223
+ * The code format to generate. If 'js', the model will be compiled to a JavaScript
224
+ * file. If 'c', the model will be compiled to a C file (in which case an additional
225
+ * plugin will be needed to convert the C code to a WebAssembly module).
226
+ */
227
+ genFormat: 'js' | 'c';
228
+ /**
229
+ * The absolute path to the JSON file that will be written by the build process that
230
+ * lists all dimensions and variables in the model.
231
+ */
232
+ outListingFile?: string;
233
+ /**
234
+ * The path to the `@sdeverywhere/cli` package. This is currently only used to get
235
+ * access to the files in the `src/c` directory.
236
+ * @hidden This should be removed once we have tighter integration with the `cli` package.
237
+ */
238
+ sdeDir: string;
239
+ /**
240
+ * The path to the `sde` command.
241
+ * @hidden This should be removed once we have tighter integration with the `cli` package.
242
+ */
243
+ sdeCmdPath: string;
241
244
  }
242
-
245
+ //#endregion
246
+ //#region src/context/spawn-child.d.ts
243
247
  /**
244
248
  * @hidden This isn't ready to be included in the public API just yet.
245
249
  */
246
250
  interface ProcessOptions {
247
- logOutput?: boolean;
248
- ignoredMessageFilter?: string;
249
- captureOutput?: boolean;
250
- ignoreError?: boolean;
251
+ logOutput?: boolean;
252
+ ignoredMessageFilter?: string;
253
+ captureOutput?: boolean;
254
+ ignoreError?: boolean;
251
255
  }
252
256
  /**
253
257
  * @hidden This isn't ready to be included in the public API just yet.
254
258
  */
255
259
  interface ProcessOutput {
256
- exitCode: number;
257
- stdoutMessages: string[];
258
- stderrMessages: string[];
260
+ exitCode: number;
261
+ stdoutMessages: string[];
262
+ stderrMessages: string[];
259
263
  }
260
-
264
+ //#endregion
265
+ //#region src/context/staged-files.d.ts
261
266
  declare class StagedFiles {
262
- private readonly baseStagedDir;
263
- private readonly stagedFiles;
264
- constructor(prepDir: string);
265
- /**
266
- * Prepare for writing a file to the staged directory.
267
- *
268
- * This will add the path to the array of tracked files and will create the
269
- * staged directory if needed.
270
- *
271
- * @param srcDir The directory underneath the configured `staged` directory where
272
- * the file will be written (this must be a relative path).
273
- * @param srcFile The name of the file as written to the `staged` directory.
274
- * @param dstDir The absolute path to the destination directory where the staged
275
- * file will be copied when the build has completed.
276
- * @param dstFile The name of the file as written to the destination directory.
277
- * @return The absolute path to the staged file.
278
- */
279
- prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
280
- /**
281
- * Write a file to the staged directory.
282
- *
283
- * This file will be copied (along with other staged files) into the destination
284
- * directory only after the build process has completed. Copying all staged files
285
- * at once helps improve the local development experience by making it so that
286
- * live reloading tools only need to refresh once instead of every time a build
287
- * file is written.
288
- *
289
- * @param srcDir The directory underneath the configured `staged` directory where
290
- * the file will be written (this must be a relative path).
291
- * @param dstDir The absolute path to the destination directory where the staged
292
- * file will be copied when the build has completed.
293
- * @param filename The name of the file.
294
- * @param content The file content.
295
- */
296
- writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
297
- /**
298
- * Return the absolute path to the staged file for the given source directory and file name.
299
- *
300
- * @param srcDir The directory underneath the configured `staged` directory where
301
- * the file would be written initially (this must be a relative path).
302
- * @param srcFile The name of the file.
303
- */
304
- getStagedFilePath(srcDir: string, srcFile: string): string;
305
- /**
306
- * Return true if the staged file exists for the given source directory and file name.
307
- *
308
- * @param srcDir The directory underneath the configured `staged` directory where
309
- * the file would be written initially (this must be a relative path).
310
- * @param srcFile The name of the file.
311
- */
312
- stagedFileExists(srcDir: string, srcFile: string): boolean;
313
- /**
314
- * Return true if the destination file exists for the given source directory and file name.
315
- *
316
- * @param srcDir The directory underneath the configured `staged` directory where
317
- * the file would be written initially (this must be a relative path).
318
- * @param srcFile The name of the file.
319
- */
320
- destinationFileExists(srcDir: string, srcFile: string): boolean;
321
- /**
322
- * Copy staged files to their destination; this will only copy the staged
323
- * files if they are different than the existing destination files. We
324
- * copy the files in a batch like this so that hot module reload is only
325
- * triggered once at the end of the whole build process.
326
- */
327
- copyChangedFiles(): void;
328
- /**
329
- * Copy a file from the `staged` directory to its destination. If the file already
330
- * exists in the destination directory and has the same contents as the source file,
331
- * the file will not be copied and this function will return false.
332
- *
333
- * @param f The staged file entry.
334
- */
335
- private copyStagedFile;
267
+ private readonly baseStagedDir;
268
+ private readonly stagedFiles;
269
+ constructor(prepDir: string);
270
+ /**
271
+ * Prepare for writing a file to the staged directory.
272
+ *
273
+ * This will add the path to the array of tracked files and will create the
274
+ * staged directory if needed.
275
+ *
276
+ * @param srcDir The directory underneath the configured `staged` directory where
277
+ * the file will be written (this must be a relative path).
278
+ * @param srcFile The name of the file as written to the `staged` directory.
279
+ * @param dstDir The absolute path to the destination directory where the staged
280
+ * file will be copied when the build has completed.
281
+ * @param dstFile The name of the file as written to the destination directory.
282
+ * @return The absolute path to the staged file.
283
+ */
284
+ prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
285
+ /**
286
+ * Write a file to the staged directory.
287
+ *
288
+ * This file will be copied (along with other staged files) into the destination
289
+ * directory only after the build process has completed. Copying all staged files
290
+ * at once helps improve the local development experience by making it so that
291
+ * live reloading tools only need to refresh once instead of every time a build
292
+ * file is written.
293
+ *
294
+ * @param srcDir The directory underneath the configured `staged` directory where
295
+ * the file will be written (this must be a relative path).
296
+ * @param dstDir The absolute path to the destination directory where the staged
297
+ * file will be copied when the build has completed.
298
+ * @param filename The name of the file.
299
+ * @param content The file content.
300
+ */
301
+ writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
302
+ /**
303
+ * Return the absolute path to the staged file for the given source directory and file name.
304
+ *
305
+ * @param srcDir The directory underneath the configured `staged` directory where
306
+ * the file would be written initially (this must be a relative path).
307
+ * @param srcFile The name of the file.
308
+ */
309
+ getStagedFilePath(srcDir: string, srcFile: string): string;
310
+ /**
311
+ * Return true if the staged file exists for the given source directory and file name.
312
+ *
313
+ * @param srcDir The directory underneath the configured `staged` directory where
314
+ * the file would be written initially (this must be a relative path).
315
+ * @param srcFile The name of the file.
316
+ */
317
+ stagedFileExists(srcDir: string, srcFile: string): boolean;
318
+ /**
319
+ * Return true if the destination file exists for the given source directory and file name.
320
+ *
321
+ * @param srcDir The directory underneath the configured `staged` directory where
322
+ * the file would be written initially (this must be a relative path).
323
+ * @param srcFile The name of the file.
324
+ */
325
+ destinationFileExists(srcDir: string, srcFile: string): boolean;
326
+ /**
327
+ * Copy staged files to their destination; this will only copy the staged
328
+ * files if they are different than the existing destination files. We
329
+ * copy the files in a batch like this so that hot module reload is only
330
+ * triggered once at the end of the whole build process.
331
+ */
332
+ copyChangedFiles(): void;
333
+ /**
334
+ * Copy a file from the `staged` directory to its destination. If the file already
335
+ * exists in the destination directory and has the same contents as the source file,
336
+ * the file will not be copied and this function will return false.
337
+ *
338
+ * @param f The staged file entry.
339
+ */
340
+ private copyStagedFile;
336
341
  }
337
-
342
+ //#endregion
343
+ //#region src/context/context.d.ts
338
344
  /**
339
345
  * Provides access to common functionality that is needed during the build process.
340
346
  * This is passed to most plugin functions.
341
347
  */
342
348
  declare class BuildContext {
343
- readonly config: ResolvedConfig;
344
- private readonly stagedFiles;
345
- private readonly abortSignal;
346
- /**
347
- * @param config The resolved configuration.
348
- * @hidden
349
- */
350
- constructor(config: ResolvedConfig, stagedFiles: StagedFiles, abortSignal: AbortSignal | undefined);
351
- /**
352
- * Log a message to the console and/or the in-browser overlay panel.
353
- *
354
- * @param level The log level (verbose, info, error).
355
- * @param msg The message.
356
- */
357
- log(level: LogLevel, msg: string): void;
358
- /**
359
- * Prepare for writing a file to the staged directory.
360
- *
361
- * This will add the path to the array of tracked files and will create the
362
- * staged directory if needed.
363
- *
364
- * @param srcDir The directory underneath the configured `staged` directory where
365
- * the file will be written (this must be a relative path).
366
- * @param srcFile The name of the file as written to the `staged` directory.
367
- * @param dstDir The absolute path to the destination directory where the staged
368
- * file will be copied when the build has completed.
369
- * @param dstFile The name of the file as written to the destination directory.
370
- * @return The absolute path to the staged file.
371
- */
372
- prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
373
- /**
374
- * Write a file to the staged directory.
375
- *
376
- * This file will be copied (along with other staged files) into the destination
377
- * directory only after the build process has completed. Copying all staged files
378
- * at once helps improve the local development experience by making it so that
379
- * live reloading tools only need to refresh once instead of every time a build
380
- * file is written.
381
- *
382
- * @param srcDir The directory underneath the configured `staged` directory where
383
- * the file will be written (this must be a relative path).
384
- * @param dstDir The absolute path to the destination directory where the staged
385
- * file will be copied when the build has completed.
386
- * @param filename The name of the file.
387
- * @param content The file content.
388
- */
389
- writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
390
- /**
391
- * Spawn a child process that runs the given command.
392
- *
393
- * @param cwd The directory in which the command will be executed.
394
- * @param command The command to execute.
395
- * @param args The arguments to pass to the command.
396
- * @param opts Additional options to configure the process.
397
- * @returns The output of the process.
398
- */
399
- spawnChild(cwd: string, command: string, args: string[], opts?: ProcessOptions): Promise<ProcessOutput>;
400
- /**
401
- * Format a (subscripted or non-subscripted) model variable name into a canonical
402
- * identifier (with special characters converted to underscore, and subscript/dimension
403
- * parts separated by commas).
404
- *
405
- * @param name The name of the variable in the source model, e.g., `Variable name[DimA, B2]`.
406
- * @returns The canonical identifier for the given name, e.g., `_variable_name[_dima,_b2]`.
407
- */
408
- canonicalVarId(name: string): string;
349
+ readonly config: ResolvedConfig;
350
+ private readonly stagedFiles;
351
+ private readonly abortSignal;
352
+ /**
353
+ * @param config The resolved configuration.
354
+ * @hidden
355
+ */
356
+ constructor(config: ResolvedConfig, stagedFiles: StagedFiles, abortSignal: AbortSignal | undefined);
357
+ /**
358
+ * Log a message to the console and/or the in-browser overlay panel.
359
+ *
360
+ * @param level The log level (verbose, info, error).
361
+ * @param msg The message.
362
+ */
363
+ log(level: LogLevel, msg: string): void;
364
+ /**
365
+ * Prepare for writing a file to the staged directory.
366
+ *
367
+ * This will add the path to the array of tracked files and will create the
368
+ * staged directory if needed.
369
+ *
370
+ * @param srcDir The directory underneath the configured `staged` directory where
371
+ * the file will be written (this must be a relative path).
372
+ * @param srcFile The name of the file as written to the `staged` directory.
373
+ * @param dstDir The absolute path to the destination directory where the staged
374
+ * file will be copied when the build has completed.
375
+ * @param dstFile The name of the file as written to the destination directory.
376
+ * @return The absolute path to the staged file.
377
+ */
378
+ prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
379
+ /**
380
+ * Write a file to the staged directory.
381
+ *
382
+ * This file will be copied (along with other staged files) into the destination
383
+ * directory only after the build process has completed. Copying all staged files
384
+ * at once helps improve the local development experience by making it so that
385
+ * live reloading tools only need to refresh once instead of every time a build
386
+ * file is written.
387
+ *
388
+ * @param srcDir The directory underneath the configured `staged` directory where
389
+ * the file will be written (this must be a relative path).
390
+ * @param dstDir The absolute path to the destination directory where the staged
391
+ * file will be copied when the build has completed.
392
+ * @param filename The name of the file.
393
+ * @param content The file content.
394
+ */
395
+ writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
396
+ /**
397
+ * Spawn a child process that runs the given command.
398
+ *
399
+ * @param cwd The directory in which the command will be executed.
400
+ * @param command The command to execute.
401
+ * @param args The arguments to pass to the command.
402
+ * @param opts Additional options to configure the process.
403
+ * @returns The output of the process.
404
+ */
405
+ spawnChild(cwd: string, command: string, args: string[], opts?: ProcessOptions): Promise<ProcessOutput>;
406
+ /**
407
+ * Format a (subscripted or non-subscripted) model variable name into a canonical
408
+ * identifier (with special characters converted to underscore, and subscript/dimension
409
+ * parts separated by commas).
410
+ *
411
+ * @param name The name of the variable in the source model, e.g., `Variable name[DimA, B2]`.
412
+ * @returns The canonical identifier for the given name, e.g., `_variable_name[_dima,_b2]`.
413
+ */
414
+ canonicalVarId(name: string): string;
409
415
  }
410
-
416
+ //#endregion
417
+ //#region src/plugin/plugin.d.ts
411
418
  /**
412
419
  * The plugin interface that can be implemented to customize the model
413
420
  * generation and build process.
@@ -427,168 +434,170 @@ declare class BuildContext {
427
434
  * - watch (only called once after initial build steps when mode==development)
428
435
  */
429
436
  interface Plugin {
430
- /**
431
- * Called after the user configuration has been resolved, but before the
432
- * model is generated and other build steps.
433
- *
434
- * @param config The build configuration.
435
- */
436
- init?(config: ResolvedConfig): Promise<void>;
437
- /**
438
- * Called before the "generate model" steps are performed.
439
- *
440
- * @param context The build context (for logging, etc).
441
- * @param modelSpec The spec that controls how the model is generated.
442
- */
443
- preGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<void>;
444
- /**
445
- * Called before SDE preprocesses the mdl file (in the case of one mdl file),
446
- * or before SDE flattens the mdl files (in the case of multiple mdl files).
447
- *
448
- * @param context The build context (for logging, etc).
449
- */
450
- preProcessMdl?(context: BuildContext): Promise<void>;
451
- /**
452
- * Called after SDE preprocesses the mdl file (in the case of one mdl file),
453
- * or after SDE flattens the mdl files (in the case of multiple mdl files).
454
- *
455
- * @param context The build context (for logging, etc).
456
- * @param mdlContent The resulting mdl file content.
457
- * @return The modified mdl file content (if postprocessing was needed).
458
- */
459
- postProcessMdl?(context: BuildContext, mdlContent: string): Promise<string>;
460
- /**
461
- * Called before SDE generates a JS or C file from the mdl file.
462
- *
463
- * @param context The build context (for logging, etc).
464
- * @param format The generated code format, either 'js' or 'c'.
465
- */
466
- preGenerateCode?(context: BuildContext, format: 'js' | 'c'): Promise<void>;
467
- /**
468
- * Called after SDE generates a JS or C file from the mdl file.
469
- *
470
- * @param context The build context (for logging, etc).
471
- * @param format The generated code format, either 'js' or 'c'.
472
- * @param content The resulting JS or C file content.
473
- * @return The modified JS or C file content (if postprocessing was needed).
474
- */
475
- postGenerateCode?(context: BuildContext, format: 'js' | 'c', content: string): Promise<string>;
476
- /**
477
- * Called after the "generate model" process has completed (but before the staged
478
- * files are copied to their destination).
479
- *
480
- * @param context The build context (for logging, etc).
481
- * @param modelSpec The spec that controls how the model is generated.
482
- * @return Whether the plugin succeeded (for example, a plugin that runs tests can
483
- * return false to indicate that one or more tests failed).
484
- */
485
- postGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
486
- /**
487
- * Called after the model has been generated and after the staged files
488
- * have been copied to their destination.
489
- *
490
- * @param context The build context (for logging, etc).
491
- * @param modelSpec The spec that controls how the model is generated.
492
- * @return Whether the plugin succeeded (for example, a plugin that runs tests can
493
- * return false to indicate that one or more tests failed).
494
- */
495
- postBuild?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
496
- /**
497
- * Called in development/watch mode after the initial build has completed
498
- * (i.e., after the model has been generated and after the staged files
499
- * have been copied to their destination).
500
- *
501
- * @param config The build configuration.
502
- */
503
- watch?(config: ResolvedConfig): Promise<void>;
437
+ /**
438
+ * Called after the user configuration has been resolved, but before the
439
+ * model is generated and other build steps.
440
+ *
441
+ * @param config The build configuration.
442
+ */
443
+ init?(config: ResolvedConfig): Promise<void>;
444
+ /**
445
+ * Called before the "generate model" steps are performed.
446
+ *
447
+ * @param context The build context (for logging, etc).
448
+ * @param modelSpec The spec that controls how the model is generated.
449
+ */
450
+ preGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<void>;
451
+ /**
452
+ * Called before SDE preprocesses the mdl file (in the case of one mdl file),
453
+ * or before SDE flattens the mdl files (in the case of multiple mdl files).
454
+ *
455
+ * @param context The build context (for logging, etc).
456
+ */
457
+ preProcessMdl?(context: BuildContext): Promise<void>;
458
+ /**
459
+ * Called after SDE preprocesses the mdl file (in the case of one mdl file),
460
+ * or after SDE flattens the mdl files (in the case of multiple mdl files).
461
+ *
462
+ * @param context The build context (for logging, etc).
463
+ * @param mdlContent The resulting mdl file content.
464
+ * @return The modified mdl file content (if postprocessing was needed).
465
+ */
466
+ postProcessMdl?(context: BuildContext, mdlContent: string): Promise<string>;
467
+ /**
468
+ * Called before SDE generates a JS or C file from the mdl file.
469
+ *
470
+ * @param context The build context (for logging, etc).
471
+ * @param format The generated code format, either 'js' or 'c'.
472
+ */
473
+ preGenerateCode?(context: BuildContext, format: 'js' | 'c'): Promise<void>;
474
+ /**
475
+ * Called after SDE generates a JS or C file from the mdl file.
476
+ *
477
+ * @param context The build context (for logging, etc).
478
+ * @param format The generated code format, either 'js' or 'c'.
479
+ * @param content The resulting JS or C file content.
480
+ * @return The modified JS or C file content (if postprocessing was needed).
481
+ */
482
+ postGenerateCode?(context: BuildContext, format: 'js' | 'c', content: string): Promise<string>;
483
+ /**
484
+ * Called after the "generate model" process has completed (but before the staged
485
+ * files are copied to their destination).
486
+ *
487
+ * @param context The build context (for logging, etc).
488
+ * @param modelSpec The spec that controls how the model is generated.
489
+ * @return Whether the plugin succeeded (for example, a plugin that runs tests can
490
+ * return false to indicate that one or more tests failed).
491
+ */
492
+ postGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
493
+ /**
494
+ * Called after the model has been generated and after the staged files
495
+ * have been copied to their destination.
496
+ *
497
+ * @param context The build context (for logging, etc).
498
+ * @param modelSpec The spec that controls how the model is generated.
499
+ * @return Whether the plugin succeeded (for example, a plugin that runs tests can
500
+ * return false to indicate that one or more tests failed).
501
+ */
502
+ postBuild?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
503
+ /**
504
+ * Called in development/watch mode after the initial build has completed
505
+ * (i.e., after the model has been generated and after the staged files
506
+ * have been copied to their destination).
507
+ *
508
+ * @param config The build configuration.
509
+ */
510
+ watch?(config: ResolvedConfig): Promise<void>;
504
511
  }
505
-
512
+ //#endregion
513
+ //#region src/config/user-config.d.ts
506
514
  /**
507
515
  * The sde configuration as defined by the user, either inline or in a `sde.config.js` file.
508
516
  */
509
517
  interface UserConfig {
510
- /**
511
- * The project root directory. If undefined, the current directory is
512
- * assumed to be the project root. This directory should contain all the
513
- * model and config files referenced during the build process.
514
- */
515
- rootDir?: string;
516
- /**
517
- * The directory used to prepare the model. If undefined, an 'sde-prep'
518
- * directory will be created under the resolved `rootDir`.
519
- */
520
- prepDir?: string;
521
- /**
522
- * The mdl files to be built (must provide one or more).
523
- */
524
- modelFiles: string[];
525
- /**
526
- * Paths to files that are considered to be inputs to the model build process.
527
- * These can be paths to files or glob patterns (relative to the project directory).
528
- * If left undefined, this will resolve to the `modelFiles` array.
529
- */
530
- modelInputPaths?: string[];
531
- /**
532
- * Paths to files that when changed will trigger a rebuild in watch mode. These
533
- * can be paths to files or glob patterns (relative to the project directory).
534
- * If left undefined, this will resolve to the `modelFiles` array.
535
- */
536
- watchPaths?: string[];
537
- /**
538
- * The code format to generate. If 'js', the model will be compiled to a JavaScript
539
- * file. If 'c', the model will be compiled to a C file (in which case an additional
540
- * plugin will be needed to convert the C code to a WebAssembly module). If undefined,
541
- * defaults to 'js'.
542
- */
543
- genFormat?: 'js' | 'c';
544
- /**
545
- * If defined, the build process will write a JSON file to the provided path that lists
546
- * all dimensions and variables in the model. This can be an absolute path, or if it
547
- * is a relative path it will be resolved relative to the `rootDir` for the project.
548
- */
549
- outListingFile?: string;
550
- /**
551
- * The array of plugins that are used to customize the build process. These will be
552
- * executed in the order defined here.
553
- */
554
- plugins?: Plugin[];
555
- /**
556
- * Called before the "generate model" steps are performed.
557
- *
558
- * You must implement this function so that the generated model is
559
- * configured with the desired inputs and outputs.
560
- *
561
- * @return A `ModelSpec` that defines the model inputs and outputs.
562
- */
563
- modelSpec: (context: BuildContext) => Promise<ModelSpec>;
518
+ /**
519
+ * The project root directory. If undefined, the current directory is
520
+ * assumed to be the project root. This directory should contain all the
521
+ * model and config files referenced during the build process.
522
+ */
523
+ rootDir?: string;
524
+ /**
525
+ * The directory used to prepare the model. If undefined, an 'sde-prep'
526
+ * directory will be created under the resolved `rootDir`.
527
+ */
528
+ prepDir?: string;
529
+ /**
530
+ * The mdl files to be built (must provide one or more).
531
+ */
532
+ modelFiles: string[];
533
+ /**
534
+ * Paths to files that are considered to be inputs to the model build process.
535
+ * These can be paths to files or glob patterns (relative to the project directory).
536
+ * If left undefined, this will resolve to the `modelFiles` array.
537
+ */
538
+ modelInputPaths?: string[];
539
+ /**
540
+ * Paths to files that when changed will trigger a rebuild in watch mode. These
541
+ * can be paths to files or glob patterns (relative to the project directory).
542
+ * If left undefined, this will resolve to the `modelFiles` array.
543
+ */
544
+ watchPaths?: string[];
545
+ /**
546
+ * The code format to generate. If 'js', the model will be compiled to a JavaScript
547
+ * file. If 'c', the model will be compiled to a C file (in which case an additional
548
+ * plugin will be needed to convert the C code to a WebAssembly module). If undefined,
549
+ * defaults to 'js'.
550
+ */
551
+ genFormat?: 'js' | 'c';
552
+ /**
553
+ * If defined, the build process will write a JSON file to the provided path that lists
554
+ * all dimensions and variables in the model. This can be an absolute path, or if it
555
+ * is a relative path it will be resolved relative to the `rootDir` for the project.
556
+ */
557
+ outListingFile?: string;
558
+ /**
559
+ * The array of plugins that are used to customize the build process. These will be
560
+ * executed in the order defined here.
561
+ */
562
+ plugins?: Plugin[];
563
+ /**
564
+ * Called before the "generate model" steps are performed.
565
+ *
566
+ * You must implement this function so that the generated model is
567
+ * configured with the desired inputs and outputs.
568
+ *
569
+ * @return A `ModelSpec` that defines the model inputs and outputs.
570
+ */
571
+ modelSpec: (context: BuildContext) => Promise<ModelSpec>;
564
572
  }
565
-
573
+ //#endregion
574
+ //#region src/build/build.d.ts
566
575
  interface BuildOptions {
567
- /** The path to an `sde.config.js` file, or a `UserConfig` object. */
568
- config?: string | UserConfig;
569
- /**
570
- * The log levels to include. If undefined, the default 'info' and 'error' levels
571
- * will be active.
572
- */
573
- logLevels?: LogLevel[];
574
- /**
575
- * The path to the `@sdeverywhere/cli` package. This is currently only used to get
576
- * access to the files in the `src/c` directory.
577
- * @hidden This should be removed once we have tighter integration with the `cli` package.
578
- */
579
- sdeDir: string;
580
- /**
581
- * The path to the `sde` command.
582
- * @hidden This should be removed once we have tighter integration with the `cli` package.
583
- */
584
- sdeCmdPath: string;
576
+ /** The path to an `sde.config.js` file, or a `UserConfig` object. */
577
+ config?: string | UserConfig;
578
+ /**
579
+ * The log levels to include. If undefined, the default 'info' and 'error' levels
580
+ * will be active.
581
+ */
582
+ logLevels?: LogLevel[];
583
+ /**
584
+ * The path to the `@sdeverywhere/cli` package. This is currently only used to get
585
+ * access to the files in the `src/c` directory.
586
+ * @hidden This should be removed once we have tighter integration with the `cli` package.
587
+ */
588
+ sdeDir: string;
589
+ /**
590
+ * The path to the `sde` command.
591
+ * @hidden This should be removed once we have tighter integration with the `cli` package.
592
+ */
593
+ sdeCmdPath: string;
585
594
  }
586
595
  interface BuildResult {
587
- /**
588
- * The exit code that should be set by the process. This will be undefined
589
- * if `mode` is 'development', indicating that the process should be kept alive.
590
- */
591
- exitCode?: number;
596
+ /**
597
+ * The exit code that should be set by the process. This will be undefined
598
+ * if `mode` is 'development', indicating that the process should be kept alive.
599
+ */
600
+ exitCode?: number;
592
601
  }
593
602
  /**
594
603
  * Initiate the build process, which can either be a single build if `mode` is
@@ -598,6 +607,7 @@ interface BuildResult {
598
607
  * @param options The build options.
599
608
  * @return An `ok` result if the build completed, otherwise an `err` result.
600
609
  */
601
- declare function build(mode: BuildMode, options: BuildOptions): Promise<Result<BuildResult, Error>>;
602
-
603
- export { BuildContext, type BuildMode, type BuildOptions, type BuildResult, type InputSpec, type LogLevel, type ModelSpec, type OutputSpec, type Plugin, type ResolvedConfig, type ResolvedModelSpec, type UserConfig, type VarName, build };
610
+ export declare function build(mode: BuildMode, options: BuildOptions): Promise<Result<BuildResult, Error>>;
611
+ //#endregion
612
+ export type { BuildContext, BuildMode, BuildOptions, BuildResult, InputSpec, LogLevel, ModelSpec, OutputSpec, Plugin, ResolvedConfig, ResolvedModelSpec, UserConfig, VarName };
613
+ //# sourceMappingURL=index.d.ts.map