Skip to content

Commit edddb50

Browse files
authored
Move getHeader into Asserter, update Rollup/Webpack plugins (#51)
* Asserter: add getHeader * update plugin-rollup * Asserter: add "addHeader" option, disable headers for tests * update plugin-webpack to @runtime-type-inspector/transpiler@2.1.0 * update plugin-rollup to @runtime-type-inspector/transpiler@2.1.0 * update transpiler to @runtime-type-inspector/transpiler@2.1.0
1 parent 5f8e1e0 commit edddb50

File tree

10 files changed

+287
-281
lines changed

10 files changed

+287
-281
lines changed

@runtime-type-inspector/transpiler/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@runtime-type-inspector/transpiler",
3-
"version": "2.0.15",
3+
"version": "2.1.0",
44
"description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
5-
"main": "./index.cjs",
6-
"module": "./index.mjs",
7-
"types": "./types.d.ts",
5+
"main": "index.cjs",
6+
"module": "index.mjs",
7+
"types": "types.d.ts",
88
"repository": {
99
"type": "git",
1010
"url": "git+https://github.com/kungfooman/RuntimeTypeInspector.js.git"

plugin-rollup/index.mjs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@ import {
33
addTypeChecks, expandType, compareAST, code2ast2code
44
} from '@runtime-type-inspector/transpiler';
55
/**
6-
* Alternatively "import * as rti from ..." would also prevent "Unused external imports" warning...
7-
* or keeping log of every single call during RTI parsing.
8-
* @param {boolean} validateDivision
9-
*/
10-
function getHeader(validateDivision) {
11-
let header = "import { assertType, youCanAddABreakpointHere";
12-
if (validateDivision) {
13-
header += ", validateDivision";
14-
}
15-
header += ", registerTypedef, registerClass } from '@runtime-type-inspector/runtime';\n";
16-
// Prevent tree-shaking in UMD build so we can always "add a breakpoint here".
17-
header += "export * from '@runtime-type-inspector/runtime';\n";
18-
return header;
19-
}
20-
/**
21-
* @param {object} [options] - Optional options.
22-
* @param {boolean} [options.enable] - Enable or disable entire plugin. Defaults to true.
23-
* @param {boolean} [options.selftest] - Every once in a while Babel changes the AST, so we
6+
* @typedef Options
7+
* @property {boolean} [enable] - Enable or disable entire plugin. Defaults to true.
8+
* @property {boolean} [selftest] - Every once in a while Babel changes the AST, so we
249
* self-test Stringifier class to ensure its functionanlity.
25-
* @param {string[]} [options.ignoredFiles] - Ignore certain files which operate in a different
10+
* @property {string[]} [ignoredFiles] - Ignore certain files which operate in a different
2611
* context, for example framework/parsers/draco-worker.js operates as WebWorker (without RTI).
12+
* @property {boolean} [validateDivision] - Whether divisions are validated. Defaults to true.
13+
*/
14+
/**
15+
* @param {Options} [options] - Optional options.
2716
* @returns {import('rollup').Plugin} The rollup plugin.
2817
*/
29-
function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles} = {}) {
18+
function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles, validateDivision = true} = {}) {
3019
const filter = createFilter([
3120
'**/*.js'
3221
], []);
@@ -46,8 +35,6 @@ function runtimeTypeInspector({enable = true, selftest = false, ignoredFiles} =
4635
console.warn(`AST is NOT equal`);
4736
}
4837
}
49-
const validateDivision = true;
50-
code = getHeader(validateDivision) + code;
5138
// todo expose options to rollup plugin
5239
code = addTypeChecks(code, {
5340
validateDivision,

0 commit comments

Comments
 (0)