Skip to content

Commit

Permalink
fix(@ngtools/webpack): enforce typescript dep without peerDep
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Oct 25, 2017
1 parent 8cce41d commit 607087e
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/@angular/cli/utilities/read-tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as path from 'path';
import * as ts from 'typescript';
import { requireProjectModule } from '../utilities/require-project-module';

export function readTsconfig(tsconfigPath: string) {
const projectTs = requireProjectModule(path.dirname(tsconfigPath), 'typescript');
const configResult = projectTs.readConfigFile(tsconfigPath, ts.sys.readFile);
const tsConfig = projectTs.parseJsonConfigFileContent(configResult.config, ts.sys,
const configResult = projectTs.readConfigFile(tsconfigPath, projectTs.sys.readFile);
const tsConfig = projectTs.parseJsonConfigFileContent(configResult.config, projectTs.sys,
path.dirname(tsconfigPath), undefined, tsconfigPath);
return tsConfig;
}
Expand Down
1 change: 0 additions & 1 deletion packages/@ngtools/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"source-map": "^0.5.6"
},
"peerDependencies": {
"typescript": "^2.0.2",
"webpack": "^2.2.0 || ^3.0.0"
}
}
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as fs from 'fs';
import { fork, ForkOptions, ChildProcess } from 'child_process';
import * as path from 'path';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import {basename, dirname, join, sep} from 'path';
import * as fs from 'fs';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/entry_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as fs from 'fs';
import {join} from 'path';
import * as ts from 'typescript';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/gather_diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { time, timeEnd } from './benchmark';
Expand Down
19 changes: 17 additions & 2 deletions packages/@ngtools/webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// @ignoreDep typescript
import { satisfies } from 'semver';

// Test if typescript is available
try {
const version = require('typescript').version;
if (!satisfies(version, '^2.0.2')) {
throw new Error();
}
} catch (e) {
throw new Error('Could not find local "typescript" package.'
+ 'The "@ngtools/webpack" package requires a local "typescript@^2.0.2" package to be installed.'
+ e);
}

export * from './plugin';
export * from './angular_compiler_plugin';
export * from './extract_i18n_plugin';
export {ngcLoader as default} from './loader';
export {PathsPlugin} from './paths-plugin';
export { ngcLoader as default } from './loader';
export { PathsPlugin } from './paths-plugin';
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/ngtools_api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ignoreDep @angular/compiler-cli
// @ignoreDep typescript
/**
* This is a copy of types in @compiler-cli/src/ngtools_api.d.ts file,
* together with safe imports for private apis for cases where @angular/compiler-cli isn't
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/paths-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as path from 'path';
import * as ts from 'typescript';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/refactor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
// TODO: move this in its own package.
import * as path from 'path';
import * as ts from 'typescript';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/transformers/ast_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { WebpackCompilerHost } from '../compiler_host';
import { makeTransform, TransformOperation } from './make_transform';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { oneLine, stripIndent } from 'common-tags';
import { transformTypescript } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as path from 'path';
import * as ts from 'typescript';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { oneLine, stripIndent } from 'common-tags';
import { transformTypescript } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes, getFirstNode } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes, getFirstNode } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { oneLine, stripIndent } from 'common-tags';
import { transformTypescript } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes, getFirstNode } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { oneLine, stripIndent } from 'common-tags';
import { transformTypescript } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';
import { oneLine, stripIndent } from 'common-tags';
import { transformTypescript } from './ast_helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as ts from 'typescript';

import { findAstNodes, getFirstNode } from './ast_helpers';
Expand Down
1 change: 1 addition & 0 deletions packages/@ngtools/webpack/src/type_checker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ignoreDep typescript
import * as process from 'process';
import * as ts from 'typescript';
import chalk from 'chalk';
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/tests/misc/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ export default function() {
return ng('version')
.then(() => deleteFile('.angular-cli.json'))
// doesn't fail on a project with missing .angular-cli.json
.then(() => ng('version'))
// Doesn't fail outside a project.
.then(() => process.chdir('/'))
.then(() => ng('version'));
}

0 comments on commit 607087e

Please sign in to comment.