Skip to content

refactor: move base-href webpack plugin into its own package. #1909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"protractor": "4.0.3",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "^2.0.0"
"typescript": "2.0.0"
}
}
4 changes: 1 addition & 3 deletions addon/ng2/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
import * as webpack from 'webpack';
const atl = require('awesome-typescript-loader');

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


import { BaseHrefWebpackPlugin } from '../utilities/base-href-webpack-plugin';


export function getWebpackCommonConfig(
projectRoot: string,
environment: string,
Expand Down
1 change: 0 additions & 1 deletion addon/ng2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "ng2",
"version": "0.0.0",
"description": "An addon to generate an ng2 project",
"author": "rodyhaddad",
"license": "MIT",
"keywords": [
"ember-addon"
Expand Down
1 change: 1 addition & 0 deletions addon/ng2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"baseUrl": "",
"paths": {
"@angular-cli/ast-tools": [ "../../packages/ast-tools/src" ],
"@angular-cli/base-href-webpack": [ "../../packages/base-href-webpack/src" ],
"@angular-cli/webpack": [ "../../packages/webpack/src" ]
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"ts-loader": "^0.8.2",
"tslint-loader": "^2.1.4",
"typedoc": "^0.4.2",
"typescript": "^2.0.0",
"typescript": "2.0.0",
"url-loader": "^0.5.7",
"webpack": "2.1.0-beta.21",
"webpack-dev-server": "2.1.0-beta.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ast-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@angular-cli/ast-tools",
"version": "1.0.0-beta.11-webpack.5",
"description": "CLI tool for Angular",
"main": "./index.js",
"main": "./src/index.js",
"keywords": [
"angular",
"cli",
Expand All @@ -22,6 +22,6 @@
"dependencies": {
"rxjs": "^5.0.0-beta.11",
"denodeify": "^1.2.1",
"typescript": "^2.0.0"
"typescript": "2.0.0"
}
}
25 changes: 25 additions & 0 deletions packages/base-href-webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@angular-cli/base-href-webpack",
"version": "1.0.0",
"description": "Base HREF Webpack plugin",
"main": "./src/index.js",
"keywords": [
"angular",
"cli",
"webpack",
"plugin",
"tool"
],
"repository": {
"type": "git",
"url": "https://github.com/angular/angular-cli.git"
},
"author": "angular",
"license": "MIT",
"bugs": {
"url": "https://github.com/angular/angular-cli/issues"
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
}
}
66 changes: 66 additions & 0 deletions packages/base-href-webpack/src/base-href-webpack-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {oneLineTrim} from 'common-tags';
import {BaseHrefWebpackPlugin} from './base-href-webpack-plugin';


function mockCompiler(indexHtml, callback) {
return {
plugin: function (event, compilerCallback) {
const compilation = {
plugin: function (hook, compilationCallback) {
const htmlPluginData = {
html: indexHtml
};
compilationCallback(htmlPluginData, callback);
}
};
compilerCallback(compilation);
}
};
}

describe('base href webpack plugin', () => {
const html = oneLineTrim`
<html>
<head></head>
<body></body>
</html>
`;

it('should do nothing when baseHref is null', () => {
const plugin = new BaseHrefWebpackPlugin({ baseHref: null });

const compiler = mockCompiler(html, (x, htmlPluginData) => {
expect(htmlPluginData.html).toEqual('<body><head></head></body>');
});
plugin.apply(compiler);
});

it('should insert base tag when not exist', function () {
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/' });
const compiler = mockCompiler(html, (x, htmlPluginData) => {
expect(htmlPluginData.html).toEqual(oneLineTrim`
<html>
<head><base href="/"></head>
<body></body>
</html>
`);
});

plugin.apply(compiler);
});

it('should replace href attribute when base tag already exists', function () {
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/myUrl/' });

const compiler = mockCompiler(oneLineTrim`
<head><base href="/" target="_blank"></head>
<body></body>
`, (x, htmlPluginData) => {
expect(htmlPluginData.html).toEqual(oneLineTrim`
<head><base href="/myUrl/" target="_blank"></head>
<body></body>
`);
});
plugin.apply(compiler);
});
});
2 changes: 2 additions & 0 deletions packages/base-href-webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export * from './base-href-webpack-plugin';
24 changes: 24 additions & 0 deletions packages/base-href-webpack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"declaration": true,
"experimentalDecorators": true,
"mapRoot": "",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"outDir": "../../dist/base-href-webpack",
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
"target": "es5",
"lib": ["es6"],
"typeRoots": [
"../../node_modules/@types"
],
"types": [
"jasmine",
"node"
]
}
}
4 changes: 1 addition & 3 deletions scripts/run-packages-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const projectBaseDir = path.join(__dirname, '../packages');

// Create a Jasmine runner and configure it.
const jasmine = new Jasmine({ projectBaseDir: projectBaseDir });
jasmine.loadConfig({
spec_dir: projectBaseDir
});
jasmine.loadConfig({});
jasmine.addReporter(new JasmineSpecReporter());

// Run the tests.
Expand Down
50 changes: 0 additions & 50 deletions tests/acceptance/base-href-webpack-plugin.spec.js

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"paths": {
"@angular-cli/ast-tools": [ "./packages/ast-tools/src" ],
"@angular-cli/base-href-webpack": [ "./packages/base-href-webpack/src" ],
"@angular-cli/webpack": [ "./packages/webpack/src" ]
}
},
Expand Down