Skip to content

Commit dafdc6a

Browse files
authoredJul 22, 2020
fix: remove extension from Stackblitz examples (#841)
In d00cb12 the docs generation script changed the `indexFilename` to include the file extension which ends up propagating to TS imports inside generated Stackblitz examples. These changes strip the extension. Fixes #20061.
1 parent c26bde2 commit dafdc6a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
 

‎material.angular.io/src/app/shared/stack-blitz/stack-blitz-writer.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('StackBlitzWriter', () => {
2929
data = new ExampleData('');
3030
data.componentNames = [];
3131
data.exampleFiles = ['test.ts', 'test.html', 'src/detail.ts'];
32+
data.indexFilename = data.exampleFiles[0];
3233

3334
// Fake the example in the `EXAMPLE_COMPONENTS`. The stack blitz writer relies on
3435
// module information for the example in order to read the example sources from disk.

‎material.angular.io/src/app/shared/stack-blitz/stack-blitz-writer.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ export class StackBlitzWriter {
213213
// Replace `bootstrap: [MaterialDocsExample]`
214214
// will be replaced as `bootstrap: [ButtonDemo]`
215215
// This assumes the first component listed in the main component
216-
const componentList = data.componentNames[0];
217216
fileContent = fileContent.
218217
replace(/bootstrap: \[MaterialDocsExample]/g,
219-
`bootstrap: [${componentList}]`);
218+
`bootstrap: [${data.componentNames[0]}]`);
219+
220+
const dotIndex = data.indexFilename.lastIndexOf('.');
221+
const importFileName = data.indexFilename.slice(0, dotIndex === -1 ? undefined : dotIndex);
222+
fileContent = fileContent.replace(/material-docs-example/g, importFileName);
220223

221-
fileContent = fileContent.replace(/material-docs-example/g, data.indexFilename);
222224
}
223225
return fileContent;
224226
}

0 commit comments

Comments
 (0)
Please sign in to comment.