Skip to content

Commit

Permalink
Use fileHandling option instead of isIgnored
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and nicolo-ribaudo committed Oct 9, 2020
1 parent 5dc7c49 commit 960b087
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/babel-core/src/config/config-chain.js
Expand Up @@ -126,11 +126,12 @@ const loadPresetOverridesEnvDescriptors = makeWeakCacheSync(
),
);

export type FileHandling = "transpile" | "ignored" | "unsupported";
export type RootConfigChain = ConfigChain & {
babelrc: ConfigFile | void,
config: ConfigFile | void,
ignore: IgnoreFile | void,
isIgnored: boolean,
fileHandling: FileHandling,
files: Set<string>,
};

Expand Down Expand Up @@ -275,7 +276,7 @@ export function* buildRootChain(
plugins: isIgnored ? [] : dedupDescriptors(chain.plugins),
presets: isIgnored ? [] : dedupDescriptors(chain.presets),
options: isIgnored ? [] : chain.options.map(o => normalizeOptions(o)),
isIgnored,
fileHandling: isIgnored ? "ignored" : "transpile",
ignore: ignoreFile || undefined,
babelrc: babelrcFile || undefined,
config: configFile || undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/src/config/full.js
Expand Up @@ -64,9 +64,9 @@ export default gensync<[any], ResolvedConfig | null>(function* loadFullConfig(
if (!result) {
return null;
}
const { options, context, isIgnored } = result;
const { options, context, fileHandling } = result;

if (isIgnored) {
if (fileHandling === "ignored") {
return null;
}

Expand Down
22 changes: 13 additions & 9 deletions packages/babel-core/src/config/partial.js
Expand Up @@ -5,7 +5,11 @@ import gensync, { type Handler } from "gensync";
import Plugin from "./plugin";
import { mergeOptions } from "./util";
import { createItemFromDescriptor } from "./item";
import { buildRootChain, type ConfigContext } from "./config-chain";
import {
buildRootChain,
type ConfigContext,
type FileHandling,
} from "./config-chain";
import { getEnv } from "./helpers/environment";
import {
validate,
Expand Down Expand Up @@ -59,7 +63,7 @@ function* resolveRootMode(
type PrivPartialConfig = {
options: ValidatedOptions,
context: ConfigContext,
isIgnored: boolean,
fileHandling: FileHandling,
ignore: IgnoreFile | void,
babelrc: ConfigFile | void,
config: ConfigFile | void,
Expand Down Expand Up @@ -139,7 +143,7 @@ export default function* loadPrivatePartialConfig(
return {
options,
context,
isIgnored: configChain.isIgnored,
fileHandling: configChain.fileHandling,
ignore: configChain.ignore,
babelrc: configChain.babelrc,
config: configChain.config,
Expand All @@ -158,9 +162,9 @@ export const loadPartialConfig = gensync<[any], PartialConfig | null>(
const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(opts);
if (!result) return null;

const { options, babelrc, ignore, config, isIgnored, files } = result;
const { options, babelrc, ignore, config, fileHandling, files } = result;

if (isIgnored && !showIgnoredFiles) {
if (fileHandling === "ignored" && !showIgnoredFiles) {
return null;
}

Expand All @@ -178,7 +182,7 @@ export const loadPartialConfig = gensync<[any], PartialConfig | null>(
babelrc ? babelrc.filepath : undefined,
ignore ? ignore.filepath : undefined,
config ? config.filepath : undefined,
isIgnored,
fileHandling,
files,
);
},
Expand All @@ -195,22 +199,22 @@ class PartialConfig {
babelrc: string | void;
babelignore: string | void;
config: string | void;
isIgnored: boolean;
fileHandling: FileHandling;
files: Set<string>;

constructor(
options: ValidatedOptions,
babelrc: string | void,
ignore: string | void,
config: string | void,
isIgnored: boolean,
fileHandling: FileHandling,
files: Set<string>,
) {
this.options = options;
this.babelignore = ignore;
this.babelrc = babelrc;
this.config = config;
this.isIgnored = isIgnored;
this.fileHandling = fileHandling;
this.files = files;

// Freeze since this is a public API and it should be extremely obvious that
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/test/config-chain.js
Expand Up @@ -1281,7 +1281,7 @@ describe("buildConfigChain", function () {
babelignore: fixture("config-files", ".babelignore"),
babelrc: fixture("config-files", "babelrc-extended", ".babelrc"),
config: undefined,
isIgnored: false,
fileHandling: "transpile",
options: {
...getDefaults(),
filename: filename,
Expand Down Expand Up @@ -1318,7 +1318,7 @@ describe("buildConfigChain", function () {
babelignore: fixture("config-files", "babelignore", ".babelignore"),
babelrc: undefined,
config: undefined,
isIgnored: true,
fileHandling: "ignored",
options: {
...getDefaults(),
filename: filename,
Expand Down

0 comments on commit 960b087

Please sign in to comment.