Merge pull request #4 from websnacksjs/fix/nodejs10-support
Fix: support nodejs v10
This commit is contained in:
commit
4d96993ae8
7 changed files with 52 additions and 11 deletions
|
|
@ -5,8 +5,8 @@
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"jsxFactory": "createElement",
|
"jsxFactory": "createElement",
|
||||||
"target": "ES2019",
|
"target": "ES2018",
|
||||||
"lib": ["ES2019"],
|
"lib": ["ES2018"],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
|
|
|
||||||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -62,9 +62,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.12.38",
|
"version": "10.17.24",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.38.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.24.tgz",
|
||||||
"integrity": "sha512-75eLjX0pFuTcUXnnWmALMzzkYorjND0ezNEycaKesbUBg9eGZp4GHPuDmkRc4mQQvIpe29zrzATNRA6hkYqwmA==",
|
"integrity": "sha512-5SCfvCxV74kzR3uWgTYiGxrd69TbT1I6+cMx1A5kEly/IVveJBimtAMlXiEyVFn5DvUFewQWxOOiJhlxeQwxgA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/ws": {
|
"@types/ws": {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "types.d.ts",
|
"types": "types.d.ts",
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
"test": "ts-node --project=test/tsconfig.json test/run-tests.ts"
|
"test": "ts-node --project=test/tsconfig.json test/run-tests.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "~12",
|
"@types/node": "~10",
|
||||||
"@types/ws": "^7.2.4",
|
"@types/ws": "^7.2.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^3.0.2",
|
"@typescript-eslint/eslint-plugin": "^3.0.2",
|
||||||
"@typescript-eslint/parser": "^3.0.2",
|
"@typescript-eslint/parser": "^3.0.2",
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,21 @@ import * as path from "path";
|
||||||
const ROOT_DIR = path.resolve(__dirname, "..");
|
const ROOT_DIR = path.resolve(__dirname, "..");
|
||||||
const DIST_DIR = path.join(ROOT_DIR, "dist");
|
const DIST_DIR = path.join(ROOT_DIR, "dist");
|
||||||
|
|
||||||
fs.rmdirSync(DIST_DIR, { recursive: true });
|
const rmdirRecursive = (dirPath: string): void => {
|
||||||
|
if (!fs.existsSync(dirPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const entryNames = fs.readdirSync(dirPath);
|
||||||
|
for (const entryName of entryNames) {
|
||||||
|
const entryPath = path.join(dirPath, entryName);
|
||||||
|
const dirent = fs.lstatSync(entryPath);
|
||||||
|
if (dirent.isDirectory()) {
|
||||||
|
rmdirRecursive(entryPath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(entryPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.rmdirSync(dirPath);
|
||||||
|
};
|
||||||
|
|
||||||
|
rmdirRecursive(DIST_DIR);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import { Component, Element, HTMLElement } from "./component";
|
import { Component, Element, HTMLElement } from "./component";
|
||||||
import { HTMLAttributes } from "./jsx";
|
import { HTMLAttributes } from "./jsx";
|
||||||
|
import { flatDeep } from "./utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an HTMLElement from a custom Component.
|
* Create an HTMLElement from a custom Component.
|
||||||
|
|
@ -42,7 +43,7 @@ export function createElement(
|
||||||
...children: Element[]
|
...children: Element[]
|
||||||
): HTMLElement {
|
): HTMLElement {
|
||||||
// Flatten the children array so we can accept arrays as children.
|
// Flatten the children array so we can accept arrays as children.
|
||||||
const normalizedChildren = children.flat();
|
const normalizedChildren = flatDeep(children);
|
||||||
if (type instanceof Function) {
|
if (type instanceof Function) {
|
||||||
return type({ ...props, children: normalizedChildren });
|
return type({ ...props, children: normalizedChildren });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
src/utils.ts
23
src/utils.ts
|
|
@ -48,3 +48,26 @@ export const purgeModuleAndDepsFromCache = (modName: string): void => {
|
||||||
}
|
}
|
||||||
delete require.cache[modPath];
|
delete require.cache[modPath];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Flattenable<T> = Array<T | Flattenable<T>>;
|
||||||
|
|
||||||
|
const flatDeepRec = <T>(arr: Flattenable<T>, d: number): T[] => {
|
||||||
|
if (d <= 0) {
|
||||||
|
return arr.slice() as T[];
|
||||||
|
}
|
||||||
|
|
||||||
|
let acc = [] as T[];
|
||||||
|
for (const val of arr) {
|
||||||
|
acc = acc.concat(Array.isArray(val) ? flatDeepRec(arr, d - 1) : val);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flatten an arbitrarily-deeply nested array into a flat array.
|
||||||
|
*
|
||||||
|
* @param arr Array to flatten.
|
||||||
|
*
|
||||||
|
* @return Flattened array.
|
||||||
|
*/
|
||||||
|
export const flatDeep = <T>(arr: Flattenable<T>): T[] => flatDeepRec(arr, 1);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"module": "CommonJS",
|
"module": "CommonJS",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"target": "ES2019",
|
"target": "ES2018",
|
||||||
"lib": ["ES2019"],
|
"lib": ["ES2018"],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue