forked from brandingbrand/flagship
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request brandingbrand#2680 from crherman7/feat/ENG-5152_cu…
…stom_privacy_manifest_v13 feat(privacy-manifest): ENG-5152 allow custom privacy manifest
- Loading branch information
Showing
11 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @jest-environment-options {"requireTemplate": true, "fixtures": "privacy-info-xcprivacy_fixtures"} | ||
*/ | ||
|
||
/// <reference types="@brandingbrand/code-jest-config" /> | ||
|
||
import { type BuildConfig, fs, path } from "@brandingbrand/code-cli-kit"; | ||
|
||
import transformer from "../src/transformers/ios/privacy-info-xcprivacy"; | ||
|
||
describe("ios PrivacyInfo.xcprivacy transformers", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should not update PrivacyInfo.xcprivacy file", async () => { | ||
const config = { | ||
...__flagship_code_build_config, | ||
} as BuildConfig; | ||
|
||
const origionalContent = await fs.readFile( | ||
path.ios.privacyManifest, | ||
"utf-8" | ||
); | ||
await transformer.transform(config, {} as any); | ||
const content = await fs.readFile(path.ios.privacyManifest, "utf-8"); | ||
|
||
expect(content).toEqual(origionalContent); | ||
}); | ||
|
||
it("should update PrivacyInfo.xcprivacy file", async () => { | ||
const config = { | ||
...__flagship_code_build_config, | ||
} as BuildConfig; | ||
|
||
config.ios.privacyManifestPath = "./PrivacyInfo.xcprivacy"; | ||
|
||
const privacyManifestContent = await fs.readFile( | ||
path.project.resolve("PrivacyInfo.xcprivacy"), | ||
"utf-8" | ||
); | ||
|
||
await transformer.transform(config, {} as any); | ||
const content = await fs.readFile(path.ios.privacyManifest, "utf-8"); | ||
|
||
expect(content).toEqual(privacyManifestContent); | ||
}); | ||
|
||
it("should throw error for wrong PrivacyInfo.xcprivacy path", async () => { | ||
const config = { | ||
...__flagship_code_build_config, | ||
} as BuildConfig; | ||
|
||
config.ios.privacyManifestPath = "./blah/PrivacyInfo.xcprivacy"; | ||
|
||
const privacyManifestAbsolutePath = path.project.resolve( | ||
config.ios.privacyManifestPath | ||
); | ||
|
||
const throwError = async () => { | ||
await transformer.transform(config, {} as any); | ||
}; | ||
|
||
await expect(throwError).rejects.toThrow( | ||
new Error( | ||
`[PrivacyInfoXCPrivacyTransformerError]: path to privacy manifest does not exist ${privacyManifestAbsolutePath}, please update privacyManifestPath to the correct path relative to the root of your React Native project.` | ||
) | ||
); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/cli/__tests__/privacy-info-xcprivacy_fixtures/PrivacyInfo.xcprivacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSPrivacyCollectedDataTypes</key> | ||
<array> | ||
</array> | ||
<key>NSPrivacyAccessedAPITypes</key> | ||
<array> | ||
<dict> | ||
<key>NSPrivacyAccessedAPIType</key> | ||
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string> | ||
<key>NSPrivacyAccessedAPITypeReasons</key> | ||
<array> | ||
<string>C617.1</string> | ||
</array> | ||
</dict> | ||
<dict> | ||
<key>NSPrivacyAccessedAPIType</key> | ||
<string>NSPrivacyAccessedAPICategorySystemBootTime</string> | ||
<key>NSPrivacyAccessedAPITypeReasons</key> | ||
<array> | ||
<string>35F9.1</string> | ||
</array> | ||
</dict> | ||
</array> | ||
<key>NSPrivacyTracking</key> | ||
<false/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/cli/src/transformers/ios/privacy-info-xcprivacy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import fs from "fs"; | ||
|
||
import { | ||
type BuildConfig, | ||
type PrebuildOptions, | ||
withUTF8, | ||
path, | ||
string, | ||
} from "@brandingbrand/code-cli-kit"; | ||
|
||
import { Transforms, defineTransformer } from "@/lib"; | ||
|
||
/** | ||
* Defines a transformer for the iOS project's "PrivacyInfo.xcprivacy" file. | ||
* | ||
* @type {typeof defineTransformer<(content: string, config: BuildConfig) => string>} - The type of the transformer. | ||
* @property {string} file - The name of the file to be transformed ("PrivacyInfo.xcprivacy"). | ||
* @property {Array<(content: string, config: BuildConfig) => string>} transforms - An array of transformer functions. | ||
* @property {Function} transform - The main transform function that applies all specified transformations. | ||
* @returns {Promise<string>} The updated content of the "PrivacyInfo.xcprivacy" file. | ||
*/ | ||
export default defineTransformer<Transforms<string>>({ | ||
/** | ||
* The name of the file to be transformed ("PrivacyInfo.xcprivacy"). | ||
* @type {string} | ||
*/ | ||
file: "PrivacyInfo.xcprivacy", | ||
|
||
/** | ||
* An array of transformer functions to be applied to the "PrivacyInfo.xcprivacy" file. | ||
* Each function receives the content of the file and the build configuration, | ||
* and returns the updated content after applying specific transformations. | ||
* @type {Array<(content: string, config: BuildConfig) => string>} | ||
*/ | ||
transforms: [ | ||
/** | ||
* Transformer for updating the dependencies in the "PrivacyInfo.xcprivacy" file. | ||
* @param {string} content - The content of the file. | ||
* @param {BuildConfig} config - The build configuration. | ||
* @returns {string} - The updated content. | ||
*/ | ||
(content: string, config: BuildConfig): string => { | ||
const { privacyManifestPath } = config.ios; | ||
|
||
if (!privacyManifestPath) return content; | ||
|
||
const privacyManifestAbsolutePath = | ||
path.project.resolve(privacyManifestPath); | ||
|
||
if (!fs.existsSync(privacyManifestAbsolutePath)) { | ||
throw new Error( | ||
`[PrivacyInfoXCPrivacyTransformerError]: path to privacy manifest does not exist ${privacyManifestAbsolutePath}, please update privacyManifestPath to the correct path relative to the root of your React Native project.` | ||
); | ||
} | ||
|
||
const privacyManifestContent = fs.readFileSync( | ||
privacyManifestAbsolutePath, | ||
"utf-8" | ||
); | ||
|
||
return string.replace(content, /[\s\S]*/m, privacyManifestContent); | ||
}, | ||
], | ||
/** | ||
* The main transform function that applies all specified transformations to the "PrivacyInfo.xcprivacy" file. | ||
* @param {BuildConfig} config - The build configuration. | ||
* @returns {Promise<void>} - The updated content of the "PrivacyInfo.xcprivacy" file. | ||
*/ | ||
transform: async function ( | ||
config: BuildConfig, | ||
options: PrebuildOptions | ||
): Promise<void> { | ||
return withUTF8(path.ios.privacyManifest, (content: string) => { | ||
return this.transforms.reduce((acc, curr) => { | ||
return curr(acc, config, options); | ||
}, content); | ||
}); | ||
}, | ||
}); |