Skip to content
Permalink
Browse files

Migrated from Webpack to Rollup for cleaner builds, converted most of…

… the codebase to ES6 modules while at it
  • Loading branch information...
palant committed Aug 5, 2019
1 parent 545169f commit 1a89e8ed8019f342bfc61dd261f58338977b4cbe
Showing with 729 additions and 707 deletions.
  1. +2 −1 contentScript/fillIn.js
  2. +1 −17 gulp-utils.js
  3. +90 −142 gulpfile.js
  4. +3 −3 lib/browserAPI.js
  5. +26 −30 lib/crypto.js
  6. +7 −5 lib/eventTarget.js
  7. +20 −18 lib/importers/default.js
  8. +1 −1 lib/importers/lastPass.js
  9. +1 −1 lib/lock.js
  10. +15 −15 lib/main.js
  11. +59 −66 lib/masterPassword.js
  12. +4 −4 lib/messaging.js
  13. +4 −5 lib/migration.js
  14. +8 −8 lib/passwordRetrieval.js
  15. +41 −50 lib/passwords.js
  16. +8 −6 lib/prefs.js
  17. +51 −19 lib/proxy.js
  18. +30 −28 lib/recoveryCodes.js
  19. +10 −15 lib/storage.js
  20. +12 −12 lib/sync-providers/dropbox.js
  21. +13 −13 lib/sync-providers/gdrive.js
  22. +12 −12 lib/sync-providers/remotestorage.js
  23. +57 −43 lib/sync.js
  24. +4 −1 lib/typedArrayConversion.js
  25. +6 −11 lib/ui.js
  26. +9 −6 package.json
  27. +7 −3 test-lib/browserAPI.js
  28. +11 −11 test-lib/fake-crypto.js
  29. +25 −0 test-lib/lib.js
  30. +29 −25 test-lib/sync-providers/dropbox.js
  31. +2 −2 test-lib/typedArrayConversion.js
  32. +1 −1 test/crypto.js
  33. +1 −1 test/lock.js
  34. +10 −11 test/masterPassword.js
  35. +5 −8 test/passwords.js
  36. +1 −1 test/pbkdf2.js
  37. +7 −9 test/recoveryCodes.js
  38. +2 −2 test/scrypt.js
  39. +45 −45 test/sync.js
  40. +1 −0 ui/allpasswords/App.vue
  41. +1 −0 ui/allpasswords/components/GlobalActions.vue
  42. +1 −0 ui/allpasswords/components/PasswordInfo.vue
  43. +1 −0 ui/allpasswords/components/SiteInfo.vue
  44. +1 −0 ui/components/Confirm.vue
  45. +1 −0 ui/components/EnterMaster.vue
  46. +1 −0 ui/components/PasswordMessage.vue
  47. +1 −0 ui/components/Setting.vue
  48. +1 −0 ui/components/UnknownError.vue
  49. +3 −1 ui/i18n.js
  50. +1 −0 ui/panel/App.vue
  51. +1 −0 ui/panel/components/GeneratedPassword.vue
  52. +1 −0 ui/panel/components/ManualAuth.vue
  53. +1 −0 ui/panel/components/NotesEditor.vue
  54. +1 −0 ui/panel/components/PasswordEntry.vue
  55. +1 −0 ui/panel/components/PasswordMenu.vue
  56. +1 −0 ui/panel/components/PasswordNameEntry.vue
  57. +1 −0 ui/panel/components/QRCode.vue
  58. +1 −0 ui/panel/components/RecoveryCode.vue
  59. +1 −0 ui/panel/components/RemoteStorageUsernameInput.vue
  60. +1 −0 ui/panel/components/SiteSelection.vue
  61. +1 −0 ui/panel/components/StoredPassword.vue
  62. +1 −0 ui/panel/pages/ChangeMaster.vue
  63. +1 −0 ui/panel/pages/EnterMaster.vue
  64. +1 −0 ui/panel/pages/Migration.vue
  65. +1 −0 ui/panel/pages/PasswordList.vue
  66. +1 −0 ui/panel/pages/SelectSite.vue
  67. +2 −1 ui/panel/pages/Sync.vue
  68. +2 −2 ui/proxy.js
  69. +9 −5 web/backgroundBrowserAPI.js
  70. +2 −4 worker/pbkdf2.js
  71. +8 −4 worker/scrypt.js
  72. +37 −39 workerLoader.js
@@ -8,6 +8,8 @@

/* global _parameters */

import {port} from "../ui/messaging";

function getActiveElement(doc)
{
let result = doc.activeElement;
@@ -195,7 +197,6 @@ function fillIn(wnd, name, password, noFocus)
else if (!fillIn(window, name, password))
result = "no_password_fields";

let {port} = require("../ui/messaging");
port.emit("done", {
scriptID,
result
@@ -170,20 +170,6 @@ exports.runTests = function()
}
}

function rewriteRequires(source)
{
let modules = new Map();
for (let file of readdir("test-lib"))
modules.set(file.replace(/\.js$/, ""), path.resolve("test-lib", file));
return source.replace(/(\brequire\(["'])\.\/([^"']+)/g, (match, prefix, request) =>
{
if (modules.has(request))
return prefix + escape_string(modules.get(request));
else
return match;
});
}

let {TextEncoder, TextDecoder} = require("text-encoding");

class WorkerEventTarget
@@ -246,15 +232,13 @@ exports.runTests = function()
}
}

let crypto = require("./test-lib/fake-crypto");
let atob = str => Buffer.from(str, "base64").toString("binary");
let btoa = str => Buffer.from(str, "binary").toString("base64");
let {URL} = require("url");

let nodeunit = require("sandboxed-module").require("nodeunit", {
sourceTransformers: {rewriteRequires},
globals: {
console, process, Buffer, TextEncoder, TextDecoder, crypto, atob, btoa, URL,
console, process, Buffer, TextEncoder, TextDecoder, atob, btoa, URL,
Worker: FakeWorker,
navigator: {
onLine: true
@@ -14,53 +14,53 @@ const del = require("del");
const gulp = require("gulp");
const eslint = require("gulp-eslint");
const htmlhint = require("gulp-htmlhint");
const rollupStream = require("gulp-better-rollup");
const sass = require("gulp-sass");
const stylelint = require("gulp-stylelint");
const merge = require("merge-stream");
const zip = require("gulp-zip");
const webpackStream = require("webpack-stream");
const mergeConfig = require("webpack-merge");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const merge = require("merge-stream");
const alias = require("rollup-plugin-alias");
const babel = require("rollup-plugin-babel");
const commonjs = require("rollup-plugin-commonjs");
const json = require("rollup-plugin-json");
const resolve = require("rollup-plugin-node-resolve");
const vue = require("rollup-plugin-vue");

const utils = require("./gulp-utils");

const webpackBaseConfig = {
mode: "production",
optimization: {
minimize: false
},
node: {
process: false,
global: false,
setImmediate: false
},
module: {
rules: [
{
test: /\.vue$/,
use: {
loader: "vue-loader",
options: {
transformAssetUrls: {img: []},
compilerOptions: {
whitespace: "condense"
}
function rollup(overrides = {})
{
let prePlugins = overrides.plugins || [];
let postPlugins = overrides.postPlugins || [];
delete overrides.plugins;
delete overrides.postPlugins;

return rollupStream({
plugins: [
...prePlugins,
resolve(),
commonjs({
include: ["node_modules/**"]
}),
vue({
template: {
compilerOptions: {
whitespace: "condense"
}
}
}
]
},
plugins: [new VueLoaderPlugin()],
externals: {
vue: "Vue",
jsqr: "JSQR",
zxcvbn: "zxcvbn"
}
};

function webpack(config)
{
return webpackStream(mergeConfig(webpackBaseConfig, config));
}),
...postPlugins
],
external: ["vue", "jsqr", "zxcvbn"]
}, Object.assign({
format: "iife",
compact: true,
globals: {
vue: "Vue",
jsqr: "JSQR",
zxcvbn: "zxcvbn"
}
}, overrides));
}

gulp.task("eslint", function()
@@ -100,33 +100,24 @@ gulp.task("validate", gulp.parallel("eslint", "htmlhint", "stylelint"));

function buildWorkers(targetdir)
{
let resolveConfig = {};
let overrides = {};

if (targetdir == "build-test/worker")
{
resolveConfig.alias = {
"../lib/typedArrayConversion$": path.resolve(__dirname, "test-lib", "typedArrayConversion.js")
overrides = {
plugins: [alias({
"../lib/typedArrayConversion": path.resolve(__dirname, "test-lib", "typedArrayConversion.js")
})],
format: "cjs"
};
}

return merge(
gulp.src(["worker/pbkdf2.js"])
.pipe(webpack({
output: {
filename: "pbkdf2.js",
pathinfo: true
},
resolve: resolveConfig
}))
.pipe(rollup(overrides))
.pipe(gulp.dest(`${targetdir}`)),
gulp.src(["worker/scrypt.js"])
.pipe(webpack({
output: {
filename: "scrypt.js",
pathinfo: true
},
resolve: resolveConfig
}))
.pipe(rollup(overrides))
.pipe(gulp.dest(`${targetdir}`))
);
}
@@ -143,38 +134,21 @@ function buildCommon(targetdir)
gulp.src("ui/third-party/**")
.pipe(gulp.dest(`${targetdir}/ui/third-party`)),
gulp.src(["contentScript/fillIn.js"])
.pipe(webpack({
output: {
filename: "fillIn.js",
pathinfo: true
}
}))
.pipe(rollup())
.pipe(gulp.dest(`${targetdir}/contentScript`)),
gulp.src("ui/panel/main.js")
.pipe(webpack({
output: {
filename: "panel.js",
pathinfo: true,
library: "__webpack_require__"
}
.pipe(rollup({
file: "panel.js"
}))
.pipe(gulp.dest(`${targetdir}/ui/panel`)),
gulp.src("ui/allpasswords/main.js")
.pipe(webpack({
output: {
filename: "allpasswords.js",
pathinfo: true,
library: "__webpack_require__"
}
.pipe(rollup({
file: "allpasswords.js"
}))
.pipe(gulp.dest(`${targetdir}/ui/allpasswords`)),
gulp.src("ui/options/main.js")
.pipe(webpack({
output: {
filename: "options.js",
pathinfo: true,
library: "__webpack_require__"
}
.pipe(rollup({
file: "options.js"
}))
.pipe(gulp.dest(`${targetdir}/ui/options`)),
gulp.src(["ui/**/*.scss"])
@@ -185,12 +159,8 @@ function buildCommon(targetdir)
.pipe(utils.toChromeLocale())
.pipe(gulp.dest(`${targetdir}/_locales`)),
gulp.src("lib/main.js")
.pipe(webpack({
output: {
filename: "background.js",
pathinfo: true,
library: "__webpack_require__"
}
.pipe(rollup({
file: "background.js"
}))
.pipe(gulp.dest(`${targetdir}`)),
gulp.src(["lib/reloader.js"])
@@ -252,7 +222,19 @@ gulp.task("build-firefox", gulp.series("validate", function buildFirefox()

gulp.task("build-test", gulp.series("validate", function buildTest()
{
return buildWorkers("build-test/worker");
return merge(
buildWorkers("build-test/worker"),
gulp.src("test-lib/lib.js")
.pipe(rollup({
plugins: [alias({
"./browserAPI": path.resolve(__dirname, "test-lib", "browserAPI.js"),
"./typedArrayConversion": path.resolve(__dirname, "test-lib", "typedArrayConversion.js"),
"./sync-providers/dropbox": path.resolve(__dirname, "test-lib", "sync-providers", "dropbox.js"),
})],
format: "cjs"
}))
.pipe(gulp.dest("build-test"))
);
}));

gulp.task("watch-firefox", gulp.series("build-firefox", function watchFirefox()
@@ -281,64 +263,30 @@ gulp.task("build-web", gulp.series("validate", "build-web-locales", function bui
.pipe(sass())
.pipe(gulp.dest(targetdir)),
gulp.src("lib/main.js")
.pipe(webpack({
output: {
filename: "background.js",
pathinfo: true,
library: "__webpack_require__"
},
module: {
rules: [
{
test: /\/(scrypt|pbkdf2)\.js$/,
use: path.resolve(__dirname, "workerLoader.js")
},
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
}
]
},
resolve: {
alias: {
"./browserAPI$": path.resolve(__dirname, "web", "backgroundBrowserAPI.js"),
"../browserAPI$": path.resolve(__dirname, "web", "backgroundBrowserAPI.js")
}
}
.pipe(rollup({
file: "background.js",
plugins: [alias({
"./browserAPI": path.resolve(__dirname, "web", "backgroundBrowserAPI.js"),
"../browserAPI": path.resolve(__dirname, "web", "backgroundBrowserAPI.js")
}), require("./workerLoader")(/\/(scrypt|pbkdf2)\.js$/)],
postPlugins: [babel({
babelrc: false,
presets: ["@babel/preset-env"]
})]
}))
.pipe(gulp.dest(targetdir)),
gulp.src("web/index.js")
.pipe(webpack({
output: {
filename: "index.js",
pathinfo: true,
library: "__webpack_require__"
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
}
]
},
resolve: {
alias: {
"./browserAPI$": path.resolve(__dirname, "web", "contentBrowserAPI.js"),
"../browserAPI$": path.resolve(__dirname, "web", "contentBrowserAPI.js"),
"locale$": path.resolve(__dirname, "build-web", "locale", "en_US.json")
}
}
.pipe(rollup({
plugins: [alias({
"./browserAPI": path.resolve(__dirname, "web", "contentBrowserAPI.js"),
"../browserAPI": path.resolve(__dirname, "web", "contentBrowserAPI.js"),
"locale": path.resolve(__dirname, "build-web", "locale", "en_US.json"),
resolve: [".js", ".json"]
}), json()],
postPlugins: [babel({
babelrc: false,
presets: ["@babel/preset-env"]
})]
}))
.pipe(gulp.dest(targetdir)),
gulp.src("web/**/*.scss")
@@ -18,8 +18,8 @@ function promisify(method, numArgs, ...args)

this[method](...args, result =>
{
if (module.exports.runtime.lastError)
reject(module.exports.runtime.lastError.message);
if (browser.runtime.lastError)
reject(browser.runtime.lastError.message);
else
resolve(result);
});
@@ -57,4 +57,4 @@ let browser = window.browser;
if (!browser)
browser = promisifyAPI(chrome);

module.exports = browser;
export default browser;

0 comments on commit 1a89e8e

Please sign in to comment.
You can’t perform that action at this time.