Skip to content

Commit

Permalink
Make dir for babel --out-file
Browse files Browse the repository at this point in the history
Currently there's unexpected regression after upgrade from babel 6.
On creating file with any depth like dist/index.js the error about
not existing directory is thrown.

In this diff I modified babel-cli to create deep directory for out-file
command.

I also replaced `mkdirp` with more supported `make-dir` package which
also have official promise support.
  • Loading branch information
TrySound committed Sep 3, 2018
1 parent 4beb977 commit 93e8bea
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 436 deletions.
2 changes: 1 addition & 1 deletion packages/babel-cli/package.json
Expand Up @@ -24,7 +24,7 @@
"fs-readdir-recursive": "^1.1.0",
"glob": "^7.0.0",
"lodash": "^4.17.10",
"mkdirp": "^0.5.1",
"make-dir": "^1.3.0",
"output-file-sync": "^2.0.0",
"slash": "^2.0.0",
"source-map": "^0.5.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-cli/src/babel/dir.js
@@ -1,6 +1,6 @@
import defaults from "lodash/defaults";
import outputFileSync from "output-file-sync";
import { sync as mkdirpSync } from "mkdirp";
import { sync as makeDirSync } from "make-dir";
import slash from "slash";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -116,7 +116,7 @@ export default async function({ cliOptions, babelOptions }) {
util.deleteDir(cliOptions.outDir);
}

mkdirpSync(cliOptions.outDir);
makeDirSync(cliOptions.outDir);

let compiledFiles = 0;
for (const filename of cliOptions.filenames) {
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-cli/src/babel/file.js
Expand Up @@ -2,6 +2,7 @@ import convertSourceMap from "convert-source-map";
import defaults from "lodash/defaults";
import sourceMap from "source-map";
import slash from "slash";
import { sync as makeDirSync } from "make-dir";
import path from "path";
import fs from "fs";

Expand Down Expand Up @@ -78,6 +79,8 @@ export default async function({ cliOptions, babelOptions }) {
const result = buildResult(fileResults);

if (cliOptions.outFile) {
makeDirSync(path.dirname(cliOptions.outFile));

// we've requested for a sourcemap to be written to disk
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
const mapLoc = cliOptions.outFile + ".map";
Expand Down
@@ -0,0 +1 @@
arr.map(x => x * MULTIPLIER);
@@ -0,0 +1,3 @@
{
"args": ["script.js", "--out-file", "dist/nested/script.js"]
}

0 comments on commit 93e8bea

Please sign in to comment.