Add mobile review diff and comment sheets (#2021)
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
a62b2ac173
commit
efc36b41d4
37 files changed
+2734
-3
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const root = process.cwd();
|
||||
const bunStorePath = join(root, "node_modules/.bun");
|
||||
|
||||
const packageDirs = [];
|
||||
|
||||
if (existsSync(join(root, "node_modules/@pierre/diffs"))) {
|
||||
packageDirs.push(join(root, "node_modules/@pierre/diffs"));
|
||||
}
|
||||
|
||||
if (existsSync(bunStorePath)) {
|
||||
for (const entry of readdirSync(bunStorePath)) {
|
||||
if (!entry.startsWith("@pierre+diffs@")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
packageDirs.push(join(bunStorePath, entry, "node_modules/@pierre/diffs"));
|
||||
}
|
||||
}
|
||||
|
||||
const utilsIndexJs = [
|
||||
'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
|
||||
"export {",
|
||||
" EXTENSION_TO_FILE_FORMAT,",
|
||||
" getCustomExtensionsMap,",
|
||||
" getCustomExtensionsVersion,",
|
||||
" getFiletypeFromFileName,",
|
||||
" replaceCustomExtensions,",
|
||||
" setCustomExtension,",
|
||||
'} from "./getFiletypeFromFileName.js";',
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
const utilsIndexDts = [
|
||||
'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
|
||||
"export {",
|
||||
" EXTENSION_TO_FILE_FORMAT,",
|
||||
" getCustomExtensionsMap,",
|
||||
" getCustomExtensionsVersion,",
|
||||
" getFiletypeFromFileName,",
|
||||
" replaceCustomExtensions,",
|
||||
" setCustomExtension,",
|
||||
'} from "./getFiletypeFromFileName.js";',
|
||||
'export type { ChangeTypes, FileDiffMetadata, ParsedPatch, SupportedLanguages } from "../types.js";',
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
let patchedCount = 0;
|
||||
let locatedCount = 0;
|
||||
|
||||
for (const packageDir of packageDirs) {
|
||||
if (!existsSync(packageDir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
locatedCount += 1;
|
||||
|
||||
const packageJsonPath = join(packageDir, "package.json");
|
||||
const utilsIndexJsPath = join(packageDir, "dist/utils/index.js");
|
||||
const utilsIndexDtsPath = join(packageDir, "dist/utils/index.d.ts");
|
||||
|
||||
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
||||
const currentUtilsExport = pkg.exports?.["./utils"];
|
||||
|
||||
const expectedUtilsExport = {
|
||||
types: "./dist/utils/index.d.ts",
|
||||
import: "./dist/utils/index.js",
|
||||
};
|
||||
|
||||
const needsExportPatch =
|
||||
currentUtilsExport?.types !== expectedUtilsExport.types ||
|
||||
currentUtilsExport?.import !== expectedUtilsExport.import;
|
||||
|
||||
if (needsExportPatch) {
|
||||
pkg.exports = {
|
||||
...pkg.exports,
|
||||
"./utils": expectedUtilsExport,
|
||||
};
|
||||
writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
||||
}
|
||||
|
||||
const currentJs = existsSync(utilsIndexJsPath) ? readFileSync(utilsIndexJsPath, "utf8") : null;
|
||||
if (currentJs !== utilsIndexJs) {
|
||||
writeFileSync(utilsIndexJsPath, utilsIndexJs);
|
||||
}
|
||||
|
||||
const currentDts = existsSync(utilsIndexDtsPath) ? readFileSync(utilsIndexDtsPath, "utf8") : null;
|
||||
if (currentDts !== utilsIndexDts) {
|
||||
writeFileSync(utilsIndexDtsPath, utilsIndexDts);
|
||||
}
|
||||
|
||||
if (needsExportPatch || currentJs !== utilsIndexJs || currentDts !== utilsIndexDts) {
|
||||
patchedCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (patchedCount > 0) {
|
||||
console.log(`[patch-pierre-diffs-utils] patched ${patchedCount} @pierre/diffs installation(s).`);
|
||||
} else if (locatedCount > 0) {
|
||||
console.log("[patch-pierre-diffs-utils] @pierre/diffs already patched.");
|
||||
} else {
|
||||
console.log("[patch-pierre-diffs-utils] @pierre/diffs not installed; skipping.");
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const root = process.cwd();
|
||||
|
||||
const candidates = [join(root, "node_modules/react-native-nitro-modules/package.json")];
|
||||
|
||||
const bunStorePath = join(root, "node_modules/.bun");
|
||||
|
||||
if (existsSync(bunStorePath)) {
|
||||
for (const entry of readdirSync(bunStorePath)) {
|
||||
if (!entry.startsWith("react-native-nitro-modules@")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
candidates.push(
|
||||
join(bunStorePath, entry, "node_modules/react-native-nitro-modules/package.json"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let patchedCount = 0;
|
||||
let locatedCount = 0;
|
||||
|
||||
for (const filePath of candidates) {
|
||||
if (!existsSync(filePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
locatedCount += 1;
|
||||
|
||||
const source = readFileSync(filePath, "utf8");
|
||||
const pkg = JSON.parse(source);
|
||||
|
||||
if (pkg.codegenConfig == null || typeof pkg.codegenConfig !== "object") {
|
||||
throw new Error(
|
||||
`Found react-native-nitro-modules package at ${filePath}, but codegenConfig was missing.`,
|
||||
);
|
||||
}
|
||||
|
||||
const iosConfig =
|
||||
pkg.codegenConfig.ios != null && typeof pkg.codegenConfig.ios === "object"
|
||||
? pkg.codegenConfig.ios
|
||||
: {};
|
||||
|
||||
const modulesProvider =
|
||||
iosConfig.modulesProvider != null && typeof iosConfig.modulesProvider === "object"
|
||||
? iosConfig.modulesProvider
|
||||
: {};
|
||||
|
||||
if (modulesProvider.NitroModules === "NativeNitroModules") {
|
||||
continue;
|
||||
}
|
||||
|
||||
modulesProvider.NitroModules = "NativeNitroModules";
|
||||
iosConfig.modulesProvider = modulesProvider;
|
||||
pkg.codegenConfig.ios = iosConfig;
|
||||
|
||||
writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`);
|
||||
patchedCount += 1;
|
||||
}
|
||||
|
||||
if (patchedCount > 0) {
|
||||
console.log(
|
||||
`[patch-react-native-nitro-modules] patched ${patchedCount} react-native-nitro-modules installation(s).`,
|
||||
);
|
||||
} else if (locatedCount > 0) {
|
||||
console.log("[patch-react-native-nitro-modules] react-native-nitro-modules already patched.");
|
||||
} else {
|
||||
console.log(
|
||||
"[patch-react-native-nitro-modules] react-native-nitro-modules not installed; skipping.",
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user