File tree Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
## Unreleased
8
8
9
+ ## [2.5.3]
10
+ ### Changed
11
+ - Use a separate `ts-node` compiler per-snippet to ensure that compilation of snippets is independent
12
+
9
13
## [2.5.2]
10
14
### Removed
11
15
- Obsolete Travis CI build badge from README
Original file line number Diff line number Diff line change 18
18
" typescript" ,
19
19
" verify"
20
20
],
21
- "version" : " 2.5.2 " ,
21
+ "version" : " 2.5.3 " ,
22
22
"main" : " dist/index.js" ,
23
23
"@types" : " dist/index.d.ts" ,
24
24
"bin" : {
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export type SnippetCompilationResult = {
24
24
} ;
25
25
26
26
export class SnippetCompiler {
27
- private readonly compiler : TSNode . Service ;
27
+ private readonly compilerConfig : TSNode . CreateOptions ;
28
28
29
29
constructor (
30
30
private readonly workingDirectory : string ,
@@ -35,11 +35,10 @@ export class SnippetCompiler {
35
35
packageDefinition . packageRoot ,
36
36
project
37
37
) ;
38
- const tsConfig = {
38
+ this . compilerConfig = {
39
39
...( configOptions . config as TSNode . CreateOptions ) ,
40
40
transpileOnly : false ,
41
41
} ;
42
- this . compiler = TSNode . create ( tsConfig ) ;
43
42
}
44
43
45
44
private static loadTypeScriptConfig (
@@ -124,7 +123,8 @@ export class SnippetCompiler {
124
123
const id = process . hrtime . bigint ( ) . toString ( ) ;
125
124
const codeFile = path . join ( this . workingDirectory , `block-${ id } .${ type } ` ) ;
126
125
await fsExtra . writeFile ( codeFile , code ) ;
127
- this . compiler . compile ( code , codeFile ) ;
126
+ const compiler = TSNode . create ( this . compilerConfig ) ;
127
+ compiler . compile ( code , codeFile ) ;
128
128
}
129
129
130
130
private removeTemporaryFilePaths (
Original file line number Diff line number Diff line change @@ -388,6 +388,31 @@ export const bob = () => (<div></div>);
388
388
}
389
389
) ;
390
390
391
+ verify . it ( "compiles snippets independently" , async ( ) => {
392
+ const snippet1 = `interface Foo { bar: 123 }` ;
393
+ const snippet2 = `interface Foo { bar: () => void }` ;
394
+ const typeScriptMarkdown = wrapSnippet ( snippet1 ) + wrapSnippet ( snippet2 ) ;
395
+ await createProject ( {
396
+ markdownFiles : [ { name : "README.md" , contents : typeScriptMarkdown } ] ,
397
+ } ) ;
398
+ return await TypeScriptDocsVerifier . compileSnippets ( ) . should . eventually . eql (
399
+ [
400
+ {
401
+ file : "README.md" ,
402
+ index : 1 ,
403
+ snippet : snippet1 ,
404
+ linesWithErrors : [ ] ,
405
+ } ,
406
+ {
407
+ file : "README.md" ,
408
+ index : 2 ,
409
+ snippet : snippet2 ,
410
+ linesWithErrors : [ ] ,
411
+ } ,
412
+ ]
413
+ ) ;
414
+ } ) ;
415
+
391
416
verify . it (
392
417
"compiles snippets containing modules" ,
393
418
genSnippet ,
You can’t perform that action at this time.
0 commit comments