@use-voltra/metro 2.1.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/LICENSE.txt +21 -0
- package/README.md +86 -0
- package/build/cjs/bin/bundle-widgets.js +13 -0
- package/build/cjs/bin/bundle-widgets.js.map +1 -0
- package/build/cjs/bundleWidgets.js +87 -0
- package/build/cjs/bundleWidgets.js.map +1 -0
- package/build/cjs/createErrorOnlyMetroReporter.js +26 -0
- package/build/cjs/createErrorOnlyMetroReporter.js.map +1 -0
- package/build/cjs/createVoltraMiddleware.js +81 -0
- package/build/cjs/createVoltraMiddleware.js.map +1 -0
- package/build/cjs/createWidgetMetroConfig.js +74 -0
- package/build/cjs/createWidgetMetroConfig.js.map +1 -0
- package/build/cjs/index.js +110 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/resolveProjectModule.js +45 -0
- package/build/cjs/resolveProjectModule.js.map +1 -0
- package/build/cjs/scanner.js +6 -0
- package/build/cjs/scanner.js.map +1 -0
- package/build/cjs/widgetRegistry.js +415 -0
- package/build/cjs/widgetRegistry.js.map +1 -0
- package/build/esm/bin/bundle-widgets.js +11 -0
- package/build/esm/bin/bundle-widgets.js.map +1 -0
- package/build/esm/bundleWidgets.js +79 -0
- package/build/esm/bundleWidgets.js.map +1 -0
- package/build/esm/createErrorOnlyMetroReporter.js +23 -0
- package/build/esm/createErrorOnlyMetroReporter.js.map +1 -0
- package/build/esm/createVoltraMiddleware.js +78 -0
- package/build/esm/createVoltraMiddleware.js.map +1 -0
- package/build/esm/createWidgetMetroConfig.js +68 -0
- package/build/esm/createWidgetMetroConfig.js.map +1 -0
- package/build/esm/index.js +97 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/package.json +3 -0
- package/build/esm/resolveProjectModule.js +38 -0
- package/build/esm/resolveProjectModule.js.map +1 -0
- package/build/esm/scanner.js +2 -0
- package/build/esm/scanner.js.map +1 -0
- package/build/esm/widgetRegistry.js +404 -0
- package/build/esm/widgetRegistry.js.map +1 -0
- package/build/types/bin/bundle-widgets.d.ts +3 -0
- package/build/types/bin/bundle-widgets.d.ts.map +1 -0
- package/build/types/bundleWidgets.d.ts +16 -0
- package/build/types/bundleWidgets.d.ts.map +1 -0
- package/build/types/createErrorOnlyMetroReporter.d.ts +6 -0
- package/build/types/createErrorOnlyMetroReporter.d.ts.map +1 -0
- package/build/types/createVoltraMiddleware.d.ts +10 -0
- package/build/types/createVoltraMiddleware.d.ts.map +1 -0
- package/build/types/createWidgetMetroConfig.d.ts +5 -0
- package/build/types/createWidgetMetroConfig.d.ts.map +1 -0
- package/build/types/index.d.ts +10 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/resolveProjectModule.d.ts +3 -0
- package/build/types/resolveProjectModule.d.ts.map +1 -0
- package/build/types/scanner.d.ts +3 -0
- package/build/types/scanner.d.ts.map +1 -0
- package/build/types/widgetRegistry.d.ts +42 -0
- package/build/types/widgetRegistry.d.ts.map +1 -0
- package/package.json +87 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Saúl Sharma, Szymon Chmal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
### Metro integration for Voltra client-rendered widgets
|
|
4
|
+
|
|
5
|
+
[![mit licence][license-badge]][license] [![npm downloads][npm-downloads-badge]][npm-downloads] [![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
|
6
|
+
|
|
7
|
+
`@use-voltra/metro` helps Voltra client-rendered widgets work in Metro-based React Native apps.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Metro config transformer**: Wrap your app's Metro config with `withVoltra()` to enable Voltra's widget pipeline.
|
|
12
|
+
|
|
13
|
+
- **Widget registry**: Work with widgets declared in app.json and keep the widget pipeline organized per platform.
|
|
14
|
+
|
|
15
|
+
- **Project-aware module resolution**: Resolve app dependencies from the consuming project's install layout, including pnpm setups.
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
This package supports the client-rendered widget workflow in Voltra. Relevant topics:
|
|
20
|
+
|
|
21
|
+
- [Getting Started](https://use-voltra.dev/getting-started/installation)
|
|
22
|
+
- [iOS client-rendered widgets](https://use-voltra.dev/ios/development/dynamic-widgets)
|
|
23
|
+
- [Android client-rendered widgets](https://use-voltra.dev/android/development/dynamic-widgets)
|
|
24
|
+
- [iOS API Reference](https://use-voltra.dev/ios/api/configuration)
|
|
25
|
+
- [Android API Reference](https://use-voltra.dev/android/api/plugin-configuration)
|
|
26
|
+
|
|
27
|
+
## Getting started
|
|
28
|
+
|
|
29
|
+
`@use-voltra/metro` is usually consumed through `@use-voltra/ios-client` or `@use-voltra/android-client`, but you can install it directly if you need to customize Metro yourself.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install @use-voltra/metro
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Wrap your Metro config with `withVoltra`:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { withVoltra } from '@use-voltra/metro'
|
|
39
|
+
|
|
40
|
+
export default withVoltra({
|
|
41
|
+
projectRoot: __dirname,
|
|
42
|
+
resolver: {
|
|
43
|
+
sourceExts: ['ts', 'tsx', 'js', 'jsx'],
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Declare client-rendered widgets in app.json with a stable `id` and an explicit `entry` path, then default-export the widget module.
|
|
49
|
+
|
|
50
|
+
## Quick example
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { bundleWidgets, createWidgetRegistry } from '@use-voltra/metro'
|
|
54
|
+
|
|
55
|
+
const registry = createWidgetRegistry({ projectRoot: process.cwd() })
|
|
56
|
+
console.log(registry.listWidgets('ios'))
|
|
57
|
+
registry.close()
|
|
58
|
+
|
|
59
|
+
await bundleWidgets({
|
|
60
|
+
projectRoot: process.cwd(),
|
|
61
|
+
outDir: './dist/widgets',
|
|
62
|
+
platform: 'ios',
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Platform compatibility
|
|
67
|
+
|
|
68
|
+
This package works with Metro-based React Native apps on **iOS** and **Android** when you are using Voltra client-rendered widgets.
|
|
69
|
+
|
|
70
|
+
## Authors
|
|
71
|
+
|
|
72
|
+
Voltra is an open source collaboration between [Saúl Sharma](https://github.com/saulsharma) and [Szymon Chmal](https://github.com/szymonchmal) at [Callstack][callstack-readme-with-love].
|
|
73
|
+
|
|
74
|
+
If you think it's cool, please star it 🌟. This project will always remain free to use.
|
|
75
|
+
|
|
76
|
+
[Callstack][callstack-readme-with-love] is a group of React and React Native geeks, contact us at [hello@callstack.com](mailto:hello@callstack.com) if you need any help with these or just want to say hi!
|
|
77
|
+
|
|
78
|
+
Like the project? ⚛️ [Join the Callstack team](https://callstack.com/careers/?utm_campaign=Senior_RN&utm_source=github&utm_medium=readme) who does amazing stuff for clients and drives React Native Open Source! 🔥
|
|
79
|
+
|
|
80
|
+
[callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=voltra&utm_term=readme-with-love
|
|
81
|
+
[license-badge]: https://img.shields.io/npm/l/@use-voltra/metro?style=for-the-badge
|
|
82
|
+
[license]: https://github.com/callstackincubator/voltra/blob/main/LICENSE.txt
|
|
83
|
+
[npm-downloads-badge]: https://img.shields.io/npm/dm/@use-voltra/metro?style=for-the-badge
|
|
84
|
+
[npm-downloads]: https://www.npmjs.com/package/@use-voltra/metro
|
|
85
|
+
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
|
|
86
|
+
[prs-welcome]: ../../CONTRIBUTING.md
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const bundleWidgets_1 = require("../bundleWidgets");
|
|
5
|
+
(0, bundleWidgets_1.runBundleWidgetsCli)()
|
|
6
|
+
.then(() => {
|
|
7
|
+
process.exit(0);
|
|
8
|
+
})
|
|
9
|
+
.catch((error) => {
|
|
10
|
+
console.error(`[voltra] widget bundling failed: ${error instanceof Error ? error.stack || error.message : String(error)}`);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=bundle-widgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-widgets.js","sourceRoot":"","sources":["../../../src/bin/bundle-widgets.ts"],"names":[],"mappings":";;;AACA,oDAAsD;AAEtD,IAAA,mCAAmB,GAAE;KAClB,IAAI,CAAC,GAAG,EAAE;IACT,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,OAAO,CAAC,KAAK,CACX,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC5G,CAAA;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseBundleWidgetsArgs = parseBundleWidgetsArgs;
|
|
7
|
+
exports.bundleWidgets = bundleWidgets;
|
|
8
|
+
exports.runBundleWidgetsCli = runBundleWidgetsCli;
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const createWidgetMetroConfig_1 = require("./createWidgetMetroConfig");
|
|
12
|
+
const resolveProjectModule_1 = require("./resolveProjectModule");
|
|
13
|
+
const widgetRegistry_1 = require("./widgetRegistry");
|
|
14
|
+
function parsePlatform(value) {
|
|
15
|
+
if (value === 'ios' || value === 'android') {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Invalid platform '${value}'. Expected 'ios' or 'android'.`);
|
|
19
|
+
}
|
|
20
|
+
function parseBundleWidgetsArgs(argv) {
|
|
21
|
+
const args = { outDir: null, platform: 'ios', projectRoot: process.cwd() };
|
|
22
|
+
for (let i = 2; i < argv.length; i += 1) {
|
|
23
|
+
const value = argv[i + 1];
|
|
24
|
+
switch (argv[i]) {
|
|
25
|
+
case '--out-dir':
|
|
26
|
+
args.outDir = value;
|
|
27
|
+
i += 1;
|
|
28
|
+
break;
|
|
29
|
+
case '--platform':
|
|
30
|
+
args.platform = parsePlatform(value);
|
|
31
|
+
i += 1;
|
|
32
|
+
break;
|
|
33
|
+
case '--project-root':
|
|
34
|
+
args.projectRoot = node_path_1.default.resolve(value);
|
|
35
|
+
i += 1;
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
async function loadAppMetroConfig(projectRoot) {
|
|
44
|
+
const { loadConfig } = (0, resolveProjectModule_1.requireProjectModule)('metro-config', projectRoot);
|
|
45
|
+
return loadConfig({ cwd: projectRoot });
|
|
46
|
+
}
|
|
47
|
+
async function bundleWidgets({ projectRoot, outDir, platform }) {
|
|
48
|
+
if (!outDir) {
|
|
49
|
+
throw new Error('bundleWidgets: --out-dir is required');
|
|
50
|
+
}
|
|
51
|
+
const registry = (0, widgetRegistry_1.createWidgetRegistry)({ projectRoot });
|
|
52
|
+
try {
|
|
53
|
+
const widgets = registry.listWidgets(platform);
|
|
54
|
+
if (widgets.length === 0) {
|
|
55
|
+
console.log(`[voltra] no Dynamic Widgets to bundle for platform "${platform}"`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const Metro = (0, resolveProjectModule_1.requireProjectModule)('metro', projectRoot);
|
|
59
|
+
const appConfig = await loadAppMetroConfig(projectRoot);
|
|
60
|
+
const widgetConfig = await (0, createWidgetMetroConfig_1.createWidgetMetroConfig)({ projectRoot, appConfig });
|
|
61
|
+
node_fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
62
|
+
for (const widget of widgets) {
|
|
63
|
+
const entry = node_path_1.default.resolve(projectRoot, widget.generatedEntryRelativePath);
|
|
64
|
+
const { code } = await Metro.runBuild(widgetConfig, {
|
|
65
|
+
entry,
|
|
66
|
+
platform,
|
|
67
|
+
dev: false,
|
|
68
|
+
minify: true,
|
|
69
|
+
});
|
|
70
|
+
const outPath = node_path_1.default.join(outDir, `voltra-widget-${widget.id}.bundle`);
|
|
71
|
+
node_fs_1.default.writeFileSync(outPath, code);
|
|
72
|
+
console.log(`[voltra] baked ${node_path_1.default.basename(outPath)} (${code.length} bytes)`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
registry.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function runBundleWidgetsCli(argv = process.argv) {
|
|
80
|
+
const args = parseBundleWidgetsArgs(argv);
|
|
81
|
+
await bundleWidgets({
|
|
82
|
+
projectRoot: args.projectRoot,
|
|
83
|
+
outDir: args.outDir ?? '',
|
|
84
|
+
platform: args.platform,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=bundleWidgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleWidgets.js","sourceRoot":"","sources":["../../src/bundleWidgets.ts"],"names":[],"mappings":";;;;;AA6BA,wDAsBC;AAOD,sCAwCC;AAED,kDAOC;AA3GD,sDAAwB;AACxB,0DAA4B;AAI5B,uEAAmE;AACnE,iEAA6D;AAC7D,qDAAuD;AAcvD,SAAS,aAAa,CAAC,KAAyB;IAC9C,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,iCAAiC,CAAC,CAAA;AAC9E,CAAC;AAED,SAAgB,sBAAsB,CAAC,IAAc;IACnD,MAAM,IAAI,GAAe,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,EAAE,E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IAAI,CAAC,CAAA;IACzC,MAAM,aAAa,CAAC;QAClB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;QACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;KACxB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createErrorOnlyMetroReporter = createErrorOnlyMetroReporter;
|
|
4
|
+
const metro_1 = require("metro");
|
|
5
|
+
function isErrorEvent(event) {
|
|
6
|
+
switch (event.type) {
|
|
7
|
+
case 'initialize_failed':
|
|
8
|
+
case 'bundling_error':
|
|
9
|
+
case 'hmr_client_error':
|
|
10
|
+
return true;
|
|
11
|
+
default:
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function createErrorOnlyMetroReporter() {
|
|
16
|
+
const reporter = new metro_1.TerminalReporter(new metro_1.Terminal(process.stderr));
|
|
17
|
+
return {
|
|
18
|
+
update(event) {
|
|
19
|
+
if (!isErrorEvent(event)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
reporter.update(event);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=createErrorOnlyMetroReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createErrorOnlyMetroReporter.js","sourceRoot":"","sources":["../../src/createErrorOnlyMetroReporter.ts"],"names":[],"mappings":";;AA4BA,oEAYC;AAxCD,iCAAkD;AAiBlD,SAAS,YAAY,CAAC,KAAuB;IAC3C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,mBAAmB,CAAC;QACzB,KAAK,gBAAgB,CAAC;QACtB,KAAK,kBAAkB;YACrB,OAAO,IAAI,CAAA;QACb;YACE,OAAO,KAAK,CAAA;IAChB,CAAC;AACH,CAAC;AAED,SAAgB,4BAA4B;IAC1C,MAAM,QAAQ,GAAG,IAAI,wBAAgB,CAAC,IAAI,gBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;IAEnE,OAAO;QACL,MAAM,CAAC,KAAK;YACV,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAM;YACR,CAAC;YAED,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACxB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createVoltraMiddleware = createVoltraMiddleware;
|
|
4
|
+
function parsePlatform(value) {
|
|
5
|
+
if (value === 'ios' || value === 'android') {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
function sendJson(res, status, value) {
|
|
11
|
+
res.writeHead(status, {
|
|
12
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
13
|
+
});
|
|
14
|
+
res.end(JSON.stringify(value, null, 2));
|
|
15
|
+
}
|
|
16
|
+
function createBundleRequest(widget, originalSearchParams) {
|
|
17
|
+
const query = new URLSearchParams(originalSearchParams);
|
|
18
|
+
query.set('bundleEntry', widget.generatedEntryRelativePath);
|
|
19
|
+
query.set('platform', widget.platform);
|
|
20
|
+
return `/voltra-widget.bundle?${query.toString()}`;
|
|
21
|
+
}
|
|
22
|
+
function createVoltraMiddleware({ registry, widgetMetro, }) {
|
|
23
|
+
return (req, res, next) => {
|
|
24
|
+
const requestUrl = new URL(req.url, 'http://localhost');
|
|
25
|
+
const pathname = requestUrl.pathname || '/';
|
|
26
|
+
const requestedPlatform = parsePlatform(requestUrl.searchParams.get('platform'));
|
|
27
|
+
const hasPlatformParam = requestUrl.searchParams.has('platform');
|
|
28
|
+
if (hasPlatformParam && !requestedPlatform) {
|
|
29
|
+
sendJson(res, 400, {
|
|
30
|
+
error: 'Missing or invalid platform query parameter. Expected "ios" or "android".',
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (pathname === '/' || pathname === '/widgets') {
|
|
35
|
+
try {
|
|
36
|
+
sendJson(res, 200, {
|
|
37
|
+
ready: registry.isReady(),
|
|
38
|
+
platform: requestedPlatform,
|
|
39
|
+
widgets: registry.listWidgets(requestedPlatform ?? undefined),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
sendJson(res, 500, {
|
|
44
|
+
error: error instanceof Error ? error.message : String(error),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const widgetBundleMatch = pathname.match(/^\/widgets\/([^/]+)\.bundle$/);
|
|
50
|
+
if (widgetBundleMatch) {
|
|
51
|
+
const widgetId = decodeURIComponent(widgetBundleMatch[1]);
|
|
52
|
+
if (!requestedPlatform) {
|
|
53
|
+
sendJson(res, 400, {
|
|
54
|
+
error: 'Missing or invalid platform query parameter. Expected "ios" or "android".',
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const widget = registry.getWidget(requestedPlatform, widgetId);
|
|
60
|
+
if (!widget) {
|
|
61
|
+
sendJson(res, 404, {
|
|
62
|
+
error: `Unknown Voltra widget "${widgetId}" for platform "${requestedPlatform}".`,
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
req.url = createBundleRequest(widget, requestUrl.searchParams);
|
|
67
|
+
widgetMetro.middleware(req, res, next);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
sendJson(res, 500, {
|
|
72
|
+
error: error instanceof Error ? error.message : String(error),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
sendJson(res, 404, {
|
|
77
|
+
error: `Unknown Voltra endpoint "${pathname}".`,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=createVoltraMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVoltraMiddleware.js","sourceRoot":"","sources":["../../src/createVoltraMiddleware.ts"],"names":[],"mappings":";;AA8BA,wDAqEC;AA/FD,SAAS,aAAa,CAAC,KAAoB;IACzC,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,QAAQ,CAAC,GAAQ,EAAE,MAAc,EAAE,KAAc;IACxD,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE;QACpB,cAAc,EAAE,iCAAiC;KAClD,CAAC,CAAA;IACF,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AACzC,CAAC;AAED,SAAS,mBAAmB,CAC1B,MAA2E,EAC3E,oBAAqC;IAErC,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,oBAAoB,CAAC,CAAA;IACvD,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;IAC3D,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEtC,OAAO,yBAAyB,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,SAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,WAAW,GAIZ;IACC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACxB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAA;QACvD,MAAM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2EAA2E;iBACnF,CAAC,CAAA;gBACF,OAAM;YACR,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;gBAE9D,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;wBACjB,KAAK,EAAE,0BAA0B,QAAQ,mBAAmB,iBAAiB,IAAI;qBAClF,CAAC,CAAA;oBACF,OAAM;gBACR,CAAC;gBAED,GAAG,CAAC,GAAG,GAAG,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;gBAC9D,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;gBACtC,OAAM;YACR,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;oBACjB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC9D,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE;YACjB,KAAK,EAAE,4BAA4B,QAAQ,IAAI;SAChD,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createWidgetMetroConfig = createWidgetMetroConfig;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const resolveProjectModule_1 = require("./resolveProjectModule");
|
|
9
|
+
const createErrorOnlyMetroReporter_1 = require("./createErrorOnlyMetroReporter");
|
|
10
|
+
const blockedModules = new Set(['react-native']);
|
|
11
|
+
function unique(items) {
|
|
12
|
+
return Array.from(new Set(items.filter((item) => item !== null && item !== undefined)));
|
|
13
|
+
}
|
|
14
|
+
function resolvePnpmTransitive(name, projectRoot) {
|
|
15
|
+
try {
|
|
16
|
+
return node_path_1.default.dirname((0, resolveProjectModule_1.resolveProjectModulePath)(`${name}/package.json`, projectRoot));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function createWidgetMetroConfig({ projectRoot, appConfig, }) {
|
|
23
|
+
const appNodeModules = node_path_1.default.join(projectRoot, 'node_modules');
|
|
24
|
+
const { getDefaultConfig } = (0, resolveProjectModule_1.requireProjectModule)('metro-config', projectRoot);
|
|
25
|
+
const config = await getDefaultConfig(projectRoot);
|
|
26
|
+
const sourceExts = unique([...(config.resolver?.sourceExts ?? []), ...(appConfig.resolver?.sourceExts ?? [])]);
|
|
27
|
+
const pnpmTransitives = {
|
|
28
|
+
'@babel/runtime': resolvePnpmTransitive('@babel/runtime', projectRoot),
|
|
29
|
+
'metro-runtime': resolvePnpmTransitive('metro-runtime', projectRoot),
|
|
30
|
+
};
|
|
31
|
+
const pnpmTransitiveModules = Object.fromEntries(Object.entries(pnpmTransitives).filter((entry) => entry[1] !== null));
|
|
32
|
+
return {
|
|
33
|
+
...config,
|
|
34
|
+
projectRoot,
|
|
35
|
+
watchFolders: unique([...(config.watchFolders ?? []), ...(appConfig.watchFolders ?? [])]),
|
|
36
|
+
resolver: {
|
|
37
|
+
...config.resolver,
|
|
38
|
+
sourceExts,
|
|
39
|
+
extraNodeModules: {
|
|
40
|
+
...config.resolver?.extraNodeModules,
|
|
41
|
+
...appConfig.resolver?.extraNodeModules,
|
|
42
|
+
...pnpmTransitiveModules,
|
|
43
|
+
react: node_path_1.default.join(appNodeModules, 'react'),
|
|
44
|
+
},
|
|
45
|
+
nodeModulesPaths: unique([
|
|
46
|
+
appNodeModules,
|
|
47
|
+
...(config.resolver?.nodeModulesPaths ?? []),
|
|
48
|
+
...(appConfig.resolver?.nodeModulesPaths ?? []),
|
|
49
|
+
]),
|
|
50
|
+
resolveRequest(context, moduleName, platform) {
|
|
51
|
+
if (blockedModules.has(moduleName) || moduleName.startsWith('react-native/')) {
|
|
52
|
+
throw new Error(`Voltra widget bundles cannot import "${moduleName}"`);
|
|
53
|
+
}
|
|
54
|
+
return context.resolveRequest(context, moduleName, platform);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
serializer: {
|
|
58
|
+
...config.serializer,
|
|
59
|
+
getModulesRunBeforeMainModule: () => [],
|
|
60
|
+
getPolyfills: () => [],
|
|
61
|
+
polyfillModuleNames: [],
|
|
62
|
+
},
|
|
63
|
+
reporter: (0, createErrorOnlyMetroReporter_1.createErrorOnlyMetroReporter)(),
|
|
64
|
+
transformer: {
|
|
65
|
+
...config.transformer,
|
|
66
|
+
babelTransformerPath: appConfig.transformer?.babelTransformerPath,
|
|
67
|
+
},
|
|
68
|
+
server: {
|
|
69
|
+
...config.server,
|
|
70
|
+
enhanceMiddleware: (middleware) => middleware,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=createWidgetMetroConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWidgetMetroConfig.js","sourceRoot":"","sources":["../../src/createWidgetMetroConfig.ts"],"names":[],"mappings":";;;;;AAmBA,0DAgEC;AAnFD,0DAA4B;AAE5B,iEAAuF;AACvF,iFAA6E;AAE7E,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,CAAA;AAEhD,SAAS,MAAM,CAAI,KAAkC;IACnD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAa,EAAE,CAAC,IAAI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G,MAAM,CAAC,MAAM;YAChB,iBAAiB,EAAE,CAAC,UAAmB,EAAE,EAAE,CAAC,UAAU;SACvD;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DuplicateVoltraWidgetError = exports.scanVoltraDirectives = exports.resolveProjectModulePath = exports.requireProjectModule = exports.createWidgetRegistry = exports.createWidgetMetroConfig = exports.createVoltraMiddleware = exports.bundleWidgets = exports.withVoltra = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const metro_config_transformers_1 = require("metro-config-transformers");
|
|
10
|
+
const bundleWidgets_1 = require("./bundleWidgets");
|
|
11
|
+
Object.defineProperty(exports, "bundleWidgets", { enumerable: true, get: function () { return bundleWidgets_1.bundleWidgets; } });
|
|
12
|
+
const createVoltraMiddleware_1 = require("./createVoltraMiddleware");
|
|
13
|
+
Object.defineProperty(exports, "createVoltraMiddleware", { enumerable: true, get: function () { return createVoltraMiddleware_1.createVoltraMiddleware; } });
|
|
14
|
+
const createWidgetMetroConfig_1 = require("./createWidgetMetroConfig");
|
|
15
|
+
Object.defineProperty(exports, "createWidgetMetroConfig", { enumerable: true, get: function () { return createWidgetMetroConfig_1.createWidgetMetroConfig; } });
|
|
16
|
+
const resolveProjectModule_1 = require("./resolveProjectModule");
|
|
17
|
+
const widgetRegistry_1 = require("./widgetRegistry");
|
|
18
|
+
Object.defineProperty(exports, "createWidgetRegistry", { enumerable: true, get: function () { return widgetRegistry_1.createWidgetRegistry; } });
|
|
19
|
+
const HOT_RELOAD_ALIAS = '@use-voltra/widget-hot-reload';
|
|
20
|
+
const DEV_BARREL_PLATFORMS = new Set(['ios', 'android']);
|
|
21
|
+
const WIDGET_PLATFORMS = ['ios', 'android'];
|
|
22
|
+
function resolveHotReloadAlias(projectRoot, context, platform) {
|
|
23
|
+
if (!context.dev) {
|
|
24
|
+
return { type: 'empty' };
|
|
25
|
+
}
|
|
26
|
+
if (!platform || !DEV_BARREL_PLATFORMS.has(platform)) {
|
|
27
|
+
return { type: 'sourceFile', filePath: (0, widgetRegistry_1.ensureEmptyDevBarrel)(projectRoot) };
|
|
28
|
+
}
|
|
29
|
+
const platformBarrel = node_path_1.default.join(projectRoot, '.voltra', 'metro', `widget-hot-reload.${platform}.js`);
|
|
30
|
+
if (!node_fs_1.default.existsSync(platformBarrel)) {
|
|
31
|
+
return { type: 'sourceFile', filePath: (0, widgetRegistry_1.ensureEmptyDevBarrel)(projectRoot) };
|
|
32
|
+
}
|
|
33
|
+
return { type: 'sourceFile', filePath: platformBarrel };
|
|
34
|
+
}
|
|
35
|
+
function createResolveRequest(projectRoot, previousResolveRequest) {
|
|
36
|
+
return (context, moduleName, platform) => {
|
|
37
|
+
if (moduleName === HOT_RELOAD_ALIAS) {
|
|
38
|
+
return resolveHotReloadAlias(projectRoot, context, platform);
|
|
39
|
+
}
|
|
40
|
+
if (previousResolveRequest) {
|
|
41
|
+
return previousResolveRequest(context, moduleName, platform);
|
|
42
|
+
}
|
|
43
|
+
return context.resolveRequest(context, moduleName, platform);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function listConfiguredWidgets(registry) {
|
|
47
|
+
const widgets = [];
|
|
48
|
+
for (const platform of WIDGET_PLATFORMS) {
|
|
49
|
+
try {
|
|
50
|
+
widgets.push(...registry.listWidgets(platform));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof widgetRegistry_1.MissingVoltraManifestError) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return widgets;
|
|
60
|
+
}
|
|
61
|
+
exports.withVoltra = (0, metro_config_transformers_1.createMetroConfigTransformer)(async (metroConfig) => {
|
|
62
|
+
const projectRoot = metroConfig.projectRoot ?? process.cwd();
|
|
63
|
+
const registry = (0, widgetRegistry_1.createWidgetRegistry)({ projectRoot });
|
|
64
|
+
const previousResolveRequest = metroConfig.resolver?.resolveRequest;
|
|
65
|
+
const configWithResolver = {
|
|
66
|
+
...metroConfig,
|
|
67
|
+
projectRoot,
|
|
68
|
+
resolver: {
|
|
69
|
+
...metroConfig.resolver,
|
|
70
|
+
resolveRequest: createResolveRequest(projectRoot, previousResolveRequest),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const configuredWidgets = listConfiguredWidgets(registry);
|
|
74
|
+
if (configuredWidgets.length === 0) {
|
|
75
|
+
registry.close();
|
|
76
|
+
return configWithResolver;
|
|
77
|
+
}
|
|
78
|
+
const widgetConfig = await (0, createWidgetMetroConfig_1.createWidgetMetroConfig)({
|
|
79
|
+
projectRoot,
|
|
80
|
+
appConfig: metroConfig,
|
|
81
|
+
});
|
|
82
|
+
const Metro = (0, resolveProjectModule_1.requireProjectModule)('metro', projectRoot);
|
|
83
|
+
const connect = (0, resolveProjectModule_1.requireProjectModule)('connect', projectRoot);
|
|
84
|
+
const widgetMetro = await Metro.createConnectMiddleware(widgetConfig, {
|
|
85
|
+
port: metroConfig.server?.port,
|
|
86
|
+
});
|
|
87
|
+
const voltraMiddleware = (0, createVoltraMiddleware_1.createVoltraMiddleware)({
|
|
88
|
+
registry,
|
|
89
|
+
widgetMetro,
|
|
90
|
+
});
|
|
91
|
+
const previousEnhanceMiddleware = metroConfig.server?.enhanceMiddleware || ((middleware) => middleware);
|
|
92
|
+
return {
|
|
93
|
+
...configWithResolver,
|
|
94
|
+
server: {
|
|
95
|
+
...metroConfig.server,
|
|
96
|
+
enhanceMiddleware(metroMiddleware, metroServer) {
|
|
97
|
+
const enhancedAppMetroMiddleware = previousEnhanceMiddleware(metroMiddleware, metroServer);
|
|
98
|
+
return connect().use('/voltra', voltraMiddleware).use(enhancedAppMetroMiddleware);
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
var resolveProjectModule_2 = require("./resolveProjectModule");
|
|
104
|
+
Object.defineProperty(exports, "requireProjectModule", { enumerable: true, get: function () { return resolveProjectModule_2.requireProjectModule; } });
|
|
105
|
+
Object.defineProperty(exports, "resolveProjectModulePath", { enumerable: true, get: function () { return resolveProjectModule_2.resolveProjectModulePath; } });
|
|
106
|
+
var scanner_1 = require("./scanner");
|
|
107
|
+
Object.defineProperty(exports, "scanVoltraDirectives", { enumerable: true, get: function () { return scanner_1.scanVoltraDirectives; } });
|
|
108
|
+
var widgetRegistry_2 = require("./widgetRegistry");
|
|
109
|
+
Object.defineProperty(exports, "DuplicateVoltraWidgetError", { enumerable: true, get: function () { return widgetRegistry_2.DuplicateVoltraWidgetError; } });
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,0DAA4B;AAE5B,yEAAwE;AAExE,mDAA+C;AA6HtC,8FA7HA,6BAAa,OA6HA;AA5HtB,qEAAiE;AA4HzC,uGA5Hf,+CAAsB,OA4He;AA3H9C,uEAAmE;AA2HnB,wGA3HvC,iDAAuB,OA2HuC;AA1HvE,iEAA6D;AAC7D,qDAMyB;AAmHgD,qGAxHvE,qCAAoB,OAwHuE;AAjH7F,MAAM,gBAAgB,GAAG,+BAA+B,CAAA;AACxD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAA;AACxD,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,CAAU,CAAA;AAIpD,SAAS,qBAAqB,CAAC,WAAmB,EAAE,OAAY,EAAE,QAAuB;IACvF,IA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W,CACZ,CAAA;IACD,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,uBAAuB,CAAC,YAAY,EAAE;QACpE,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI;KAC/B,CAAC,CAAA;IACF,MAAM,gBAAgB,GAAG,IAAA,+CAAsB,EAAC;QAC9C,QAAQ;QACR,WAAW;KACZ,CAAC,CAAA;IAEF,MAAM,yBAAyB,GAAG,WAAW,CAAC,MAAM,EAAE,iBAAiB,IAAI,CAAC,CAAC,UAAmB,EAAE,EAAE,CAAC,UAAU,CAAC,CAAA;IAEhH,OAAO;QACL,GAAG,kBAAkB;QACrB,MAAM,EAAE;YACN,GAAG,WAAW,CAAC,MAAM;YACrB,iBAAiB,CAAC,eAAwB,EAAE,WAAoB;gBAC9D,MAAM,0BAA0B,GAAG,yBAAyB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAA;gBAE1F,OAAO,OAAO,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;YACnF,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAC,CAAA;AAGF,+DAAuF;AAA9E,4HAAA,oBAAoB,OAAA;AAAE,gIAAA,wBAAwB,OAAA;AACvD,qCAA4E;AAAnE,+GAAA,oBAAoB,OAAA;AAC7B,mDAA+G;AAAtG,4HAAA,0BAA0B,OAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.requireProjectModule = requireProjectModule;
|
|
7
|
+
exports.resolveProjectModulePath = resolveProjectModulePath;
|
|
8
|
+
const node_module_1 = require("node:module");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
function createProjectRequire(projectRoot) {
|
|
11
|
+
return (0, node_module_1.createRequire)(node_path_1.default.join(projectRoot, 'package.json'));
|
|
12
|
+
}
|
|
13
|
+
function createExpoMetroRequire(projectRoot) {
|
|
14
|
+
const requireFromProject = createProjectRequire(projectRoot);
|
|
15
|
+
return (0, node_module_1.createRequire)(requireFromProject.resolve('expo/metro-config'));
|
|
16
|
+
}
|
|
17
|
+
function requireProjectModule(moduleName, projectRoot = process.cwd()) {
|
|
18
|
+
const requireFromProject = createProjectRequire(projectRoot);
|
|
19
|
+
try {
|
|
20
|
+
return requireFromProject(moduleName);
|
|
21
|
+
}
|
|
22
|
+
catch (projectError) {
|
|
23
|
+
try {
|
|
24
|
+
return createExpoMetroRequire(projectRoot)(moduleName);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw projectError;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function resolveProjectModulePath(moduleName, projectRoot = process.cwd()) {
|
|
32
|
+
const requireFromProject = createProjectRequire(projectRoot);
|
|
33
|
+
try {
|
|
34
|
+
return requireFromProject.resolve(moduleName);
|
|
35
|
+
}
|
|
36
|
+
catch (projectError) {
|
|
37
|
+
try {
|
|
38
|
+
return createExpoMetroRequire(projectRoot).resolve(moduleName);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw projectError;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=resolveProjectModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveProjectModule.js","sourceRoot":"","sources":["../../src/resolveProjectModule.ts"],"names":[],"mappings":";;;;;AAYA,oDAYC;AAED,4DAYC;AAtCD,6CAA2C;AAC3C,0DAA4B;AAE5B,SAAS,oBAAoB,CAAC,WAAmB;IAC/C,OAAO,IAAA,2BAAa,EAAC,mBAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,sBAAsB,CAAC,WAAmB;IACjD,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAA;IAC5D,OAAO,IAAA,2BAAa,EAAC,kBAAkB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAA;AACvE,CAAC;AAED,SAAgB,oBAAoB,CAAc,UAAkB,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE;IAC/F,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAA;IAE5D,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,UAAU,CAAM,CAAA;IAC5C,CAAC;IAAC,OAAO,YAAY,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC,UAAU,CAAM,CAAA;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,YAAY,CAAA;QACpB,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,wBAAwB,CAAC,UAAkB,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE;IACtF,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAA;IAE5D,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC/C,CAAC;IAAC,OAAO,YAAY,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,YAAY,CAAA;QACpB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scanVoltraDirectives = void 0;
|
|
4
|
+
var compiler_1 = require("@use-voltra/compiler");
|
|
5
|
+
Object.defineProperty(exports, "scanVoltraDirectives", { enumerable: true, get: function () { return compiler_1.scanVoltraDirectives; } });
|
|
6
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/scanner.ts"],"names":[],"mappings":";;;AAAA,iDAA2D;AAAlD,gHAAA,oBAAoB,OAAA"}
|