Skip to content

Commit d08a77f

Browse files
committed
refactor(scripts): Removed path-exists dependency
path-exists is not reuiqred for synchronous checks in file system, so it was replaced by fs.existsSync closes #84
1 parent b5bcf7d commit d08a77f

File tree

9 files changed

+121
-46
lines changed

9 files changed

+121
-46
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"html-webpack-plugin": "2.24.1",
6161
"http-proxy-middleware": "^0.17.3",
6262
"minimist": "1.2.0",
63-
"path-exists": "3.0.0",
6463
"postcss-loader": "1.2.1",
6564
"prompt": "1.0.0",
6665
"react-dev-utils": "0.4.2",

scripts/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Suppress warnings if this file is missing.
33
require('dotenv').config({silent: true});
44

5-
const pathExists = require('path-exists');
5+
const fs = require('fs');
66
const chalk = require('chalk');
77
const webpack = require('webpack');
88
const config = require('../config/webpack.config.prod');
99

10-
if (pathExists.sync('elm-package.json') === false) {
10+
if (fs.existsSync('elm-package.json') === false) {
1111
console.log('Please, run the build script from project root directory');
1212
process.exit(1);
1313
}

scripts/create.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const renameSync = require('fs').renameSync;
1+
const fs = require('fs');
22
const copySync = require('fs-extra').copySync;
33
const path = require('path');
44
const chalk = require('chalk');
5-
const pathExists = require('path-exists');
65
const spawnSync = require('child_process').spawnSync;
76
const argv = require('minimist')(process.argv.slice(2));
87
const commands = argv._;
@@ -24,11 +23,11 @@ function createElmApp (name) {
2423
var root = path.resolve(name);
2524
var template = path.join(__dirname, '../template');
2625

27-
if (!pathExists.sync(name)) {
26+
if (!fs.existsSync(name)) {
2827

2928
try {
3029
copySync(template, root);
31-
renameSync(path.resolve(root, 'gitignore'), path.resolve(root, '.gitignore'));
30+
fs.renameSync(path.resolve(root, 'gitignore'), path.resolve(root, '.gitignore'));
3231
} catch (err) {
3332
console.log(err);
3433
process.exit(1);

scripts/eject.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ const path = require('path');
22
const spawn = require('cross-spawn');
33
const chalk = require('chalk');
44
const extend = require('extend');
5-
const pathExists = require('path-exists');
65
const prompt = require('prompt');
7-
const fs = require('fs');
8-
const copySync = require('fs-extra').copySync;
6+
const fs = require('fs-extra');
97
const Table = require('cli-table');
108
const Promise = require('bluebird');
119
const pkgOwn = require(path.join(__dirname, '../package.json'));
@@ -72,9 +70,9 @@ function promptYesOrNo () {
7270
function performEject (pkg) {
7371
// Copy the configuration and start/build scripts.
7472
try {
75-
copySync(path.resolve(__dirname, 'build.js'), './scripts/build.js');
76-
copySync(path.resolve(__dirname, 'start.js'), './scripts/start.js');
77-
copySync(path.resolve(__dirname, '../config'), './config');
73+
fs.copySync(path.resolve(__dirname, 'build.js'), './scripts/build.js');
74+
fs.copySync(path.resolve(__dirname, 'start.js'), './scripts/start.js');
75+
fs.copySync(path.resolve(__dirname, '../config'), './config');
7876
} catch (err) {
7977
console.log(chalk.red('Failed to copy scripts, the error is:\n'));
8078
console.log(err);
@@ -100,7 +98,6 @@ function performEject (pkg) {
10098
const unusedDependencies = [
10199
'cross-spawn',
102100
'fs-extra',
103-
'minimist',
104101
'cli-table',
105102
'extend',
106103
'prompt',
@@ -117,12 +114,12 @@ const scripts = {
117114
test: 'elm-test'
118115
};
119116

120-
if (pathExists.sync('elm-package.json') === false) {
117+
if (fs.existsSync('elm-package.json') === false) {
121118
console.log('Please, run the eject script from project root directory');
122119
process.exit(1);
123120
}
124121

125-
if (pathExists.sync('./package.json') === true) {
122+
if (fs.existsSync('./package.json') === true) {
126123
console.log('Found existing package.json');
127124
var pkgEjected = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf-8' }));
128125

scripts/start.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const fs = require('fs');
2-
const pathExists = require('path-exists');
32
const chalk = require('chalk');
43
const webpack = require('webpack');
54
const WebpackDevServer = require('webpack-dev-server');
@@ -14,7 +13,7 @@ const httpProxyMiddleware = require('http-proxy-middleware');
1413
// Suppress warnings if this file is missing.
1514
require('dotenv').config({silent: true});
1615

17-
if (pathExists.sync('elm-package.json') === false) {
16+
if (fs.existsSync('elm-package.json') === false) {
1817
console.log('Please, run the build script from project root directory');
1918
process.exit(0);
2019
}

tests/create-elm-app.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const expect = require('chai').expect;
33
const spawn = require('cross-spawn');
44
const dircompare = require('dir-compare');
5-
const pathExists = require('path-exists');
5+
const fs = require('fs');
66
const rimraf = require('rimraf');
77

88

@@ -22,11 +22,11 @@ describe('Create Elm application with `create-elm-app` command', function () {
2222
}).timeout(60 * 1000);
2323

2424
it('`' + testAppName + '` should have elm-package.json file', function () {
25-
expect(pathExists.sync(path.join(testAppDir, 'elm-package.json'))).to.be.equal(true);
25+
expect(fs.existsSync(path.join(testAppDir, 'elm-package.json'))).to.be.equal(true);
2626
});
2727

2828
it('`' + testAppName + '` should have .gitignore file', function () {
29-
expect(pathExists.sync(path.join(testAppDir, '.gitignore'))).to.be.equal(true);
29+
expect(fs.existsSync(path.join(testAppDir, '.gitignore'))).to.be.equal(true);
3030
});
3131

3232
it('`' + testAppName + '` should have the same file structure as template', function () {

tests/elm-app.build.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fs = require('fs');
22
const path = require('path');
33
const spawn = require('cross-spawn');
44
const rimraf = require('rimraf');
5-
const pathExists = require('path-exists');
65
const expect = require('chai').expect;
76

87

@@ -36,7 +35,7 @@ describe('Building Elm application with `elm-app build`', function () {
3635
}).join('');
3736
expect(result.status).to.be.equal(0, 'Incorrect exit status code');
3837
expect(outputString).to.have.string('build is ready in `dist/`');
39-
expect(pathExists.sync(path.join(testAppDir, 'dist'))).to.be.equal(true);
38+
expect(fs.existsSync(path.join(testAppDir, 'dist'))).to.be.equal(true);
4039
}).timeout(12 * 60 * 1000);
4140

4241
it('`elm-app build` should exit with non zero status code when build failed', function () {

tests/elm-app.eject.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const path = require('path');
33
const expect = require('chai').expect;
44
const spawn = require('cross-spawn');
55
const dircompare = require('dir-compare');
6-
const pathExists = require('path-exists');
76
const rimraf = require('rimraf');
87

98

@@ -54,9 +53,9 @@ describe('Ejecting Elm application. (Please wait...)', function () {
5453
});
5554

5655
it('Ejected application should have build and start scripts', function () {
57-
expect(pathExists.sync(path.join(testAppDir, './scripts/build.js')))
56+
expect(fs.existsSync(path.join(testAppDir, './scripts/build.js')))
5857
.to.be.equal(true);
59-
expect(pathExists.sync(path.join(testAppDir, './scripts/start.js')))
58+
expect(fs.existsSync(path.join(testAppDir, './scripts/start.js')))
6059
.to.be.equal(true);
6160
});
6261

0 commit comments

Comments
 (0)