Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): support typescript configs #1233

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ id: configuration
title: Configuring Metro
---

A Metro config can be created in these three ways (ordered by priority):
A Metro config can be created in these five ways (ordered by priority):

1. `metro.config.js`
2. `metro.config.json`
3. The `metro` field in `package.json`
2. `metro.config.ts`
3. `metro.config.cjs`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - we should land this docs fix regardless.

4. `metro.config.json`
5. The `metro` field in `package.json`

You can also give a custom file to the configuration by specifying `--config <path/to/config>` when calling the CLI.

Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"connect": "^3.6.5",
"cosmiconfig": "^5.0.5",
"cosmiconfig-typescript-loader": "^5.0.0",
"jest-validate": "^29.6.3",
"metro": "0.80.6",
"metro-cache": "0.80.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/metro-config/src/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {ConfigT, InputConfigT, YargArguments} from './configTypes.flow';
const getDefaultConfig = require('./defaults');
const validConfig = require('./defaults/validConfig');
const cosmiconfig = require('cosmiconfig');
const {TypeScriptLoader} = require('cosmiconfig-typescript-loader');
const fs = require('fs');
const {validate} = require('jest-validate');
const MetroCache = require('metro-cache');
Expand Down Expand Up @@ -48,11 +49,13 @@ function overrideArgument<T>(arg: Array<T> | T): T {
const explorer = cosmiconfig('metro', {
searchPlaces: [
'metro.config.js',
'metro.config.ts',
'metro.config.cjs',
'metro.config.json',
'package.json',
],
loaders: {
'.ts': TypeScriptLoader(),
'.json': cosmiconfig.loadJson,
'.yaml': cosmiconfig.loadYaml,
'.yml': cosmiconfig.loadYaml,
Expand Down
3 changes: 1 addition & 2 deletions packages/metro/src/DeltaBundler/__tests__/resolver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {InputConfigT} from 'metro-config/src/configTypes.flow';

const {getDefaultConfig, mergeConfig} = require('metro-config');
const path = require('path');
const mockPlatform = process.platform;

jest.useRealTimers();
jest
Expand All @@ -26,7 +25,7 @@ jest
.mock('os', () => ({
...jest.requireActual('os'),
platform: () => 'test',
tmpdir: () => (mockPlatform === 'win32' ? 'C:\\tmp' : '/tmp'),
tmpdir: () => (process.platform === 'win32' ? 'C:\\tmp' : '/tmp'),
hostname: () => 'testhost',
endianness: () => 'LE',
release: () => '',
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,13 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cosmiconfig-typescript-loader@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-5.0.0.tgz#0d3becfe022a871f7275ceb2397d692e06045dc8"
integrity sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==
dependencies:
jiti "^1.19.1"

cosmiconfig@^5.0.5:
version "5.2.1"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
Expand Down Expand Up @@ -4516,6 +4523,11 @@ jest@^29.6.3:
import-local "^3.0.2"
jest-cli "^29.6.3"

jiti@^1.19.1:
version "1.21.0"
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.21.0.tgz#7c97f8fe045724e136a397f7340475244156105d"
integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==

js-sdsl@^4.1.4:
version "4.4.2"
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.4.2.tgz#2e3c031b1f47d3aca8b775532e3ebb0818e7f847"
Expand Down