@runtime-type-inspector/plugin-rollup 5.0.3 → 5.0.4
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/index.mjs +33 -1
- package/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
+
import {existsSync, readFileSync} from 'fs';
|
|
2
|
+
import {join} from 'path';
|
|
1
3
|
import {createFilter} from '@rollup/pluginutils';
|
|
2
4
|
import {
|
|
3
5
|
addTypeChecks, expandType, compareAST, code2ast2code
|
|
4
6
|
} from '@runtime-type-inspector/transpiler';
|
|
7
|
+
/**
|
|
8
|
+
* Host project version funneled into the emitted header (`setProjectVersion`
|
|
9
|
+
* in `Download log` meta): explicit option wins, else the version from the
|
|
10
|
+
* host package.json in the build working directory, else unset (the log
|
|
11
|
+
* then nudges toward setting it).
|
|
12
|
+
* @param {string} [explicit] - Explicit `projectVersion` option.
|
|
13
|
+
* @returns {string|undefined} Resolved version or undefined.
|
|
14
|
+
*/
|
|
15
|
+
function resolveProjectVersion(explicit) {
|
|
16
|
+
if (explicit !== undefined && explicit !== null) {
|
|
17
|
+
return explicit;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const path = join(process.cwd(), 'package.json');
|
|
21
|
+
if (!existsSync(path)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const {version} = JSON.parse(readFileSync(path, 'utf8'));
|
|
25
|
+
if (typeof version === 'string' && version) {
|
|
26
|
+
return version;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// No readable host package.json: leave unset (log says so).
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
5
33
|
/**
|
|
6
34
|
* @typedef OptionsProps
|
|
7
35
|
* @property {boolean} [enable] - Enable or disable entire plugin. Defaults to true.
|
|
@@ -13,6 +41,9 @@ import {
|
|
|
13
41
|
* @property {boolean} [inspectIndexedAccess] - Whether indexed accesses like
|
|
14
42
|
* `arr[i]` are wrapped for bounds and integer validation. Disable to drop
|
|
15
43
|
* indexed access inspection entirely. Defaults to true.
|
|
44
|
+
* @property {string} [projectVersion] - Host project version for `Download
|
|
45
|
+
* log` meta. Defaults to the host package.json version in the build working
|
|
46
|
+
* directory; unset when none is readable (the log then nudges to set it).
|
|
16
47
|
*/
|
|
17
48
|
/**
|
|
18
49
|
* @typedef {OptionsProps & import('@runtime-type-inspector/transpiler').Options} Options
|
|
@@ -45,7 +76,8 @@ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles, ..
|
|
|
45
76
|
code = addTypeChecks(code, {
|
|
46
77
|
expandType,
|
|
47
78
|
filename: id,
|
|
48
|
-
...options
|
|
79
|
+
...options,
|
|
80
|
+
projectVersion: resolveProjectVersion(options.projectVersion),
|
|
49
81
|
});
|
|
50
82
|
return {
|
|
51
83
|
code,
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtime-type-inspector/plugin-rollup",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.4",
|
|
5
5
|
"description": "Rollup plugin for https://runtimetypeinspector.org/",
|
|
6
6
|
"main": "index.mjs",
|
|
7
7
|
"types": "index.mjs",
|
|
8
8
|
"author": "Hermann Rolfes (kungfooman)",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@runtime-type-inspector/transpiler": "^5.0.
|
|
11
|
+
"@runtime-type-inspector/transpiler": "^5.0.4",
|
|
12
12
|
"@rollup/pluginutils": "^5.1.0",
|
|
13
13
|
"rollup": "^3.29.4"
|
|
14
14
|
}
|