@sentry/wizard 6.1.2 → 6.3.0
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.
- package/CHANGELOG.md +25 -0
- package/dist/e2e-tests/tests/angular-17.test.js +5 -0
- package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
- package/dist/e2e-tests/tests/angular-19.test.js +5 -0
- package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
- package/dist/e2e-tests/tests/expo.test.js +9 -2
- package/dist/e2e-tests/tests/expo.test.js.map +1 -1
- package/dist/e2e-tests/tests/flutter.test.js +32 -4
- package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-14.test.js +4 -3
- package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-15.test.js +17 -4
- package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-3.test.js +9 -2
- package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-4.test.js +9 -2
- package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-native.test.js +8 -1
- package/dist/e2e-tests/tests/react-native.test.js.map +1 -1
- package/dist/e2e-tests/tests/remix.test.js +19 -4
- package/dist/e2e-tests/tests/remix.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit.test.js +16 -2
- package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
- package/dist/lib/Steps/Integrations/Electron.js +4 -0
- package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
- package/dist/src/android/android-wizard.js +3 -0
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/angular/angular-wizard.js +3 -0
- package/dist/src/angular/angular-wizard.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +13 -0
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/apple/code-tools.d.ts +1 -1
- package/dist/src/apple/code-tools.js +3 -3
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/inject-code-snippet.d.ts +2 -1
- package/dist/src/apple/inject-code-snippet.js +2 -2
- package/dist/src/apple/inject-code-snippet.js.map +1 -1
- package/dist/src/apple/templates.d.ts +2 -2
- package/dist/src/apple/templates.js +22 -6
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/flutter/code-tools.d.ts +1 -0
- package/dist/src/flutter/code-tools.js +6 -0
- package/dist/src/flutter/code-tools.js.map +1 -1
- package/dist/src/flutter/flutter-wizard.js +3 -0
- package/dist/src/flutter/flutter-wizard.js.map +1 -1
- package/dist/src/flutter/templates.d.ts +1 -0
- package/dist/src/flutter/templates.js +5 -0
- package/dist/src/flutter/templates.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +14 -7
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/utils.d.ts +8 -0
- package/dist/src/nextjs/utils.js +36 -1
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/nuxt/nuxt-wizard.js +3 -0
- package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
- package/dist/src/react-native/expo-metro.d.ts +2 -2
- package/dist/src/react-native/expo-metro.js +32 -27
- package/dist/src/react-native/expo-metro.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +4 -4
- package/dist/src/react-native/metro.js +39 -17
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +3 -0
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/remix/codemods/root.d.ts +1 -0
- package/dist/src/remix/codemods/root.js +30 -2
- package/dist/src/remix/codemods/root.js.map +1 -1
- package/dist/src/remix/remix-wizard.d.ts +4 -0
- package/dist/src/remix/remix-wizard.js +7 -0
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +3 -0
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/utils/clack/mcp-config.d.ts +7 -0
- package/dist/src/utils/clack/mcp-config.js +427 -0
- package/dist/src/utils/clack/mcp-config.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/test/angular/angular-wizard.test.js +3 -0
- package/dist/test/angular/angular-wizard.test.js.map +1 -1
- package/dist/test/apple/code-tools.test.js +62 -14
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/templates.test.js +71 -2
- package/dist/test/apple/templates.test.js.map +1 -1
- package/dist/test/flutter/code-tools.test.js +1 -0
- package/dist/test/flutter/code-tools.test.js.map +1 -1
- package/dist/test/flutter/templates.test.js +31 -1
- package/dist/test/flutter/templates.test.js.map +1 -1
- package/dist/test/nextjs/wizard-double-wrap-prevention.test.d.ts +1 -0
- package/dist/test/nextjs/wizard-double-wrap-prevention.test.js +269 -0
- package/dist/test/nextjs/wizard-double-wrap-prevention.test.js.map +1 -0
- package/dist/test/nuxt/templates.test.js +3 -0
- package/dist/test/nuxt/templates.test.js.map +1 -1
- package/dist/test/react-native/expo-metro.test.js +3 -3
- package/dist/test/react-native/expo-metro.test.js.map +1 -1
- package/dist/test/react-native/metro.test.js +76 -15
- package/dist/test/react-native/metro.test.js.map +1 -1
- package/dist/test/remix/root.test.js +229 -0
- package/dist/test/remix/root.test.js.map +1 -1
- package/dist/test/sveltekit/templates.test.js +3 -0
- package/dist/test/sveltekit/templates.test.js.map +1 -1
- package/dist/test/utils/clack/mcp-config.test.d.ts +1 -0
- package/dist/test/utils/clack/mcp-config.test.js +520 -0
- package/dist/test/utils/clack/mcp-config.test.js.map +1 -0
- package/package.json +1 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.test.js","sourceRoot":"","sources":["../../../test/nuxt/templates.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAC9C,wDAIkC;AAElC,IAAA,iBAAQ,EA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,EAAE,KAAK;iBACZ,CACF,CAAC;gBAEF,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;OAUxC,CAAC,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,iBAAQ,EAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,IAAA,WAAE,EAAC,qDAAqD,EAAE,GAAG,EAAE;YAC7D,MAAM,QAAQ,GAAG,IAAA,yCAA6B,EAC5C;gBACE,GAAG,EAAE,QAAQ;gBACb,OAAO,EAAE,YAAY;gBACrB,GAAG,EAAE,mBAAmB;gBACxB,UAAU,EAAE,KAAK;aAClB,EACD,KAAK,CACN,CAAC;YAEF,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;OAStC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,2EAA2E,EAAE,GAAG,EAAE;YACnF,MAAM,QAAQ,GAAG,IAAA,yCAA6B,EAC5C;gBACE,GAAG,EAAE,QAAQ;gBACb,OAAO,EAAE,YAAY;gBACrB,GAAG,EAAE,mBAAmB;gBACxB,UAAU,EAAE,KAAK;aAClB,EACD,IAAI,CACL,CAAC;YAEF,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;OAUtC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, it } from 'vitest';\nimport {\n getDefaultNuxtConfig,\n getNuxtModuleFallbackTemplate,\n getSentryConfigContents,\n} from '../../src/nuxt/templates';\n\ndescribe('Nuxt code templates', () => {\n describe('getDefaultNuxtConfig', () => {\n it('returns a default nuxt config', () => {\n expect(getDefaultNuxtConfig()).toMatchInlineSnapshot(`\n \"// https://nuxt.com/docs/api/configuration/nuxt-config\n export default defineNuxtConfig({\n compatibilityDate: '2024-04-03',\n devtools: { enabled: true }\n })\n \"\n`);\n });\n });\n\n describe('getSentryConfigContents', () => {\n describe('client config', () => {\n it('generates Sentry config with all features enabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with session replay disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: false,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with logs disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: true,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring and session replay disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with all features disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: false,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('server config', () => {\n it('generates Sentry config with all features enabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: false,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with logs disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: true,\n replay: true,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with all features disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: false,\n replay: false,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n });\n\n describe('getNuxtModuleFallbackTemplate', () => {\n it('generates configuration options for the nuxt config', () => {\n const template = getNuxtModuleFallbackTemplate(\n {\n org: 'my-org',\n project: 'my-project',\n url: 'https://sentry.io',\n selfHosted: false,\n },\n false,\n );\n\n expect(template).toMatchInlineSnapshot(`\n \" modules: [\"@sentry/nuxt/module\"],\n sentry: {\n sourceMapsUploadOptions: {\n org: \"my-org\",\n project: \"my-project\",\n },\n },\n sourcemap: { client: \"hidden\" },\"\n `);\n });\n\n it('generates configuration options for the nuxt config with top level import', () => {\n const template = getNuxtModuleFallbackTemplate(\n {\n org: 'my-org',\n project: 'my-project',\n url: 'https://sentry.io',\n selfHosted: false,\n },\n true,\n );\n\n expect(template).toMatchInlineSnapshot(`\n \" modules: [\"@sentry/nuxt/module\"],\n sentry: {\n sourceMapsUploadOptions: {\n org: \"my-org\",\n project: \"my-project\",\n },\n autoInjectServerSentry: \"top-level-import\",\n },\n sourcemap: { client: \"hidden\" },\"\n `);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"templates.test.js","sourceRoot":"","sources":["../../../test/nuxt/templates.test.ts"],"names":[],"mappings":";;AAAA,mCAAkD;AAClD,wDAIkC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ackTemplate,\n getSentryConfigContents,\n} from '../../src/nuxt/templates';\n\nvi.mock('../../src/utils/clack/mcp-config', () => ({\n offerProjectScopedMcpConfig: vi.fn().mockResolvedValue(undefined),\n}));\n\ndescribe('Nuxt code templates', () => {\n describe('getDefaultNuxtConfig', () => {\n it('returns a default nuxt config', () => {\n expect(getDefaultNuxtConfig()).toMatchInlineSnapshot(`\n \"// https://nuxt.com/docs/api/configuration/nuxt-config\n export default defineNuxtConfig({\n compatibilityDate: '2024-04-03',\n devtools: { enabled: true }\n })\n \"\n`);\n });\n });\n\n describe('getSentryConfigContents', () => {\n describe('client config', () => {\n it('generates Sentry config with all features enabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with session replay disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: false,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with logs disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: true,\n replay: true,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n \n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n \n // If you don't want to use Session Replay, just remove the line below:\n integrations: [Sentry.replayIntegration()],\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring and session replay disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: false,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with all features disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'client',\n {\n performance: false,\n replay: false,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n\n Sentry.init({\n // If set up, you can use your runtime config here\n // dsn: useRuntimeConfig().public.sentry.dsn,\n dsn: \"https://sentry.io/123\",\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n\n describe('server config', () => {\n it('generates Sentry config with all features enabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: true,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with performance monitoring disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: false,\n replay: true,\n logs: true,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // Enable logs to be sent to Sentry\n enableLogs: true,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with logs disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: true,\n replay: true,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n\n // We recommend adjusting this value in production, or using tracesSampler\n // for finer control\n tracesSampleRate: 1.0,\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n\n it('generates Sentry config with all features disabled', () => {\n const template = getSentryConfigContents(\n 'https://sentry.io/123',\n 'server',\n {\n performance: false,\n replay: false,\n logs: false,\n },\n );\n\n expect(template).toMatchInlineSnapshot(`\n \"import * as Sentry from \"@sentry/nuxt\";\n \n Sentry.init({\n dsn: \"https://sentry.io/123\",\n \n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n });\n \"\n `);\n });\n });\n });\n\n describe('getNuxtModuleFallbackTemplate', () => {\n it('generates configuration options for the nuxt config', () => {\n const template = getNuxtModuleFallbackTemplate(\n {\n org: 'my-org',\n project: 'my-project',\n url: 'https://sentry.io',\n selfHosted: false,\n },\n false,\n );\n\n expect(template).toMatchInlineSnapshot(`\n \" modules: [\"@sentry/nuxt/module\"],\n sentry: {\n sourceMapsUploadOptions: {\n org: \"my-org\",\n project: \"my-project\",\n },\n },\n sourcemap: { client: \"hidden\" },\"\n `);\n });\n\n it('generates configuration options for the nuxt config with top level import', () => {\n const template = getNuxtModuleFallbackTemplate(\n {\n org: 'my-org',\n project: 'my-project',\n url: 'https://sentry.io',\n selfHosted: false,\n },\n true,\n );\n\n expect(template).toMatchInlineSnapshot(`\n \" modules: [\"@sentry/nuxt/module\"],\n sentry: {\n sourceMapsUploadOptions: {\n org: \"my-org\",\n project: \"my-project\",\n },\n autoInjectServerSentry: \"top-level-import\",\n },\n sourcemap: { client: \"hidden\" },\"\n `);\n });\n });\n});\n"]}
|
|
@@ -19,7 +19,7 @@ config.resolver.assetExts.push(
|
|
|
19
19
|
|
|
20
20
|
module.exports = config;
|
|
21
21
|
`);
|
|
22
|
-
const result = (0, expo_metro_1.patchMetroInMemory)(mod);
|
|
22
|
+
const result = (0, expo_metro_1.patchMetroInMemory)(mod, 'metro.config.js');
|
|
23
23
|
(0, vitest_1.expect)(result).toBe(true);
|
|
24
24
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`
|
|
25
25
|
const {
|
|
@@ -45,7 +45,7 @@ const config = getDefaultConfig(__dirname);
|
|
|
45
45
|
|
|
46
46
|
module.exports = config;
|
|
47
47
|
`);
|
|
48
|
-
const result = (0, expo_metro_1.patchMetroInMemory)(mod);
|
|
48
|
+
const result = (0, expo_metro_1.patchMetroInMemory)(mod, 'metro.config.js');
|
|
49
49
|
(0, vitest_1.expect)(result).toBe(true);
|
|
50
50
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`
|
|
51
51
|
const { getDefaultConfig, otherExport } = require("expo/metro-config");
|
|
@@ -63,7 +63,7 @@ module.exports = config;
|
|
|
63
63
|
const mod = (0, magicast_1.parseModule)(`
|
|
64
64
|
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
|
|
65
65
|
`);
|
|
66
|
-
const result = (0, expo_metro_1.patchMetroInMemory)(mod);
|
|
66
|
+
const result = (0, expo_metro_1.patchMetroInMemory)(mod, 'metro.config.js');
|
|
67
67
|
(0, vitest_1.expect)(result).toBe(false);
|
|
68
68
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`
|
|
69
69
|
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo-metro.test.js","sourceRoot":"","sources":["../../../test/react-native/expo-metro.test.ts"],"names":[],"mappings":";;AAAA,kFAAkF;AAClF,uCAAqD;AACrD,kEAAuE;AACvE,mCAAgD;AAEhD,IAAA,iBAAQ,EAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAA,aAAI,EAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC;;;;;;;;;;;;OAYrB,CAAC,CAAC;QAEL,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"expo-metro.test.js","sourceRoot":"","sources":["../../../test/react-native/expo-metro.test.ts"],"names":[],"mappings":";;AAAA,kFAAkF;AAClF,uCAAqD;AACrD,kEAAuE;AACvE,mCAAgD;AAEhD,IAAA,iBAAQ,EAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAA,aAAI,EAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC;;;;;;;;;;;;OAYrB,CAAC,CAAC;QAEL,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAC1D,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAA,eAAM,EAAC,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CACtC;;;;;;;;;;;;;;CAcL,CAAC,IAAI,EAAE,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,aAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;QAChE,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC;;;;;;OAMrB,CAAC,CAAC;QAEL,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAC1D,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAA,eAAM,EAAC,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CACtC;;;;;;;;;;CAUL,CAAC,IAAI,EAAE,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,aAAI,EAAC,6CAA6C,EAAE,GAAG,EAAE;QACvD,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC;;CAE3B,CAAC,CAAC;QAEC,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QAC1D,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,IAAA,eAAM,EAAC,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CACtC;;CAEL,CAAC,IAAI,EAAE,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\nimport { patchMetroInMemory } from '../../src/react-native/expo-metro';\nimport { describe, expect, test } from 'vitest';\n\ndescribe('expo-metro config', () => {\n test('patches minimal expo config', () => {\n const mod = parseModule(`\nconst { getDefaultConfig } = require(\"expo/metro-config\");\n\n/** @type {import('expo/metro-config').MetroConfig} */\nconst config = getDefaultConfig(__dirname);\n\nconfig.resolver.assetExts.push(\n // Adds support for .db files for SQLite databases\n 'db'\n);\n\nmodule.exports = config;\n `);\n\n const result = patchMetroInMemory(mod, 'metro.config.js');\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(\n `\nconst {\n getSentryExpoConfig\n} = require(\"@sentry/react-native/metro\");\n\n/** @type {import('expo/metro-config').MetroConfig} */\nconst config = getSentryExpoConfig(__dirname);\n\nconfig.resolver.assetExts.push(\n // Adds support for .db files for SQLite databases\n 'db'\n);\n\nmodule.exports = config;\n`.trim(),\n );\n });\n\n test('keeps expo metro config if other imports are present', () => {\n const mod = parseModule(`\nconst { getDefaultConfig, otherExport } = require(\"expo/metro-config\");\n\nconst config = getDefaultConfig(__dirname);\n\nmodule.exports = config;\n `);\n\n const result = patchMetroInMemory(mod, 'metro.config.js');\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(\n `\nconst { getDefaultConfig, otherExport } = require(\"expo/metro-config\");\n\nconst {\n getSentryExpoConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst config = getSentryExpoConfig(__dirname);\n\nmodule.exports = config;\n`.trim(),\n );\n });\n\n test('does not modify when sentry already present', () => {\n const mod = parseModule(`\nconst { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");\n`);\n\n const result = patchMetroInMemory(mod, 'metro.config.js');\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(\n `\nconst { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");\n`.trim(),\n );\n });\n});\n"]}
|
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
4
27
|
const magicast_1 = require("magicast");
|
|
5
28
|
const metro_1 = require("../../src/react-native/metro");
|
|
6
29
|
const vitest_1 = require("vitest");
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
vitest_1.vi.mock('../../src/utils/clack/mcp-config', () => ({
|
|
32
|
+
offerProjectScopedMcpConfig: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
33
|
+
}));
|
|
34
|
+
vitest_1.vi.mock('fs', async () => {
|
|
35
|
+
const actual = await vitest_1.vi.importActual('fs');
|
|
36
|
+
return {
|
|
37
|
+
...actual,
|
|
38
|
+
existsSync: vitest_1.vi.fn(),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
7
41
|
(0, vitest_1.describe)('patch metro config - sentry serializer', () => {
|
|
8
42
|
(0, vitest_1.describe)('patchMetroWithSentryConfigInMemory', () => {
|
|
9
43
|
(0, vitest_1.it)('patches react native 0.72 default metro config', async () => {
|
|
@@ -18,9 +52,7 @@ const vitest_1 = require("vitest");
|
|
|
18
52
|
const config = {};
|
|
19
53
|
|
|
20
54
|
module.exports = mergeConfig(getDefaultConfig(__dirname), config);`);
|
|
21
|
-
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod,
|
|
22
|
-
/* noop */
|
|
23
|
-
});
|
|
55
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.js', true);
|
|
24
56
|
(0, vitest_1.expect)(result).toBe(true);
|
|
25
57
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code)
|
|
26
58
|
.toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
@@ -57,9 +89,7 @@ module.exports = {
|
|
|
57
89
|
}),
|
|
58
90
|
},
|
|
59
91
|
};`);
|
|
60
|
-
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod,
|
|
61
|
-
/* noop */
|
|
62
|
-
});
|
|
92
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.js', true);
|
|
63
93
|
(0, vitest_1.expect)(result).toBe(true);
|
|
64
94
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`const {
|
|
65
95
|
withSentryConfig
|
|
@@ -87,9 +117,7 @@ module.exports = withSentryConfig({
|
|
|
87
117
|
const mod = (0, magicast_1.parseModule)(`const testConfig = {};
|
|
88
118
|
|
|
89
119
|
module.exports = testConfig;`);
|
|
90
|
-
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod,
|
|
91
|
-
/* noop */
|
|
92
|
-
});
|
|
120
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.js', true);
|
|
93
121
|
(0, vitest_1.expect)(result).toBe(true);
|
|
94
122
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`const {
|
|
95
123
|
withSentryConfig
|
|
@@ -151,9 +179,7 @@ const config = {
|
|
|
151
179
|
};
|
|
152
180
|
|
|
153
181
|
module.exports = mergeConfig(getDefaultConfig(__dirname), config);`);
|
|
154
|
-
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod,
|
|
155
|
-
/* noop */
|
|
156
|
-
});
|
|
182
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.js', true);
|
|
157
183
|
(0, vitest_1.expect)(result).toBe(true);
|
|
158
184
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code)
|
|
159
185
|
.toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
@@ -212,11 +238,21 @@ const config = {
|
|
|
212
238
|
|
|
213
239
|
module.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);
|
|
214
240
|
});
|
|
241
|
+
(0, vitest_1.it)('patches CJS style metro config', async () => {
|
|
242
|
+
const mod = (0, magicast_1.parseModule)(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
243
|
+
|
|
244
|
+
const config = {};
|
|
245
|
+
|
|
246
|
+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);`);
|
|
247
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.cjs', true);
|
|
248
|
+
(0, vitest_1.expect)(result).toBe(true);
|
|
249
|
+
const code = (0, magicast_1.generateCode)(mod.$ast).code;
|
|
250
|
+
(0, vitest_1.expect)(code).toContain('require("@sentry/react-native/metro")');
|
|
251
|
+
(0, vitest_1.expect)(code).toContain('withSentryConfig');
|
|
252
|
+
});
|
|
215
253
|
(0, vitest_1.it)('does not patch react native metro config exported as factory function', async () => {
|
|
216
254
|
const mod = (0, magicast_1.parseModule)(`module.exports = () => ({});`);
|
|
217
|
-
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod,
|
|
218
|
-
/* noop */
|
|
219
|
-
});
|
|
255
|
+
const result = await (0, metro_1.patchMetroWithSentryConfigInMemory)(mod, 'metro.config.js', true);
|
|
220
256
|
(0, vitest_1.expect)(result).toBe(false);
|
|
221
257
|
(0, vitest_1.expect)((0, magicast_1.generateCode)(mod.$ast).code).toBe(`module.exports = () => ({});`);
|
|
222
258
|
});
|
|
@@ -331,6 +367,31 @@ module.exports = {
|
|
|
331
367
|
});
|
|
332
368
|
});
|
|
333
369
|
});
|
|
370
|
+
(0, vitest_1.describe)('Dynamic Metro Config path', () => {
|
|
371
|
+
(0, vitest_1.beforeEach)(() => {
|
|
372
|
+
vitest_1.vi.clearAllMocks();
|
|
373
|
+
});
|
|
374
|
+
(0, vitest_1.it)('finds metro.config.js when it exists', () => {
|
|
375
|
+
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'metro.config.js');
|
|
376
|
+
const result = (0, metro_1.findMetroConfigPath)();
|
|
377
|
+
(0, vitest_1.expect)(result).toBe('metro.config.js');
|
|
378
|
+
});
|
|
379
|
+
(0, vitest_1.it)('finds metro.config.cjs when it exists', () => {
|
|
380
|
+
vitest_1.vi.mocked(fs.existsSync).mockImplementation((path) => path === 'metro.config.cjs');
|
|
381
|
+
const result = (0, metro_1.findMetroConfigPath)();
|
|
382
|
+
(0, vitest_1.expect)(result).toBe('metro.config.cjs');
|
|
383
|
+
});
|
|
384
|
+
(0, vitest_1.it)('prefers metro.config.js over metro.config.cjs when both exist', () => {
|
|
385
|
+
vitest_1.vi.mocked(fs.existsSync).mockImplementation(() => true);
|
|
386
|
+
const result = (0, metro_1.findMetroConfigPath)();
|
|
387
|
+
(0, vitest_1.expect)(result).toBe('metro.config.js');
|
|
388
|
+
});
|
|
389
|
+
(0, vitest_1.it)('returns undefined when no metro config exists', () => {
|
|
390
|
+
vitest_1.vi.mocked(fs.existsSync).mockImplementation(() => false);
|
|
391
|
+
const result = (0, metro_1.findMetroConfigPath)();
|
|
392
|
+
(0, vitest_1.expect)(result).toBeUndefined();
|
|
393
|
+
});
|
|
394
|
+
});
|
|
334
395
|
function getModuleExportsObject(mod, index = 0) {
|
|
335
396
|
return mod.$ast.body[index]
|
|
336
397
|
.expression.right;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metro.test.js","sourceRoot":"","sources":["../../../test/react-native/metro.test.ts"],"names":[],"mappings":";;AAAA,kFAAkF;AAClF,uCAA2E;AAM3E,wDAKsC;AACtC,mCAA8C;AAE9C,IAAA,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/C,MAAM,GAAG,GAAG,IAAA,sBAAW,EAAC,sCAAsC,CAAC,CAAC;YAChE,MAAM,YAAY,GAAG,IAAA,4BAAoB,EAAC,GAAG,CAAC,IAAiB,CAAC,CAAC;YACjE,IAAA,eAAM,EACH,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA,CAAC,GAAoB;iBACpE,IAAI,CACR,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,IAAA,eAAM,EAEF,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAsB,CAAA;iBAC9C,KACJ,CAAC,KAAK,CACR,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAC7B,GAAoB,EACpB,KAAK,GAAG,CAAC;IAET,OACI,GAAG,CAAC,IAAkB,CAAC,IAAI,CAAC,KAAK,CAA2B;SAC3D,UACJ,CAAC,KAA2B,CAAC;AAChC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, type ProxifiedModule, parseModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport {\n addSentrySerializerRequireToMetroConfig,\n addSentrySerializerToMetroConfig,\n getMetroConfigObject,\n patchMetroWithSentryConfigInMemory,\n} from '../../src/react-native/metro';\nimport { describe, expect, it } from 'vitest';\n\ndescribe('patch metro config - sentry serializer', () => {\n describe('patchMetroWithSentryConfigInMemory', () => {\n it('patches react native 0.72 default metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('patches react native 0.65 default metro config', async () => {\n const mod = parseModule(`/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = {\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n};`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = withSentryConfig({\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n});`);\n });\n\n it('patches react native metro config exported variable', async () => {\n const mod = parseModule(`const testConfig = {};\n\nmodule.exports = testConfig;`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst testConfig = {};\n\nmodule.exports = withSentryConfig(testConfig);`);\n });\n\n it('patches custom react native metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('does not patch react native metro config exported as factory function', async () => {\n const mod = parseModule(`module.exports = () => ({});`);\n\n const result = await patchMetroWithSentryConfigInMemory(mod, async () => {\n /* noop */\n });\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = () => ({});`);\n });\n });\n\n describe('addSentrySerializerToMetroConfig', () => {\n it('add to empty config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config'\n }`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n\n serializer: {\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('add to existing serializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('not add to existing customSerializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n });\n });\n\n describe('addSentrySerializerImportToMetroConfig', () => {\n it('add import', () => {\n const mod =\n parseModule(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nmodule.exports = {\n other: 'config'\n}`);\n const result = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nconst {\n createSentryMetroSerializer\n} = require(\"@sentry/react-native/dist/js/tools/sentryMetroSerializer\");\n\nmodule.exports = {\n other: 'config'\n}`);\n });\n });\n\n describe('getMetroConfigObject', () => {\n it('get config object from variable called config', () => {\n const mod = parseModule(`var config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from const called config', () => {\n const mod = parseModule(`const config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config oject from let called config', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from module.exports', () => {\n const mod = parseModule(`module.exports = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n });\n});\n\nfunction getModuleExportsObject(\n mod: ProxifiedModule,\n index = 0,\n): t.ObjectExpression {\n return (\n ((mod.$ast as t.Program).body[index] as t.ExpressionStatement)\n .expression as t.AssignmentExpression\n ).right as t.ObjectExpression;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"metro.test.js","sourceRoot":"","sources":["../../../test/react-native/metro.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kFAAkF;AAClF,uCAA2E;AAM3E,wDAMsC;AACtC,mCAA8D;AAC9D,uCAAyB;AAEzB,WAAE,CAAC,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,2BAA2B,EAAE,WAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;CAClE,CAAC,CAAC,CAAC;AAEJ,WAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;IACvB,MAAM,MAAM,GAAG,MAAM,WAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO;QACL,GAAG,MAAM;QACT,UAAU,EAAE,WAAE,CAAC,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAA,iBAAQ,EAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,IAAA,iBAAQ,EAAC,oCAAoC,EAAE,GAAG,EAAE;QAClD,IAAA,WAAE,EAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;YAC9D,MAAM,GAAG,GACP,IAAA,sBAAW,EAAC;;;;;;;;;;mEAU+C,CAAC,CAAC;YAE/D,MAAM,MAAM,GAAG,MAAM,IAAA,0CAAkC,EACrD,GAAG,EACH,iBAAiB,EACjB,IAAI,CACL,CAAC;YACF,IAAA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,KAAK,kBAAkB,CAC9C,CAAC;QAEF,MAAM,MAAM,GAAG,IAAA,2BAAmB,GAAE,CAAC;QACrC,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,WAAE,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QAExD,MAAM,MAAM,GAAG,IAAA,2BAAmB,GAAE,CAAC;QACrC,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,WAAE,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAEzD,MAAM,MAAM,GAAG,IAAA,2BAAmB,GAAE,CAAC;QACrC,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAC7B,GAAoB,EACpB,KAAK,GAAG,CAAC;IAET,OACI,GAAG,CAAC,IAAkB,CAAC,IAAI,CAAC,KAAK,CAA2B;SAC3D,UACJ,CAAC,KAA2B,CAAC;AAChC,CAAC","sourcesContent":["// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, type ProxifiedModule, parseModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport {\n addSentrySerializerRequireToMetroConfig,\n addSentrySerializerToMetroConfig,\n findMetroConfigPath,\n getMetroConfigObject,\n patchMetroWithSentryConfigInMemory,\n} from '../../src/react-native/metro';\nimport { beforeEach, describe, expect, it, vi } from 'vitest';\nimport * as fs from 'fs';\n\nvi.mock('../../src/utils/clack/mcp-config', () => ({\n offerProjectScopedMcpConfig: vi.fn().mockResolvedValue(undefined),\n}));\n\nvi.mock('fs', async () => {\n const actual = await vi.importActual('fs');\n return {\n ...actual,\n existsSync: vi.fn(),\n };\n});\n\ndescribe('patch metro config - sentry serializer', () => {\n describe('patchMetroWithSentryConfigInMemory', () => {\n it('patches react native 0.72 default metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.js',\n true,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('patches react native 0.65 default metro config', async () => {\n const mod = parseModule(`/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = {\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n};`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.js',\n true,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\n/**\n* Metro configuration for React Native\n* https://github.com/facebook/react-native\n*\n* @format\n*/\n\nmodule.exports = withSentryConfig({\n transformer: {\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n});`);\n });\n\n it('patches react native metro config exported variable', async () => {\n const mod = parseModule(`const testConfig = {};\n\nmodule.exports = testConfig;`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.js',\n true,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`const {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst testConfig = {};\n\nmodule.exports = withSentryConfig(testConfig);`);\n });\n\n it('patches custom react native metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.js',\n true,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst {\n withSentryConfig\n} = require(\"@sentry/react-native/metro\");\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst {assetExts, sourceExts} = defaultConfig.resolver;\n/**\n * Metro configuration\n * https://facebook.github.io/metro/docs/configuration\n *\n * @type {import('metro-config').MetroConfig}\n */\n\nconst jsoMetroPlugin = require('obfuscator-io-metro-plugin')(\n {\n // for these option look javascript-obfuscator library options from above url\n compact: false,\n sourceMap: false,\n controlFlowFlattening: true,\n controlFlowFlatteningThreshold: 1,\n numbersToExpressions: true,\n simplify: true,\n stringArrayShuffle: true,\n splitStrings: true,\n stringArrayThreshold: 1,\n },\n {\n runInDev: false /* optional */,\n logObfuscatedFiles: true /* optional generated files will be located at ./.jso */,\n // source Map generated after obfuscation is not useful right now\n sourceMapLocation:\n './index.android.bundle.map' /* optional only works if sourceMap: true in obfuscation option */,\n },\n);\n\nconst config = {\n transformer: {\n babelTransformerPath: require.resolve('react-native-svg-transformer'),\n getTransformOptions: async () => ({\n transform: {\n experimentalImportSupport: false,\n inlineRequires: true,\n },\n }),\n },\n resolver: {\n assetExts: assetExts.filter(ext => ext !== 'svg'),\n sourceExts: [...sourceExts, 'svg'],\n },\n ...jsoMetroPlugin,\n};\n\nmodule.exports = withSentryConfig(mergeConfig(getDefaultConfig(__dirname), config));`);\n });\n\n it('patches CJS style metro config', async () => {\n const mod =\n parseModule(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\n\nconst config = {};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.cjs',\n true,\n );\n expect(result).toBe(true);\n\n const code = generateCode(mod.$ast).code;\n expect(code).toContain('require(\"@sentry/react-native/metro\")');\n expect(code).toContain('withSentryConfig');\n });\n\n it('does not patch react native metro config exported as factory function', async () => {\n const mod = parseModule(`module.exports = () => ({});`);\n\n const result = await patchMetroWithSentryConfigInMemory(\n mod,\n 'metro.config.js',\n true,\n );\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = () => ({});`);\n });\n });\n\n describe('addSentrySerializerToMetroConfig', () => {\n it('add to empty config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config'\n }`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n\n serializer: {\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('add to existing serializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: createSentryMetroSerializer()\n }\n}`);\n });\n\n it('not add to existing customSerializer config', () => {\n const mod = parseModule(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n const configObject = getModuleExportsObject(mod);\n const result = addSentrySerializerToMetroConfig(configObject);\n expect(result).toBe(false);\n expect(generateCode(mod.$ast).code).toBe(`module.exports = {\n other: 'config',\n serializer: {\n other: 'config',\n customSerializer: 'existing-serializer'\n }\n}`);\n });\n });\n\n describe('addSentrySerializerImportToMetroConfig', () => {\n it('add import', () => {\n const mod =\n parseModule(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nmodule.exports = {\n other: 'config'\n}`);\n const result = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n expect(result).toBe(true);\n expect(generateCode(mod.$ast).code)\n .toBe(`const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');\n\nconst {\n createSentryMetroSerializer\n} = require(\"@sentry/react-native/dist/js/tools/sentryMetroSerializer\");\n\nmodule.exports = {\n other: 'config'\n}`);\n });\n });\n\n describe('getMetroConfigObject', () => {\n it('get config object from variable called config', () => {\n const mod = parseModule(`var config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from const called config', () => {\n const mod = parseModule(`const config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config oject from let called config', () => {\n const mod = parseModule(`let config = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n\n it('get config object from module.exports', () => {\n const mod = parseModule(`module.exports = { some: 'config' };`);\n const configObject = getMetroConfigObject(mod.$ast as t.Program);\n expect(\n ((configObject?.properties[0] as t.ObjectProperty).key as t.Identifier)\n .name,\n ).toBe('some');\n expect(\n (\n (configObject?.properties[0] as t.ObjectProperty)\n .value as t.StringLiteral\n ).value,\n ).toBe('config');\n });\n });\n});\n\ndescribe('Dynamic Metro Config path', () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it('finds metro.config.js when it exists', () => {\n vi.mocked(fs.existsSync).mockImplementation(\n (path: string) => path === 'metro.config.js',\n );\n\n const result = findMetroConfigPath();\n expect(result).toBe('metro.config.js');\n });\n\n it('finds metro.config.cjs when it exists', () => {\n vi.mocked(fs.existsSync).mockImplementation(\n (path: string) => path === 'metro.config.cjs',\n );\n\n const result = findMetroConfigPath();\n expect(result).toBe('metro.config.cjs');\n });\n\n it('prefers metro.config.js over metro.config.cjs when both exist', () => {\n vi.mocked(fs.existsSync).mockImplementation(() => true);\n\n const result = findMetroConfigPath();\n expect(result).toBe('metro.config.js');\n });\n\n it('returns undefined when no metro config exists', () => {\n vi.mocked(fs.existsSync).mockImplementation(() => false);\n\n const result = findMetroConfigPath();\n expect(result).toBeUndefined();\n });\n});\n\nfunction getModuleExportsObject(\n mod: ProxifiedModule,\n index = 0,\n): t.ObjectExpression {\n return (\n ((mod.$ast as t.Program).body[index] as t.ExpressionStatement)\n .expression as t.AssignmentExpression\n ).right as t.ObjectExpression;\n}\n"]}
|
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
4
27
|
const magicast_1 = require("magicast");
|
|
5
28
|
const vitest_1 = require("vitest");
|
|
29
|
+
const fs = __importStar(require("fs"));
|
|
30
|
+
const path = __importStar(require("path"));
|
|
6
31
|
const root_1 = require("../../src/remix/codemods/root");
|
|
32
|
+
vitest_1.vi.mock('@clack/prompts', () => {
|
|
33
|
+
const mock = {
|
|
34
|
+
log: {
|
|
35
|
+
warn: vitest_1.vi.fn(),
|
|
36
|
+
info: vitest_1.vi.fn(),
|
|
37
|
+
success: vitest_1.vi.fn(),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
default: mock,
|
|
42
|
+
...mock,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
vitest_1.vi.mock('../../src/utils/clack/mcp-config', () => ({
|
|
46
|
+
offerProjectScopedMcpConfig: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
47
|
+
}));
|
|
7
48
|
(0, vitest_1.describe)('wrapAppWithSentry', () => {
|
|
8
49
|
(0, vitest_1.it)('should wrap the app with Sentry', () => {
|
|
9
50
|
// Empty root.tsx file for testing
|
|
@@ -28,4 +69,192 @@ const root_1 = require("../../src/remix/codemods/root");
|
|
|
28
69
|
`);
|
|
29
70
|
});
|
|
30
71
|
});
|
|
72
|
+
(0, vitest_1.describe)('isWithSentryAlreadyUsed', () => {
|
|
73
|
+
(0, vitest_1.it)('should return false when withSentry is not used', () => {
|
|
74
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
75
|
+
import { Outlet } from '@remix-run/react';
|
|
76
|
+
|
|
77
|
+
export default function App() {
|
|
78
|
+
return <Outlet />;
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.it)('should return true when withSentry is used in default export', () => {
|
|
84
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
85
|
+
import { withSentry } from '@sentry/remix';
|
|
86
|
+
import { Outlet } from '@remix-run/react';
|
|
87
|
+
|
|
88
|
+
function App() {
|
|
89
|
+
return <Outlet />;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default withSentry(App);
|
|
93
|
+
`);
|
|
94
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.it)('should return true when withSentry is used in a variable assignment', () => {
|
|
97
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
98
|
+
import { withSentry } from '@sentry/remix';
|
|
99
|
+
import { Outlet } from '@remix-run/react';
|
|
100
|
+
|
|
101
|
+
function App() {
|
|
102
|
+
return <Outlet />;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const WrappedApp = withSentry(App);
|
|
106
|
+
export default WrappedApp;
|
|
107
|
+
`);
|
|
108
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
(0, vitest_1.it)('should return true when withSentry is used inside a function', () => {
|
|
111
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
112
|
+
import { withSentry } from '@sentry/remix';
|
|
113
|
+
import { Outlet } from '@remix-run/react';
|
|
114
|
+
|
|
115
|
+
function App() {
|
|
116
|
+
return <Outlet />;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createApp() {
|
|
120
|
+
return withSentry(App);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default createApp();
|
|
124
|
+
`);
|
|
125
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.it)('should return false when withSentry is imported but not used', () => {
|
|
128
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
129
|
+
import { withSentry } from '@sentry/remix';
|
|
130
|
+
import { Outlet } from '@remix-run/react';
|
|
131
|
+
|
|
132
|
+
export default function App() {
|
|
133
|
+
return <Outlet />;
|
|
134
|
+
}
|
|
135
|
+
`);
|
|
136
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.it)('should return false when a different function with similar name is used', () => {
|
|
139
|
+
const rootAst = (0, magicast_1.parseModule)(`
|
|
140
|
+
import { Outlet } from '@remix-run/react';
|
|
141
|
+
|
|
142
|
+
function withSentryLike() {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default function App() {
|
|
147
|
+
withSentryLike();
|
|
148
|
+
return <Outlet />;
|
|
149
|
+
}
|
|
150
|
+
`);
|
|
151
|
+
(0, vitest_1.expect)((0, root_1.isWithSentryAlreadyUsed)(rootAst)).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.describe)('instrumentRoot', () => {
|
|
155
|
+
const fixturesDir = path.join(__dirname, 'fixtures');
|
|
156
|
+
const tmpDir = path.join(fixturesDir, 'tmp');
|
|
157
|
+
(0, vitest_1.beforeEach)(() => {
|
|
158
|
+
vitest_1.vi.clearAllMocks();
|
|
159
|
+
// Mock process.cwd() to return the fixtures directory
|
|
160
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(fixturesDir);
|
|
161
|
+
});
|
|
162
|
+
(0, vitest_1.afterEach)(() => {
|
|
163
|
+
// Clean up any temporary files
|
|
164
|
+
if (fs.existsSync(tmpDir)) {
|
|
165
|
+
try {
|
|
166
|
+
// Remove files first, then directory
|
|
167
|
+
const appDir = path.join(tmpDir, 'app');
|
|
168
|
+
if (fs.existsSync(appDir)) {
|
|
169
|
+
const files = fs.readdirSync(appDir);
|
|
170
|
+
files.forEach((file) => {
|
|
171
|
+
fs.unlinkSync(path.join(appDir, file));
|
|
172
|
+
});
|
|
173
|
+
fs.rmdirSync(appDir);
|
|
174
|
+
}
|
|
175
|
+
const files = fs.readdirSync(tmpDir);
|
|
176
|
+
files.forEach((file) => {
|
|
177
|
+
const filePath = path.join(tmpDir, file);
|
|
178
|
+
const stat = fs.statSync(filePath);
|
|
179
|
+
if (stat.isDirectory()) {
|
|
180
|
+
fs.rmdirSync(filePath);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
fs.unlinkSync(filePath);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
// Ignore cleanup errors in tests
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
(0, vitest_1.it)('should add ErrorBoundary and wrap app with Sentry when no ErrorBoundary exists and withSentry is not used', async () => {
|
|
193
|
+
// Copy fixture to tmp directory for testing
|
|
194
|
+
const srcFile = path.join(fixturesDir, 'root-no-error-boundary.tsx');
|
|
195
|
+
const appDir = path.join(tmpDir, 'app');
|
|
196
|
+
// Create app directory and copy file
|
|
197
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
198
|
+
fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
|
|
199
|
+
// Mock process.cwd() to return tmpDir
|
|
200
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
|
|
201
|
+
await (0, root_1.instrumentRoot)('root.tsx');
|
|
202
|
+
// Check that the file was modified correctly
|
|
203
|
+
const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
|
|
204
|
+
(0, vitest_1.expect)(modifiedContent).toContain('import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix";');
|
|
205
|
+
(0, vitest_1.expect)(modifiedContent).toContain("import { Outlet, useRouteError } from '@remix-run/react';");
|
|
206
|
+
(0, vitest_1.expect)(modifiedContent).toContain('withSentry(App)');
|
|
207
|
+
(0, vitest_1.expect)(modifiedContent).toContain('const ErrorBoundary = () => {');
|
|
208
|
+
});
|
|
209
|
+
(0, vitest_1.it)('should wrap app with Sentry when ErrorBoundary exists but no Sentry content', async () => {
|
|
210
|
+
const srcFile = path.join(fixturesDir, 'root-with-error-boundary.tsx');
|
|
211
|
+
const appDir = path.join(tmpDir, 'app');
|
|
212
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
213
|
+
fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
|
|
214
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
|
|
215
|
+
await (0, root_1.instrumentRoot)('root.tsx');
|
|
216
|
+
const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
|
|
217
|
+
(0, vitest_1.expect)(modifiedContent).toContain('import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix";');
|
|
218
|
+
(0, vitest_1.expect)(modifiedContent).toContain('withSentry(App)');
|
|
219
|
+
});
|
|
220
|
+
(0, vitest_1.it)('should wrap app with Sentry when ErrorBoundary exists with Sentry content but withSentry is not used', async () => {
|
|
221
|
+
const srcFile = path.join(fixturesDir, 'root-with-sentry-error-boundary.tsx');
|
|
222
|
+
const appDir = path.join(tmpDir, 'app');
|
|
223
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
224
|
+
fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
|
|
225
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
|
|
226
|
+
await (0, root_1.instrumentRoot)('root.tsx');
|
|
227
|
+
const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
|
|
228
|
+
(0, vitest_1.expect)(modifiedContent).toContain("import { captureRemixErrorBoundaryError, withSentry } from '@sentry/remix';");
|
|
229
|
+
(0, vitest_1.expect)(modifiedContent).toContain('withSentry(App)');
|
|
230
|
+
});
|
|
231
|
+
(0, vitest_1.it)('should not wrap app when withSentry is already used', async () => {
|
|
232
|
+
const srcFile = path.join(fixturesDir, 'root-already-wrapped.tsx');
|
|
233
|
+
const appDir = path.join(tmpDir, 'app');
|
|
234
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
235
|
+
fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
|
|
236
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
|
|
237
|
+
await (0, root_1.instrumentRoot)('root.tsx');
|
|
238
|
+
const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
|
|
239
|
+
// Should not add withSentry import or wrap again
|
|
240
|
+
(0, vitest_1.expect)(modifiedContent).toContain('withSentry(App)');
|
|
241
|
+
// Count occurrences of withSentry to ensure it's not duplicated
|
|
242
|
+
const withSentryOccurrences = (modifiedContent.match(/withSentry/g) || [])
|
|
243
|
+
.length;
|
|
244
|
+
(0, vitest_1.expect)(withSentryOccurrences).toBe(2); // One import, one usage
|
|
245
|
+
// The content should remain largely the same since withSentry is already used
|
|
246
|
+
(0, vitest_1.expect)(modifiedContent).toContain('export default withSentry(App)');
|
|
247
|
+
});
|
|
248
|
+
(0, vitest_1.it)('should handle ErrorBoundary as variable declaration', async () => {
|
|
249
|
+
const srcFile = path.join(fixturesDir, 'root-variable-error-boundary.tsx');
|
|
250
|
+
const appDir = path.join(tmpDir, 'app');
|
|
251
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
252
|
+
fs.copyFileSync(srcFile, path.join(appDir, 'root.tsx'));
|
|
253
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(tmpDir);
|
|
254
|
+
await (0, root_1.instrumentRoot)('root.tsx');
|
|
255
|
+
const modifiedContent = fs.readFileSync(path.join(appDir, 'root.tsx'), 'utf8');
|
|
256
|
+
(0, vitest_1.expect)(modifiedContent).toContain('import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix";');
|
|
257
|
+
(0, vitest_1.expect)(modifiedContent).toContain('withSentry(App)');
|
|
258
|
+
});
|
|
259
|
+
});
|
|
31
260
|
//# sourceMappingURL=root.test.js.map
|