Chore: mobile sdk refinements (#858)

* Add sdk-alpha package with MRZ helper

* chore: add migration report script

* Add lint config and MRZ tests to sdk-alpha

* fix tests

* fixes. wip

* fixes

* fix bundler tests

* mrz improvements based on cr feedback

* prettier

* fix build errors

* Document browser shim (#859)

* Validate required adapters (#861)

* Use sdkError for web scanner shim (#862)

* Document new workspaces in AGENTS (#864)

* Add client tests (#860)

* Use deep merge for client config (#863)

* Add config merge helper

* format

* Add SDK alpha CI workflow (#865)

* rename

* rename file

* update workflow

* coderabbit feedback and fixes

* fix linter

* fix import paths

* wip fixes

* updates

* fix tests

* formatting

* update workflow

* remove console mocks

* rename folder and fixes

* fix tests

* save wip

* auto format on save for all sdk package files

* fixes

* cr feedback

* fix pipelines
This commit is contained in:
Justin Hernandez
2025-08-09 17:14:56 -07:00
committed by GitHub
parent 5356b8b5e0
commit b59dbe1b05
47 changed files with 1867 additions and 397 deletions

View File

@@ -0,0 +1,22 @@
import { readdir, readFile } from 'node:fs/promises';
import { join } from 'node:path';
const dist = new URL('../dist/', import.meta.url);
const files = await readdir(dist);
const report = {};
for (const f of files) {
if (!f.endsWith('.js')) continue;
const src = await readFile(join(dist.pathname, f), 'utf8');
const direct = [...src.matchAll(/export\s+(?:const|function|class|let|var)\s+([A-Za-z0-9_$]+)/g)].map(m => m[1]);
const re = [...src.matchAll(/export\s*{([^}]+)}/g)]
.flatMap(m => m[1].split(',').map(s => s.trim()))
.map(s => s.split('\s+as\s+').pop())
.filter(name => name && name !== 'default');
report[f] = [...direct, ...re];
}
console.log('Exported symbols by file:');
for (const [file, names] of Object.entries(report)) {
console.log(`- ${file}: ${names.join(', ') || '(none)'}`);
}

View File

@@ -0,0 +1,22 @@
// Dev-only script to ensure named exports only and ESM shape (ok to use Node here)
import { readFile } from 'node:fs/promises';
import { readdir } from 'node:fs/promises';
import { join } from 'node:path';
const dist = new URL('../dist/', import.meta.url);
const files = await readdir(dist);
let hasDefault = false;
for (const f of files) {
if (!f.endsWith('.js')) continue;
const src = await readFile(join(dist.pathname, f), 'utf8');
if (/\bexport\s+default\b/.test(src)) {
console.error(`Default export found in dist/${f}`);
hasDefault = true;
}
}
if (hasDefault) {
process.exitCode = 1;
} else {
console.log('OK: no default exports, ESM build looks clean.');
}

View File

@@ -0,0 +1,32 @@
import { URL } from 'node:url';
import { readFile } from 'node:fs/promises';
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
const errors = [];
if (pkg.type !== 'module') errors.push('package.json must set type: module');
if (!pkg.exports || !pkg.exports['.']) errors.push("package.json must define conditional exports for '.'");
if (pkg.sideEffects !== false) errors.push('package.json must set sideEffects: false for tree-shaking');
if (!pkg.scripts?.build?.includes('tsup')) errors.push('build script should use tsup');
// Check for environment-specific exports
const dotExports = pkg.exports?.['.'];
if (dotExports && typeof dotExports === 'object') {
if (!dotExports.browser) errors.push("exports['.'] must include 'browser' condition for web environments");
if (!dotExports['react-native'])
errors.push("exports['.'] must include 'react-native' condition for React Native environments");
}
// Check for types exports
if (!dotExports?.types && !pkg.types) {
errors.push("Either exports['.'].types or pkg.types must be defined for TypeScript support");
}
if (errors.length) {
console.error('Export conditions validation failed:');
for (const e of errors) console.error(' - ' + e);
process.exit(1);
} else {
console.log('OK: export conditions & packaging validated.');
}