From a5c7ed71827c24e41753f076217725731dc8661d Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:51:48 +0000 Subject: [PATCH 1/7] Breaking: Resolve the module system via `metro:runtime` The module system is currently an absolute path from `require.resolve` in `metro-config`, which skips resolution and depends on `metro-config`'s copy of `metro-runtime` being in the file map. This changes it to `metro:runtime/polyfills/require`, resolved once per graph, so it always comes from the copy Metro adds to the file map, and it's one fewer use of `metro-runtime/src/*`. A custom `resolveRequest` will now see this specifier and must delegate it to `context.resolveRequest`. A catch-all returning `{type: 'empty'}` would otherwise build a bundle with no module system that only fails at runtime, so that's now a build error. Changelog: ``` - **[Breaking]**: Resolve the module system via `metro:runtime/polyfills/require`. A custom `resolver.resolveRequest` must delegate `metro:` specifiers it doesn't handle to `context.resolveRequest` ``` Test plan: New integration tests. Built and ran a bundle from a project outside this repo, so that `metro-runtime` isn't reachable from it (setting `asyncRequireModulePath` to `metro:runtime/modules/asyncRequire` for that), and a catch-all `{type: 'empty'}` resolver giving the new error. Overwriting the `moduleSystem` export with an absolute path, as Expo CLI does, still builds and gives a byte-identical bundle. I haven't run this through Expo itself. --- .../metro-config/src/defaults/defaults.js | 3 +- .../__tests__/dynamic-roots-test.js | 35 +++++++++++++++++++ packages/metro/src/lib/getPrependedScripts.js | 34 ++++++++++++++---- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/packages/metro-config/src/defaults/defaults.js b/packages/metro-config/src/defaults/defaults.js index f0e7588bbf..450c277a0f 100644 --- a/packages/metro-config/src/defaults/defaults.js +++ b/packages/metro-config/src/defaults/defaults.js @@ -56,8 +56,7 @@ export const sourceExts: Array = ['js', 'jsx', 'json', 'ts', 'tsx']; export const additionalExts: Array = ['cjs', 'mjs']; -export const moduleSystem: string = - require.resolve('metro-runtime/src/polyfills/require.js'); +export const moduleSystem: string = 'metro:runtime/polyfills/require'; export const platforms: Array = ['ios', 'android', 'windows', 'web']; diff --git a/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js b/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js index 80def669b2..fd77dda5f0 100644 --- a/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js +++ b/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js @@ -174,4 +174,39 @@ describe("Metro's own metro-runtime outside every configured root", () => { ); expect(execBundle(result.code).emptyValue).toEqual({}); }); + + test('resolves the module system through the resolver', async () => { + const resolveRequest = jest.fn((context, moduleName, platform) => + context.resolveRequest(context, moduleName, platform), + ); + await Metro.runBuild( + {...config, resolver: {...config.resolver, resolveRequest}}, + {entry: 'metro-runtime/index.js'}, + ); + expect(resolveRequest).toHaveBeenCalledWith( + expect.anything(), + 'metro:runtime/polyfills/require', + expect.anything(), + ); + }); + + test('rejects a module system that resolves to an empty module', async () => { + await expect( + Metro.runBuild( + { + ...config, + resolver: { + ...config.resolver, + resolveRequest: (context, moduleName, platform) => + moduleName === 'metro:runtime/polyfills/require' + ? {type: 'empty'} + : context.resolveRequest(context, moduleName, platform), + }, + }, + {entry: 'metro-runtime/index.js'}, + ), + ).rejects.toThrow( + "The module system ('metro:runtime/polyfills/require') resolved to an empty module.", + ); + }); }); diff --git a/packages/metro/src/lib/getPrependedScripts.js b/packages/metro/src/lib/getPrependedScripts.js index ed74f09bcb..e8ba2e58d6 100644 --- a/packages/metro/src/lib/getPrependedScripts.js +++ b/packages/metro/src/lib/getPrependedScripts.js @@ -41,16 +41,36 @@ export default async function getPrependedScripts( type: 'script', }; + const resolve = await transformHelpers.getResolveDependencyFn( + bundler, + options.platform, + resolverOptions, + ); + const resolveFromProjectRoot = (name: string) => + resolve(`${config.projectRoot}/.`, { + name, + data: {key: name, locs: [], asyncType: null, isESMImport: false}, + }).filePath; + + const moduleSystem = resolveFromProjectRoot(defaults.moduleSystem); + + // A bundle with no module system builds successfully but fails at runtime. + if ( + moduleSystem === resolveFromProjectRoot(config.resolver.emptyModulePath) + ) { + throw new Error( + `The module system ('${defaults.moduleSystem}') resolved to an empty ` + + 'module. A custom `resolver.resolveRequest` must delegate this ' + + 'specifier to `context.resolveRequest`, or resolve it to a file.', + ); + } + const dependencies = await deltaBundler.getDependencies( - [defaults.moduleSystem, ...polyfillModuleNames], + [moduleSystem, ...polyfillModuleNames], { - resolve: await transformHelpers.getResolveDependencyFn( - bundler, - options.platform, - resolverOptions, - ), + resolve, transform: await transformHelpers.getTransformFn( - [defaults.moduleSystem, ...polyfillModuleNames], + [moduleSystem, ...polyfillModuleNames], bundler, deltaBundler, config, From c09560662e4f37d4d8d7fe043e17547040b1262e Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:52:04 +0000 Subject: [PATCH 2/7] Detect an empty module system without resolving `emptyModulePath` --- docs/Configuration.md | 4 +- docs/Resolution.md | 2 + packages/metro/API.md | 1 + .../__tests__/dynamic-roots-test.js | 35 ----------- .../__tests__/module-system-test.js | 63 +++++++++++++++++++ packages/metro/src/lib/getPrependedScripts.js | 20 +++--- .../metro/src/node-haste/DependencyGraph.js | 4 ++ .../DependencyGraph/ModuleResolution.js | 9 +++ 8 files changed, 93 insertions(+), 45 deletions(-) create mode 100644 packages/metro/src/integration_tests/__tests__/module-system-test.js diff --git a/docs/Configuration.md b/docs/Configuration.md index 741ba57dc5..063278473b 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -329,7 +329,9 @@ resolveRequest: (context, moduleName, platform) => { // Resolve to a file path, or throw if there is no resolution. return {filePath: 'path/to/file', type: 'sourceFile'}; } - // Optionally, chain to the standard Metro resolver. + // Chain to the standard Metro resolver for anything not handled above. This + // must include `metro:` specifiers, such as the module system + // (`metro:runtime/polyfills/require`), which is resolved for every build. return context.resolveRequest(context, moduleName, platform); }; ``` diff --git a/docs/Resolution.md b/docs/Resolution.md index c8759970f0..f2ec1bf3e9 100644 --- a/docs/Resolution.md +++ b/docs/Resolution.md @@ -333,6 +333,8 @@ resolveRequest: (context, moduleName, platform) => { }, ``` +A custom resolver must delegate any specifier it doesn't handle, including those in the [`metro:` scheme](./Configuration.md#schemeresolvers). Metro resolves its module system, `metro:runtime/polyfills/require`, through the resolver for every build, and it's a build error if that resolves to an empty module. + Custom resolvers must follow the [caching](#caching) rules. #### `schemeResolvers: Readonly<{[scheme: string]: CustomResolver}>` diff --git a/packages/metro/API.md b/packages/metro/API.md index 62d7286a96..05c1eff43f 100644 --- a/packages/metro/API.md +++ b/packages/metro/API.md @@ -72,6 +72,7 @@ export class DependencyGraph extends EventEmitter { getHasteName(filePath: string): string; getOrComputeSha1(mixedPath: string): Promise<{content?: Buffer | undefined; sha1: string}>; getWatcher(): EventEmitter; + isEmptyModule(filePath: string): boolean; matchFilesWithContext(from: string, context: Readonly<{recursive: boolean; filter: RegExp}>): Iterable; ready(): Promise; resolveDependency( diff --git a/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js b/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js index fd77dda5f0..80def669b2 100644 --- a/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js +++ b/packages/metro/src/integration_tests/__tests__/dynamic-roots-test.js @@ -174,39 +174,4 @@ describe("Metro's own metro-runtime outside every configured root", () => { ); expect(execBundle(result.code).emptyValue).toEqual({}); }); - - test('resolves the module system through the resolver', async () => { - const resolveRequest = jest.fn((context, moduleName, platform) => - context.resolveRequest(context, moduleName, platform), - ); - await Metro.runBuild( - {...config, resolver: {...config.resolver, resolveRequest}}, - {entry: 'metro-runtime/index.js'}, - ); - expect(resolveRequest).toHaveBeenCalledWith( - expect.anything(), - 'metro:runtime/polyfills/require', - expect.anything(), - ); - }); - - test('rejects a module system that resolves to an empty module', async () => { - await expect( - Metro.runBuild( - { - ...config, - resolver: { - ...config.resolver, - resolveRequest: (context, moduleName, platform) => - moduleName === 'metro:runtime/polyfills/require' - ? {type: 'empty'} - : context.resolveRequest(context, moduleName, platform), - }, - }, - {entry: 'metro-runtime/index.js'}, - ), - ).rejects.toThrow( - "The module system ('metro:runtime/polyfills/require') resolved to an empty module.", - ); - }); }); diff --git a/packages/metro/src/integration_tests/__tests__/module-system-test.js b/packages/metro/src/integration_tests/__tests__/module-system-test.js new file mode 100644 index 0000000000..c9536d384e --- /dev/null +++ b/packages/metro/src/integration_tests/__tests__/module-system-test.js @@ -0,0 +1,63 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall react_native + */ + +'use strict'; + +const Metro = require('../../..'); + +jest.useRealTimers(); +jest.setTimeout(60 * 1000); + +const build = async (resolver: {...}) => { + const baseConfig = await Metro.loadConfig({ + config: require.resolve('../metro.config.js'), + }); + return Metro.runBuild( + {...baseConfig, resolver: {...baseConfig.resolver, ...resolver}}, + {entry: 'TestBundle.js'}, + ); +}; + +const delegate = (context, moduleName, platform) => + context.resolveRequest(context, moduleName, platform); + +test('resolves the module system through the resolver', async () => { + const resolveRequest = jest.fn(delegate); + await build({resolveRequest}); + expect(resolveRequest).toHaveBeenCalledWith( + expect.anything(), + 'metro:runtime/polyfills/require', + expect.anything(), + ); +}); + +test('rejects a module system that resolves to an empty module', async () => { + await expect( + build({ + resolveRequest: (context, moduleName, platform) => + moduleName === 'metro:runtime/polyfills/require' + ? {type: 'empty'} + : delegate(context, moduleName, platform), + }), + ).rejects.toThrow( + "The module system ('metro:runtime/polyfills/require') resolved to an empty module.", + ); +}); + +test('does not resolve an unused `emptyModulePath`', async () => { + const emptyModulePath = '/does/not/exist/empty.js'; + const resolveRequest = jest.fn(delegate); + await build({emptyModulePath, resolveRequest}); + expect(resolveRequest).not.toHaveBeenCalledWith( + expect.anything(), + emptyModulePath, + expect.anything(), + ); +}); diff --git a/packages/metro/src/lib/getPrependedScripts.js b/packages/metro/src/lib/getPrependedScripts.js index e8ba2e58d6..c5b4b4049f 100644 --- a/packages/metro/src/lib/getPrependedScripts.js +++ b/packages/metro/src/lib/getPrependedScripts.js @@ -46,18 +46,20 @@ export default async function getPrependedScripts( options.platform, resolverOptions, ); - const resolveFromProjectRoot = (name: string) => - resolve(`${config.projectRoot}/.`, { - name, - data: {key: name, locs: [], asyncType: null, isESMImport: false}, - }).filePath; + const dependencyGraph = await bundler.getDependencyGraph(); - const moduleSystem = resolveFromProjectRoot(defaults.moduleSystem); + const moduleSystem = resolve(`${config.projectRoot}/.`, { + name: defaults.moduleSystem, + data: { + key: defaults.moduleSystem, + locs: [], + asyncType: null, + isESMImport: false, + }, + }).filePath; // A bundle with no module system builds successfully but fails at runtime. - if ( - moduleSystem === resolveFromProjectRoot(config.resolver.emptyModulePath) - ) { + if (dependencyGraph.isEmptyModule(moduleSystem)) { throw new Error( `The module system ('${defaults.moduleSystem}') resolved to an empty ` + 'module. A custom `resolver.resolveRequest` must delegate this ' + diff --git a/packages/metro/src/node-haste/DependencyGraph.js b/packages/metro/src/node-haste/DependencyGraph.js index e4d2c559a4..70505e1f35 100644 --- a/packages/metro/src/node-haste/DependencyGraph.js +++ b/packages/metro/src/node-haste/DependencyGraph.js @@ -367,6 +367,10 @@ export default class DependencyGraph extends EventEmitter { return resolution; } + isEmptyModule(filePath: string): boolean { + return this._moduleResolver.isEmptyModule(filePath); + } + doesFileExist = (filePath: string): boolean => { return this._fileSystem.exists(filePath); }; diff --git a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js index 12e279d46b..e249a403cb 100644 --- a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js +++ b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js @@ -113,6 +113,15 @@ export class ModuleResolver { return emptyModule; } + /** + * Whether a prior resolution of this resolver returned `filePath` as the + * empty module. This doesn't resolve `emptyModulePath`, which is only needed + * once a resolution returns `{type: 'empty'}`. + */ + isEmptyModule(filePath: string): boolean { + return this._cachedEmptyModule?.filePath === filePath; + } + resolveDependency( originModulePath: string, dependency: TransformResultDependency, From 7199867f459b736f131b1fc8834d32417368f128 Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:52:04 +0000 Subject: [PATCH 3/7] Remove the empty module system check --- docs/Resolution.md | 2 +- packages/metro/API.md | 1 - .../__tests__/module-system-test.js | 13 ------------- packages/metro/src/lib/getPrependedScripts.js | 11 ----------- packages/metro/src/node-haste/DependencyGraph.js | 4 ---- .../node-haste/DependencyGraph/ModuleResolution.js | 9 --------- 6 files changed, 1 insertion(+), 39 deletions(-) diff --git a/docs/Resolution.md b/docs/Resolution.md index f2ec1bf3e9..4562f1b098 100644 --- a/docs/Resolution.md +++ b/docs/Resolution.md @@ -333,7 +333,7 @@ resolveRequest: (context, moduleName, platform) => { }, ``` -A custom resolver must delegate any specifier it doesn't handle, including those in the [`metro:` scheme](./Configuration.md#schemeresolvers). Metro resolves its module system, `metro:runtime/polyfills/require`, through the resolver for every build, and it's a build error if that resolves to an empty module. +A custom resolver must delegate any specifier it doesn't handle, including those in the [`metro:` scheme](./Configuration.md#schemeresolvers). Metro resolves its module system, `metro:runtime/polyfills/require`, through the resolver for every build. Custom resolvers must follow the [caching](#caching) rules. diff --git a/packages/metro/API.md b/packages/metro/API.md index 05c1eff43f..62d7286a96 100644 --- a/packages/metro/API.md +++ b/packages/metro/API.md @@ -72,7 +72,6 @@ export class DependencyGraph extends EventEmitter { getHasteName(filePath: string): string; getOrComputeSha1(mixedPath: string): Promise<{content?: Buffer | undefined; sha1: string}>; getWatcher(): EventEmitter; - isEmptyModule(filePath: string): boolean; matchFilesWithContext(from: string, context: Readonly<{recursive: boolean; filter: RegExp}>): Iterable; ready(): Promise; resolveDependency( diff --git a/packages/metro/src/integration_tests/__tests__/module-system-test.js b/packages/metro/src/integration_tests/__tests__/module-system-test.js index c9536d384e..19314dc668 100644 --- a/packages/metro/src/integration_tests/__tests__/module-system-test.js +++ b/packages/metro/src/integration_tests/__tests__/module-system-test.js @@ -38,19 +38,6 @@ test('resolves the module system through the resolver', async () => { ); }); -test('rejects a module system that resolves to an empty module', async () => { - await expect( - build({ - resolveRequest: (context, moduleName, platform) => - moduleName === 'metro:runtime/polyfills/require' - ? {type: 'empty'} - : delegate(context, moduleName, platform), - }), - ).rejects.toThrow( - "The module system ('metro:runtime/polyfills/require') resolved to an empty module.", - ); -}); - test('does not resolve an unused `emptyModulePath`', async () => { const emptyModulePath = '/does/not/exist/empty.js'; const resolveRequest = jest.fn(delegate); diff --git a/packages/metro/src/lib/getPrependedScripts.js b/packages/metro/src/lib/getPrependedScripts.js index c5b4b4049f..1737cacfa4 100644 --- a/packages/metro/src/lib/getPrependedScripts.js +++ b/packages/metro/src/lib/getPrependedScripts.js @@ -46,8 +46,6 @@ export default async function getPrependedScripts( options.platform, resolverOptions, ); - const dependencyGraph = await bundler.getDependencyGraph(); - const moduleSystem = resolve(`${config.projectRoot}/.`, { name: defaults.moduleSystem, data: { @@ -58,15 +56,6 @@ export default async function getPrependedScripts( }, }).filePath; - // A bundle with no module system builds successfully but fails at runtime. - if (dependencyGraph.isEmptyModule(moduleSystem)) { - throw new Error( - `The module system ('${defaults.moduleSystem}') resolved to an empty ` + - 'module. A custom `resolver.resolveRequest` must delegate this ' + - 'specifier to `context.resolveRequest`, or resolve it to a file.', - ); - } - const dependencies = await deltaBundler.getDependencies( [moduleSystem, ...polyfillModuleNames], { diff --git a/packages/metro/src/node-haste/DependencyGraph.js b/packages/metro/src/node-haste/DependencyGraph.js index 70505e1f35..e4d2c559a4 100644 --- a/packages/metro/src/node-haste/DependencyGraph.js +++ b/packages/metro/src/node-haste/DependencyGraph.js @@ -367,10 +367,6 @@ export default class DependencyGraph extends EventEmitter { return resolution; } - isEmptyModule(filePath: string): boolean { - return this._moduleResolver.isEmptyModule(filePath); - } - doesFileExist = (filePath: string): boolean => { return this._fileSystem.exists(filePath); }; diff --git a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js index e249a403cb..12e279d46b 100644 --- a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js +++ b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js @@ -113,15 +113,6 @@ export class ModuleResolver { return emptyModule; } - /** - * Whether a prior resolution of this resolver returned `filePath` as the - * empty module. This doesn't resolve `emptyModulePath`, which is only needed - * once a resolution returns `{type: 'empty'}`. - */ - isEmptyModule(filePath: string): boolean { - return this._cachedEmptyModule?.filePath === filePath; - } - resolveDependency( originModulePath: string, dependency: TransformResultDependency, From 469e003e386661a9ae47b329e0c2384eec8a2b1b Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:58:05 +0000 Subject: [PATCH 4/7] Remove redundant emptyModulePath test --- .../integration_tests/__tests__/module-system-test.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/metro/src/integration_tests/__tests__/module-system-test.js b/packages/metro/src/integration_tests/__tests__/module-system-test.js index 19314dc668..1a3b397d02 100644 --- a/packages/metro/src/integration_tests/__tests__/module-system-test.js +++ b/packages/metro/src/integration_tests/__tests__/module-system-test.js @@ -37,14 +37,3 @@ test('resolves the module system through the resolver', async () => { expect.anything(), ); }); - -test('does not resolve an unused `emptyModulePath`', async () => { - const emptyModulePath = '/does/not/exist/empty.js'; - const resolveRequest = jest.fn(delegate); - await build({emptyModulePath, resolveRequest}); - expect(resolveRequest).not.toHaveBeenCalledWith( - expect.anything(), - emptyModulePath, - expect.anything(), - ); -}); From 7d84878c025f0c771b2c54a85cd2b4085ca1f5bb Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:58:41 +0000 Subject: [PATCH 5/7] Drop metro-config's metro-runtime dependency --- packages/metro-config/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json index 4ca00aa638..099bf4f25a 100644 --- a/packages/metro-config/package.json +++ b/packages/metro-config/package.json @@ -24,8 +24,7 @@ "jest-validate": "^29.7.0", "metro": "0.87.3", "metro-cache": "0.87.3", - "metro-core": "0.87.3", - "metro-runtime": "0.87.3" + "metro-core": "0.87.3" }, "devDependencies": { "@types/connect": "^3.4.35", From 08a859516166aa4ee0802e759aa9d45db91d51ea Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:04:07 +0000 Subject: [PATCH 6/7] Shorten docs comment --- docs/Configuration.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 063278473b..bfd1da9508 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -329,9 +329,7 @@ resolveRequest: (context, moduleName, platform) => { // Resolve to a file path, or throw if there is no resolution. return {filePath: 'path/to/file', type: 'sourceFile'}; } - // Chain to the standard Metro resolver for anything not handled above. This - // must include `metro:` specifiers, such as the module system - // (`metro:runtime/polyfills/require`), which is resolved for every build. + // Chain to the standard Metro resolver for anything not handled above. return context.resolveRequest(context, moduleName, platform); }; ``` From d1ea958f789b18fbea212fd13a669c42e482a770 Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:06:29 +0000 Subject: [PATCH 7/7] Shorten docs comment --- docs/Resolution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Resolution.md b/docs/Resolution.md index 4562f1b098..2d399f9b7d 100644 --- a/docs/Resolution.md +++ b/docs/Resolution.md @@ -333,7 +333,7 @@ resolveRequest: (context, moduleName, platform) => { }, ``` -A custom resolver must delegate any specifier it doesn't handle, including those in the [`metro:` scheme](./Configuration.md#schemeresolvers). Metro resolves its module system, `metro:runtime/polyfills/require`, through the resolver for every build. +A custom resolver must delegate any specifier it doesn't handle, including those in the [`metro:` scheme](./Configuration.md#schemeresolvers). Custom resolvers must follow the [caching](#caching) rules.