@vxrn/vite-plugin-metro 2.0.0-beta.99.1 → 2.6.0
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/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +40 -27
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.cjs +57 -42
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +57 -42
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/plugins/metroPlugin.cjs +1 -0
- package/dist/cjs/plugins/metroPlugin.native.cjs +5 -4
- package/dist/cjs/plugins/metroPlugin.native.js +5 -4
- package/dist/cjs/plugins/metroPlugin.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/buildBundle.native.cjs +1 -1
- package/dist/cjs/rn-commands/bundle/buildBundle.native.js +1 -1
- package/dist/cjs/rn-commands/bundle/buildBundle.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/saveAssets.native.cjs +2 -2
- package/dist/cjs/rn-commands/bundle/saveAssets.native.js +2 -2
- package/dist/cjs/rn-commands/bundle/saveAssets.native.js.map +1 -1
- package/dist/cjs/transformer/babel-transformer.cjs +7 -1
- package/dist/cjs/transformer/babel-transformer.native.cjs +9 -2
- package/dist/cjs/transformer/babel-transformer.native.js +9 -2
- package/dist/cjs/transformer/babel-transformer.native.js.map +1 -1
- package/dist/cjs/transformer/metroNativeWorker.cjs +6 -1
- package/dist/cjs/transformer/metroNativeWorker.native.cjs +9 -7
- package/dist/cjs/transformer/metroNativeWorker.native.js +9 -7
- package/dist/cjs/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/cjs/utils/exit.native.cjs +2 -2
- package/dist/cjs/utils/exit.native.js +2 -2
- package/dist/cjs/utils/exit.native.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +40 -27
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +57 -42
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/plugins/metroPlugin.mjs +1 -0
- package/dist/esm/plugins/metroPlugin.mjs.map +1 -1
- package/dist/esm/plugins/metroPlugin.native.js +5 -4
- package/dist/esm/plugins/metroPlugin.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/buildBundle.native.js +1 -1
- package/dist/esm/rn-commands/bundle/buildBundle.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/saveAssets.native.js +2 -2
- package/dist/esm/rn-commands/bundle/saveAssets.native.js.map +1 -1
- package/dist/esm/transformer/babel-transformer.mjs +7 -1
- package/dist/esm/transformer/babel-transformer.mjs.map +1 -1
- package/dist/esm/transformer/babel-transformer.native.js +9 -2
- package/dist/esm/transformer/babel-transformer.native.js.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.mjs +6 -1
- package/dist/esm/transformer/metroNativeWorker.mjs.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.native.js +9 -7
- package/dist/esm/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/esm/utils/exit.native.js +2 -2
- package/dist/esm/utils/exit.native.js.map +1 -1
- package/package.json +6 -5
- package/src/__tests__/getMetroConfigFromViteConfig.test.ts +269 -0
- package/src/metro-config/getMetroConfigFromViteConfig.ts +55 -18
- package/src/metro-config/glbAssets.test.ts +57 -0
- package/src/plugins/metroPlugin.ts +6 -1
- package/src/transformer/babel-transformer.ts +21 -1
- package/src/transformer/metroNativeWorker.test.ts +4 -18
- package/src/transformer/metroNativeWorker.ts +18 -2
- package/src/transformer/swiftPackageTransform.test.ts +111 -0
- package/types/metro-config/getMetroConfigFromViteConfig.d.ts.map +1 -1
- package/types/plugins/metroPlugin.d.ts.map +1 -1
- package/types/transformer/babel-transformer.d.ts.map +1 -1
- package/types/transformer/metroNativeWorker.d.ts.map +1 -1
- package/src/metro-config/getMetroConfigFromViteConfig.test.ts +0 -60
|
@@ -2,7 +2,7 @@ import { ChildProcess } from "child_process";
|
|
|
2
2
|
import process from "process";
|
|
3
3
|
import colors from "picocolors";
|
|
4
4
|
|
|
5
|
-
var debug = function() {
|
|
5
|
+
var debug = function debug2() {
|
|
6
6
|
for (var _len = arguments.length, _ = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7
7
|
_[_key] = arguments[_key];
|
|
8
8
|
}
|
|
@@ -209,7 +209,7 @@ function tryWarnActiveProcesses() {
|
|
|
209
209
|
function guardAsync(fn) {
|
|
210
210
|
var invoked = false;
|
|
211
211
|
var returnValue;
|
|
212
|
-
var guard = async function() {
|
|
212
|
+
var guard = async function guard2() {
|
|
213
213
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
214
214
|
args[_key] = arguments[_key];
|
|
215
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit.native.js","names":[],"sources":["esm/utils/exit.native.js"],"sourcesContent":["import { ChildProcess } from \"child_process\";\nimport process from \"process\";\nimport colors from \"picocolors\";\nvar debug = function() {\n for (var _len = arguments.length, _ = new Array(_len), _key = 0; _key < _len; _key++) {\n _[_key] = arguments[_key];\n }\n};\nvar PRE_EXIT_SIGNALS = [\n \"SIGHUP\",\n \"SIGINT\",\n \"SIGTERM\",\n \"SIGBREAK\"\n];\nvar queue = [];\nvar unsubscribe = null;\nfunction installExitHooks(asyncExitHook) {\n if (!queue.length) {\n unsubscribe = attachMasterListener();\n }\n queue.push(asyncExitHook);\n return function() {\n var index = queue.indexOf(asyncExitHook);\n if (index >= 0) {\n queue.splice(index, 1);\n }\n if (!queue.length) {\n unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();\n }\n };\n}\nfunction createExitHook(signal) {\n return guardAsync(async function() {\n var _process_exitCode;\n debug(`pre-exit (signal: ${signal}, queue length: ${queue.length})`);\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = Object.entries(queue)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var [index, hookAsync] = _step.value;\n try {\n await hookAsync(signal);\n } catch (error) {\n debug(`Error in exit hook: %O (queue: ${index})`, error);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n debug(`post-exit (code: ${(_process_exitCode = process.exitCode) !== null && _process_exitCode !== void 0 ? _process_exitCode : 0})`);\n process.exit();\n });\n}\nfunction attachMasterListener() {\n var hooks = [];\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = PRE_EXIT_SIGNALS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var signal = _step.value;\n var hook = createExitHook(signal);\n hooks.push([\n signal,\n hook\n ]);\n process.on(signal, hook);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n return function() {\n var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;\n try {\n for (var _iterator2 = hooks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {\n var [signal2, hook2] = _step2.value;\n process.removeListener(signal2, hook2);\n }\n } catch (err) {\n _didIteratorError2 = true;\n _iteratorError2 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion2 && _iterator2.return != null) {\n _iterator2.return();\n }\n } finally {\n if (_didIteratorError2) {\n throw _iteratorError2;\n }\n }\n }\n };\n}\nfunction ensureProcessExitsAfterDelay() {\n var waitUntilExitMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1e4, startedAtMs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Date.now();\n var expectedResources = [\n process.stdout.isTTY ? \"TTYWrap\" : \"PipeWrap\",\n process.stderr.isTTY ? \"TTYWrap\" : \"PipeWrap\",\n process.stdin.isTTY ? \"TTYWrap\" : \"PipeWrap\"\n ];\n var activeResources = process.getActiveResourcesInfo();\n var unexpectedActiveResources = activeResources.filter(function(activeResource) {\n var index = expectedResources.indexOf(activeResource);\n if (index >= 0) {\n expectedResources.splice(index, 1);\n return false;\n }\n return true;\n });\n var canExitProcess = !unexpectedActiveResources.length;\n if (canExitProcess) {\n return debug(\"no active resources detected, process can safely exit\");\n }\n debug(`process is trying to exit, but is stuck on unexpected active resources:`, unexpectedActiveResources);\n var elapsedTime = Date.now() - startedAtMs;\n var killedChildren = killActiveChildProcesses(elapsedTime < 200 ? \"SIGTERM\" : \"SIGKILL\");\n if (killedChildren > 0) {\n var recheck = setTimeout(function() {\n clearTimeout(recheck);\n ensureProcessExitsAfterDelay(waitUntilExitMs, startedAtMs);\n }, 50);\n return;\n }\n if (elapsedTime > waitUntilExitMs) {\n debug(\"active handles detected past the exit delay, forcefully exiting:\", activeResources);\n tryWarnActiveProcesses();\n return process.exit(0);\n }\n var timeoutId = setTimeout(function() {\n clearTimeout(timeoutId);\n ensureProcessExitsAfterDelay(waitUntilExitMs, startedAtMs);\n }, 100);\n}\nfunction killActiveChildProcesses(signal) {\n try {\n var children = process._getActiveHandles().filter(function(handle) {\n return handle instanceof ChildProcess;\n });\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var child = _step.value;\n try {\n child.kill(signal);\n } catch (err) {\n debug(\"failed to kill child process:\", err);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n return children.length;\n } catch (err) {\n debug(\"failed to enumerate active child processes:\", err);\n return 0;\n }\n}\nfunction tryWarnActiveProcesses() {\n var activeProcesses = [];\n try {\n var children = process._getActiveHandles().filter(function(handle) {\n return handle instanceof ChildProcess;\n });\n if (children.length) {\n activeProcesses = children.map(function(child) {\n return child.spawnargs.join(\" \");\n });\n }\n } catch (error) {\n debug(\"failed to get active process information:\", error);\n }\n if (!activeProcesses.length) {\n warn(\"Something prevented the command from exiting, forcefully exiting now.\");\n } else {\n var singularOrPlural = activeProcesses.length === 1 ? \"1 process\" : `${activeProcesses.length} processes`;\n warn(`Detected ${singularOrPlural} preventing process from exiting, forcefully exiting now.`);\n warn(\" - \" + activeProcesses.join(\"\\n - \"));\n }\n}\nfunction guardAsync(fn) {\n var invoked = false;\n var returnValue;\n var guard = async function() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n if (!invoked) {\n invoked = true;\n returnValue = await fn(...args);\n }\n return returnValue;\n };\n return guard;\n}\nfunction warn() {\n for (var _len = arguments.length, message = new Array(_len), _key = 0; _key < _len; _key++) {\n message[_key] = arguments[_key];\n }\n console.warn(...message.map(function(value) {\n return colors.yellow(value);\n }));\n}\nexport {\n ensureProcessExitsAfterDelay,\n guardAsync,\n installExitHooks,\n warn\n};\n//# sourceMappingURL=exit.js.map\n"],"mappings":";;;;;AAGA,IAAI,QAAQ,WAAW;CACrB,KAAK,IAAI,OAAO,UAAU,QAAQ,IAAI,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,OAAO,MAAM,QAAQ;EACpF,EAAE,QAAQ,UAAU;CACtB;AACF;AACA,IAAI,mBAAmB;CACrB;CACA;CACA;CACA;AACF;AACA,IAAI,QAAQ,CAAC;AACb,IAAI,cAAc;AAClB,SAAS,iBAAiB,eA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Q,UAAU;CAC5B;CACA,QAAQ,KAAK,GAAG,QAAQ,IAAI,SAAS,OAAO;EAC1C,OAAO,OAAO,OAAO,KAAK;CAC5B,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"exit.native.js","names":[],"sources":["esm/utils/exit.native.js"],"sourcesContent":["import { ChildProcess } from \"child_process\";\nimport process from \"process\";\nimport colors from \"picocolors\";\nvar debug = function debug2() {\n for (var _len = arguments.length, _ = new Array(_len), _key = 0; _key < _len; _key++) {\n _[_key] = arguments[_key];\n }\n};\nvar PRE_EXIT_SIGNALS = [\n \"SIGHUP\",\n \"SIGINT\",\n \"SIGTERM\",\n \"SIGBREAK\"\n];\nvar queue = [];\nvar unsubscribe = null;\nfunction installExitHooks(asyncExitHook) {\n if (!queue.length) {\n unsubscribe = attachMasterListener();\n }\n queue.push(asyncExitHook);\n return function() {\n var index = queue.indexOf(asyncExitHook);\n if (index >= 0) {\n queue.splice(index, 1);\n }\n if (!queue.length) {\n unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();\n }\n };\n}\nfunction createExitHook(signal) {\n return guardAsync(async function() {\n var _process_exitCode;\n debug(`pre-exit (signal: ${signal}, queue length: ${queue.length})`);\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = Object.entries(queue)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var [index, hookAsync] = _step.value;\n try {\n await hookAsync(signal);\n } catch (error) {\n debug(`Error in exit hook: %O (queue: ${index})`, error);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n debug(`post-exit (code: ${(_process_exitCode = process.exitCode) !== null && _process_exitCode !== void 0 ? _process_exitCode : 0})`);\n process.exit();\n });\n}\nfunction attachMasterListener() {\n var hooks = [];\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = PRE_EXIT_SIGNALS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var signal = _step.value;\n var hook = createExitHook(signal);\n hooks.push([\n signal,\n hook\n ]);\n process.on(signal, hook);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n return function() {\n var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;\n try {\n for (var _iterator2 = hooks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {\n var [signal2, hook2] = _step2.value;\n process.removeListener(signal2, hook2);\n }\n } catch (err) {\n _didIteratorError2 = true;\n _iteratorError2 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion2 && _iterator2.return != null) {\n _iterator2.return();\n }\n } finally {\n if (_didIteratorError2) {\n throw _iteratorError2;\n }\n }\n }\n };\n}\nfunction ensureProcessExitsAfterDelay() {\n var waitUntilExitMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1e4, startedAtMs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Date.now();\n var expectedResources = [\n process.stdout.isTTY ? \"TTYWrap\" : \"PipeWrap\",\n process.stderr.isTTY ? \"TTYWrap\" : \"PipeWrap\",\n process.stdin.isTTY ? \"TTYWrap\" : \"PipeWrap\"\n ];\n var activeResources = process.getActiveResourcesInfo();\n var unexpectedActiveResources = activeResources.filter(function(activeResource) {\n var index = expectedResources.indexOf(activeResource);\n if (index >= 0) {\n expectedResources.splice(index, 1);\n return false;\n }\n return true;\n });\n var canExitProcess = !unexpectedActiveResources.length;\n if (canExitProcess) {\n return debug(\"no active resources detected, process can safely exit\");\n }\n debug(`process is trying to exit, but is stuck on unexpected active resources:`, unexpectedActiveResources);\n var elapsedTime = Date.now() - startedAtMs;\n var killedChildren = killActiveChildProcesses(elapsedTime < 200 ? \"SIGTERM\" : \"SIGKILL\");\n if (killedChildren > 0) {\n var recheck = setTimeout(function() {\n clearTimeout(recheck);\n ensureProcessExitsAfterDelay(waitUntilExitMs, startedAtMs);\n }, 50);\n return;\n }\n if (elapsedTime > waitUntilExitMs) {\n debug(\"active handles detected past the exit delay, forcefully exiting:\", activeResources);\n tryWarnActiveProcesses();\n return process.exit(0);\n }\n var timeoutId = setTimeout(function() {\n clearTimeout(timeoutId);\n ensureProcessExitsAfterDelay(waitUntilExitMs, startedAtMs);\n }, 100);\n}\nfunction killActiveChildProcesses(signal) {\n try {\n var children = process._getActiveHandles().filter(function(handle) {\n return handle instanceof ChildProcess;\n });\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var child = _step.value;\n try {\n child.kill(signal);\n } catch (err) {\n debug(\"failed to kill child process:\", err);\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n return children.length;\n } catch (err) {\n debug(\"failed to enumerate active child processes:\", err);\n return 0;\n }\n}\nfunction tryWarnActiveProcesses() {\n var activeProcesses = [];\n try {\n var children = process._getActiveHandles().filter(function(handle) {\n return handle instanceof ChildProcess;\n });\n if (children.length) {\n activeProcesses = children.map(function(child) {\n return child.spawnargs.join(\" \");\n });\n }\n } catch (error) {\n debug(\"failed to get active process information:\", error);\n }\n if (!activeProcesses.length) {\n warn(\"Something prevented the command from exiting, forcefully exiting now.\");\n } else {\n var singularOrPlural = activeProcesses.length === 1 ? \"1 process\" : `${activeProcesses.length} processes`;\n warn(`Detected ${singularOrPlural} preventing process from exiting, forcefully exiting now.`);\n warn(\" - \" + activeProcesses.join(\"\\n - \"));\n }\n}\nfunction guardAsync(fn) {\n var invoked = false;\n var returnValue;\n var guard = async function guard2() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n if (!invoked) {\n invoked = true;\n returnValue = await fn(...args);\n }\n return returnValue;\n };\n return guard;\n}\nfunction warn() {\n for (var _len = arguments.length, message = new Array(_len), _key = 0; _key < _len; _key++) {\n message[_key] = arguments[_key];\n }\n console.warn(...message.map(function(value) {\n return colors.yellow(value);\n }));\n}\nexport {\n ensureProcessExitsAfterDelay,\n guardAsync,\n installExitHooks,\n warn\n};\n//# sourceMappingURL=exit.js.map\n"],"mappings":";;;;;AAGA,IAAI,QAAQ,SAAS,SAAS;CAC5B,KAAK,IAAI,OAAO,UAAU,QAAQ,IAAI,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,OAAO,MAAM,QAAQ;EACpF,EAAE,QAAQ,UAAU;CACtB;AACF;AACA,IAAI,mBAAmB;CACrB;CACA;CACA;CACA;AACF;AACA,IAAI,QAAQ,CAAC;AACb,IAAI,cAAc;AAClB,SAAS,iBAAiB,eAAe;CACvC,IAAI,CAAC,MAAM,QAAQ;EACjB,cAAc,qBAAqB;CACrC;CACA,MAAM,KAAK,aAAa;CACxB,OAAO,WAAW;EAChB,IAAI,QAAQ,MAAM,QAAQ,aAAa;EACvC,IAAI,SAAS,GAAG;GACd,MAAM,OAAO,OAAO,CAAC;EACvB;EACA,IAAI,CAAC,MAAM,QAAQ;GACjB,gBAAgB,QAAQ,gBAAgB,KAAK,IAAI,KAAK,IAAI,YAAY;EACxE;CACF;AACF;AACA,SAAS,eAAe,QAAQ;CAC9B,OAAO,WAAW,iBAAiB;EACjC,IAAI;EACJ,MAAM,qBAAqB,OAAO,kBAAkB,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QAAQ;GACnB,kBAAkB,SAAS,IAAI,SAAS,OAAO;IAC7C,OAAO,MAAM,UAAU,KAAK,GAAG;GACjC,CAAC;EACH;CACF,SAAS,OAAO;EACd,MAAM,6CAA6C,KAAK;CAC1D;CACA,IAAI,CAAC,gBAAgB,QAAQ;EAC3B,KAAK,uEAAuE;CAC9E,OAAO;EACL,IAAI,mBAAmB,gBAAgB,WAAW,IAAI,cAAc,GAAG,gBAAgB,OAAO;EAC9F,KAAK,YAAY,iBAAiB,0DAA0D;EAC5F,KAAK,SAAS,gBAAgB,KAAK,QAAQ,CAAC;CAC9C;AACF;AACA,SAAS,WAAW,IAAI;CACtB,IAAI,UAAU;CACd,IAAI;CACJ,IAAI,QAAQ,eAAe,SAAS;EAClC,KAAK,IAAI,OAAO,UAAU,QAAQ,OAAO,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,OAAO,MAAM,QAAQ;GACvF,KAAK,QAAQ,UAAU;EACzB;EACA,IAAI,CAAC,SAAS;GACZ,UAAU;GACV,cAAc,MAAM,GAAG,GAAG,IAAI;EAChC;EACA,OAAO;CACT;CACA,OAAO;AACT;AACA,SAAS,OAAO;CACd,KAAK,IAAI,OAAO,UAAU,QAAQ,UAAU,IAAI,MAAM,IAAI,GAAG,OAAO,GAAG,OAAO,MAAM,QAAQ;EAC1F,QAAQ,QAAQ,UAAU;CAC5B;CACA,QAAQ,KAAK,GAAG,QAAQ,IAAI,SAAS,OAAO;EAC1C,OAAO,OAAO,OAAO,KAAK;CAC5B,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/vite-plugin-metro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
"@oxc-project/runtime": "^0.112.0",
|
|
75
75
|
"@react-native/babel-preset": "^0.87.1",
|
|
76
76
|
"@react-native/metro-config": "^0.87.1",
|
|
77
|
-
"@vxrn/compiler": "2.
|
|
78
|
-
"@vxrn/debug": "2.
|
|
79
|
-
"@vxrn/utils": "2.
|
|
77
|
+
"@vxrn/compiler": "2.6.0",
|
|
78
|
+
"@vxrn/debug": "2.6.0",
|
|
79
|
+
"@vxrn/utils": "2.6.0",
|
|
80
80
|
"esbuild": "^0.25.12",
|
|
81
81
|
"flow-parser": "^0.331.0",
|
|
82
82
|
"launch-editor": "^2.10.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@biomejs/biome": "2.3.3",
|
|
91
91
|
"@react-native/dev-middleware": "^0.87.1",
|
|
92
|
-
"@tamagui/build": "3.0.
|
|
92
|
+
"@tamagui/build": "3.0.3",
|
|
93
93
|
"@types/babel__helper-plugin-utils": "^7",
|
|
94
94
|
"@types/node": "^24.10.0",
|
|
95
95
|
"depcheck": "^1.4.7",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"access": "public"
|
|
104
104
|
},
|
|
105
|
+
"releaseSourceCommit": "9822993504bd9422425d1d6ee9bfbe96f84c909c",
|
|
105
106
|
"repository": {
|
|
106
107
|
"type": "git",
|
|
107
108
|
"url": "git+https://github.com/onejs/one.git",
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { runInNewContext } from 'node:vm'
|
|
5
|
+
import { resolveConfig } from 'vite'
|
|
6
|
+
import type { ResolverConfigT } from 'metro-config'
|
|
7
|
+
import type { MetroPluginOptions } from '../plugins/metroPlugin'
|
|
8
|
+
import { afterAll, describe, expect, it } from 'vitest'
|
|
9
|
+
import { dedupe } from '../../../vxrn/src/config/getBaseViteConfigOnly'
|
|
10
|
+
import {
|
|
11
|
+
buildMetroConfigInputFromViteConfig,
|
|
12
|
+
getMetroConfigFromViteConfig,
|
|
13
|
+
} from '../metro-config/getMetroConfigFromViteConfig'
|
|
14
|
+
|
|
15
|
+
const tmpDirs: string[] = []
|
|
16
|
+
|
|
17
|
+
describe('vite package dedupe through real metro bundles', () => {
|
|
18
|
+
it.each([
|
|
19
|
+
['input', 'android'],
|
|
20
|
+
['input', 'ios'],
|
|
21
|
+
['full', 'android'],
|
|
22
|
+
['full', 'ios'],
|
|
23
|
+
])(
|
|
24
|
+
'keeps one registration and native resolution for %s/%s',
|
|
25
|
+
async (mode, platform) => {
|
|
26
|
+
const workspaceRoot = path.resolve(__dirname, '../../../../')
|
|
27
|
+
const scratch = path.join(workspaceRoot, 'scripts/tmp')
|
|
28
|
+
fs.mkdirSync(scratch, { recursive: true })
|
|
29
|
+
const fixtureRoot = fs.mkdtempSync(path.join(scratch, 'metro-dedupe-'))
|
|
30
|
+
tmpDirs.push(fixtureRoot)
|
|
31
|
+
fs.writeFileSync(path.join(fixtureRoot, 'package.json'), '{"private":true}')
|
|
32
|
+
const writePackage = (directory: string, name: string, source: string) => {
|
|
33
|
+
fs.mkdirSync(directory, { recursive: true })
|
|
34
|
+
fs.writeFileSync(
|
|
35
|
+
path.join(directory, 'package.json'),
|
|
36
|
+
JSON.stringify({ name, version: '1.0.0', main: 'index.js' })
|
|
37
|
+
)
|
|
38
|
+
fs.writeFileSync(path.join(directory, 'index.js'), source)
|
|
39
|
+
}
|
|
40
|
+
const registry = (name: string) => `
|
|
41
|
+
globalThis.registrations = (globalThis.registrations || 0) + 1;
|
|
42
|
+
if (globalThis.registrations > 1) throw new Error('duplicate native view');
|
|
43
|
+
module.exports = ${JSON.stringify(name)};
|
|
44
|
+
`
|
|
45
|
+
const rootRegistry = path.join(fixtureRoot, 'node_modules/@fixture/registry')
|
|
46
|
+
writePackage(rootRegistry, '@fixture/registry', registry('root'))
|
|
47
|
+
fs.writeFileSync(
|
|
48
|
+
path.join(rootRegistry, 'package.json'),
|
|
49
|
+
JSON.stringify({
|
|
50
|
+
name: '@fixture/registry',
|
|
51
|
+
version: '1.0.0',
|
|
52
|
+
exports: {
|
|
53
|
+
'.': { 'react-native': './index.js', default: './wrong.js' },
|
|
54
|
+
'./platform': './platform.js',
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
fs.writeFileSync(
|
|
59
|
+
path.join(rootRegistry, 'wrong.js'),
|
|
60
|
+
"throw new Error('native export condition lost');"
|
|
61
|
+
)
|
|
62
|
+
fs.writeFileSync(
|
|
63
|
+
path.join(rootRegistry, 'platform.js'),
|
|
64
|
+
"module.exports='export-subpath';"
|
|
65
|
+
)
|
|
66
|
+
const nativePackage = path.join(fixtureRoot, 'node_modules/@fixture/native')
|
|
67
|
+
writePackage(nativePackage, '@fixture/native', "module.exports='wrong';")
|
|
68
|
+
fs.writeFileSync(path.join(nativePackage, 'platform.js'), "module.exports='wrong';")
|
|
69
|
+
for (const target of ['ios', 'android']) {
|
|
70
|
+
fs.writeFileSync(
|
|
71
|
+
path.join(nativePackage, `platform.${target}.js`),
|
|
72
|
+
`module.exports=${JSON.stringify(target)};`
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
writePackage(
|
|
76
|
+
path.join(fixtureRoot, 'node_modules/@fixture/registry-extra'),
|
|
77
|
+
'@fixture/registry-extra',
|
|
78
|
+
"module.exports='wrong-root';"
|
|
79
|
+
)
|
|
80
|
+
writePackage(
|
|
81
|
+
path.join(fixtureRoot, 'node_modules/plain'),
|
|
82
|
+
'plain',
|
|
83
|
+
"module.exports='root';"
|
|
84
|
+
)
|
|
85
|
+
for (const name of ['first', 'second']) {
|
|
86
|
+
const directory = path.join(fixtureRoot, `node_modules/@fixture/${name}`)
|
|
87
|
+
writePackage(
|
|
88
|
+
directory,
|
|
89
|
+
`@fixture/${name}`,
|
|
90
|
+
`module.exports=[
|
|
91
|
+
require('@fixture/registry'), require('@fixture/registry/platform'), require('@fixture/native/platform'),
|
|
92
|
+
require('@fixture/registry-extra'), require('plain'), require('./local'), require('@fixture/alias'), require('escape-string-regexp')];`
|
|
93
|
+
)
|
|
94
|
+
writePackage(
|
|
95
|
+
path.join(directory, 'node_modules/escape-string-regexp'),
|
|
96
|
+
'escape-string-regexp',
|
|
97
|
+
`module.exports=${JSON.stringify(name + '-utility')};`
|
|
98
|
+
)
|
|
99
|
+
fs.writeFileSync(
|
|
100
|
+
path.join(directory, 'local.js'),
|
|
101
|
+
`module.exports=${JSON.stringify(name)};`
|
|
102
|
+
)
|
|
103
|
+
writePackage(
|
|
104
|
+
path.join(directory, 'node_modules/@fixture/native'),
|
|
105
|
+
'@fixture/native',
|
|
106
|
+
`module.exports=${JSON.stringify(name)};`
|
|
107
|
+
)
|
|
108
|
+
writePackage(
|
|
109
|
+
path.join(directory, 'node_modules/@fixture/registry'),
|
|
110
|
+
'@fixture/registry',
|
|
111
|
+
registry(name)
|
|
112
|
+
)
|
|
113
|
+
writePackage(
|
|
114
|
+
path.join(directory, 'node_modules/@fixture/registry-extra'),
|
|
115
|
+
'@fixture/registry-extra',
|
|
116
|
+
`module.exports=${JSON.stringify(name)};`
|
|
117
|
+
)
|
|
118
|
+
writePackage(
|
|
119
|
+
path.join(directory, 'node_modules/plain'),
|
|
120
|
+
'plain',
|
|
121
|
+
`module.exports=${JSON.stringify(name)};`
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
const alias = path.join(fixtureRoot, 'alias.js')
|
|
125
|
+
fs.writeFileSync(alias, "module.exports='custom';")
|
|
126
|
+
const resolver: Partial<ResolverConfigT> = {
|
|
127
|
+
resolveRequest: (context, name, target) =>
|
|
128
|
+
name === '@fixture/alias'
|
|
129
|
+
? { type: 'sourceFile', filePath: alias }
|
|
130
|
+
: context.resolveRequest(context, name, target),
|
|
131
|
+
}
|
|
132
|
+
const viteConfig = await resolveConfig(
|
|
133
|
+
{
|
|
134
|
+
root: workspaceRoot,
|
|
135
|
+
configFile: false,
|
|
136
|
+
resolve: { dedupe: [...dedupe, '@fixture/registry', '@fixture/native', 'plain'] },
|
|
137
|
+
},
|
|
138
|
+
'build'
|
|
139
|
+
)
|
|
140
|
+
const options = {
|
|
141
|
+
watchman: false,
|
|
142
|
+
argv: { projectRoot: fixtureRoot },
|
|
143
|
+
defaultConfigOverrides: (config) => ({
|
|
144
|
+
resolver: { ...config?.resolver, ...resolver },
|
|
145
|
+
}),
|
|
146
|
+
} satisfies MetroPluginOptions
|
|
147
|
+
const config =
|
|
148
|
+
mode === 'input'
|
|
149
|
+
? (await buildMetroConfigInputFromViteConfig(viteConfig, options)).defaultConfig
|
|
150
|
+
: await getMetroConfigFromViteConfig(viteConfig, options)
|
|
151
|
+
const entry = path.join(fixtureRoot, 'entry.js')
|
|
152
|
+
fs.writeFileSync(
|
|
153
|
+
entry,
|
|
154
|
+
"globalThis.values=[require('@fixture/first'),require('@fixture/second')];"
|
|
155
|
+
)
|
|
156
|
+
const require = createRequire(path.join(workspaceRoot, 'package.json'))
|
|
157
|
+
const Server = require('metro/private/Server').default
|
|
158
|
+
const output = require('metro/private/shared/output/bundle')
|
|
159
|
+
const server = new Server({ ...config, maxWorkers: 1 })
|
|
160
|
+
try {
|
|
161
|
+
const bundle = await output.build(server, {
|
|
162
|
+
entryFile: entry,
|
|
163
|
+
platform,
|
|
164
|
+
dev: false,
|
|
165
|
+
minify: false,
|
|
166
|
+
})
|
|
167
|
+
const observed = { registrations: 0, values: [] }
|
|
168
|
+
runInNewContext(bundle.code, observed)
|
|
169
|
+
expect(observed.registrations).toBe(1)
|
|
170
|
+
expect(observed.values).toEqual([
|
|
171
|
+
['root', 'export-subpath', platform, 'first', 'root', 'first', 'custom', 'first-utility'],
|
|
172
|
+
['root', 'export-subpath', platform, 'second', 'root', 'second', 'custom', 'second-utility'],
|
|
173
|
+
])
|
|
174
|
+
} finally {
|
|
175
|
+
await server.end()
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
180_000
|
|
179
|
+
)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
afterAll(() => {
|
|
183
|
+
for (const tmpDir of tmpDirs) {
|
|
184
|
+
fs.rmSync(tmpDir, { recursive: true, force: true })
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
describe('bare main module entry', () => {
|
|
189
|
+
it('survives a resolver-replacing defaultConfigOverrides', async () => {
|
|
190
|
+
const workspaceRoot = path.resolve(__dirname, '../../../../')
|
|
191
|
+
const fixtureRoot = fs.mkdtempSync(path.join(workspaceRoot, '.tmp-metro-entry-'))
|
|
192
|
+
tmpDirs.push(fixtureRoot)
|
|
193
|
+
fs.writeFileSync(
|
|
194
|
+
path.join(fixtureRoot, 'package.json'),
|
|
195
|
+
JSON.stringify({ name: 'tmp-metro-entry', private: true })
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
const seen: string[] = []
|
|
199
|
+
const { defaultConfig } = await buildMetroConfigInputFromViteConfig(
|
|
200
|
+
{ root: fixtureRoot } as any,
|
|
201
|
+
{
|
|
202
|
+
mainModuleName: 'one/metro-entry',
|
|
203
|
+
watchman: false,
|
|
204
|
+
defaultConfigOverrides: {
|
|
205
|
+
resolver: {
|
|
206
|
+
sourceExts: ['js'],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
} as any
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
expect((defaultConfig as any).watchFolders).toContain(workspaceRoot)
|
|
213
|
+
expect((defaultConfig as any).resolver.nodeModulesPaths).toContain(
|
|
214
|
+
path.join(workspaceRoot, 'node_modules')
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
const context = {
|
|
218
|
+
originModulePath: `${fixtureRoot}/.`,
|
|
219
|
+
resolveRequest: (_ctx: any, name: string) => {
|
|
220
|
+
seen.push(name)
|
|
221
|
+
return { type: 'sourceFile', filePath: name }
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
await (defaultConfig as any).resolver.resolveRequest(
|
|
225
|
+
context,
|
|
226
|
+
'./one/metro-entry',
|
|
227
|
+
'ios'
|
|
228
|
+
)
|
|
229
|
+
expect(seen).toEqual(['one/metro-entry'])
|
|
230
|
+
|
|
231
|
+
await (defaultConfig as any).resolver.resolveRequest(context, 'react-native', 'ios')
|
|
232
|
+
expect(seen).toEqual(['one/metro-entry', 'react-native'])
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
describe('watch exclusions', () => {
|
|
237
|
+
it("block the app's build output but not a dependency's dist/server", async () => {
|
|
238
|
+
const workspaceRoot = path.resolve(__dirname, '../../../../')
|
|
239
|
+
const fixtureRoot = fs.mkdtempSync(path.join(workspaceRoot, '.tmp-metro-block-'))
|
|
240
|
+
tmpDirs.push(fixtureRoot)
|
|
241
|
+
fs.writeFileSync(
|
|
242
|
+
path.join(fixtureRoot, 'package.json'),
|
|
243
|
+
JSON.stringify({ name: 'tmp-metro-block', private: true })
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
const { defaultConfig } = await buildMetroConfigInputFromViteConfig(
|
|
247
|
+
{ root: fixtureRoot } as any,
|
|
248
|
+
{ watchman: false } as any
|
|
249
|
+
)
|
|
250
|
+
const blockList: RegExp[] = (defaultConfig as any).resolver.blockList
|
|
251
|
+
const blocked = (file: string) => blockList.some((pattern) => pattern.test(file))
|
|
252
|
+
|
|
253
|
+
expect(blocked(path.join(fixtureRoot, 'dist', 'server', 'entry.js'))).toBe(true)
|
|
254
|
+
expect(blocked(path.join(fixtureRoot, 'dist', 'static', 'index.html'))).toBe(true)
|
|
255
|
+
expect(
|
|
256
|
+
blocked(
|
|
257
|
+
path.join(
|
|
258
|
+
fixtureRoot,
|
|
259
|
+
'node_modules',
|
|
260
|
+
'@o',
|
|
261
|
+
'helpers',
|
|
262
|
+
'dist',
|
|
263
|
+
'server',
|
|
264
|
+
'ensureEnv.js'
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
).toBe(false)
|
|
268
|
+
})
|
|
269
|
+
})
|
|
@@ -18,6 +18,8 @@ type MetroInputConfig = NonNullable<Parameters<typeof loadConfigT>[1]>
|
|
|
18
18
|
|
|
19
19
|
const WATCHMAN_PROBE_TIMEOUT_MS = 2000
|
|
20
20
|
const expoEnvAdditionalExts = ['env', 'local', 'development']
|
|
21
|
+
// keep js before mjs so platform-aware .native.js wins for one dist.
|
|
22
|
+
const metroSourceExts = ['js', 'jsx', 'json', 'ts', 'tsx', 'mjs', 'cjs', 'swift', 'kt']
|
|
21
23
|
const watchmanResponsivePromises = new Map<string, Promise<boolean>>()
|
|
22
24
|
let didWarnAboutWatchmanFallback = false
|
|
23
25
|
const rootIndexBundleRequestPattern = /^(https?:\/\/[^/]+)?\/index\.bundle(?=$|[?#])/
|
|
@@ -30,9 +32,11 @@ const rootIndexBundleRequestPattern = /^(https?:\/\/[^/]+)?\/index\.bundle(?=$|[
|
|
|
30
32
|
const expoVirtualEntryBundleRequestPattern =
|
|
31
33
|
/^(https?:\/\/[^/]+)?\/\.expo\/\.virtual-metro-entry\.bundle(?=$|[?#])/
|
|
32
34
|
// keep app build output and volatile caches out of Metro's fallback watcher.
|
|
33
|
-
// package dist directories remain visible because Metro resolves modules from
|
|
35
|
+
// package dist directories remain visible because Metro resolves modules from
|
|
36
|
+
// them, including a dependency's own dist/server, so the app build output
|
|
37
|
+
// pattern never matches inside node_modules.
|
|
34
38
|
const metroWatchExclusions = [
|
|
35
|
-
|
|
39
|
+
/^(?!.*[/\\]node_modules[/\\]).*[/\\]dist[/\\](?:static|server)(?:[/\\]|$)/,
|
|
36
40
|
/[/\\]tests[/\\][^/\\]+[/\\]dist(?:[/\\]|$)/,
|
|
37
41
|
/[/\\]\.docker(?:[/\\]|$)/,
|
|
38
42
|
/[/\\]\.vite(?:[/\\]|$)/,
|
|
@@ -63,10 +67,17 @@ function enforceWorkspaceVisibility(
|
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
function getReactNativeDefaultConfig(projectRoot: string): MetroInputConfig {
|
|
66
|
-
|
|
70
|
+
const config = enforceWorkspaceVisibility(
|
|
67
71
|
getDefaultConfig(projectRoot) as MetroInputConfig,
|
|
68
72
|
projectRoot
|
|
69
73
|
)
|
|
74
|
+
return {
|
|
75
|
+
...config,
|
|
76
|
+
resolver: {
|
|
77
|
+
...config.resolver,
|
|
78
|
+
assetExts: [...new Set([...(config.resolver?.assetExts ?? []), 'glb'])],
|
|
79
|
+
},
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
function getPlatformFromBundleUrl(url: string): 'ios' | 'android' {
|
|
@@ -83,7 +94,10 @@ function rewriteMainModuleBundleUrl(
|
|
|
83
94
|
})
|
|
84
95
|
|
|
85
96
|
if (rootIndexBundleRequestPattern.test(url)) {
|
|
86
|
-
return url.replace(
|
|
97
|
+
return url.replace(
|
|
98
|
+
rootIndexBundleRequestPattern,
|
|
99
|
+
`$1/${resolvedMainModulePath}.bundle`
|
|
100
|
+
)
|
|
87
101
|
}
|
|
88
102
|
return url.replace(
|
|
89
103
|
expoVirtualEntryBundleRequestPattern,
|
|
@@ -114,19 +128,38 @@ function bareMainModuleForRequest(
|
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
// defaultConfigOverrides and Metro config loading can replace the resolver.
|
|
117
|
-
// enforce
|
|
118
|
-
//
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
// enforce entry and vite dedupe semantics on the final resolver while
|
|
132
|
+
// preserving its platform, export conditions and custom resolution policy.
|
|
133
|
+
function enforcePackageResolution(
|
|
134
|
+
config: MetroInputConfig,
|
|
135
|
+
mainModuleName: string | undefined,
|
|
136
|
+
dedupe: readonly string[],
|
|
137
|
+
projectRoot: string
|
|
138
|
+
): MetroInputConfig {
|
|
139
|
+
const dedupedPackages = new Set(dedupe)
|
|
140
|
+
if ((!mainModuleName || !isBareSpecifier(mainModuleName)) && !dedupedPackages.size) {
|
|
141
|
+
return config
|
|
142
|
+
}
|
|
143
|
+
const rootOrigin = resolve(projectRoot, 'package.json')
|
|
144
|
+
const innerResolveRequest = config.resolver?.resolveRequest
|
|
122
145
|
return {
|
|
123
146
|
...config,
|
|
124
147
|
resolver: {
|
|
125
|
-
...config
|
|
126
|
-
resolveRequest: (context
|
|
148
|
+
...config.resolver,
|
|
149
|
+
resolveRequest: (context, moduleName, platform) => {
|
|
127
150
|
const bareMain = bareMainModuleForRequest(moduleName, mainModuleName)
|
|
151
|
+
const request = bareMain ?? moduleName
|
|
152
|
+
const packageEnd = request.indexOf(
|
|
153
|
+
'/',
|
|
154
|
+
request.startsWith('@') ? request.indexOf('/') + 1 : 0
|
|
155
|
+
)
|
|
156
|
+
const packageName = packageEnd === -1 ? request : request.slice(0, packageEnd)
|
|
157
|
+
const resolutionContext =
|
|
158
|
+
isBareSpecifier(request) && dedupedPackages.has(packageName)
|
|
159
|
+
? { ...context, originModulePath: rootOrigin }
|
|
160
|
+
: context
|
|
128
161
|
const resolveRequest = innerResolveRequest || context.resolveRequest
|
|
129
|
-
return resolveRequest(
|
|
162
|
+
return resolveRequest(resolutionContext, request, platform)
|
|
130
163
|
},
|
|
131
164
|
},
|
|
132
165
|
}
|
|
@@ -293,7 +326,7 @@ export async function buildMetroConfigInputFromViteConfig(
|
|
|
293
326
|
..._defaultConfig?.resolver,
|
|
294
327
|
useWatchman,
|
|
295
328
|
blockList,
|
|
296
|
-
sourceExts:
|
|
329
|
+
sourceExts: metroSourceExts,
|
|
297
330
|
resolveRequest: (context, moduleName, platform) => {
|
|
298
331
|
const origResolveRequestFn =
|
|
299
332
|
_defaultConfig?.resolver?.resolveRequest || context.resolveRequest
|
|
@@ -348,9 +381,11 @@ export async function buildMetroConfigInputFromViteConfig(
|
|
|
348
381
|
}
|
|
349
382
|
|
|
350
383
|
return {
|
|
351
|
-
defaultConfig:
|
|
384
|
+
defaultConfig: enforcePackageResolution(
|
|
352
385
|
enforceWorkspaceVisibility(merged, projectRoot),
|
|
353
|
-
mainModuleName
|
|
386
|
+
mainModuleName,
|
|
387
|
+
config.resolve?.dedupe ?? [],
|
|
388
|
+
projectRoot
|
|
354
389
|
),
|
|
355
390
|
projectRoot,
|
|
356
391
|
extraConfig,
|
|
@@ -438,7 +473,7 @@ export async function getMetroConfigFromViteConfig(
|
|
|
438
473
|
..._defaultConfig?.resolver,
|
|
439
474
|
useWatchman,
|
|
440
475
|
blockList,
|
|
441
|
-
sourceExts:
|
|
476
|
+
sourceExts: metroSourceExts,
|
|
442
477
|
resolveRequest: (context, moduleName, platform) => {
|
|
443
478
|
const origResolveRequestFn =
|
|
444
479
|
_defaultConfig?.resolver?.resolveRequest || context.resolveRequest
|
|
@@ -509,9 +544,11 @@ export async function getMetroConfigFromViteConfig(
|
|
|
509
544
|
)
|
|
510
545
|
|
|
511
546
|
return {
|
|
512
|
-
...
|
|
547
|
+
...enforcePackageResolution(
|
|
513
548
|
enforceWorkspaceVisibility(metroConfig, projectRoot),
|
|
514
|
-
mainModuleName
|
|
549
|
+
mainModuleName,
|
|
550
|
+
config.resolve?.dedupe ?? [],
|
|
551
|
+
projectRoot
|
|
515
552
|
),
|
|
516
553
|
...extraConfig,
|
|
517
554
|
} as MetroConfigExtended
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { runInNewContext } from 'node:vm'
|
|
4
|
+
import type { ResolvedConfig } from 'vite'
|
|
5
|
+
import { expect, it } from 'vitest'
|
|
6
|
+
import { buildMetroConfigInputFromViteConfig } from './getMetroConfigFromViteConfig'
|
|
7
|
+
import { transform } from '../transformer/metroNativeWorker'
|
|
8
|
+
|
|
9
|
+
it('classifies a binary GLB with stock Metro config and registers its identity', async () => {
|
|
10
|
+
const root = await mkdtemp(join(import.meta.dirname, '.glb-metro-'))
|
|
11
|
+
const bytes = Buffer.from([0x67, 0x6c, 0x54, 0x46, 2, 0, 0, 0, 0xff, 0x80, 0, 1])
|
|
12
|
+
await writeFile(join(root, 'sofa.glb'), bytes)
|
|
13
|
+
try {
|
|
14
|
+
const { defaultConfig } = await buildMetroConfigInputFromViteConfig(
|
|
15
|
+
{ root } as ResolvedConfig,
|
|
16
|
+
{ watchman: false }
|
|
17
|
+
)
|
|
18
|
+
const type = defaultConfig.resolver.assetExts.includes('glb') ? 'asset' : 'module'
|
|
19
|
+
const result = await transform(
|
|
20
|
+
{ assetRegistryPath: 'react-native/asset-registry', publicPath: '/assets' },
|
|
21
|
+
root,
|
|
22
|
+
'sofa.glb',
|
|
23
|
+
bytes,
|
|
24
|
+
{ dev: true, platform: 'ios', type }
|
|
25
|
+
)
|
|
26
|
+
expect(result.output[0].type).toBe('js/module/asset')
|
|
27
|
+
let descriptor: any
|
|
28
|
+
runInNewContext(result.output[0].data.code, {
|
|
29
|
+
__d: (factory: Function) =>
|
|
30
|
+
factory(
|
|
31
|
+
{},
|
|
32
|
+
() => ({
|
|
33
|
+
registerAsset: (asset: any) => {
|
|
34
|
+
descriptor = asset
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
{},
|
|
38
|
+
{},
|
|
39
|
+
{ exports: {} },
|
|
40
|
+
{},
|
|
41
|
+
[0]
|
|
42
|
+
),
|
|
43
|
+
})
|
|
44
|
+
expect(descriptor).toMatchObject({
|
|
45
|
+
name: 'sofa',
|
|
46
|
+
type: 'glb',
|
|
47
|
+
scales: [1],
|
|
48
|
+
httpServerLocation: '/assets',
|
|
49
|
+
})
|
|
50
|
+
expect(descriptor.hash).not.toBe('')
|
|
51
|
+
expect(descriptor.width).toBeUndefined()
|
|
52
|
+
expect(descriptor.height).toBeUndefined()
|
|
53
|
+
expect(await readFile(join(root, 'sofa.glb'))).toEqual(bytes)
|
|
54
|
+
} finally {
|
|
55
|
+
await rm(root, { recursive: true, force: true })
|
|
56
|
+
}
|
|
57
|
+
})
|
|
@@ -228,7 +228,7 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
228
228
|
// metro parity: the packager message socket (metro serves /message via
|
|
229
229
|
// @react-native-community/cli-server-api). leaving the upgrade unanswered
|
|
230
230
|
// dangles the socket and chromium queues every later websocket handshake
|
|
231
|
-
// to the same host:port behind it (blocking e.g. zero /sync in
|
|
231
|
+
// to the same host:port behind it (blocking e.g. zero /sync in peach).
|
|
232
232
|
'/message': createMessageSocket(),
|
|
233
233
|
...devMiddleware.websocketEndpoints,
|
|
234
234
|
}
|
|
@@ -338,6 +338,11 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
338
338
|
// See: https://github.com/facebook/react-native/blob/v0.80.0-rc.4/packages/react-native/React/Base/RCTBundleURLProvider.mm#L87-L113
|
|
339
339
|
if (req.url === '/status' && isNativeRequest) {
|
|
340
340
|
res.statusCode = 200
|
|
341
|
+
// the header react native's statusPageMiddleware sends
|
|
342
|
+
res.setHeader(
|
|
343
|
+
'X-React-Native-Project-Root',
|
|
344
|
+
new URL(`file:///${projectRoot}`).pathname.slice(1)
|
|
345
|
+
)
|
|
341
346
|
res.end('packager-status:running')
|
|
342
347
|
return
|
|
343
348
|
}
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
import assert from 'node:assert'
|
|
18
18
|
import { createHash } from 'node:crypto'
|
|
19
19
|
import { readFileSync } from 'node:fs'
|
|
20
|
+
import { createRequire } from 'node:module'
|
|
20
21
|
import path from 'node:path'
|
|
21
22
|
|
|
22
23
|
import type { TransformOptions } from './babel-core'
|
|
@@ -158,6 +159,25 @@ const transform: BabelTransformer['transform'] = ({
|
|
|
158
159
|
// `plugins` is used for `functionMapBabelPlugin` from `metro-source-map`.
|
|
159
160
|
plugins,
|
|
160
161
|
}: BabelTransformerArgs): ReturnType<BabelTransformer['transform']> => {
|
|
162
|
+
if (/\.(swift|kt)$/.test(filename)) {
|
|
163
|
+
const requireFromProject = createRequire(
|
|
164
|
+
path.resolve(options.projectRoot, 'package.json')
|
|
165
|
+
)
|
|
166
|
+
const oneTransforms = requireFromProject(
|
|
167
|
+
'one/native-transforms'
|
|
168
|
+
) as typeof import('one/native-transforms') & {
|
|
169
|
+
renderNativeSourceModule: (
|
|
170
|
+
id: string,
|
|
171
|
+
platform: string,
|
|
172
|
+
root: string
|
|
173
|
+
) => { code: string; watchFiles: string[] }
|
|
174
|
+
}
|
|
175
|
+
originalSrc = oneTransforms.renderNativeSourceModule(
|
|
176
|
+
path.isAbsolute(filename) ? filename : path.resolve(options.projectRoot, filename),
|
|
177
|
+
options.platform ?? '',
|
|
178
|
+
options.projectRoot
|
|
179
|
+
).code
|
|
180
|
+
}
|
|
161
181
|
// narrow optional Expo compatibility (expo/virtual/env.js and .env files
|
|
162
182
|
// only), shared with the native worker. no-Expo apps pass through byte
|
|
163
183
|
// for byte without resolving any Expo module.
|
|
@@ -258,7 +278,7 @@ const transform: BabelTransformer['transform'] = ({
|
|
|
258
278
|
|
|
259
279
|
export function getCacheKey(options?: BabelTransformerCacheKeyOptions): string {
|
|
260
280
|
const hash = createHash('sha256')
|
|
261
|
-
hash.update('vxrn-metro-babel-transformer-
|
|
281
|
+
hash.update('vxrn-metro-babel-transformer-v2')
|
|
262
282
|
|
|
263
283
|
const projectRoot = options?.projectRoot
|
|
264
284
|
if (!projectRoot) {
|