History

Add mobile review diff and comment sheets (#2021)

Julius Marminge committed 7 months ago

Commit efc36b41 parent a62b2ac37 files · +2732 −1Browse files

Showing the changes to scripts (2 of 37 files). Show all

Unified · Split

2 files
  1. scripts/patch-pierre-diffs-utils.mjs +105 −0
  2. scripts/patch-react-native-nitro-modules.mjs +73 −0
scripts/patch-pierre-diffs-utils.mjs+105−0
@@ -0,0 +1,105 @@
1import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const root = process.cwd();
5const bunStorePath = join(root, "node_modules/.bun");
6
7const packageDirs = [];
8
9if (existsSync(join(root, "node_modules/@pierre/diffs"))) {
10 packageDirs.push(join(root, "node_modules/@pierre/diffs"));
11}
12
13if (existsSync(bunStorePath)) {
14 for (const entry of readdirSync(bunStorePath)) {
15 if (!entry.startsWith("@pierre+diffs@")) {
16 continue;
17 }
18
19 packageDirs.push(join(bunStorePath, entry, "node_modules/@pierre/diffs"));
20 }
21}
22
23const utilsIndexJs = [
24 'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
25 "export {",
26 " EXTENSION_TO_FILE_FORMAT,",
27 " getCustomExtensionsMap,",
28 " getCustomExtensionsVersion,",
29 " getFiletypeFromFileName,",
30 " replaceCustomExtensions,",
31 " setCustomExtension,",
32 '} from "./getFiletypeFromFileName.js";',
33 "",
34].join("\n");
35
36const utilsIndexDts = [
37 'export { parsePatchFiles, processFile, processPatch } from "./parsePatchFiles.js";',
38 "export {",
39 " EXTENSION_TO_FILE_FORMAT,",
40 " getCustomExtensionsMap,",
41 " getCustomExtensionsVersion,",
42 " getFiletypeFromFileName,",
43 " replaceCustomExtensions,",
44 " setCustomExtension,",
45 '} from "./getFiletypeFromFileName.js";',
46 'export type { ChangeTypes, FileDiffMetadata, ParsedPatch, SupportedLanguages } from "../types.js";',
47 "",
48].join("\n");
49
50let patchedCount = 0;
51let locatedCount = 0;
52
53for (const packageDir of packageDirs) {
54 if (!existsSync(packageDir)) {
55 continue;
56 }
57
58 locatedCount += 1;
59
60 const packageJsonPath = join(packageDir, "package.json");
61 const utilsIndexJsPath = join(packageDir, "dist/utils/index.js");
62 const utilsIndexDtsPath = join(packageDir, "dist/utils/index.d.ts");
63
64 const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
65 const currentUtilsExport = pkg.exports?.["./utils"];
66
67 const expectedUtilsExport = {
68 types: "./dist/utils/index.d.ts",
69 import: "./dist/utils/index.js",
70 };
71
72 const needsExportPatch =
73 currentUtilsExport?.types !== expectedUtilsExport.types ||
74 currentUtilsExport?.import !== expectedUtilsExport.import;
75
76 if (needsExportPatch) {
77 pkg.exports = {
78 ...pkg.exports,
79 "./utils": expectedUtilsExport,
80 };
81 writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
82 }
83
84 const currentJs = existsSync(utilsIndexJsPath) ? readFileSync(utilsIndexJsPath, "utf8") : null;
85 if (currentJs !== utilsIndexJs) {
86 writeFileSync(utilsIndexJsPath, utilsIndexJs);
87 }
88
89 const currentDts = existsSync(utilsIndexDtsPath) ? readFileSync(utilsIndexDtsPath, "utf8") : null;
90 if (currentDts !== utilsIndexDts) {
91 writeFileSync(utilsIndexDtsPath, utilsIndexDts);
92 }
93
94 if (needsExportPatch || currentJs !== utilsIndexJs || currentDts !== utilsIndexDts) {
95 patchedCount += 1;
96 }
97}
98
99if (patchedCount > 0) {
100 console.log(`[patch-pierre-diffs-utils] patched ${patchedCount} @pierre/diffs installation(s).`);
101} else if (locatedCount > 0) {
102 console.log("[patch-pierre-diffs-utils] @pierre/diffs already patched.");
103} else {
104 console.log("[patch-pierre-diffs-utils] @pierre/diffs not installed; skipping.");
105}
scripts/patch-react-native-nitro-modules.mjs+73−0
@@ -0,0 +1,73 @@
1import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const root = process.cwd();
5
6const candidates = [join(root, "node_modules/react-native-nitro-modules/package.json")];
7
8const bunStorePath = join(root, "node_modules/.bun");
9
10if (existsSync(bunStorePath)) {
11 for (const entry of readdirSync(bunStorePath)) {
12 if (!entry.startsWith("react-native-nitro-modules@")) {
13 continue;
14 }
15
16 candidates.push(
17 join(bunStorePath, entry, "node_modules/react-native-nitro-modules/package.json"),
18 );
19 }
20}
21
22let patchedCount = 0;
23let locatedCount = 0;
24
25for (const filePath of candidates) {
26 if (!existsSync(filePath)) {
27 continue;
28 }
29
30 locatedCount += 1;
31
32 const source = readFileSync(filePath, "utf8");
33 const pkg = JSON.parse(source);
34
35 if (pkg.codegenConfig == null || typeof pkg.codegenConfig !== "object") {
36 throw new Error(
37 `Found react-native-nitro-modules package at ${filePath}, but codegenConfig was missing.`,
38 );
39 }
40
41 const iosConfig =
42 pkg.codegenConfig.ios != null && typeof pkg.codegenConfig.ios === "object"
43 ? pkg.codegenConfig.ios
44 : {};
45
46 const modulesProvider =
47 iosConfig.modulesProvider != null && typeof iosConfig.modulesProvider === "object"
48 ? iosConfig.modulesProvider
49 : {};
50
51 if (modulesProvider.NitroModules === "NativeNitroModules") {
52 continue;
53 }
54
55 modulesProvider.NitroModules = "NativeNitroModules";
56 iosConfig.modulesProvider = modulesProvider;
57 pkg.codegenConfig.ios = iosConfig;
58
59 writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`);
60 patchedCount += 1;
61}
62
63if (patchedCount > 0) {
64 console.log(
65 `[patch-react-native-nitro-modules] patched ${patchedCount} react-native-nitro-modules installation(s).`,
66 );
67} else if (locatedCount > 0) {
68 console.log("[patch-react-native-nitro-modules] react-native-nitro-modules already patched.");
69} else {
70 console.log(
71 "[patch-react-native-nitro-modules] react-native-nitro-modules not installed; skipping.",
72 );
73}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t