Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit c8afdcc

Browse files
author
Chris McConnell
authored
Bug fixes for nuget versions and import/export. (#971)
If nuget versions use build rules will use most recent version. For C# will copy ExportedAssets to ImportedAssets. Fixed bug in timing.
1 parent 7d6ad59 commit c8afdcc

File tree

21 files changed

+50
-24
lines changed

21 files changed

+50
-24
lines changed

packages/dialog/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ This package is intended for Microsoft use only and should be consumed through @
1313

1414
# Commands
1515
<!-- commands -->
16-
* [`bf dialog`](#bf-dialog)
17-
* [`bf dialog:merge PATTERNS`](#bf-dialogmerge-patterns)
18-
* [`bf dialog:verify PATTERNS`](#bf-dialogverify-patterns)
16+
- [@microsoft/bf-dialog](#microsoftbf-dialog)
17+
- [Relevant docs](#relevant-docs)
18+
- [Commands](#commands)
19+
- [`bf dialog`](#bf-dialog)
20+
- [`bf dialog:merge PATTERNS`](#bf-dialogmerge-patterns)
21+
- [`bf dialog:verify PATTERNS`](#bf-dialogverify-patterns)
1922

2023
## `bf dialog`
2124

@@ -29,11 +32,11 @@ OPTIONS
2932
-h, --help Dialog command help
3033
```
3134

32-
_See code: [src/commands/dialog/index.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/src/commands/dialog/index.ts)_
35+
_See code: [src/commands/dialog/index.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src/commands/dialog/index.ts)_
3336

3437
## `bf dialog:merge PATTERNS`
3538

36-
Merge <kind>.schema and <kind>[.<locale>].uischema definitions from a project and its dependencies into a single .schema for describing .dialog files and a per locale .uischema for describing how Composer shows them. For C#, ensures all nuget declarative resources are included in the same location.
39+
Merge `<kind>.schema` and `<kind>[.<locale>].uischema` definitions from a project and its dependencies into a single .schema for describing .dialog files and a per locale .uischema for describing how Composer shows them. For C#, ensures all nuget declarative resources in ExportedAssets are copied to ImportedAssets in the same location.
3740

3841
```
3942
USAGE
@@ -54,7 +57,7 @@ EXAMPLES
5457
$ bf dialog:merge package.json -o app.schema
5558
```
5659

57-
_See code: [src/commands/dialog/merge.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/src/commands/dialog/merge.ts)_
60+
_See code: [src/commands/dialog/merge.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src/commands/dialog/merge.ts)_
5861

5962
## `bf dialog:verify PATTERNS`
6063

@@ -72,5 +75,5 @@ OPTIONS
7275
-v, --verbose Show verbose output
7376
```
7477

75-
_See code: [src/commands/dialog/verify.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/src/commands/dialog/verify.ts)_
78+
_See code: [src/commands/dialog/verify.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src/commands/dialog/verify.ts)_
7679
<!-- commandsstop -->

packages/dialog/src/commands/dialog/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Command, flags} from '@microsoft/bf-cli-command'
77
import SchemaMerger from '../../library/schemaMerger'
88

99
export default class DialogMerge extends Command {
10-
static description = 'Merge `<kind>.schema` and `<kind>[.<locale>].uischema` definitions from a project and its dependencies into a single .schema for describing .dialog files and a per locale .uischema for describing how Composer shows them. For C#, ensures all nuget declarative resources are included in the same location.'
10+
static description = 'Merge `<kind>.schema` and `<kind>[.<locale>].uischema` definitions from a project and its dependencies into a single .schema for describing .dialog files and a per locale .uischema for describing how Composer shows them. For C#, ensures all nuget declarative resources in ExportedAssets are copied to ImportedAssets in the same location.'
1111

1212
static args = [
1313
{name: 'patterns', required: true, description: 'Any number of glob regex patterns to match .csproj, .nuspec or package.json files.'},

packages/dialog/src/library/schemaMerger.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export default class SchemaMerger {
288288
try {
289289
this.log('Finding component files')
290290
await this.expandPackages(await glob(this.patterns.map(p => p.replace(/\\/g, '/'))))
291-
this.analyze()
291+
await this.analyze()
292292
let schema = await this.mergeSchemas()
293293
this.log('')
294294
await this.mergeUISchemas(schema)
@@ -476,10 +476,11 @@ export default class SchemaMerger {
476476
this.verifySchema(finalSchema)
477477
if (!this.failed) {
478478
// Verify all refs work
479-
let start = process.hrtime()
479+
let start = process.hrtime.bigint()
480480
fullSchema = await parser.dereference(clone(finalSchema))
481-
let end = process.hrtime(start)[1] / 1000000000
482-
this.vlog(`Expanding all $ref took ${end} seconds`)
481+
let end = process.hrtime.bigint()
482+
let elapsed = Number(end - start) / 1000000000
483+
this.vlog(`Expanding all $ref took ${elapsed} seconds`)
483484
this.log(`Writing ${this.currentFile}`)
484485
await fs.writeJSON(this.currentFile, finalSchema, this.jsonOptions)
485486
}
@@ -597,18 +598,23 @@ export default class SchemaMerger {
597598
}
598599
}
599600
if (isCS) {
600-
let generatedPath = ppath.join(ppath.dirname(this.output), 'generated')
601-
this.log(`Copying C# package assets to ${generatedPath}`)
601+
let generatedPath = ppath.join(ppath.dirname(this.output), 'ImportedAssets')
602+
let found = false
602603
for (let files of this.files.values()) {
603604
for (let componentPaths of files.values()) {
604605
for (let componentPath of componentPaths) {
605606
let component = componentPath.component
606607
let path = componentPath.path
607-
// Don't copy .schema/.uischema so that we don't pick-up in project
608-
if (!component.isCSProject() && !path.endsWith('.schema') && !path.endsWith('.uischema')) {
608+
let relativePath = ppath.relative(ppath.dirname(component.path), path)
609+
// Copy anything found in exportedassets outside of project
610+
if (!component.isCSProject() && relativePath.toLowerCase().startsWith('exportedassets')) {
609611
// Copy package files to output
610-
let relativePath = ppath.relative(ppath.dirname(component.path), path)
611-
let outputPath = ppath.join(generatedPath, componentPath.component.name, relativePath)
612+
if (!found) {
613+
found = true
614+
this.log(`Copying C# package exported assets to ${generatedPath}`)
615+
}
616+
let remaining = relativePath.substring('exportedAssets/'.length)
617+
let outputPath = ppath.join(generatedPath, componentPath.component.name, remaining)
612618
this.vlog(`Copying ${path} to ${outputPath}`)
613619
await fs.ensureDir(ppath.dirname(outputPath))
614620
await fs.copyFile(path, outputPath)
@@ -779,7 +785,8 @@ export default class SchemaMerger {
779785
this.popParent()
780786
}
781787
} else if (this.debug) {
782-
this.parsingWarning(' Could not find nuspec')
788+
// Assume missing nuget is because of build complexities
789+
this.parsingWarning('Could not find nuget')
783790
}
784791
}
785792
}
@@ -796,9 +803,16 @@ export default class SchemaMerger {
796803
for (let pkgVersion of await fs.readdir(pkgPath)) {
797804
versions.push(pkgVersion.toLowerCase())
798805
}
799-
minVersion = minVersion || '0.0.0'
800806
// NOTE: The semver package does not handle more complex nuget range revisions
801807
// We get an exception and will ignore those dependencies.
808+
minVersion = minVersion || '0.0.0'
809+
if (minVersion.startsWith('$')) {
810+
// Deal with build variables by installing most recent version
811+
minVersion = nuget.maxSatisfying(versions, '0-1000')
812+
if (this.debug) {
813+
this.parsingWarning(`Using most recent version ${minVersion}`)
814+
}
815+
}
802816
let version = nuget.minSatisfying(versions, minVersion)
803817
pkgPath = ppath.join(pkgPath, version || '')
804818
let nuspecPath = ppath.join(pkgPath, `${packageName}.nuspec`)
@@ -982,7 +996,7 @@ export default class SchemaMerger {
982996
// Analyze component files to identify:
983997
// 1) Multiple definitions of the same file in a component. (Error)
984998
// 2) Multiple definitions of .schema across projects/components (Error)
985-
private analyze() {
999+
private async analyze() {
9861000
for (let [ext, files] of this.files.entries()) {
9871001
for (let [file, records] of files.entries()) {
9881002
let winner = records[0]
@@ -993,7 +1007,13 @@ export default class SchemaMerger {
9931007
if (winner.component === alt.component) {
9941008
same.push(alt)
9951009
} else if (ext === '.schema') {
996-
conflicts.push(alt)
1010+
// Check for same content which can happen when project and nuget from project are
1011+
// both being used.
1012+
let winnerSrc = await fs.readFile(winner.path, 'utf8')
1013+
let altSrc = await fs.readFile(alt.path, 'utf8')
1014+
if (winnerSrc !== altSrc) {
1015+
conflicts.push(alt)
1016+
}
9971017
}
9981018
}
9991019
}
@@ -1048,6 +1068,9 @@ export default class SchemaMerger {
10481068
// Convert XML to JSON
10491069
private async xmlToJSON(path: string): Promise<any> {
10501070
let xml = (await fs.readFile(path)).toString()
1071+
if (xml.startsWith('\uFEFF')) {
1072+
xml = xml.slice(1)
1073+
}
10511074
return new Promise((resolve, reject) =>
10521075
xp.parseString(xml, (err: Error, result: any) => {
10531076
if (err) {

packages/dialog/test/commands/dialog/merge.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('dialog:merge', async () => {
172172
assert(countMatches(/Copying.*nuget3.lg/i, lines) === 1, 'Did not copy .lg')
173173
assert(countMatches(/Copying.*nuget3.lu/i, lines) === 1, 'Did not copy .lu')
174174
assert(countMatches(/Copying.*nuget3.qna/i, lines) === 1, 'Did not copy .qna')
175-
assert(await fs.pathExists(ppath.join(tempDir, 'generated', 'nuget3', 'assets', 'nuget3.qna')), 'Did not copy directory')
175+
assert(await fs.pathExists(ppath.join(tempDir, 'ImportedAssets', 'nuget3', 'stuff', 'nuget3.qna')), 'Did not copy directory')
176176
await compareToOracle('project3.schema')
177177
await compareToOracle('project3.en-us.uischema')
178178
})

packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/assets/nuget1-10.lg renamed to packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/exportedAssets/nuget1-10.lg

File renamed without changes.

packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/assets/nuget1-10.lu renamed to packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/exportedAssets/nuget1-10.lu

File renamed without changes.

packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/assets/nuget1-10.qna renamed to packages/dialog/test/commands/dialog/nuget/nuget1/10.0.1/exportedAssets/nuget1-10.qna

File renamed without changes.

packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/assets/nuget1-11.lg renamed to packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/exportedAssets/nuget1-11.lg

File renamed without changes.

packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/assets/nuget1-11.lu renamed to packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/exportedAssets/nuget1-11.lu

File renamed without changes.

packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/assets/nuget1-11.qna renamed to packages/dialog/test/commands/dialog/nuget/nuget1/11.0.0/exportedAssets/nuget1-11.qna

File renamed without changes.

0 commit comments

Comments
 (0)