@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.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/index.cjs +519 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +496 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
- package/template-bundle/package.json +8 -0
- package/template-bundle/src/bundle.ts +172 -0
- package/template-bundle/src/empty-model-spec.ts +15 -0
- package/template-bundle/src/index.ts +3 -0
- package/template-bundle/src/inputs.ts +139 -0
- package/template-bundle/src/outputs.ts +36 -0
- package/template-bundle/src/worker.js +9 -0
- package/template-bundle/tsconfig.json +27 -0
- package/template-report/index.html +27 -0
- package/template-report/package.json +6 -0
- package/template-report/src/empty-bundle.ts +23 -0
- package/template-report/src/empty-test-config.ts +24 -0
- package/template-report/src/env.d.ts +7 -0
- package/template-report/src/global.css +22 -0
- package/template-report/src/index.ts +56 -0
- package/template-report/src/messages.html +6 -0
- package/template-report/src/overlay.ts +32 -0
- package/template-report/src/url-polyfill.ts +10 -0
- package/template-report/tsconfig.json +31 -0
- package/template-tests/package.json +5 -0
- package/template-tests/src/env.d.ts +5 -0
- package/template-tests/src/index.ts +82 -0
- package/template-tests/tsconfig.json +19 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) 2022 Climate Interactive / New Venture Fund
|
|
2
|
+
|
|
3
|
+
import messagesHtml from '@_prep_/messages.html?raw'
|
|
4
|
+
|
|
5
|
+
// This constant is exported only for HMR handling within this file; it is
|
|
6
|
+
// not intended to be consumed by outside modules
|
|
7
|
+
export const messages = messagesHtml
|
|
8
|
+
|
|
9
|
+
// Note that this initialization of the dev overlay component is kept in a
|
|
10
|
+
// separate file so that updates to `messages.html` cause HMR to reload only
|
|
11
|
+
// this file and the overlay element (rather than reloading the entire app)
|
|
12
|
+
export function initOverlay(): void {
|
|
13
|
+
updateOverlay(messages)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function updateOverlay(m: string): void {
|
|
17
|
+
const content = document.getElementById('overlay-content')
|
|
18
|
+
content.style.display = m && m.length > 0 ? 'unset' : 'none'
|
|
19
|
+
const text = document.getElementById('overlay-text')
|
|
20
|
+
text.innerHTML = m
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// In dev mode (with HMR enabled), when the `messages.html` file is updated,
|
|
24
|
+
// reload its contents into the overlay here instead of having the change
|
|
25
|
+
// event propagate up to the app shell. This makes the HMR event more
|
|
26
|
+
// precise and makes the text change show up immediately without having
|
|
27
|
+
// to reload other parts of the app.
|
|
28
|
+
if (import.meta.hot) {
|
|
29
|
+
import.meta.hot.accept(newModule => {
|
|
30
|
+
updateOverlay(newModule.messages)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) 2022 Climate Interactive / New Venture Fund
|
|
2
|
+
|
|
3
|
+
// XXX: This is a workaround for an issue in which threads.js uses `fileURLToPath`
|
|
4
|
+
// (from Node's 'util' module), but that function is not included in the
|
|
5
|
+
// `rollup-plugin-node-polyfills` package we use in the Vite config, so we roll
|
|
6
|
+
// our own no-op polyfill here. This does not actually get used at runtime
|
|
7
|
+
// in the browser because it is only referenced in the (unused) Node code path.
|
|
8
|
+
export function fileURLToPath(s: string): string {
|
|
9
|
+
return s
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
// Use "es2020" for dynamic import
|
|
5
|
+
"module": "es2020",
|
|
6
|
+
// Emit additional JS to ease support for importing CommonJS modules
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
// Use Node.js-style module resolution
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
// Enable warnings for transpilation-unsafe code
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
// Enable strict enforcement of `import type`
|
|
13
|
+
"importsNotUsedAsValues": "error",
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
// "types": ["vite/client", "vite-plugin-glob/client"],
|
|
18
|
+
"types": ["vite/client"],
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
// Use placeholders for path aliases that are configured in the Vite
|
|
21
|
+
// config; this prevents TypeScript from complaining but still allows
|
|
22
|
+
// for plugging in "real" files later
|
|
23
|
+
"baseUrl": ".",
|
|
24
|
+
"paths": {
|
|
25
|
+
"@_baseline_bundle_": ["./src/empty-bundle.ts"],
|
|
26
|
+
"@_current_bundle_": ["./src/empty-bundle.ts"],
|
|
27
|
+
"@_test_config_": ["./src/empty-test-config.ts"],
|
|
28
|
+
"@_prep_": ["./src"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright (c) 2022 Climate Interactive / New Venture Fund
|
|
2
|
+
|
|
3
|
+
import type { Bundle, CompareOptions, ConfigOptions, DatasetKey } from '@sdeverywhere/check-core'
|
|
4
|
+
|
|
5
|
+
import { DatasetManager, ScenarioManager } from '@sdeverywhere/check-core'
|
|
6
|
+
|
|
7
|
+
// Load the yaml test files. Note that we use `vite-plugin-glob` here
|
|
8
|
+
// instead of Vite's built-in `import.meta.globEager` because the plugin
|
|
9
|
+
// does a better job of handling HMR when the yaml files are outside of
|
|
10
|
+
// the `template-report` app root directory.
|
|
11
|
+
const yamlGlob = import.meta.importGlob(__YAML_PATH__, {
|
|
12
|
+
eager: true,
|
|
13
|
+
as: 'raw'
|
|
14
|
+
})
|
|
15
|
+
const tests: string[] = []
|
|
16
|
+
for (const yamlKey of Object.keys(yamlGlob)) {
|
|
17
|
+
const yaml = yamlGlob[yamlKey]
|
|
18
|
+
tests.push(yaml as unknown as string)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If an output variable is renamed, define the mapping from the old key
|
|
22
|
+
// to the new key here. If this step is omitted, the old variable will
|
|
23
|
+
// appear as being removed and the new variable will appear as being added,
|
|
24
|
+
// which will prevent them from being compared.
|
|
25
|
+
// TODO: Inject this from sde.config.ts file
|
|
26
|
+
const renamedDatasetKeys: Map<DatasetKey, DatasetKey> = new Map([
|
|
27
|
+
// ['Model_old_name', 'Model_new_name']
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
export interface BundleOptions {
|
|
31
|
+
nameL?: string
|
|
32
|
+
nameR?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TODO: Make this pluggable (with default implementation similar to below)
|
|
36
|
+
export async function getConfigOptions(
|
|
37
|
+
bundleL: Bundle | undefined,
|
|
38
|
+
bundleR: Bundle,
|
|
39
|
+
opts: BundleOptions
|
|
40
|
+
): Promise<ConfigOptions> {
|
|
41
|
+
// Only include compare options if the baseline bundle is defined (and
|
|
42
|
+
// has the same version)
|
|
43
|
+
let compareOptions: CompareOptions
|
|
44
|
+
if (bundleL && bundleL.version === bundleR.version) {
|
|
45
|
+
// Configure the set of input scenarios used for comparisons. This includes
|
|
46
|
+
// the default matrix of scenarios; for any output variable, the model will
|
|
47
|
+
// be run:
|
|
48
|
+
// - once with all inputs at their default
|
|
49
|
+
// - once with all inputs at their minimum
|
|
50
|
+
// - once with all inputs at their maximum
|
|
51
|
+
// - twice for each input
|
|
52
|
+
// - once with single input at its minimum
|
|
53
|
+
// - once with single input at its maximum
|
|
54
|
+
const scenarios = new ScenarioManager(bundleL, bundleR)
|
|
55
|
+
scenarios.addScenarioMatrix()
|
|
56
|
+
|
|
57
|
+
// Configure the dataset keys (corresponding to the available model outputs
|
|
58
|
+
// in the given bundles) that can be used to compare two versions of the model
|
|
59
|
+
const datasets = new DatasetManager(bundleL, bundleR, renamedDatasetKeys)
|
|
60
|
+
|
|
61
|
+
compareOptions = {
|
|
62
|
+
baseline: {
|
|
63
|
+
name: opts?.nameL || 'baseline',
|
|
64
|
+
bundle: bundleL
|
|
65
|
+
},
|
|
66
|
+
thresholds: [1, 5, 10],
|
|
67
|
+
scenarios,
|
|
68
|
+
datasets
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
current: {
|
|
74
|
+
name: opts?.nameR || 'current',
|
|
75
|
+
bundle: bundleR
|
|
76
|
+
},
|
|
77
|
+
check: {
|
|
78
|
+
tests
|
|
79
|
+
},
|
|
80
|
+
compare: compareOptions
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
// Use "es2020" for dynamic import
|
|
5
|
+
"module": "es2020",
|
|
6
|
+
// Emit additional JS to ease support for importing CommonJS modules
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
// Use Node.js-style module resolution
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
// Enable warnings for transpilation-unsafe code
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
// Enable strict enforcement of `import type`
|
|
13
|
+
"importsNotUsedAsValues": "error",
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"types": ["vite-plugin-glob/client"]
|
|
18
|
+
}
|
|
19
|
+
}
|