vendors for background. clean out gulp.

This commit is contained in:
Kyle Spearrin 2017-11-08 10:22:26 -05:00
parent 1cd192a398
commit f937fca917
8 changed files with 63 additions and 126 deletions

View File

@ -1,19 +1,14 @@
const gulp = require('gulp'), const gulp = require('gulp'),
gulpif = require('gulp-if'), gulpif = require('gulp-if'),
replace = require('gulp-replace'), replace = require('gulp-replace'),
rimraf = require('rimraf'),
runSequence = require('run-sequence'),
jshint = require('gulp-jshint'), jshint = require('gulp-jshint'),
merge = require('merge-stream'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
googleWebFonts = require('gulp-google-webfonts'), googleWebFonts = require('gulp-google-webfonts'),
webpack = require('webpack-stream'),
jeditor = require("gulp-json-editor"), jeditor = require("gulp-json-editor"),
child = require('child_process'), child = require('child_process'),
zip = require('gulp-zip'), zip = require('gulp-zip'),
manifest = require('./src/manifest.json'), manifest = require('./src/manifest.json'),
xmlpoke = require('gulp-xmlpoke'); xmlpoke = require('gulp-xmlpoke'),
del = require("del");
const paths = { const paths = {
releases: './releases/', releases: './releases/',
@ -34,10 +29,13 @@ function dist(browserName, manifest) {
return gulp.src(paths.dist + '**/*') return gulp.src(paths.dist + '**/*')
.pipe(gulpif('popup/index.html', replace('__BROWSER__', browserName))) .pipe(gulpif('popup/index.html', replace('__BROWSER__', browserName)))
.pipe(gulpif('manifest.json', jeditor(manifest))) .pipe(gulpif('manifest.json', jeditor(manifest)))
//.pipe(gulpif(browserName !== 'edge', del(['edge/**'])))
.pipe(zip(`dist-${browserName}.zip`)) .pipe(zip(`dist-${browserName}.zip`))
.pipe(gulp.dest(paths.releases)); .pipe(gulp.dest(paths.releases));
} }
gulp.task('dist', ['dist:firefox', 'dist:chrome', 'dist:opera', 'dist:edge']);
gulp.task('dist:firefox', function (cb) { gulp.task('dist:firefox', function (cb) {
return dist('firefox', function (manifest) { return dist('firefox', function (manifest) {
manifest.applications = { manifest.applications = {
@ -63,7 +61,7 @@ gulp.task('dist:chrome', function (cb) {
return dist('chrome', function (manifest) { return dist('chrome', function (manifest) {
return manifest; return manifest;
}); });
}) });
// Since Edge extensions require makeappx to be run we temporarily store it in a folder. // Since Edge extensions require makeappx to be run we temporarily store it in a folder.
gulp.task('dist:edge', function (cb) { gulp.task('dist:edge', function (cb) {
@ -74,7 +72,7 @@ gulp.task('dist:edge', function (cb) {
.then(copyAssetsEdge('./store/windows/**/*', edgePath)) .then(copyAssetsEdge('./store/windows/**/*', edgePath))
.then(function () { .then(function () {
// makeappx.exe must be in your system's path already // makeappx.exe must be in your system's path already
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', paths.releases + 'bitwarden.appx']); child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', paths.releases + 'dist-edge.appx']);
cb(); cb();
}, function () { }, function () {
cb(); cb();
@ -116,12 +114,7 @@ function copyAssetsEdge(source, dest) {
}); });
} }
gulp.task('build', function (cb) { gulp.task('build', ['lint', 'webfonts']);
return runSequence(
'clean',
['browserify', 'webpack', 'lib', 'lint', 'webfonts'],
cb);
});
gulp.task('webfonts', function () { gulp.task('webfonts', function () {
return gulp.src('./webfonts.list') return gulp.src('./webfonts.list')
@ -133,8 +126,6 @@ gulp.task('webfonts', function () {
}); });
// LEGACY CODE! // LEGACY CODE!
//
// Needed until background.js is converted into a proper webpack compatible file.
gulp.task('lint', function () { gulp.task('lint', function () {
return gulp.src([ return gulp.src([
@ -151,60 +142,3 @@ gulp.task('lint', function () {
})) }))
.pipe(jshint.reporter('default')); .pipe(jshint.reporter('default'));
}); });
gulp.task('clean:lib', function (cb) {
return rimraf(paths.libDir, cb);
});
gulp.task('clean', ['clean:lib']);
gulp.task('lib', ['clean:lib'], function () {
var libs = [
{
src: paths.npmDir + 'jquery/dist/jquery.js',
dest: paths.libDir + 'jquery'
}
];
var tasks = libs.map(function (lib) {
return gulp.src(lib.src).pipe(gulp.dest(lib.dest));
});
return merge(tasks);
});
gulp.task('browserify', ['browserify:tldjs']);
gulp.task('browserify:tldjs', function () {
return browserify(paths.npmDir + 'tldjs/index.js', { standalone: 'tldjs' })
.bundle()
.pipe(source('tld.js'))
.pipe(gulp.dest(paths.libDir + 'tldjs'));
});
gulp.task('webpack', ['webpack:forge']);
gulp.task('webpack:forge', function () {
var forgeDir = paths.npmDir + '/node-forge/lib/';
return gulp.src([
forgeDir + 'pbkdf2.js',
forgeDir + 'aes.js',
forgeDir + 'hmac.js',
forgeDir + 'sha256.js',
forgeDir + 'random.js',
forgeDir + 'forge.js'
]).pipe(webpack({
output: {
filename: 'forge.js',
library: 'forge',
libraryTarget: 'umd'
},
node: {
Buffer: false,
process: false,
crypto: false,
setImmediate: false
}
})).pipe(gulp.dest(paths.libDir + 'forge'));
});

View File

@ -17,12 +17,12 @@
"angulartics": "1.4.0", "angulartics": "1.4.0",
"angulartics-google-analytics": "0.4.0", "angulartics-google-analytics": "0.4.0",
"bootstrap": "3.3.7", "bootstrap": "3.3.7",
"browserify": "14.4.0",
"child_process": "1.0.2", "child_process": "1.0.2",
"clean-webpack-plugin": "^0.1.17", "clean-webpack-plugin": "^0.1.17",
"clipboard": "1.7.1", "clipboard": "1.7.1",
"copy-webpack-plugin": "^4.2.0", "copy-webpack-plugin": "^4.2.0",
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"del": "3.0.0",
"extract-text-webpack-plugin": "^3.0.1", "extract-text-webpack-plugin": "^3.0.1",
"file-loader": "^1.1.5", "file-loader": "^1.1.5",
"font-awesome": "4.7.0", "font-awesome": "4.7.0",
@ -31,7 +31,6 @@
"gulp-if": "^2.0.2", "gulp-if": "^2.0.2",
"gulp-jshint": "2.0.4", "gulp-jshint": "2.0.4",
"gulp-json-editor": "2.2.1", "gulp-json-editor": "2.2.1",
"gulp-less": "3.3.2",
"gulp-replace": "^0.6.1", "gulp-replace": "^0.6.1",
"gulp-xmlpoke": "0.2.1", "gulp-xmlpoke": "0.2.1",
"gulp-zip": "4.0.0", "gulp-zip": "4.0.0",
@ -41,13 +40,10 @@
"jshint": "2.9.5", "jshint": "2.9.5",
"less": "^3.0.0-alpha.3", "less": "^3.0.0-alpha.3",
"less-loader": "^4.0.5", "less-loader": "^4.0.5",
"merge-stream": "1.0.1",
"ng-infinite-scroll": "1.3.0", "ng-infinite-scroll": "1.3.0",
"ngclipboard": "1.1.1", "ngclipboard": "1.1.1",
"node-forge": "0.7.1", "node-forge": "0.7.1",
"papaparse": "4.3.5", "papaparse": "4.3.5",
"rimraf": "2.6.1",
"run-sequence": "^2.2.0",
"style-loader": "^0.19.0", "style-loader": "^0.19.0",
"sweetalert": "1.1.3", "sweetalert": "1.1.3",
"tldjs": "2.0.0", "tldjs": "2.0.0",
@ -55,16 +51,16 @@
"tslint": "^5.8.0", "tslint": "^5.8.0",
"tslint-loader": "^3.5.3", "tslint-loader": "^3.5.3",
"typescript": "^2.5.3", "typescript": "^2.5.3",
"vinyl-source-stream": "1.1.0",
"web-ext": "2.0.0", "web-ext": "2.0.0",
"webpack": "^3.8.1", "webpack": "^3.8.1",
"webpack-merge": "^4.1.0", "webpack-merge": "^4.1.0"
"webpack-stream": "4.0.0"
}, },
"dependencies": { "dependencies": {
"@types/angular": "^1.6.34", "@types/angular": "^1.6.34",
"@types/chrome": "0.0.51", "@types/chrome": "0.0.51",
"@types/jquery": "^3.2.16", "@types/jquery": "^3.2.16",
"@types/node-forge": "0.6.10",
"@types/tldjs": "1.7.1",
"@types/webcrypto": "^0.0.28", "@types/webcrypto": "^0.0.28",
"@uirouter/angularjs": "^1.0.10" "@uirouter/angularjs": "^1.0.10"
} }

3
src/background.d.ts vendored
View File

@ -1,4 +1,5 @@
declare function escape(s: string): string; declare function escape(s: string): string;
declare function unescape(s: string): string; declare function unescape(s: string): string;
declare var forge: any;
declare var opr: any; declare var opr: any;
declare var tldjs: any;
declare var forge: any;

View File

@ -1,8 +1,5 @@
<html> <html>
<head> <head>
<script type="text/javascript" src="lib/jquery/jquery.js"></script>
<script type="text/javascript" src="lib/tldjs/tld.js"></script>
<script type="text/javascript" src="lib/forge/forge.js"></script>
</head> </head>
<body> <body>
</body> </body>

View File

@ -1,3 +1,7 @@
require('jquery');
require('node-forge');
require('tldjs');
// Service imports // Service imports
import ApiService from './services/api.service'; import ApiService from './services/api.service';
import AppIdService from './services/appId.service'; import AppIdService from './services/appId.service';

View File

@ -120,6 +120,15 @@ export default class UtilsService {
return bytes; return bytes;
} }
static fromUtf8ToArray(str: string): Uint8Array {
const strUtf8 = unescape(encodeURIComponent(str));
const arr = new Uint8Array(strUtf8.length);
for (let i = 0; i < strUtf8.length; i++) {
arr[i] = strUtf8.charCodeAt(i);
}
return arr;
}
static fromBufferToB64(buffer: ArrayBuffer): string { static fromBufferToB64(buffer: ArrayBuffer): string {
let binary = ''; let binary = '';
const bytes = new Uint8Array(buffer); const bytes = new Uint8Array(buffer);
@ -135,15 +144,6 @@ export default class UtilsService {
return decodeURIComponent(escape(encodedString)); return decodeURIComponent(escape(encodedString));
} }
static fromUtf8ToArray(str: string): Uint8Array {
const strUtf8 = unescape(encodeURIComponent(str));
const arr = new Uint8Array(strUtf8.length);
for (let i = 0; i < strUtf8.length; i++) {
arr[i] = strUtf8.charCodeAt(i);
}
return arr;
}
static saveObjToStorage(key: string, obj: any) { static saveObjToStorage(key: string, obj: any) {
return new Promise((resolve) => { return new Promise((resolve) => {
chrome.storage.local.set({ [key]: obj }, () => { chrome.storage.local.set({ [key]: obj }, () => {
@ -185,7 +185,7 @@ export default class UtilsService {
if (uriString.startsWith('http://') || uriString.startsWith('https://')) { if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
try { try {
const url = new URL(uriString); const url = new URL(uriString);
if (!url || !url.hostname) { if (!url.hostname) {
return null; return null;
} }
@ -193,17 +193,17 @@ export default class UtilsService {
return url.hostname; return url.hostname;
} }
if ((window as any).tldjs) { if (typeof tldjs !== 'undefined' && tldjs) {
const domain = (window as any).tldjs.getDomain(uriString); const domain = tldjs.getDomain(url.hostname);
if (domain) { if (domain != null) {
return domain; return domain;
} }
} }
return url.hostname; return url.hostname;
} catch (e) { } } catch (e) { }
} else if ((window as any).tldjs) { } else if (typeof tldjs !== 'undefined' && tldjs) {
const domain: string = (window as any).tldjs.getDomain(uriString); const domain = tldjs.getDomain(uriString);
if (domain != null) { if (domain != null) {
return domain; return domain;
} }
@ -212,12 +212,6 @@ export default class UtilsService {
return null; return null;
} }
static validIpAddress(ipString: string): boolean {
// tslint:disable-next-line
const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return ipRegex.test(ipString);
}
static getHostname(uriString: string): string { static getHostname(uriString: string): string {
if (uriString == null) { if (uriString == null) {
return null; return null;
@ -231,7 +225,7 @@ export default class UtilsService {
if (uriString.startsWith('http://') || uriString.startsWith('https://')) { if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
try { try {
const url = new URL(uriString); const url = new URL(uriString);
if (!url || !url.hostname) { if (!url.hostname) {
return null; return null;
} }
@ -242,6 +236,12 @@ export default class UtilsService {
return null; return null;
} }
private static validIpAddress(ipString: string): boolean {
// tslint:disable-next-line
const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return ipRegex.test(ipString);
}
private browserCache: BrowserType = null; private browserCache: BrowserType = null;
private analyticsIdCache: string = null; private analyticsIdCache: string = null;

View File

@ -4,6 +4,11 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
const isVendorModule = (module) => {
// returns true for everything in node_modules
return module.context && module.context.indexOf('node_modules') !== -1;
};
module.exports = { module.exports = {
entry: { entry: {
'popup/app': './src/popup/app/app.js', 'popup/app': './src/popup/app/app.js',
@ -64,10 +69,12 @@ module.exports = {
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
name: 'popup/vendor', name: 'popup/vendor',
chunks: ['popup/app'], chunks: ['popup/app'],
minChunks: function (module) { minChunks: isVendorModule
// this assumes your vendor imports exist in the node_modules directory }),
return module.context && module.context.indexOf('node_modules') !== -1; new webpack.optimize.CommonsChunkPlugin({
} name: 'vendor',
chunks: ['background'],
minChunks: isVendorModule
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './src/popup/index.html', template: './src/popup/index.html',
@ -77,7 +84,7 @@ module.exports = {
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './src/background.html', template: './src/background.html',
filename: 'background.html', filename: 'background.html',
chunks: ['background'] chunks: ['vendor', 'background']
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './src/notification/bar.html', template: './src/notification/bar.html',
@ -86,15 +93,14 @@ module.exports = {
}), }),
new CopyWebpackPlugin([ new CopyWebpackPlugin([
'./src/manifest.json', './src/manifest.json',
'./src/background.js',
{ from: './src/_locales', to: '_locales' }, { from: './src/_locales', to: '_locales' },
{ from: './src/edge', to: 'edge' }, { from: './src/edge', to: 'edge' },
{ from: './src/images', to: 'images' }, { from: './src/images', to: 'images' },
{ from: './src/lib', to: 'lib' }, { from: './src/lib', to: 'lib' },
{ from: './src/models', to: 'models' }, { from: './src/models', to: 'models' },
{ from: './src/overlay', to: 'overlay' },
{ from: './src/scripts', to: 'scripts' }, { from: './src/scripts', to: 'scripts' },
{ from: './src/content/autofill.css', to: 'content' }, { from: './src/content/autofill.css', to: 'content' }
'./src/background.js'
]) ])
], ],
resolve: { resolve: {

View File

@ -1,16 +1,8 @@
const merge = require('webpack-merge'); const merge = require('webpack-merge');
//const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin');
const common = require('./webpack.common.js'); const common = require('./webpack.common.js');
const extractLess = new ExtractTextPlugin({
filename: 'popup/css/[name].css',
disable: false,
allChunks: true
});
module.exports = merge(common, { module.exports = merge(common, {
devtool: 'source-map',
module: { module: {
rules: [ rules: [
{ {
@ -29,7 +21,14 @@ module.exports = merge(common, {
] ]
}, },
plugins: [ plugins: [
extractLess new webpack.SourceMapDevToolPlugin({
//new UglifyJSPlugin() filename: '[name].js.map',
exclude: ['vendor.js', 'popup/vendor.js']
}),
new ExtractTextPlugin({
filename: 'popup/css/[name].css',
disable: false,
allChunks: true
})
] ]
}); });