@quiesco/expo-plugin 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +18 -2
- package/app.plugin.js +144 -0
- package/package.json +42 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Quiesco contributors
|
|
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
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @quiesco/expo-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Expo config plugin for Quiesco. In e2e builds (`EXPO_PUBLIC_QUIESCO=1` at `expo prebuild`) it links
|
|
4
|
+
[`@quiesco/native`](https://github.com/h2nology/quiesco/tree/main/packages/native) and allows the local connection to the test run; in
|
|
5
|
+
production builds it excludes the native module.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -D @quiesco/expo-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{ "expo": { "plugins": ["@quiesco/expo-plugin"] } }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Part of [Quiesco](https://github.com/h2nology/quiesco): gray-box end-to-end testing for Expo apps on iOS, Android and the web. Setup: `npx quiesco init` ([quick start](https://github.com/h2nology/quiesco#quick-start-web-about-10-minutes)).
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Expo config plugin of Quiesco (requirements.md §6.8). Add `"@quiesco/expo-plugin"` to `plugins` in
|
|
4
|
+
* app.json / app.config.ts. Decided by EXPO_PUBLIC_QUIESCO at prebuild time:
|
|
5
|
+
*
|
|
6
|
+
* - not an e2e build: exclude @quiesco/native from autolinking on both platforms, so the touch
|
|
7
|
+
* injection code (private UIKit API on iOS) never reaches a production binary
|
|
8
|
+
* (docs/spikes/06-prod-strip.md). Being in devDependencies is not enough: autolinking would still
|
|
9
|
+
* find it.
|
|
10
|
+
* - e2e build: keep the module and let the app reach the Quiesco host on localhost:
|
|
11
|
+
* - Android: cleartext traffic to localhost / 127.0.0.1 (ws:// through adb reverse, docs/spikes/05).
|
|
12
|
+
* Debug builds keep allowing all cleartext traffic (Metro over the LAN), because a
|
|
13
|
+
* networkSecurityConfig replaces `usesCleartextTraffic`.
|
|
14
|
+
* - iOS: `NSAllowsLocalNetworking` in App Transport Security (Expo sets it by default; this keeps it
|
|
15
|
+
* when an app config overrides NSAppTransportSecurity).
|
|
16
|
+
*/
|
|
17
|
+
const fs = require('node:fs');
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
const { withAndroidManifest, withDangerousMod, withInfoPlist, withPodfile, withSettingsGradle } = require('@expo/config-plugins');
|
|
20
|
+
|
|
21
|
+
const PLUGIN = '@quiesco/expo-plugin';
|
|
22
|
+
/** The package autolinking must leave out of production builds. */
|
|
23
|
+
const NATIVE_PACKAGE = '@quiesco/native';
|
|
24
|
+
const GRADLE_MARK = `// ${PLUGIN}: ${NATIVE_PACKAGE} excluded from autolinking (not an e2e build)`;
|
|
25
|
+
const PODFILE_MARK = `# ${PLUGIN}: ${NATIVE_PACKAGE} excluded from autolinking (not an e2e build)`;
|
|
26
|
+
const XML_NAME = 'quiesco_network_security_config';
|
|
27
|
+
|
|
28
|
+
/** @param {NodeJS.ProcessEnv | Record<string, string | undefined>} env */
|
|
29
|
+
function isE2E(env) {
|
|
30
|
+
return env.EXPO_PUBLIC_QUIESCO === '1';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Android: set `expoAutolinking.exclude` before `expoAutolinking.useExpoModules()`. Idempotent. */
|
|
34
|
+
function excludeFromSettingsGradle(src) {
|
|
35
|
+
if (src.includes(GRADLE_MARK)) return src;
|
|
36
|
+
if (!/^\s*expoAutolinking\.useExpoModules\(\)\s*$/m.test(src)) {
|
|
37
|
+
throw new Error(`${PLUGIN}: settings.gradle has no expoAutolinking.useExpoModules(); cannot exclude ${NATIVE_PACKAGE}`);
|
|
38
|
+
}
|
|
39
|
+
return src.replace(
|
|
40
|
+
/^(\s*)expoAutolinking\.useExpoModules\(\)\s*$/m,
|
|
41
|
+
`$1${GRADLE_MARK}\n$1expoAutolinking.exclude = ["${NATIVE_PACKAGE}"]\n$1expoAutolinking.useExpoModules()`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* iOS: pass `exclude:` to `use_expo_modules!` (forwarded to autolinking as --exclude). Idempotent.
|
|
47
|
+
* Only the bare call generated by Expo is rewritten; a customized call fails loudly rather than being
|
|
48
|
+
* guessed at.
|
|
49
|
+
*/
|
|
50
|
+
function excludeFromPodfile(src) {
|
|
51
|
+
if (src.includes(PODFILE_MARK)) return src;
|
|
52
|
+
const bare = /^(\s*)use_expo_modules!\s*$/m;
|
|
53
|
+
if (!bare.test(src)) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`${PLUGIN}: the Podfile has no bare \`use_expo_modules!\` line; add \`exclude: ['${NATIVE_PACKAGE}']\` to it yourself for non-e2e builds`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return src.replace(bare, `$1${PODFILE_MARK}\n$1use_expo_modules!(exclude: ['${NATIVE_PACKAGE}'])`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {'localhost' | 'all'} kind */
|
|
62
|
+
function networkSecurityXml(kind) {
|
|
63
|
+
const body =
|
|
64
|
+
kind === 'all'
|
|
65
|
+
? ' <base-config cleartextTrafficPermitted="true" />\n'
|
|
66
|
+
: ' <domain-config cleartextTrafficPermitted="true">\n <domain includeSubdomains="false">localhost</domain>\n <domain includeSubdomains="false">127.0.0.1</domain>\n </domain-config>\n';
|
|
67
|
+
return `<?xml version="1.0" encoding="utf-8"?>\n<!-- Generated by ${PLUGIN} for e2e builds. -->\n<network-security-config>\n${body}</network-security-config>\n`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* iOS e2e: make sure App Transport Security allows ws://localhost.
|
|
72
|
+
* @param {Record<string, unknown>} plist
|
|
73
|
+
*/
|
|
74
|
+
function allowLocalNetworking(plist) {
|
|
75
|
+
const ats = /** @type {Record<string, unknown>} */ (plist.NSAppTransportSecurity ?? {});
|
|
76
|
+
return { ...plist, NSAppTransportSecurity: { ...ats, NSAllowsLocalNetworking: true } };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @param {import('@expo/config-plugins').ExportedConfig} config */
|
|
80
|
+
function withProductionExclusion(config) {
|
|
81
|
+
config = withSettingsGradle(config, (cfg) => {
|
|
82
|
+
cfg.modResults.contents = excludeFromSettingsGradle(cfg.modResults.contents);
|
|
83
|
+
return cfg;
|
|
84
|
+
});
|
|
85
|
+
return withPodfile(config, (cfg) => {
|
|
86
|
+
cfg.modResults.contents = excludeFromPodfile(cfg.modResults.contents);
|
|
87
|
+
return cfg;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @param {import('@expo/config-plugins').ExportedConfig} config */
|
|
92
|
+
function withE2EAndroid(config) {
|
|
93
|
+
let ownConfig = true;
|
|
94
|
+
config = withAndroidManifest(config, (cfg) => {
|
|
95
|
+
const app = cfg.modResults.manifest.application?.[0];
|
|
96
|
+
if (app === undefined) return cfg;
|
|
97
|
+
const current = app.$['android:networkSecurityConfig'];
|
|
98
|
+
if (current !== undefined && current !== `@xml/${XML_NAME}`) {
|
|
99
|
+
ownConfig = false;
|
|
100
|
+
console.warn(`${PLUGIN}: the app already sets android:networkSecurityConfig (${current}); make sure it allows cleartext to localhost`);
|
|
101
|
+
return cfg;
|
|
102
|
+
}
|
|
103
|
+
app.$['android:networkSecurityConfig'] = `@xml/${XML_NAME}`;
|
|
104
|
+
return cfg;
|
|
105
|
+
});
|
|
106
|
+
return withDangerousMod(config, [
|
|
107
|
+
'android',
|
|
108
|
+
async (cfg) => {
|
|
109
|
+
if (!ownConfig) return cfg;
|
|
110
|
+
const appDir = path.join(cfg.modRequest.platformProjectRoot, 'app', 'src');
|
|
111
|
+
for (const [sourceSet, kind] of /** @type {const} */ ([['main', 'localhost'], ['debug', 'all']])) {
|
|
112
|
+
const dir = path.join(appDir, sourceSet, 'res', 'xml');
|
|
113
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
114
|
+
fs.writeFileSync(path.join(dir, `${XML_NAME}.xml`), networkSecurityXml(kind));
|
|
115
|
+
}
|
|
116
|
+
return cfg;
|
|
117
|
+
},
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @param {import('@expo/config-plugins').ExportedConfig} config */
|
|
122
|
+
function withE2EIos(config) {
|
|
123
|
+
return withInfoPlist(config, (cfg) => {
|
|
124
|
+
cfg.modResults = /** @type {typeof cfg.modResults} */ (allowLocalNetworking(cfg.modResults));
|
|
125
|
+
return cfg;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {import('@expo/config-plugins').ExportedConfig} config
|
|
131
|
+
* @param {{ env?: NodeJS.ProcessEnv | Record<string, string | undefined> }} [options] `env` is for tests.
|
|
132
|
+
*/
|
|
133
|
+
function withQuiesco(config, options = {}) {
|
|
134
|
+
const env = options.env ?? process.env;
|
|
135
|
+
if (!isE2E(env)) return withProductionExclusion(config);
|
|
136
|
+
return withE2EIos(withE2EAndroid(config));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = withQuiesco;
|
|
140
|
+
module.exports.isE2E = isE2E;
|
|
141
|
+
module.exports.excludeFromSettingsGradle = excludeFromSettingsGradle;
|
|
142
|
+
module.exports.excludeFromPodfile = excludeFromPodfile;
|
|
143
|
+
module.exports.networkSecurityXml = networkSecurityXml;
|
|
144
|
+
module.exports.allowLocalNetworking = allowLocalNetworking;
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiesco/expo-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Quiesco Expo config plugin: links @quiesco/native into e2e builds only.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "h2nology",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"quiesco",
|
|
9
|
+
"e2e",
|
|
10
|
+
"testing",
|
|
11
|
+
"expo",
|
|
12
|
+
"react-native",
|
|
13
|
+
"expo-config-plugin"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/h2nology/quiesco/tree/main/packages/expo-plugin#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/h2nology/quiesco.git",
|
|
19
|
+
"directory": "packages/expo-plugin"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/h2nology/quiesco/issues"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"main": "./app.plugin.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./app.plugin.js",
|
|
33
|
+
"./app.plugin.js": "./app.plugin.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"app.plugin.js"
|
|
38
|
+
],
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@expo/config-plugins": "*"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
6
45
|
}
|