Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut committed Dec 11, 2024
1 parent c3cf44f commit 5678e68
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 53 deletions.
4 changes: 0 additions & 4 deletions libraries/botbuilder-repo-utils/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-vendors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
106 changes: 67 additions & 39 deletions libraries/botbuilder-vendors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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(
Expand All @@ -136,44 +147,55 @@ ${pkg.name}

if (isBuild) {
const tsconfig = await readJsonFile<any>(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<string, any> = {};
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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
};
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5678e68

Please sign in to comment.