Make dir for babel --out-file (#8622)
* Make dir for babel --out-file 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. * Fix test
This commit is contained in:
parent
4e5ac1fd5c
commit
be0fcaaf49
@ -24,7 +24,7 @@
|
|||||||
"fs-readdir-recursive": "^1.1.0",
|
"fs-readdir-recursive": "^1.1.0",
|
||||||
"glob": "^7.0.0",
|
"glob": "^7.0.0",
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
"mkdirp": "^0.5.1",
|
"make-dir": "^2.1.0",
|
||||||
"output-file-sync": "^2.0.0",
|
"output-file-sync": "^2.0.0",
|
||||||
"slash": "^2.0.0",
|
"slash": "^2.0.0",
|
||||||
"source-map": "^0.5.0"
|
"source-map": "^0.5.0"
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import defaults from "lodash/defaults";
|
import defaults from "lodash/defaults";
|
||||||
import outputFileSync from "output-file-sync";
|
import outputFileSync from "output-file-sync";
|
||||||
import { sync as mkdirpSync } from "mkdirp";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@ -122,7 +122,7 @@ export default async function({
|
|||||||
util.deleteDir(cliOptions.outDir);
|
util.deleteDir(cliOptions.outDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdirpSync(cliOptions.outDir);
|
makeDirSync(cliOptions.outDir);
|
||||||
|
|
||||||
let compiledFiles = 0;
|
let compiledFiles = 0;
|
||||||
for (const filename of cliOptions.filenames) {
|
for (const filename of cliOptions.filenames) {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import convertSourceMap from "convert-source-map";
|
|||||||
import defaults from "lodash/defaults";
|
import defaults from "lodash/defaults";
|
||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
@ -89,6 +90,8 @@ export default async function({
|
|||||||
const result = buildResult(fileResults);
|
const result = buildResult(fileResults);
|
||||||
|
|
||||||
if (cliOptions.outFile) {
|
if (cliOptions.outFile) {
|
||||||
|
makeDirSync(path.dirname(cliOptions.outFile));
|
||||||
|
|
||||||
// we've requested for a sourcemap to be written to disk
|
// we've requested for a sourcemap to be written to disk
|
||||||
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
|
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
|
||||||
const mapLoc = cliOptions.outFile + ".map";
|
const mapLoc = cliOptions.outFile + ".map";
|
||||||
|
|||||||
1
packages/babel-cli/test/fixtures/babel/filename --out-file deep/in-files/script.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/filename --out-file deep/in-files/script.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
arr.map(x => x * MULTIPLIER);
|
||||||
3
packages/babel-cli/test/fixtures/babel/filename --out-file deep/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/filename --out-file deep/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"args": ["script.js", "--out-file", "folder/nested/script.js"]
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
arr.map(function (x) {
|
||||||
|
return x * MULTIPLIER;
|
||||||
|
});
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"find-cache-dir": "^2.0.0",
|
"find-cache-dir": "^2.0.0",
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
"mkdirp": "^0.5.1",
|
"make-dir": "^2.1.0",
|
||||||
"pirates": "^4.0.0",
|
"pirates": "^4.0.0",
|
||||||
"source-map-support": "^0.5.9"
|
"source-map-support": "^0.5.9"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { sync as mkdirpSync } from "mkdirp";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import * as babel from "@babel/core";
|
import * as babel from "@babel/core";
|
||||||
import findCacheDir from "find-cache-dir";
|
import findCacheDir from "find-cache-dir";
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ export function save() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mkdirpSync(path.dirname(FILENAME));
|
makeDirSync(path.dirname(FILENAME));
|
||||||
fs.writeFileSync(FILENAME, serialised);
|
fs.writeFileSync(FILENAME, serialised);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
switch (e.code) {
|
switch (e.code) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user