Skip to content

Commit e3947c5

Browse files
committed
update ts options
1 parent 5459593 commit e3947c5

File tree

4 files changed

+10
-66
lines changed

4 files changed

+10
-66
lines changed

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

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,11 @@ 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 { addMetaInformation, createSystemJsSandbox } from '@codelab/code-demos';
16+
import { ScriptLoaderService } from '@codelab/sandbox-runner';
1817
import { BehaviorSubject, Subscription } from 'rxjs';
19-
import { handleTestMessage } from './tests';
2018
import { TestRunResult } from '@codelab/utils';
21-
import { createSystemJsSandbox } from '@codelab/code-demos';
22-
import { getTypeScript, ScriptLoaderService } from '@codelab/sandbox-runner';
23-
24-
const ts = getTypeScript();
25-
26-
// TODO(kirjs): This is a duplicate
27-
export function addMetaInformation(sandbox, files: { [key: string]: string }) {
28-
// sandbox.evalJs(`System.registry.delete(System.normalizeSync('./code'));`);
29-
30-
(sandbox.iframe.contentWindow as any).System.register(
31-
'code',
32-
[],
33-
function (exports) {
34-
return {
35-
setters: [],
36-
execute: function () {
37-
exports('ts', ts);
38-
exports('babylon', babylon);
39-
exports('babel_traverse', babel_traverse);
40-
exports('babel_types', babel_types);
41-
Object.entries(files)
42-
.filter(([moduleName]) => moduleName.match(/\.ts$/))
43-
.forEach(([path, code]) => {
44-
exports(path.replace(/[\/.-]/gi, '_'), code);
45-
exports(
46-
path.replace(/[\/.-]/gi, '_') + '_AST',
47-
ts.createSourceFile(path, code, ts.ScriptTarget.ES5)
48-
);
49-
});
50-
51-
Object.entries(files)
52-
.filter(([moduleName]) => moduleName.match(/\.html/))
53-
.forEach(([path, code]) => {
54-
const templatePath = path.replace(/[\/.-]/gi, '_');
55-
exports(templatePath, code);
56-
});
57-
},
58-
};
59-
}
60-
);
61-
}
19+
import { handleTestMessage } from './tests';
6220

6321
@Component({
6422
selector: 'codelab-simple-angular-test-runner',
@@ -126,8 +84,8 @@ export class SimpleAngularTestRunnerComponent
12684
},
12785
({ evalJs }) => {
12886
evalJs(this.scriptLoaderService.getScript('chai'));
129-
// evalJs(this.scriptLoaderService.getScript('shim'));
13087
evalJs(this.scriptLoaderService.getScript('zone'));
88+
evalJs(this.scriptLoaderService.getScript('reflectMetadata'));
13189
}
13290
);
13391

@@ -161,7 +119,7 @@ export class SimpleAngularTestRunnerComponent
161119
.some((a) => a);
162120

163121
if (!hasErrors) {
164-
sandbox.evalJs(`System.import('${this.bootstrap}')`);
122+
sandbox.evalJs(`System.import('./${this.bootstrap}')`);
165123
}
166124
});
167125
}

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)