@react-native-harness/metro 1.0.0 → 1.1.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/__tests__/withRnHarness.test.d.ts +2 -0
- package/dist/__tests__/withRnHarness.test.d.ts.map +1 -0
- package/dist/__tests__/withRnHarness.test.js +25 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/withRnHarness.d.ts +1 -2
- package/dist/withRnHarness.d.ts.map +1 -1
- package/dist/withRnHarness.js +6 -76
- package/package.json +4 -9
- package/src/__tests__/withRnHarness.test.ts +32 -0
- package/src/withRnHarness.ts +9 -101
- package/tsconfig.json +0 -9
- package/tsconfig.lib.json +1 -12
- package/vite.config.ts +18 -0
- package/.claude/settings.local.json +0 -9
- package/dist/babel-transformer.d.ts +0 -6
- package/dist/babel-transformer.d.ts.map +0 -1
- package/dist/babel-transformer.js +0 -31
- package/dist/errors.d.ts +0 -4
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -10
- package/dist/getHarnessSerializer.d.ts +0 -4
- package/dist/getHarnessSerializer.d.ts.map +0 -1
- package/dist/getHarnessSerializer.js +0 -33
- package/dist/jest-globals-mock.d.ts +0 -2
- package/dist/jest-globals-mock.d.ts.map +0 -1
- package/dist/jest-globals-mock.js +0 -5
- package/dist/json-reporter.d.ts +0 -2
- package/dist/json-reporter.d.ts.map +0 -1
- package/dist/json-reporter.js +0 -9
- package/dist/manifest.d.ts +0 -3
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js +0 -21
- package/dist/metro-cache.d.ts +0 -4
- package/dist/metro-cache.d.ts.map +0 -1
- package/dist/metro-cache.js +0 -16
- package/dist/moduleSystem.d.ts +0 -2
- package/dist/moduleSystem.d.ts.map +0 -1
- package/dist/moduleSystem.js +0 -30
- package/dist/node_modules/.cache/rn-harness/manifest.js +0 -1
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolver.js +0 -30
- package/dist/resolvers/composite-resolver.d.ts +0 -3
- package/dist/resolvers/composite-resolver.d.ts.map +0 -1
- package/dist/resolvers/composite-resolver.js +0 -15
- package/dist/resolvers/resolver.d.ts +0 -8
- package/dist/resolvers/resolver.d.ts.map +0 -1
- package/dist/resolvers/resolver.js +0 -83
- package/dist/resolvers/tsconfig-resolver.d.ts +0 -18
- package/dist/resolvers/tsconfig-resolver.d.ts.map +0 -1
- package/dist/resolvers/tsconfig-resolver.js +0 -160
- package/dist/resolvers/types.d.ts +0 -4
- package/dist/resolvers/types.d.ts.map +0 -1
- package/dist/resolvers/types.js +0 -2
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -2
- package/src/babel-transformer.ts +0 -40
- package/src/errors.ts +0 -6
- package/src/getHarnessSerializer.ts +0 -46
- package/src/jest-globals-mock.ts +0 -6
- package/src/manifest.ts +0 -24
- package/src/metro-cache.ts +0 -24
- package/src/resolvers/composite-resolver.ts +0 -16
- package/src/resolvers/resolver.ts +0 -100
- package/src/resolvers/tsconfig-resolver.ts +0 -210
- package/src/resolvers/types.ts +0 -4
- package/src/utils.ts +0 -3
package/src/withRnHarness.ts
CHANGED
|
@@ -1,109 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { getConfig } from '@react-native-harness/config';
|
|
3
|
-
import { getHarnessResolver } from './resolvers/resolver';
|
|
4
|
-
import { getHarnessManifest } from './manifest';
|
|
5
|
-
import { getHarnessBabelTransformerPath } from './babel-transformer';
|
|
6
|
-
import { getHarnessCacheStores } from './metro-cache';
|
|
7
|
-
import type { NotReadOnly } from './utils';
|
|
1
|
+
let hasWarned = false;
|
|
8
2
|
|
|
9
|
-
const
|
|
10
|
-
/(^|[\\/])(node_modules[/\\]@react-native-harness)([\\/]|$)/;
|
|
11
|
-
|
|
12
|
-
export const withRnHarness = <T extends MetroConfig>(
|
|
3
|
+
export const withRnHarness = <T>(
|
|
13
4
|
config: T | Promise<T>,
|
|
14
|
-
|
|
5
|
+
_isInvokedByHarness = false
|
|
15
6
|
): (() => Promise<T>) => {
|
|
16
|
-
// This is a workaround for a regression in Metro 0.83, when promises are not handled correctly.
|
|
17
7
|
return async () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const metroConfig = await config;
|
|
25
|
-
const { config: harnessConfig } = await getConfig(process.cwd());
|
|
26
|
-
|
|
27
|
-
const harnessResolver = getHarnessResolver(metroConfig, harnessConfig);
|
|
28
|
-
const harnessManifest = getHarnessManifest(harnessConfig);
|
|
29
|
-
const harnessBabelTransformerPath =
|
|
30
|
-
getHarnessBabelTransformerPath(metroConfig);
|
|
31
|
-
|
|
32
|
-
const patchedConfig: MetroConfig = {
|
|
33
|
-
...metroConfig,
|
|
34
|
-
cacheVersion: 'react-native-harness',
|
|
35
|
-
server: {
|
|
36
|
-
...metroConfig.server,
|
|
37
|
-
forwardClientLogs: harnessConfig.forwardClientLogs ?? false,
|
|
38
|
-
},
|
|
39
|
-
serializer: {
|
|
40
|
-
...metroConfig.serializer,
|
|
41
|
-
getPolyfills: (...args) => [
|
|
42
|
-
...(metroConfig.serializer?.getPolyfills?.(...args) ?? []),
|
|
43
|
-
harnessManifest,
|
|
44
|
-
require.resolve(
|
|
45
|
-
'@react-native-harness/runtime/polyfills/harness-module-system'
|
|
46
|
-
),
|
|
47
|
-
],
|
|
48
|
-
isThirdPartyModule({ path: modulePath }) {
|
|
49
|
-
const isThirdPartyByDefault =
|
|
50
|
-
metroConfig.serializer?.isThirdPartyModule?.({
|
|
51
|
-
path: modulePath,
|
|
52
|
-
}) ?? false;
|
|
53
|
-
|
|
54
|
-
if (isThirdPartyByDefault) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return INTERNAL_CALLSITES_REGEX.test(modulePath);
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
resolver: {
|
|
62
|
-
...metroConfig.resolver,
|
|
63
|
-
// Unlock __tests__ directory
|
|
64
|
-
blockList: undefined,
|
|
65
|
-
resolveRequest: harnessResolver,
|
|
66
|
-
},
|
|
67
|
-
transformer: {
|
|
68
|
-
...metroConfig.transformer,
|
|
69
|
-
babelTransformerPath: harnessBabelTransformerPath,
|
|
70
|
-
},
|
|
71
|
-
symbolicator: {
|
|
72
|
-
...metroConfig.symbolicator,
|
|
73
|
-
customizeFrame: async (frame) => {
|
|
74
|
-
const defaultCustomizeFrame =
|
|
75
|
-
await metroConfig.symbolicator?.customizeFrame?.(frame);
|
|
76
|
-
const shouldCollapseByDefault =
|
|
77
|
-
defaultCustomizeFrame?.collapse ?? false;
|
|
78
|
-
|
|
79
|
-
if (shouldCollapseByDefault) {
|
|
80
|
-
return {
|
|
81
|
-
collapse: true,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
collapse:
|
|
87
|
-
frame.file != null && INTERNAL_CALLSITES_REGEX.test(frame.file),
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
if (harnessConfig.unstable__enableMetroCache) {
|
|
94
|
-
(patchedConfig.cacheStores as NotReadOnly<MetroConfig['cacheStores']>) =
|
|
95
|
-
getHarnessCacheStores();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (harnessConfig.unstable__skipAlreadyIncludedModules) {
|
|
99
|
-
(
|
|
100
|
-
patchedConfig.serializer as NonNullable<
|
|
101
|
-
NotReadOnly<MetroConfig['serializer']>
|
|
102
|
-
>
|
|
103
|
-
).customSerializer =
|
|
104
|
-
require('./getHarnessSerializer').getHarnessSerializer();
|
|
8
|
+
if (!hasWarned) {
|
|
9
|
+
hasWarned = true;
|
|
10
|
+
console.warn(
|
|
11
|
+
"[react-native-harness] `withRnHarness` in Metro configs is deprecated and will be removed in a future release. Remove `withRnHarness` from your Metro config; React Native Harness now patches Metro internally."
|
|
12
|
+
);
|
|
105
13
|
}
|
|
106
14
|
|
|
107
|
-
return
|
|
15
|
+
return await config;
|
|
108
16
|
};
|
|
109
17
|
};
|
package/tsconfig.json
CHANGED
package/tsconfig.lib.json
CHANGED
|
@@ -9,16 +9,5 @@
|
|
|
9
9
|
"forceConsistentCasingInFileNames": true,
|
|
10
10
|
"types": ["node"]
|
|
11
11
|
},
|
|
12
|
-
"include": ["src/**/*.ts"]
|
|
13
|
-
"references": [
|
|
14
|
-
{
|
|
15
|
-
"path": "../babel-preset/tsconfig.lib.json"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"path": "../config/tsconfig.lib.json"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"path": "../runtime/tsconfig.lib.json"
|
|
22
|
-
}
|
|
23
|
-
]
|
|
12
|
+
"include": ["src/**/*.ts"]
|
|
24
13
|
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
|
|
4
|
+
export default defineConfig(() => ({
|
|
5
|
+
root: __dirname,
|
|
6
|
+
cacheDir: '../../node_modules/.vite/packages/metro',
|
|
7
|
+
test: {
|
|
8
|
+
watch: false,
|
|
9
|
+
globals: true,
|
|
10
|
+
environment: 'node',
|
|
11
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
12
|
+
reporters: ['default'],
|
|
13
|
+
coverage: {
|
|
14
|
+
reportsDirectory: './test-output/vitest/coverage',
|
|
15
|
+
provider: 'v8' as const,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BabelTransformer } from 'metro-babel-transformer';
|
|
2
|
-
import { MetroConfig } from '@react-native/metro-config';
|
|
3
|
-
export declare const getHarnessBabelTransformerPath: (metroConfig: MetroConfig) => string;
|
|
4
|
-
declare const transform: BabelTransformer['transform'];
|
|
5
|
-
export { transform };
|
|
6
|
-
//# sourceMappingURL=babel-transformer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel-transformer.d.ts","sourceRoot":"","sources":["../src/babel-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,eAAO,MAAM,8BAA8B,GACzC,aAAa,WAAW,KACvB,MASF,CAAC;AAEF,QAAA,MAAM,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAoB5C,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transform = exports.getHarnessBabelTransformerPath = void 0;
|
|
4
|
-
const babel_preset_1 = require("@react-native-harness/babel-preset");
|
|
5
|
-
const getHarnessBabelTransformerPath = (metroConfig) => {
|
|
6
|
-
const upstreamTransformerPath = metroConfig.transformer?.babelTransformerPath;
|
|
7
|
-
if (!upstreamTransformerPath || typeof upstreamTransformerPath !== 'string') {
|
|
8
|
-
throw new Error('Upstream transformer path is not a string');
|
|
9
|
-
}
|
|
10
|
-
process.env.RN_HARNESS_UPSTREAM_TRANSFORMER_PATH = upstreamTransformerPath;
|
|
11
|
-
return require.resolve('./babel-transformer.js');
|
|
12
|
-
};
|
|
13
|
-
exports.getHarnessBabelTransformerPath = getHarnessBabelTransformerPath;
|
|
14
|
-
const transform = (args) => {
|
|
15
|
-
const { plugins } = args;
|
|
16
|
-
const upstreamTransformerPath = process.env.RN_HARNESS_UPSTREAM_TRANSFORMER_PATH;
|
|
17
|
-
if (!upstreamTransformerPath || typeof upstreamTransformerPath !== 'string') {
|
|
18
|
-
throw new Error('Upstream transformer path is not a string');
|
|
19
|
-
}
|
|
20
|
-
const upstreamTransformer = require(upstreamTransformerPath);
|
|
21
|
-
const pluginsWithHarness = [
|
|
22
|
-
// Checked against @babel/core's type definitions - plugins are an array of PluginItem
|
|
23
|
-
...(plugins ?? []),
|
|
24
|
-
...babel_preset_1.rnHarnessPlugins,
|
|
25
|
-
];
|
|
26
|
-
return upstreamTransformer.transform({
|
|
27
|
-
...args,
|
|
28
|
-
plugins: pluginsWithHarness,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
exports.transform = transform;
|
package/dist/errors.d.ts
DELETED
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,8BAA+B,SAAQ,KAAK;;CAKxD"}
|
package/dist/errors.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CouldNotPatchModuleSystemError = void 0;
|
|
4
|
-
class CouldNotPatchModuleSystemError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super('Could not patch module system');
|
|
7
|
-
this.name = 'CouldNotPatchModuleSystemError';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.CouldNotPatchModuleSystemError = CouldNotPatchModuleSystemError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getHarnessSerializer.d.ts","sourceRoot":"","sources":["../src/getHarnessSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG,WAAW,CAClC,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAC3D,CAAC;AAYF,eAAO,MAAM,oBAAoB,QAAO,UA6BvC,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHarnessSerializer = void 0;
|
|
4
|
-
const getBaseSerializer = () => {
|
|
5
|
-
const baseJSBundle = require('metro/private/DeltaBundler/Serializers/baseJSBundle');
|
|
6
|
-
const bundleToString = require('metro/private/lib/bundleToString');
|
|
7
|
-
return (entryPoint, prepend, graph, bundleOptions) => bundleToString(baseJSBundle(entryPoint, prepend, graph, bundleOptions));
|
|
8
|
-
};
|
|
9
|
-
const getAllFiles = require('metro/private/DeltaBundler/Serializers/getAllFiles');
|
|
10
|
-
const getHarnessSerializer = () => {
|
|
11
|
-
const baseSerializer = getBaseSerializer();
|
|
12
|
-
let mainEntryPointModules = new Set();
|
|
13
|
-
return async (entryPoint, preModules, graph, options) => {
|
|
14
|
-
if (options.modulesOnly) {
|
|
15
|
-
// This is most likely a test file
|
|
16
|
-
return baseSerializer(entryPoint, preModules, graph, {
|
|
17
|
-
...options,
|
|
18
|
-
processModuleFilter: (mod) => {
|
|
19
|
-
if (options.processModuleFilter &&
|
|
20
|
-
!options.processModuleFilter(mod)) {
|
|
21
|
-
// If the module is not allowed by the processModuleFilter, skip it
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
// If the module is in the main entry point, skip it
|
|
25
|
-
return !mainEntryPointModules.has(mod.path);
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
mainEntryPointModules = new Set(await getAllFiles(preModules, graph, options));
|
|
30
|
-
return baseSerializer(entryPoint, preModules, graph, options);
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
exports.getHarnessSerializer = getHarnessSerializer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest-globals-mock.d.ts","sourceRoot":"","sources":["../src/jest-globals-mock.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Mock module for @jest/globals imports
|
|
3
|
-
// This module throws immediately when imported to warn users about using Jest APIs
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
throw new Error("Importing '@jest/globals' is not supported in Harness tests. Import from 'react-native-harness' instead.");
|
package/dist/json-reporter.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-reporter.d.ts","sourceRoot":"","sources":["../src/json-reporter.ts"],"names":[],"mappings":""}
|
package/dist/json-reporter.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const JsonReporter = require('metro/private/lib/JsonReporter');
|
|
4
|
-
class CustomReporter extends JsonReporter {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(process.stdout);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
module.exports = CustomReporter;
|
package/dist/manifest.d.ts
DELETED
package/dist/manifest.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAUvE,eAAO,MAAM,kBAAkB,GAAI,eAAe,aAAa,KAAG,MAWjE,CAAC"}
|
package/dist/manifest.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHarnessManifest = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
|
-
const getManifestContent = (harnessConfig) => {
|
|
8
|
-
return `global.RN_HARNESS = {
|
|
9
|
-
appRegistryComponentName: '${harnessConfig.appRegistryComponentName}',
|
|
10
|
-
webSocketPort: ${harnessConfig.webSocketPort},
|
|
11
|
-
disableViewFlattening: ${harnessConfig.disableViewFlattening},
|
|
12
|
-
};`;
|
|
13
|
-
};
|
|
14
|
-
const getHarnessManifest = (harnessConfig) => {
|
|
15
|
-
const manifestContent = getManifestContent(harnessConfig);
|
|
16
|
-
const manifestPath = node_path_1.default.resolve(process.cwd(), 'node_modules/.cache/rn-harness/manifest.js');
|
|
17
|
-
node_fs_1.default.mkdirSync(node_path_1.default.dirname(manifestPath), { recursive: true });
|
|
18
|
-
node_fs_1.default.writeFileSync(manifestPath, manifestContent);
|
|
19
|
-
return manifestPath;
|
|
20
|
-
};
|
|
21
|
-
exports.getHarnessManifest = getHarnessManifest;
|
package/dist/metro-cache.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metro-cache.d.ts","sourceRoot":"","sources":["../src/metro-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAIrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAOvD,eAAO,MAAM,qBAAqB,QAAO,CAAC,CACxC,UAAU,EAAE,UAAU,KACnB,kBAAkB,CAUtB,CAAC"}
|
package/dist/metro-cache.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHarnessCacheStores = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
-
const CACHE_ROOT = node_path_1.default.resolve(process.cwd(), 'node_modules/.cache/rn-harness/metro-cache');
|
|
8
|
-
const getHarnessCacheStores = () => {
|
|
9
|
-
return ({ FileStore }) => {
|
|
10
|
-
node_fs_1.default.mkdirSync(CACHE_ROOT, { recursive: true });
|
|
11
|
-
return [
|
|
12
|
-
new FileStore({ root: CACHE_ROOT }),
|
|
13
|
-
];
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
exports.getHarnessCacheStores = getHarnessCacheStores;
|
package/dist/moduleSystem.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"moduleSystem.d.ts","sourceRoot":"","sources":["../src/moduleSystem.ts"],"names":[],"mappings":"AAqCA,eAAO,MAAM,iBAAiB,QAAO,IAOpC,CAAC"}
|
package/dist/moduleSystem.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchModuleSystem = void 0;
|
|
4
|
-
const errors_1 = require("./errors");
|
|
5
|
-
const optionalResolve = (path, from) => {
|
|
6
|
-
try {
|
|
7
|
-
return require.resolve(path, { paths: [from] });
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const getMetroDefaultsPath = () => {
|
|
14
|
-
const reactNativeMetroConfigPath = require.resolve('@react-native/metro-config', { paths: [process.cwd()] });
|
|
15
|
-
const preExportsDefaults = optionalResolve('metro-config/src/defaults/defaults', reactNativeMetroConfigPath);
|
|
16
|
-
if (preExportsDefaults) {
|
|
17
|
-
return preExportsDefaults;
|
|
18
|
-
}
|
|
19
|
-
const privateDefaults = optionalResolve('metro-config/private/defaults/defaults', reactNativeMetroConfigPath);
|
|
20
|
-
if (privateDefaults) {
|
|
21
|
-
return privateDefaults;
|
|
22
|
-
}
|
|
23
|
-
throw new errors_1.CouldNotPatchModuleSystemError();
|
|
24
|
-
};
|
|
25
|
-
const patchModuleSystem = () => {
|
|
26
|
-
const metroConfigPath = getMetroDefaultsPath();
|
|
27
|
-
const metroConfig = require(metroConfigPath);
|
|
28
|
-
metroConfig.moduleSystem = require.resolve('@react-native-harness/runtime/moduleSystem');
|
|
29
|
-
};
|
|
30
|
-
exports.patchModuleSystem = patchModuleSystem;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
global.RN_HARNESS = { appRegistryComponentName: 'Playground' };
|
package/dist/resolver.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { MetroConfig } from '@react-native/metro-config';
|
|
2
|
-
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
3
|
-
type CustomResolver = NonNullable<NonNullable<MetroConfig['resolver']>['resolveRequest']>;
|
|
4
|
-
export declare const getHarnessResolver: (metroConfig: MetroConfig, harnessConfig: HarnessConfig) => CustomResolver;
|
|
5
|
-
export {};
|
|
6
|
-
//# sourceMappingURL=resolver.d.ts.map
|
package/dist/resolver.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE5E,KAAK,cAAc,GAAG,WAAW,CAC/B,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CACvD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,aAAa,WAAW,EACxB,eAAe,aAAa,KAC3B,cAgCF,CAAC"}
|
package/dist/resolver.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHarnessResolver = void 0;
|
|
4
|
-
const getHarnessResolver = (metroConfig, harnessConfig) => {
|
|
5
|
-
// Can be relative to the project root or absolute, need to normalize it
|
|
6
|
-
const resolvedEntryPointPath = require.resolve(harnessConfig.entryPoint, {
|
|
7
|
-
paths: [process.cwd()],
|
|
8
|
-
});
|
|
9
|
-
return (context, moduleName, platform) => {
|
|
10
|
-
const existingResolver = metroConfig.resolver?.resolveRequest ?? context.resolveRequest;
|
|
11
|
-
const resolvedModule = existingResolver(context, moduleName, platform);
|
|
12
|
-
// Replace the entry point with Harness
|
|
13
|
-
if (resolvedModule.type === 'sourceFile' &&
|
|
14
|
-
resolvedModule.filePath === resolvedEntryPointPath) {
|
|
15
|
-
return {
|
|
16
|
-
type: 'sourceFile',
|
|
17
|
-
filePath: require.resolve('@react-native-harness/runtime/entry-point'),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
// Intercept @jest/globals imports and redirect to mock module
|
|
21
|
-
if (moduleName === '@jest/globals') {
|
|
22
|
-
return {
|
|
23
|
-
type: 'sourceFile',
|
|
24
|
-
filePath: require.resolve('./jest-globals-mock'),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return resolvedModule;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
exports.getHarnessResolver = getHarnessResolver;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"composite-resolver.d.ts","sourceRoot":"","sources":["../../src/resolvers/composite-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE9D,eAAO,MAAM,qBAAqB,GAChC,WAAW,eAAe,EAAE,KAC3B,aAWF,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHarnessResolver = void 0;
|
|
4
|
-
const createHarnessResolver = (resolvers) => {
|
|
5
|
-
return (context, moduleName, platform) => {
|
|
6
|
-
for (const resolver of resolvers) {
|
|
7
|
-
const result = resolver(context, moduleName, platform);
|
|
8
|
-
if (result != null) {
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return context.resolveRequest(context, moduleName, platform);
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.createHarnessResolver = createHarnessResolver;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { MetroConfig } from '@react-native/metro-config';
|
|
2
|
-
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
3
|
-
import type { HarnessResolver, MetroResolver } from './types';
|
|
4
|
-
export declare const createHarnessEntryPointResolver: (harnessConfig: HarnessConfig) => HarnessResolver;
|
|
5
|
-
export declare const createJestGlobalsResolver: () => HarnessResolver;
|
|
6
|
-
export declare const createJsxRuntimeResolver: () => HarnessResolver;
|
|
7
|
-
export declare const getHarnessResolver: (metroConfig: MetroConfig, harnessConfig: HarnessConfig) => MetroResolver;
|
|
8
|
-
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/resolvers/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI5E,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS9D,eAAO,MAAM,+BAA+B,GAAI,eAAe,aAAa,KAAG,eA4B9E,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,eAY5C,CAAC;AAEF,eAAO,MAAM,wBAAwB,QAAO,eAyB3C,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,aAAa,WAAW,EACxB,eAAe,aAAa,KAC3B,aAWF,CAAC"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHarnessResolver = exports.createJsxRuntimeResolver = exports.createJestGlobalsResolver = exports.createHarnessEntryPointResolver = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
-
const composite_resolver_1 = require("./composite-resolver");
|
|
7
|
-
const tsconfig_resolver_1 = require("./tsconfig-resolver");
|
|
8
|
-
// Safely resolves a path and strips its extension
|
|
9
|
-
const getExtensionlessAbsolutePath = (basePath, relativePath = '') => {
|
|
10
|
-
const fullPath = node_path_1.default.resolve(basePath, relativePath);
|
|
11
|
-
const parsed = node_path_1.default.parse(fullPath);
|
|
12
|
-
return node_path_1.default.join(parsed.dir, parsed.name);
|
|
13
|
-
};
|
|
14
|
-
const createHarnessEntryPointResolver = (harnessConfig) => {
|
|
15
|
-
const rootPath = node_path_1.default.resolve(process.cwd());
|
|
16
|
-
const expectedEntryPoint = getExtensionlessAbsolutePath(rootPath, harnessConfig.entryPoint);
|
|
17
|
-
const resolvedHarnessPath = require.resolve('@react-native-harness/runtime/entry-point');
|
|
18
|
-
return (context, moduleName, _platform) => {
|
|
19
|
-
// 1. Resolve the origin path of the file making the import
|
|
20
|
-
const currentOrigin = node_path_1.default.resolve(context.originModulePath);
|
|
21
|
-
// Fast Fail: If the import isn't happening from the root directory, skip it immediately
|
|
22
|
-
if (currentOrigin !== rootPath) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
// 2. Resolve the module being imported and strip its extension
|
|
26
|
-
// This safely normalizes './index', './index.js', 'index.js', etc.
|
|
27
|
-
const requestedModule = getExtensionlessAbsolutePath(currentOrigin, moduleName);
|
|
28
|
-
// 3. String comparison
|
|
29
|
-
if (requestedModule === expectedEntryPoint) {
|
|
30
|
-
return {
|
|
31
|
-
type: 'sourceFile',
|
|
32
|
-
filePath: resolvedHarnessPath,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
exports.createHarnessEntryPointResolver = createHarnessEntryPointResolver;
|
|
39
|
-
const createJestGlobalsResolver = () => {
|
|
40
|
-
return (_context, moduleName, _platform) => {
|
|
41
|
-
// Intercept @jest/globals imports and redirect to mock module
|
|
42
|
-
if (moduleName === '@jest/globals') {
|
|
43
|
-
return {
|
|
44
|
-
type: 'sourceFile',
|
|
45
|
-
filePath: require.resolve('../jest-globals-mock'),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
exports.createJestGlobalsResolver = createJestGlobalsResolver;
|
|
52
|
-
const createJsxRuntimeResolver = () => {
|
|
53
|
-
const resolvedJsxRuntimePath = require.resolve('@react-native-harness/runtime/jsx-runtime');
|
|
54
|
-
const resolvedJsxDevRuntimePath = require.resolve('@react-native-harness/runtime/jsx-dev-runtime');
|
|
55
|
-
return (_context, moduleName, _platform) => {
|
|
56
|
-
if (moduleName === '@react-native-harness/runtime/jsx-runtime') {
|
|
57
|
-
return {
|
|
58
|
-
type: 'sourceFile',
|
|
59
|
-
filePath: resolvedJsxRuntimePath,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (moduleName === '@react-native-harness/runtime/jsx-dev-runtime') {
|
|
63
|
-
return {
|
|
64
|
-
type: 'sourceFile',
|
|
65
|
-
filePath: resolvedJsxDevRuntimePath,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
exports.createJsxRuntimeResolver = createJsxRuntimeResolver;
|
|
72
|
-
const getHarnessResolver = (metroConfig, harnessConfig) => {
|
|
73
|
-
const userResolver = metroConfig.resolver?.resolveRequest;
|
|
74
|
-
const resolvers = [
|
|
75
|
-
(0, exports.createHarnessEntryPointResolver)(harnessConfig),
|
|
76
|
-
(0, exports.createJestGlobalsResolver)(),
|
|
77
|
-
(0, exports.createJsxRuntimeResolver)(),
|
|
78
|
-
(0, tsconfig_resolver_1.createTsConfigResolver)(process.cwd()),
|
|
79
|
-
userResolver,
|
|
80
|
-
].filter((resolver) => !!resolver);
|
|
81
|
-
return (0, composite_resolver_1.createHarnessResolver)(resolvers);
|
|
82
|
-
};
|
|
83
|
-
exports.getHarnessResolver = getHarnessResolver;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Resolution, CustomResolutionContext } from 'metro-resolver';
|
|
2
|
-
import type { HarnessResolver } from './types';
|
|
3
|
-
export type TsConfigPaths = {
|
|
4
|
-
paths: Record<string, string[]>;
|
|
5
|
-
baseUrl: string;
|
|
6
|
-
hasBaseUrl: boolean;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Load tsconfig.json or jsconfig.json and extract path mappings
|
|
10
|
-
*/
|
|
11
|
-
export declare const loadTsConfigPaths: (projectRoot: string) => TsConfigPaths | null;
|
|
12
|
-
/**
|
|
13
|
-
* Resolve module using tsconfig path mappings
|
|
14
|
-
* Use this directly in your custom resolver
|
|
15
|
-
*/
|
|
16
|
-
export declare const resolveWithTsConfigPaths: (tsConfig: TsConfigPaths, context: CustomResolutionContext, moduleName: string, platform: string | null) => Resolution | null;
|
|
17
|
-
export declare const createTsConfigResolver: (projectRoot: string) => HarnessResolver;
|
|
18
|
-
//# sourceMappingURL=tsconfig-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig-resolver.d.ts","sourceRoot":"","sources":["../../src/resolvers/tsconfig-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAO/C,MAAM,MAAM,aAAa,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACpB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC7B,aAAa,MAAM,KACjB,aAAa,GAAG,IA+BlB,CAAC;AAsFF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GACpC,UAAU,aAAa,EACvB,SAAS,uBAAuB,EAChC,YAAY,MAAM,EAClB,UAAU,MAAM,GAAG,IAAI,KACrB,UAAU,GAAG,IAqCf,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAClC,aAAa,MAAM,KACjB,eAqBF,CAAC"}
|