Skip to content
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

Modernize codebase #307

Merged
merged 3 commits into from
Nov 9, 2023
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
137 changes: 49 additions & 88 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"plugin:jsonc/recommended-with-json"
],
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "script",
"ecmaVersion": 2022,
"sourceType": "module",
"ecmaFeatures": {
"globalReturn": false,
"impliedStrict": true
}
},
"env": {
"browser": true,
"es2018": true,
"es2022": true,
"webextensions": true
},
"plugins": [
Expand All @@ -24,7 +24,8 @@
"jsonc"
],
"ignorePatterns": [
"/ext/lib/"
"/ext/lib/",
"/dev/lib/handlebars/"
],
"rules": {
"arrow-parens": [
Expand All @@ -50,6 +51,7 @@
"no-case-declarations": "error",
"no-const-assign": "error",
"no-constant-condition": "off",
"no-console": "warn",
"no-global-assign": "error",
"no-param-reassign": "off",
"no-prototype-builtins": "error",
Expand Down Expand Up @@ -180,6 +182,7 @@
"after": true
}
],
"no-implicit-globals": "error",
"no-trailing-spaces": "error",
"no-whitespace-before-property": "error",
"object-curly-spacing": [
Expand Down Expand Up @@ -250,6 +253,7 @@
"jsdoc/multiline-blocks": "error",
"jsdoc/no-bad-blocks": "error",
"jsdoc/no-multi-asterisks": "error",
"jsdoc/no-undefined-types": 1,
"jsdoc/require-asterisk-prefix": "error",
"jsdoc/require-hyphen-before-param-description": [
"error",
Expand Down Expand Up @@ -375,49 +379,6 @@
"webextensions": false
}
},
{
"files": [
"ext/**/*.js"
],
"excludedFiles": [
"ext/js/core.js",
"ext/js/accessibility/google-docs.js",
"ext/js/**/sandbox/**/*.js"
],
"globals": {
"serializeError": "readonly",
"deserializeError": "readonly",
"isObject": "readonly",
"stringReverse": "readonly",
"promiseTimeout": "readonly",
"escapeRegExp": "readonly",
"deferPromise": "readonly",
"clone": "readonly",
"deepEqual": "readonly",
"generateId": "readonly",
"promiseAnimationFrame": "readonly",
"invokeMessageHandler": "readonly",
"log": "readonly",
"DynamicProperty": "readonly",
"EventDispatcher": "readonly",
"EventListenerCollection": "readonly",
"Logger": "readonly"
}
},
{
"files": [
"ext/**/*.js"
],
"excludedFiles": [
"ext/js/core.js",
"ext/js/accessibility/google-docs.js",
"ext/js/yomichan.js",
"ext/js/**/sandbox/**/*.js"
],
"globals": {
"yomichan": "readonly"
}
},
{
"files": [
"ext/js/yomichan.js"
Expand All @@ -431,49 +392,26 @@
"test/**/*.js",
"dev/**/*.js"
],
"excludedFiles": [
"test/data/html/*.js"
],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module"
},
"env": {
"browser": false,
"es2017": true,
"node": true,
"webextensions": false
}
},
{
"files": [
"playwright.config.js"
"test/data/html/*.js"
],
"env": {
"browser": false,
"es2017": true,
"node": true,
"webextensions": false
"parserOptions": {
"sourceType": "script"
},
"rules": {
"no-undefined": "off"
}
},
{
"files": [
"integration.spec.js",
"playwright-util.js",
"visual.spec.js"
],
"env": {
"browser": false,
"es2017": true,
"node": true,
"browser": true,
"node": false,
"webextensions": false
},
"rules": {
"no-undefined": "off",
"no-empty-pattern": "off"
"no-implicit-globals": "off"
}
},
{
Expand Down Expand Up @@ -514,13 +452,13 @@
"env": {
"browser": false,
"serviceworker": true,
"es2017": true,
"webextensions": true
},
"globals": {
"FileReader": "readonly",
"Intl": "readonly",
"crypto": "readonly"
"crypto": "readonly",
"AbortController": "readonly"
}
},
{
Expand All @@ -538,29 +476,52 @@
"env": {
"browser": false,
"worker": true,
"es2017": true,
"webextensions": true
}
},
{
"files": [
"ext/js/**/*.js"
],
"excludedFiles": [
"ext/js/core.js",
"ext/js/**/*main.js"
"playwright.config.js"
],
"env": {
"browser": false,
"node": true,
"webextensions": false
},
"rules": {
"no-implicit-globals": "error"
"no-undefined": "off"
}
},
{
"files": [
"ext/js/**/*.js"
"integration.spec.js",
"playwright-util.js",
"visual.spec.js"
],
"globals": {
"AbortController": "readonly"
"env": {
"browser": false,
"node": true,
"webextensions": false
},
"rules": {
"no-undefined": "off",
"no-empty-pattern": "off"
}
},
{
"files": [
"test/**"
],
"plugins": [
"vitest"
],
"extends": [
"plugin:vitest/recommended"
],
"rules": {
"vitest/prefer-to-be": "off"
},
"env": {}
}
]
}
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Lint
run: npm run test-lint
- name: Lint JS
run: npm run test-lint-js
env:
CI: true

Expand All @@ -36,6 +36,9 @@ jobs:
env:
CI: true

- name: Build Libs
run: npm run build-libs

- name: Tests
run: npm run test-code
env:
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
.DS_Store

node_modules/

builds/
.DS_Store

dictionaries/

/test-results/
/playwright-report/
/playwright/.cache/
/test/playwright/__screenshots__/

ext/manifest.json

ext/lib/*
!ext/lib/__mocks__/
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"markdown.extension.toc.levels": "1..3",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.addMissingImports": true,
"source.organizeImports": true,
"source.fixAll.eslint": true,
},
"eslint.format.enable": true,
"playwright.env": {
"PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS": 1
}
},
"javascript.preferences.importModuleSpecifierEnding": "js",
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ There are two scripts to build the extension to a packaged file for various buil
- [build.bat](build.bat) on Windows
- [build.sh](build.sh) on Linux

Both of these files are convenience scripts which invoke <code>node [dev/build.js](dev/build.js)</code>.
Both of these files are convenience scripts which invoke <code>node [dev/bin/build.js](dev/bin/build.js)</code>.
The build script can produce several different build files based on manifest configurations defined in
[manifest-variants.json](dev/data/manifest-variants.json).
Several command line arguments are available for these scripts:
Expand Down
21 changes: 21 additions & 0 deletions dev/bin/build-libs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Yomitan Authors
* Copyright (C) 2020-2022 Yomichan Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {buildLibs} from '../build-libs.js';

buildLibs();
37 changes: 16 additions & 21 deletions dev/build.js → dev/bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const readline = require('readline');
const childProcess = require('child_process');
const util = require('./util');
const {getAllFiles, getArgs, testMain} = util;
const {ManifestUtil} = require('./manifest-util');

import assert from 'assert';
import childProcess from 'child_process';
import fs from 'fs';
import path from 'path';
import readline from 'readline';
import {fileURLToPath} from 'url';
import {buildLibs} from '../build-libs.js';
import {ManifestUtil} from '../manifest-util.js';
import {getAllFiles, getArgs, testMain} from '../util.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));

async function createZip(directory, excludeFiles, outputFileName, sevenZipExes, onUpdate, dryRun) {
try {
Expand Down Expand Up @@ -59,7 +61,7 @@ async function createZip(directory, excludeFiles, outputFileName, sevenZipExes,
}

async function createJSZip(directory, excludeFiles, outputFileName, onUpdate, dryRun) {
const JSZip = util.JSZip;
const JSZip = null;
const files = getAllFiles(directory);
removeItemsFromArray(files, excludeFiles);
const zip = new JSZip();
Expand Down Expand Up @@ -178,7 +180,7 @@ function ensureFilesExist(directory, files) {
}


async function main(argv) {
export async function main(argv) {
const args = getArgs(argv, new Map([
['all', false],
['default', false],
Expand All @@ -195,12 +197,13 @@ async function main(argv) {

const manifestUtil = new ManifestUtil();

const rootDir = path.join(__dirname, '..');
const rootDir = path.join(dirname, '..', '..');
const extDir = path.join(rootDir, 'ext');
const buildDir = path.join(rootDir, 'builds');
const manifestPath = path.join(extDir, 'manifest.json');

try {
await buildLibs();
const variantNames = (
argv.length === 0 || args.get('all') ?
manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) :
Expand All @@ -218,12 +221,4 @@ async function main(argv) {
}
}


if (require.main === module) {
testMain(main, process.argv.slice(2));
}


module.exports = {
main
};
testMain(main, process.argv.slice(2));
Loading
Loading