[BUG] New dts gneration doesn't work when the environment doesn't have powershell #1473 (#1475)

- Convert PowerShell script to a nodejs one.
This commit is contained in:
Nev 2021-02-17 10:57:22 -08:00 коммит произвёл GitHub
Родитель a6913c2801
Коммит 8eba542754
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 227 добавлений и 35 удалений

Просмотреть файл

@ -19,7 +19,7 @@
"build:snippet": "grunt snippetvnext",
"test": "grunt aiskutests",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && powershell -ExecutionPolicy Bypass ../scripts/dtsgen.ps1 'Microsoft.ApplicationInsights'",
"dtsgen": "api-extractor run --local && node ../scripts/dtsgen.js 'Microsoft.ApplicationInsights'",
"nightwatch:chrome": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env chrome",
"nightwatch:firefox": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env firefox",
"nightwatch:edge": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env edge",

Просмотреть файл

@ -13,7 +13,7 @@
"build:browser": "rollup -c rollup.config.js",
"test": "echo 'No tests'",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && powershell -ExecutionPolicy Bypass ../scripts/dtsgen.ps1 'Microsoft.ApplicationInsights'"
"dtsgen": "api-extractor run --local && node ../scripts/dtsgen.js 'Microsoft.ApplicationInsights'"
},
"devDependencies": {
"@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",

92
common/config/rush/npm-shrinkwrap.json сгенерированный
Просмотреть файл

@ -161,9 +161,9 @@
}
},
"node_modules/@microsoft/api-extractor/node_modules/typescript": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz",
"integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@ -2124,9 +2124,9 @@
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="
},
"node_modules/graceful-fs": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.5.tgz",
"integrity": "sha512-kBBSQbz2K0Nyn+31j/w36fUfxkBW9/gfwRWdUY1ULReH3iokVJgddZAFcD1D0xlgTmFxJCbUkUclAlc6/IDJkw=="
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
},
"node_modules/grunt": {
"version": "1.3.0",
@ -3834,6 +3834,25 @@
"node": ">=0.6"
}
},
"node_modules/queue-microtask": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.2.tgz",
"integrity": "sha512-dB15eXv3p2jDlbOiNLyMabYg1/sXvppd8DP2J3EOCQ0AkuSXCW2tP7mnVouVLJKgUMY6yP0kcQDVpLCN13h4Xg==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/qunit": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/qunit/-/qunit-2.14.0.tgz",
@ -4154,9 +4173,9 @@
}
},
"node_modules/rollup": {
"version": "2.38.5",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.38.5.tgz",
"integrity": "sha512-VoWt8DysFGDVRGWuHTqZzT02J0ASgjVq/hPs9QcBOGMd7B+jfTr/iqMVEyOi901rE3xq+Deq66GzIT1yt7sGwQ==",
"version": "2.39.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.39.0.tgz",
"integrity": "sha512-+WR3bttcq7zE+BntH09UxaW3bQo3vItuYeLsyk4dL2tuwbeSKJuvwiawyhEnvRdRgrII0Uzk00FpctHO/zB1kw==",
"dependencies": {
"fsevents": "~2.3.1"
},
@ -4192,9 +4211,9 @@
}
},
"node_modules/run-parallel": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.10.tgz",
"integrity": "sha512-zb/1OuZ6flOlH6tQyMPUrE3x3Ulxjlo9WIVXR4yVYi4H9UXQaeIsPbLn2R3O3vQCnDKkAl2qHiuocKKX4Tz/Sw==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
"funding": [
{
"type": "github",
@ -4208,7 +4227,10 @@
"type": "consulting",
"url": "https://feross.org/support"
}
]
],
"dependencies": {
"queue-microtask": "^1.2.2"
}
},
"node_modules/safe-buffer": {
"version": "5.1.2",
@ -5067,9 +5089,9 @@
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA=="
},
"node_modules/uglify-js": {
"version": "3.12.6",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.6.tgz",
"integrity": "sha512-aqWHe3DfQmZUDGWBbabZ2eQnJlQd1fKlMUu7gV+MiTuDzdgDw31bI3wA2jLLsV/hNcDP26IfyEgSVoft5+0SVw==",
"version": "3.12.8",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.8.tgz",
"integrity": "sha512-fvBeuXOsvqjecUtF/l1dwsrrf5y2BCUk9AOJGzGcm6tE7vegku5u/YvqjyDaAGr422PLoLnrxg3EnRvTqsdC1w==",
"bin": {
"uglifyjs": "bin/uglifyjs"
},
@ -5418,9 +5440,9 @@
},
"dependencies": {
"typescript": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg=="
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz",
"integrity": "sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA=="
}
}
},
@ -7019,9 +7041,9 @@
"integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="
},
"graceful-fs": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.5.tgz",
"integrity": "sha512-kBBSQbz2K0Nyn+31j/w36fUfxkBW9/gfwRWdUY1ULReH3iokVJgddZAFcD1D0xlgTmFxJCbUkUclAlc6/IDJkw=="
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
},
"grunt": {
"version": "1.3.0",
@ -8335,6 +8357,11 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
},
"queue-microtask": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.2.tgz",
"integrity": "sha512-dB15eXv3p2jDlbOiNLyMabYg1/sXvppd8DP2J3EOCQ0AkuSXCW2tP7mnVouVLJKgUMY6yP0kcQDVpLCN13h4Xg=="
},
"qunit": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/qunit/-/qunit-2.14.0.tgz",
@ -8581,9 +8608,9 @@
}
},
"rollup": {
"version": "2.38.5",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.38.5.tgz",
"integrity": "sha512-VoWt8DysFGDVRGWuHTqZzT02J0ASgjVq/hPs9QcBOGMd7B+jfTr/iqMVEyOi901rE3xq+Deq66GzIT1yt7sGwQ==",
"version": "2.39.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.39.0.tgz",
"integrity": "sha512-+WR3bttcq7zE+BntH09UxaW3bQo3vItuYeLsyk4dL2tuwbeSKJuvwiawyhEnvRdRgrII0Uzk00FpctHO/zB1kw==",
"requires": {
"fsevents": "~2.3.1"
},
@ -8605,9 +8632,12 @@
}
},
"run-parallel": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.10.tgz",
"integrity": "sha512-zb/1OuZ6flOlH6tQyMPUrE3x3Ulxjlo9WIVXR4yVYi4H9UXQaeIsPbLn2R3O3vQCnDKkAl2qHiuocKKX4Tz/Sw=="
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
"requires": {
"queue-microtask": "^1.2.2"
}
},
"safe-buffer": {
"version": "5.1.2",
@ -9275,9 +9305,9 @@
}
},
"uglify-js": {
"version": "3.12.6",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.6.tgz",
"integrity": "sha512-aqWHe3DfQmZUDGWBbabZ2eQnJlQd1fKlMUu7gV+MiTuDzdgDw31bI3wA2jLLsV/hNcDP26IfyEgSVoft5+0SVw=="
"version": "3.12.8",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.8.tgz",
"integrity": "sha512-fvBeuXOsvqjecUtF/l1dwsrrf5y2BCUk9AOJGzGcm6tE7vegku5u/YvqjyDaAGr422PLoLnrxg3EnRvTqsdC1w=="
},
"unc-path-regex": {
"version": "0.1.2",

Просмотреть файл

@ -12,7 +12,7 @@
"build:browser": "rollup -c",
"test": "grunt clickanalyticstests",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && powershell -ExecutionPolicy Bypass ../../scripts/dtsgen.ps1 'Microsoft.ApplicationInsights'"
"dtsgen": "api-extractor run --local && node ../../scripts/dtsgen.js 'Microsoft.ApplicationInsights'"
},
"devDependencies": {
"@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",

Просмотреть файл

@ -16,7 +16,7 @@
"build:browser": "rollup -c",
"test": "",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && powershell -ExecutionPolicy Bypass ../../scripts/dtsgen.ps1 'Microsoft.ApplicationInsights'"
"dtsgen": "api-extractor run --local && node ../../scripts/dtsgen.js 'Microsoft.ApplicationInsights'"
},
"devDependencies": {
"@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",

162
scripts/dtsgen.js Normal file
Просмотреть файл

@ -0,0 +1,162 @@
//
// This script wrap the generated api dts file with a oneDS namespace and copyright notice the version
//
// node ../../scripts\dtsgen.js ./dist-esm/applicationinsights-web.d.ts 'Microsoft.ApplicationInsights' ./
//
const fs = require("fs");
const path = require("path");
function parseArgs(expectedArgs) {
var passedArgs = process.argv;
var theArgs = {
"$script" : passedArgs[1]
};
for (var lp = 0; lp < expectedArgs.length; lp++) {
var argIdx = 2 + lp;
var expArg = expectedArgs[lp];
var value = expArg.value;
if (passedArgs.length > argIdx) {
value = passedArgs[argIdx];
if (value && value.length > 2 && (
(value[0] === "'" && value[value.length - 1] === "'") ||
(value[0] === '"' && value[value.length - 1] === '"')
)) {
value = value.substring(1, value.length - 1);
}
}
if (expArg.isSwitch) {
// Convert to boolean
value = !!value;
}
theArgs[expArg.name] = value;
}
return theArgs;
}
var theArgs = parseArgs([
{ name: "skuName", value: null}, // The Sku name to place in the copyright notice
{ name: "projectPath", value: "./"}, // The root path for the project
{ name: "dtsFile", value: ""}, // [Optional] The generated Dts file (if cannot be derived from the package.json)
{ name: "hidePrivate", value: false, isSwitch: true}, // [Optional] Switch to hide private properties and functions
]);
if (!theArgs.skuName) {
throw "Missing skuName";
}
var projectPath = path.resolve(process.cwd(), theArgs.projectPath)
var packagePath = path.resolve(theArgs.projectPath, "package.json");
console.log(`Using Package: ${packagePath}, current path cwd ${process.cwd()}`);
var packageJson = require(packagePath);
if (!packageJson || !packageJson.version) {
throw `Missing package.json or version from [${packagePath}]`
}
var version = packageJson.version
var author = packageJson.author || "";
var homepage = packageJson.homepage || "";
var packageName = packageJson.name
packageName = packageName.replace('@microsoft/', '').replace('/', '_');
if (!theArgs.dtsFile) {
theArgs.dtsFile = path.resolve(projectPath, "dist", `${packageName}.d.ts`);
}
var dtsFileRollup = theArgs.dtsFile.replace(`${packageName}.d.ts`, `${packageName}.rollup.d.ts`);
var rollupContent =
"/*\n" +
` * ${theArgs.skuName}, ${version}\n` +
" * Copyright (c) Microsoft and contributors. All rights reserved.\n" +
" *\n" +
` * ${author}\n` +
` * ${homepage}\n`;
var newContent = rollupContent +
" */\n\n" +
"declare namespace ApplicationInsights {";
rollupContent +=
" *\n" +
" * ---------------------------------------------------------------------------\n" +
" * This is a single combined (rollup) declaration file for the package,\n" +
" * use this version if your build environment doesn't support the using the\n" +
" * individual *.d.ts files or default namespace wrapped version.\n" +
` * - Namespaced version: ${packageName}.d.ts\n` +
" * ---------------------------------------------------------------------------\n" +
" */\n";
console.log(`Transforming: ${theArgs.dtsFile}`);
fs.readFile(theArgs.dtsFile, (err, data) => {
if (err) {
console.error(err);
throw `Failed to read .d.ts file [${theArgs.dtsFile}]`;
} else {
processFile(data.toString());
}
});
function processFile(dtsContents) {
console.log("File...");
console.log(dtsContents);
// Read the generated dts file and append to the new content
var lastLine = ""
// Prefix every line with 4 spaces (indenting the lines)
var lines = dtsContents.split("\n");
console.log(`Lines: ${lines.length}`);
console.log(dtsContents);
lines.forEach((line) => {
// Trim whitespace from the end of the string
var rollupLine = line.replace(/(\s+$)/g, '');
if (line && line.trim().length > 0) {
// Remove exports and declares
line = line.replace('export declare ', '');
line = line.replace('declare ', '');
line = line.replace('export { }', '');
// Trim whitespace from the end of the string
line = line.replace(/(\s+$)/g, '');
if (theArgs.hidePrivate) {
// Hide private properties and functions
line = line.replace(/(^\s+)private (.*);/, '$1// private $2;');
rollupLine = rollupLine.replace(/(^\s+)private (.*);/, '$1// private $2;');
}
rollupContent += `\n${rollupLine}`;
newContent += `\n ${line}`;
} else if (lastLine) {
// Only add 1 blank line
rollupContent += "\n"
newContent += "\n"
}
lastLine = line
});
// Add final trailing closing bracket for the namespace
newContent += "\n}";
fs.writeFile(dtsFileRollup, rollupContent, (err, data) => {
if (err) {
console.error(err);
throw `Failed to write ${dtsFileRollup}`;
}
});
fs.writeFile(theArgs.dtsFile, newContent, (err, data) => {
if (err) {
console.error(err);
throw `Failed to write ${theArgs.dtsFile}`;
}
});
}