Skip to content

Commit 730d7d7

Browse files
committed
update ts options
1 parent 3fb398b commit 730d7d7

File tree

4 files changed

+11
-66
lines changed

4 files changed

+11
-66
lines changed

apps/codelab/src/app/components/angular-test-runner/angular-test-runner.component.ts

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,13 @@ import {
1212
SimpleChanges,
1313
ViewChild,
1414
} from '@angular/core';
15-
import babel_traverse from '@babel/traverse';
16-
import * as babylon from 'babylon';
17-
import * as babel_types from 'babel-types';
15+
import { createSystemJsSandbox } from '@codelab/code-demos/src/lib/shared/sandbox';
16+
import { ScriptLoaderService } from '@codelab/code-demos/src/lib/shared/script-loader.service';
1817
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
1918
import { Subscription } from 'rxjs/internal/Subscription';
19+
import { TestRunResult } from '@codelab/utils/src/lib/test-results/common';
2020
import { handleTestMessage } from './tests';
21-
import { TestRunResult } from "@codelab/utils";
22-
import { createSystemJsSandbox } from "@codelab/code-demos";
23-
import { getTypeScript, ScriptLoaderService } from '@codelab/sandbox-runner';
24-
25-
const ts = getTypeScript();
26-
27-
// TODO(kirjs): This is a duplicate
28-
export function addMetaInformation(sandbox, files: { [key: string]: string }) {
29-
// sandbox.evalJs(`System.registry.delete(System.normalizeSync('./code'));`);
30-
31-
(sandbox.iframe.contentWindow as any).System.register(
32-
'code',
33-
[],
34-
function (exports) {
35-
return {
36-
setters: [],
37-
execute: function () {
38-
exports('ts', ts);
39-
exports('babylon', babylon);
40-
exports('babel_traverse', babel_traverse);
41-
exports('babel_types', babel_types);
42-
Object.entries(files)
43-
.filter(([moduleName]) => moduleName.match(/\.ts$/))
44-
.forEach(([path, code]) => {
45-
exports(path.replace(/[\/.-]/gi, '_'), code);
46-
exports(
47-
path.replace(/[\/.-]/gi, '_') + '_AST',
48-
ts.createSourceFile(path, code, ts.ScriptTarget.ES5)
49-
);
50-
});
51-
52-
Object.entries(files)
53-
.filter(([moduleName]) => moduleName.match(/\.html/))
54-
.forEach(([path, code]) => {
55-
const templatePath = path.replace(/[\/.-]/gi, '_');
56-
exports(templatePath, code);
57-
});
58-
},
59-
};
60-
}
61-
);
62-
}
21+
import { addMetaInformation } from "@codelab/code-demos/src/lib/shared/helpers";
6322

6423
@Component({
6524
selector: 'codelab-simple-angular-test-runner',
@@ -127,8 +86,8 @@ export class SimpleAngularTestRunnerComponent
12786
},
12887
({ evalJs }) => {
12988
evalJs(this.scriptLoaderService.getScript('chai'));
130-
// evalJs(this.scriptLoaderService.getScript('shim'));
13189
evalJs(this.scriptLoaderService.getScript('zone'));
90+
evalJs(this.scriptLoaderService.getScript('reflectMetadata'));
13291
}
13392
);
13493

@@ -162,7 +121,7 @@ export class SimpleAngularTestRunnerComponent
162121
.some((a) => a);
163122

164123
if (!hasErrors) {
165-
sandbox.evalJs(`System.import('${this.bootstrap}')`);
124+
sandbox.evalJs(`System.import('./${this.bootstrap}')`);
166125
}
167126
});
168127
}

libs/code-demos/src/lib/code-demo-runner/code-demo-runner.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class CodeDemoRunnerComponent
9191
url: this.url,
9292
},
9393
({ evalJs }) => {
94-
// evalJs(this.scriptLoaderService.getScript('shim'));
94+
evalJs(this.scriptLoaderService.getScript('reflectMetadata'));
9595
evalJs(this.scriptLoaderService.getScript('zone'));
9696
}
9797
);
@@ -157,7 +157,7 @@ export class CodeDemoRunnerComponent
157157

158158
if (jsFiles.length) {
159159
if (this.bootstrap && !hasErrors) {
160-
sandbox.evalJs(`System.import('${this.bootstrap}')`);
160+
sandbox.evalJs(`System.import('./${this.bootstrap}')`);
161161
}
162162
}
163163
});

libs/code-demos/src/lib/runner/compile-ts-files.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,16 @@ interface Output {
3030
}
3131

3232
const compilerOptions: TsTypes.CompilerOptions = {
33+
baseUrl: './',
3334
module: ts.ModuleKind.System,
3435
target: ts.ScriptTarget.ES2017,
3536
experimentalDecorators: true,
3637
emitDecoratorMetadata: true,
3738
noImplicitAny: true,
3839
declaration: true,
39-
baseUrl: './',
4040
lib: ['dom', 'es6'],
4141
};
4242

43-
// TODO(sancheez): List of named imports
44-
const namedRegisterModules = [
45-
'main',
46-
'code',
47-
'tests/test',
48-
'bootstrap'
49-
];
50-
5143

5244
type ObservableFiles = Observable<Files>;
5345

@@ -77,14 +69,10 @@ function watch(
7769
return undefined;
7870
}
7971

80-
const namedModule = namedRegisterModules.find((item) => fileName.toLowerCase().includes(item));
81-
8272
const baseName = fileName.replace('.ts', '');
8373

84-
const name = namedModule ? baseName: `./${baseName}`;
85-
8674
return ts.ScriptSnapshot.fromString(
87-
`/// <amd-module name="${name}" />\n` + file.file
75+
`/// <amd-module name="./${baseName}" />\n` + file.file
8876
);
8977
},
9078
getCurrentDirectory: () => options.baseUrl,

libs/code-demos/src/lib/shared/helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import * as babylon from 'babylon';
66
import * as babel_types from 'babel-types';
77

88
export function addMetaInformation(sandbox, files: { [key: string]: string }) {
9-
// sandbox.evalJs(`System.registry.delete(System.normalizeSync('./code'));`);
10-
119
(sandbox.iframe.contentWindow as any).System.register(
12-
'code',
10+
'./code',
1311
[],
1412
function (exports) {
1513
return {

0 commit comments

Comments
 (0)