Skip to content

Commit

Permalink
fix(@angular/cli): remove typescript dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Oct 25, 2017
1 parent efcf1dc commit 8cce41d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
14 changes: 11 additions & 3 deletions packages/@angular/cli/models/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
import { stripIndent } from 'common-tags';

import {SchemaClass, SchemaClassFactory} from '@ngtools/json-schema';
Expand Down Expand Up @@ -80,13 +79,22 @@ export class CliConfig<JsonType> {
}

static fromConfigPath<T>(configPath: string, otherPath: string[] = []): CliConfig<T> {
const configContent = ts.sys.readFile(configPath) || '{}';
const schemaContent = fs.readFileSync(DEFAULT_CONFIG_SCHEMA_PATH, 'utf-8');
let configContent = '{}';
if (fs.existsSync(configPath)) {
configContent = fs.readFileSync(configPath, 'utf-8') || '{}';
}


let otherContents = new Array<string>();
if (configPath !== otherPath[0]) {
otherContents = otherPath
.map(path => ts.sys.readFile(path))
.map(path => {
if (fs.existsSync(path)) {
return fs.readFileSync(path, 'utf-8');
}
return undefined;
})
.filter(content => !!content);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/@angular/cli/models/webpack-configs/browser.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import * as fs from 'fs';
import * as webpack from 'webpack';
import * as path from 'path';
import * as ts from 'typescript';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');

import { packageChunkSort } from '../../utilities/package-chunk-sort';
import { BaseHrefWebpackPlugin } from '../../lib/base-href-webpack';
import { extraEntryParser, lazyChunksFilter } from './utils';
import { WebpackConfigOptions } from '../webpack-config';
import { requireProjectModule } from '../../utilities/require-project-module';


export function getBrowserConfig(wco: WebpackConfigOptions) {
const { projectRoot, buildOptions, appConfig } = wco;

const projectTs = requireProjectModule(projectRoot, 'typescript');

const appRoot = path.resolve(projectRoot, appConfig.root);

let extraPlugins: any[] = [];
Expand Down Expand Up @@ -78,8 +80,8 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
}));
}

const supportES2015 = wco.tsConfig.options.target !== ts.ScriptTarget.ES3
&& wco.tsConfig.options.target !== ts.ScriptTarget.ES5;
const supportES2015 = wco.tsConfig.options.target !== projectTs.ScriptTarget.ES3
&& wco.tsConfig.options.target !== projectTs.ScriptTarget.ES5;

return {
resolve: {
Expand Down
8 changes: 5 additions & 3 deletions packages/@angular/cli/models/webpack-configs/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as path from 'path';
import * as webpack from 'webpack';
import * as fs from 'fs';
import * as semver from 'semver';
import * as ts from 'typescript';
import { stripIndent } from 'common-tags';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import { PurifyPlugin } from '@angular-devkit/build-optimizer';
import { StaticAssetPlugin } from '../../plugins/static-asset';
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin';
import { WebpackConfigOptions } from '../webpack-config';
import { readTsconfig } from '../../utilities/read-tsconfig';
import { requireProjectModule } from '../../utilities/require-project-module';

const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

Expand All @@ -24,6 +24,8 @@ const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
export function getProdConfig(wco: WebpackConfigOptions) {
const { projectRoot, buildOptions, appConfig } = wco;

const projectTs = requireProjectModule(projectRoot, 'typescript');

let extraPlugins: any[] = [];
let entryPoints: { [key: string]: string[] } = {};

Expand Down Expand Up @@ -124,8 +126,8 @@ export function getProdConfig(wco: WebpackConfigOptions) {
// Read the tsconfig to determine if we should apply ES6 uglify.
const tsconfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsconfig);
const tsConfig = readTsconfig(tsconfigPath);
const supportES2015 = tsConfig.options.target !== ts.ScriptTarget.ES3
&& tsConfig.options.target !== ts.ScriptTarget.ES5;
const supportES2015 = tsConfig.options.target !== projectTs.ScriptTarget.ES3
&& tsConfig.options.target !== projectTs.ScriptTarget.ES5;

return {
entry: entryPoints,
Expand Down
9 changes: 6 additions & 3 deletions packages/@angular/cli/models/webpack-configs/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { WebpackConfigOptions } from '../webpack-config';
import * as ts from 'typescript';
import { requireProjectModule } from '../../utilities/require-project-module';

/**
* Returns a partial specific to creating a bundle for node
* @param wco Options which are include the build options and app config
*/
export function getServerConfig(wco: WebpackConfigOptions) {
const supportES2015 = wco.tsConfig.options.target !== ts.ScriptTarget.ES3
&& wco.tsConfig.options.target !== ts.ScriptTarget.ES5;

const projectTs = requireProjectModule(wco.projectRoot, 'typescript');

const supportES2015 = wco.tsConfig.options.target !== projectTs.ScriptTarget.ES3
&& wco.tsConfig.options.target !== projectTs.ScriptTarget.ES5;

const config: any = {
resolve: {
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"style-loader": "^0.13.1",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"typescript": ">=2.0.0 <2.6.0",
"uglifyjs-webpack-plugin": "1.0.0",
"url-loader": "^0.6.2",
"webpack": "~3.8.1",
Expand Down
5 changes: 2 additions & 3 deletions packages/@angular/cli/tasks/eject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
import * as webpack from 'webpack';
import chalk from 'chalk';

Expand Down Expand Up @@ -511,7 +510,7 @@ export default Task.extend({
})
// Read the package.json and update it to include npm scripts. We do this first so that if
// an error already exists
.then(() => ts.sys.readFile('package.json'))
.then(() => fs.readFileSync('package.json', 'utf-8'))
.then((packageJson: string) => JSON.parse(packageJson))
.then((packageJson: any) => {
const scripts = packageJson['scripts'];
Expand Down Expand Up @@ -587,7 +586,7 @@ export default Task.extend({

return writeFile('package.json', JSON.stringify(packageJson, null, 2) + '\n');
})
.then(() => JSON.parse(ts.sys.readFile(tsConfigPath)))
.then(() => JSON.parse(fs.readFileSync(tsConfigPath, 'utf-8')))
.then((tsConfigJson: any) => {
if (!tsConfigJson.exclude || force) {
// Make sure we now include tests. Do not touch otherwise.
Expand Down
2 changes: 2 additions & 0 deletions packages/@angular/cli/tasks/lint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// We only use typescript for type information here.
// @ignoreDep typescript
import chalk from 'chalk';
import * as fs from 'fs';
import * as glob from 'glob';
Expand Down
6 changes: 4 additions & 2 deletions packages/@angular/cli/utilities/read-tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as path from 'path';
import * as ts from 'typescript';
import { requireProjectModule } from '../utilities/require-project-module';

export function readTsconfig(tsconfigPath: string) {
const configResult = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
const tsConfig = ts.parseJsonConfigFileContent(configResult.config, ts.sys,
const projectTs = requireProjectModule(path.dirname(tsconfigPath), 'typescript');
const configResult = projectTs.readConfigFile(tsconfigPath, ts.sys.readFile);
const tsConfig = projectTs.parseJsonConfigFileContent(configResult.config, ts.sys,
path.dirname(tsconfigPath), undefined, tsconfigPath);
return tsConfig;
}
Expand Down

0 comments on commit 8cce41d

Please sign in to comment.