Skip to content

Commit a57e3d7

Browse files
authored
refactor: pure es6 import syntax (#384)
* refactor: convert require syntax to import syntax * refactor: downgrade ssestream to avoild "SSEStream is not a constructor" problem See EventSource/node-ssestream#3 (comment) * refactor: module is not defined in pure es6 module package so remove it The removed code is not important since we use absolute path when calling the crx-webpack-plugin. * fix: exsiting way to write process.env.XXX does not work * chore: format code * refactor: convert specific ci scripts to es6 modules * refactor: conventional-changelog-action requires pre-commit.js as a CommonJS module
1 parent 211a287 commit a57e3d7

15 files changed

Lines changed: 874 additions & 861 deletions

File tree

.github/workflows/release-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
github-token: ${{ secrets.GITHUB_TOKEN }}
2525
skip-on-empty: 'false'
26-
pre-commit: scripts/pre-commit.js
26+
pre-commit: scripts/pre-commit.cjs
2727
git-message: 'chore(release): {version}'
2828

2929
- name: Build

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "hypercrx",
33
"version": "1.6.0",
4+
"type": "module",
45
"private": true,
56
"description": "Hypertrons Chromium Extension",
67
"license": "Apache",
78
"scripts": {
8-
"build": "node utils/build.js",
9-
"start": "node utils/server.js",
9+
"build": "NODE_ENV='production' BABEL_ENV='production' node utils/build.js",
10+
"start": "NODE_ENV='development' BABEL_ENV='development' node utils/server.js",
1011
"deploy": "node scripts/deploy.js",
1112
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss}\"",
1213
"prettier:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css,scss}\"",
@@ -43,7 +44,7 @@
4344
"@types/react": "^17.0.39",
4445
"@types/react-dom": "^17.0.11",
4546
"babel-loader": "^8.2.3",
46-
"chrome-webstore-upload": "0.5.0",
47+
"chrome-webstore-upload": "^1.0.0",
4748
"clean-webpack-plugin": "^4.0.0",
4849
"copy-webpack-plugin": "^7.0.0",
4950
"crx": "^5.0.1",
@@ -53,14 +54,15 @@
5354
"html-loader": "^3.1.0",
5455
"html-webpack-plugin": "^5.5.0",
5556
"husky": "^8.0.1",
57+
"lodash-es": "^4.17.21",
5658
"mkdirp": "^1.0.4",
5759
"prettier": "^2.7.1",
5860
"pretty-quick": "^3.1.3",
5961
"querystring": "^0.2.1",
6062
"sass": "^1.52.1",
6163
"sass-loader": "^12.4.0",
6264
"source-map-loader": "^3.0.1",
63-
"ssestream": "^1.1.0",
65+
"ssestream": "1.0.1",
6466
"style-loader": "^3.3.1",
6567
"terser-webpack-plugin": "^5.3.1",
6668
"ts-loader": "^9.2.6",
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
// according to https://github.com/TriPSs/conventional-changelog-action#pre-commit-hook
2+
// this script should be a CommonJS module
3+
14
async function bump({ version, deploy }) {
2-
const { readJson, writeJson, processFile } = require('./utils.js');
5+
const { readJson, writeJson, processFile } = require('./utils.cjs');
36
// update package.json
47
const pkgPath = 'package.json';
58
const pkg = await readJson(pkgPath);
69
pkg.version = version;
7-
await writeJson(pkgPath, pkg);
10+
writeJson(pkgPath, pkg);
811

912
// update update_information.json
1013
const infoPath = 'publish/update_information.json';

scripts/deploy.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const chromeWebstoreUpload = require('chrome-webstore-upload');
2-
const path = require('path');
3-
const fs = require('fs');
1+
import chromeWebstoreUpload from 'chrome-webstore-upload';
2+
import { fileURLToPath } from 'url';
3+
import path, { dirname } from 'path';
4+
import fs from 'fs';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
48

59
const ZIP_PATH = path.join(__dirname, '..', '/release/hypercrx.zip');
610

scripts/pre-commit.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// according to https://github.com/TriPSs/conventional-changelog-action#pre-commit-hook
2+
// this script should be a CommonJS module
3+
4+
const { bump } = require('./bump-version.cjs');
5+
6+
exports.preCommit = ({ version }) => {
7+
bump({ version: version, deploy: true });
8+
};

scripts/pre-commit.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/utils.js renamed to scripts/utils.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// according to https://github.com/TriPSs/conventional-changelog-action#pre-commit-hook
2+
// this script should be a CommonJS module
3+
14
const fs = require('fs');
25

36
function readJson(filename) {

src/utils/request.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const ENV = require('../../utils/env');
1+
// @ts-ignore
2+
import ENV from '../../utils/env';
23
import { ErrorCode } from '../constant';
34

45
/**

utils/autoReloadClients/backgroundClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const querystring = require('querystring');
1+
import querystring from 'querystring';
22

33
const logger = (msg) => {
44
console.log(`[BGC] ${msg}`);

utils/build.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// Do this as the first thing so that any code reading it knows the right env.
2-
process.env.BABEL_ENV = 'production';
3-
process.env.NODE_ENV = 'production';
4-
process.env.ASSET_PATH = '/';
1+
import { fileURLToPath } from 'url';
2+
import path, { dirname } from 'path';
3+
import CrxWebpackPlugin from './crx-webpack-plugin/index.js';
4+
import webpack from 'webpack';
5+
import config from '../webpack.config.js';
56

6-
const path = require('path');
7-
const CrxWebpackPlugin = require('./crx-webpack-plugin/index');
8-
9-
var webpack = require('webpack'),
10-
config = require('../webpack.config');
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
119

1210
delete config.custom;
1311

0 commit comments

Comments
 (0)