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

chore(deps): drop mz dependency #3215

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
79 changes: 0 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"jszip": "3.10.1",
"mkdirp": "3.0.1",
"multimatch": "6.0.0",
"mz": "2.7.0",
"node-fetch": "3.3.2",
"node-notifier": "10.0.1",
"open": "9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { createWriteStream } from 'fs';
import fs from 'fs/promises';

import { fs } from 'mz';
import parseJSON from 'parse-json';
import stripBom from 'strip-bom';
import defaultFromEvent from 'promise-toolbox/fromEvent';
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { fs } from 'mz';
import fs from 'fs/promises';
import nodeFs from 'fs';

import defaultBuildExtension from './build.js';
import { showDesktopNotification as defaultDesktopNotifications } from '../util/desktop-notifier.js';
Expand Down Expand Up @@ -94,7 +94,7 @@ export default async function run(
'--firefox-profile or --chromium-profile',
);
}
const isDir = fs.existsSync(profileDir);
const isDir = nodeFs.existsSync(profileDir);
if (isDir) {
log.info(`Profile directory ${profileDir} already exists`);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os from 'os';
import path from 'path';
import fs from 'fs/promises';

import camelCase from 'camelcase';
import decamelize from 'decamelize';
import { fs } from 'mz';
import parseJSON from 'parse-json';

import fileExists from './util/file-exists.js';
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import nodeFs from 'fs';
import path from 'path';
import { promisify } from 'util';
import fs from 'fs/promises';

import { default as defaultFxRunner } from 'fx-runner';
import FirefoxProfile from 'firefox-profile';
import { fs } from 'mz';
import fromEvent from 'promise-toolbox/fromEvent';

import isDirectory from '../util/is-directory.js';
Expand Down
5 changes: 3 additions & 2 deletions src/util/artifacts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fs } from 'mz';
import fs from 'fs/promises';

import { mkdirp as defaultAsyncMkdirp } from 'mkdirp';

import { UsageError, isErrorWithCode } from '../errors.js';
Expand All @@ -24,7 +25,7 @@ export async function prepareArtifactsDir(
}
// If the artifactsDir already exists, check that we have the write permissions on it.
try {
await asyncFsAccess(artifactsDir, fs.W_OK);
await asyncFsAccess(artifactsDir, fs.constants.W_OK);
} catch (accessErr) {
if (isErrorWithCode('EACCES', accessErr)) {
throw new UsageError(
Expand Down
2 changes: 1 addition & 1 deletion src/util/file-exists.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fs } from 'mz';
import fs from 'fs/promises';

import { isErrorWithCode } from '../errors.js';

Expand Down
2 changes: 1 addition & 1 deletion src/util/is-directory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fs } from 'mz';
import fs from 'fs/promises';

import { onlyErrorsWithCode } from '../errors.js';

Expand Down
2 changes: 1 addition & 1 deletion src/util/manifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs/promises';

import { fs } from 'mz';
import parseJSON from 'parse-json';
import stripBom from 'strip-bom';
import stripJsonComments from 'strip-json-comments';
Expand Down
5 changes: 3 additions & 2 deletions src/watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fs } from 'mz';
import { existsSync, lstatSync } from 'fs';

import Watchpack from 'watchpack';
import debounce from 'debounce';

Expand Down Expand Up @@ -46,7 +47,7 @@ export default function onSourceChange({

if (watchFile) {
for (const filePath of watchFile) {
if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isFile()) {
if (existsSync(filePath) && !lstatSync(filePath).isFile()) {
throw new UsageError(
'Invalid --watch-file value: ' + `"${filePath}" is not a file.`,
);
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test.cli.run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { writeFileSync } from 'fs';

import { describe, it } from 'mocha';
import { assert } from 'chai';
import { fs } from 'mz';

import {
minimalAddonPath,
Expand All @@ -29,10 +29,10 @@ describe('web-ext run', () => {
);
const watchIgnoredFile = path.join(srcDir, 'ignoredFile3.txt');

fs.writeFileSync(watchedFile, '');
watchedFilesArr.forEach((file) => fs.writeFileSync(file, ''));
watchIgnoredArr.forEach((file) => fs.writeFileSync(file, ''));
fs.writeFileSync(watchIgnoredFile, '');
writeFileSync(watchedFile, '');
watchedFilesArr.forEach((file) => writeFileSync(file, ''));
watchIgnoredArr.forEach((file) => writeFileSync(file, ''));
writeFileSync(watchIgnoredFile, '');

const argv = [
'run',
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/test.cli.sign.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { spawn } from 'child_process';
import path from 'path';
import { writeFileSync } from 'fs';

import { assert } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { fs } from 'mz';

import {
minimalAddonPath,
Expand Down Expand Up @@ -85,12 +85,12 @@ describe('web-ext sign', () => {

it('should use config file if required parameters are not in the arguments', () =>
withTempAddonDir({ addonPath: minimalAddonPath }, (srcDir, tmpDir) => {
fs.writeFileSync(
writeFileSync(
path.join(tmpDir, 'web-ext-config.js'),
GOOD_EXAMPLE_OF_WEB_EXT_CONFIG_JS,
);

fs.writeFileSync(
writeFileSync(
path.join(tmpDir, 'package.json'),
JSON.stringify({
webExt: {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('web-ext sign', () => {
it('should show an error message if the api-key is not set in the config', () =>
withTempAddonDir({ addonPath: minimalAddonPath }, (srcDir, tmpDir) => {
const configFilePath = path.join(tmpDir, 'web-ext-config.js');
fs.writeFileSync(configFilePath, BAD_EXAMPLE_OF_WEB_EXT_CONFIG_JS);
writeFileSync(configFilePath, BAD_EXAMPLE_OF_WEB_EXT_CONFIG_JS);
const argv = [
'sign',
'--verbose',
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/test-cmd/test.build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import fs from 'fs/promises';
import { writeFileSync } from 'fs';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases I used the single export instead. This pattern was also already used in parts of the repo. However this is not always possible due to stubbing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense (and thanks a lot for mentioning the motivations behind these choices explicitly in this comment, that really helped to speed up the review and sign off ❤️)


import { fs } from 'mz';
import { it, describe } from 'mocha';
import { assert } from 'chai';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -192,7 +193,7 @@ describe('build', () => {
it('handles repeating localization keys', () => {
return withTempDir((tmpDir) => {
const messageFileName = path.join(tmpDir.path(), 'messages.json');
fs.writeFileSync(
writeFileSync(
messageFileName,
`{"extensionName": {
"message": "example extension",
Expand Down Expand Up @@ -233,7 +234,7 @@ describe('build', () => {
it('handles comments in messages.json', () => {
return withTempDir((tmpDir) => {
const messageFileName = path.join(tmpDir.path(), 'messages.json');
fs.writeFileSync(
writeFileSync(
messageFileName,
`{"extensionName": {
"message": "example extension", // comments
Expand All @@ -257,7 +258,7 @@ describe('build', () => {
it('checks locale file for malformed json', () => {
return withTempDir((tmpDir) => {
const messageFileName = path.join(tmpDir.path(), 'messages.json');
fs.writeFileSync(messageFileName, '{"simulated:" "json syntax error"');
writeFileSync(messageFileName, '{"simulated:" "json syntax error"');

return getDefaultLocalizedName({
messageFile: messageFileName,
Expand Down Expand Up @@ -285,7 +286,7 @@ describe('build', () => {
return withTempDir((tmpDir) => {
const messageFileName = path.join(tmpDir.path(), 'messages.json');
//This is missing the 'message' key
fs.writeFileSync(
writeFileSync(
messageFileName,
`{"extensionName": {
"description": "example extension"
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test-cmd/test.run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import nodeFs from 'fs';
import fs from 'fs/promises';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes both APIs are used. For consistency, I let fs stay the promised API and used nodeFs for the other APIs. This name was actually used elsewhere too.


import { fs } from 'mz';
import { afterEach, beforeEach, describe, it } from 'mocha';
import { assert } from 'chai';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -368,18 +369,18 @@ describe('run', () => {
describe('profile-create-new option', () => {
beforeEach(() => {
sinon.stub(fs, 'mkdir');
sinon.stub(fs, 'existsSync');
sinon.stub(nodeFs, 'existsSync');
});

afterEach(() => {
fs.mkdir.restore();
fs.existsSync.restore();
nodeFs.existsSync.restore();
});

const fakeProfile = '/pretend/path/to/profile';

async function testCreateProfileIfMissing(expectProfileExists, runParams) {
fs.existsSync.returns(expectProfileExists);
nodeFs.existsSync.returns(expectProfileExists);
const cmd = await prepareRun();

await cmd.run(runParams);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test-cmd/test.sign.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { promisify } from 'util';
import fs from 'fs/promises';

import copyDir from 'copy-dir';
import { fs } from 'mz';
import { describe, it } from 'mocha';
import { assert } from 'chai';
import * as sinon from 'sinon';
Expand Down
Loading