diff --git a/package.json b/package.json index d6c5909795b5b5..9cbad93ef2cbb1 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,6 @@ "gettext-parser": "1.3.1", "gl-matrix": "^3.4.3", "invariant": "^2.2.4", - "ios-device-list": "1.1.37", "jed": "^1.1.0", "jest-fetch-mock": "^3.0.3", "js-beautify": "^1.15.1", diff --git a/scripts/extract-ios-device-names.ts b/scripts/extract-ios-device-names.ts deleted file mode 100644 index 3bda98192fd90d..00000000000000 --- a/scripts/extract-ios-device-names.ts +++ /dev/null @@ -1,106 +0,0 @@ -'use strict'; -import {existsSync, unlinkSync} from 'node:fs'; -import fs from 'node:fs/promises'; -import path from 'node:path'; - -// joining path of directory -const tmpOutputPath = path.join( - __dirname, - '../static/app/constants/ios-device-list.tmp.tsx' -); -const outputPath = path.join(__dirname, '../static/app/constants/ios-device-list.tsx'); -const directoryPath = path.join(__dirname, '../node_modules/ios-device-list/'); - -type Generation = string; -type Identifier = string; -type Mapping = Record; - -async function getDefinitionFiles(): Promise { - const files: string[] = []; - - const maybeJSONFiles = await fs.readdir(directoryPath); - - // listing all files using forEach - for (const file of maybeJSONFiles) { - if (!file.endsWith('.json') || file === 'package.json') { - continue; - } - - files.push(path.join(path.resolve(directoryPath), file)); - } - - return files; -} - -async function collectDefinitions(files: string[]): Promise { - const definitions: Mapping = {}; - - const queue = [...files]; - - while (queue.length > 0) { - const file = queue.pop(); - - if (!file) { - throw new Error('Empty queue'); - } - - const contents = await fs.readFile(file, 'utf8'); - const content = JSON.parse(contents); - - if (typeof content?.[0]?.Identifier === 'undefined') { - continue; - } - - for (const c of content) { - if (c.Identifier) { - definitions[c.Identifier] = c.Generation; - } - } - } - - return definitions; -} - -const HEADER = ` -// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -// generated using scripts/extract-ios-device-names.ts as part of build step. -// the purpose of the script is to extract only the iOS information that Sentry cares about -// and discard the rest of the JSON so we do not end up bloating bundle size. -`; - -// The formatting issues will be picked up by the CI and can quickly be fixed by -// running `yarn fix` command that triggers the linter and formatter. -const template = (contents: string) => { - return ` - ${HEADER} - const iOSDeviceMapping: Record = ${contents} - - export {iOSDeviceMapping} - `; -}; - -async function run() { - const files = await getDefinitionFiles(); - const definitions = await collectDefinitions(files); - const formatted = template(JSON.stringify(definitions, undefined, 2)); - - // All exit code has to synchronous - function cleanup() { - if (existsSync(tmpOutputPath)) { - unlinkSync(tmpOutputPath); - } - } - - process.once('exit', cleanup); - process.once('SIGINT', () => { - cleanup(); - process.exit(1); - }); - - // Write to tmp output path - await fs.writeFile(tmpOutputPath, formatted); - // Rename the file (atomic) - await fs.rename(tmpOutputPath, outputPath); -} - -run().catch(error => console.error(`Failed to run extract-ios-device-names`, error)); diff --git a/static/app/components/deviceName.spec.tsx b/static/app/components/deviceName.spec.tsx index d0873b2abddf27..324c4e04216fce 100644 --- a/static/app/components/deviceName.spec.tsx +++ b/static/app/components/deviceName.spec.tsx @@ -2,8 +2,6 @@ import {render, screen} from 'sentry-test/reactTestingLibrary'; import {DeviceName} from 'sentry/components/deviceName'; -jest.mock('ios-device-list'); - describe('DeviceName', () => { it('renders device name if module is loaded', async () => { render(); diff --git a/static/app/constants/ios-device-list.tsx b/static/app/constants/ios-device-list.tsx index 794ce37abf78e3..7cbeb528d9e12b 100644 --- a/static/app/constants/ios-device-list.tsx +++ b/static/app/constants/ios-device-list.tsx @@ -1,9 +1,12 @@ -// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -// generated using scripts/extract-ios-device-names.ts as part of build step. -// the purpose of the script is to extract only the iOS information that Sentry cares about -// and discard the rest of the JSON so we do not end up bloating bundle size. +// When updating this file, please also update +// Relay: https://github.com/getsentry/relay/blob/a91f0c92860f88789ad6092ef5b1062aa3e34b80/relay-event-schema/src/protocol/device_class.rs +// Python: https://github.com/getsentry/sentry/blob/c53745bb716899758d0f1caf5446d830e4ebbdb2/src/sentry/api/helpers/ios_models.py + +// We used to auto-generate this file from the ios-device-list library the node package (https://www.npmjs.com/package/ios-device-list) +// is unmaintained; see https://github.com/pbakondy/ios-device-list. +// Therefore, we manually update the device mapping list below. +// You can check https://gist.github.com/adamawolf/3048717 or https://theapplewiki.com/wiki/models for a comprehensive list of Apple devices. -// see https://theapplewiki.com/wiki/models const iOSDeviceMapping: Record = { // iPod touch 'iPod1,1': 'iPod touch', diff --git a/webpack.config.ts b/webpack.config.ts index c08d00a56e6999..2e5892460f199b 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -451,13 +451,6 @@ const appConfig: webpack.Configuration = { less: path.join(staticPrefix, 'less'), 'sentry-test': path.join(__dirname, 'tests', 'js', 'sentry-test'), 'sentry-locale': path.join(__dirname, 'src', 'sentry', 'locale'), - 'ios-device-list': path.join( - __dirname, - 'node_modules', - 'ios-device-list', - 'dist', - 'ios-device-list.min.js' - ), }, fallback: { diff --git a/yarn.lock b/yarn.lock index 471eeebd3b7d30..9be627ea49d8a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7875,15 +7875,6 @@ invariant@2.2.4, invariant@^2.2.4: dependencies: loose-envify "^1.0.0" -ios-device-list@1.1.37: - version "1.1.37" - resolved "https://registry.yarnpkg.com/ios-device-list/-/ios-device-list-1.1.37.tgz#0461dcba91ff824422740cfabc32490bfd95e686" - integrity sha512-0CS8kand3WDF58GtQV7AlFl9mONeHyQDtrypNEVSUyFsxNcbvj/o4gGeS/LNrQAK8V8V4rSIIpxx3hBVDDFwIg== - dependencies: - lodash.clonedeep "^4.5.0" - lodash.flatten "^4.4.0" - lodash.uniq "^4.5.0" - ipaddr.js@1.9.1: version "1.9.1" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3" @@ -9046,21 +9037,11 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" -lodash.clonedeep@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" - integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= - lodash.debounce@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow== -lodash.flatten@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f" - integrity sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8= - lodash.isequal@^4.0.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"