Skip to content

Commit 31c914a

Browse files
committed
chore: migrate package to ES module
1 parent a8519c0 commit 31c914a

10 files changed

Lines changed: 7260 additions & 10558 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/report.json
77
/report.html
88

9-
/web-ext-config.js
9+
/web-ext-config.mjs
1010

1111
node_modules/
1212
/npm-debug.log

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.12.2
1+
24.13.0

babel.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
const path = require('node:path');
1+
import path from 'node:path';
2+
import {createRequire} from 'node:module';
3+
4+
const require = createRequire(import.meta.url);
25

36
const corejsVersion = require(
47
path.join(path.dirname(require.resolve('core-js')), 'package.json')
58
).version;
69

7-
module.exports = function (api) {
10+
export default function (api) {
811
api.cache(true);
912

1013
const presets = [
@@ -25,7 +28,7 @@ module.exports = function (api) {
2528
new RegExp(`node_modules\\${path.sep}(?!(vueton|wesa)\\${path.sep}).*`)
2629
];
2730

28-
const parserOpts = {plugins: ['importAttributes']};
31+
const parserOpts = {};
2932

3033
return {presets, plugins, ignore, parserOpts};
31-
};
34+
}

gulpfile.js

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
const path = require('node:path');
2-
const {exec} = require('node:child_process');
3-
const {
4-
lstatSync,
5-
readdirSync,
6-
readFileSync,
7-
writeFileSync,
8-
rmSync
9-
} = require('node:fs');
10-
11-
const {series, parallel, src, dest} = require('gulp');
12-
const postcss = require('gulp-postcss');
13-
const gulpif = require('gulp-if');
1+
import path from 'node:path';
2+
import {exec} from 'node:child_process';
3+
import {lstat, readdir, readFile, writeFile, rm} from 'node:fs/promises';
4+
import {createRequire} from 'node:module';
5+
6+
import {series, parallel, src, dest} from 'gulp';
7+
import postcss from 'gulp-postcss';
8+
import gulpif from 'gulp-if';
9+
import jsonmin from 'gulp-jsonmin';
10+
import htmlmin from 'gulp-htmlmin';
11+
import imagemin from 'gulp-imagemin';
12+
import {ensureDir} from 'fs-extra';
13+
import sharp from 'sharp';
14+
15+
const require = createRequire(import.meta.url);
16+
const __dirname = import.meta.dirname;
17+
1418
const jsonMerge = require('gulp-merge-json');
15-
const jsonmin = require('gulp-jsonmin');
16-
const htmlmin = require('gulp-htmlmin');
17-
const imagemin = require('gulp-imagemin');
18-
const {ensureDirSync} = require('fs-extra');
19-
const sharp = require('sharp');
2019

2120
const targetEnv = process.env.TARGET_ENV || 'chrome';
2221
const isProduction = process.env.NODE_ENV === 'production';
@@ -31,20 +30,22 @@ function initEnv() {
3130
process.env.BROWSERSLIST_ENV = targetEnv;
3231
}
3332

34-
function init(done) {
33+
async function init() {
3534
initEnv();
3635

37-
rmSync(distDir, {recursive: true, force: true});
38-
ensureDirSync(distDir);
39-
done();
36+
await rm(distDir, {recursive: true, force: true});
37+
await ensureDir(distDir);
4038
}
4139

4240
function js(done) {
43-
exec('webpack-cli build --color', function (err, stdout, stderr) {
44-
console.log(stdout);
45-
console.log(stderr);
46-
done(err);
47-
});
41+
exec(
42+
`webpack-cli build --color --env mv3=${mv3}`,
43+
function (err, stdout, stderr) {
44+
console.log(stdout);
45+
console.log(stderr);
46+
done(err);
47+
}
48+
);
4849
}
4950

5051
function html() {
@@ -64,8 +65,8 @@ function html() {
6465
}
6566

6667
async function images(done) {
67-
ensureDirSync(path.join(distDir, 'src/assets/icons/app'));
68-
const appIconSvg = readFileSync('src/assets/icons/app/icon.svg');
68+
await ensureDir(path.join(distDir, 'src/assets/icons/app'));
69+
const appIconSvg = await readFile('src/assets/icons/app/icon.svg');
6970
const appIconSizes = [16, 19, 24, 32, 38, 48, 64, 96, 128];
7071
if (targetEnv === 'safari') {
7172
appIconSizes.push(256, 512, 1024);
@@ -136,9 +137,16 @@ async function fonts(done) {
136137

137138
async function locale(done) {
138139
const localesRootDir = path.join(__dirname, 'src/assets/locales');
139-
const localeDirs = readdirSync(localesRootDir).filter(function (file) {
140-
return lstatSync(path.join(localesRootDir, file)).isDirectory();
141-
});
140+
const localeDirs = (
141+
await Promise.all(
142+
(await readdir(localesRootDir)).map(async function (file) {
143+
if ((await lstat(path.join(localesRootDir, file))).isDirectory()) {
144+
return file;
145+
}
146+
})
147+
)
148+
).filter(Boolean);
149+
142150
for (const localeDir of localeDirs) {
143151
const localePath = path.join(localesRootDir, localeDir);
144152
await new Promise(resolve => {
@@ -187,7 +195,7 @@ function manifest() {
187195
.pipe(dest(distDir));
188196
}
189197

190-
function license(done) {
198+
async function license(done) {
191199
let year = '2017';
192200
const currentYear = new Date().getFullYear().toString();
193201
if (year !== currentYear) {
@@ -199,18 +207,28 @@ Copyright (c) ${year} Armin Sebastian
199207
`;
200208

201209
if (['safari', 'samsung'].includes(targetEnv)) {
202-
writeFileSync(path.join(distDir, 'NOTICE'), notice);
203-
done();
210+
await writeFile(path.join(distDir, 'NOTICE'), notice);
204211
} else {
205212
notice = `${notice}
206213
This software is released under the terms of the GNU General Public License v3.0.
207214
See the LICENSE file for further information.
208215
`;
209-
writeFileSync(path.join(distDir, 'NOTICE'), notice);
210-
return src('LICENSE').pipe(dest(distDir));
216+
await writeFile(path.join(distDir, 'NOTICE'), notice);
217+
218+
await new Promise(resolve => {
219+
src('LICENSE')
220+
.pipe(dest(distDir))
221+
.on('error', done)
222+
.on('finish', resolve);
223+
});
211224
}
212225
}
213226

227+
const build = series(
228+
init,
229+
parallel(js, html, images, fonts, locale, manifest, license)
230+
);
231+
214232
function zip(done) {
215233
exec(
216234
`web-ext build -s dist/${targetEnv} -a artifacts/${targetEnv} -n "{name}-{version}-${targetEnv}.zip" --overwrite-dest`,
@@ -238,9 +256,4 @@ function inspect(done) {
238256
);
239257
}
240258

241-
exports.build = series(
242-
init,
243-
parallel(js, html, images, fonts, locale, manifest, license)
244-
);
245-
exports.zip = zip;
246-
exports.inspect = inspect;
259+
export {build, zip, inspect};

0 commit comments

Comments
 (0)