Skip to content

Commit 801336b

Browse files
devversionmmalerba
authored andcommitted
build: fix missing example in generated example-module file (#18086)
The `example-module.ts` file which is generated by Bazel, currently misses the last example specified in the source manifest file. This is because the `$(locations)` expansion of Bazel results in a trailing new line in the manifest that throws of manifest parsing. We fix this by always trimming the file paths of the manifest.
1 parent 8948055 commit 801336b

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

tools/example-module/bazel-bin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if (require.main === module) {
99
const [sourceFileManifest, outputFile, baseDir] = process.argv.slice(2);
1010
const sourceFiles = readFileSync(sourceFileManifest, 'utf8')
1111
.split(' ')
12+
.map(filePath => filePath.trim())
1213
.filter(s => s.endsWith('.ts'));
1314

1415
generateExampleModule(sourceFiles, outputFile, baseDir);

tools/example-module/example-module.template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* tslint:disable */
2-
31
/**
42
******************************************************************************
53
* DO NOT MANUALLY EDIT THIS FILE. THIS FILE IS AUTOMATICALLY GENERATED.

tools/example-module/generate-example-module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function inlineExampleModuleTemplate(parsedData: AnalyzedExamples): string {
4141
.map(({additionalComponents, component, importPath}) =>
4242
createImportDeclaration(importPath!, additionalComponents.concat(component))),
4343
...exampleModules.map(({name, packagePath}) => createImportDeclaration(packagePath, [name])),
44-
].join('');
44+
].join('\n');
4545
const quotePlaceholder = '◬';
4646
const exampleList = exampleMetadata.reduce((result, data) => {
4747
return result.concat(data.component).concat(data.additionalComponents);
@@ -63,9 +63,9 @@ function inlineExampleModuleTemplate(parsedData: AnalyzedExamples): string {
6363

6464
return fs.readFileSync(require.resolve('./example-module.template'), 'utf8')
6565
.replace(/\${exampleImports}/g, exampleImports)
66-
.replace(/\${exampleComponents}/g, JSON.stringify(exampleComponents))
67-
.replace(/\${exampleList}/g, exampleList.join(', '))
68-
.replace(/\${exampleModules}/g, `[${exampleModules.map(m => m.name).join(', ')}]`)
66+
.replace(/\${exampleComponents}/g, JSON.stringify(exampleComponents, null, 2))
67+
.replace(/\${exampleList}/g, exampleList.join(',\n'))
68+
.replace(/\${exampleModules}/g, `[${exampleModules.map(m => m.name).join(',\n')}]`)
6969
.replace(new RegExp(`"${quotePlaceholder}|${quotePlaceholder}"`, 'g'), '');
7070
}
7171

0 commit comments

Comments
 (0)