Skip to content

Commit f283506

Browse files
committed
build(@angular-devkit/build-webpack): build and test using Bazel
1 parent 803ff5e commit f283506

File tree

29 files changed

+269
-4134
lines changed

29 files changed

+269
-4134
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"typescript": "3.8.3",
149149
"verdaccio": "4.4.4",
150150
"webpack": "4.42.0",
151+
"webpack-dev-server": "3.10.3",
151152
"webpack-sources": "1.4.3"
152153
},
153154
"husky": {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright Google Inc. All Rights Reserved.
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be
4+
# found in the LICENSE file at https://angular.io/license
5+
6+
licenses(["notice"]) # MIT
7+
8+
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
9+
load("@npm_bazel_typescript//:index.bzl", "ts_library")
10+
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
11+
load("//tools:ts_json_schema.bzl", "ts_json_schema")
12+
13+
package(default_visibility = ["//visibility:public"])
14+
15+
ts_json_schema(
16+
name = "webpack_schema",
17+
src = "src/webpack/schema.json",
18+
)
19+
20+
ts_json_schema(
21+
name = "webpack_dev_server_schema",
22+
src = "src/webpack-dev-server/schema.json",
23+
)
24+
25+
ts_library(
26+
name = "build_webpack",
27+
srcs = glob(
28+
include = ["src/**/*.ts"],
29+
exclude = [
30+
"src/test-utils.ts",
31+
"src/**/*_spec.ts",
32+
],
33+
),
34+
data = glob(
35+
include = [
36+
"package.json",
37+
"builders.json",
38+
"src/webpack/schema.json",
39+
"src/webpack-dev-server/schema.json",
40+
],
41+
),
42+
module_name = "@angular-devkit/build-webpack",
43+
module_root = "src/index.d.ts",
44+
deps = [
45+
":webpack_schema",
46+
":webpack_dev_server_schema",
47+
"//packages/angular_devkit/architect",
48+
"//packages/angular_devkit/core",
49+
"@npm//@types/node",
50+
"@npm//@types/webpack",
51+
"@npm//@types/webpack-dev-server",
52+
"@npm//rxjs",
53+
"@npm//webpack",
54+
"@npm//webpack-dev-server",
55+
],
56+
)
57+
58+
ts_library(
59+
name = "build_webpack_test_lib",
60+
testonly = True,
61+
srcs = glob(
62+
include = [
63+
"src/test-utils.ts",
64+
"src/**/*_spec.ts",
65+
"src/**/*_spec_large.ts",
66+
],
67+
),
68+
data = glob(
69+
include = [
70+
"test/**/*",
71+
],
72+
),
73+
tsconfig = "//:tsconfig-test.json",
74+
deps = [
75+
":build_webpack",
76+
"//packages/angular_devkit/core",
77+
"//packages/angular_devkit/core:node",
78+
"//packages/angular_devkit/architect",
79+
"//packages/angular_devkit/architect:node",
80+
"//packages/angular_devkit/architect:testing",
81+
"@npm//@types/jasmine",
82+
"@npm//@types/node",
83+
"@npm//@types/node-fetch",
84+
"@npm//node-fetch",
85+
],
86+
)
87+
88+
jasmine_node_test(
89+
name = "build_webpack_test",
90+
srcs = [":build_webpack_test_lib"],
91+
deps = [
92+
"@npm//jasmine",
93+
"@npm//source-map",
94+
],
95+
)
96+
97+
pkg_npm(
98+
name = "npm_package",
99+
deps = [
100+
":build_webpack",
101+
],
102+
)

packages/angular_devkit/build_webpack/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"webpack-dev-server": "^3.1.4"
1717
},
1818
"devDependencies": {
19+
"@types/node-fetch": "^2.1.6",
20+
"node-fetch": "^2.2.0",
1921
"webpack": "4.42.0",
20-
"webpack-dev-server": "^3.1.4"
22+
"webpack-dev-server": "3.10.3"
2123
}
2224
}

packages/angular_devkit/build_webpack/src/test-utils.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/angular_devkit/build_webpack/src/webpack-dev-server/index_spec_large.ts renamed to packages/angular_devkit/build_webpack/src/webpack-dev-server/index_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/nod
1010
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
1111
import { schema, workspaces } from '@angular-devkit/core';
1212
import { NodeJsSyncHost } from '@angular-devkit/core/node';
13-
import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies
13+
import fetch from 'node-fetch';
1414
import * as path from 'path';
1515
import { DevServerBuildOutput } from './index';
1616

17-
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
18-
1917

2018
describe('Dev Server Builder', () => {
2119
let testArchitectHost: TestingArchitectHost;
@@ -41,7 +39,9 @@ describe('Dev Server Builder', () => {
4139
}
4240

4341
beforeEach(async () => {
44-
await createArchitect(path.join(devkitRoot, 'tests/angular_devkit/build_webpack/basic-app/'));
42+
const ngJsonPath = path.join(path.dirname(__filename), '../../test/basic-app/angular.json');
43+
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
44+
await createArchitect(workspaceRoot);
4545
});
4646

4747
it('works', async () => {

packages/angular_devkit/build_webpack/src/webpack/index_spec_large.ts renamed to packages/angular_devkit/build_webpack/src/webpack/index_spec.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { NodeJsSyncHost } from '@angular-devkit/core/node';
1313
import * as path from 'path';
1414
import { BuildResult } from './index';
1515

16-
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
17-
1816

1917
describe('Webpack Builder basic test', () => {
2018
let testArchitectHost: TestingArchitectHost;
@@ -38,7 +36,8 @@ describe('Webpack Builder basic test', () => {
3836
}
3937

4038
describe('basic app', () => {
41-
const workspaceRoot = path.join(devkitRoot, 'tests/angular_devkit/build_webpack/basic-app/');
39+
const ngJsonPath = path.join(path.dirname(__filename), '../../test/basic-app/angular.json');
40+
const workspaceRoot = path.dirname(require.resolve(ngJsonPath));
4241
const outputPath = join(normalize(workspaceRoot), 'dist');
4342

4443
beforeEach(async () => {
@@ -70,36 +69,4 @@ describe('Webpack Builder basic test', () => {
7069
await run.stop();
7170
});
7271
});
73-
74-
describe('Angular app', () => {
75-
const workspaceRoot = path.join(devkitRoot, 'tests/angular_devkit/build_webpack/angular-app/');
76-
const outputPath = join(normalize(workspaceRoot), 'dist/');
77-
78-
beforeEach(async () => {
79-
await createArchitect(workspaceRoot);
80-
});
81-
82-
it('works', async () => {
83-
const run = await architect.scheduleTarget({ project: 'app', target: 'build-webpack' });
84-
const output = await run.result;
85-
86-
expect(output.success).toBe(true);
87-
expect(await vfHost.exists(join(outputPath, 'main.js')).toPromise()).toBe(true);
88-
expect(await vfHost.exists(join(outputPath, 'polyfills.js')).toPromise()).toBe(true);
89-
await run.stop();
90-
});
91-
92-
it('works and returns emitted files', async () => {
93-
const run = await architect.scheduleTarget({ project: 'app', target: 'build-webpack' });
94-
const output = await run.result as BuildResult;
95-
96-
expect(output.success).toBe(true);
97-
expect(output.emittedFiles).toContain(
98-
{ id: 'main', name: 'main', initial: true, file: 'main.js', extension: '.js' },
99-
{ id: 'polyfills', name: 'polyfills', initial: true, file: 'polyfills.js', extension: '.js' },
100-
);
101-
102-
await run.stop();
103-
});
104-
});
10572
});

tests/angular_devkit/build_webpack/basic-app/angular.json renamed to packages/angular_devkit/build_webpack/test/basic-app/angular.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "../../../../packages/angular_devkit/core/src/workspace/workspace-schema.json",
2+
"$schema": "../../../core/src/workspace/workspace-schema.json",
33
"version": 1,
44
"newProjectRoot": "./projects",
55
"cli": {},
@@ -13,13 +13,13 @@
1313
"schematics": {},
1414
"targets": {
1515
"build": {
16-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack",
16+
"builder": "../../:webpack",
1717
"options": {
1818
"webpackConfig": "webpack.config.js"
1919
}
2020
},
2121
"serve": {
22-
"builder": "../../../../packages/angular_devkit/build_webpack:webpack-dev-server",
22+
"builder": "../../:webpack-dev-server",
2323
"options": {
2424
"webpackConfig": "webpack.config.js"
2525
}

tests/angular_devkit/build_webpack/angular-app/angular.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/app/app.component.css

Whitespace-only changes.

tests/angular_devkit/build_webpack/angular-app/src/app/app.component.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/app/app.component.spec.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/app/app.component.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/app/app.module.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/app/app.server.module.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/angular_devkit/build_webpack/angular-app/src/assets/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)