Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
* LICENSE file in the root directory of this source tree.
*/

const {getPackages} = require('./scripts/buildUtils');
const fs = require('fs');
const path = require('path');
const {sync: readPkg} = require('read-pkg');

const internalPackages = getPackages()
.map(({pkg}) => pkg.name)
.sort();
function getPackages() {
const PACKAGES_DIR = path.resolve(__dirname, 'packages');
const packages = fs
.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
return packages.map(packageDir => {
const pkg = readPkg({cwd: packageDir});
return pkg.name;
});
}

module.exports = {
env: {
Expand Down Expand Up @@ -254,7 +264,7 @@ module.exports = {
},
{
env: {node: true},
files: ['*.js', '*.jsx'],
files: ['*.js', '*.jsx', '*.mjs', '*.cjs'],
},
{
files: [
Expand Down Expand Up @@ -325,7 +335,7 @@ module.exports = {
'scripts/**',
'babel.config.js',
'testSetupFile.js',
'.eslintrc.js',
'.eslintrc.cjs',
],
},
],
Expand Down Expand Up @@ -507,7 +517,9 @@ module.exports = {
'import/ignore': ['react-native'],
// using `new RegExp` makes sure to escape `/`
'import/internal-regex': new RegExp(
internalPackages.map(pkg => `^${pkg}$`).join('|'),
getPackages()
.map(pkg => `^${pkg}$`)
.join('|'),
).source,
'import/resolver': {
typescript: {},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:
yarn jest-coverage --color --config jest.config.ci.js --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ matrix.shard }}
yarn test-leak
- name: map coverage
run: node ./scripts/mapCoverage.js
run: node ./scripts/mapCoverage.mjs
if: always()
- uses: codecov/codecov-action@v2
if: always()
Expand Down
6 changes: 2 additions & 4 deletions e2e/watch-plugins/cjs/my-watch-plugin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*/
class MyWatchPlugin {
// Add hooks to Jest lifecycle events
apply(jestHooks) {
}
apply(jestHooks) {}

// Get the prompt information for interactive plugins
getUsageInfo(globalConfig) {
console.log('getUsageInfo');
}

// Executed when the key from `getUsageInfo` is input
run(globalConfig, updateConfigAndRun) {
}
run(globalConfig, updateConfigAndRun) {}
}

module.exports = MyWatchPlugin;
6 changes: 2 additions & 4 deletions e2e/watch-plugins/mjs/my-watch-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*/
class MyWatchPlugin {
// Add hooks to Jest lifecycle events
apply(jestHooks) {
}
apply(jestHooks) {}

// Get the prompt information for interactive plugins
getUsageInfo(globalConfig) {
console.log('getUsageInfo');
}

// Executed when the key from `getUsageInfo` is input
run(globalConfig, updateConfigAndRun) {
}
run(globalConfig, updateConfigAndRun) {}
}

export default MyWatchPlugin;
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,31 @@
"scripts": {
"build-clean": "rimraf './packages/*/build' './packages/*/dist' './packages/*/tsconfig.tsbuildinfo' './packages/*/api-extractor.json' './api-extractor.json'",
"build": "yarn build:js && yarn build:ts && yarn bundle:ts",
"build:js": "node ./scripts/build.js",
"build:ts": "node ./scripts/buildTs.js",
"bundle:ts": "node ./scripts/bundleTs.js",
"check-copyright-headers": "node ./scripts/checkCopyrightHeaders.js",
"build:js": "node ./scripts/build.mjs",
"build:ts": "node ./scripts/buildTs.mjs",
"bundle:ts": "node ./scripts/bundleTs.mjs",
"check-copyright-headers": "node ./scripts/checkCopyrightHeaders.mjs",
"clean-all": "yarn clean-e2e && yarn build-clean && rimraf './packages/*/node_modules' && rimraf './node_modules'",
"clean-e2e": "node ./scripts/cleanE2e.js",
"clean-e2e": "node ./scripts/cleanE2e.mjs",
"crowdin:upload": "echo 'Uploading sources to Crowdin' && crowdin upload sources --config ./crowdin.yaml",
"crowdin:download": "echo 'Downloading translations from Crowdin' && crowdin download --config ./crowdin.yaml",
"jest": "node ./packages/jest-cli/bin/jest.js",
"jest-jasmine": "JEST_JASMINE=1 yarn jest",
"jest-jasmine-ci": "yarn jest-jasmine --color --config jest.config.ci.js",
"jest-coverage": "yarn jest --coverage",
"lint": "eslint . --cache --ext js,jsx,ts,tsx,md",
"lint": "eslint . --cache --ext js,jsx,cjs,mjs,ts,tsx,md",
"lint:prettier": "prettier '**/*.{json,md,yml,yaml}' 'website/**/*.{css,js}' --write",
"lint:prettier:ci": "prettier '**/*.{json,md,yml,yaml}' 'website/**/*.{css,js}' --check",
"remove-examples": "node ./scripts/remove-examples.js",
"remove-examples": "node ./scripts/remove-examples.mjs",
"test-types": "yarn jest --config jest.config.tsd.js",
"test-ci-partial": "yarn test-ci-partial:parallel -i",
"test-ci-partial:parallel": "yarn jest --color --config jest.config.ci.js",
"test-pretty-format-perf": "node packages/pretty-format/perf/test.js",
"test-leak": "yarn jest -i --detectLeaks --color jest-mock jest-diff jest-repl pretty-format",
"test": "yarn lint && yarn jest",
"verify-old-ts": "node ./scripts/verifyOldTs.js",
"verify-pnp": "node ./scripts/verifyPnP.js",
"watch": "yarn build:js && node ./scripts/watch.js",
"verify-old-ts": "node ./scripts/verifyOldTs.mjs",
"verify-pnp": "node ./scripts/verifyPnP.mjs",
"watch": "yarn build:js && node ./scripts/watch.mjs",
"watch:ts": "yarn build:ts --watch"
},
"workspaces": [
Expand Down
44 changes: 25 additions & 19 deletions scripts/build.js → scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,39 @@
* Non-js files not matching IGNORE_PATTERN will be copied without transpiling.
*
* Example:
* node ./scripts/build.js
* node ./scripts/build.js /users/123/jest/packages/jest-111/src/111.js
*
* NOTE: this script is node@6 compatible
* node ./scripts/build.mjs
* node ./scripts/build.mjs /users/123/jest/packages/jest-111/src/111.js
*/

'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const babel = require('@babel/core');
const chalk = require('chalk');
const glob = require('glob');
const micromatch = require('micromatch');
const prettier = require('prettier');
const transformOptions = require('../babel.config.js');
const {getPackages, adjustToTerminalWidth, OK} = require('./buildUtils');
import assert from 'assert';
import path from 'path';
import {fileURLToPath} from 'url';
import babel from '@babel/core';
import chalk from 'chalk';
import glob from 'glob';
import fs from 'graceful-fs';
import micromatch from 'micromatch';
import prettier from 'prettier';
import transformOptions from '../babel.config.js';
import {
OK,
PACKAGES_DIR,
adjustToTerminalWidth,
getPackages,
} from './buildUtils.mjs';

const SRC_DIR = 'src';
const BUILD_DIR = 'build';
const JS_FILES_PATTERN = '**/*.js';
const TS_FILES_PATTERN = '**/*.ts';
const IGNORE_PATTERN = '**/__{tests,mocks}__/**';
const PACKAGES_DIR = path.resolve(__dirname, '../packages');

const INLINE_REQUIRE_EXCLUDE_LIST =
/packages\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\//;

const prettierConfig = prettier.resolveConfig.sync(__filename);
const prettierConfig = prettier.resolveConfig.sync(
fileURLToPath(import.meta.url),
);
prettierConfig.trailingComma = 'none';
prettierConfig.parser = 'babel';

Expand Down Expand Up @@ -110,7 +113,10 @@ function buildFile(file, silent) {
// The excluded modules are injected into the user's sandbox
// We need to guard some globals there.
options.plugins.push(
require.resolve('./babel-plugin-jest-native-globals'),
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'babel-plugin-jest-native-globals.js',
),
);
} else {
options.plugins = options.plugins.map(plugin => {
Expand Down
22 changes: 10 additions & 12 deletions scripts/buildTs.js → scripts/buildTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const chalk = require('chalk');
const execa = require('execa');
const globby = require('globby');
const stripJsonComments = require('strip-json-comments');
const throat = require('throat');
const {getPackages} = require('./buildUtils');
import assert from 'assert';
import os from 'os';
import path from 'path';
import chalk from 'chalk';
import execa from 'execa';
import globby from 'globby';
import fs from 'graceful-fs';
import stripJsonComments from 'strip-json-comments';
import throat from 'throat';
import {getPackages} from './buildUtils.mjs';

(async () => {
const packages = getPackages();
Expand Down
41 changes: 21 additions & 20 deletions scripts/buildUtils.js → scripts/buildUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const {sync: readPkg} = require('read-pkg');
const stringLength = require('string-length');
const rootPackage = require('../package.json');

const PACKAGES_DIR = path.resolve(__dirname, '../packages');

const OK = chalk.reset.inverse.bold.green(' DONE ');
import assert from 'assert';
import {createRequire} from 'module';
import path from 'path';
import {fileURLToPath} from 'url';
import chalk from 'chalk';
import fs from 'graceful-fs';
import {sync as readPkg} from 'read-pkg';
import stringLength from 'string-length';

export const PACKAGES_DIR = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../packages',
);

export const OK = chalk.reset.inverse.bold.green(' DONE ');

// Get absolute paths of all directories under packages/*
module.exports.getPackages = function getPackages() {
export function getPackages() {
const packages = fs
.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
const require = createRequire(import.meta.url);
const rootPackage = require('../package.json');

const nodeEngineRequirement = rootPackage.engines.node;

Expand Down Expand Up @@ -104,9 +108,9 @@ module.exports.getPackages = function getPackages() {

return {packageDir, pkg};
});
};
}

module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) {
export function adjustToTerminalWidth(str) {
const columns = process.stdout.columns || 80;
const WIDTH = columns - stringLength(OK) + 1;
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g'));
Expand All @@ -115,7 +119,4 @@ module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) {
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
}
return strs.slice(0, -1).concat(lastString).join('\n');
};

module.exports.OK = OK;
module.exports.PACKAGES_DIR = PACKAGES_DIR;
}
30 changes: 17 additions & 13 deletions scripts/bundleTs.js → scripts/bundleTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const fs = require('fs');
const path = require('path');
const {
import {createRequire} from 'module';
import path from 'path';
import {fileURLToPath} from 'url';
import {
CompilerState,
Extractor,
ExtractorConfig,
} = require('@microsoft/api-extractor');
const chalk = require('chalk');
const {sync: pkgDir} = require('pkg-dir');
const prettier = require('prettier');
const rimraf = require('rimraf');
const {getPackages} = require('./buildUtils');
} from '@microsoft/api-extractor';
import chalk from 'chalk';
import fs from 'graceful-fs';
import {sync as pkgDir} from 'pkg-dir';
import prettier from 'prettier';
import rimraf from 'rimraf';
import {getPackages} from './buildUtils.mjs';

const prettierConfig = prettier.resolveConfig.sync(
__filename.replace(/\.js$/, '.d.ts'),
fileURLToPath(import.meta.url).replace(/\.js$/, '.d.ts'),
);

const require = createRequire(import.meta.url);
const typescriptCompilerFolder = pkgDir(require.resolve('typescript'));

const copyrightSnippet = `
Expand Down Expand Up @@ -104,7 +105,10 @@ const copyrightSnippet = `
};

await fs.promises.writeFile(
path.resolve(__dirname, '../api-extractor.json'),
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../api-extractor.json',
),
JSON.stringify(sharedExtractorConfig, null, 2),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const {execSync} = require('child_process');
const fs = require('fs');
const {isBinaryFileSync} = require('isbinaryfile');
import {execSync} from 'child_process';
import fs from 'graceful-fs';
import {isBinaryFileSync} from 'isbinaryfile';

const getFileContents = path => fs.readFileSync(path, {encoding: 'utf-8'});
const isDirectory = path => fs.lstatSync(path).isDirectory();
Expand Down Expand Up @@ -149,7 +147,7 @@ function check() {

${invalidFiles.join('\n ')}

Please include the header or exclude the files in \`scripts/checkCopyrightHeaders.js\``);
Please include the header or exclude the files in \`scripts/checkCopyrightHeaders.mjs\``);
process.exit(1);
}
}
Expand Down
Loading