dts-gen 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SECURITY.md +41 -0
- package/bin/lib/definitely-typed.js +11 -5
- package/bin/lib/index.js +5 -3
- package/bin/lib/names.js +1 -0
- package/bin/lib/run.js +15 -11
- package/package.json +1 -1
- package/.vscode/launch.json +0 -19
package/SECURITY.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->
|
|
2
|
+
|
|
3
|
+
## Security
|
|
4
|
+
|
|
5
|
+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
|
6
|
+
|
|
7
|
+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
|
|
8
|
+
|
|
9
|
+
## Reporting Security Issues
|
|
10
|
+
|
|
11
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
12
|
+
|
|
13
|
+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
|
|
14
|
+
|
|
15
|
+
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
|
|
16
|
+
|
|
17
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
|
|
18
|
+
|
|
19
|
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
20
|
+
|
|
21
|
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
22
|
+
* Full paths of source file(s) related to the manifestation of the issue
|
|
23
|
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
24
|
+
* Any special configuration required to reproduce the issue
|
|
25
|
+
* Step-by-step instructions to reproduce the issue
|
|
26
|
+
* Proof-of-concept or exploit code (if possible)
|
|
27
|
+
* Impact of the issue, including how an attacker might exploit the issue
|
|
28
|
+
|
|
29
|
+
This information will help us triage your report more quickly.
|
|
30
|
+
|
|
31
|
+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
|
|
32
|
+
|
|
33
|
+
## Preferred Languages
|
|
34
|
+
|
|
35
|
+
We prefer all communications to be in English.
|
|
36
|
+
|
|
37
|
+
## Policy
|
|
38
|
+
|
|
39
|
+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
|
|
40
|
+
|
|
41
|
+
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
12
|
const fs_1 = require("fs");
|
|
12
13
|
const http_1 = require("http");
|
|
14
|
+
const https_1 = require("https");
|
|
13
15
|
const os_1 = require("os");
|
|
14
16
|
const parseGitConfig = require("parse-git-config");
|
|
15
17
|
const path_1 = require("path");
|
|
@@ -21,7 +23,7 @@ function writeDefinitelyTypedPackage(indexDtsContent, packageName, overwrite) {
|
|
|
21
23
|
// Check for overwrite
|
|
22
24
|
if (!overwrite) {
|
|
23
25
|
if (fs_1.existsSync(packageDir)) {
|
|
24
|
-
console.log(`Directory ${packageDir} already exists and
|
|
26
|
+
console.log(`Directory ${packageDir} already exists and --overwrite was not specified; exiting.`);
|
|
25
27
|
process.exit(2);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -40,7 +42,7 @@ function run(indexDtsContent, packageName, dtName, packageDir) {
|
|
|
40
42
|
["index.d.ts", yield getIndex(indexDtsContent, packageName)],
|
|
41
43
|
[`${dtName}-tests.ts`, ""],
|
|
42
44
|
["tsconfig.json", `${JSON.stringify(getTSConfig(dtName), undefined, 4)}\n`],
|
|
43
|
-
["tslint.json", '{ "extends": "dtslint/dt.json" }\n'],
|
|
45
|
+
["tslint.json", '{ "extends": "@definitelytyped/dtslint/dt.json" }\n'],
|
|
44
46
|
];
|
|
45
47
|
for (const [name, text] of files) {
|
|
46
48
|
fs_1.writeFileSync(path_1.join(packageDir, name), text, "utf-8");
|
|
@@ -48,13 +50,14 @@ function run(indexDtsContent, packageName, dtName, packageDir) {
|
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
function getIndex(content, packageName) {
|
|
53
|
+
var _a, _b, _c;
|
|
51
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
55
|
let version = "x.x";
|
|
53
56
|
let project = "https://github.com/baz/foo " +
|
|
54
57
|
"(Does not have to be to GitHub, " +
|
|
55
58
|
"but prefer linking to a source code repository rather than to a project website.)";
|
|
56
59
|
try {
|
|
57
|
-
const reg = JSON.parse(yield loadString(`
|
|
60
|
+
const reg = JSON.parse(yield loadString(`https://registry.npmjs.org/${packageName}`));
|
|
58
61
|
const { latest } = reg["dist-tags"];
|
|
59
62
|
const { homepage } = reg.versions[latest];
|
|
60
63
|
version = latest.split(".").slice(0, 2).join("."); // Just major.minor
|
|
@@ -82,6 +85,9 @@ function getIndex(content, packageName) {
|
|
|
82
85
|
if (url.hostname === 'github.com' && url.pathname) {
|
|
83
86
|
authorUserName = url.pathname.split('/')[1] || authorUserName;
|
|
84
87
|
}
|
|
88
|
+
else if ((_a = url.pathname) === null || _a === void 0 ? void 0 : _a.startsWith('git@github.com')) {
|
|
89
|
+
authorUserName = ((_c = (_b = url.pathname.split(':')) === null || _b === void 0 ? void 0 : _b[1].split('/')) === null || _c === void 0 ? void 0 : _c[0]) || authorUserName;
|
|
90
|
+
}
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
catch (e) {
|
|
@@ -123,7 +129,7 @@ function getTSConfig(dtName) {
|
|
|
123
129
|
}
|
|
124
130
|
function loadString(url) {
|
|
125
131
|
return new Promise((resolve, reject) => {
|
|
126
|
-
|
|
132
|
+
https_1.get(url, res => {
|
|
127
133
|
if (res.statusCode !== 200) {
|
|
128
134
|
return reject(new Error(`HTTP Error ${res.statusCode}: ${http_1.STATUS_CODES[res.statusCode || 500]} for ${url}`));
|
|
129
135
|
}
|
package/bin/lib/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIdentifierDeclarationFile = exports.generateModuleDeclarationFile = void 0;
|
|
3
4
|
const dom = require("dts-dom");
|
|
4
5
|
const dts_dom_1 = require("dts-dom");
|
|
5
|
-
const names_1 = require("./names");
|
|
6
6
|
const ts = require("typescript");
|
|
7
|
+
const names_1 = require("./names");
|
|
7
8
|
const builtins = {
|
|
8
9
|
Date,
|
|
9
10
|
RegExp,
|
|
@@ -341,8 +342,9 @@ function inferParameterType(_fn, _param) {
|
|
|
341
342
|
// TODO: Inspect function body for clues
|
|
342
343
|
return dom.type.any;
|
|
343
344
|
}
|
|
345
|
+
const stringifyFunction = Function.prototype.call.bind(Function.prototype.toString);
|
|
344
346
|
function parseFunctionBody(fn) {
|
|
345
|
-
const setup = `const myFn = ${fn
|
|
347
|
+
const setup = `const myFn = ${stringifyFunction(fn)};`;
|
|
346
348
|
const srcFile = ts.createSourceFile('test.ts', setup, ts.ScriptTarget.Latest, true);
|
|
347
349
|
const statement = srcFile.statements[0];
|
|
348
350
|
const decl = statement.declarationList.declarations[0];
|
|
@@ -350,5 +352,5 @@ function parseFunctionBody(fn) {
|
|
|
350
352
|
return init;
|
|
351
353
|
}
|
|
352
354
|
function isNativeFunction(fn) {
|
|
353
|
-
return fn
|
|
355
|
+
return stringifyFunction(fn).indexOf('{ [native code] }') > 0;
|
|
354
356
|
}
|
package/bin/lib/names.js
CHANGED
package/bin/lib/run.js
CHANGED
|
@@ -42,17 +42,17 @@ try {
|
|
|
42
42
|
throw new ArgsError('Must specify exactly one input');
|
|
43
43
|
}
|
|
44
44
|
if (typeof args.name === 'boolean')
|
|
45
|
-
throw new ArgsError('Must specify a value for "
|
|
45
|
+
throw new ArgsError('Must specify a value for "--name"');
|
|
46
46
|
if (typeof args.identifier === 'boolean')
|
|
47
|
-
throw new ArgsError('Must specify a value for "
|
|
47
|
+
throw new ArgsError('Must specify a value for "--identifier"');
|
|
48
48
|
if (typeof args.module === 'boolean')
|
|
49
|
-
throw new ArgsError('Must specify a value for "
|
|
49
|
+
throw new ArgsError('Must specify a value for "--module"');
|
|
50
50
|
if (args.overwrite !== undefined && args.overwrite !== true)
|
|
51
|
-
throw new ArgsError('
|
|
51
|
+
throw new ArgsError('--overwrite does not accept an argument');
|
|
52
52
|
let name;
|
|
53
53
|
if (args.module) {
|
|
54
54
|
if (args.name)
|
|
55
|
-
throw new ArgsError('Cannot use
|
|
55
|
+
throw new ArgsError('Cannot use --name with --module');
|
|
56
56
|
name = args.module;
|
|
57
57
|
module.paths.unshift(process.cwd() + '/node_modules');
|
|
58
58
|
result = guess.generateModuleDeclarationFile(args.module, require(args.module));
|
|
@@ -63,7 +63,7 @@ try {
|
|
|
63
63
|
}
|
|
64
64
|
else if (args['expression-file']) {
|
|
65
65
|
if (args.name)
|
|
66
|
-
throw new ArgsError('Cannot use
|
|
66
|
+
throw new ArgsError('Cannot use --name with --expression-file');
|
|
67
67
|
const filename = args['expression-file'];
|
|
68
68
|
name = path.basename(filename, path.extname(filename)).replace(/[^A-Za-z0-9]/g, '_');
|
|
69
69
|
module.paths.unshift(process.cwd() + '/node_modules');
|
|
@@ -72,7 +72,7 @@ try {
|
|
|
72
72
|
}
|
|
73
73
|
else if (args.identifier) {
|
|
74
74
|
if (args.name)
|
|
75
|
-
throw new ArgsError('Cannot use
|
|
75
|
+
throw new ArgsError('Cannot use --name with --identifier');
|
|
76
76
|
if (args.module || args.expression)
|
|
77
77
|
throw new ArgsError('Cannot specify more than one input');
|
|
78
78
|
name = args.identifier;
|
|
@@ -83,7 +83,7 @@ try {
|
|
|
83
83
|
throw new ArgsError('Needs a name');
|
|
84
84
|
name = args.name;
|
|
85
85
|
if (args.module || args.expression)
|
|
86
|
-
throw new ArgsError('Cannot mix
|
|
86
|
+
throw new ArgsError('Cannot mix --template with --module or --expression');
|
|
87
87
|
result = getTemplate(args.template);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
@@ -101,7 +101,7 @@ try {
|
|
|
101
101
|
filename = filename + '.d.ts';
|
|
102
102
|
}
|
|
103
103
|
if (!args.overwrite && fs.existsSync(filename)) {
|
|
104
|
-
console.error(`File ${filename} already exists and
|
|
104
|
+
console.error(`File ${filename} already exists and --overwrite was not specified; exiting.`);
|
|
105
105
|
process.exit(2);
|
|
106
106
|
}
|
|
107
107
|
fs.writeFileSync(filename, prependOurHeader(result), 'utf-8');
|
|
@@ -116,8 +116,9 @@ catch (e) {
|
|
|
116
116
|
process.exit(1);
|
|
117
117
|
}
|
|
118
118
|
else if (e.code === 'MODULE_NOT_FOUND') {
|
|
119
|
-
console.
|
|
120
|
-
|
|
119
|
+
console.error(`Error loading module "${args.module}".\n` +
|
|
120
|
+
getErrorMessageFirstLine(e).replace(/'/g, '"') + '.\n' +
|
|
121
|
+
`Please install missing module and try again.`);
|
|
121
122
|
process.exit(1);
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
@@ -160,3 +161,6 @@ function getTemplate(templateName) {
|
|
|
160
161
|
function allTemplateNames() {
|
|
161
162
|
return fs.readdirSync(templatesDirectory).map(t => t.slice(0, t.length - ".d.ts".length)).join(", ");
|
|
162
163
|
}
|
|
164
|
+
function getErrorMessageFirstLine(error) {
|
|
165
|
+
return error.message.split('\n', 1)[0];
|
|
166
|
+
}
|
package/package.json
CHANGED
package/.vscode/launch.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "attach",
|
|
10
|
-
"name": "Attach",
|
|
11
|
-
"port": 9229,
|
|
12
|
-
"sourceMaps": true
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"name": "Launch Program",
|
|
16
|
-
"program": "${workspaceFolder}/bin/lib/index.js"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|