react-native-asset 2.2.13 → 2.2.15

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.
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AAaA,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,iBAqC9B"}
@@ -1,13 +1,16 @@
1
1
  import * as dntShim from "../_dnt.shims.js";
2
2
  import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js";
3
- /// <reference types="../xcode.d.ts" />
4
3
  import * as xcode from "xcode";
4
+ import * as xcodeParserUntyped from "xcode/lib/parser/pbxproj.js";
5
+ const xcodeParser = xcodeParserUntyped;
5
6
  import createGroupWithMessage from "../react-native-lib/ios/createGroupWithMessage.js";
6
7
  import getPlist from "../react-native-lib/ios/getPlist.js";
7
8
  import writePlist from "../react-native-lib/ios/writePlist.js";
8
9
  import { getTargetUUIDs } from "../utils.js";
9
10
  export default async function cleanAssetsIos(filePaths, platformConfig, options) {
10
- const project = xcode.project(platformConfig.pbxprojPath).parseSync();
11
+ const project = xcode.project(platformConfig.pbxprojPath);
12
+ const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => new TextDecoder("utf-8").decode(buf));
13
+ project.hash = xcodeParser.parse(pbxprojContent);
11
14
  createGroupWithMessage(project, "Resources");
12
15
  for (const targetUUID of getTargetUUIDs(project)) {
13
16
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAaA,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,iBAwD9B"}
@@ -1,28 +1,46 @@
1
1
  import * as dntShim from "../_dnt.shims.js";
2
2
  import * as path from "../deps/jsr.io/@std/path/1.1.4/mod.js";
3
- /// <reference types="../xcode.d.ts" />
4
3
  import * as xcode from "xcode";
5
- /// <reference types="../xcode.d.ts" />
6
- import * as xcodeParser from "xcode/lib/parser/pbxproj.js";
4
+ import * as xcodeParserUntyped from "xcode/lib/parser/pbxproj.js";
5
+ const xcodeParser = xcodeParserUntyped;
7
6
  import createGroupWithMessage from "../react-native-lib/ios/createGroupWithMessage.js";
8
7
  import getPlist from "../react-native-lib/ios/getPlist.js";
9
8
  import writePlist from "../react-native-lib/ios/writePlist.js";
10
9
  import { getTargetUUIDs } from "../utils.js";
11
10
  export default async function copyAssetsIos(filePaths, platformConfig, options) {
12
11
  const project = xcode.project(platformConfig.pbxprojPath);
13
- const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => {
14
- const decoder = new TextDecoder("utf-8");
15
- return decoder.decode(buf);
16
- });
12
+ const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => new TextDecoder("utf-8").decode(buf));
17
13
  project.hash = xcodeParser.parse(pbxprojContent);
18
14
  createGroupWithMessage(project, "Resources");
15
+ const targetUUIDs = getTargetUUIDs(project);
16
+ for (const filePath of filePaths) {
17
+ const relativeFilePath = path.relative(platformConfig.path, filePath);
18
+ let file = false;
19
+ for (const target of targetUUIDs) {
20
+ if (!file) {
21
+ file = project.addResourceFile(relativeFilePath, { target });
22
+ if (!file) {
23
+ // We know the resource is already in the project but there's no obvious way to get the PBXFile reference
24
+ // It's kinda sloppy but we can remove and re-add the resource to get the reference
25
+ // This has the side effect of unlinking all other targets... not a problem because we're about to link them anyway
26
+ project.removeResourceFile(relativeFilePath, { target });
27
+ file = project.addResourceFile(relativeFilePath, { target });
28
+ if (!file) {
29
+ throw new Error(`Failed to add file to pbxproj "${filePath}"`);
30
+ }
31
+ }
32
+ }
33
+ else {
34
+ file.target = target;
35
+ project.addToPbxResourcesBuildPhase(file);
36
+ }
37
+ }
38
+ }
39
+ await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
19
40
  const fileBasenames = filePaths.map((p) => path.basename(p));
20
- for (const targetUUID of getTargetUUIDs(project)) {
41
+ for (const targetUUID of targetUUIDs) {
21
42
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
22
43
  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
44
  if (options.addFont && plist) {
27
45
  const existingFonts = plist.UIAppFonts || [];
28
46
  const allFonts = [...existingFonts, ...fileBasenames];
@@ -31,5 +49,4 @@ export default async function copyAssetsIos(filePaths, platformConfig, options)
31
49
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
32
50
  await writePlist(project, platformConfig.path, plist, targetUUID);
33
51
  }
34
- await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
35
52
  }
package/esm/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type xcode from "xcode";
1
+ import type { PBXProject } from "./xcode";
2
2
  /**
3
3
  * Get an array containing the UUID of each target in the project
4
4
  */
5
- export declare function getTargetUUIDs(project: xcode.Project): string[];
5
+ export declare function getTargetUUIDs(project: PBXProject): string[];
6
6
  /**
7
7
  * Get a target by UUID
8
8
  */
9
- export declare function getTargetByUUID(project: xcode.Project, uuid: string): unknown;
9
+ export declare function getTargetByUUID(project: PBXProject, uuid: string): unknown;
10
10
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,CAE5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAEhE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-asset",
3
- "version": "2.2.13",
3
+ "version": "2.2.15",
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",
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/clean-assets/ios.ts"],"names":[],"mappings":"AAaA,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,iBAqC9B"}
@@ -39,14 +39,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.default = cleanAssetsIos;
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
- /// <reference types="../xcode.d.ts" />
43
42
  const xcode = __importStar(require("xcode"));
43
+ const xcodeParserUntyped = __importStar(require("xcode/lib/parser/pbxproj.js"));
44
+ const xcodeParser = xcodeParserUntyped;
44
45
  const createGroupWithMessage_js_1 = __importDefault(require("../react-native-lib/ios/createGroupWithMessage.js"));
45
46
  const getPlist_js_1 = __importDefault(require("../react-native-lib/ios/getPlist.js"));
46
47
  const writePlist_js_1 = __importDefault(require("../react-native-lib/ios/writePlist.js"));
47
48
  const utils_js_1 = require("../utils.js");
48
49
  async function cleanAssetsIos(filePaths, platformConfig, options) {
49
- const project = xcode.project(platformConfig.pbxprojPath).parseSync();
50
+ const project = xcode.project(platformConfig.pbxprojPath);
51
+ const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => new TextDecoder("utf-8").decode(buf));
52
+ project.hash = xcodeParser.parse(pbxprojContent);
50
53
  (0, createGroupWithMessage_js_1.default)(project, "Resources");
51
54
  for (const targetUUID of (0, utils_js_1.getTargetUUIDs)(project)) {
52
55
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/copy-assets/ios.ts"],"names":[],"mappings":"AAaA,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,iBAwD9B"}
@@ -39,29 +39,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
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
- /// <reference types="../xcode.d.ts" />
43
42
  const xcode = __importStar(require("xcode"));
44
- /// <reference types="../xcode.d.ts" />
45
- const xcodeParser = __importStar(require("xcode/lib/parser/pbxproj.js"));
43
+ const xcodeParserUntyped = __importStar(require("xcode/lib/parser/pbxproj.js"));
44
+ const xcodeParser = xcodeParserUntyped;
46
45
  const createGroupWithMessage_js_1 = __importDefault(require("../react-native-lib/ios/createGroupWithMessage.js"));
47
46
  const getPlist_js_1 = __importDefault(require("../react-native-lib/ios/getPlist.js"));
48
47
  const writePlist_js_1 = __importDefault(require("../react-native-lib/ios/writePlist.js"));
49
48
  const utils_js_1 = require("../utils.js");
50
49
  async function copyAssetsIos(filePaths, platformConfig, options) {
51
50
  const project = xcode.project(platformConfig.pbxprojPath);
52
- const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => {
53
- const decoder = new TextDecoder("utf-8");
54
- return decoder.decode(buf);
55
- });
51
+ const pbxprojContent = await dntShim.Deno.readFile(platformConfig.pbxprojPath).then((buf) => new TextDecoder("utf-8").decode(buf));
56
52
  project.hash = xcodeParser.parse(pbxprojContent);
57
53
  (0, createGroupWithMessage_js_1.default)(project, "Resources");
54
+ const targetUUIDs = (0, utils_js_1.getTargetUUIDs)(project);
55
+ for (const filePath of filePaths) {
56
+ const relativeFilePath = path.relative(platformConfig.path, filePath);
57
+ let file = false;
58
+ for (const target of targetUUIDs) {
59
+ if (!file) {
60
+ file = project.addResourceFile(relativeFilePath, { target });
61
+ if (!file) {
62
+ // We know the resource is already in the project but there's no obvious way to get the PBXFile reference
63
+ // It's kinda sloppy but we can remove and re-add the resource to get the reference
64
+ // This has the side effect of unlinking all other targets... not a problem because we're about to link them anyway
65
+ project.removeResourceFile(relativeFilePath, { target });
66
+ file = project.addResourceFile(relativeFilePath, { target });
67
+ if (!file) {
68
+ throw new Error(`Failed to add file to pbxproj "${filePath}"`);
69
+ }
70
+ }
71
+ }
72
+ else {
73
+ file.target = target;
74
+ project.addToPbxResourcesBuildPhase(file);
75
+ }
76
+ }
77
+ }
78
+ await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
58
79
  const fileBasenames = filePaths.map((p) => path.basename(p));
59
- for (const targetUUID of (0, utils_js_1.getTargetUUIDs)(project)) {
80
+ for (const targetUUID of targetUUIDs) {
60
81
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
61
82
  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
83
  if (options.addFont && plist) {
66
84
  const existingFonts = plist.UIAppFonts || [];
67
85
  const allFonts = [...existingFonts, ...fileBasenames];
@@ -70,5 +88,4 @@ async function copyAssetsIos(filePaths, platformConfig, options) {
70
88
  // deno-lint-ignore no-await-in-loop -- sequential read/write to same plist file
71
89
  await (0, writePlist_js_1.default)(project, platformConfig.path, plist, targetUUID);
72
90
  }
73
- await dntShim.Deno.writeTextFile(platformConfig.pbxprojPath, project.writeSync());
74
91
  }
package/script/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type xcode from "xcode";
1
+ import type { PBXProject } from "./xcode";
2
2
  /**
3
3
  * Get an array containing the UUID of each target in the project
4
4
  */
5
- export declare function getTargetUUIDs(project: xcode.Project): string[];
5
+ export declare function getTargetUUIDs(project: PBXProject): string[];
6
6
  /**
7
7
  * Get a target by UUID
8
8
  */
9
- export declare function getTargetByUUID(project: xcode.Project, uuid: string): unknown;
9
+ export declare function getTargetByUUID(project: PBXProject, uuid: string): unknown;
10
10
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,CAE5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAEhE"}