Expose a 'cwd' option for Babel's root options.
This commit is contained in:
@@ -39,16 +39,17 @@ type ConfigPart =
|
||||
};
|
||||
|
||||
export default function buildConfigChain(
|
||||
cwd: string,
|
||||
opts: ValidatedOptions,
|
||||
envName: string,
|
||||
): Array<ConfigItem> | null {
|
||||
const filename = opts.filename ? path.resolve(opts.filename) : null;
|
||||
const filename = opts.filename ? path.resolve(cwd, opts.filename) : null;
|
||||
const builder = new ConfigChainBuilder(
|
||||
filename ? new LoadedFile(filename) : null,
|
||||
);
|
||||
|
||||
try {
|
||||
builder.mergeConfigArguments(opts, process.cwd(), envName);
|
||||
builder.mergeConfigArguments(opts, cwd, envName);
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false && filename) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
|
||||
import path from "path";
|
||||
import * as context from "../index";
|
||||
import Plugin, { validatePluginObject } from "./plugin";
|
||||
import merge from "lodash/merge";
|
||||
@@ -103,9 +104,10 @@ class OptionManager {
|
||||
init(inputOpts: {}) {
|
||||
const args = validate("arguments", inputOpts);
|
||||
|
||||
const { envName = getEnv() } = args;
|
||||
const { envName = getEnv(), cwd = "." } = args;
|
||||
const absoluteCwd = path.resolve(cwd);
|
||||
|
||||
const configChain = buildConfigChain(args, envName);
|
||||
const configChain = buildConfigChain(absoluteCwd, args, envName);
|
||||
if (!configChain) return null;
|
||||
|
||||
try {
|
||||
@@ -134,6 +136,7 @@ class OptionManager {
|
||||
.map(plugins => ({ plugins }));
|
||||
opts.passPerPreset = opts.presets.length > 0;
|
||||
opts.envName = envName;
|
||||
opts.cwd = absoluteCwd;
|
||||
|
||||
return {
|
||||
options: opts,
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
} from "./option-assertions";
|
||||
|
||||
const ROOT_VALIDATORS: ValidatorSet = {
|
||||
cwd: (assertString: Validator<$PropertyType<ValidatedOptions, "cwd">>),
|
||||
filename: (assertString: Validator<
|
||||
$PropertyType<ValidatedOptions, "filename">,
|
||||
>),
|
||||
@@ -128,6 +129,7 @@ const COMMON_VALIDATORS: ValidatorSet = {
|
||||
export type InputOptions = ValidatedOptions;
|
||||
|
||||
export type ValidatedOptions = {
|
||||
cwd?: string,
|
||||
filename?: string,
|
||||
filenameRelative?: string,
|
||||
babelrc?: boolean,
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import assert from "assert";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import buildConfigChain from "../lib/config/build-config-chain";
|
||||
import buildConfigChainFn from "../lib/config/build-config-chain";
|
||||
|
||||
const DEFAULT_ENV = "development";
|
||||
|
||||
function buildConfigChain(opts, envName) {
|
||||
return buildConfigChainFn(process.cwd(), opts, envName);
|
||||
}
|
||||
|
||||
function fixture() {
|
||||
const args = [__dirname, "fixtures", "config"];
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user