Skip to content

Commit 56ffa1c

Browse files
alan-agius4clydin
authored andcommitted
build: vendor typescript 3.6 in build optimizer
With this change we "vendor" TypeScript 3.6 in build optimizer instead of using directly the npm package. Reasons: - We cannot update to a more recent version of TypeScript due to microsoft/TypeScript#38412 - Yarn workspace are not supported under Bazel. This means currently we are running unit testswhich uses a different TypeScript version at runtime. - In TypeScript 3.9, the shape of ES2015 classes changed microsoft/TypeScript#32011, this requires some changes in the UT expects, but this again will not be correct to change now.
1 parent c8ebbe0 commit 56ffa1c

File tree

14 files changed

+133983
-13
lines changed

14 files changed

+133983
-13
lines changed

packages/angular_devkit/build_optimizer/BUILD.bazel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ ts_library(
3131
module_name = "@angular-devkit/build-optimizer",
3232
module_root = "src/index.d.ts",
3333
deps = [
34+
"//packages/angular_devkit/build_optimizer/third_party/github.com/Microsoft/TypeScript",
3435
"@npm//@types/node",
3536
"@npm//@types/webpack",
3637
"@npm//@types/webpack-sources",
3738
"@npm//source-map",
3839
"@npm//tslib",
39-
"@npm//typescript",
4040
],
4141
)
4242

@@ -47,6 +47,7 @@ ts_library(
4747
# @external_begin
4848
deps = [
4949
":build_optimizer",
50+
"//packages/angular_devkit/build_optimizer/third_party/github.com/Microsoft/TypeScript",
5051
"//packages/angular_devkit/core",
5152
"@npm//source-map",
5253
],
@@ -62,6 +63,15 @@ jasmine_node_test(
6263
],
6364
)
6465

66+
jasmine_node_test(
67+
name = "no_typescript_runtime_dep_test",
68+
srcs = ["no_typescript_runtime_dep_spec.js"],
69+
deps = [
70+
":build_optimizer",
71+
"@npm//jasmine",
72+
],
73+
)
74+
6575
pkg_npm(
6676
name = "npm_package",
6777
deps = [
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
12+
const pkg = path.dirname(require.resolve(__filename));
13+
describe('@angular-devkit/build-optimizer javascript code', () => {
14+
fs.readdirSync(pkg).forEach(d => {
15+
const dir = path.join(pkg, d);
16+
if (!fs.statSync(dir).isDirectory()) return;
17+
18+
it(`${d} has no typescript dependency`, () => {
19+
function check(subdir) {
20+
fs.readdirSync(subdir).forEach(f => {
21+
const file = path.join(subdir, f);
22+
if (fs.statSync(file).isDirectory()) {
23+
check(file);
24+
} else if (file.endsWith('.js')) {
25+
const content = fs.readFileSync(file, { encoding: 'utf-8' });
26+
if (content.includes(`require("typescript")`) || content.includes(`require('typescript')`)) {
27+
fail(`${file} has a typescript import`);
28+
}
29+
}
30+
});
31+
}
32+
check(dir);
33+
});
34+
});
35+
});

packages/angular_devkit/build_optimizer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"loader-utils": "2.0.0",
1313
"source-map": "0.7.3",
1414
"tslib": "1.11.2",
15-
"typescript": "3.6.5",
1615
"webpack-sources": "1.4.3"
1716
}
1817
}

packages/angular_devkit/build_optimizer/src/helpers/ast-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import * as tslib from 'tslib';
9-
import * as ts from 'typescript';
9+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1010

1111
const pureFunctionComment = '@__PURE__';
1212

packages/angular_devkit/build_optimizer/src/helpers/transform-javascript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { RawSourceMap } from 'source-map';
9-
import * as ts from 'typescript';
9+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1010

1111

1212
export interface TransformJavascriptOptions {

packages/angular_devkit/build_optimizer/src/transforms/prefix-classes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import * as ts from 'typescript';
8+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
99
import { addPureComment } from '../helpers/ast-utils';
1010

1111
export function testPrefixClasses(content: string) {

packages/angular_devkit/build_optimizer/src/transforms/prefix-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import * as ts from 'typescript';
8+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
99
import { addPureComment, getCleanHelperName, hasPureComment } from '../helpers/ast-utils';
1010

1111
export function getPrefixFunctionsTransformer(): ts.TransformerFactory<ts.SourceFile> {

packages/angular_devkit/build_optimizer/src/transforms/scrub-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import * as ts from 'typescript';
8+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
99
import { collectDeepNodes } from '../helpers/ast-utils';
1010

1111
export function testScrubFile(content: string) {

packages/angular_devkit/build_optimizer/src/transforms/wrap-enums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import * as ts from 'typescript';
8+
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
99
import { addPureComment } from '../helpers/ast-utils';
1010

1111
function isBlockLike(node: ts.Node): node is ts.BlockLike {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("//tools:defaults.bzl", "ts_library")
2+
3+
# files fetched on 2020-05-08 from
4+
# https://github.com/Microsoft/TypeScript/tree/v3.6.4
5+
licenses(["notice"]) # Apache 2.0
6+
7+
ts_library(
8+
name = "TypeScript",
9+
srcs = ["lib/typescript.d.ts"],
10+
data = ["lib/typescript.js"],
11+
visibility = [
12+
"//packages/angular_devkit/build_angular:__subpackages__",
13+
"//packages/angular_devkit/build_optimizer:__subpackages__",
14+
],
15+
)

0 commit comments

Comments
 (0)