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: replace make-dir with fs.mkdir #10136

Merged
merged 4 commits into from
Jun 23, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- `[jest-runtime]` Jest-internal sandbox escape hatch ([#9907](https://github.com/facebook/jest/pull/9907))
- `[jest-fake-timers]` Update `now` param type to support `Date` in addition to `number`. ([#10169](https://github.com/facebook/jest/pull/10169))
- `[docs]` Add param to `setSystemTime` docs and remove preceding period from it and `getRealSystemTime` ([#10169](https://github.com/facebook/jest/pull/10169))
- `[jest-snapshot, jest-util]` Replace `make-dir` with `fs.mkdir` ([#10136](https://github.com/facebook/jest/pull/10136))

### Performance

Expand Down
13 changes: 6 additions & 7 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {Config} from '@jest/types';

// eslint-disable-next-line import/named
import {ExecaReturnValue, sync as spawnSync} from 'execa';
import makeDir = require('make-dir');
import rimraf = require('rimraf');
import dedent = require('dedent');
import which = require('which');
Expand Down Expand Up @@ -46,7 +45,7 @@ export const linkJestPackage = (packageName: string, cwd: Config.Path) => {
const packagesDir = path.resolve(__dirname, '../packages');
const packagePath = path.resolve(packagesDir, packageName);
const destination = path.resolve(cwd, 'node_modules/', packageName);
makeDir.sync(destination);
fs.mkdirSync(destination, {recursive: true});
rimraf.sync(destination);
fs.symlinkSync(packagePath, destination, 'junction');
};
Expand Down Expand Up @@ -77,12 +76,12 @@ export const writeFiles = (
directory: string,
files: {[filename: string]: string},
) => {
makeDir.sync(directory);
fs.mkdirSync(directory, {recursive: true});
Object.keys(files).forEach(fileOrPath => {
const dirname = path.dirname(fileOrPath);

if (dirname !== '/') {
makeDir.sync(path.join(directory, dirname));
fs.mkdirSync(path.join(directory, dirname), {recursive: true});
}
fs.writeFileSync(
path.resolve(directory, ...fileOrPath.split('/')),
Expand All @@ -95,13 +94,13 @@ export const writeSymlinks = (
directory: string,
symlinks: {[existingFile: string]: string},
) => {
makeDir.sync(directory);
fs.mkdirSync(directory, {recursive: true});
Object.keys(symlinks).forEach(fileOrPath => {
const symLinkPath = symlinks[fileOrPath];
const dirname = path.dirname(symLinkPath);

if (dirname !== '/') {
makeDir.sync(path.join(directory, dirname));
fs.mkdirSync(path.join(directory, dirname), {recursive: true});
}
fs.symlinkSync(
path.resolve(directory, ...fileOrPath.split('/')),
Expand Down Expand Up @@ -165,7 +164,7 @@ export const createEmptyPackage = (
},
};

makeDir.sync(directory);
fs.mkdirSync(directory, {recursive: true});
packageJson || (packageJson = DEFAULT_PACKAGE_JSON);
fs.writeFileSync(
path.resolve(directory, 'package.json'),
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"jest-watch-typeahead": "^0.5.0",
"jquery": "^3.2.1",
"lerna": "^3.20.2",
"make-dir": "^3.0.0",
"micromatch": "^4.0.2",
"mock-fs": "^4.4.1",
"opencollective": "^1.0.3",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"jest-matcher-utils": "^26.0.1",
"jest-message-util": "^26.0.1",
"jest-resolve": "^26.0.1",
"make-dir": "^3.0.0",
"natural-compare": "^1.4.0",
"pretty-format": "^26.0.1",
"semver": "^7.3.2"
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import * as path from 'path';
import * as fs from 'graceful-fs';
import makeDir = require('make-dir');
import naturalCompare = require('natural-compare');
import chalk = require('chalk');
import type {Config} from '@jest/types';
Expand Down Expand Up @@ -183,7 +182,7 @@ const printBacktickString = (str: string): string =>

export const ensureDirectoryExists = (filePath: Config.Path): void => {
try {
makeDir.sync(path.join(path.dirname(filePath)));
fs.mkdirSync(path.join(path.dirname(filePath)), {recursive: true});
} catch (e) {}
};

Expand Down
1 change: 0 additions & 1 deletion packages/jest-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"is-ci": "^2.0.0",
"make-dir": "^3.0.0",
"micromatch": "^4.0.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-util/src/createDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import makeDir = require('make-dir');
import * as fs from 'graceful-fs';
import type {Config} from '@jest/types';

export default function createDirectory(path: Config.Path): void {
Copy link
Member

Choose a reason for hiding this comment

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

should probably remove this helper at some point

try {
makeDir.sync(path);
fs.mkdirSync(path, {recursive: true});
} catch (e) {
if (e.code !== 'EEXIST') {
throw e;
Expand Down
3 changes: 1 addition & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const makeDir = require('make-dir');

const babel = require('@babel/core');
const chalk = require('chalk');
Expand Down Expand Up @@ -83,7 +82,7 @@ function buildFile(file, silent) {
return;
}

makeDir.sync(path.dirname(destPath));
fs.mkdirSync(path.dirname(destPath), {recursive: true});
if (
!micromatch.isMatch(file, JS_FILES_PATTERN) &&
!micromatch.isMatch(file, TS_FILES_PATTERN)
Expand Down