Skip to content

Commit e16a42e

Browse files
committed
Refactoring files, tests, and fixing linting errors.
1 parent 3d8025c commit e16a42e

30 files changed

+281
-223
lines changed

lib/packages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const packages = fs.readdirSync(packageRoot)
1111
.map(pkgName => ({ name: pkgName, root: path.join(packageRoot, pkgName) }))
1212
.filter(pkg => fs.statSync(pkg.root).isDirectory())
1313
.reduce((packages, pkg) => {
14-
let name = pkg == 'angular-cli' ? 'angular-cli' : `@angular-cli/${pkg.name}`;
14+
let pkgJson = JSON.parse(fs.readFileSync(path.join(pkg.root, 'package.json'), 'utf8'));
15+
let name = pkgJson['name'];
1516
packages[name] = {
1617
root: pkg.root,
1718
main: path.resolve(pkg.root, 'src/index.ts')

packages/base-href-webpack/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"experimentalDecorators": true,
54
"mapRoot": "",
65
"module": "commonjs",
76
"moduleResolution": "node",

packages/webpack/package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
{
2-
"name": "@angular-cli/webpack",
2+
"name": "@ngtools/webpack",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "lib/index.js",
6-
"scripts": {
7-
"build:main": "tsc",
8-
"test": "echo \"Error: no test specified\" && exit 0"
9-
},
10-
"author": "Rob Wormald <[email protected]>",
5+
"main": "./src/index.js",
116
"license": "MIT",
12-
"devDependencies": {
13-
"@types/node": "^6.0.39",
14-
"node-sass": "^3.8.0",
15-
"sass-loader": "^4.0.1",
7+
"peerDependencies": {
168
"typescript": "2.0.2",
17-
"webpack": "^2.1.0-beta.21",
189
"@angular/compiler-cli": "^0.6.0",
1910
"@angular/core": "^2.0.0"
2011
}

packages/webpack/src/codegen.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
import {Observable} from 'rxjs/Rx'
2-
import * as ts from 'typescript'
3-
import * as ngCompiler from '@angular/compiler-cli'
4-
import * as tscWrapped from '@angular/tsc-wrapped'
5-
import * as tsc from '@angular/tsc-wrapped/src/tsc'
6-
import * as path from 'path'
7-
import * as fs from 'fs'
1+
import {Observable} from 'rxjs/Rx';
2+
import * as ts from 'typescript';
3+
import * as ngCompiler from '@angular/compiler-cli';
4+
85

96
export interface CodeGenOptions {
107
program: ts.Program;
118
ngcOptions: any;
129
i18nOptions: any;
13-
resourceLoader?:any; //impl of ResourceLoader
10+
resourceLoader?: any; // Impl of ResourceLoader
1411
compilerHost: any;
1512
}
1613

17-
function _readConfig(tsConfigPath){
18-
let {config, error} = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
19-
if(error){
20-
throw error;
21-
}
22-
return config;
23-
}
2414

25-
export function createCodeGenerator({ngcOptions, i18nOptions, resourceLoader, compilerHost}){
15+
type ProgramFile = { fileName: string, sourceText: string };
2616

27-
return program => new Observable<{fileName:string, sourceText: string}>(codegenOutput => {
28-
//emit files from observable monkeypatch
17+
export function createCodeGenerator({ngcOptions, i18nOptions, resourceLoader, compilerHost}) {
18+
return (program: ts.Program) => new Observable<ProgramFile>(codegenOutput => {
19+
// Emit files from observable monkeypatch
2920
const writeFile = compilerHost.writeFile;
3021

3122
compilerHost.writeFile = (fileName, sourceText) => {
@@ -37,7 +28,7 @@ export function createCodeGenerator({ngcOptions, i18nOptions, resourceLoader, co
3728
i18nOptions,
3829
program,
3930
compilerHost,
40-
undefined, //TODO: hook in reflector host context
31+
undefined, // TODO: hook in reflector host context
4132
resourceLoader
4233
);
4334

packages/webpack/src/compiler.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import * as ngCompiler from '@angular/compiler-cli'
2-
import * as tscWrapped from '@angular/tsc-wrapped/src/compiler_host'
3-
import * as ts from 'typescript'
1+
import * as tscWrapped from '@angular/tsc-wrapped/src/compiler_host';
2+
import * as ts from 'typescript';
43

54

65
export class NgcWebpackCompilerHost extends tscWrapped.DelegatingHost {
7-
fileCache:Map<string,string> = new Map<string, string> ()
8-
constructor(delegate: ts.CompilerHost){
9-
super(delegate);
6+
fileCache = new Map<string, string>();
107

8+
constructor(delegate: ts.CompilerHost) {
9+
super(delegate);
1110
}
1211
}
1312

14-
export function createCompilerHost(tsConfig){
15-
const delegateHost = ts.createCompilerHost(tsConfig.compilerOptions);
13+
export function createCompilerHost(tsConfig: any) {
14+
const delegateHost = ts.createCompilerHost(tsConfig['compilerOptions']);
1615
return new NgcWebpackCompilerHost(delegateHost);
1716
}

packages/webpack/src/loader.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
//super simple TS transpiler loader for testing / isolated usage. does not type check!
2-
import * as path from 'path'
3-
import * as fs from 'fs'
4-
import * as ts from 'typescript'
1+
import * as ts from 'typescript';
52

6-
export function ngcLoader(sourceFile){
73

8-
return ts.transpileModule(sourceFile, {compilerOptions: {target: ts.ScriptTarget.ES5, module: ts.ModuleKind.ES2015}}).outputText;
4+
// Super simple TS transpiler loader for testing / isolated usage. does not type check!
5+
export function ngcLoader(sourceFile: string) {
6+
return ts.transpileModule(sourceFile, {
7+
compilerOptions: {
8+
target: ts.ScriptTarget.ES5,
9+
module: ts.ModuleKind.ES2015,
10+
}
11+
}).outputText;
912
}

0 commit comments

Comments
 (0)