Skip to content

Commit fd1fefe

Browse files
filipesilvahansl
authored andcommitted
fix(@ngtools/webpack): enforce typescript dep without peerDep
1 parent a28a967 commit fd1fefe

26 files changed

+46
-6
lines changed

packages/@angular/cli/utilities/read-tsconfig.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as path from 'path';
2-
import * as ts from 'typescript';
32
import { requireProjectModule } from '../utilities/require-project-module';
43

54
export function readTsconfig(tsconfigPath: string) {
65
const projectTs = requireProjectModule(path.dirname(tsconfigPath), 'typescript');
7-
const configResult = projectTs.readConfigFile(tsconfigPath, ts.sys.readFile);
8-
const tsConfig = projectTs.parseJsonConfigFileContent(configResult.config, ts.sys,
6+
const configResult = projectTs.readConfigFile(tsconfigPath, projectTs.sys.readFile);
7+
const tsConfig = projectTs.parseJsonConfigFileContent(configResult.config, projectTs.sys,
98
path.dirname(tsconfigPath), undefined, tsconfigPath);
109
return tsConfig;
1110
}

packages/@ngtools/webpack/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"source-map": "^0.5.6"
3535
},
3636
"peerDependencies": {
37-
"typescript": "^2.0.2",
3837
"webpack": "^2.2.0 || ^3.0.0"
3938
}
4039
}

packages/@ngtools/webpack/src/angular_compiler_plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as fs from 'fs';
23
import { fork, ForkOptions, ChildProcess } from 'child_process';
34
import * as path from 'path';

packages/@ngtools/webpack/src/compiler_host.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import {basename, dirname, join, sep} from 'path';
34
import * as fs from 'fs';

packages/@ngtools/webpack/src/entry_resolver.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as fs from 'fs';
23
import {join} from 'path';
34
import * as ts from 'typescript';

packages/@ngtools/webpack/src/gather_diagnostics.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { time, timeEnd } from './benchmark';
+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
// @ignoreDep typescript
2+
import { satisfies } from 'semver';
3+
4+
// Test if typescript is available. This is a hack. We should be using peerDependencies instead
5+
// but can't until we split global and local packages.
6+
// See https://github.com/angular/angular-cli/issues/8107#issuecomment-338185872
7+
try {
8+
const version = require('typescript').version;
9+
if (!satisfies(version, '^2.0.2')) {
10+
throw new Error();
11+
}
12+
} catch (e) {
13+
throw new Error('Could not find local "typescript" package.'
14+
+ 'The "@ngtools/webpack" package requires a local "typescript@^2.0.2" package to be installed.'
15+
+ e);
16+
}
17+
118
export * from './plugin';
219
export * from './angular_compiler_plugin';
320
export * from './extract_i18n_plugin';
4-
export {ngcLoader as default} from './loader';
5-
export {PathsPlugin} from './paths-plugin';
21+
export { ngcLoader as default } from './loader';
22+
export { PathsPlugin } from './paths-plugin';

packages/@ngtools/webpack/src/ngtools_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ignoreDep @angular/compiler-cli
2+
// @ignoreDep typescript
23
/**
34
* This is a copy of types in @compiler-cli/src/ngtools_api.d.ts file,
45
* together with safe imports for private apis for cases where @angular/compiler-cli isn't

packages/@ngtools/webpack/src/paths-plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as path from 'path';
23
import * as ts from 'typescript';
34
import {

packages/@ngtools/webpack/src/plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as fs from 'fs';
23
import * as path from 'path';
34
import * as ts from 'typescript';

packages/@ngtools/webpack/src/refactor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
// TODO: move this in its own package.
23
import * as path from 'path';
34
import * as ts from 'typescript';

packages/@ngtools/webpack/src/transformers/ast_helpers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { WebpackCompilerHost } from '../compiler_host';
34
import { makeTransform, TransformOperation } from './make_transform';

packages/@ngtools/webpack/src/transformers/export_lazy_module_map.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { oneLine, stripIndent } from 'common-tags';
34
import { transformTypescript } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/export_lazy_module_map.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as path from 'path';
23
import * as ts from 'typescript';
34

packages/@ngtools/webpack/src/transformers/export_ngfactory.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { oneLine, stripIndent } from 'common-tags';
34
import { transformTypescript } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/export_ngfactory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes, getFirstNode } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/insert_import.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes, getFirstNode } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/register_locale_data.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { oneLine, stripIndent } from 'common-tags';
34
import { transformTypescript } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/register_locale_data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes, getFirstNode } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/remove_import.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/replace_bootstrap.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { oneLine, stripIndent } from 'common-tags';
34
import { transformTypescript } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/replace_bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/replace_resources.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23
import { oneLine, stripIndent } from 'common-tags';
34
import { transformTypescript } from './ast_helpers';

packages/@ngtools/webpack/src/transformers/replace_resources.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as ts from 'typescript';
23

34
import { findAstNodes, getFirstNode } from './ast_helpers';

packages/@ngtools/webpack/src/type_checker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ignoreDep typescript
12
import * as process from 'process';
23
import * as ts from 'typescript';
34
import chalk from 'chalk';

tests/e2e/tests/misc/version.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ export default function() {
66
return ng('version')
77
.then(() => deleteFile('.angular-cli.json'))
88
// doesn't fail on a project with missing .angular-cli.json
9+
.then(() => ng('version'))
10+
// Doesn't fail outside a project.
11+
.then(() => process.chdir('/'))
912
.then(() => ng('version'));
1013
}

0 commit comments

Comments
 (0)