Modernize the declaration as a hybrid UMD + explicit global (#20512)

* Modernize the declaration as a hybrid UMD + explicit global

* fix failing tests

* remove dependency on lib.dom.d.ts

* append own name to maintainers list

* add a tslint.json file; lint declaration; lint tests

* remove SystemJSSystemFields interface
move SystemJSSystemFields properties to System interface
add comments to additional members. reference: https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#warnings

https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#pluginfirst

* Update header as per code review.
This commit is contained in:
Aluan Haddad
2017-10-12 16:51:02 -04:00
committed by Wesley Wigham
parent 5cadfa2d5d
commit be50516c67
4 changed files with 69 additions and 55 deletions

View File

@@ -1,11 +1,28 @@
// Type definitions for SystemJS 0.20
// Project: https://github.com/systemjs/systemjs
// Definitions by: Ludovic HENIN <https://github.com/ludohenin>, Nathan Walker <https://github.com/NathanWalker>, Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
// Definitions by: Ludovic HENIN <https://github.com/ludohenin>
// Nathan Walker <https://github.com/NathanWalker>
// Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
// Aluan Haddad <https://github.com/aluanhaddad>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = SystemJSLoader;
export as namespace SystemJSLoader;
declare global {
const SystemJS: typeof SystemJSLoader;
/**
* @deprecated use SystemJS https://github.com/systemjs/systemjs/releases/tag/0.19.10
*/
const System: typeof SystemJSLoader;
const __moduleName: string;
}
declare const SystemJSLoader: SystemJSLoader.System;
declare namespace SystemJSLoader {
interface ModulesList {
[bundleName: string]: string[];
}
@@ -173,7 +190,7 @@ declare namespace SystemJSLoader {
/**
* Set the Babel transpiler options when System.transpiler is set to babel.
*/
//TODO: Import BabelCore.TransformOptions
// TODO: Import BabelCore.TransformOptions
babelOptions?: any;
/**
@@ -234,7 +251,7 @@ declare namespace SystemJSLoader {
/**
* Sets the TypeScript transpiler options.
*/
//TODO: Import Typescript.CompilerOptions
// TODO: Import Typescript.CompilerOptions
typescriptOptions?: {
/**
* A boolean flag which instructs the plugin to load configuration from "tsconfig.json".
@@ -248,25 +265,16 @@ declare namespace SystemJSLoader {
};
}
interface SystemJSSystemFields {
env: string;
loaderErrorStack: boolean;
packageConfigPaths: string[];
pluginFirst: boolean;
version: string;
warnings: boolean;
}
interface System extends Config, SystemJSSystemFields {
interface System extends Config {
/**
* For backwards-compatibility with AMD environments, set window.define = System.amdDefine.
*/
amdDefine: (...args: any[]) => void;
amdDefine(...args: any[]): void;
/**
* For backwards-compatibility with AMD environments, set window.require = System.amdRequire.
*/
amdRequire: (deps: string[], callback: (...modules: any[]) => void) => void;
amdRequire(deps: string[], callback: (...modules: any[]) => void): void;
/**
* SystemJS configuration helper function.
@@ -288,7 +296,6 @@ declare namespace SystemJSLoader {
* Returns a module from the registry by normalized name.
*/
get(moduleName: string): any;
get<TModule>(moduleName: string): TModule;
/**
* Returns a clone of the internal SystemJS configuration in use.
@@ -305,7 +312,6 @@ declare namespace SystemJSLoader {
* Promise resolves to the module value.
*/
import(moduleName: string, normalizedParentName?: string): Promise<any>;
import<TModule>(moduleName: string, normalizedParentName?: string): Promise<TModule>;
/**
* Given any object, returns true if the object is either a SystemJS module or native JavaScript module object, and false otherwise.
@@ -318,7 +324,6 @@ declare namespace SystemJSLoader {
* Useful when writing a custom instantiate hook or using System.set.
*/
newModule(object: any): any;
newModule<TModule>(object: any): TModule;
/**
* Declaration function for defining modules of the System.register polyfill module format.
@@ -349,32 +354,35 @@ declare namespace SystemJSLoader {
* Synchronous alternative to `SystemJS.resolve`.
*/
resolveSync(moduleName: string, parentName?: string): string;
/**
* In CommonJS environments, SystemJS will substitute the global require as needed by the module format being
* loaded to ensure the correct detection paths in loaded code.
* The CommonJS require can be recovered within these modules from System._nodeRequire.
*/
_nodeRequire: (dep: string) => any;
_nodeRequire(dep: string): any;
/**
* Modules list available only with trace=true
*/
loads: PackageList<any>;
env: string;
loaderErrorStack: boolean;
packageConfigPaths: string[];
/**
* Specify a value of true to have SystemJS conform to the AMD-style plugin syntax, e.g. "text!some/file.txt", over the default of "some/file.txt!text".
*/
pluginFirst: boolean;
version: string;
/**
* Enables the output of warnings to the console, including deprecation messages.
*/
warnings: boolean;
}
}
declare var SystemJS: SystemJSLoader.System;
declare var __moduleName: string;
/**
* @deprecated use SystemJS https://github.com/systemjs/systemjs/releases/tag/0.19.10
*/
declare const System: SystemJSLoader.System;
declare module "systemjs" {
import systemJSLoader = SystemJSLoader;
const system: systemJSLoader.System;
export = system;
}

View File

@@ -7,15 +7,13 @@ SystemJS.config({
SystemJS.import('main.js');
SystemJS.config({
// or 'traceur' or 'typescript'
transpiler: 'babel',
// or traceurOptions or typescriptOptions
// 'plugin-traceur' or 'plugin-typescript' or 'babel' or 'traceur' or 'typescript' or false.
transpiler: 'plugin-babel',
// or traceurOptions or typescriptOptions
babelOptions: {
}
});
SystemJS.config({
map: {
traceur: 'path/to/traceur.js'
@@ -39,26 +37,32 @@ SystemJS.config({
});
SystemJS.config({
map: {
'local/package': {
x: 'vendor/x.js'
},
'another/package': {
x: 'vendor/y.js'
map: {
'local/package': {
x: 'vendor/x.js'
},
'another/package': {
x: 'vendor/y.js'
}
}
}
});
SystemJS.transpiler = 'traceur';
const mockModule = {
default: () => {
return 42;
}
};
// loads './app.js' from the current directory
SystemJS.import('./app.js').then(function (m) {
console.log(m);
SystemJS.set('./app.js', SystemJS.newModule(mockModule));
SystemJS.import('./app.js').then((m: typeof mockModule) => {
m.default();
});
SystemJS.import('lodash').then(function (_) {
console.log(_);
SystemJS.import('lodash').then((_: (...args: any[]) => any) => {
_(1, '2', {}, []);
});
const clonedSystemJSJS = new SystemJS.constructor();

View File

@@ -2,8 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}