chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-04 01:12:55 -07:00
parent 9341cd9554
commit 1525c89733
274 changed files with 1755 additions and 2733 deletions

View File

@@ -1,9 +0,0 @@
Globals module for defining functions part of the global context - you need only to call *require* for this module and all globals will be registered. For example:
```js
require("globals");
setTimeout(function(){ console.log("Test"); }, 2000);
```
Global functions/objects are: setTimeout, clearTimeout, setInterval, clearInterval and console.

View File

@@ -1,6 +1,5 @@
// Required by TypeScript compiler
import "../ts-helpers";
import "../register-module-helpers";
// This method iterates all the keys in the source exports object and copies them to the destination exports one.

View File

@@ -1,6 +0,0 @@
/**
* Nothing exported. Side effects: registers ts-helpers and module-helpers
* @module "globals/core"
*/ /** */
import "../ts-helpers";
import "../register-module-helpers";

View File

@@ -1,6 +0,0 @@
{
"name": "core",
"main": "globals-core",
"types": "globals-core.d.ts",
"nativescript": {}
}

View File

@@ -1,10 +0,0 @@
import "./core";
import "./polyfills/timers";
import "./polyfills/animation";
import "./polyfills/dialogs";
import "./polyfills/text";
import "./polyfills/xhr";
import "./polyfills/fetch";
import "./decorators";

View File

@@ -1,4 +1,4 @@
/**
* Register globals such as setTimeout, setInterval, console etc.
*/
export function install();
export function initGlobal();

View File

@@ -0,0 +1,78 @@
export let hasInitGlobal = false;
function registerOnGlobalContext(moduleName: string, exportName: string): void {
Object.defineProperty(global, exportName, {
get: function () {
// We do not need to cache require() call since it is already cached in the runtime.
let m = global.loadModule(moduleName);
// Redefine the property to make sure the above code is executed only once.
let resolvedValue = m[exportName];
Object.defineProperty(global, exportName, { value: resolvedValue, configurable: true, writable: true });
return resolvedValue;
},
configurable: true
});
}
export function installPolyfills(moduleName: string, exportNames: string[]) {
if (global.__snapshot) {
const loadedModule = global.loadModule(moduleName);
exportNames.forEach(exportName => global[exportName] = loadedModule[exportName]);
} else {
exportNames.forEach(exportName => registerOnGlobalContext(moduleName, exportName));
}
}
export function initGlobal() {
console.log("initPolyfills called, init:", hasInitGlobal);
if (!hasInitGlobal) {
hasInitGlobal = true;
// apply global polyfills first
require("./core");
// DOM api polyfills
global.registerModule("timer", () => require("../timer"));
installPolyfills("timer", [
"setTimeout",
"clearTimeout",
"setInterval",
"clearInterval",
]);
global.registerModule("animation", () => require("../animation-frame"));
installPolyfills("animation", [
"requestAnimationFrame",
"cancelAnimationFrame",
]);
global.registerModule("ui-dialogs", () => require("../ui/dialogs"));
installPolyfills("ui-dialogs", [
"alert",
"confirm",
"prompt",
"login",
"action",
]);
global.registerModule("text", () => require("../text"));
installPolyfills("text", ["TextDecoder", "TextEncoder"]);
global.registerModule("xhr", () => require("../xhr"));
installPolyfills("xhr", [
"XMLHttpRequest",
"FormData",
"Blob",
"File",
"FileReader",
]);
global.registerModule("fetch", () => require("../fetch"));
installPolyfills("fetch", ["fetch", "Headers", "Request", "Response"]);
// Custom decorators
require("./decorators");
}
}

View File

@@ -1,6 +0,0 @@
{
"name": "globals",
"main": "globals",
"types": "globals.d.ts",
"nativescript": {}
}

View File

@@ -1,5 +0,0 @@
/**
* Installs animations polyfill.
* @module "globals/polyfills/animations"
*/ /** */
import "../../core";

View File

@@ -1,6 +0,0 @@
import "../../core";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("animation", () => require("../../../animation-frame"));
installPolyfills("animation", ["requestAnimationFrame", "cancelAnimationFrame"]);

View File

@@ -1,6 +0,0 @@
{
"name": "animation",
"main": "animation",
"types": "animation.d.ts",
"nativescript": {}
}

View File

@@ -1,5 +0,0 @@
/**
* Installs dialogs polyfill.
* @module "globals/polyfills/dialogs"
*/ /** */
import "../../core";

View File

@@ -1,6 +0,0 @@
import "../../core";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("ui-dialogs", () => require("../../../ui/dialogs"));
installPolyfills("ui-dialogs", ["alert", "confirm", "prompt", "login", "action"]);

View File

@@ -1,6 +0,0 @@
{
"name": "dialogs",
"main": "dialogs",
"types": "dialogs.d.ts",
"nativescript": {}
}

View File

@@ -1,6 +0,0 @@
/**
* Installs fetch polyfill.
* @module "globals/polyfills/fetch"
*/ /** */
import "../../core";
import "../../polyfills/xhr";

View File

@@ -1,8 +0,0 @@
import "../../core";
import "../../polyfills/xhr";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("fetch", () => require("../../../fetch"));
installPolyfills("fetch", ["fetch", "Headers", "Request", "Response"]);

View File

@@ -1,6 +0,0 @@
{
"name": "fetch",
"main": "fetch",
"types": "fetch.d.ts",
"nativescript": {}
}

View File

@@ -1,6 +0,0 @@
{
"name": "polyfill-helpers",
"main": "polyfill-helpers",
"types": "polyfill-helpers.d.ts",
"nativescript": {}
}

View File

@@ -1,6 +0,0 @@
/**
* Global polyfills helpers.
* @module "globals/polyfills/polyfill-helpers"
*/ /** */
import "../../core";
export declare function installPolyfills(moduleName: string, exportNames: string[]): void;

View File

@@ -1,26 +0,0 @@
import "../../core";
function registerOnGlobalContext(moduleName: string, exportName: string): void {
Object.defineProperty(global, exportName, {
get: function () {
// We do not need to cache require() call since it is already cached in the runtime.
let m = global.loadModule(moduleName);
// Redefine the property to make sure the above code is executed only once.
let resolvedValue = m[exportName];
Object.defineProperty(global, exportName, { value: resolvedValue, configurable: true, writable: true });
return resolvedValue;
},
configurable: true
});
}
export function installPolyfills(moduleName: string, exportNames: string[]) {
if (global.__snapshot) {
const loadedModule = global.loadModule(moduleName);
exportNames.forEach(exportName => global[exportName] = loadedModule[exportName]);
} else {
exportNames.forEach(exportName => registerOnGlobalContext(moduleName, exportName));
}
}

View File

@@ -1,5 +0,0 @@
{
"name" : "text",
"main" : "text",
"nativescript": {}
}

View File

@@ -1,8 +0,0 @@
import "../../core";
import "../../polyfills/xhr";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("text", () => require("../../../text"));
installPolyfills("text", ["TextDecoder", "TextEncoder"]);

View File

@@ -1,6 +0,0 @@
{
"name": "timers",
"main": "timers",
"types": "timers.d.ts",
"nativescript": {}
}

View File

@@ -1,5 +0,0 @@
/**
* Installs timers polyfill.
* @module "globals/polyfills/fetch"
*/ /** */
import "../../core";

View File

@@ -1,6 +0,0 @@
import "../../core";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("timer", () => require("../../../timer"));
installPolyfills("timer", ["setTimeout", "clearTimeout", "setInterval", "clearInterval"]);

View File

@@ -1,6 +0,0 @@
{
"name": "xhr",
"main": "xhr",
"types": "xhr.d.ts",
"nativescript": {}
}

View File

@@ -1,5 +0,0 @@
/**
* Installs xhr polyfill.
* @module "globals/polyfills/fetch"
*/ /** */
import "../../core";

View File

@@ -1,6 +0,0 @@
import "../../core";
import { installPolyfills } from "../polyfill-helpers";
global.registerModule("xhr", () => require("../../../xhr"));
installPolyfills("xhr", ["XMLHttpRequest", "FormData", "Blob", "File", "FileReader"]);