Skip to content

Commit

Permalink
Normalize file endings (#139)
Browse files Browse the repository at this point in the history
* Normalize runtime file endings

* Rename transpiler files

* transpiler

* repl

* fix rollup and lint

* lint

* fix build / tests

* fix test imports
  • Loading branch information
kungfooman authored Feb 16, 2024
1 parent daff89b commit b3ae6db
Show file tree
Hide file tree
Showing 69 changed files with 172 additions and 174 deletions.
File renamed without changes.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
"name": "runtime-type-inspector",
"version": "2.0.4",
"description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
"main": "build/rti-transpiler.cjs",
"module": "build/rti-transpiler.mjs",
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w",
"build:atBabelCore": "rollup -c --environment target:atBabelCore",
"build:dts": "tsc src-transpiler/index.mjs --outDir types/transpiler --allowJs --declaration --emitDeclarationOnly --target esnext",
"build:dts": "tsc src-transpiler/index.js --outDir types/transpiler --allowJs --declaration --emitDeclarationOnly --target esnext",
"build:types": "npm run build:dts && rollup -c --environment target:types",
"test": "npm run test:update && node test.mjs && node test_runtime.mjs",
"test:update": "node gen_tests.mjs > test/typechecking.json",
"test": "npm run test:update && node test.js && node test_runtime.js",
"test:update": "node gen_tests.js > test/typechecking.json",
"lint": "eslint --ext .js,.mjs,.cjs src-transpiler src-runtime",
"docs": "jsdoc -c jsdoc.json"
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions repl/importmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function importFile(content) {
return "data:text/javascript;base64," + btoa(content);
}
const imports = {
"@runtime-type-inspector/runtime" : '../src-runtime/index.mjs',
"@runtime-type-inspector/transpiler": '../src-transpiler/index.mjs',
"@babel/parser": "./babel-parser.mjs",
"display-anything": "./node_modules/display-anything/src/index.js",
"test-import-validation-b": "../test/typechecking/import-validation/b.js",
//"@babel/helper-plugin-utils": "./babel-helper-plugin-utils.mjs",
//"@babel/plugin-syntax-typescript": "./babel-plugin-syntax-typescript.mjs",
"fs": importFile("export default {};"),
"typescript": importFile("export default ts;"), // UMD import
"@runtime-type-inspector/runtime" : '../src-runtime/index.js',
"@runtime-type-inspector/transpiler": '../src-transpiler/index.js',
"@babel/parser" : "./babel-parser.js",
"display-anything" : "./node_modules/display-anything/src/index.js",
"test-import-validation-b" : "../test/typechecking/import-validation/b.js",
//"@babel/helper-plugin-utils" : "./babel-helper-plugin-utils.js",
//"@babel/plugin-syntax-typescript" : "./babel-plugin-syntax-typescript.js",
"fs" : importFile("export default {};"),
"typescript" : importFile("export default ts;"), // UMD import
};
if (location.host.includes('runtimetypeinspector.org') || location.port === '7000') {
imports['@runtime-type-inspector/runtime' ] = './node_modules/@runtime-type-inspector/runtime/index.mjs';
Expand Down
2 changes: 1 addition & 1 deletion repl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Left: <input id="left" type="checkbox" checked></input>
Right: <input id="right" type="checkbox" checked></input>
<script type="module">
import * as Index from "./index.mjs";
import * as Index from "./index.js";
Object.assign(window, {...Index});
</script>
</body>
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions rollup.config.mjs → rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import terser from '@rollup/plugin-terser';
import dts from 'rollup-plugin-dts';
import {visualizer} from 'rollup-plugin-visualizer';
import json from '@rollup/plugin-json';
//import {addTypeChecks} from "./src-transpiler/typeInserter.mjs";
//const {addTypeChecks} = await import("runtime-type-inspector/src-transpiler/typeInserter.mjs");
//import {addTypeChecks} from "./src-transpiler/typeInserter.js";
//const {addTypeChecks} = await import("runtime-type-inspector/src-transpiler/typeInserter.js");
import commonjs from '@rollup/plugin-commonjs';
/** @typedef {import('rollup').RollupOptions} RollupOptions */
/** @typedef {import('rollup').Plugin} Plugin */
Expand Down Expand Up @@ -174,8 +174,8 @@ export default (args) => {
['release', /*'debug', 'profiler', 'min', 'rti'*/].forEach((t) => {
['es5', 'es6'].forEach((m) => {
if (envTarget === null || envTarget === t || envTarget === m || envTarget === `${t}_${m}`) {
targets.push(buildTarget('rtiTranspiler', 'src-transpiler/index.mjs', '@runtime-type-inspector/transpiler/index', t, m));
targets.push(buildTarget('rtiRuntime' , 'src-runtime/index.mjs' , '@runtime-type-inspector/runtime/index' , t, m));
targets.push(buildTarget('rtiTranspiler', 'src-transpiler/index.js', '@runtime-type-inspector/transpiler/index', t, m));
targets.push(buildTarget('rtiRuntime' , 'src-runtime/index.js' , '@runtime-type-inspector/runtime/index' , t, m));
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src-runtime/TypePanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {assertMode } from "./assertMode.js";
import {options } from "./options.mjs";
import {warnedTable} from "./warnedTable.mjs";
import {options } from "./options.js";
import {warnedTable} from "./warnedTable.js";
import {Warning } from "./Warning.js";
/**
* @param {HTMLDivElement} div - The <div>.
Expand Down
8 changes: 4 additions & 4 deletions src-runtime/Warning.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {options} from "./options.mjs";
import {options} from "./options.js";
import {DisplayAnything} from 'display-anything';
/**
* @todo Also construct a Node.js version, WarningConsole and WarningBrowser
Expand All @@ -21,7 +21,7 @@ class Warning {
_dbg = false;
/** @type {any} */
_value;
/** @type {import('./validateType.mjs').Type} */
/** @type {import('./validateType.js').Type} */
_expect;
constructor(msg, value, expect, loc, name) {
this.loc = loc;
Expand Down Expand Up @@ -82,8 +82,8 @@ class Warning {
return this._value;
}
/**
* @type {import('./validateType.mjs').Type}
* @param {import('./validateType.mjs').Type} _ - The expected type.
* @type {import('./validateType.js').Type}
* @param {import('./validateType.js').Type} _ - The expected type.
*/
set expect(_) {
const val = new DisplayAnything(_);
Expand Down
2 changes: 1 addition & 1 deletion src-runtime/assertMode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @returns {asserts mode is typeof import('./options.mjs').options.mode} asd
* @returns {asserts mode is typeof import('./options.js').options.mode} asd
* @param {string} mode - The mode to test.
*/
function assertMode(mode) {
Expand Down
4 changes: 2 additions & 2 deletions src-runtime/createType.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {createTypeFromIndexedAccess} from "./createTypeFromIndexedAccess.js";
import {createTypeFromKeyof } from "./createTypeFromKeyof.js";
import {createTypeFromMapping } from "./createTypeFromMapping.js";
/**
* @param {string|import('./validateType.mjs').Type} expect - The supposed type information of said value.
* @param {string|import('./validateType.js').Type} expect - The supposed type information of said value.
* @param {console["warn"]} warn - Function to warn with.
* @returns {import('./validateType.mjs').Type|undefined} - New type that can be used for validatoin
* @returns {import('./validateType.js').Type|undefined} - New type that can be used for validatoin
*/
function createType(expect, warn) {
const mapping = resolveType(expect, 'mapping', warn);
Expand Down
4 changes: 2 additions & 2 deletions src-runtime/createType.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createType } from './createType.js';
import {registerTypedef} from './registerTypedef.mjs';
import {registerTypedef} from './registerTypedef.js';
function prepare() {
/**
* @typedef {{a: 'aa', b: 'bb', c: 'cc'}} Obj
Expand Down Expand Up @@ -28,7 +28,7 @@ function prepare() {
}
function test1() {
prepare();
/** @type {import('./validateUnion.mjs').Union} */
/** @type {import('./validateUnion.js').Union} */
// @ts-ignore
const t = createType("ObjValuesTypedef2", console.warn);
if (!t) {
Expand Down
8 changes: 4 additions & 4 deletions src-runtime/createTypeFromIndexedAccess.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//import {createType } from "./createType.js";
import {resolveType } from "./resolveType.js";
//import {replaceType } from "./replaceType.js";
import {getTypeKeys } from "./validateKeyof.mjs";
import {getTypeKeys } from "./getTypeKeys.js";
/**
* @param {import('./validateIndexedAccess.js').IndexedAccess} expect - The supposed type information of said value.
* @param {console["warn"]} warn - Function to warn with.
* @returns {import('./validateType.mjs').TypeObject|undefined} - New type that can be used for validation.
* @returns {import('./validateType.js').TypeObject|undefined} - New type that can be used for validation.
*/
function createTypeFromIndexedAccess(expect, warn) {
const {object, index} = expect;
const resolvedObject = resolveType(object, 'object', warn);
if (resolvedObject) {
if (resolvedObject) {
// const indexType = createType(index, warn);
const indexKeys = getTypeKeys(index, warn);
//console.log("createTypeFromIndexedAccess", {resolvedObject, object, index, indexType, indexKeys});
if (!indexKeys) {
warn('createTypeFromIndexedAccess: missing indexKeys');
return;
}
/** @type {import('./validateType.mjs').Type[]} */
/** @type {import('./validateType.js').Type[]} */
const members = [];
for (const indexKey of indexKeys) {
let prop = resolvedObject.properties[indexKey];
Expand Down
4 changes: 2 additions & 2 deletions src-runtime/createTypeFromKeyof.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {resolveType} from "./resolveType.js";
/**
* @todo reuse this function in createTypeFromMapping/getTypeKeys
* @param {import('./validateKeyof.mjs').Keyof} expect - The supposed type information of said value.
* @param {import('./validateKeyof.js').Keyof} expect - The supposed type information of said value.
* @param {console["warn"]} warn - Function to warn with.
* @returns {import('./validateType.mjs').TypeObject|undefined} - New type that can be used for validatoin
* @returns {import('./validateType.js').TypeObject|undefined} - New type that can be used for validatoin
*/
function createTypeFromKeyof(expect, warn) {
const {argument} = expect;
Expand Down
4 changes: 2 additions & 2 deletions src-runtime/createTypeFromKeyof.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createType } from './createType.js';
import {registerTypedef} from './registerTypedef.mjs';
import {registerTypedef} from './registerTypedef.js';
function prepare() {
/**
* @template T
Expand Down Expand Up @@ -27,7 +27,7 @@ function prepare() {
}
function test1() {
prepare();
/** @type {import('./validateUnion.mjs').Union} */
/** @type {import('./validateUnion.js').Union} */
const newType = createType('ObjKeysTypedef', console.warn);
if (!newType) {
console.warn('t is not defined.');
Expand Down
12 changes: 6 additions & 6 deletions src-runtime/createTypeFromMapping.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {replaceType } from "./replaceType.js";
import {getTypeKeys } from "./validateKeyof.mjs";
import {typedefs } from "./registerTypedef.mjs";
import {replaceType} from "./replaceType.js";
import {getTypeKeys} from "./getTypeKeys.js";
import {typedefs } from "./registerTypedef.js";
/**
* @param {string|import('./validateMapping.mjs').Mapping} expect - The supposed type information of said value.
* @param {string|import('./validateMapping.js').Mapping} expect - The supposed type information of said value.
* @param {console["warn"]} warn - Function to warn with.
* @returns {import('./validateType.mjs').TypeObject|undefined} - New type that can be used for validation.
* @returns {import('./validateType.js').TypeObject|undefined} - New type that can be used for validation.
*/
function createTypeFromMapping(expect, warn) {
/** @todo some kind of resolveType(expect, 'mapping', depth = 0) function */
Expand All @@ -17,7 +17,7 @@ function createTypeFromMapping(expect, warn) {
warn('validateMapping: missing typeKeys');
return;
}
/** @type {Record<string, import('./validateType.mjs').Type>} */
/** @type {Record<string, import('./validateType.js').Type>} */
const properties = {};
for (const typeKey of typeKeys) {
const cloneResult = structuredClone(result);
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src-runtime/getTypeKeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {variables} from "./registerVariable.js";
import {typedefs } from "./registerTypedef.mjs";
import {typedefs } from "./registerTypedef.js";
/**
* @example
* getTypeKeys({type: 'typeof', argument: 'DataTypeMap'}, console.warn);
Expand Down
36 changes: 36 additions & 0 deletions src-runtime/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export * from './assertMode.js';
export * from './createType.js';
export * from './createTypeFromIndexedAccess.js';
export * from './createTypeFromKeyof.js';
export * from './createTypeFromMapping.js';
export * from './customTypes.js';
export * from './customValidations.js';
export * from './getTypeKeys.js';
export * from './inspectType.js';
export * from './isObject.js';
export * from './makeJSDoc.js';
export * from './options.js';
export * from './partition.js';
export * from './registerClass.js';
export * from './registerImportNamespaceSpecifier.js';
export * from './registerTypedef.js';
export * from './registerVariable.js';
export * from './replaceType.js';
export * from './resolveType.js';
export * from './TypePanel.js';
export * from './validateArray.js';
export * from './validateDivision.js';
export * from './validateIntersection.js';
export * from './validateKeyof.js';
export * from './validateMap.js';
export * from './validateMapping.js';
export * from './validateNumber.js';
export * from './validateObject.js';
export * from './validateRecord.js';
export * from './validateTuple.js';
export * from './validateType.js';
export * from './validateTypedef.js';
export * from './validateUnion.js';
export * from './warnedTable.js';
export * from './Warning.js';
export * from './youCanAddABreakpointHere.js';
36 changes: 0 additions & 36 deletions src-runtime/index.mjs

This file was deleted.

6 changes: 3 additions & 3 deletions src-runtime/inspectType.mjs → src-runtime/inspectType.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {options } from './options.mjs';
import {warnedTable } from './warnedTable.mjs';
import {validateType } from './validateType.mjs';
import {options } from './options.js';
import {warnedTable } from './warnedTable.js';
import {validateType } from './validateType.js';
import {partition } from './partition.js';
import {Warning } from './Warning.js';
import {typePanel } from './TypePanel.js';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src-runtime/resolveType.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {typedefs} from "./registerTypedef.mjs";
import {typedefs} from "./registerTypedef.js";
/**
* @param {any} type - The type.
* @param {string} as - What to resolve as.
Expand Down
2 changes: 1 addition & 1 deletion src-runtime/resolveType.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {registerTypedef} from './registerTypedef.mjs';
import {registerTypedef} from './registerTypedef.js';
import {resolveType } from './resolveType.js';
function prepare() {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {validateType} from "./validateType.mjs";
import {validateType} from "./validateType.js";
/**
* @param {*} value - The actual value that we need to validate.
* @param {*} expect - The supposed type information of said value.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src-runtime/validateIndexedAccess.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef {object} IndexedAccess
* @property {'indexedAccess'} type - The type.
* @property {import('./validateType.mjs').Type} object - The object, for example `Obj`
* @property {import('./validateType.mjs').Type} index - The index, for example `{type: 'keyof', argument: 'Obj'}`
* @property {import('./validateType.js').Type} object - The object, for example `Obj`
* @property {import('./validateType.js').Type} index - The index, for example `{type: 'keyof', argument: 'Obj'}`
*/
2 changes: 1 addition & 1 deletion src-runtime/validateIntersection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {validateType} from "./validateType.mjs";
import {validateType} from "./validateType.js";
/**
* @param {*} value - The actual value that we need to validate.
* @param {*} expect - The supposed type information of said value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {getTypeKeys} from "./getTypeKeys.js";
/**
* @typedef {object} Keyof
* @property {'keyof'} iterable - The type.
* @property {import('./validateType.mjs').Type} argument - The argument.
* @property {import('./validateType.js').Type} argument - The argument.
*/
/**
* @param {*} value - The actual value that we need to validate.
Expand All @@ -27,4 +27,4 @@ function validateKeyof(value, expect, loc, name, critical, warn, depth) {
}
return ret;
}
export {getTypeKeys, validateKeyof};
export {validateKeyof};
2 changes: 1 addition & 1 deletion src-runtime/validateMap.mjs → src-runtime/validateMap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {validateType} from "./validateType.mjs";
import {validateType} from "./validateType.js";
/**
* @todo Implement checking all possible key/val types
* @param {*} value - The actual value that we need to validate.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {createTypeFromMapping} from "./createTypeFromMapping.js";
import {validateType } from "./validateType.mjs";
import {validateType } from "./validateType.js";
/**
* @typedef {object} Mapping
* @property {import('./validateType.mjs').Type} iterable - The iterable.
* @property {import('./validateType.js').Type} iterable - The iterable.
* @property {string} element - The element.
* @property {import('./validateType.mjs').Type} result - The result.
* @property {import('./validateType.js').Type} result - The result.
*/
/**
* @param {*} value - The actual value that we need to validate.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {validateType} from "./validateType.mjs";
import {options } from "./options.mjs";
import {validateType} from "./validateType.js";
import {options } from "./options.js";
import {isObject } from "./isObject.js";
/**
* @param {*} value - The actual value that we need to validate.
Expand Down
Loading

0 comments on commit b3ae6db

Please sign in to comment.