diff --git a/.travis.yml b/.travis.yml index 7e3ebbe9..c8597c0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,5 @@ language: node_js node_js: - - "10" - - "11" - - "12" - "13" - "14" before_script: diff --git a/README.md b/README.md index fb4dc460..6b2e5370 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You can get an idea of how PfP works by using the [online version](https://pfp.w Installing build prerequisites ------------------------------ -In order to build PfP you will need to install [Node.js](https://nodejs.org/) first (Node 10.0 or higher is required). You will also need [Gulp](http://gulpjs.com/), run the following command to install it (administrator privileges required): +In order to build PfP you will need to install [Node.js](https://nodejs.org/) first (Node 13.0 or higher is required). You will also need [Gulp](http://gulpjs.com/), run the following command to install it (administrator privileges required): npm install --global gulp-cli diff --git a/contentScript/.eslintrc.json b/contentScript/.eslintrc.json index a94ef515..719e971c 100644 --- a/contentScript/.eslintrc.json +++ b/contentScript/.eslintrc.json @@ -1,7 +1,6 @@ { "env": { "node": false, - "browser": true, - "commonjs": true + "browser": true } } diff --git a/generateVowelsRegexp.js b/generateVowelsRegexp.js index b3f53283..a7130623 100755 --- a/generateVowelsRegexp.js +++ b/generateVowelsRegexp.js @@ -8,7 +8,7 @@ "use strict"; -const https = require("https"); +import https from "https"; // Only Latin, Greek and Cyrillic vowels for now, derivations of those will // be determined below. diff --git a/globalLoader.js b/globalLoader.js index ff5f7dd7..05d8bd01 100644 --- a/globalLoader.js +++ b/globalLoader.js @@ -6,7 +6,7 @@ "use strict"; -module.exports = function(map) +export default function(map) { return { name: "global-loader", @@ -24,4 +24,4 @@ module.exports = function(map) return "export default " + map[id]; } }; -}; +} diff --git a/gulp-utils.js b/gulp-utils.js index 2418b8bf..f7ace7f8 100644 --- a/gulp-utils.js +++ b/gulp-utils.js @@ -6,20 +6,22 @@ "use strict"; -let fs = require("fs"); -let path = require("path"); -let {spawn} = require("child_process"); -let {Duplex, Transform} = require("stream"); - -exports.readArg = function(prefix, defaultValue) +import fs from "fs"; +import path from "path"; +import {spawn} from "child_process"; +import {Duplex, Transform} from "stream"; +import {TextEncoder, TextDecoder} from "util"; +import sandboxedModule from "sandboxed-module"; + +export function readArg(prefix, defaultValue) { for (let arg of process.argv) if (arg.startsWith(prefix)) return arg.substr(prefix.length); return defaultValue; -}; +} -function transform(modifier, opts) +export function transform(modifier, opts) { if (!opts) opts = {}; @@ -53,9 +55,8 @@ function transform(modifier, opts) }; return stream; } -exports.transform = transform; -exports.jsonModify = function(modifier, newName) +export function jsonModify(modifier, newName) { return transform((filepath, contents) => { @@ -65,9 +66,9 @@ exports.jsonModify = function(modifier, newName) filepath = path.resolve(filepath, "..", newName); return [filepath, JSON.stringify(data, null, 2)]; }); -}; +} -exports.combineLocales = function() +export function combineLocales() { let rootDir = path.join(process.cwd(), "locale"); let locales = {}; @@ -120,9 +121,9 @@ exports.combineLocales = function() }); return stream; -}; +} -exports.toChromeLocale = function() +export function toChromeLocale() { return transform((filepath, contents) => { @@ -132,7 +133,7 @@ exports.toChromeLocale = function() data[key] = {message: strings[key]}; let locale = path.basename(filepath, ".json"); - let manifest = require("./package.json"); + let manifest = JSON.parse(fs.readFileSync("./package.json")); data.name = {"message": manifest.title}; data.description = {"message": manifest.description}; if ("locales" in manifest && locale in manifest.locales) @@ -149,9 +150,9 @@ exports.toChromeLocale = function() JSON.stringify(data, null, 2) ]; }); -}; +} -exports.runTests = function() +export function runTests() { function escape_string(str) { @@ -170,8 +171,6 @@ exports.runTests = function() } } - let {TextEncoder, TextDecoder} = require("util"); - class WorkerEventTarget { constructor(other) @@ -224,7 +223,7 @@ exports.runTests = function() { super(); - require("sandboxed-module").require(url, { + sandboxedModule.require(url, { globals: { self: new WorkerEventTarget(this) } @@ -234,9 +233,8 @@ exports.runTests = function() 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", { + let nodeunit = sandboxedModule.require("nodeunit", { globals: { console, process, Buffer, TextEncoder, TextDecoder, atob, btoa, URL, Worker: FakeWorker, @@ -260,4 +258,4 @@ exports.runTests = function() }); }); }); -}; +} diff --git a/gulpfile.js b/gulpfile.js index b7485bbe..55ccb856 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,26 +6,32 @@ "use strict"; -const fs = require("fs"); -const path = require("path"); -const url = require("url"); +import fs from "fs"; +import path from "path"; +import url from "url"; -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 zip = require("gulp-zip"); -const merge = require("merge-stream"); -const babel = require("@rollup/plugin-babel").default; -const commonjs = require("@rollup/plugin-commonjs"); -const resolve = require("@rollup/plugin-node-resolve").default; -const vue = require("rollup-plugin-vue"); +import del from "del"; +import gulp from "gulp"; +import eslint from "gulp-eslint"; +import htmlhint from "gulp-htmlhint"; +import rollupStream from "gulp-better-rollup"; +import sass from "gulp-sass"; +import stylelint from "gulp-stylelint"; +import zip from "gulp-zip"; +import merge from "merge-stream"; +import babel from "@rollup/plugin-babel"; +import commonjs from "@rollup/plugin-commonjs"; +import resolve from "@rollup/plugin-node-resolve"; +import vue from "rollup-plugin-vue"; -const replace = require("./replacePlugin"); -const utils = require("./gulp-utils"); +import globalLoader from "./globalLoader.js"; +import * as utils from "./gulp-utils.js"; +import localeLoader from "./localeLoader.js"; +import replace from "./replacePlugin.js"; +import workerLoader from "./workerLoader.js"; + +const VERSION = JSON.parse(fs.readFileSync("./manifest.json")).version; +const __dirname = process.cwd(); // import.meta unsupported by current eslint version function rollup(overrides = {}) { @@ -37,12 +43,12 @@ function rollup(overrides = {}) return rollupStream({ plugins: [ ...prePlugins, - require("./globalLoader")({ + globalLoader({ vue: "Vue", jsqr: "JSQR", zxcvbn: "zxcvbn" }), - resolve(), + resolve.default(), commonjs({ include: ["node_modules/**"] }), @@ -260,11 +266,11 @@ gulp.task("build-web", gulp.series("validate", function buildWeb() [path.resolve(__dirname, "lib", "browserAPI.js")]: path.resolve(__dirname, "web", "backgroundBrowserAPI.js"), [path.resolve(__dirname, "ui", "browserAPI.js")]: path.resolve(__dirname, "web", "contentBrowserAPI.js") }), - require("./workerLoader")(/\/(scrypt|pbkdf2)\.js$/), - require("./localeLoader")(path.resolve(__dirname, "locale", "en_US")) + workerLoader(/\/(scrypt|pbkdf2)\.js$/), + localeLoader(path.resolve(__dirname, "locale", "en_US")) ], postPlugins: [ - babel({ + babel.default({ babelrc: false, babelHelpers: "bundled", presets: ["@babel/preset-env"] @@ -282,7 +288,6 @@ gulp.task("build-web", gulp.series("validate", function buildWeb() gulp.task("crx", gulp.series("build-chrome", function buildCRX() { - let manifest = require("./manifest.json"); return merge( gulp.src([ "build-chrome/**", @@ -290,12 +295,11 @@ gulp.task("crx", gulp.series("build-chrome", function buildCRX() "!build-chrome/**/.*", "!build-chrome/**/*.zip", "!build-chrome/**/*.crx" ]), gulp.src("build-chrome/manifest.json").pipe(utils.jsonModify(removeReloader)) - ).pipe(zip("pfp-" + manifest.version + ".zip")).pipe(gulp.dest("build-chrome")); + ).pipe(zip("pfp-" + VERSION + ".zip")).pipe(gulp.dest("build-chrome")); })); gulp.task("xpi", gulp.series("build-firefox", function buildXPI() { - let manifest = require("./manifest.json"); return merge( gulp.src([ "build-firefox/**", @@ -303,16 +307,15 @@ gulp.task("xpi", gulp.series("build-firefox", function buildXPI() "!build-firefox/**/.*", "!build-firefox/**/*.xpi" ]), gulp.src("build-firefox/manifest.json").pipe(utils.jsonModify(removeReloader)) - ).pipe(zip("pfp-" + manifest.version + ".xpi")).pipe(gulp.dest("build-firefox")); + ).pipe(zip("pfp-" + VERSION + ".xpi")).pipe(gulp.dest("build-firefox")); })); gulp.task("web", gulp.series("build-web", function zipWeb() { - let manifest = require("./manifest.json"); return gulp.src([ "build-web/**", "!build-web/**/.*", "!build-web/**/*.zip" - ]).pipe(zip("pfp-web-" + manifest.version + ".zip")).pipe(gulp.dest("build-web")); + ]).pipe(zip("pfp-web-" + VERSION + ".zip")).pipe(gulp.dest("build-web")); })); gulp.task("test", gulp.series("validate", "build-test", function doTest() diff --git a/lib/.eslintrc.json b/lib/.eslintrc.json index fa060123..7d1b7a8a 100644 --- a/lib/.eslintrc.json +++ b/lib/.eslintrc.json @@ -1,7 +1,6 @@ { "env": { "node": false, - "commonjs": true, "webextensions": true } } diff --git a/localeLoader.js b/localeLoader.js index 19302dc0..8e1d9e0d 100644 --- a/localeLoader.js +++ b/localeLoader.js @@ -6,8 +6,8 @@ "use strict"; -const fs = require("fs"); -const path = require("path"); +import fs from "fs"; +import path from "path"; function walkDirectory(dir, callback) { @@ -35,7 +35,7 @@ function walkDirectory(dir, callback) }); } -module.exports = function(localeRoot) +export default function(localeRoot) { return { name: "locale-loader", @@ -75,4 +75,4 @@ module.exports = function(localeRoot) }); } }; -}; +} diff --git a/package.json b/package.json index 5f8f03bb..165dd728 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Use a single master password to generate secure passwords for all websites - without losing track of passwords you cannot change.", "author": "Wladimir Palant", "license": "MPL-2.0", + "type": "module", "repository": { "type": "git", "url": "https://github.com/palant/easypasswords.git" diff --git a/replacePlugin.js b/replacePlugin.js index 4d2fc025..048a5cd9 100644 --- a/replacePlugin.js +++ b/replacePlugin.js @@ -6,9 +6,9 @@ "use strict"; -const path = require("path"); +import path from "path"; -module.exports = function(map) +export default function(map) { map = new Map(Object.entries(map).map(([key, value]) => [path.normalize(key), path.normalize(value)])); @@ -19,7 +19,7 @@ module.exports = function(map) if (!id.endsWith(".js")) id += ".js"; if (!importer) - importer = __dirname; + importer = process.cwd(); // import.meta unsupported by current eslint version let resolved = path.normalize(path.join(path.dirname(importer), ...id.split("/"))); let mapped = map.get(resolved); if (mapped) @@ -28,4 +28,4 @@ module.exports = function(map) return null; } }; -}; +} diff --git a/ui/.eslintrc.json b/ui/.eslintrc.json index fa060123..7d1b7a8a 100644 --- a/ui/.eslintrc.json +++ b/ui/.eslintrc.json @@ -1,7 +1,6 @@ { "env": { "node": false, - "commonjs": true, "webextensions": true } } diff --git a/web/.eslintrc.json b/web/.eslintrc.json index a94ef515..719e971c 100644 --- a/web/.eslintrc.json +++ b/web/.eslintrc.json @@ -1,7 +1,6 @@ { "env": { "node": false, - "browser": true, - "commonjs": true + "browser": true } } diff --git a/workerLoader.js b/workerLoader.js index 4a1f164c..5833fa1f 100644 --- a/workerLoader.js +++ b/workerLoader.js @@ -6,9 +6,9 @@ "use strict"; -const rollup = require("rollup"); +import rollup from "rollup"; -module.exports = function(regexp) +export default function(regexp) { return { name: "worker-loader", @@ -40,4 +40,4 @@ module.exports = function(regexp) }); } }; -}; +}