Skip to content

Commit

Permalink
Convert code base to ESM import (#3778)
Browse files Browse the repository at this point in the history
* Convert code base to ESM import

* [squash] specify correct babel plugin for import transpilation

* [squash] specify correct babel plugin for import transpilation in babelrc

* trigger ci
  • Loading branch information
SimenB authored and cpojer committed Jun 9, 2017
1 parent 21e8a2a commit dec54a3
Show file tree
Hide file tree
Showing 146 changed files with 553 additions and 554 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-async-to-generator",
"transform-strict-mode"
"transform-strict-mode",
["transform-es2015-modules-commonjs", {"allowTopLevelThis": true}]
],
"retainLines": true
}
9 changes: 7 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ module.exports = {
'flowtype/require-valid-file-annotation': 2,
'max-len': 0,
'no-multiple-empty-lines': 1,
'import/order': 2,
'import/no-duplicates': 2,
'import/no-unresolved': [2, { 'ignore': ['^types/'] }]
'import/no-unresolved': [2, { 'ignore': ['^types/'] }],
// This has to be disabled until all type and module imports are combined
// https://github.com/benmosher/eslint-plugin-import/issues/645
'import/order': 0,
// These has to be disabled until the whole code base is converted to ESM
'import/default': 0,
'import/named': 0,
},
'plugins': [
'markdown',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"babel-plugin-syntax-trailing-function-commas": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-flow-strip-types": "^6.18.0",
"babel-plugin-transform-runtime": "^6.23.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import type {Path, ProjectConfig} from 'types/Config';
import type {TransformOptions} from 'types/Transform';

const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const jestPreset = require('babel-preset-jest');
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import jestPreset from 'babel-preset-jest';

const BABELRC_FILENAME = '.babelrc';
const BABELRC_JS_FILENAME = '.babelrc.js';
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config-fb-strict/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
*/

// Can't be ESModules as this is not transpiled
const fbjsConfig = require('eslint-config-fbjs');

const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import type {Path} from 'types/Config';

const path = require('path');
const childProcess = require('child_process');
import path from 'path';
import childProcess from 'child_process';

type Options = {|
lastCommit?: boolean,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import type {Path} from 'types/Config';

const path = require('path');
const childProcess = require('child_process');
import path from 'path';
import childProcess from 'child_process';

const env = Object.assign({}, process.env, {
HGPLAIN: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/eventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import type {EventHandler} from '../types';

const {makeDescribe, getTestDuration, makeTest} = require('./utils');
import {makeDescribe, getTestDuration, makeTest} from './utils';

// To pass this value from Runtime object to state we need to use global[sym]
const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
BlockName,
TestName,
} from '../types';
const {dispatch} = require('./state');
import {dispatch} from './state';

const describe = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import type {TestResult, Status} from 'types/TestResult';
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {Event, TestEntry} from '../../types';

const {getState, setState} = require('jest-matchers');
const {formatResultsErrors} = require('jest-message-util');
const {SnapshotState, addSerializer} = require('jest-snapshot');
const {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} = require('../state');
const {getTestID} = require('../utils');
const run = require('../run');
const globals = require('../index');
import {getState, setState} from 'jest-matchers';
import {formatResultsErrors} from 'jest-message-util';
import {SnapshotState, addSerializer} from 'jest-snapshot';
import {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} from '../state';
import {getTestID} from '../utils';
import run from '../run';
import globals from '../index';

const initialize = ({
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {TestResult} from 'types/TestResult';
import type Runtime from 'jest-runtime';

const FRAMEWORK_INITIALIZER = require.resolve('./jest-adapter-init');
const path = require('path');
import path from 'path';

const jestAdapter = async (
globalConfig: GlobalConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import type {RawMatcherFn} from 'types/Matchers';

const expect = require('jest-matchers');
import expect from 'jest-matchers';

const {
import {
addSerializer,
toMatchSnapshot,
toThrowErrorMatchingSnapshot,
} = require('jest-snapshot');
} from 'jest-snapshot';

type JasmineMatcher = {
(): JasmineMatcher,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-circus/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import type {
DescribeBlock,
} from '../types';

const {getState, dispatch} = require('./state');
const {
import {getState, dispatch} from './state';
import {
callAsyncFn,
getAllHooksForDescribe,
getEachHooksForTest,
makeTestResults,
} = require('./utils');
} from './utils';

const run = async (): Promise<TestResults> => {
const {rootDescribeBlock} = getState();
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-circus/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import type {Event, State, EventHandler} from '../types';

const {makeDescribe} = require('./utils');
const eventHandler = require('./eventHandler');
import {makeDescribe} from './utils';
import eventHandler from './eventHandler';

const eventHandlers: Array<EventHandler> = [eventHandler];

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/PatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import type {ScrollOptions} from './lib/scrollList';

const chalk = require('chalk');
const ansiEscapes = require('ansi-escapes');
const Prompt = require('./lib/Prompt');
import chalk from 'chalk';
import ansiEscapes from 'ansi-escapes';
import Prompt from './lib/Prompt';

const usage = (entity: string) =>
`\n${chalk.bold('Pattern Mode Usage')}\n` +
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import type {Glob, Path} from 'types/Config';
import type {ResolveModuleConfig} from 'types/Resolve';
import type {Test} from 'types/TestRunner';

const path = require('path');

const micromatch = require('micromatch');

const DependencyResolver = require('jest-resolve-dependencies');
const changedFiles = require('jest-changed-files');
const {escapePathForRegex, replacePathSepForRegex} = require('jest-regex-util');
import path from 'path';
import micromatch from 'micromatch';
import DependencyResolver from 'jest-resolve-dependencies';
import changedFiles from 'jest-changed-files';
import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';

type SearchResult = {|
noSCM?: boolean,
Expand Down
14 changes: 7 additions & 7 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
import type {TestResult} from 'types/TestResult';
import type {ScrollOptions} from './lib/scrollList';

const scroll = require('./lib/scrollList');
const {getTerminalWidth} = require('./lib/terminalUtils');
const Prompt = require('./lib/Prompt');
const formatTestNameByPattern = require('./lib/formatTestNameByPattern');
const {
import scroll from './lib/scrollList';
import {getTerminalWidth} from './lib/terminalUtils';
import Prompt from './lib/Prompt';
import formatTestNameByPattern from './lib/formatTestNameByPattern';
import {
formatTypeaheadSelection,
printMore,
printPatternCaret,
printPatternMatches,
printRestoredPatternCaret,
printStartTyping,
printTypeaheadItem,
} = require('./lib/patternModeHelpers');
const PatternPrompt = require('./PatternPrompt');
} from './lib/patternModeHelpers';
import PatternPrompt from './PatternPrompt';

module.exports = class TestNamePatternPrompt extends PatternPrompt {
_cachedTestResults: Array<TestResult>;
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import type {ScrollOptions} from './lib/scrollList';
// eslint-disable-next-line import/default
import type SearchSource from './SearchSource';

const chalk = require('chalk');
const stringLength = require('string-length');
const scroll = require('./lib/scrollList');
const {getTerminalWidth} = require('./lib/terminalUtils');
const highlight = require('./lib/highlight');
const {trimAndFormatPath} = require('./reporters/utils');
const Prompt = require('./lib/Prompt');
const {
import chalk from 'chalk';
import stringLength from 'string-length';
import scroll from './lib/scrollList';
import {getTerminalWidth} from './lib/terminalUtils';
import highlight from './lib/highlight';
import {trimAndFormatPath} from './reporters/utils';
import Prompt from './lib/Prompt';
import {
formatTypeaheadSelection,
printMore,
printPatternCaret,
printPatternMatches,
printRestoredPatternCaret,
printStartTyping,
printTypeaheadItem,
} = require('./lib/patternModeHelpers');
const PatternPrompt = require('./PatternPrompt');
} from './lib/patternModeHelpers';
import PatternPrompt from './PatternPrompt';

type SearchSources = Array<{|
context: Context,
Expand Down
25 changes: 12 additions & 13 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ import type {Context} from 'types/Context';
import type {Reporter, Test} from 'types/TestRunner';
import type {PathPattern} from './SearchSource';

const {formatExecError} = require('jest-message-util');
const snapshot = require('jest-snapshot');
const pify = require('pify');
const throat = require('throat');
const workerFarm = require('worker-farm');

const DefaultReporter = require('./reporters/DefaultReporter');
const NotifyReporter = require('./reporters/NotifyReporter');
const SummaryReporter = require('./reporters/SummaryReporter');
const VerboseReporter = require('./reporters/VerboseReporter');
const runTest = require('./runTest');
const TestWatcher = require('./TestWatcher');
const ReporterDispatcher = require('./ReporterDispatcher');
import {formatExecError} from 'jest-message-util';
import snapshot from 'jest-snapshot';
import pify from 'pify';
import throat from 'throat';
import workerFarm from 'worker-farm';
import DefaultReporter from './reporters/DefaultReporter';
import NotifyReporter from './reporters/NotifyReporter';
import SummaryReporter from './reporters/SummaryReporter';
import VerboseReporter from './reporters/VerboseReporter';
import runTest from './runTest';
import TestWatcher from './TestWatcher';
import ReporterDispatcher from './ReporterDispatcher';

const SLOW_TEST_TIME = 3000;

Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/TestSequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import type {AggregatedResult} from 'types/TestResult';
import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';

const fs = require('fs');
const getCacheFilePath = require('jest-haste-map').getCacheFilePath;
import fs from 'fs';
// $FlowFixMe: Missing ESM export
import {getCacheFilePath} from 'jest-haste-map';

const FAIL = 0;
const SUCCESS = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/TestWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @flow
*/

const {EventEmitter} = require('events');
import EventEmitter from 'events';

type State = {|
interrupted: boolean,
Expand Down
11 changes: 6 additions & 5 deletions packages/jest-cli/src/TestWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ process.on('uncaughtException', err => {
process.exit(1);
});

const {ModuleMap} = require('jest-haste-map');
const {separateMessageFromStack} = require('jest-message-util');

const Runtime = require('jest-runtime');
const runTest = require('./runTest');
// $FlowFixMe: Missing ESM export
import {ModuleMap} from 'jest-haste-map';
import {separateMessageFromStack} from 'jest-message-util';
import Runtime from 'jest-runtime';
import runTest from './runTest';

type WorkerData = {|
config: ProjectConfig,
Expand Down Expand Up @@ -59,6 +59,7 @@ const getResolver = (config, rawModuleMap) => {
if (rawModuleMap) {
return Runtime.createResolver(
config,
// $FlowFixMe: Missing ESM export
new ModuleMap(rawModuleMap.map, rawModuleMap.mocks),
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import type {Argv} from 'types/Argv';

const isCI = require('is-ci');
import isCI from 'is-ci';

const check = (argv: Argv) => {
if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) {
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/cli/getJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import type {Path} from 'types/Config';

const path = require('path');
const chalk = require('chalk');
const fs = require('graceful-fs');
import path from 'path';
import chalk from 'chalk';
import fs from 'graceful-fs';

function getJest(packageRoot: Path) {
const packageJSONPath = path.join(packageRoot, 'package.json');
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import type {Path} from 'types/Config';
import type {Argv} from 'types/Argv';

const {validateCLIOptions} = require('jest-util');
const yargs = require('yargs');
const args = require('./args');
const getJest = require('./getJest');
const runCLI = require('./runCLI');
import {validateCLIOptions} from 'jest-util';
import yargs from 'yargs';
import args from './args';
import getJest from './getJest';
import runCLI from './runCLI';

function run(argv?: Argv, project?: Path) {
argv = yargs(argv || process.argv.slice(2))
Expand Down
Loading

0 comments on commit dec54a3

Please sign in to comment.