react-native-asset 2.2.10 → 2.2.13

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.
Files changed (45) hide show
  1. package/esm/clean-assets/android.js +2 -2
  2. package/esm/clean-assets/ios.d.ts.map +1 -1
  3. package/esm/clean-assets/ios.js +14 -10
  4. package/esm/copy-assets/ios.d.ts +1 -1
  5. package/esm/copy-assets/ios.d.ts.map +1 -1
  6. package/esm/copy-assets/ios.js +16 -10
  7. package/esm/main.js +3 -3
  8. package/esm/react-native-lib/ios/getBuildProperty.d.ts +1 -8
  9. package/esm/react-native-lib/ios/getBuildProperty.d.ts.map +1 -1
  10. package/esm/react-native-lib/ios/getBuildProperty.js +3 -3
  11. package/esm/react-native-lib/ios/getPlist.d.ts +1 -1
  12. package/esm/react-native-lib/ios/getPlist.d.ts.map +1 -1
  13. package/esm/react-native-lib/ios/getPlist.js +2 -2
  14. package/esm/react-native-lib/ios/getPlistPath.d.ts +1 -1
  15. package/esm/react-native-lib/ios/getPlistPath.d.ts.map +1 -1
  16. package/esm/react-native-lib/ios/getPlistPath.js +2 -2
  17. package/esm/react-native-lib/ios/writePlist.d.ts +1 -1
  18. package/esm/react-native-lib/ios/writePlist.d.ts.map +1 -1
  19. package/esm/react-native-lib/ios/writePlist.js +2 -2
  20. package/esm/utils.d.ts +10 -0
  21. package/esm/utils.d.ts.map +1 -0
  22. package/esm/utils.js +12 -0
  23. package/package.json +1 -1
  24. package/script/clean-assets/android.js +2 -2
  25. package/script/clean-assets/ios.d.ts.map +1 -1
  26. package/script/clean-assets/ios.js +14 -10
  27. package/script/copy-assets/ios.d.ts +1 -1
  28. package/script/copy-assets/ios.d.ts.map +1 -1
  29. package/script/copy-assets/ios.js +17 -11
  30. package/script/main.js +3 -3
  31. package/script/react-native-lib/ios/getBuildProperty.d.ts +1 -8
  32. package/script/react-native-lib/ios/getBuildProperty.d.ts.map +1 -1
  33. package/script/react-native-lib/ios/getBuildProperty.js +3 -3
  34. package/script/react-native-lib/ios/getPlist.d.ts +1 -1
  35. package/script/react-native-lib/ios/getPlist.d.ts.map +1 -1
  36. package/script/react-native-lib/ios/getPlist.js +2 -2
  37. package/script/react-native-lib/ios/getPlistPath.d.ts +1 -1
  38. package/script/react-native-lib/ios/getPlistPath.d.ts.map +1 -1
  39. package/script/react-native-lib/ios/getPlistPath.js +2 -2
  40. package/script/react-native-lib/ios/writePlist.d.ts +1 -1
  41. package/script/react-native-lib/ios/writePlist.d.ts.map +1 -1
  42. package/script/react-native-lib/ios/writePlist.js +2 -2
  43. package/script/utils.d.ts +10 -0
  44. package/script/utils.d.ts.map +1 -0
  45. package/script/utils.js +16 -0
@@ -2,11 +2,11 @@ import * as dntShim from "../_dnt.shims.js";
2
2
  import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js";
3
3
  export default async function cleanAssetsAndroid(filePaths, _platformConfig, options) {
4
4
  console.log(`options path in cleanAssetsAndroid: ${options.path}`);
5
- for (const p of filePaths) {
5
+ await Promise.all(filePaths.map(async (p) => {
6
6
  const target = path.join(options.path, path.basename(p));
7
7
  const st = await dntShim.Deno.lstat(target);
8
8
  if (st.isFile) {
9
9
  await dntShim.Deno.remove(target);
10
10
  }
11
- }
11
+ }));
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AAQA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAgC9B"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AASA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAiC9B"}
@@ -5,19 +5,23 @@ import * as xcode from "xcode";
5
5
  import createGroupWithMessage from "../react-native-lib/ios/createGroupWithMessage.js";
6
6
  import getPlist from "../react-native-lib/ios/getPlist.js";
7
7
  import writePlist from "../react-native-lib/ios/writePlist.js";
8
+ import { getTargetUUIDs } from "../utils.js";
8
9
  export default async function cleanAssetsIos(filePaths, platformConfig, options) {
9
10
  const project = xcode.project(platformConfig.pbxprojPath).parseSync();
10
- const plist = await getPlist(project, platformConfig
11
- .path);
12
11
  createGroupWithMessage(project, "Resources");
13
- const removedFiles = filePaths.map((p) => {
14
- return project.removeResourceFile(path.relative(platformConfig.path, p), { target: project.getFirstTarget().uuid });
15
- }).filter((x) => x).map((file) => file.basename);
16
- if (options.addFont) {
17
- const existingFonts = plist.UIAppFonts || [];
18
- const allFonts = existingFonts.filter((file) => removedFiles.indexOf(file) === -1);
19
- plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
12
+ for (const targetUUID of getTargetUUIDs(project)) {
13
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
14
+ const plist = await getPlist(project, platformConfig.path, targetUUID);
15
+ const removedFiles = filePaths.map((p) => {
16
+ return project.removeResourceFile(path.relative(platformConfig.path, p), { target: targetUUID });
17
+ }).filter((x) => x).map((file) => file.basename);
18
+ if (options.addFont) {
19
+ const existingFonts = plist.UIAppFonts || [];
20
+ const allFonts = existingFonts.filter((file) => removedFiles.indexOf(file) === -1);
21
+ plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
22
+ }
23
+ // deno-lint-ignore no-await-in-loop
24
+ await writePlist(project, platformConfig.path, plist, targetUUID);
20
25
  }
21
26
  await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
22
- writePlist(project, platformConfig.path, plist);
23
27
  }
@@ -1,4 +1,4 @@
1
- export default function cleanAssetsIos(filePaths: string[], platformConfig: {
1
+ export default function copyAssetsIos(filePaths: string[], platformConfig: {
2
2
  path: string;
3
3
  pbxprojPath: string;
4
4
  }, options: {
@@ -1 +1 @@
1
- {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAUA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAwC9B"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAWA,wBAA8B,aAAa,CACzC,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAyC9B"}
@@ -7,23 +7,29 @@ import * as xcodeParser from "xcode/lib/parser/pbxproj.js";
7
7
  import createGroupWithMessage from "../react-native-lib/ios/createGroupWithMessage.js";
8
8
  import getPlist from "../react-native-lib/ios/getPlist.js";
9
9
  import writePlist from "../react-native-lib/ios/writePlist.js";
10
- export default async function cleanAssetsIos(filePaths, platformConfig, options) {
10
+ import { getTargetUUIDs } from "../utils.js";
11
+ export default async function copyAssetsIos(filePaths, platformConfig, options) {
11
12
  const project = xcode.project(platformConfig.pbxprojPath);
12
13
  const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => {
13
14
  const decoder = new TextDecoder("utf-8");
14
15
  return decoder.decode(buf);
15
16
  });
16
17
  project.hash = xcodeParser.parse(pbxprojContent);
17
- const plist = await getPlist(project, platformConfig
18
- .path);
19
18
  createGroupWithMessage(project, "Resources");
20
- const addedFiles = filePaths.map((p) => project.addResourceFile(path.relative(platformConfig.path, p), { target: project.getFirstTarget().uuid })).filter((x) => x)
21
- .map((file) => file.basename);
22
- if (options.addFont) {
23
- const existingFonts = plist.UIAppFonts || [];
24
- const allFonts = [...existingFonts, ...addedFiles];
25
- plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
19
+ const fileBasenames = filePaths.map((p) => path.basename(p));
20
+ for (const targetUUID of getTargetUUIDs(project)) {
21
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
22
+ const plist = await getPlist(project, platformConfig.path, targetUUID);
23
+ for (const filePath of filePaths) {
24
+ project.addResourceFile(path.relative(platformConfig.path, filePath), { target: targetUUID });
25
+ }
26
+ if (options.addFont && plist) {
27
+ const existingFonts = plist.UIAppFonts || [];
28
+ const allFonts = [...existingFonts, ...fileBasenames];
29
+ plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
30
+ }
31
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
32
+ await writePlist(project, platformConfig.path, plist, targetUUID);
26
33
  }
27
34
  await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
28
- await writePlist(project, platformConfig.path, plist);
29
35
  }
package/esm/main.js CHANGED
@@ -137,9 +137,7 @@ export const linkAssets = async ({ rootPath, platforms, shouldUnlink = true, })
137
137
  }
138
138
  };
139
139
  const loadAll = async () => {
140
- for (const p of assetsPaths) {
141
- await loadAsset(p);
142
- }
140
+ await Promise.all(assetsPaths.map((p) => loadAsset(p)));
143
141
  assets = clearDuplicated(assets);
144
142
  };
145
143
  // run loading synchronously for simplicity
@@ -171,10 +169,12 @@ export const linkAssets = async ({ rootPath, platforms, shouldUnlink = true, })
171
169
  .filter(filterFilesToIgnore);
172
170
  if (su && prevRelativeAssetsWithExt.length > 0) {
173
171
  console.info(`Cleaning previously linked ${fileConfigName} assets from ${name} project, prevRelativeAssetsWithExt: ${prevRelativeAssetsWithExt.map((x) => x.path)}`);
172
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
174
173
  await cleanAssets(prevRelativeAssetsWithExt.map(({ path: filePath }) => getAbsolute({ filePath, dirPath: rp })), platformConfig, options);
175
174
  }
176
175
  if (assetsWithExt.length > 0) {
177
176
  console.info(`Linking ${fileConfigName} assets to ${name} project`);
177
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
178
178
  await copyAssets(assetsWithExt.map(({ path: assetPath }) => assetPath), platformConfig, options);
179
179
  }
180
180
  }
@@ -1,19 +1,12 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
1
  /**
8
2
  * Gets build property from the main target build section
9
3
  *
10
4
  * It differs from the project.getBuildProperty exposed by xcode in the way that:
11
- * - it only checks for build property in the main target `Debug` section
12
5
  * - `xcode` library iterates over all build sections and because it misses
13
6
  * an early return when property is found, it will return undefined/wrong value
14
7
  * when there's another build section typically after the one you want to access
15
8
  * without the property defined (e.g. CocoaPods sections appended to project
16
9
  * miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765
17
10
  */
18
- export default function getBuildProperty(project: any, prop: any): any;
11
+ export default function getBuildProperty(project: any, prop: any, targetUUID: any): any;
19
12
  //# sourceMappingURL=getBuildProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBuildProperty.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getBuildProperty.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,uEASC"}
1
+ {"version":3,"file":"getBuildProperty.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getBuildProperty.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,wFASC"}
@@ -4,19 +4,19 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ import { getTargetByUUID } from "../../utils.js";
7
8
  /**
8
9
  * Gets build property from the main target build section
9
10
  *
10
11
  * It differs from the project.getBuildProperty exposed by xcode in the way that:
11
- * - it only checks for build property in the main target `Debug` section
12
12
  * - `xcode` library iterates over all build sections and because it misses
13
13
  * an early return when property is found, it will return undefined/wrong value
14
14
  * when there's another build section typically after the one you want to access
15
15
  * without the property defined (e.g. CocoaPods sections appended to project
16
16
  * miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765
17
17
  */
18
- export default function getBuildProperty(project, prop) {
19
- const target = project.getFirstTarget().firstTarget;
18
+ export default function getBuildProperty(project, prop, targetUUID) {
19
+ const target = getTargetByUUID(project, targetUUID);
20
20
  const config = project.pbxXCConfigurationList()[target.buildConfigurationList];
21
21
  const buildSection = project.pbxXCBuildConfigurationSection()[config.buildConfigurations[0].value];
22
22
  return buildSection.buildSettings[prop];
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Returns `null` if INFOPLIST_FILE is not specified.
5
5
  */
6
- export default function getPlist(project: any, sourceDir: any): Promise<any>;
6
+ export default function getPlist(project: any, sourceDir: any, targetUUID: any): Promise<any>;
7
7
  //# sourceMappingURL=getPlist.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,6EAkBC"}
1
+ {"version":3,"file":"getPlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,8FAkBC"}
@@ -12,8 +12,8 @@ import getPlistPath from "./getPlistPath.js";
12
12
  *
13
13
  * Returns `null` if INFOPLIST_FILE is not specified.
14
14
  */
15
- export default async function getPlist(project, sourceDir) {
16
- const plistPath = getPlistPath(project, sourceDir);
15
+ export default async function getPlist(project, sourceDir, targetUUID) {
16
+ const plistPath = getPlistPath(project, sourceDir, targetUUID);
17
17
  if (!plistPath ||
18
18
  !(await dntShim.Deno.lstat(plistPath)
19
19
  .then(() => true)
@@ -1,2 +1,2 @@
1
- export default function getPlistPath(project: any, sourceDir: any): string | null;
1
+ export default function getPlistPath(project: any, sourceDir: any, targetUUID: any): string | null;
2
2
  //# sourceMappingURL=getPlistPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPlistPath.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlistPath.js"],"names":[],"mappings":"AAUA,kFAWC"}
1
+ {"version":3,"file":"getPlistPath.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlistPath.js"],"names":[],"mappings":"AAUA,mGAWC"}
@@ -6,8 +6,8 @@
6
6
  */
7
7
  import * as path from "../../deps/jsr.io/@std/path/1.1.4/mod.js";
8
8
  import getBuildProperty from "./getBuildProperty.js";
9
- export default function getPlistPath(project, sourceDir) {
10
- const plistFile = getBuildProperty(project, "INFOPLIST_FILE");
9
+ export default function getPlistPath(project, sourceDir, targetUUID) {
10
+ const plistFile = getBuildProperty(project, "INFOPLIST_FILE", targetUUID);
11
11
  if (!plistFile) {
12
12
  return null;
13
13
  }
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
5
5
  */
6
- export default function writePlist(project: any, sourceDir: any, plist: any): Promise<void | null>;
6
+ export default function writePlist(project: any, sourceDir: any, plist: any, targetUUID: any): Promise<void | null>;
7
7
  //# sourceMappingURL=writePlist.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writePlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/writePlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,mGAcC"}
1
+ {"version":3,"file":"writePlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/writePlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,oHAmBC"}
@@ -12,8 +12,8 @@ import getPlistPath from "./getPlistPath.js";
12
12
  *
13
13
  * Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
14
14
  */
15
- export default async function writePlist(project, sourceDir, plist) {
16
- const plistPath = getPlistPath(project, sourceDir);
15
+ export default async function writePlist(project, sourceDir, plist, targetUUID) {
16
+ const plistPath = getPlistPath(project, sourceDir, targetUUID);
17
17
  if (!plistPath) {
18
18
  return null;
19
19
  }
package/esm/utils.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type xcode from "xcode";
2
+ /**
3
+ * Get an array containing the UUID of each target in the project
4
+ */
5
+ export declare function getTargetUUIDs(project: xcode.Project): string[];
6
+ /**
7
+ * Get a target by UUID
8
+ */
9
+ export declare function getTargetByUUID(project: xcode.Project, uuid: string): unknown;
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,EAAE,CAE/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,WAEnE"}
package/esm/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get an array containing the UUID of each target in the project
3
+ */
4
+ export function getTargetUUIDs(project) {
5
+ return project.getFirstProject().firstProject.targets.map((t) => t.value);
6
+ }
7
+ /**
8
+ * Get a target by UUID
9
+ */
10
+ export function getTargetByUUID(project, uuid) {
11
+ return project.pbxNativeTargetSection()[uuid];
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-asset",
3
- "version": "2.2.10",
3
+ "version": "2.2.13",
4
4
  "description": "Linking and unlinking of assets in your react-native app, works for fonts and sounds",
5
5
  "keywords": [
6
6
  "react-native",
@@ -38,11 +38,11 @@ const dntShim = __importStar(require("../_dnt.shims.js"));
38
38
  const path = __importStar(require("../deps/jsr.io/@std/path/1.1.4/mod.js"));
39
39
  async function cleanAssetsAndroid(filePaths, _platformConfig, options) {
40
40
  console.log(`options path in cleanAssetsAndroid: ${options.path}`);
41
- for (const p of filePaths) {
41
+ await Promise.all(filePaths.map(async (p) => {
42
42
  const target = path.join(options.path, path.basename(p));
43
43
  const st = await dntShim.Deno.lstat(target);
44
44
  if (st.isFile) {
45
45
  await dntShim.Deno.remove(target);
46
46
  }
47
- }
47
+ }));
48
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AAQA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAgC9B"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AASA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAiC9B"}
@@ -44,19 +44,23 @@ const xcode = __importStar(require("xcode"));
44
44
  const createGroupWithMessage_js_1 = __importDefault(require("../react-native-lib/ios/createGroupWithMessage.js"));
45
45
  const getPlist_js_1 = __importDefault(require("../react-native-lib/ios/getPlist.js"));
46
46
  const writePlist_js_1 = __importDefault(require("../react-native-lib/ios/writePlist.js"));
47
+ const utils_js_1 = require("../utils.js");
47
48
  async function cleanAssetsIos(filePaths, platformConfig, options) {
48
49
  const project = xcode.project(platformConfig.pbxprojPath).parseSync();
49
- const plist = await (0, getPlist_js_1.default)(project, platformConfig
50
- .path);
51
50
  (0, createGroupWithMessage_js_1.default)(project, "Resources");
52
- const removedFiles = filePaths.map((p) => {
53
- return project.removeResourceFile(path.relative(platformConfig.path, p), { target: project.getFirstTarget().uuid });
54
- }).filter((x) => x).map((file) => file.basename);
55
- if (options.addFont) {
56
- const existingFonts = plist.UIAppFonts || [];
57
- const allFonts = existingFonts.filter((file) => removedFiles.indexOf(file) === -1);
58
- plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
51
+ for (const targetUUID of (0, utils_js_1.getTargetUUIDs)(project)) {
52
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
53
+ const plist = await (0, getPlist_js_1.default)(project, platformConfig.path, targetUUID);
54
+ const removedFiles = filePaths.map((p) => {
55
+ return project.removeResourceFile(path.relative(platformConfig.path, p), { target: targetUUID });
56
+ }).filter((x) => x).map((file) => file.basename);
57
+ if (options.addFont) {
58
+ const existingFonts = plist.UIAppFonts || [];
59
+ const allFonts = existingFonts.filter((file) => removedFiles.indexOf(file) === -1);
60
+ plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
61
+ }
62
+ // deno-lint-ignore no-await-in-loop
63
+ await (0, writePlist_js_1.default)(project, platformConfig.path, plist, targetUUID);
59
64
  }
60
65
  await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
61
- (0, writePlist_js_1.default)(project, platformConfig.path, plist);
62
66
  }
@@ -1,4 +1,4 @@
1
- export default function cleanAssetsIos(filePaths: string[], platformConfig: {
1
+ export default function copyAssetsIos(filePaths: string[], platformConfig: {
2
2
  path: string;
3
3
  pbxprojPath: string;
4
4
  }, options: {
@@ -1 +1 @@
1
- {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAUA,wBAA8B,cAAc,CAC1C,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAwC9B"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAWA,wBAA8B,aAAa,CACzC,SAAS,EAAE,MAAM,EAAE,EACnB,cAAc,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACrD,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,iBAyC9B"}
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = cleanAssetsIos;
39
+ exports.default = copyAssetsIos;
40
40
  const dntShim = __importStar(require("../_dnt.shims.js"));
41
41
  const path = __importStar(require("../deps/jsr.io/@std/path/1.1.4/mod.js"));
42
42
  /// <reference types="../xcode.d.ts" />
@@ -46,23 +46,29 @@ const xcodeParser = __importStar(require("xcode/lib/parser/pbxproj.js"));
46
46
  const createGroupWithMessage_js_1 = __importDefault(require("../react-native-lib/ios/createGroupWithMessage.js"));
47
47
  const getPlist_js_1 = __importDefault(require("../react-native-lib/ios/getPlist.js"));
48
48
  const writePlist_js_1 = __importDefault(require("../react-native-lib/ios/writePlist.js"));
49
- async function cleanAssetsIos(filePaths, platformConfig, options) {
49
+ const utils_js_1 = require("../utils.js");
50
+ async function copyAssetsIos(filePaths, platformConfig, options) {
50
51
  const project = xcode.project(platformConfig.pbxprojPath);
51
52
  const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => {
52
53
  const decoder = new TextDecoder("utf-8");
53
54
  return decoder.decode(buf);
54
55
  });
55
56
  project.hash = xcodeParser.parse(pbxprojContent);
56
- const plist = await (0, getPlist_js_1.default)(project, platformConfig
57
- .path);
58
57
  (0, createGroupWithMessage_js_1.default)(project, "Resources");
59
- const addedFiles = filePaths.map((p) => project.addResourceFile(path.relative(platformConfig.path, p), { target: project.getFirstTarget().uuid })).filter((x) => x)
60
- .map((file) => file.basename);
61
- if (options.addFont) {
62
- const existingFonts = plist.UIAppFonts || [];
63
- const allFonts = [...existingFonts, ...addedFiles];
64
- plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
58
+ const fileBasenames = filePaths.map((p) => path.basename(p));
59
+ for (const targetUUID of (0, utils_js_1.getTargetUUIDs)(project)) {
60
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
61
+ const plist = await (0, getPlist_js_1.default)(project, platformConfig.path, targetUUID);
62
+ for (const filePath of filePaths) {
63
+ project.addResourceFile(path.relative(platformConfig.path, filePath), { target: targetUUID });
64
+ }
65
+ if (options.addFont && plist) {
66
+ const existingFonts = plist.UIAppFonts || [];
67
+ const allFonts = [...existingFonts, ...fileBasenames];
68
+ plist.UIAppFonts = Array.from(new Set(allFonts)); // use Set to dedupe w/existing
69
+ }
70
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
71
+ await (0, writePlist_js_1.default)(project, platformConfig.path, plist, targetUUID);
65
72
  }
66
73
  await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
67
- await (0, writePlist_js_1.default)(project, platformConfig.path, plist);
68
74
  }
package/script/main.js CHANGED
@@ -176,9 +176,7 @@ const linkAssets = async ({ rootPath, platforms, shouldUnlink = true, }) => {
176
176
  }
177
177
  };
178
178
  const loadAll = async () => {
179
- for (const p of assetsPaths) {
180
- await loadAsset(p);
181
- }
179
+ await Promise.all(assetsPaths.map((p) => loadAsset(p)));
182
180
  assets = clearDuplicated(assets);
183
181
  };
184
182
  // run loading synchronously for simplicity
@@ -210,10 +208,12 @@ const linkAssets = async ({ rootPath, platforms, shouldUnlink = true, }) => {
210
208
  .filter(filterFilesToIgnore);
211
209
  if (su && prevRelativeAssetsWithExt.length > 0) {
212
210
  console.info(`Cleaning previously linked ${fileConfigName} assets from ${name} project, prevRelativeAssetsWithExt: ${prevRelativeAssetsWithExt.map((x) => x.path)}`);
211
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
213
212
  await cleanAssets(prevRelativeAssetsWithExt.map(({ path: filePath }) => getAbsolute({ filePath, dirPath: rp })), platformConfig, options);
214
213
  }
215
214
  if (assetsWithExt.length > 0) {
216
215
  console.info(`Linking ${fileConfigName} assets to ${name} project`);
216
+ // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
217
217
  await copyAssets(assetsWithExt.map(({ path: assetPath }) => assetPath), platformConfig, options);
218
218
  }
219
219
  }
@@ -1,19 +1,12 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
1
  /**
8
2
  * Gets build property from the main target build section
9
3
  *
10
4
  * It differs from the project.getBuildProperty exposed by xcode in the way that:
11
- * - it only checks for build property in the main target `Debug` section
12
5
  * - `xcode` library iterates over all build sections and because it misses
13
6
  * an early return when property is found, it will return undefined/wrong value
14
7
  * when there's another build section typically after the one you want to access
15
8
  * without the property defined (e.g. CocoaPods sections appended to project
16
9
  * miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765
17
10
  */
18
- export default function getBuildProperty(project: any, prop: any): any;
11
+ export default function getBuildProperty(project: any, prop: any, targetUUID: any): any;
19
12
  //# sourceMappingURL=getBuildProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBuildProperty.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getBuildProperty.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,uEASC"}
1
+ {"version":3,"file":"getBuildProperty.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getBuildProperty.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,wFASC"}
@@ -7,19 +7,19 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.default = getBuildProperty;
10
+ const utils_js_1 = require("../../utils.js");
10
11
  /**
11
12
  * Gets build property from the main target build section
12
13
  *
13
14
  * It differs from the project.getBuildProperty exposed by xcode in the way that:
14
- * - it only checks for build property in the main target `Debug` section
15
15
  * - `xcode` library iterates over all build sections and because it misses
16
16
  * an early return when property is found, it will return undefined/wrong value
17
17
  * when there's another build section typically after the one you want to access
18
18
  * without the property defined (e.g. CocoaPods sections appended to project
19
19
  * miss INFOPLIST_FILE), see: https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L1765
20
20
  */
21
- function getBuildProperty(project, prop) {
22
- const target = project.getFirstTarget().firstTarget;
21
+ function getBuildProperty(project, prop, targetUUID) {
22
+ const target = (0, utils_js_1.getTargetByUUID)(project, targetUUID);
23
23
  const config = project.pbxXCConfigurationList()[target.buildConfigurationList];
24
24
  const buildSection = project.pbxXCBuildConfigurationSection()[config.buildConfigurations[0].value];
25
25
  return buildSection.buildSettings[prop];
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Returns `null` if INFOPLIST_FILE is not specified.
5
5
  */
6
- export default function getPlist(project: any, sourceDir: any): Promise<any>;
6
+ export default function getPlist(project: any, sourceDir: any, targetUUID: any): Promise<any>;
7
7
  //# sourceMappingURL=getPlist.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,6EAkBC"}
1
+ {"version":3,"file":"getPlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,8FAkBC"}
@@ -51,8 +51,8 @@ const getPlistPath_js_1 = __importDefault(require("./getPlistPath.js"));
51
51
  *
52
52
  * Returns `null` if INFOPLIST_FILE is not specified.
53
53
  */
54
- async function getPlist(project, sourceDir) {
55
- const plistPath = (0, getPlistPath_js_1.default)(project, sourceDir);
54
+ async function getPlist(project, sourceDir, targetUUID) {
55
+ const plistPath = (0, getPlistPath_js_1.default)(project, sourceDir, targetUUID);
56
56
  if (!plistPath ||
57
57
  !(await dntShim.Deno.lstat(plistPath)
58
58
  .then(() => true)
@@ -1,2 +1,2 @@
1
- export default function getPlistPath(project: any, sourceDir: any): string | null;
1
+ export default function getPlistPath(project: any, sourceDir: any, targetUUID: any): string | null;
2
2
  //# sourceMappingURL=getPlistPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPlistPath.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlistPath.js"],"names":[],"mappings":"AAUA,kFAWC"}
1
+ {"version":3,"file":"getPlistPath.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/getPlistPath.js"],"names":[],"mappings":"AAUA,mGAWC"}
@@ -45,8 +45,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.default = getPlistPath;
46
46
  const path = __importStar(require("../../deps/jsr.io/@std/path/1.1.4/mod.js"));
47
47
  const getBuildProperty_js_1 = __importDefault(require("./getBuildProperty.js"));
48
- function getPlistPath(project, sourceDir) {
49
- const plistFile = (0, getBuildProperty_js_1.default)(project, "INFOPLIST_FILE");
48
+ function getPlistPath(project, sourceDir, targetUUID) {
49
+ const plistFile = (0, getBuildProperty_js_1.default)(project, "INFOPLIST_FILE", targetUUID);
50
50
  if (!plistFile) {
51
51
  return null;
52
52
  }
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
5
5
  */
6
- export default function writePlist(project: any, sourceDir: any, plist: any): Promise<void | null>;
6
+ export default function writePlist(project: any, sourceDir: any, plist: any, targetUUID: any): Promise<void | null>;
7
7
  //# sourceMappingURL=writePlist.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writePlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/writePlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,mGAcC"}
1
+ {"version":3,"file":"writePlist.d.ts","sourceRoot":"","sources":["../../../src/react-native-lib/ios/writePlist.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,oHAmBC"}
@@ -51,8 +51,8 @@ const getPlistPath_js_1 = __importDefault(require("./getPlistPath.js"));
51
51
  *
52
52
  * Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
53
53
  */
54
- async function writePlist(project, sourceDir, plist) {
55
- const plistPath = (0, getPlistPath_js_1.default)(project, sourceDir);
54
+ async function writePlist(project, sourceDir, plist, targetUUID) {
55
+ const plistPath = (0, getPlistPath_js_1.default)(project, sourceDir, targetUUID);
56
56
  if (!plistPath) {
57
57
  return null;
58
58
  }
@@ -0,0 +1,10 @@
1
+ import type xcode from "xcode";
2
+ /**
3
+ * Get an array containing the UUID of each target in the project
4
+ */
5
+ export declare function getTargetUUIDs(project: xcode.Project): string[];
6
+ /**
7
+ * Get a target by UUID
8
+ */
9
+ export declare function getTargetByUUID(project: xcode.Project, uuid: string): unknown;
10
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,EAAE,CAE/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,WAEnE"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTargetUUIDs = getTargetUUIDs;
4
+ exports.getTargetByUUID = getTargetByUUID;
5
+ /**
6
+ * Get an array containing the UUID of each target in the project
7
+ */
8
+ function getTargetUUIDs(project) {
9
+ return project.getFirstProject().firstProject.targets.map((t) => t.value);
10
+ }
11
+ /**
12
+ * Get a target by UUID
13
+ */
14
+ function getTargetByUUID(project, uuid) {
15
+ return project.pbxNativeTargetSection()[uuid];
16
+ }