@sdeverywhere/plugin-check 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.
@@ -0,0 +1,30 @@
1
+ import { Plugin } from '@sdeverywhere/build';
2
+
3
+ interface CheckBundle {
4
+ /** The name of the bundle as displayed in the report (this is typically a branch name). */
5
+ name: string;
6
+ /** The absolute path to the JS bundle file. */
7
+ path: string;
8
+ }
9
+ interface CheckPluginOptions {
10
+ /** The baseline bundle. If undefined, no comparison tests will be run. */
11
+ baseline?: CheckBundle;
12
+ /** The current bundle, i.e., the bundle that is being developed and checked. */
13
+ current?: CheckBundle;
14
+ /**
15
+ * The absolute path to the JS file containing the test configuration. If undefined,
16
+ * a default test configuration will be used.
17
+ */
18
+ testConfigPath?: string;
19
+ /**
20
+ * The absolute path to the directory where the report will be written. If undefined,
21
+ * the report will be written to the configured `prepDir`.
22
+ */
23
+ reportPath?: string;
24
+ /** The port used for the local dev server (defaults to 8081). */
25
+ serverPort?: number;
26
+ }
27
+
28
+ declare function checkPlugin(options?: CheckPluginOptions): Plugin;
29
+
30
+ export { CheckBundle, CheckPluginOptions, checkPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,496 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/plugin.ts
19
+ import { join as joinPath3 } from "path";
20
+ import { pathToFileURL } from "url";
21
+ import { build, createServer } from "vite";
22
+ import { createConfig } from "@sdeverywhere/check-core";
23
+
24
+ // src/run-suite.ts
25
+ import { performance } from "perf_hooks";
26
+ import pico from "picocolors";
27
+ import {
28
+ datasetMessage,
29
+ predicateMessage,
30
+ runSuite,
31
+ scenarioMessage,
32
+ suiteSummaryFromReport
33
+ } from "@sdeverywhere/check-core";
34
+ async function runTestSuite(context, config, verbose) {
35
+ return new Promise((resolve, reject) => {
36
+ const t0 = performance.now();
37
+ let lastPctByInc;
38
+ const callbacks = {
39
+ onProgress: (progress) => {
40
+ const pct = Math.round(progress * 100);
41
+ const pctByInc = Math.floor(pct / 5) * 5;
42
+ if (lastPctByInc === void 0 || pctByInc > lastPctByInc) {
43
+ lastPctByInc = pctByInc;
44
+ context.log("info", `${pctByInc}%`);
45
+ }
46
+ },
47
+ onComplete: (report) => {
48
+ try {
49
+ const t1 = performance.now();
50
+ const elapsed = ((t1 - t0) / 1e3).toFixed(1);
51
+ context.log("info", `
52
+ Test suite completed in ${elapsed}s`);
53
+ const allChecksPassed = printCheckSummary(context, report.checkReport, verbose);
54
+ if (report.compareReport) {
55
+ printPerfStats(context, config.compare, report.compareReport);
56
+ }
57
+ const suiteSummary = suiteSummaryFromReport(report);
58
+ resolve({
59
+ allChecksPassed,
60
+ suiteSummary
61
+ });
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ },
66
+ onError: (error) => {
67
+ reject(error);
68
+ }
69
+ };
70
+ runSuite(config, callbacks);
71
+ });
72
+ }
73
+ function printCheckSummary(context, checkReport, verbose) {
74
+ function printResult(indent, status, text) {
75
+ if (!verbose && status === "passed" && indent > 1) {
76
+ return;
77
+ }
78
+ let statusChar;
79
+ switch (status) {
80
+ case "passed":
81
+ statusChar = "\u2713";
82
+ break;
83
+ case "failed":
84
+ statusChar = "\u2717";
85
+ break;
86
+ case "error":
87
+ statusChar = "\u203C";
88
+ break;
89
+ default:
90
+ statusChar = "";
91
+ break;
92
+ }
93
+ const msg = `${" ".repeat(indent)}${statusChar} ${text}`;
94
+ context.log("info", status === "passed" ? pico.green(msg) : pico.red(msg));
95
+ }
96
+ function bold(s) {
97
+ return pico.bold(s);
98
+ }
99
+ function printTest(test) {
100
+ const msg = `${test.name}${verbose || test.status !== "passed" ? ":" : ""}`;
101
+ printResult(1, test.status, msg);
102
+ }
103
+ let allPassed = true;
104
+ context.log("info", "\nCheck results:");
105
+ for (const group of checkReport.groups) {
106
+ context.log("info", `
107
+ ${group.name}`);
108
+ for (const test of group.tests) {
109
+ if (test.status !== "passed") {
110
+ allPassed = false;
111
+ }
112
+ printTest(test);
113
+ for (const scenario of test.scenarios) {
114
+ printResult(3, scenario.status, scenarioMessage(scenario, bold));
115
+ for (const dataset of scenario.datasets) {
116
+ printResult(5, dataset.status, datasetMessage(dataset, bold));
117
+ for (const predicate of dataset.predicates) {
118
+ printResult(7, predicate.result.status, predicateMessage(predicate, bold));
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ context.log("info", "");
125
+ return allPassed;
126
+ }
127
+ function stat(label, n) {
128
+ return `${label}=${n.toFixed(1)}ms`;
129
+ }
130
+ function printPerfReportLine(context, perfReport) {
131
+ const avg = stat("avg", perfReport.avgTime);
132
+ const min = stat("min", perfReport.minTime);
133
+ const max = stat("max", perfReport.maxTime);
134
+ context.log("info", ` ${avg} ${min} ${max}`);
135
+ }
136
+ function printPerfStats(context, compareConfig, report) {
137
+ context.log("info", "\nPerformance stats:");
138
+ context.log("info", ` ${compareConfig.bundleL.name}:`);
139
+ printPerfReportLine(context, report.perfReportL);
140
+ context.log("info", ` ${compareConfig.bundleR.name}:`);
141
+ printPerfReportLine(context, report.perfReportR);
142
+ context.log("info", "");
143
+ }
144
+
145
+ // src/vite-config-for-bundle.ts
146
+ import { dirname, join as joinPath, relative, resolve as resolvePath } from "path";
147
+ import { fileURLToPath } from "url";
148
+ import { nodeResolve } from "@rollup/plugin-node-resolve";
149
+
150
+ // src/var-names.ts
151
+ function sdeNameForVensimName(name) {
152
+ return "_" + name.trim().replace(/"/g, "_").replace(/\s+!$/g, "!").replace(/\s/g, "_").replace(/,/g, "_").replace(/-/g, "_").replace(/\./g, "_").replace(/\$/g, "_").replace(/'/g, "_").replace(/&/g, "_").replace(/%/g, "_").replace(/\//g, "_").replace(/\|/g, "_").toLowerCase();
153
+ }
154
+ function sdeNameForVensimVarName(varName) {
155
+ const m = varName.match(/([^[]+)(?:\[([^\]]+)\])?/);
156
+ if (!m) {
157
+ throw new Error(`Invalid Vensim name: ${varName}`);
158
+ }
159
+ let id = sdeNameForVensimName(m[1]);
160
+ if (m[2]) {
161
+ const subscripts = m[2].split(",").map((x) => sdeNameForVensimName(x));
162
+ id += `[${subscripts.join("][")}]`;
163
+ }
164
+ return id;
165
+ }
166
+
167
+ // src/vite-config-for-bundle.ts
168
+ var __filename = fileURLToPath(import.meta.url);
169
+ var __dirname = dirname(__filename);
170
+ function injectModelSpec(modelSpec) {
171
+ const inputSpecs = modelSpec.inputs.map((i) => {
172
+ return __spreadValues({
173
+ varId: sdeNameForVensimVarName(i.varName)
174
+ }, i);
175
+ });
176
+ const outputSpecs = modelSpec.outputs.map((o) => {
177
+ return __spreadValues({
178
+ varId: sdeNameForVensimVarName(o.varName)
179
+ }, o);
180
+ });
181
+ const moduleSrc = `
182
+ export const startTime = ${modelSpec.startTime};
183
+ export const endTime = ${modelSpec.endTime};
184
+ export const inputSpecs = ${JSON.stringify(inputSpecs)};
185
+ export const outputSpecs = ${JSON.stringify(outputSpecs)};
186
+ `;
187
+ const virtualModuleId = "virtual:model-spec";
188
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
189
+ return {
190
+ name: "vite-plugin-virtual-custom",
191
+ resolveId(id) {
192
+ if (id === virtualModuleId) {
193
+ return resolvedVirtualModuleId;
194
+ }
195
+ },
196
+ load(id) {
197
+ if (id === resolvedVirtualModuleId) {
198
+ return moduleSrc;
199
+ }
200
+ }
201
+ };
202
+ }
203
+ async function createViteConfigForBundle(prepDir, modelSpec) {
204
+ const root = resolvePath(__dirname, "..", "template-bundle");
205
+ const outDir = relative(root, prepDir);
206
+ const modelWorkerPath = joinPath(prepDir, "staged", "model", "worker.js?raw");
207
+ return {
208
+ configFile: false,
209
+ root,
210
+ clearScreen: false,
211
+ resolve: {
212
+ alias: [
213
+ {
214
+ find: "@_model_worker_",
215
+ replacement: modelWorkerPath
216
+ },
217
+ {
218
+ find: "threads",
219
+ replacement: "threads",
220
+ customResolver: async function(source, importer, options) {
221
+ const customResolver = nodeResolve({ browser: false });
222
+ const resolved = await customResolver.resolveId.call(this, source, importer, options);
223
+ if (source === "threads/worker") {
224
+ return resolved.id.replace("worker.mjs", "dist-esm/worker/index.js");
225
+ } else {
226
+ return resolved.id.replace("index.mjs", "dist-esm/index.js");
227
+ }
228
+ }
229
+ }
230
+ ]
231
+ },
232
+ plugins: [
233
+ injectModelSpec(modelSpec)
234
+ ],
235
+ build: {
236
+ outDir,
237
+ emptyOutDir: false,
238
+ lib: {
239
+ entry: "./src/index.ts",
240
+ formats: ["es"],
241
+ fileName: () => "check-bundle.js"
242
+ },
243
+ rollupOptions: {
244
+ external: ["events", "os", "path", "url"],
245
+ output: {
246
+ banner: `
247
+ import * as worker_threads from 'worker_threads'
248
+ let __non_webpack_require__ = () => {
249
+ return worker_threads;
250
+ };
251
+ `
252
+ },
253
+ onwarn: (warning, warn) => {
254
+ if (warning.code !== "EVAL") {
255
+ warn(warning);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ };
261
+ }
262
+
263
+ // src/vite-config-for-report.ts
264
+ import { dirname as dirname2, relative as relative2, join as joinPath2, resolve as resolvePath2 } from "path";
265
+ import { fileURLToPath as fileURLToPath2 } from "url";
266
+ import { nodeResolve as nodeResolve2 } from "@rollup/plugin-node-resolve";
267
+ var __filename2 = fileURLToPath2(import.meta.url);
268
+ var __dirname2 = dirname2(__filename2);
269
+ function createViteConfigForReport(options, prepDir, currentBundleName, currentBundlePath, testConfigPath, suiteSummary) {
270
+ var _a;
271
+ const root = resolvePath2(__dirname2, "..", "template-report");
272
+ let reportPath;
273
+ if (options == null ? void 0 : options.reportPath) {
274
+ reportPath = options.reportPath;
275
+ } else {
276
+ reportPath = joinPath2(prepDir, "check-report");
277
+ }
278
+ const outDir = relative2(root, reportPath);
279
+ const suiteSummaryJson = suiteSummary ? JSON.stringify(suiteSummary) : "";
280
+ const alias = (find, replacement) => {
281
+ return {
282
+ find,
283
+ replacement
284
+ };
285
+ };
286
+ const polyfillAlias = (find) => {
287
+ return {
288
+ find,
289
+ replacement: find,
290
+ customResolver: async function(_source, _importer, options2) {
291
+ const customResolver = nodeResolve2();
292
+ const customSource = `rollup-plugin-node-polyfills/polyfills/${find}`;
293
+ const customImporter = __filename2;
294
+ const resolved = await customResolver.resolveId.call(this, customSource, customImporter, options2);
295
+ return resolved.id;
296
+ }
297
+ };
298
+ };
299
+ return {
300
+ configFile: false,
301
+ root,
302
+ base: "",
303
+ clearScreen: false,
304
+ optimizeDeps: {
305
+ entries: ["index.html"],
306
+ exclude: ["tiny-worker"]
307
+ },
308
+ resolve: {
309
+ alias: [
310
+ alias("@_baseline_bundle_", (options == null ? void 0 : options.baseline) ? options.baseline.path : "/src/empty-bundle.ts"),
311
+ alias("@_current_bundle_", currentBundlePath),
312
+ alias("@_test_config_", testConfigPath),
313
+ alias("@_prep_", prepDir),
314
+ polyfillAlias("events"),
315
+ polyfillAlias("os"),
316
+ polyfillAlias("path"),
317
+ alias("url", "/src/url-polyfill.ts")
318
+ ]
319
+ },
320
+ define: {
321
+ __SUITE_SUMMARY_JSON__: JSON.stringify(suiteSummaryJson),
322
+ __BASELINE_NAME__: JSON.stringify(((_a = options == null ? void 0 : options.baseline) == null ? void 0 : _a.name) || ""),
323
+ __CURRENT_NAME__: JSON.stringify(currentBundleName)
324
+ },
325
+ plugins: [],
326
+ build: {
327
+ outDir,
328
+ assetsDir: "",
329
+ rollupOptions: {
330
+ output: {
331
+ manualChunks: void 0
332
+ },
333
+ onwarn: (warning, warn) => {
334
+ if (warning.code !== "EVAL") {
335
+ warn(warning);
336
+ }
337
+ }
338
+ }
339
+ },
340
+ server: {
341
+ port: (options == null ? void 0 : options.serverPort) || 8081,
342
+ open: "/index.html",
343
+ watch: {
344
+ awaitWriteFinish: {
345
+ stabilityThreshold: 100
346
+ }
347
+ }
348
+ }
349
+ };
350
+ }
351
+
352
+ // src/vite-config-for-tests.ts
353
+ import { dirname as dirname3, relative as relative3, resolve as resolvePath3 } from "path";
354
+ import { fileURLToPath as fileURLToPath3 } from "url";
355
+ import globPlugin from "vite-plugin-glob";
356
+ import replace from "@rollup/plugin-replace";
357
+ var __filename3 = fileURLToPath3(import.meta.url);
358
+ var __dirname3 = dirname3(__filename3);
359
+ function createViteConfigForTests(projDir, prepDir, mode) {
360
+ const root = resolvePath3(__dirname3, "..", "template-tests");
361
+ const templateSrcDir = resolvePath3(root, "src");
362
+ const relProjDir = relative3(templateSrcDir, projDir);
363
+ const yamlPath = `${relProjDir}/**/*.check.yaml`;
364
+ const outDir = relative3(root, prepDir);
365
+ return {
366
+ configFile: false,
367
+ root,
368
+ clearScreen: false,
369
+ plugins: [
370
+ replace({
371
+ preventAssignment: true,
372
+ values: {
373
+ __YAML_PATH__: JSON.stringify(yamlPath)
374
+ }
375
+ }),
376
+ globPlugin()
377
+ ],
378
+ build: {
379
+ outDir,
380
+ emptyOutDir: false,
381
+ lib: {
382
+ entry: "./src/index.ts",
383
+ formats: ["es"],
384
+ fileName: () => "check-tests.js"
385
+ },
386
+ watch: mode === "watch" && {},
387
+ rollupOptions: {}
388
+ }
389
+ };
390
+ }
391
+
392
+ // src/plugin.ts
393
+ function checkPlugin(options) {
394
+ return new CheckPlugin(options);
395
+ }
396
+ var CheckPlugin = class {
397
+ constructor(options) {
398
+ this.options = options;
399
+ }
400
+ async watch(config) {
401
+ var _a;
402
+ if (((_a = this.options) == null ? void 0 : _a.testConfigPath) === void 0) {
403
+ await this.genTestConfig(config, "watch");
404
+ }
405
+ const testOptions = this.resolveTestOptions(config);
406
+ const viteConfig = this.createViteConfigForReport(config, testOptions, void 0);
407
+ const server = await createServer(viteConfig);
408
+ await server.listen();
409
+ }
410
+ async postBuild(context, modelSpec) {
411
+ var _a, _b;
412
+ if (((_a = this.options) == null ? void 0 : _a.current) === void 0) {
413
+ context.log("info", "Generating model check bundle...");
414
+ await this.genCurrentBundle(context.config, modelSpec);
415
+ }
416
+ if (context.config.mode === "production") {
417
+ if (((_b = this.options) == null ? void 0 : _b.testConfigPath) === void 0) {
418
+ context.log("info", "Generating model check test configuration...");
419
+ await this.genTestConfig(context.config, "build");
420
+ }
421
+ const testOptions = this.resolveTestOptions(context.config);
422
+ return this.runChecks(context, testOptions);
423
+ } else {
424
+ return true;
425
+ }
426
+ }
427
+ async genCurrentBundle(config, modelSpec) {
428
+ const prepDir = config.prepDir;
429
+ const viteConfig = await createViteConfigForBundle(prepDir, modelSpec);
430
+ await build(viteConfig);
431
+ }
432
+ async genTestConfig(config, mode) {
433
+ const rootDir = config.rootDir;
434
+ const prepDir = config.prepDir;
435
+ const viteConfig = createViteConfigForTests(rootDir, prepDir, mode);
436
+ await build(viteConfig);
437
+ }
438
+ async runChecks(context, testOptions) {
439
+ var _a;
440
+ context.log("info", "Running model checks...");
441
+ const moduleR = await import(pathToFileURL(testOptions.currentBundlePath).toString());
442
+ const bundleR = moduleR.createBundle();
443
+ const nameR = testOptions.currentBundleName;
444
+ let bundleL;
445
+ let nameL;
446
+ if ((_a = this.options) == null ? void 0 : _a.baseline) {
447
+ const moduleL = await import(pathToFileURL(this.options.baseline.path).toString());
448
+ const rawBundleL = moduleL.createBundle();
449
+ if (rawBundleL.version === bundleR.version) {
450
+ bundleL = rawBundleL;
451
+ nameL = this.options.baseline.name;
452
+ }
453
+ }
454
+ const testConfigModule = await import(pathToFileURL(testOptions.testConfigPath).toString());
455
+ const checkOptions = await testConfigModule.getConfigOptions(bundleL, bundleR, {
456
+ nameL,
457
+ nameR
458
+ });
459
+ const checkConfig = await createConfig(checkOptions);
460
+ const result = await runTestSuite(context, checkConfig, false);
461
+ context.log("info", "Building model check report");
462
+ const viteConfig = this.createViteConfigForReport(context.config, testOptions, result.suiteSummary);
463
+ await build(viteConfig);
464
+ return result.allChecksPassed;
465
+ }
466
+ resolveTestOptions(config) {
467
+ var _a, _b;
468
+ let currentBundleName;
469
+ let currentBundlePath;
470
+ if (((_a = this.options) == null ? void 0 : _a.current) === void 0) {
471
+ currentBundleName = "current";
472
+ currentBundlePath = joinPath3(config.prepDir, "check-bundle.js");
473
+ } else {
474
+ currentBundleName = this.options.current.name;
475
+ currentBundlePath = this.options.current.path;
476
+ }
477
+ let testConfigPath;
478
+ if (((_b = this.options) == null ? void 0 : _b.testConfigPath) === void 0) {
479
+ testConfigPath = joinPath3(config.prepDir, "check-tests.js");
480
+ } else {
481
+ testConfigPath = this.options.testConfigPath;
482
+ }
483
+ return {
484
+ currentBundleName,
485
+ currentBundlePath,
486
+ testConfigPath
487
+ };
488
+ }
489
+ createViteConfigForReport(config, testOptions, suiteSummary) {
490
+ return createViteConfigForReport(this.options, config.prepDir, testOptions.currentBundleName, testOptions.currentBundlePath, testOptions.testConfigPath, suiteSummary);
491
+ }
492
+ };
493
+ export {
494
+ checkPlugin
495
+ };
496
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts","../src/run-suite.ts","../src/vite-config-for-bundle.ts","../src/var-names.ts","../src/vite-config-for-report.ts","../src/vite-config-for-tests.ts"],"sourcesContent":["// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport { join as joinPath } from 'path'\nimport { pathToFileURL } from 'url'\n\nimport type { InlineConfig, ViteDevServer } from 'vite'\nimport { build, createServer } from 'vite'\n\nimport type { BuildContext, ModelSpec, Plugin, ResolvedConfig } from '@sdeverywhere/build'\n\nimport type { Bundle, SuiteSummary } from '@sdeverywhere/check-core'\nimport { createConfig } from '@sdeverywhere/check-core'\n\nimport type { CheckPluginOptions } from './options'\nimport { runTestSuite } from './run-suite'\nimport { createViteConfigForBundle } from './vite-config-for-bundle'\nimport { createViteConfigForReport } from './vite-config-for-report'\nimport { createViteConfigForTests } from './vite-config-for-tests'\n\nexport function checkPlugin(options?: CheckPluginOptions): Plugin {\n return new CheckPlugin(options)\n}\n\ninterface TestOptions {\n currentBundleName: string\n currentBundlePath: string\n testConfigPath: string\n}\n\nclass CheckPlugin implements Plugin {\n constructor(private readonly options?: CheckPluginOptions) {}\n\n async watch(config: ResolvedConfig): Promise<void> {\n if (this.options?.testConfigPath === undefined) {\n // Test config was not provided, so generate a default config in watch mode.\n // The test template uses import.meta.importGlob so that checks are re-run\n // automatically when the *.check.yaml files are changed.\n await this.genTestConfig(config, 'watch')\n }\n\n // For development mode, run Vite in dev mode so that it serves the\n // model-check report locally (with live reload enabled). When a model\n // test file is changed, the tests will be re-run in the browser.\n const testOptions = this.resolveTestOptions(config)\n const viteConfig = this.createViteConfigForReport(config, testOptions, undefined)\n const server: ViteDevServer = await createServer(viteConfig)\n await server.listen()\n }\n\n // TODO: Note that this plugin runs as a `postBuild` step because it currently\n // needs to run after other plugins, and those plugins need to run after the\n // staged files are copied to their final destination(s). We should probably\n // make it configurable so that it can either be run as a `postGenerate` or a\n // `postBuild` step.\n async postBuild(context: BuildContext, modelSpec: ModelSpec): Promise<boolean> {\n // For both production builds and local development, generate default bundle\n // in this post-build step each time a source file is changed\n // TODO: We could potentially use watch mode for the bundle similar to\n // what we do for the test config, but the bundle depends on the ModelSpec,\n // which currently isn't made available to the `watch` function\n if (this.options?.current === undefined) {\n // Path to current bundle was not provided, so generate a default bundle\n context.log('info', 'Generating model check bundle...')\n await this.genCurrentBundle(context.config, modelSpec)\n }\n\n if (context.config.mode === 'production') {\n if (this.options?.testConfigPath === undefined) {\n // Test config was not provided, so generate a default config\n context.log('info', 'Generating model check test configuration...')\n await this.genTestConfig(context.config, 'build')\n }\n\n // For production builds, run the model checks/comparisons, and then\n // inject the results into the generated report\n const testOptions = this.resolveTestOptions(context.config)\n return this.runChecks(context, testOptions)\n } else {\n // Nothing to do here in dev mode; the dev server will refresh and\n // re-run the tests in the browser when changes are detected\n return true\n }\n }\n\n private async genCurrentBundle(config: ResolvedConfig, modelSpec: ModelSpec): Promise<void> {\n const prepDir = config.prepDir\n const viteConfig = await createViteConfigForBundle(prepDir, modelSpec)\n await build(viteConfig)\n }\n\n private async genTestConfig(config: ResolvedConfig, mode: 'build' | 'watch'): Promise<void> {\n const rootDir = config.rootDir\n const prepDir = config.prepDir\n const viteConfig = createViteConfigForTests(rootDir, prepDir, mode)\n await build(viteConfig)\n }\n\n private async runChecks(context: BuildContext, testOptions: TestOptions): Promise<boolean> {\n context.log('info', 'Running model checks...')\n\n // Load the bundles used by the model check/compare configuration. We\n // always initialize the \"current\" bundle. Note that on Windows the\n // dynamic import path must be a `file://` URL, so we have to convert.\n const moduleR = await import(pathToFileURL(testOptions.currentBundlePath).toString())\n const bundleR = moduleR.createBundle() as Bundle\n const nameR = testOptions.currentBundleName\n\n // Only initialize the \"baseline\" bundle if it is defined and the version\n // is the same as the \"current\" one. If the baseline bundle has a different\n // version, we will skip the comparison tests and only run the checks on the\n // current bundle.\n let bundleL: Bundle\n let nameL: string\n if (this.options?.baseline) {\n const moduleL = await import(pathToFileURL(this.options.baseline.path).toString())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rawBundleL: any = moduleL.createBundle() as any\n if (rawBundleL.version === bundleR.version) {\n bundleL = rawBundleL as Bundle\n nameL = this.options.baseline.name\n }\n }\n\n // Get the model check/compare configuration\n const testConfigModule = await import(pathToFileURL(testOptions.testConfigPath).toString())\n const checkOptions = await testConfigModule.getConfigOptions(bundleL, bundleR, {\n nameL,\n nameR\n })\n\n // Run the suite of checks and comparisons\n const checkConfig = await createConfig(checkOptions)\n const result = await runTestSuite(context, checkConfig, /*verbose=*/ false)\n\n // Build the report (using Vite)\n context.log('info', 'Building model check report')\n const viteConfig = this.createViteConfigForReport(context.config, testOptions, result.suiteSummary)\n await build(viteConfig)\n\n // context.log('info', 'Done!')\n\n return result.allChecksPassed\n }\n\n private resolveTestOptions(config: ResolvedConfig): TestOptions {\n let currentBundleName: string\n let currentBundlePath: string\n if (this.options?.current === undefined) {\n // Path to current bundle was not provided, so use a generated bundle\n currentBundleName = 'current'\n currentBundlePath = joinPath(config.prepDir, 'check-bundle.js')\n } else {\n // Use the provided bundle\n currentBundleName = this.options.current.name\n currentBundlePath = this.options.current.path\n }\n\n let testConfigPath: string\n if (this.options?.testConfigPath === undefined) {\n // Test config was not provided, so use a generated config\n testConfigPath = joinPath(config.prepDir, 'check-tests.js')\n } else {\n // Use the provided test config\n testConfigPath = this.options.testConfigPath\n }\n\n return {\n currentBundleName,\n currentBundlePath,\n testConfigPath\n }\n }\n\n private createViteConfigForReport(\n config: ResolvedConfig,\n testOptions: TestOptions,\n suiteSummary: SuiteSummary | undefined\n ): InlineConfig {\n return createViteConfigForReport(\n this.options,\n config.prepDir,\n testOptions.currentBundleName,\n testOptions.currentBundlePath,\n testOptions.testConfigPath,\n suiteSummary\n )\n }\n}\n","// Copyright (c) 2021-2022 Climate Interactive / New Venture Fund\n\nimport { performance } from 'perf_hooks'\n\nimport pico from 'picocolors'\n\nimport type { BuildContext } from '@sdeverywhere/build'\n\nimport type {\n Config,\n CompareReport,\n PerfReport,\n RunSuiteCallbacks,\n CheckReport,\n CheckStatus,\n CompareConfig,\n CheckTestReport,\n SuiteSummary\n} from '@sdeverywhere/check-core'\nimport {\n datasetMessage,\n predicateMessage,\n runSuite,\n scenarioMessage,\n suiteSummaryFromReport\n} from '@sdeverywhere/check-core'\n\nexport interface RunTestSuiteResult {\n allChecksPassed: boolean\n suiteSummary: SuiteSummary\n}\n\n/**\n * Runs the test suite.\n */\nexport async function runTestSuite(\n context: BuildContext,\n config: Config,\n verbose: boolean\n): Promise<RunTestSuiteResult> {\n return new Promise((resolve, reject) => {\n const t0 = performance.now()\n let lastPctByInc: number\n const callbacks: RunSuiteCallbacks = {\n onProgress: progress => {\n const pct = Math.round(progress * 100)\n const pctByInc = Math.floor(pct / 5) * 5\n if (lastPctByInc === undefined || pctByInc > lastPctByInc) {\n lastPctByInc = pctByInc\n context.log('info', `${pctByInc}%`)\n }\n },\n onComplete: report => {\n try {\n const t1 = performance.now()\n const elapsed = ((t1 - t0) / 1000).toFixed(1)\n context.log('info', `\\nTest suite completed in ${elapsed}s`)\n\n // Print check summary to the console\n const allChecksPassed = printCheckSummary(context, report.checkReport, verbose)\n\n if (report.compareReport) {\n // Print the perf stats to the console\n printPerfStats(context, config.compare, report.compareReport)\n }\n\n // Convert check and compare reports to terse form that only includes\n // failed/errored checks or comparisons with differences\n // TODO: The terse form was originally used when we had to write the\n // results to a JSON file and then read them back in when building\n // the report, but we no longer use that intermediate file, so there's\n // less reason to use the terse form (since it requires the web app\n // code to reconstruct the results). But for now, we will continue\n // to use the terse form, and later we can update the app code.\n const suiteSummary = suiteSummaryFromReport(report)\n\n resolve({\n allChecksPassed,\n suiteSummary\n })\n } catch (e) {\n reject(e)\n }\n },\n onError: error => {\n reject(error)\n }\n }\n runSuite(config, callbacks)\n })\n}\n\nfunction printCheckSummary(context: BuildContext, checkReport: CheckReport, verbose: boolean): boolean {\n function printResult(indent: number, status: CheckStatus, text: string): void {\n if (!verbose && status === 'passed' && indent > 1) {\n return\n }\n let statusChar: string\n switch (status) {\n case 'passed':\n statusChar = '✓'\n break\n case 'failed':\n statusChar = '✗'\n break\n case 'error':\n statusChar = '‼'\n break\n default:\n statusChar = ''\n break\n }\n const msg = `${' '.repeat(indent)}${statusChar} ${text}`\n context.log('info', status === 'passed' ? pico.green(msg) : pico.red(msg))\n }\n\n function bold(s: string): string {\n return pico.bold(s)\n }\n\n function printTest(test: CheckTestReport): void {\n const msg = `${test.name}${verbose || test.status !== 'passed' ? ':' : ''}`\n printResult(1, test.status, msg)\n }\n\n let allPassed = true\n context.log('info', '\\nCheck results:')\n for (const group of checkReport.groups) {\n context.log('info', `\\n${group.name}`)\n\n for (const test of group.tests) {\n if (test.status !== 'passed') {\n allPassed = false\n }\n printTest(test)\n\n for (const scenario of test.scenarios) {\n printResult(3, scenario.status, scenarioMessage(scenario, bold))\n\n for (const dataset of scenario.datasets) {\n printResult(5, dataset.status, datasetMessage(dataset, bold))\n\n for (const predicate of dataset.predicates) {\n printResult(7, predicate.result.status, predicateMessage(predicate, bold))\n }\n }\n }\n }\n }\n context.log('info', '')\n\n return allPassed\n}\n\nfunction stat(label: string, n: number): string {\n return `${label}=${n.toFixed(1)}ms`\n}\n\nfunction printPerfReportLine(context: BuildContext, perfReport: PerfReport): void {\n const avg = stat('avg', perfReport.avgTime)\n const min = stat('min', perfReport.minTime)\n const max = stat('max', perfReport.maxTime)\n context.log('info', ` ${avg} ${min} ${max}`)\n}\n\nfunction printPerfStats(context: BuildContext, compareConfig: CompareConfig, report: CompareReport): void {\n context.log('info', '\\nPerformance stats:')\n context.log('info', ` ${compareConfig.bundleL.name}:`)\n printPerfReportLine(context, report.perfReportL)\n context.log('info', ` ${compareConfig.bundleR.name}:`)\n printPerfReportLine(context, report.perfReportR)\n context.log('info', '')\n}\n","// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport type { ModelSpec } from '@sdeverywhere/build'\nimport { dirname, join as joinPath, relative, resolve as resolvePath } from 'path'\nimport { fileURLToPath } from 'url'\n\nimport type { InlineConfig, Plugin as VitePlugin } from 'vite'\nimport { nodeResolve } from '@rollup/plugin-node-resolve'\n\nimport { sdeNameForVensimVarName } from './var-names'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\n/**\n * This is a virtual module plugin used to inject model-specific configuration\n * values into the generated worker bundle.\n *\n * This follows the \"Virtual Modules Convention\" described here:\n * https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention\n *\n * TODO: This could be simplified by using `vite-plugin-virtual` but that\n * doesn't seem to be working correctly in an ESM setting\n */\nfunction injectModelSpec(modelSpec: ModelSpec): VitePlugin {\n // Include the SDE variable ID with each spec\n const inputSpecs = modelSpec.inputs.map(i => {\n return {\n varId: sdeNameForVensimVarName(i.varName),\n ...i\n }\n })\n const outputSpecs = modelSpec.outputs.map(o => {\n return {\n varId: sdeNameForVensimVarName(o.varName),\n ...o\n }\n })\n\n const moduleSrc = `\nexport const startTime = ${modelSpec.startTime};\nexport const endTime = ${modelSpec.endTime};\nexport const inputSpecs = ${JSON.stringify(inputSpecs)};\nexport const outputSpecs = ${JSON.stringify(outputSpecs)};\n`\n\n const virtualModuleId = 'virtual:model-spec'\n const resolvedVirtualModuleId = '\\0' + virtualModuleId\n\n return {\n name: 'vite-plugin-virtual-custom',\n resolveId(id: string) {\n if (id === virtualModuleId) {\n return resolvedVirtualModuleId\n }\n },\n load(id: string) {\n if (id === resolvedVirtualModuleId) {\n return moduleSrc\n }\n }\n }\n}\n\nexport async function createViteConfigForBundle(prepDir: string, modelSpec: ModelSpec): Promise<InlineConfig> {\n // Use `template-bundle` as the root directory for the bundle project\n const root = resolvePath(__dirname, '..', 'template-bundle')\n\n // Calculate output directory relative to the template root\n // TODO: For now we write it to `prepDir`; make this configurable?\n const outDir = relative(root, prepDir)\n\n // Use the model worker from the staged directory\n // TODO: Make this configurable?\n const modelWorkerPath = joinPath(prepDir, 'staged', 'model', 'worker.js?raw')\n\n return {\n // Don't use an external config file\n configFile: false,\n\n // Use the root directory configured above\n root,\n\n // Don't clear the screen in dev mode so that we can see builder output\n clearScreen: false,\n\n // TODO: Disable vite output by default?\n // logLevel: 'silent',\n\n // Configure path aliases\n resolve: {\n alias: [\n // Inject the configured model worker\n {\n find: '@_model_worker_',\n replacement: modelWorkerPath\n },\n\n // XXX: Prevent Vite from using the `browser` section of `threads/package.json`\n // since we want to force the use of the general module (under dist-esm) that chooses\n // the correct implementation (Web Worker vs worker_threads) at runtime. Currently\n // Vite's library mode is browser focused, so using a `customResolver` seems to be\n // the easiest way to prevent Vite from picking up the `browser` exports.\n {\n find: 'threads',\n replacement: 'threads',\n customResolver: async function (source, importer, options) {\n // Note that we need to use `resolveId.call` here in order to provide the\n // right `this` context, which provides Rollup plugin functionality\n const customResolver = nodeResolve({ browser: false })\n const resolved = await customResolver.resolveId.call(this, source, importer, options)\n // Force the use of the `dist-esm` variant of the threads.js package\n if (source === 'threads/worker') {\n return resolved.id.replace('worker.mjs', 'dist-esm/worker/index.js')\n } else {\n return resolved.id.replace('index.mjs', 'dist-esm/index.js')\n }\n }\n }\n ]\n },\n\n plugins: [\n // Use a virtual module plugin to inject the model spec values\n injectModelSpec(modelSpec)\n ],\n\n build: {\n // Write output files to the configured directory (instead of the default `dist`);\n // note that this must be relative to the project `root`\n outDir,\n emptyOutDir: false,\n\n lib: {\n entry: './src/index.ts',\n formats: ['es'],\n fileName: () => 'check-bundle.js'\n },\n\n rollupOptions: {\n // Don't transform Node imports used by threads.js\n external: ['events', 'os', 'path', 'url'],\n\n // XXX: Insert custom code at the top of the generated bundle that defines\n // the special `__non_webpack_require__` function that is used by threads.js\n // in its Node implementation. This import ensures that threads.js uses\n // the native `worker_threads` implementation when using the bundle in a\n // Node environment. When importing the bundle for use in the browser,\n // Vite will transform this import into an empty module (it does not seem\n // to be necessary to define a polyfill).\n output: {\n banner: `\nimport * as worker_threads from 'worker_threads'\nlet __non_webpack_require__ = () => {\n return worker_threads;\n};\n`\n },\n\n onwarn: (warning, warn) => {\n // XXX: Suppress \"Use of eval is strongly discouraged\" warnings that are\n // triggered by use of the following pattern in threads.js:\n // eval(\"require\")(\"worker_threads\")\n // It would be nice to avoid use of `eval` there, but it's not critical for\n // our use case so we will suppress the warnings for now\n if (warning.code !== 'EVAL') {\n warn(warning)\n }\n }\n }\n }\n }\n}\n","// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\n/**\n * Helper function that converts a Vensim variable or subscript name\n * into a valid C identifier as used by SDE.\n * TODO: Import helper function from `compile` package instead\n */\nfunction sdeNameForVensimName(name: string): string {\n return (\n '_' +\n name\n .trim()\n .replace(/\"/g, '_')\n .replace(/\\s+!$/g, '!')\n .replace(/\\s/g, '_')\n .replace(/,/g, '_')\n .replace(/-/g, '_')\n .replace(/\\./g, '_')\n .replace(/\\$/g, '_')\n .replace(/'/g, '_')\n .replace(/&/g, '_')\n .replace(/%/g, '_')\n .replace(/\\//g, '_')\n .replace(/\\|/g, '_')\n .toLowerCase()\n )\n}\n\n/**\n * Helper function that converts a Vensim variable name (possibly containing\n * subscripts) into a valid C identifier as used by SDE.\n * TODO: Import helper function from `compile` package instead\n */\nexport function sdeNameForVensimVarName(varName: string): string {\n const m = varName.match(/([^[]+)(?:\\[([^\\]]+)\\])?/)\n if (!m) {\n throw new Error(`Invalid Vensim name: ${varName}`)\n }\n let id = sdeNameForVensimName(m[1])\n if (m[2]) {\n const subscripts = m[2].split(',').map(x => sdeNameForVensimName(x))\n id += `[${subscripts.join('][')}]`\n }\n\n return id\n}\n","// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport { dirname, relative, join as joinPath, resolve as resolvePath } from 'path'\nimport { fileURLToPath } from 'url'\n\nimport type { Alias, InlineConfig } from 'vite'\n// import globPlugin from 'vite-plugin-glob'\nimport { nodeResolve } from '@rollup/plugin-node-resolve'\n\nimport type { SuiteSummary } from '@sdeverywhere/check-core'\n\nimport type { CheckPluginOptions } from './options'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\nexport function createViteConfigForReport(\n options: CheckPluginOptions | undefined,\n prepDir: string,\n currentBundleName: string,\n currentBundlePath: string,\n testConfigPath: string,\n suiteSummary: SuiteSummary | undefined\n): InlineConfig {\n // Use `template-report` as the root directory for the report project\n const root = resolvePath(__dirname, '..', 'template-report')\n\n // Calculate output directory relative to the template root\n let reportPath: string\n if (options?.reportPath) {\n reportPath = options.reportPath\n } else {\n reportPath = joinPath(prepDir, 'check-report')\n }\n const outDir = relative(root, reportPath)\n\n // Convert the suite summary to JSON, which is what the app currently expects\n const suiteSummaryJson = suiteSummary ? JSON.stringify(suiteSummary) : ''\n\n const alias = (find: string, replacement: string) => {\n return {\n find,\n replacement\n } as Alias\n }\n\n // XXX: This provides custom handling for Node built-ins such as 'events' that are\n // referenced by the check bundle (specifically in the Node implementation of\n // threads.js). These are not actually used in the browser, so we just need\n // to provide no-op polyfills for these.\n const polyfillAlias = (find: string) => {\n return {\n find,\n replacement: find,\n customResolver: async function (_source, _importer, options) {\n const customResolver = nodeResolve()\n // Replace uses of Node built-ins (e.g. 'events') with the appropriate polyfill\n const customSource = `rollup-plugin-node-polyfills/polyfills/${find}`\n // Use this file as the \"importer\" so that we resolve `rollup-plugin-node-polyfills`\n // relative to `plugin-check/node_modules`. Without this workaround, the consuming\n // project would need `rollup-plugin-node-polyfills` as an explicit dependency, and\n // we want to avoid that since it's more of an implementation detail.\n const customImporter = __filename\n // Note that we need to use `resolveId.call` here in order to provide the\n // right `this` context, which provides Rollup plugin functionality\n const resolved = await customResolver.resolveId.call(this, customSource, customImporter, options)\n return resolved.id\n }\n } as Alias\n }\n\n return {\n // Don't use an external config file\n configFile: false,\n\n // Use the root directory configured above\n root,\n\n // Use `.` as the base directory (instead of the default `/`); this controls\n // how the path to the js/css files are generated in `index.html`\n base: '',\n\n // Load static files from `static` (instead of the default `public`)\n // publicDir: 'static',\n\n // Don't clear the screen in dev mode so that we can see builder output\n clearScreen: false,\n\n // TODO\n // logLevel: 'silent',\n\n optimizeDeps: {\n // Prevent Vite from examining other html files when scanning entrypoints\n // for dependency optimization\n entries: ['index.html'],\n\n // XXX: The threads.js implementation references `tiny-worker` as an optional\n // dependency, but it doesn't get used at runtime, so we can just exclude it\n // so that Vite doesn't complain in dev mode\n exclude: ['tiny-worker']\n },\n\n // Configure path aliases\n resolve: {\n alias: [\n // Use the configured \"baseline\" bundle if defined, otherwise use the \"empty\" bundle\n // (which will cause comparison tests to be skipped)\n alias('@_baseline_bundle_', options?.baseline ? options.baseline.path : '/src/empty-bundle.ts'),\n\n // Use the configured \"current\" bundle\n alias('@_current_bundle_', currentBundlePath),\n\n // Use the configured test config file\n alias('@_test_config_', testConfigPath),\n\n // Make the overlay use the `messages.html` file that is written to the prep directory\n alias('@_prep_', prepDir),\n\n // XXX: Include polyfills for these modules that are used in the Node-specific\n // implementation of threads.js; this allows us to use one bundle that works\n // in both Node and browser environments\n polyfillAlias('events'),\n polyfillAlias('os'),\n polyfillAlias('path'),\n // XXX: The following is only needed due to threads.js 1.7.0 importing `fileURLToPath`.\n // We use a no-op polyfill of our own for the time being.\n alias('url', '/src/url-polyfill.ts')\n ]\n },\n\n // Inject special values into the generated JS\n define: {\n // Inject the summary JSON into the build\n __SUITE_SUMMARY_JSON__: JSON.stringify(suiteSummaryJson),\n\n // Inject the baseline branch name\n __BASELINE_NAME__: JSON.stringify(options?.baseline?.name || ''),\n\n // Inject the current branch name\n __CURRENT_NAME__: JSON.stringify(currentBundleName)\n },\n\n plugins: [\n // Use `vite-plugin-glob` instead of Vite's built-in `import.meta.globEager`\n // because the plugin does a better job of handling HMR when the yaml files\n // are outside of the `template-report` app root directory.\n // globPlugin(),\n ],\n\n build: {\n // Write output files to the configured directory (instead of the default `dist`);\n // note that this must be relative to the project `root`\n outDir,\n\n // Write js/css files to `public` (instead of the default `<outDir>/assets`)\n assetsDir: '',\n\n rollupOptions: {\n output: {\n // XXX: Prevent vite from creating a separate `vendor.js` file\n manualChunks: undefined\n },\n\n onwarn: (warning, warn) => {\n // XXX: Suppress \"Use of eval is strongly discouraged\" warnings that are\n // triggered by use of the following pattern in threads.js:\n // eval(\"require\")(\"worker_threads\")\n // It would be nice to avoid use of `eval` there, but it's not critical for\n // our use case so we will suppress the warnings for now\n if (warning.code !== 'EVAL') {\n warn(warning)\n }\n }\n }\n },\n\n server: {\n // Run the dev server at `localhost:8081` by default\n port: options?.serverPort || 8081,\n\n // Open the app in the browser by default\n open: '/index.html',\n\n // XXX: Add a small delay, otherwise on macOS we sometimes get multiple\n // change events when a file is saved just once. That is a relatively\n // harmless issue except that it causes redundant messages in the console\n // and can cause extra churn when refreshing the app.\n watch: {\n awaitWriteFinish: {\n stabilityThreshold: 100\n }\n }\n }\n }\n}\n","// Copyright (c) 2022 Climate Interactive / New Venture Fund\n\nimport { dirname, relative, resolve as resolvePath } from 'path'\nimport { fileURLToPath } from 'url'\n\nimport type { InlineConfig } from 'vite'\nimport globPlugin from 'vite-plugin-glob'\nimport replace from '@rollup/plugin-replace'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\nexport function createViteConfigForTests(projDir: string, prepDir: string, mode: 'build' | 'watch'): InlineConfig {\n // Use `template-tests` as the root directory for the tests project\n const root = resolvePath(__dirname, '..', 'template-tests')\n\n // Include `*.check.yaml` files under the configured project root directory. This\n // glob path apparently must be a relative path (relative to the `template-tests/src`\n // directory where the glob is used).\n const templateSrcDir = resolvePath(root, 'src')\n const relProjDir = relative(templateSrcDir, projDir)\n // TODO: Use yamlPath from options\n const yamlPath = `${relProjDir}/**/*.check.yaml`\n\n // // Read the `package.json` for the template project\n // const pkgPath = resolvePath(root, 'package.json')\n // const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n\n // Calculate output directory relative to the template root\n // TODO: For now we write it to `prepDir`; make this configurable?\n const outDir = relative(root, prepDir)\n\n return {\n // Don't use an external config file\n configFile: false,\n\n // Use the root directory configured above\n root,\n\n // Don't clear the screen in dev mode so that we can see builder output\n clearScreen: false,\n\n // TODO: Disable vite output by default?\n // logLevel: 'silent',\n\n plugins: [\n // Inject special values into the generated JS\n // TODO: We currently have to use `@rollup/plugin-replace` instead of Vite's\n // built-in `define` feature because the latter does not seem to run before\n // the glob plugin, and that requires the glob to be injected as a literal;\n // `plugin-replace` seems to work as long as we order it before `plugin-glob`.\n // Maybe we can switch back to `define` once we move to Vite 3.x.\n replace({\n preventAssignment: true,\n values: {\n // Inject the glob pattern for matching check yaml files\n __YAML_PATH__: JSON.stringify(yamlPath)\n }\n }),\n\n // Use `vite-plugin-glob` instead of Vite's built-in `import.meta.globEager`\n // because the plugin does a better job of handling HMR when the yaml files\n // are outside of the `template-report` app root directory.\n globPlugin()\n ],\n\n build: {\n // Write output files to the configured directory (instead of the default `dist`);\n // note that this must be relative to the project `root`\n outDir,\n emptyOutDir: false,\n\n lib: {\n entry: './src/index.ts',\n formats: ['es'],\n fileName: () => 'check-tests.js'\n },\n\n // Enable watch mode if requested\n watch: mode === 'watch' && {},\n\n rollupOptions: {\n // Prevent dependencies from being included in packaged library\n // TODO: For now we include check-core in the packaged library so that its\n // dependencies are correctly resolved at runtime. Ideally this would only\n // include a couple functions that are used for defining tests, but Vite 2.x\n // does not implement tree shaking for ES libraries, which means the generated\n // library is much larger than it needs to be. Once we upgrade to Vite 3.x,\n // the generated library should be smaller; see related fix:\n // https://github.com/vitejs/vite/pull/8737\n // external: Object.keys(pkg.dependencies)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA;AACA;AAGA;AAKA;;;ACTA;AAEA;AAeA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,4BACE,SACA,QACA,SAC6B;AAC7B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,KAAK,YAAY,IAAI;AAC3B,QAAI;AACJ,UAAM,YAA+B;AAAA,MACnC,YAAY,cAAY;AACtB,cAAM,MAAM,KAAK,MAAM,WAAW,GAAG;AACrC,cAAM,WAAW,KAAK,MAAM,MAAM,CAAC,IAAI;AACvC,YAAI,iBAAiB,UAAa,WAAW,cAAc;AACzD,yBAAe;AACf,kBAAQ,IAAI,QAAQ,GAAG,WAAW;AAAA,QACpC;AAAA,MACF;AAAA,MACA,YAAY,YAAU;AACpB,YAAI;AACF,gBAAM,KAAK,YAAY,IAAI;AAC3B,gBAAM,UAAY,OAAK,MAAM,KAAM,QAAQ,CAAC;AAC5C,kBAAQ,IAAI,QAAQ;AAAA,0BAA6B,UAAU;AAG3D,gBAAM,kBAAkB,kBAAkB,SAAS,OAAO,aAAa,OAAO;AAE9E,cAAI,OAAO,eAAe;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