Skip to content

Commit

Permalink
Update minify script to use PC newline for imports and header banners
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Dec 17, 2022
1 parent f25c0f8 commit 7e67551
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
- run: npm install rollup -g
- run: npm install grunt-cli
- run: npm install
- run: rush check
- run: node common/scripts/install-run-rush.js check
- run: node common/scripts/install-run-rush.js install
- run: npm run build --verbose
timeout-minutes: 10
- run: npm run test --verbose
Expand Down
2 changes: 1 addition & 1 deletion AISKULight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export {
proxyFunctions,
IPlugin,
ITelemetryPlugin

} from "@microsoft/applicationinsights-core-js";

export {
SeverityLevel,
eSeverityLevel,
Expand Down
52 changes: 26 additions & 26 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"@microsoft/rush": "5.82.1",
"@nevware21/grunt-eslint-ts": "^0.2.2",
"@nevware21/grunt-ts-plugin": "^0.4.3",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"archiver": "^5.3.0",
"chromium": "^3.0.2",
"connect": "^3.7.0",
Expand Down
46 changes: 23 additions & 23 deletions tools/grunt-tasks/minifyNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var MAX_IMPORT_LENGTH = 140;
var IMPORT_INDENT_PREFIX = " ";

var AutoGeneratedConstFile =
"// Copyright (c) Microsoft Corporation. All rights reserved.\n" +
"// Licensed under the MIT License.\n" +
"// @skip-file-minify\n\n" +
"// ##############################################################\n" +
"// AUTO GENERATED FILE: This file is Auto Generated during build.\n" +
"// ##############################################################\n\n" +
"// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" +
"// Note: DON'T Export these const from the package as we are still targeting ES3 this will export a mutable variables that someone could change!!!\n" +
"// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n";
"// Copyright (c) Microsoft Corporation. All rights reserved.\r\n" +
"// Licensed under the MIT License.\r\n" +
"// @skip-file-minify\r\n\r\n" +
"// ##############################################################\r\n" +
"// AUTO GENERATED FILE: This file is Auto Generated during build.\r\n" +
"// ##############################################################\r\n\r\n" +
"// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n" +
"// Note: DON'T Export these const from the package as we are still targeting ES3 this will export a mutable variables that someone could change!!!\r\n" +
"// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n";

const encodeValues = ".();[]:";
const defaultGeneratedConstantFile = "./src/__DynamicConstants.ts";
Expand Down Expand Up @@ -190,7 +190,7 @@ function readInternalConstants(theReplacements, src, from) {
}

function removeUnusedImports(parsedFile) {
//const detectImports = /^import[\s]*\{([^}]*)\}[\s]*from[\s]*\"(.*)\";$/gm;
//const detectImports = /^import[\s]*\{([^}]*)\}[\s]*from[\s]*[\"'](.*)[\"'];$/gm;

let orgSrc = parsedFile.src;
var changed = false;
Expand Down Expand Up @@ -504,7 +504,7 @@ function replaceValues(parsedFile, theOptions, theName, values) {
});
}

newContent += theLine + "\n";
newContent += theLine.replace(/\r$/, "") + "\r\n";
if (orgLine != theLine) {
changed = true;
}
Expand Down Expand Up @@ -674,7 +674,7 @@ function extractComments(src) {
}

function extractImports(src, theImports) {
let extractAllImports = /^[ \t]*import\s*(\{([^}]+)\}|([^;]+)|(\*))[\s]*from[\s]*\"(.*)\"(.*)$/gm;
let extractAllImports = /^[ \t]*import\s*(\{([^}]+)\}|([^;]+)|(\*))[\s]*from[\s]*[\"'](.*)[\"'](.*)$/gm;

var orgSrc = src;
var matches = extractAllImports.exec(orgSrc);
Expand Down Expand Up @@ -728,7 +728,7 @@ function extractBanner(src, theBanner) {
}

idx++;
theBanner.push(theLine);
theBanner.push(theLine.replace(/\r$/, ""));

if (theLine.length === 0) {
// Stop at first blank line keeping the blank line
Expand All @@ -738,7 +738,7 @@ function extractBanner(src, theBanner) {

// Some files have a blank line before the existing use strict
if (lines[idx] && lines[idx].trim().startsWith("\"use strict\";")) {
theBanner.push(lines[idx]);
theBanner.push(lines[idx].replace(/\r$/, ""));
idx++;
}

Expand Down Expand Up @@ -770,15 +770,15 @@ function parseFile(filename, src) {
function formatImport(theImport, maxImportWidth) {
var newImport = theImport.org || "";
if (newImport) {
newImport += "\n";
newImport += "\r\n";
}

if (theImport.type === 2) {
if (theImport.values.length > 0) {
theImport.values.sort();
newImport = "import { " + theImport.values.join(", ") + " } from \"" + theImport.src + "\";\n";
newImport = "import { " + theImport.values.join(", ") + " } from \"" + theImport.src + "\";\r\n";
if (newImport.length > maxImportWidth) {
newImport = "import {\n";
newImport = "import {\r\n";
var theImports = theImport.values.join(", ");
var importLines = [];
while (theImports.length > maxImportWidth - 4) {
Expand All @@ -791,8 +791,8 @@ function formatImport(theImport, maxImportWidth) {
theImports = theImports.substring(idx + 1).trim();
}
importLines.push(IMPORT_INDENT_PREFIX + theImports);
newImport += importLines.join("\n") + "\n";
newImport += "} from \"" + theImport.src + "\";\n";
newImport += importLines.join("\r\n") + "\r\n";
newImport += "} from \"" + theImport.src + "\";\r\n";
}
} else {
// Nothing to be imported so don't emit the import
Expand All @@ -806,7 +806,7 @@ function formatImport(theImport, maxImportWidth) {
function formatFile(parsedFile, maxImportWidth) {
var newContent = "";
if (parsedFile.banner.length > 0) {
newContent += parsedFile.banner.join("\n") + "\n";
newContent += parsedFile.banner.join("\r\n") + "\r\n";
}

if (parsedFile.imports.length > 0) {
Expand Down Expand Up @@ -835,11 +835,11 @@ function formatFile(parsedFile, maxImportWidth) {
}

if (importContent) {
newContent += importContent + "\n";
newContent += importContent + "\r\n";
}
}

newContent += parsedFile.src.trim() + "\n";
newContent += parsedFile.src.trim() + "\r\n";

return newContent;
}
Expand Down Expand Up @@ -1262,7 +1262,7 @@ function minifyNamesFn(grunt) {
newValues.forEach((name) => {
if (name) {
let dupCheckValue = name.value.toUpperCase();
generatedConstants += "export const " + createDynamicName(name.value, added.indexOf(dupCheckValue) !== -1) + " = \"" + name.value + "\"; // Count: " + name.count + "\n";
generatedConstants += "export const " + createDynamicName(name.value, added.indexOf(dupCheckValue) !== -1) + " = \"" + name.value + "\"; // Count: " + name.count + "\r\n";
added.push(dupCheckValue);
}
});
Expand Down

0 comments on commit 7e67551

Please sign in to comment.