Skip to content

Commit 8a5e769

Browse files
authored
refactor: move base-href webpack plugin into its own package. (#1909)
1 parent 71670ae commit 8a5e769

File tree

14 files changed

+125
-61
lines changed

14 files changed

+125
-61
lines changed

addon/ng2/blueprints/ng2/files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
"protractor": "4.0.3",
4646
"ts-node": "1.2.1",
4747
"tslint": "3.13.0",
48-
"typescript": "^2.0.0"
48+
"typescript": "2.0.0"
4949
}
5050
}

addon/ng2/models/webpack-build-common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
44
import * as webpack from 'webpack';
55
const atl = require('awesome-typescript-loader');
66

7+
import { BaseHrefWebpackPlugin } from '@angular-cli/base-href-webpack';
78
import { findLazyModules } from './find-lazy-modules';
89

910

10-
import { BaseHrefWebpackPlugin } from '../utilities/base-href-webpack-plugin';
11-
12-
1311
export function getWebpackCommonConfig(
1412
projectRoot: string,
1513
environment: string,

addon/ng2/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "ng2",
33
"version": "0.0.0",
44
"description": "An addon to generate an ng2 project",
5-
"author": "rodyhaddad",
65
"license": "MIT",
76
"keywords": [
87
"ember-addon"

addon/ng2/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"baseUrl": "",
2121
"paths": {
2222
"@angular-cli/ast-tools": [ "../../packages/ast-tools/src" ],
23+
"@angular-cli/base-href-webpack": [ "../../packages/base-href-webpack/src" ],
2324
"@angular-cli/webpack": [ "../../packages/webpack/src" ]
2425
}
2526
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"ts-loader": "^0.8.2",
103103
"tslint-loader": "^2.1.4",
104104
"typedoc": "^0.4.2",
105-
"typescript": "^2.0.0",
105+
"typescript": "2.0.0",
106106
"url-loader": "^0.5.7",
107107
"webpack": "2.1.0-beta.21",
108108
"webpack-dev-server": "2.1.0-beta.0",

packages/ast-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@angular-cli/ast-tools",
33
"version": "1.0.0-beta.11-webpack.5",
44
"description": "CLI tool for Angular",
5-
"main": "./index.js",
5+
"main": "./src/index.js",
66
"keywords": [
77
"angular",
88
"cli",
@@ -22,6 +22,6 @@
2222
"dependencies": {
2323
"rxjs": "^5.0.0-beta.11",
2424
"denodeify": "^1.2.1",
25-
"typescript": "^2.0.0"
25+
"typescript": "2.0.0"
2626
}
2727
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@angular-cli/base-href-webpack",
3+
"version": "1.0.0",
4+
"description": "Base HREF Webpack plugin",
5+
"main": "./src/index.js",
6+
"keywords": [
7+
"angular",
8+
"cli",
9+
"webpack",
10+
"plugin",
11+
"tool"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/angular/angular-cli.git"
16+
},
17+
"author": "angular",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/angular/angular-cli/issues"
21+
},
22+
"homepage": "https://github.com/angular/angular-cli",
23+
"dependencies": {
24+
}
25+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {oneLineTrim} from 'common-tags';
2+
import {BaseHrefWebpackPlugin} from './base-href-webpack-plugin';
3+
4+
5+
function mockCompiler(indexHtml, callback) {
6+
return {
7+
plugin: function (event, compilerCallback) {
8+
const compilation = {
9+
plugin: function (hook, compilationCallback) {
10+
const htmlPluginData = {
11+
html: indexHtml
12+
};
13+
compilationCallback(htmlPluginData, callback);
14+
}
15+
};
16+
compilerCallback(compilation);
17+
}
18+
};
19+
}
20+
21+
describe('base href webpack plugin', () => {
22+
const html = oneLineTrim`
23+
<html>
24+
<head></head>
25+
<body></body>
26+
</html>
27+
`;
28+
29+
it('should do nothing when baseHref is null', () => {
30+
const plugin = new BaseHrefWebpackPlugin({ baseHref: null });
31+
32+
const compiler = mockCompiler(html, (x, htmlPluginData) => {
33+
expect(htmlPluginData.html).toEqual('<body><head></head></body>');
34+
});
35+
plugin.apply(compiler);
36+
});
37+
38+
it('should insert base tag when not exist', function () {
39+
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/' });
40+
const compiler = mockCompiler(html, (x, htmlPluginData) => {
41+
expect(htmlPluginData.html).toEqual(oneLineTrim`
42+
<html>
43+
<head><base href="/"></head>
44+
<body></body>
45+
</html>
46+
`);
47+
});
48+
49+
plugin.apply(compiler);
50+
});
51+
52+
it('should replace href attribute when base tag already exists', function () {
53+
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/myUrl/' });
54+
55+
const compiler = mockCompiler(oneLineTrim`
56+
<head><base href="/" target="_blank"></head>
57+
<body></body>
58+
`, (x, htmlPluginData) => {
59+
expect(htmlPluginData.html).toEqual(oneLineTrim`
60+
<head><base href="/myUrl/" target="_blank"></head>
61+
<body></body>
62+
`);
63+
});
64+
plugin.apply(compiler);
65+
});
66+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
export * from './base-href-webpack-plugin';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"experimentalDecorators": true,
5+
"mapRoot": "",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"noEmitOnError": true,
9+
"noImplicitAny": true,
10+
"outDir": "../../dist/base-href-webpack",
11+
"rootDir": ".",
12+
"sourceMap": true,
13+
"sourceRoot": "/",
14+
"target": "es5",
15+
"lib": ["es6"],
16+
"typeRoots": [
17+
"../../node_modules/@types"
18+
],
19+
"types": [
20+
"jasmine",
21+
"node"
22+
]
23+
}
24+
}

scripts/run-packages-spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ const projectBaseDir = path.join(__dirname, '../packages');
1111

1212
// Create a Jasmine runner and configure it.
1313
const jasmine = new Jasmine({ projectBaseDir: projectBaseDir });
14-
jasmine.loadConfig({
15-
spec_dir: projectBaseDir
16-
});
14+
jasmine.loadConfig({});
1715
jasmine.addReporter(new JasmineSpecReporter());
1816

1917
// Run the tests.

tests/acceptance/base-href-webpack-plugin.spec.js

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

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
],
2323
"paths": {
2424
"@angular-cli/ast-tools": [ "./packages/ast-tools/src" ],
25+
"@angular-cli/base-href-webpack": [ "./packages/base-href-webpack/src" ],
2526
"@angular-cli/webpack": [ "./packages/webpack/src" ]
2627
}
2728
},

0 commit comments

Comments
 (0)