Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react 17][pre-release] udpate application insight dependency #90

Merged
merged 10 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node.js CI

on:
push:
branches: [ main, release3.x ]
branches: [ main, release3.x, release17.x ]
pull_request:
branches: [ main, release3.x ]
branches: [ main, release3.x, release17.x ]

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ main, release3.x ]
branches: [ main, release3.x, release17.x ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main, release3.x ]
branches: [ main, release3.x, release17.x ]
schedule:
- cron: '17 15 * * 2'

Expand Down
4 changes: 2 additions & 2 deletions applicationinsights-react-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
},
"dependencies": {
"@microsoft/applicationinsights-shims": "^3.0.1",
"@microsoft/applicationinsights-core-js": "^3.0.8",
"@microsoft/applicationinsights-common": "^3.0.8",
"@microsoft/applicationinsights-core-js": "^3.0.9",
"@microsoft/applicationinsights-common": "^3.0.9",
"@microsoft/dynamicproto-js": "^2.0.3",
"@nevware21/ts-utils": ">= 0.10.5 < 2.x"
},
Expand Down
1,491 changes: 656 additions & 835 deletions common/config/rush/npm-shrinkwrap.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"ai-min": "node common/scripts/install-run-rush.js ai-min",
"ai-restore": "node common/scripts/install-run-rush.js ai-restore",
"gh-status": "node ./tools/status-tools/github-status.js",
"sample": "cd sample/applicationinsights-react-sample && npm install && npm run build"
"sample": "cd sample/applicationinsights-react-sample && npm install && npm run build",
"npm-package": "node ./tools/release-tools/npm-package.js"
},
"devDependencies": {
"@microsoft/rush": "^5.113.4",
Expand Down
4 changes: 2 additions & 2 deletions sample/applicationinsights-react-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"author": "Microsoft Application Insights Team",
"license": "MIT",
"dependencies": {
"@microsoft/applicationinsights-core-js": "^3.0.8",
"@microsoft/applicationinsights-core-js": "^3.0.9",
"@microsoft/applicationinsights-react-js": "17.0.4",
"@microsoft/applicationinsights-web": "^3.0.8",
"@microsoft/applicationinsights-web": "^3.0.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.11.2",
Expand Down
166 changes: 166 additions & 0 deletions tools/release-tools/npm-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
const fs = require("fs");
const child_process = require("child_process");

const packageGroupDef = "./tools/release-tools/package_groups.json";
let packageGroup;
let dropFolder;
let dryRun = "";

function showHelp() {
var scriptParts;
var scriptName = process.argv[1];
if (scriptName.indexOf("\\") !== -1) {
scriptParts = scriptName.split("\\");
scriptName = scriptParts[scriptParts.length - 1];
} else if (scriptName.indexOf("/") !== -1) {
scriptParts = scriptName.split("/");
scriptName = scriptParts[scriptParts.length - 1];
}

console.log("");
console.log(scriptName + " <group> ");
console.log("--------------------------");
console.log(" <group> - Identifies the group to publish, identifies folders, the group must be defined in package_groups.json");
console.log(" <dropFolder> - Identifies the base folder to drop the packages into, defaults to ./drop/packages/<group>");
}

function parseArgs() {
console.log("Parsing args - " + process.argv.join(" "));
if (process.argv.length < 2) {
console.error("!!! Invalid number of arguments -- " + process.argv.length);
return false;
}

let idx = 2;
while (idx < process.argv.length) {
let theArg = process.argv[idx];
if (theArg.startsWith("-")) {
if (theArg === "-test") {
dryRun = "--dry-run";
} else {
console.error("!!! Unknown switch [" + theArg + "] detected");
return false;
}
} else if (!packageGroup) {
packageGroup = theArg;
} else if (!dropFolder) {
dropFolder = theArg;
} else {
console.error("!!! Invalid Argument [" + theArg + "] detected");
return false;
}

idx++;
}

// Check for required arguments
if (!packageGroup) {
console.error("!!! Missing package group");
return false;
}

return true;
}

function removeTrailingComma(text) {
return text.replace(/,(\s*[}\],])/g, "$1");
}

function removeComments(text) {
return text.replace(/^\s*\/\/\s.*$/gm, "");
}

function getPackage(packageJsonFile) {
var packageText = removeTrailingComma(fs.readFileSync(packageJsonFile, "utf-8"));

return JSON.parse(packageText);
}

function getNpmPackageName(packageJson) {
let packageName = packageJson.name;
let packageVersion = packageJson.version;

let theNpmPackageName = packageName + "-" + packageVersion;

theNpmPackageName = theNpmPackageName.replace("@", "").replace("/", "-");

return theNpmPackageName + ".tgz";
}

function getGroupProjects() {
if (!fs.existsSync(packageGroupDef)) {
console.error("!!! Unable to locate package group definitions [" + packageGroupDef + "]");
throw new Error("!!! Unable to locate package group definitions.");
}

var groupText = removeComments(removeTrailingComma(fs.readFileSync(packageGroupDef, "utf-8")));

let groupJson = JSON.parse(groupText);
return groupJson[packageGroup] || [];
}

function movePackage(npmPackageName, packageName) {
let packageFolder = dropFolder;
if (!packageFolder) {
packageFolder = "./drop/packages";
packageFolder += "/" + packageGroup;
}

if (!fs.existsSync(packageFolder)) {
fs.mkdirSync(packageFolder, { recursive: true });
}

let packageFile = packageFolder + "/" + packageName;
if (fs.existsSync(packageFile)) {
console.log(` -- Removing existing package ${packageFile}`);
fs.unlinkSync(packageFile);
}

console.log(` -- Moving ${npmPackageName} to ${packageFile}`);
fs.renameSync(npmPackageName, packageFile);
}

if (parseArgs()) {
var packages = getGroupProjects();

console.log(`Creating [${packageGroup}] packages => ${packages.length}`);
packages.forEach((packageRoot) => {
let packageJsonFile = packageRoot + "/package.json";

if (!fs.existsSync(packageJsonFile)) {
console.error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
throw new Error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
}

const packageJson = getPackage(packageJsonFile);

const packageName = getNpmPackageName(packageJson);
console.log("\n\n##################################################################");
console.log("Packaging - " + packageName);
console.log("##################################################################");

let npmPackageName = packageRoot + "/" + packageName;
if (fs.existsSync(npmPackageName)) {
console.log(` -- Removing existing package ${npmPackageName}`);
fs.unlinkSync(npmPackageName);
}

const cwd = process.cwd();
process.chdir(packageRoot);
try {
let npmCmd = `npm pack ${dryRun}`;
console.log(`Running: \"${npmCmd}\"`);
child_process.execSync(npmCmd);
} finally {
process.chdir(cwd);
}

if (!dryRun) {
// Move the package to the package folder
movePackage(npmPackageName, packageName);
}
});
} else {
showHelp();
process.exit(1);
}
9 changes: 9 additions & 0 deletions tools/release-tools/package_groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ------------------------------
// NPM Publish group definitions
// ------------------------------
{
// DynamicProto packages
"react": [
"./applicationinsights-react-js"
]
}
Loading
Loading