Skip to content
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
1 change: 1 addition & 0 deletions packages/metro-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"license": "MIT",
"dependencies": {
"@topoconfig/extends": "^0.12.0",
"connect": "^3.6.5",
"cosmiconfig": "^5.0.5",
"jest-validate": "^29.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,187 @@ Object {
}
`;

exports[`loadConfig can populate \`extends\` references 1`] = `
Object {
"cacheStores": Array [],
"cacheVersion": "foo",
"maxWorkers": 2,
"projectRoot": "/",
"reporter": null,
"resetCache": false,
"resolver": Object {
"assetExts": Array [
"bmp",
"gif",
"jpg",
"jpeg",
"png",
"psd",
"svg",
"webp",
"m4v",
"mov",
"mp4",
"mpeg",
"mpg",
"webm",
"aac",
"aiff",
"caf",
"m4a",
"mp3",
"wav",
"html",
"pdf",
"yaml",
"yml",
"otf",
"ttf",
"zip",
],
"assetResolutions": Array [
"1",
"1.5",
"2",
"3",
"4",
],
"blockList": /\\(\\\\/__tests__\\\\/\\.\\*\\)\\$/,
"dependencyExtractor": undefined,
"disableHierarchicalLookup": false,
"emptyModulePath": "metro-runtime/src/modules/empty-module",
"enableGlobalPackages": false,
"extraNodeModules": Object {},
"hasteImplModulePath": undefined,
"nodeModulesPaths": Array [],
"platforms": Array [
"ios",
"android",
"windows",
"web",
],
"requireCycleIgnorePatterns": Array [
/\\(\\^\\|\\\\/\\|\\\\\\\\\\)node_modules\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
],
"resolveRequest": null,
"resolverMainFields": Array [
"browser",
"main",
],
"sourceExts": Array [
"js",
"jsx",
"json",
"ts",
"tsx",
],
"unstable_conditionNames": Array [
"require",
"import",
],
"unstable_conditionsByPlatform": Object {
"web": Array [
"browser",
],
},
"unstable_enablePackageExports": false,
"unstable_enableSymlinks": true,
"useWatchman": true,
},
"serializer": Object {
"createModuleIdFactory": [Function],
"customSerializer": null,
"experimentalSerializerHook": [Function],
"getModulesRunBeforeMainModule": [Function],
"getPolyfills": [Function],
"getRunModuleStatement": [Function],
"isThirdPartyModule": [Function],
"polyfillModuleNames": Array [],
"processModuleFilter": [Function],
},
"server": Object {
"enhanceMiddleware": [Function],
"forwardClientLogs": true,
"port": 8081,
"rewriteRequestUrl": [Function],
"unstable_serverRoot": null,
"useGlobalHotkey": true,
"verifyConnections": false,
},
"stickyWorkers": true,
"symbolicator": Object {
"customizeFrame": [Function],
"customizeStack": [Function],
},
"transformer": Object {
"allowOptionalDependencies": false,
"assetPlugins": Array [],
"assetRegistryPath": "missing-asset-registry-path",
"asyncRequireModulePath": "metro-runtime/src/modules/asyncRequire",
"babelTransformerPath": "metro-babel-transformer",
"dynamicDepsInPackages": "throwAtRuntime",
"enableBabelRCLookup": true,
"enableBabelRuntime": true,
"getTransformOptions": [Function],
"globalPrefix": "",
"hermesParser": false,
"minifierConfig": Object {
"compress": Object {
"reduce_funcs": false,
},
"mangle": Object {
"toplevel": false,
},
"output": Object {
"ascii_only": true,
"quote_style": 3,
"wrap_iife": true,
},
"sourceMap": Object {
"includeSources": false,
},
"toplevel": false,
},
"minifierPath": "metro-minify-terser",
"optimizationSizeLimit": 153600,
"publicPath": "/assets",
"transformVariants": Object {
"default": Object {},
},
"unstable_allowRequireContext": false,
"unstable_compactOutput": false,
"unstable_dependencyMapReservedName": null,
"unstable_disableModuleWrapping": false,
"unstable_disableNormalizePseudoGlobals": false,
"unstable_workerThreads": false,
"workerPath": "metro/src/DeltaBundler/Worker",
},
"transformerPath": "",
"unstable_perfLoggerFactory": [Function],
"watchFolders": Array [
"/",
],
"watcher": Object {
"additionalExts": Array [
"cjs",
"mjs",
],
"healthCheck": Object {
"enabled": false,
"filePrefix": ".metro-health-check",
"interval": 30000,
"timeout": 5000,
},
"unstable_workerThreads": false,
"watchman": Object {
"deferStates": Array [
"hg.update",
],
},
},
}
`;

exports[`loadConfig injects \`metro-cache\` into the \`cacheStores\` callback 1`] = `
Object {
"cacheStores": Array [],
Expand Down
34 changes: 34 additions & 0 deletions packages/metro-config/src/__tests__/loadConfig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jest.mock('cosmiconfig');
const getDefaultConfig = require('../defaults');
const {loadConfig} = require('../loadConfig');
const cosmiconfig = require('cosmiconfig');
const fs = require('fs');
const os = require('os');
const path = require('path');
const prettyFormat = require('pretty-format');
const stripAnsi = require('strip-ansi');
Expand Down Expand Up @@ -152,6 +154,38 @@ describe('loadConfig', () => {
expect(cosmiconfig.hasLoadBeenCalled()).toBeTruthy();
});

it('can populate `extends` references', async () => {
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-'));
await fs.promises.writeFile(
path.resolve(temp, 'config.json'),
'{"extends": "./base.json"}',
'utf8',
);
await fs.promises.writeFile(
path.resolve(temp, 'base.json'),
'{"cacheVersion": "foo"}',
'utf8',
);

const config: any = {
reporter: null,
maxWorkers: 2,
cacheStores: [],
transformerPath: '',
resolver: {
emptyModulePath: 'metro-runtime/src/modules/empty-module',
},
extends: path.resolve(temp, 'config.json'),
};

cosmiconfig.setResolvedConfig(config);

const result = await loadConfig({});

expect(result).toMatchSnapshot();
expect(result.cacheVersion).toBe('foo');
});

it('can load the config with no config present', async () => {
cosmiconfig.setReturnNull(true);

Expand Down
Loading