From 5678e68a922d047bc7de32e6d82cceb0854fadf2 Mon Sep 17 00:00:00 2001 From: Joel Mut Date: Wed, 11 Dec 2024 10:05:39 -0300 Subject: [PATCH] testing --- .../botbuilder-repo-utils/src/workspace.ts | 4 - libraries/botbuilder-vendors/package.json | 4 +- libraries/botbuilder-vendors/src/index.ts | 106 +++++++++++------- .../recognizers-date-time/index.js | 4 +- .../recognizers-number-with-unit/index.js | 2 +- .../recognizers-number/index.js | 6 +- package.json | 2 - 7 files changed, 75 insertions(+), 53 deletions(-) diff --git a/libraries/botbuilder-repo-utils/src/workspace.ts b/libraries/botbuilder-repo-utils/src/workspace.ts index b66dcb7c71..1a7275692e 100644 --- a/libraries/botbuilder-repo-utils/src/workspace.ts +++ b/libraries/botbuilder-repo-utils/src/workspace.ts @@ -62,10 +62,6 @@ export async function collectWorkspacePackages( return; } - if(filters.ignorePath?.length){ - console.log(relWorkspacePath, filters.ignorePath) - } - if ( filters.ignorePath?.length && filters.ignorePath.some((ignorePath) => minimatch(relWorkspacePath, ignorePath)) diff --git a/libraries/botbuilder-vendors/package.json b/libraries/botbuilder-vendors/package.json index 6a8970f16d..735bc3cb80 100644 --- a/libraries/botbuilder-vendors/package.json +++ b/libraries/botbuilder-vendors/package.json @@ -11,8 +11,8 @@ "url": "https://github.com/Microsoft/botbuilder-js.git" }, "scripts": { - "install": "ts-node src/index.ts install", - "build": "ts-node src/index.ts build" + "postinstall": "ts-node src/index.ts install", + "postbuild": "ts-node src/index.ts build" }, "dependencies": { "fast-glob": "^3.3.2", diff --git a/libraries/botbuilder-vendors/src/index.ts b/libraries/botbuilder-vendors/src/index.ts index 34aea1addf..8dcedbba3c 100644 --- a/libraries/botbuilder-vendors/src/index.ts +++ b/libraries/botbuilder-vendors/src/index.ts @@ -22,6 +22,18 @@ interface Dependency { version: string; } +const colors = { + reset: '\x1b[0m', + dim: '\x1b[2m', + red: '\x1b[31m', + green: '\x1b[32m', + blue: '\x1b[34m', + magenta: '\x1b[35m', + cyan: '\x1b[36m', +}; + +const isGitHubActions = process.env.GITHUB_ACTIONS === 'true'; + async function collectVendors(gitRoot: string) { const dir = path.resolve(gitRoot, 'libraries/botbuilder-vendors/src'); const packages = await glob('**/package.json', { cwd: dir }); @@ -108,17 +120,16 @@ export const command = (argv: string[]) => async () => { } console.log(` -summary -------- -action : ${action} -vendors : ${globalVendors.length} packages -workspaces: ${workspaces.length} packages -------- - `); +Connecting vendors to workspaces... + +${colors.blue}summary${colors.reset} +---------------------- +action : ${colors.magenta}${action}${colors.reset} +vendors : ${colors.magenta}${globalVendors.length} packages${colors.reset} +workspaces: ${colors.magenta}${workspaces.length} packages${colors.reset} +`); for (const { pkg, absPath } of workspaces) { - console.log(` -${pkg.name} --------`); + console.log(`${colors.blue}${pkg.name} ${colors.green}[workspace]${colors.reset}`); const location = pkg.localDependencies!.__location; if (!location) { throw new Error( @@ -136,44 +147,55 @@ ${pkg.name} if (isBuild) { const tsconfig = await readJsonFile(path.join(dir, 'tsconfig.json')); - const outDir = path.resolve(dir, tsconfig.compilerOptions.outDir); + const configDir = tsconfig.compilerOptions.outDir; + const outDir = path.resolve(dir, configDir); const files = await glob(`**/*.js`, { cwd: outDir }); - if (files.length > 0) { - console.log( - // `[build] Updating import/require statements under the '${tsconfig.compilerOptions.outDir}' folder in '${pkg.name}'...`, - `[build] ${pkg.name}`, - ); - } - let count = 0; + const references: Record = {}; for (const file of files) { const filePath = path.join(outDir, file); const content = await fs.readFile(filePath, 'utf8'); for (const vendor of vendors) { const vendorDir = path.join(dir, location, path.basename(vendor.dir)); const relative = path.relative(path.dirname(filePath), vendorDir).split(path.sep).join('/'); - const definition = `require("${vendor.name}")`; - if (!content.includes(definition)) { + const from = `require("${vendor.name}")`; + const to = `require("${relative}")`; + if (!content.includes(from)) { continue; } - count++; - const newContent = content.replace(definition, `require("${relative}")`); - await fs.writeFile(filePath, newContent, 'utf8'); + const line = content.split('\n').findIndex((line) => line.includes(from)) + 1; + references[file] ??= []; + references[file].push({ from, to, line }); + const newContent = content.replace(from, to); + // await fs.writeFile(filePath, newContent, 'utf8'); } } if (files.length > 0) { - // console.log(` - Found ${count} references.`); - // TODO: add a list of vendors updated in each file. - console.log( - ` - found ${count} import/require statements under the '${tsconfig.compilerOptions.outDir}' folder.`, - ); + const entries = Object.entries(references); + console.log(`└─ require statements: ${colors.magenta}${entries.length} files${colors.reset}`); + for (let i = 0; i < entries.length; i++) { + const [file, refs] = entries[i]; + const prefix = i === entries.length - 1 ? '└─' : '├─'; + console.log( + ` ${prefix} ${colors.cyan}${configDir}/${file}: ${colors.magenta}${refs.length} reference${refs.length === 1 ? '' : 's'}${colors.reset}`, + ); + for (let j = 0; j < refs.length; j++) { + const ref = refs[j]; + const prefix = j === refs.length - 1 ? '└─' : '├─'; + const prefix2 = i === entries.length - 1 ? ' ' : '│'; + console.log( + ` ${prefix2} ${prefix} ${colors.dim}line:${ref.line} | ${colors.red}${ref.from}${colors.reset} ${colors.dim}-> ${colors.green}${ref.to}${colors.reset}`, + ); + } + } } } if (isInstall) { - // console.log(`Adding packages to ${pkg.name}...`); - console.log(`vendors : ${vendors.length} packages`); + console.log( + `├─ vendors: ${colors.magenta}${vendors.length} packages ${colors.green}[linked]${colors.reset}`, + ); for (let i = 0; i < vendors.length; i++) { const vendor = vendors[i]; const source = path.join(vendor.dir, vendor.main); @@ -184,20 +206,26 @@ ${pkg.name} await fs.mkdir(vendorDir, { recursive: true }); } - const prefix = i === vendors.length - 1 ? '└' : '├'; - console.log(` ${prefix} ${vendor.name}@${vendor.version}`); + const prefix = i === vendors.length - 1 ? '└─' : '├─'; + console.log( + `│ ${prefix} ${colors.dim}${vendor.name}@${colors.cyan}${vendor.version}${colors.reset}`, + ); await fs.copyFile(source, destination); } - console.log(`dependencies: ${dependencies.length} packages`); - for (let i = 0; i < dependencies.length; i++) { - const { name, version } = dependencies[i]; - const prefix = i === dependencies.length - 1 ? '└' : '├'; - console.log(` ${prefix} ${name}@${version}`); - execSync(`npm pkg set dependencies["${name}"]="${version}"`, { cwd: dir }); + if (isGitHubActions) { + console.log( + `└─ dependencies: ${colors.magenta}${dependencies.length} packages ${colors.green}[added]${colors.reset}`, + ); + for (let i = 0; i < dependencies.length; i++) { + const { name, version } = dependencies[i]; + const prefix = i === dependencies.length - 1 ? '└─' : '├─'; + console.log(` ${prefix} ${colors.dim}${name}@${colors.cyan}${version}${colors.reset}`); + execSync(`npm pkg set dependencies["${name}"]="${version}"`, { cwd: dir }); + } } } - console.log('\n'); + console.log(''); } return success(); diff --git a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-date-time/index.js b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-date-time/index.js index bf7bd27194..01e5c69df4 100644 --- a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-date-time/index.js +++ b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-date-time/index.js @@ -3,8 +3,8 @@ var recognizersText = require('../recognizers-text'); var recognizersTextNumber = require('../recognizers-number'); var recognizersTextNumberWithUnit = require('../recognizers-number-with-unit'); -var isEqual = require("lodash/isequal"); -var toNumber = require("lodash/tonumber"); +var isEqual = require("lodash/isEqual"); +var toNumber = require("lodash/toNumber"); var DateTimeModelResult = class extends recognizersText.ModelResult { }; diff --git a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number-with-unit/index.js b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number-with-unit/index.js index 289971d606..207187847c 100644 --- a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number-with-unit/index.js +++ b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number-with-unit/index.js @@ -3,7 +3,7 @@ var recognizersText = require('../recognizers-text'); var recognizersTextNumber = require('../recognizers-number'); var max = require("lodash/max"); -var escapeRegExp = require("lodash/escaperegexp"); +var escapeRegExp = require("lodash/escapeRegExp"); var last = require("lodash/last"); var CompositeEntityType = /* @__PURE__ */ ((CompositeEntityType2) => { diff --git a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number/index.js b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number/index.js index 269675ad02..266fc6c1dd 100644 --- a/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number/index.js +++ b/libraries/botbuilder-vendors/src/recognizers-text/recognizers-number/index.js @@ -2,9 +2,9 @@ var recognizersText = require('../recognizers-text'); var bignumber = require('bignumber.js/bignumber'); -var trimEnd = require("lodash/trimend"); -var sortBy = require("lodash/sortby"); -var escapeRegExp = require("lodash/escaperegexp"); +var trimEnd = require("lodash/trimEnd"); +var sortBy = require("lodash/sortBy"); +var escapeRegExp = require("lodash/escapeRegExp"); // recognizers/recognizers-number/src/number/constants.ts var Constants = class { diff --git a/package.json b/package.json index 9283a42d1e..113147f369 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ } }, "scripts": { - "postinstall": "yarn workspace botbuilder-vendors install", - "postbuild": "yarn workspace botbuilder-vendors build", "browser-functional-test": "yarn workspace browser-functional-tests test", "build": "wsrun -e -m -t build", "build-docs": "wsrun -e -m build-docs",