@oxy.so/app-preset 2.0.5 → 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/babel/index.js +2 -0
- package/babel/inline-oxy-build-id.js +20 -0
- package/build-id/index.js +27 -0
- package/metro/index.js +9 -0
- package/package.json +2 -1
package/babel/index.js
CHANGED
|
@@ -33,6 +33,8 @@ module.exports = function oxyBabelPreset(api) {
|
|
|
33
33
|
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.svg'],
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
|
+
// The build id `@oxy.so/services` busts its persisted caches on.
|
|
37
|
+
require.resolve('./inline-oxy-build-id'),
|
|
36
38
|
// Must be LAST.
|
|
37
39
|
'react-native-worklets/plugin',
|
|
38
40
|
],
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces `process.env.OXY_BUILD_ID` with the build id, in every module the
|
|
3
|
+
* app bundles. babel-preset-expo's own `EXPO_PUBLIC_*` inlining skips
|
|
4
|
+
* node_modules, which is exactly where `@oxy.so/services` reads it.
|
|
5
|
+
*/
|
|
6
|
+
const { resolveOxyBuildId } = require('../build-id');
|
|
7
|
+
|
|
8
|
+
module.exports = function inlineOxyBuildId({ types: t }) {
|
|
9
|
+
const buildId = resolveOxyBuildId();
|
|
10
|
+
return {
|
|
11
|
+
name: 'oxy-inline-build-id',
|
|
12
|
+
visitor: {
|
|
13
|
+
MemberExpression(path) {
|
|
14
|
+
if (!path.matchesPattern('process.env.OXY_BUILD_ID')) return;
|
|
15
|
+
if (path.parentPath.isAssignmentExpression({ left: path.node })) return;
|
|
16
|
+
path.replaceWith(t.stringLiteral(buildId));
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build identity `@oxy.so/services` busts every persisted query cache on
|
|
3
|
+
* (`getOxyBuildId`): a cache written by an older bundle, in an older shape, is
|
|
4
|
+
* never served to a newer one.
|
|
5
|
+
*
|
|
6
|
+
* The commit in CI, `git rev-parse HEAD` locally, and a constant in development
|
|
7
|
+
* so the dev transform cache survives commits. Metro's config resolves it
|
|
8
|
+
* first and publishes it as `OXY_BUILD_ID`, so the Babel workers it forks read
|
|
9
|
+
* the same value.
|
|
10
|
+
*/
|
|
11
|
+
const { execFileSync } = require('child_process');
|
|
12
|
+
|
|
13
|
+
function resolveOxyBuildId(projectRoot = process.cwd()) {
|
|
14
|
+
if (process.env.OXY_BUILD_ID) return process.env.OXY_BUILD_ID;
|
|
15
|
+
if (process.env.NODE_ENV !== 'production') return 'development';
|
|
16
|
+
const ciCommit = process.env.GITHUB_SHA || process.env.EAS_BUILD_GIT_COMMIT_HASH;
|
|
17
|
+
if (ciCommit) return ciCommit;
|
|
18
|
+
try {
|
|
19
|
+
return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: projectRoot, stdio: ['ignore', 'pipe', 'ignore'] })
|
|
20
|
+
.toString()
|
|
21
|
+
.trim();
|
|
22
|
+
} catch {
|
|
23
|
+
return `time-${Date.now()}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { resolveOxyBuildId };
|
package/metro/index.js
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
const { getDefaultConfig } = require('expo/metro-config');
|
|
36
36
|
const { withNativeWind } = require('nativewind/metro');
|
|
37
37
|
const path = require('path');
|
|
38
|
+
const { resolveOxyBuildId } = require('../build-id');
|
|
38
39
|
|
|
39
40
|
function blockPath(dir) {
|
|
40
41
|
const resolved = path.resolve(dir);
|
|
@@ -61,6 +62,14 @@ function createOxyMetroConfig(projectRoot, options = {}) {
|
|
|
61
62
|
const monorepoRoot = path.resolve(projectRoot, '../..');
|
|
62
63
|
const config = getDefaultConfig(projectRoot);
|
|
63
64
|
|
|
65
|
+
// The preset's Babel plugin inlines this id into every module, but Metro's
|
|
66
|
+
// transform cache key does not cover it: without the id in `cacheVersion`, a
|
|
67
|
+
// cached SDK module would keep an old build's id. Published so the Babel
|
|
68
|
+
// workers Metro forks resolve the same value.
|
|
69
|
+
const buildId = resolveOxyBuildId(projectRoot);
|
|
70
|
+
process.env.OXY_BUILD_ID = buildId;
|
|
71
|
+
config.cacheVersion = [config.cacheVersion, `oxy-build:${buildId}`].filter(Boolean).join('|');
|
|
72
|
+
|
|
64
73
|
config.projectRoot = projectRoot;
|
|
65
74
|
|
|
66
75
|
// Include the monorepo root so Metro resolves hoisted deps in root node_modules/.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
|
|
5
5
|
"main": "./app.plugin.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"plugin",
|
|
33
33
|
"metro",
|
|
34
34
|
"babel",
|
|
35
|
+
"build-id",
|
|
35
36
|
"eslint",
|
|
36
37
|
"certs",
|
|
37
38
|
"css",
|