@oxy.so/app-preset 5.0.0 → 5.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/metro/fresh-workspace-builds.js +160 -0
- package/metro/index.js +14 -0
- package/metro/linked-native-packages.js +213 -0
- package/metro/source-stamp.js +98 -0
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refuse to put a workspace package's build output into a RELEASE bundle when
|
|
3
|
+
* it was not built from the sources the checkout holds.
|
|
4
|
+
*
|
|
5
|
+
* An app in this monorepo consumes `@oxy.so/core`, `@oxy.so/contracts`,
|
|
6
|
+
* `@oxy.so/protocol`, `@oxy.so/telemetry` and `@oxy.so/expo-splash` through
|
|
7
|
+
* their BUILT entry points (`dist/`), which nothing rebuilds when the checkout
|
|
8
|
+
* moves. Measured on Commons 1.3.0 (2026-10-25): the checkout was at the
|
|
9
|
+
* release commit but its `packages/contracts/dist` dated from five days
|
|
10
|
+
* earlier, written for Zod 3. `app/+native-intent.ts` imported
|
|
11
|
+
* `@oxy.so/contracts`, expo-router loads that file while it builds the linking
|
|
12
|
+
* config, and the stale `oauth.js` called `catalogToolSchema.innerType()` at
|
|
13
|
+
* module scope against Zod 4: `TypeError: undefined is not a function` on every
|
|
14
|
+
* launch. The bundle also carried a core from before the commit's own
|
|
15
|
+
* KeyManager changes. Nothing failed at build time; a phone found it.
|
|
16
|
+
*
|
|
17
|
+
* A package that opts in (`"oxySourceStamp": "dist"`, see `source-stamp.js`)
|
|
18
|
+
* writes a digest of its `src/` into its output at the end of every build. A
|
|
19
|
+
* release bundle (Metro `dev: false`, or NODE_ENV=production) that reaches that
|
|
20
|
+
* output fails when the stamp is missing or does not match the sources, naming
|
|
21
|
+
* the command that rebuilds it; a development bundle warns once. A package that
|
|
22
|
+
* does not opt in is only compared by mtime, and only ever warned about: an
|
|
23
|
+
* mtime cannot tell a checkout round trip from an edit.
|
|
24
|
+
*/
|
|
25
|
+
const fs = require('node:fs');
|
|
26
|
+
const path = require('node:path');
|
|
27
|
+
const { readStamp, sourceDigest, stampedOutputDir } = require('./source-stamp');
|
|
28
|
+
|
|
29
|
+
const OUTPUT_DIRS = new Set(['dist', 'lib', 'build']);
|
|
30
|
+
const IGNORED =
|
|
31
|
+
/(?:^|[/\\])(?:__tests__|__mocks__)(?:[/\\]|$)|\.(?:test|spec)\.[cm]?[jt]sx?$|\.md$/;
|
|
32
|
+
|
|
33
|
+
function newestMtime(dir, ignore) {
|
|
34
|
+
let newest = 0;
|
|
35
|
+
let newestFile = null;
|
|
36
|
+
const stack = [dir];
|
|
37
|
+
while (stack.length > 0) {
|
|
38
|
+
const current = stack.pop();
|
|
39
|
+
let entries;
|
|
40
|
+
try {
|
|
41
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
42
|
+
} catch {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const full = path.join(current, entry.name);
|
|
47
|
+
if (ignore?.test(full)) continue;
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
if (entry.name !== 'node_modules') stack.push(full);
|
|
50
|
+
} else if (entry.isFile()) {
|
|
51
|
+
const { mtimeMs } = fs.statSync(full);
|
|
52
|
+
if (mtimeMs > newest) {
|
|
53
|
+
newest = mtimeMs;
|
|
54
|
+
newestFile = full;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { newest, newestFile };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether `packageDir/outputDir` was built from `packageDir/src` as it is now.
|
|
64
|
+
* `null` when it was (or there is nothing to compare); otherwise
|
|
65
|
+
* `{ stamped, reason }`, where `stamped` says the verdict is exact (a source
|
|
66
|
+
* stamp) rather than an mtime guess.
|
|
67
|
+
*/
|
|
68
|
+
function staleBuild(packageDir, outputDir) {
|
|
69
|
+
const srcDir = path.join(packageDir, 'src');
|
|
70
|
+
const outDir = path.join(packageDir, outputDir);
|
|
71
|
+
if (!fs.existsSync(srcDir) || !fs.existsSync(outDir)) return null;
|
|
72
|
+
|
|
73
|
+
if (stampedOutputDir(packageDir) === outputDir) {
|
|
74
|
+
const stamp = readStamp(packageDir, outputDir);
|
|
75
|
+
if (stamp === null) {
|
|
76
|
+
return {
|
|
77
|
+
stamped: true,
|
|
78
|
+
reason: `${outputDir}/ carries no source stamp (built before stamping)`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (stamp !== sourceDigest(packageDir)) {
|
|
82
|
+
return { stamped: true, reason: `src/ changed since ${outputDir}/ was built` };
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const source = newestMtime(srcDir, IGNORED);
|
|
88
|
+
const output = newestMtime(outDir, null);
|
|
89
|
+
if (source.newest > output.newest) {
|
|
90
|
+
return {
|
|
91
|
+
stamped: false,
|
|
92
|
+
reason: `${path.relative(packageDir, source.newestFile)} is newer than ${outputDir}/`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {import('metro-config').MetroConfig} config
|
|
100
|
+
* @param {string} monorepoRoot
|
|
101
|
+
* @param {{ production?: boolean, warn?: (message: string) => void }} [deps] Test seams.
|
|
102
|
+
* @returns {import('metro-config').MetroConfig}
|
|
103
|
+
*/
|
|
104
|
+
function withFreshWorkspaceBuilds(config, monorepoRoot, deps = {}) {
|
|
105
|
+
// A release bundle: Metro's own `dev: false` (what `expo export:embed` in the
|
|
106
|
+
// Gradle/Xcode release task passes), or NODE_ENV=production.
|
|
107
|
+
const isProduction = (context) =>
|
|
108
|
+
deps.production ?? (context.dev === false || process.env.NODE_ENV === 'production');
|
|
109
|
+
const warn = deps.warn ?? ((message) => console.warn(message));
|
|
110
|
+
const packagesDir = `${path.resolve(monorepoRoot, 'packages')}${path.sep}`;
|
|
111
|
+
const parentResolveRequest = config.resolver.resolveRequest;
|
|
112
|
+
const verdicts = new Map();
|
|
113
|
+
const warned = new Set();
|
|
114
|
+
|
|
115
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
116
|
+
const resolution = (parentResolveRequest ?? context.resolveRequest)(
|
|
117
|
+
context,
|
|
118
|
+
moduleName,
|
|
119
|
+
platform,
|
|
120
|
+
);
|
|
121
|
+
if (resolution?.type !== 'sourceFile') return resolution;
|
|
122
|
+
let filePath = resolution.filePath;
|
|
123
|
+
try {
|
|
124
|
+
filePath = fs.realpathSync(filePath);
|
|
125
|
+
} catch {
|
|
126
|
+
return resolution;
|
|
127
|
+
}
|
|
128
|
+
if (!filePath.startsWith(packagesDir)) return resolution;
|
|
129
|
+
const [packageName, outputDir] = filePath.slice(packagesDir.length).split(path.sep);
|
|
130
|
+
if (!packageName || !OUTPUT_DIRS.has(outputDir)) return resolution;
|
|
131
|
+
|
|
132
|
+
const key = `${packageName}/${outputDir}`;
|
|
133
|
+
if (!verdicts.has(key)) {
|
|
134
|
+
verdicts.set(key, staleBuild(path.join(packagesDir, packageName), outputDir));
|
|
135
|
+
}
|
|
136
|
+
const stale = verdicts.get(key);
|
|
137
|
+
if (!stale) return resolution;
|
|
138
|
+
|
|
139
|
+
const rebuild = `bunx turbo run build --filter=./packages/${packageName}`;
|
|
140
|
+
if (stale.stamped && isProduction(context)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[@oxy.so/app-preset/metro] refusing to bundle packages/${key}: ${stale.reason}. ` +
|
|
143
|
+
'A release would ship code this checkout does not contain. Run ' +
|
|
144
|
+
`\`${rebuild}\` (or \`bun run build:all\`) at the repository root, then build again.`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (!warned.has(key)) {
|
|
148
|
+
warned.add(key);
|
|
149
|
+
warn(
|
|
150
|
+
`[@oxy.so/app-preset/metro] packages/${key} may be out of date: ${stale.reason}; ` +
|
|
151
|
+
`run \`${rebuild}\`.`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return resolution;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return config;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = { withFreshWorkspaceBuilds, staleBuild };
|
package/metro/index.js
CHANGED
|
@@ -49,6 +49,8 @@ const path = require('node:path');
|
|
|
49
49
|
const { resolveOxyBuildId } = require('../build-id');
|
|
50
50
|
const { requireFromProject } = require('../plugin/requireFromProject');
|
|
51
51
|
const { withStaticHydrationBoundary } = require('./static-hydration/resolver');
|
|
52
|
+
const { withLinkedNativePackagesOnly } = require('./linked-native-packages');
|
|
53
|
+
const { withFreshWorkspaceBuilds } = require('./fresh-workspace-builds');
|
|
52
54
|
|
|
53
55
|
function escapeRegExp(value) {
|
|
54
56
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -391,6 +393,16 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
|
|
|
391
393
|
let config = withBloomSingleInstance(nativeWindConfig, projectRoot);
|
|
392
394
|
if (staticHydrationBoundary) config = withStaticHydrationBoundary(config, projectRoot);
|
|
393
395
|
if (workletsBundleMode) config = withWorkletsBundleMode(config, projectRoot);
|
|
396
|
+
// Sees every resolution but the complete-react-native module's own two
|
|
397
|
+
// imports: an optional probe for a native package autolinking does not link
|
|
398
|
+
// is answered "not found" (see the module header for the launch crash).
|
|
399
|
+
config = withLinkedNativePackagesOnly(config, projectRoot);
|
|
400
|
+
// A production bundle never ships a workspace package's build output that is
|
|
401
|
+
// older than its sources (the same launch crash, second cause).
|
|
402
|
+
config = withFreshWorkspaceBuilds(
|
|
403
|
+
config,
|
|
404
|
+
options.workspaceRoot ? path.resolve(options.workspaceRoot) : findWorkspaceRoot(projectRoot),
|
|
405
|
+
);
|
|
394
406
|
// Outermost, so it sees the final resolution and its own module's imports
|
|
395
407
|
// reach no redirect beneath it.
|
|
396
408
|
return withCompleteReactNative(config, projectRoot);
|
|
@@ -401,4 +413,6 @@ module.exports = {
|
|
|
401
413
|
findWorkspaceRoot,
|
|
402
414
|
withBloomSingleInstance,
|
|
403
415
|
withCompleteReactNative,
|
|
416
|
+
withLinkedNativePackagesOnly,
|
|
417
|
+
withFreshWorkspaceBuilds,
|
|
404
418
|
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep native packages the build does not link out of the bundle's OPTIONAL
|
|
3
|
+
* requires.
|
|
4
|
+
*
|
|
5
|
+
* An optional require (`try { require('x') } catch {}`, an `import()` in a
|
|
6
|
+
* `try`) is how libraries probe for an optional peer: expo-router probes for
|
|
7
|
+
* `@expo/ui`, @oxy.so/protocol for `expo-crypto`, @oxy.so/services for
|
|
8
|
+
* `expo-clipboard`. Metro resolves the probe against whatever is on disk. Expo
|
|
9
|
+
* autolinking decides what native code the binary carries by a different rule:
|
|
10
|
+
* the app's dependencies and devDependencies, then, recursively, each
|
|
11
|
+
* package's dependencies and NON-optional peers. When the two disagree, the JS
|
|
12
|
+
* of a package whose native half is not in the binary is bundled, the probe
|
|
13
|
+
* succeeds, and that JS runs against native code that is not there.
|
|
14
|
+
*
|
|
15
|
+
* Measured on Commons 1.3.0 (2026-10-25): a checkout's bun store kept a stale
|
|
16
|
+
* `node_modules/.bun/node_modules/@expo/ui` (@expo/ui 57.0.17, from an old
|
|
17
|
+
* install, absent from bun.lock). Node's resolution walks up into that hoisted
|
|
18
|
+
* fallback, so expo-router's `@expo/ui/jetpack-compose` probe found it, the
|
|
19
|
+
* SDK 57 JS ran its side effects against an SDK 58 binary that never linked
|
|
20
|
+
* it, and the release crashed on launch (`Exception in HostFunction:
|
|
21
|
+
* ... getClass() on a null object reference`, then `TypeError: undefined is not
|
|
22
|
+
* a function`). A clean install has no such file and the same commit ran.
|
|
23
|
+
*
|
|
24
|
+
* So an optional request that resolves into a native package autolinking will
|
|
25
|
+
* not link is answered "not found", which is what the probe sees on a clean
|
|
26
|
+
* install: the library takes its documented fallback. Non-optional requests
|
|
27
|
+
* are left alone (a static import of an unlinked native package is reported
|
|
28
|
+
* once as a warning, not turned into a build failure), so this never changes
|
|
29
|
+
* what an app that builds today bundles, except for those probes.
|
|
30
|
+
*/
|
|
31
|
+
const fs = require('node:fs');
|
|
32
|
+
const path = require('node:path');
|
|
33
|
+
const Module = require('node:module');
|
|
34
|
+
|
|
35
|
+
/** Expo autolinking's own recursion limit (`resolution.js` MAX_DEPTH). */
|
|
36
|
+
const MAX_DEPTH = 9;
|
|
37
|
+
|
|
38
|
+
function readJson(file) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function realpathOrNull(target) {
|
|
47
|
+
try {
|
|
48
|
+
return fs.realpathSync(target);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isOptionalPeer(manifest, name) {
|
|
55
|
+
const meta = manifest.peerDependenciesMeta;
|
|
56
|
+
return Boolean(meta?.[name]?.optional);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The names Expo autolinking links for the app at `projectRoot`, computed by
|
|
61
|
+
* the rules of expo-modules-autolinking 58 (`dependencies/resolution.js`): the
|
|
62
|
+
* app's dependencies + devDependencies, then each package's dependencies and
|
|
63
|
+
* non-optional peers, resolved through the node_modules chain of the package
|
|
64
|
+
* that declares them, to depth {@link MAX_DEPTH}.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} projectRoot
|
|
67
|
+
* @returns {Set<string>}
|
|
68
|
+
*/
|
|
69
|
+
function computeLinkedPackageNames(projectRoot) {
|
|
70
|
+
const linked = new Set();
|
|
71
|
+
const shallowestDepth = new Map();
|
|
72
|
+
|
|
73
|
+
const visit = (packageDir, depth) => {
|
|
74
|
+
const seen = shallowestDepth.get(packageDir);
|
|
75
|
+
if (seen !== undefined && seen <= depth) return;
|
|
76
|
+
shallowestDepth.set(packageDir, depth);
|
|
77
|
+
const manifest = readJson(path.join(packageDir, 'package.json'));
|
|
78
|
+
if (!manifest || depth >= MAX_DEPTH) return;
|
|
79
|
+
|
|
80
|
+
const names = new Set(Object.keys(manifest.dependencies || {}));
|
|
81
|
+
if (depth === 0) {
|
|
82
|
+
for (const name of Object.keys(manifest.devDependencies || {})) names.add(name);
|
|
83
|
+
}
|
|
84
|
+
for (const name of Object.keys(manifest.peerDependencies || {})) {
|
|
85
|
+
if (!isOptionalPeer(manifest, name)) names.add(name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const lookupDirs = Module._nodeModulePaths(packageDir);
|
|
89
|
+
for (const name of names) {
|
|
90
|
+
for (const dir of lookupDirs) {
|
|
91
|
+
const resolved = realpathOrNull(path.join(dir, name));
|
|
92
|
+
if (resolved) {
|
|
93
|
+
linked.add(name);
|
|
94
|
+
visit(resolved, depth + 1);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const root = realpathOrNull(projectRoot);
|
|
102
|
+
if (root) visit(root, 0);
|
|
103
|
+
return linked;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The package a file belongs to: the nearest ancestor `package.json` that has
|
|
108
|
+
* a `name` (a nested `{"type":"module"}` manifest has none and is skipped).
|
|
109
|
+
*/
|
|
110
|
+
function createPackageLookup() {
|
|
111
|
+
const cache = new Map();
|
|
112
|
+
return function packageOf(filePath) {
|
|
113
|
+
let dir = path.dirname(filePath);
|
|
114
|
+
const visited = [];
|
|
115
|
+
let found = null;
|
|
116
|
+
for (;;) {
|
|
117
|
+
if (cache.has(dir)) {
|
|
118
|
+
found = cache.get(dir);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
visited.push(dir);
|
|
122
|
+
const manifest = readJson(path.join(dir, 'package.json'));
|
|
123
|
+
if (manifest && typeof manifest.name === 'string') {
|
|
124
|
+
found = { name: manifest.name, version: manifest.version, dir };
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
const parent = path.dirname(dir);
|
|
128
|
+
if (parent === dir) break;
|
|
129
|
+
dir = parent;
|
|
130
|
+
}
|
|
131
|
+
for (const entry of visited) cache.set(entry, found);
|
|
132
|
+
return found;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** True when a package carries native code autolinking would have to link. */
|
|
137
|
+
function createNativeCheck() {
|
|
138
|
+
const cache = new Map();
|
|
139
|
+
return function isNativePackage(pkg) {
|
|
140
|
+
if (!cache.has(pkg.dir)) {
|
|
141
|
+
cache.set(
|
|
142
|
+
pkg.dir,
|
|
143
|
+
fs.existsSync(path.join(pkg.dir, 'expo-module.config.json')) ||
|
|
144
|
+
fs.existsSync(path.join(pkg.dir, 'android', 'build.gradle')) ||
|
|
145
|
+
fs.existsSync(path.join(pkg.dir, 'android', 'build.gradle.kts')),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return cache.get(pkg.dir);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Wrap `config.resolver.resolveRequest` so an OPTIONAL request on a native
|
|
154
|
+
* platform that resolves into a native package autolinking does not link
|
|
155
|
+
* throws, which Metro records as a missing optional dependency.
|
|
156
|
+
*
|
|
157
|
+
* @param {import('metro-config').MetroConfig} config
|
|
158
|
+
* @param {string} projectRoot
|
|
159
|
+
* @param {{ computeLinked?: (projectRoot: string) => Set<string>, warn?: (message: string) => void }} [deps]
|
|
160
|
+
* Test seams.
|
|
161
|
+
* @returns {import('metro-config').MetroConfig}
|
|
162
|
+
*/
|
|
163
|
+
function withLinkedNativePackagesOnly(config, projectRoot, deps = {}) {
|
|
164
|
+
const computeLinked = deps.computeLinked ?? computeLinkedPackageNames;
|
|
165
|
+
const warn = deps.warn ?? ((message) => console.warn(message));
|
|
166
|
+
const parentResolveRequest = config.resolver.resolveRequest;
|
|
167
|
+
const packageOf = createPackageLookup();
|
|
168
|
+
const isNativePackage = createNativeCheck();
|
|
169
|
+
const reported = new Set();
|
|
170
|
+
let linked = null;
|
|
171
|
+
|
|
172
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
173
|
+
const resolution = (parentResolveRequest ?? context.resolveRequest)(
|
|
174
|
+
context,
|
|
175
|
+
moduleName,
|
|
176
|
+
platform,
|
|
177
|
+
);
|
|
178
|
+
if (platform === 'web' || resolution?.type !== 'sourceFile') return resolution;
|
|
179
|
+
const pkg = packageOf(resolution.filePath);
|
|
180
|
+
if (!pkg || !isNativePackage(pkg)) return resolution;
|
|
181
|
+
linked ??= computeLinked(projectRoot);
|
|
182
|
+
if (linked.has(pkg.name)) return resolution;
|
|
183
|
+
|
|
184
|
+
const optional = context.dependency?.data?.isOptional === true;
|
|
185
|
+
const key = `${pkg.name}@${pkg.version}`;
|
|
186
|
+
if (optional) {
|
|
187
|
+
if (!reported.has(`optional:${key}`)) {
|
|
188
|
+
reported.add(`optional:${key}`);
|
|
189
|
+
warn(
|
|
190
|
+
`[@oxy.so/app-preset/metro] left ${key} out of an optional require ` +
|
|
191
|
+
`('${moduleName}'): it has native code this build does not autolink ` +
|
|
192
|
+
'(not a dependency of the app, nor a non-optional dependency of one). ' +
|
|
193
|
+
`Found at ${pkg.dir}.`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
throw new Error(
|
|
197
|
+
`${moduleName} resolves to ${key}, a native package this build does not link`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (!reported.has(`static:${key}`)) {
|
|
201
|
+
reported.add(`static:${key}`);
|
|
202
|
+
warn(
|
|
203
|
+
`[@oxy.so/app-preset/metro] ${key} is bundled ('${moduleName}') but has native code ` +
|
|
204
|
+
'this build does not autolink; declare it as a dependency of the app.',
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return resolution;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
return config;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = { withLinkedNativePackagesOnly, computeLinkedPackageNames };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The source stamp: a digest of a workspace package's `src/`, written into its
|
|
4
|
+
* build output by its build, and checked by the Metro guard
|
|
5
|
+
* (`fresh-workspace-builds.js`) before a release bundle uses that output.
|
|
6
|
+
*
|
|
7
|
+
* Content, not mtimes: a `git checkout` there and back gives the sources new
|
|
8
|
+
* mtimes without changing them, and turbo then (correctly) replays its cache
|
|
9
|
+
* without rewriting the output, so an mtime comparison would refuse a build
|
|
10
|
+
* that is fine and name a command (`build:all`) that cannot fix it.
|
|
11
|
+
*
|
|
12
|
+
* A package opts in with `"oxySourceStamp": "<output dir>"` in its
|
|
13
|
+
* package.json and, last in its `build` (cwd = the package), calls
|
|
14
|
+
* `writeStamp(process.cwd())` from this file when the file is there:
|
|
15
|
+
*
|
|
16
|
+
* node -e "const p='../app-preset/metro/source-stamp.js';require('node:fs').existsSync(p)&&require(p).writeStamp(process.cwd())"
|
|
17
|
+
*
|
|
18
|
+
* The guard is for builds that never reach Metro: the API and node Docker
|
|
19
|
+
* images copy only the packages they build, not app-preset, and a missing
|
|
20
|
+
* stamp only matters to a Metro release bundle, which then refuses it. The
|
|
21
|
+
* stamp is `<output dir>/.oxy-source-digest`.
|
|
22
|
+
*/
|
|
23
|
+
const crypto = require('node:crypto');
|
|
24
|
+
const fs = require('node:fs');
|
|
25
|
+
const path = require('node:path');
|
|
26
|
+
|
|
27
|
+
const STAMP_FILE = '.oxy-source-digest';
|
|
28
|
+
|
|
29
|
+
/** Not part of what a build compiles: tests, mocks, docs. */
|
|
30
|
+
const IGNORED =
|
|
31
|
+
/(?:^|[/\\])(?:__tests__|__mocks__)(?:[/\\]|$)|\.(?:test|spec)\.[cm]?[jt]sx?$|\.md$/;
|
|
32
|
+
|
|
33
|
+
function listFiles(dir) {
|
|
34
|
+
const out = [];
|
|
35
|
+
const stack = [dir];
|
|
36
|
+
while (stack.length > 0) {
|
|
37
|
+
const current = stack.pop();
|
|
38
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
39
|
+
const full = path.join(current, entry.name);
|
|
40
|
+
if (IGNORED.test(full)) continue;
|
|
41
|
+
if (entry.isDirectory()) {
|
|
42
|
+
if (entry.name !== 'node_modules') stack.push(full);
|
|
43
|
+
} else if (entry.isFile()) {
|
|
44
|
+
out.push(full);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** sha256 over every source file's relative path and bytes, in a stable order. */
|
|
52
|
+
function sourceDigest(packageDir) {
|
|
53
|
+
const srcDir = path.join(packageDir, 'src');
|
|
54
|
+
const files = listFiles(srcDir)
|
|
55
|
+
.map((file) => path.relative(srcDir, file).split(path.sep).join('/'))
|
|
56
|
+
.sort();
|
|
57
|
+
const hash = crypto.createHash('sha256');
|
|
58
|
+
for (const relative of files) {
|
|
59
|
+
hash.update(relative);
|
|
60
|
+
hash.update('\0');
|
|
61
|
+
hash.update(fs.readFileSync(path.join(srcDir, relative)));
|
|
62
|
+
hash.update('\0');
|
|
63
|
+
}
|
|
64
|
+
return hash.digest('hex');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The output directory a package stamps, or `null` when it does not opt in. */
|
|
68
|
+
function stampedOutputDir(packageDir) {
|
|
69
|
+
try {
|
|
70
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
|
|
71
|
+
return typeof manifest.oxySourceStamp === 'string' ? manifest.oxySourceStamp : null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readStamp(packageDir, outputDir) {
|
|
78
|
+
try {
|
|
79
|
+
return fs.readFileSync(path.join(packageDir, outputDir, STAMP_FILE), 'utf8').trim();
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function writeStamp(packageDir) {
|
|
86
|
+
const outputDir = stampedOutputDir(packageDir);
|
|
87
|
+
if (!outputDir) {
|
|
88
|
+
throw new Error(`${packageDir}/package.json declares no "oxySourceStamp" output directory`);
|
|
89
|
+
}
|
|
90
|
+
fs.mkdirSync(path.join(packageDir, outputDir), { recursive: true });
|
|
91
|
+
fs.writeFileSync(path.join(packageDir, outputDir, STAMP_FILE), `${sourceDigest(packageDir)}\n`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (require.main === module) {
|
|
95
|
+
writeStamp(process.cwd());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { STAMP_FILE, sourceDigest, stampedOutputDir, readStamp, writeStamp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.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": {
|