@sentry/wizard 6.6.0 → 6.7.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 +28 -0
- package/LICENSE +97 -8
- package/dist/bin.js +5 -0
- package/dist/bin.js.map +1 -1
- package/dist/e2e-tests/tests/help-message.test.js +5 -1
- package/dist/e2e-tests/tests/help-message.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-15.test.js +79 -0
- package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-router.test.d.ts +1 -0
- package/dist/e2e-tests/tests/react-router.test.js +255 -0
- package/dist/e2e-tests/tests/react-router.test.js.map +1 -0
- package/dist/e2e-tests/utils/index.d.ts +8 -2
- package/dist/e2e-tests/utils/index.js +72 -21
- package/dist/e2e-tests/utils/index.js.map +1 -1
- package/dist/lib/Constants.d.ts +1 -0
- package/dist/lib/Constants.js +5 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/src/android/android-wizard.js +8 -1
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/angular/angular-wizard.js +8 -1
- package/dist/src/angular/angular-wizard.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +8 -1
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/flutter/flutter-wizard.js +8 -1
- package/dist/src/flutter/flutter-wizard.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +35 -9
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +3 -3
- package/dist/src/nextjs/templates.js +18 -7
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nuxt/nuxt-wizard.js +8 -1
- package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +8 -1
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-router/codemods/client.entry.d.ts +1 -0
- package/dist/src/react-router/codemods/client.entry.js +73 -0
- package/dist/src/react-router/codemods/client.entry.js.map +1 -0
- package/dist/src/react-router/codemods/react-router-config.d.ts +9 -0
- package/dist/src/react-router/codemods/react-router-config.js +178 -0
- package/dist/src/react-router/codemods/react-router-config.js.map +1 -0
- package/dist/src/react-router/codemods/root.d.ts +1 -0
- package/dist/src/react-router/codemods/root.js +171 -0
- package/dist/src/react-router/codemods/root.js.map +1 -0
- package/dist/src/react-router/codemods/routes-config.d.ts +1 -0
- package/dist/src/react-router/codemods/routes-config.js +106 -0
- package/dist/src/react-router/codemods/routes-config.js.map +1 -0
- package/dist/src/react-router/codemods/server-entry.d.ts +4 -0
- package/dist/src/react-router/codemods/server-entry.js +275 -0
- package/dist/src/react-router/codemods/server-entry.js.map +1 -0
- package/dist/src/react-router/codemods/utils.d.ts +2 -0
- package/dist/src/react-router/codemods/utils.js +13 -0
- package/dist/src/react-router/codemods/utils.js.map +1 -0
- package/dist/src/react-router/codemods/vite.d.ts +8 -0
- package/dist/src/react-router/codemods/vite.js +169 -0
- package/dist/src/react-router/codemods/vite.js.map +1 -0
- package/dist/src/react-router/react-router-wizard.d.ts +2 -0
- package/dist/src/react-router/react-router-wizard.js +254 -0
- package/dist/src/react-router/react-router-wizard.js.map +1 -0
- package/dist/src/react-router/sdk-example.d.ts +18 -0
- package/dist/src/react-router/sdk-example.js +306 -0
- package/dist/src/react-router/sdk-example.js.map +1 -0
- package/dist/src/react-router/sdk-setup.d.ts +17 -0
- package/dist/src/react-router/sdk-setup.js +250 -0
- package/dist/src/react-router/sdk-setup.js.map +1 -0
- package/dist/src/react-router/templates.d.ts +11 -0
- package/dist/src/react-router/templates.js +273 -0
- package/dist/src/react-router/templates.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +8 -1
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/run.d.ts +2 -1
- package/dist/src/run.js +6 -0
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +8 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +8 -1
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +30 -0
- package/dist/src/utils/ast-utils.js +71 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack/index.d.ts +5 -2
- package/dist/src/utils/clack/index.js +14 -2
- package/dist/src/utils/clack/index.js.map +1 -1
- package/dist/src/utils/types.d.ts +9 -0
- package/dist/src/utils/types.js.map +1 -1
- 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/nextjs/templates.test.js +20 -0
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/react-router/codemods/client-entry.test.d.ts +1 -0
- package/dist/test/react-router/codemods/client-entry.test.js +168 -0
- package/dist/test/react-router/codemods/client-entry.test.js.map +1 -0
- package/dist/test/react-router/codemods/react-router-config.test.d.ts +1 -0
- package/dist/test/react-router/codemods/react-router-config.test.js +168 -0
- package/dist/test/react-router/codemods/react-router-config.test.js.map +1 -0
- package/dist/test/react-router/codemods/root.test.d.ts +1 -0
- package/dist/test/react-router/codemods/root.test.js +178 -0
- package/dist/test/react-router/codemods/root.test.js.map +1 -0
- package/dist/test/react-router/codemods/server-entry.test.d.ts +1 -0
- package/dist/test/react-router/codemods/server-entry.test.js +415 -0
- package/dist/test/react-router/codemods/server-entry.test.js.map +1 -0
- package/dist/test/react-router/codemods/vite.test.d.ts +1 -0
- package/dist/test/react-router/codemods/vite.test.js +158 -0
- package/dist/test/react-router/codemods/vite.test.js.map +1 -0
- package/dist/test/react-router/routes-config.test.d.ts +1 -0
- package/dist/test/react-router/routes-config.test.js +156 -0
- package/dist/test/react-router/routes-config.test.js.map +1 -0
- package/dist/test/react-router/sdk-setup.test.d.ts +1 -0
- package/dist/test/react-router/sdk-setup.test.js +411 -0
- package/dist/test/react-router/sdk-setup.test.js.map +1 -0
- package/dist/test/react-router/templates.test.d.ts +1 -0
- package/dist/test/react-router/templates.test.js +220 -0
- package/dist/test/react-router/templates.test.js.map +1 -0
- package/dist/test/utils/clack/index.test.js +1 -1
- package/dist/test/utils/clack/index.test.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-entry.test.js","sourceRoot":"","sources":["../../../../test/react-router/codemods/server-entry.test.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+DAA+D;AAC/D,uDAAuD;;;;;;;;;;;;;;;;;;;;;;;;;AAEvD,mCAAyE;AACzE,uCAAyB;AACzB,2CAA6B;AAC7B,+CAAiC;AACjC,kFAIyD;AAEzD,kFAAkF;AAClF,uCAAkD;AAElD,WAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC7B,MAAM,IAAI,GAAG;QACX,GAAG,EAAE;YACH,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,OAAO,EAAE,WAAE,CAAC,EAAE,EAAE;SACjB;KACF,CAAC;IACF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,GAAG,IAAI;KACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,WAAE,CAAC,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,CAAC;IACzC,KAAK,EAAE,WAAE,CAAC,EAAE,EAAE;CACf,CAAC,CAAC,CAAC;AAEJ,IAAA,iBAAQ,EAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,MAAc,CAAC;IACnB,IAAI,OAAe,CAAC;IAEpB,IAAA,mBAAU,EAAC,GAAG,EAAE;QACd,WAAE,CAAC,aAAa,EAAE,CAAC;QAEnB,4CAA4C;QAC5C,MAAM,GA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KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,2CAA2C;QAE3C,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,sCAAsC,CAAC,CAAC;QAClE,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,OAAO,CAAC,CAAC;QAEpC,qCAAqC;QACrC,MAAM,eAAe,GAAG;YACtB,IAAI,EAAE,wBAAwB;YAC9B,WAAW,EAAE;gBACX,IAAI,EAAE,qBAAqB;gBAC3B,IAAI,EAAE,OAAO;gBACb,YAAY,EAAE,EAAE,EAAE,2BAA2B;aAC9C;SACF,CAAC;QAEF,sCAAsC;QACtC,wFAAwF;QACvF,GAAG,CAAC,IAAI,CAAC,IAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAE/C,gDAAgD;QAChD,IAAI,WAAW,GAAG,IAAI,CAAC;QACvB,IAAI;YACF,IAAA,oCAAqB,EAAC,GAAG,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACd,WAAW,GAAG,KAAK,CAAC;SACrB;QAED,2CAA2C;QAC3C,IAAA,eAAM,EAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as recast from 'recast';\nimport {\n instrumentServerEntry,\n instrumentHandleRequest,\n instrumentHandleError,\n} from '../../../src/react-router/codemods/server-entry';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, generateCode } from 'magicast';\n\nvi.mock('@clack/prompts', () => {\n const mock = {\n log: {\n warn: vi.fn(),\n info: vi.fn(),\n success: vi.fn(),\n },\n };\n return {\n default: mock,\n ...mock,\n };\n});\n\nvi.mock('../../../src/utils/debug', () => ({\n debug: vi.fn(),\n}));\n\ndescribe('instrumentServerEntry', () => {\n const fixturesDir = path.join(__dirname, 'fixtures', 'server-entry');\n let tmpDir: string;\n let tmpFile: string;\n\n beforeEach(() => {\n vi.clearAllMocks();\n\n // Create unique tmp directory for each test\n tmpDir = path.join(\n __dirname,\n 'fixtures',\n 'tmp',\n `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n tmpFile = path.join(tmpDir, 'entry.server.tsx');\n\n // Ensure tmp directory exists\n fs.mkdirSync(tmpDir, { recursive: true });\n });\n\n afterEach(() => {\n // Clean up tmp directory\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true });\n }\n });\n\n it('should add Sentry import and wrap handleRequest function', async () => {\n const basicContent = fs.readFileSync(\n path.join(fixturesDir, 'basic.tsx'),\n 'utf8',\n );\n\n fs.writeFileSync(tmpFile, basicContent);\n\n await instrumentServerEntry(tmpFile);\n\n const modifiedContent = fs.readFileSync(tmpFile, 'utf8');\n\n // Should add Sentry import\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n\n // Should wrap the existing handleRequest function\n expect(modifiedContent).toContain(\n 'export default Sentry.wrapSentryHandleRequest(handleRequest);',\n );\n\n // Should add the Sentry import at the top of the file (after existing imports)\n const lines = modifiedContent.split('\\n');\n const sentryImportLine = lines.findIndex((line) =>\n line.includes('import * as Sentry from \"@sentry/react-router\";'),\n );\n expect(sentryImportLine).toBeGreaterThanOrEqual(0);\n\n // Should create default handleError since none exists\n expect(modifiedContent).toContain(\n 'export const handleError = Sentry.createSentryHandleError({',\n );\n expect(modifiedContent).toContain('logErrors: false');\n });\n\n it('should handle already instrumented server entry without duplication', async () => {\n const alreadyInstrumentedContent = fs.readFileSync(\n path.join(fixturesDir, 'already-instrumented.tsx'),\n 'utf8',\n );\n\n fs.writeFileSync(tmpFile, alreadyInstrumentedContent);\n\n await instrumentServerEntry(tmpFile);\n\n const modifiedContent = fs.readFileSync(tmpFile, 'utf8');\n\n // Should not add duplicate imports or wrapping since already instrumented\n expect(modifiedContent).toContain(\n \"import * as Sentry from '@sentry/react-router';\",\n );\n expect(modifiedContent).toContain(\n 'export default Sentry.wrapSentryHandleRequest(handleRequest);',\n );\n\n // Should NOT add a new createSentryHandleError export since handleError already has captureException\n expect(modifiedContent).not.toContain(\n 'export const handleError = Sentry.createSentryHandleError({',\n );\n\n // Should preserve the existing handleError function with captureException\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n expect(modifiedContent).toContain('export async function handleError');\n });\n\n it('should handle variable export pattern with existing export', async () => {\n const variableExportContent = fs.readFileSync(\n path.join(fixturesDir, 'variable-export.tsx'),\n 'utf8',\n );\n\n fs.writeFileSync(tmpFile, variableExportContent);\n\n await instrumentServerEntry(tmpFile);\n\n const modifiedContent = fs.readFileSync(tmpFile, 'utf8');\n\n // Should add Sentry import and wrap handleRequest\n expect(modifiedContent).toContain(\n 'import * as Sentry from \"@sentry/react-router\";',\n );\n expect(modifiedContent).toContain(\n 'export default Sentry.wrapSentryHandleRequest(handleRequest);',\n );\n\n // Should instrument the existing handleError variable with captureException\n expect(modifiedContent).toContain('Sentry.captureException(error);');\n\n // Should preserve the variable export pattern\n expect(modifiedContent).toContain('export const handleError');\n });\n});\n\ndescribe('instrumentHandleRequest', () => {\n let tmpDir: string;\n\n beforeEach(() => {\n tmpDir = path.join(\n __dirname,\n 'fixtures',\n 'tmp',\n `handle-request-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n fs.mkdirSync(tmpDir, { recursive: true });\n });\n\n afterEach(() => {\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true });\n }\n });\n\n it('should add required imports when creating new handleRequest', async () => {\n const content = `// Empty server entry file`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n instrumentHandleRequest(mod);\n\n // Check if required imports were added\n const imports = mod.imports.$items;\n const hasServerRouter = imports.some(\n (item: any) =>\n item.imported === 'ServerRouter' && item.from === 'react-router',\n );\n const hasRenderToPipeableStream = imports.some(\n (item: any) =>\n item.imported === 'renderToPipeableStream' &&\n item.from === 'react-dom/server',\n );\n\n expect(hasServerRouter).toBe(true);\n expect(hasRenderToPipeableStream).toBe(true);\n });\n\n it('should not duplicate imports if they already exist', async () => {\n const content = `\nimport { ServerRouter } from 'react-router';\nimport { renderToPipeableStream } from 'react-dom/server';\nimport { createReadableStreamFromReadable } from '@react-router/node';\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n const originalImportsCount = mod.imports.$items.length;\n\n instrumentHandleRequest(mod);\n\n // Should not add duplicate imports\n expect(mod.imports.$items.length).toBe(originalImportsCount);\n });\n});\n\ndescribe('instrumentHandleError', () => {\n let tmpDir: string;\n\n beforeEach(() => {\n tmpDir = path.join(\n __dirname,\n 'fixtures',\n 'tmp',\n `handle-error-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n fs.mkdirSync(tmpDir, { recursive: true });\n });\n\n afterEach(() => {\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true });\n }\n });\n\n it('should not modify existing handleError with captureException', async () => {\n const content = `\nexport function handleError(error: unknown) {\n Sentry.captureException(error);\n console.error(error);\n}\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n const originalBodyLength = (mod.$ast as any).body.length;\n\n instrumentHandleError(mod);\n\n // Should not modify since captureException already exists\n expect((mod.$ast as any).body.length).toBe(originalBodyLength);\n });\n\n it('should not modify existing handleError with createSentryHandleError', async () => {\n const content = `\nexport const handleError = Sentry.createSentryHandleError({\n logErrors: false\n});\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const originalBodyLength = (mod.$ast as any).body.length;\n\n instrumentHandleError(mod);\n\n // Should not modify since createSentryHandleError already exists\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n expect((mod.$ast as any).body.length).toBe(originalBodyLength);\n });\n\n it('should add captureException to existing handleError function declaration without breaking AST', async () => {\n const content = `\nexport function handleError(error: unknown) {\n console.error('Custom error handling:', error);\n // some other logic here\n}\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This should not throw an error due to broken AST manipulation\n expect(() => instrumentHandleError(mod)).not.toThrow();\n\n // Verify the function was modified correctly\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n expect(modifiedCode).toContain(\n \"console.error('Custom error handling:', error)\",\n );\n });\n\n it('should add captureException to existing handleError variable declaration without breaking AST', async () => {\n const content = `\nexport const handleError = (error: unknown, { request }: { request: Request }) => {\n console.log('Handling error:', error.message);\n return new Response('Error occurred', { status: 500 });\n};\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This should not throw an error due to broken AST manipulation\n expect(() => instrumentHandleError(mod)).not.toThrow();\n\n // Verify the function was modified correctly\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n expect(modifiedCode).toContain(\n \"console.log('Handling error:', error.message)\",\n );\n });\n\n it('should handle existing handleError with only error parameter and add request parameter', async () => {\n const content = `\nexport const handleError = (error: unknown) => {\n console.error('Simple error handler:', error);\n};\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This should not throw an error due to broken AST manipulation\n expect(() => instrumentHandleError(mod)).not.toThrow();\n\n // Verify the function signature was updated correctly\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n expect(modifiedCode).toContain('if (!request.signal.aborted)');\n // Should add request parameter\n expect(modifiedCode).toMatch(\n /handleError.*=.*\\(\\s*error.*,\\s*\\{\\s*request\\s*\\}/,\n );\n });\n});\n\ndescribe('instrumentHandleError AST manipulation edge cases', () => {\n let tmpDir: string;\n\n beforeEach(() => {\n tmpDir = path.join(\n __dirname,\n 'fixtures',\n 'tmp',\n `ast-edge-cases-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n fs.mkdirSync(tmpDir, { recursive: true });\n });\n\n afterEach(() => {\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true });\n }\n });\n\n it('should handle function declaration with existing try-catch block', async () => {\n const content = `\nexport function handleError(error: unknown, { request }: { request: Request }) {\n try {\n console.error('Error occurred:', error);\n logToExternalService(error);\n } catch (loggingError) {\n console.warn('Failed to log error:', loggingError);\n }\n}\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This test will expose the broken AST logic\n expect(() => instrumentHandleError(mod)).not.toThrow();\n\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n expect(modifiedCode).toContain('if (!request.signal.aborted)');\n // Should preserve existing try-catch\n expect(modifiedCode).toContain('try {');\n expect(modifiedCode).toContain('} catch (loggingError) {');\n });\n\n it('should handle arrow function with block body', async () => {\n const content = `\nexport const handleError = (error: unknown, context: any) => {\n const { request } = context;\n console.error('Error in route:', error);\n return new Response('Internal Server Error', { status: 500 });\n};\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This test will expose the broken AST logic\n expect(() => instrumentHandleError(mod)).not.toThrow();\n\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n expect(modifiedCode).toContain('if (!request.signal.aborted)');\n });\n\n it('should demonstrate that the AST bug is now fixed - no longer throws TypeError', async () => {\n const content = `\nexport function handleError(error: unknown) {\n console.error('Error occurred:', error);\n}\n`;\n const tempFile = path.join(tmpDir, 'entry.server.tsx');\n fs.writeFileSync(tempFile, content);\n\n const mod = await loadFile(tempFile);\n\n // This test specifically targets the broken AST logic at lines 279-284 in server-entry.ts\n // The bug is in this code:\n // implementation.declarations[0].init.arguments[0].body.body.unshift(...)\n // Where 'implementation' is an IfStatement, not a VariableDeclaration\n\n let thrownError: Error | null = null;\n try {\n instrumentHandleError(mod);\n } catch (error) {\n thrownError = error as Error;\n }\n\n // The bug is fixed - no error should be thrown\n expect(thrownError).toBeNull();\n\n // And the code should be successfully modified\n const modifiedCode = generateCode(mod.$ast).code;\n expect(modifiedCode).toContain('Sentry.captureException(error)');\n\n // The error occurs because recast.parse() creates an IfStatement:\n // { type: 'IfStatement', test: ..., consequent: ... }\n // But the code tries to access .declarations[0] as if it were a VariableDeclaration\n });\n\n it('should demonstrate the specific line that breaks - recast.parse creates IfStatement not VariableDeclaration', () => {\n // This test shows exactly what the problematic line 278 in server-entry.ts creates\n const problematicCode = `if (!request.signal.aborted) {\n Sentry.captureException(error);\n}`;\n\n // This is what line 278 does: recast.parse(problematicCode).program.body[0]\n const implementation = recast.parse(problematicCode).program.body[0];\n\n // The implementation is an IfStatement, not a VariableDeclaration\n expect(implementation.type).toBe('IfStatement');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion\n expect((implementation as any).declarations).toBeUndefined();\n\n // But lines 279-284 try to access implementation.declarations[0].init.arguments[0].body.body\n // This will throw \"Cannot read properties of undefined (reading '0')\"\n expect(() => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-type-assertion\n const declarations = (implementation as any).declarations;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return declarations[0]; // This line will throw the error\n }).toThrow('Cannot read properties of undefined');\n });\n});\n\n// Test for Bug #1: Array access vulnerability\ndescribe('Array access vulnerability bugs', () => {\n let tmpDir: string;\n let tmpFile: string;\n\n beforeEach(() => {\n vi.clearAllMocks();\n\n // Create unique tmp directory for each test\n tmpDir = path.join(\n __dirname,\n 'fixtures',\n 'tmp',\n `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n tmpFile = path.join(tmpDir, 'entry.server.tsx');\n\n // Ensure tmp directory exists\n fs.mkdirSync(tmpDir, { recursive: true });\n });\n\n afterEach(() => {\n // Clean up tmp directory\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true, force: true });\n }\n });\n\n it('should safely handle VariableDeclaration with empty declarations array', () => {\n // This test verifies that the bug fix works correctly\n // Previously this would crash, but now it handles empty arrays safely\n\n // The implementation now includes proper safety checks, so we test that\n // it can handle edge cases without crashing\n\n // Test the actual safe implementation behavior\n const testResult = () => {\n // Simulate the safe check logic from the actual implementation\n const declarations: any[] = []; // Empty array\n if (!declarations || declarations.length === 0) {\n return false; // Safe early return\n }\n // This code would never be reached due to the safe check\n return declarations[0].id.name === 'handleError';\n };\n\n // Should return false safely without throwing\n expect(testResult()).toBe(false);\n });\n\n it('should safely handle VariableDeclaration with empty declarations array after fix', async () => {\n // This test will pass after we fix the bug\n\n fs.writeFileSync(tmpFile, 'export const handleError = () => {};');\n const mod = await loadFile(tmpFile);\n\n // Create a problematic AST structure\n const problematicNode = {\n type: 'ExportNamedDeclaration',\n declaration: {\n type: 'VariableDeclaration',\n kind: 'const',\n declarations: [], // Empty declarations array\n },\n };\n\n // Add the problematic node to the AST\n // @ts-expect-error - We need to access body for this test even though it's typed as any\n (mod.$ast.body as any[]).push(problematicNode);\n\n // After the fix, this should NOT throw an error\n let thrownError = null;\n try {\n instrumentHandleError(mod);\n } catch (error) {\n thrownError = error;\n }\n\n // After the fix, no error should be thrown\n expect(thrownError).toBeNull();\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs = __importStar(require("fs"));
|
|
27
|
+
const vitest_1 = require("vitest");
|
|
28
|
+
const vite_1 = require("../../../src/react-router/codemods/vite");
|
|
29
|
+
vitest_1.vi.mock('@clack/prompts', () => ({
|
|
30
|
+
default: {
|
|
31
|
+
log: {
|
|
32
|
+
info: vitest_1.vi.fn(),
|
|
33
|
+
warn: vitest_1.vi.fn(),
|
|
34
|
+
success: vitest_1.vi.fn(),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
vitest_1.vi.mock('fs', async () => {
|
|
39
|
+
const actual = await vitest_1.vi.importActual('fs');
|
|
40
|
+
return {
|
|
41
|
+
...actual,
|
|
42
|
+
existsSync: vitest_1.vi.fn(),
|
|
43
|
+
promises: {
|
|
44
|
+
...actual.promises,
|
|
45
|
+
readFile: vitest_1.vi.fn(),
|
|
46
|
+
writeFile: vitest_1.vi.fn(),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.describe)('Vite Config Instrumentation', () => {
|
|
51
|
+
const mockCwd = '/mock/project';
|
|
52
|
+
(0, vitest_1.beforeEach)(() => {
|
|
53
|
+
vitest_1.vi.clearAllMocks();
|
|
54
|
+
vitest_1.vi.spyOn(process, 'cwd').mockReturnValue(mockCwd);
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.afterEach)(() => {
|
|
57
|
+
vitest_1.vi.restoreAllMocks();
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.describe)('instrumentViteConfig', () => {
|
|
60
|
+
(0, vitest_1.it)('should throw error if vite config file does not exist', async () => {
|
|
61
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
62
|
+
await (0, vitest_1.expect)((0, vite_1.instrumentViteConfig)('my-org', 'my-project')).rejects.toThrow('Could not find vite.config.ts or vite.config.js');
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.it)('should detect and skip if Sentry content already exists', async () => {
|
|
65
|
+
const existingConfig = `import { defineConfig } from 'vite';
|
|
66
|
+
import { sentryReactRouter } from '@sentry/react-router';
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
plugins: [sentryReactRouter({ org: "my-org", project: "my-project" }, config)]
|
|
70
|
+
});`;
|
|
71
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
72
|
+
vitest_1.vi.mocked(fs.promises.readFile).mockResolvedValue(existingConfig);
|
|
73
|
+
const result = await (0, vite_1.instrumentViteConfig)('my-org', 'my-project');
|
|
74
|
+
(0, vitest_1.expect)(result.wasConverted).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('should add sentryReactRouter plugin and convert to function form', async () => {
|
|
77
|
+
const simpleConfig = `import { defineConfig } from 'vite';
|
|
78
|
+
|
|
79
|
+
export default defineConfig({
|
|
80
|
+
plugins: []
|
|
81
|
+
});`;
|
|
82
|
+
const writtenFiles = {};
|
|
83
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
84
|
+
vitest_1.vi.mocked(fs.promises.readFile).mockResolvedValue(simpleConfig);
|
|
85
|
+
vitest_1.vi.mocked(fs.promises.writeFile).mockImplementation((filePath, content) => {
|
|
86
|
+
writtenFiles[filePath] = content;
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
});
|
|
89
|
+
const result = await (0, vite_1.instrumentViteConfig)('my-org', 'my-project');
|
|
90
|
+
(0, vitest_1.expect)(result.wasConverted).toBe(true);
|
|
91
|
+
const writtenConfig = Object.values(writtenFiles)[0];
|
|
92
|
+
(0, vitest_1.expect)(writtenConfig).toContain('sentryReactRouter');
|
|
93
|
+
(0, vitest_1.expect)(writtenConfig).toContain('org: "my-org"');
|
|
94
|
+
(0, vitest_1.expect)(writtenConfig).toContain('project: "my-project"');
|
|
95
|
+
(0, vitest_1.expect)(writtenConfig).toContain('config =>');
|
|
96
|
+
});
|
|
97
|
+
(0, vitest_1.it)('should work with existing function form', async () => {
|
|
98
|
+
const functionConfig = `import { defineConfig } from 'vite';
|
|
99
|
+
|
|
100
|
+
export default defineConfig(config => ({
|
|
101
|
+
plugins: []
|
|
102
|
+
}));`;
|
|
103
|
+
const writtenFiles = {};
|
|
104
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
105
|
+
vitest_1.vi.mocked(fs.promises.readFile).mockResolvedValue(functionConfig);
|
|
106
|
+
vitest_1.vi.mocked(fs.promises.writeFile).mockImplementation((filePath, content) => {
|
|
107
|
+
writtenFiles[filePath] = content;
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
});
|
|
110
|
+
const result = await (0, vite_1.instrumentViteConfig)('my-org', 'my-project');
|
|
111
|
+
(0, vitest_1.expect)(result.wasConverted).toBe(false);
|
|
112
|
+
const writtenConfig = Object.values(writtenFiles)[0];
|
|
113
|
+
(0, vitest_1.expect)(writtenConfig).toContain('sentryReactRouter');
|
|
114
|
+
(0, vitest_1.expect)(writtenConfig).toContain('org: "my-org"');
|
|
115
|
+
(0, vitest_1.expect)(writtenConfig).toContain('project: "my-project"');
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('should prefer vite.config.ts over vite.config.js', async () => {
|
|
118
|
+
const configContent = `import { defineConfig } from 'vite';
|
|
119
|
+
export default defineConfig({ plugins: [] });`;
|
|
120
|
+
const writtenFiles = {};
|
|
121
|
+
// First call checks for vite.config.ts (returns true), second call validates it exists
|
|
122
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
123
|
+
vitest_1.vi.mocked(fs.promises.readFile).mockResolvedValue(configContent);
|
|
124
|
+
vitest_1.vi.mocked(fs.promises.writeFile).mockImplementation((filePath, content) => {
|
|
125
|
+
writtenFiles[filePath] = content;
|
|
126
|
+
return Promise.resolve();
|
|
127
|
+
});
|
|
128
|
+
await (0, vite_1.instrumentViteConfig)('my-org', 'my-project');
|
|
129
|
+
// Should write to vite.config.ts, not vite.config.js
|
|
130
|
+
const writtenPath = Object.keys(writtenFiles)[0];
|
|
131
|
+
(0, vitest_1.expect)(writtenPath).toContain('vite.config.ts');
|
|
132
|
+
(0, vitest_1.expect)(writtenPath).not.toContain('vite.config.js');
|
|
133
|
+
});
|
|
134
|
+
(0, vitest_1.it)('should work with function expression form', async () => {
|
|
135
|
+
const functionConfig = `import { defineConfig } from 'vite';
|
|
136
|
+
|
|
137
|
+
export default defineConfig(function(config) {
|
|
138
|
+
return {
|
|
139
|
+
plugins: []
|
|
140
|
+
};
|
|
141
|
+
});`;
|
|
142
|
+
const writtenFiles = {};
|
|
143
|
+
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
144
|
+
vitest_1.vi.mocked(fs.promises.readFile).mockResolvedValue(functionConfig);
|
|
145
|
+
vitest_1.vi.mocked(fs.promises.writeFile).mockImplementation((filePath, content) => {
|
|
146
|
+
writtenFiles[filePath] = content;
|
|
147
|
+
return Promise.resolve();
|
|
148
|
+
});
|
|
149
|
+
const result = await (0, vite_1.instrumentViteConfig)('my-org', 'my-project');
|
|
150
|
+
(0, vitest_1.expect)(result.wasConverted).toBe(false);
|
|
151
|
+
const writtenConfig = Object.values(writtenFiles)[0];
|
|
152
|
+
(0, vitest_1.expect)(writtenConfig).toContain('sentryReactRouter');
|
|
153
|
+
(0, vitest_1.expect)(writtenConfig).toContain('org: "my-org"');
|
|
154
|
+
(0, vitest_1.expect)(writtenConfig).toContain('project: "my-project"');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
//# sourceMappingURL=vite.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.test.js","sourceRoot":"","sources":["../../../../test/react-router/codemods/vite.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,mCAAyE;AACzE,kEAA+E;AAE/E,WAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,OAAO,EAAE;QACP,GAAG,EAAE;YACH,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,IAAI,EAAE,WAAE,CAAC,EAAE,EAAE;YACb,OAAO,EAAE,WAAE,CAAC,EAAE,EAAE;SACjB;KACF;CACF,CAAC,CAAC,CAAC;AACJ,WAAE,CAAC,IAAI,CA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CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC/C,WAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YAClE,WAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,kBAAkB,CACjD,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;gBACpB,YAAY,CAAC,QAAkB,CAAC,GAAG,OAAiB,CAAC;gBACrD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC,CACF,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAoB,EAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAElE,IAAA,eAAM,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAExC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;YACrD,IAAA,eAAM,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;YACrD,IAAA,eAAM,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YACjD,IAAA,eAAM,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';\nimport { instrumentViteConfig } from '../../../src/react-router/codemods/vite';\n\nvi.mock('@clack/prompts', () => ({\n default: {\n log: {\n info: vi.fn(),\n warn: vi.fn(),\n success: vi.fn(),\n },\n },\n}));\nvi.mock('fs', async () => {\n const actual = await vi.importActual<typeof fs>('fs');\n return {\n ...actual,\n existsSync: vi.fn(),\n promises: {\n ...actual.promises,\n readFile: vi.fn(),\n writeFile: vi.fn(),\n },\n };\n});\n\ndescribe('Vite Config Instrumentation', () => {\n const mockCwd = '/mock/project';\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(process, 'cwd').mockReturnValue(mockCwd);\n });\n\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n describe('instrumentViteConfig', () => {\n it('should throw error if vite config file does not exist', async () => {\n vi.mocked(fs.existsSync).mockReturnValue(false);\n\n await expect(\n instrumentViteConfig('my-org', 'my-project'),\n ).rejects.toThrow('Could not find vite.config.ts or vite.config.js');\n });\n\n it('should detect and skip if Sentry content already exists', async () => {\n const existingConfig = `import { defineConfig } from 'vite';\nimport { sentryReactRouter } from '@sentry/react-router';\n\nexport default defineConfig({\n plugins: [sentryReactRouter({ org: \"my-org\", project: \"my-project\" }, config)]\n});`;\n\n vi.mocked(fs.existsSync).mockReturnValue(true);\n vi.mocked(fs.promises.readFile).mockResolvedValue(existingConfig);\n\n const result = await instrumentViteConfig('my-org', 'my-project');\n\n expect(result.wasConverted).toBe(false);\n });\n\n it('should add sentryReactRouter plugin and convert to function form', async () => {\n const simpleConfig = `import { defineConfig } from 'vite';\n\nexport default defineConfig({\n plugins: []\n});`;\n\n const writtenFiles: Record<string, string> = {};\n\n vi.mocked(fs.existsSync).mockReturnValue(true);\n vi.mocked(fs.promises.readFile).mockResolvedValue(simpleConfig);\n vi.mocked(fs.promises.writeFile).mockImplementation(\n (filePath, content) => {\n writtenFiles[filePath as string] = content as string;\n return Promise.resolve();\n },\n );\n\n const result = await instrumentViteConfig('my-org', 'my-project');\n\n expect(result.wasConverted).toBe(true);\n\n const writtenConfig = Object.values(writtenFiles)[0];\n expect(writtenConfig).toContain('sentryReactRouter');\n expect(writtenConfig).toContain('org: \"my-org\"');\n expect(writtenConfig).toContain('project: \"my-project\"');\n expect(writtenConfig).toContain('config =>');\n });\n\n it('should work with existing function form', async () => {\n const functionConfig = `import { defineConfig } from 'vite';\n\nexport default defineConfig(config => ({\n plugins: []\n}));`;\n\n const writtenFiles: Record<string, string> = {};\n\n vi.mocked(fs.existsSync).mockReturnValue(true);\n vi.mocked(fs.promises.readFile).mockResolvedValue(functionConfig);\n vi.mocked(fs.promises.writeFile).mockImplementation(\n (filePath, content) => {\n writtenFiles[filePath as string] = content as string;\n return Promise.resolve();\n },\n );\n\n const result = await instrumentViteConfig('my-org', 'my-project');\n\n expect(result.wasConverted).toBe(false);\n\n const writtenConfig = Object.values(writtenFiles)[0];\n expect(writtenConfig).toContain('sentryReactRouter');\n expect(writtenConfig).toContain('org: \"my-org\"');\n expect(writtenConfig).toContain('project: \"my-project\"');\n });\n\n it('should prefer vite.config.ts over vite.config.js', async () => {\n const configContent = `import { defineConfig } from 'vite';\nexport default defineConfig({ plugins: [] });`;\n\n const writtenFiles: Record<string, string> = {};\n\n // First call checks for vite.config.ts (returns true), second call validates it exists\n vi.mocked(fs.existsSync).mockReturnValue(true);\n vi.mocked(fs.promises.readFile).mockResolvedValue(configContent);\n vi.mocked(fs.promises.writeFile).mockImplementation(\n (filePath, content) => {\n writtenFiles[filePath as string] = content as string;\n return Promise.resolve();\n },\n );\n\n await instrumentViteConfig('my-org', 'my-project');\n\n // Should write to vite.config.ts, not vite.config.js\n const writtenPath = Object.keys(writtenFiles)[0];\n expect(writtenPath).toContain('vite.config.ts');\n expect(writtenPath).not.toContain('vite.config.js');\n });\n\n it('should work with function expression form', async () => {\n const functionConfig = `import { defineConfig } from 'vite';\n\nexport default defineConfig(function(config) {\n return {\n plugins: []\n };\n});`;\n\n const writtenFiles: Record<string, string> = {};\n\n vi.mocked(fs.existsSync).mockReturnValue(true);\n vi.mocked(fs.promises.readFile).mockResolvedValue(functionConfig);\n vi.mocked(fs.promises.writeFile).mockImplementation(\n (filePath, content) => {\n writtenFiles[filePath as string] = content as string;\n return Promise.resolve();\n },\n );\n\n const result = await instrumentViteConfig('my-org', 'my-project');\n\n expect(result.wasConverted).toBe(false);\n\n const writtenConfig = Object.values(writtenFiles)[0];\n expect(writtenConfig).toContain('sentryReactRouter');\n expect(writtenConfig).toContain('org: \"my-org\"');\n expect(writtenConfig).toContain('project: \"my-project\"');\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const vitest_1 = require("vitest");
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const routes_config_1 = require("../../src/react-router/codemods/routes-config");
|
|
30
|
+
vitest_1.vi.mock('@clack/prompts', () => {
|
|
31
|
+
const mock = {
|
|
32
|
+
log: {
|
|
33
|
+
warn: vitest_1.vi.fn(),
|
|
34
|
+
info: vitest_1.vi.fn(),
|
|
35
|
+
success: vitest_1.vi.fn(),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
default: mock,
|
|
40
|
+
...mock,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.describe)('addRoutesToConfig codemod', () => {
|
|
44
|
+
let tmpDir;
|
|
45
|
+
let appDir;
|
|
46
|
+
let routesConfigPath;
|
|
47
|
+
(0, vitest_1.beforeEach)(() => {
|
|
48
|
+
vitest_1.vi.clearAllMocks();
|
|
49
|
+
// Create unique tmp directory for each test
|
|
50
|
+
tmpDir = path.join(__dirname, 'tmp', `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
|
|
51
|
+
appDir = path.join(tmpDir, 'app');
|
|
52
|
+
routesConfigPath = path.join(appDir, 'routes.ts');
|
|
53
|
+
fs.mkdirSync(appDir, { recursive: true });
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.afterEach)(() => {
|
|
56
|
+
// Clean up
|
|
57
|
+
if (fs.existsSync(tmpDir)) {
|
|
58
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('should add routes to existing configuration', async () => {
|
|
62
|
+
// Create a routes.ts file
|
|
63
|
+
const routesContent = `import type { RouteConfig } from "@react-router/dev/routes";
|
|
64
|
+
import { index, route } from "@react-router/dev/routes";
|
|
65
|
+
|
|
66
|
+
export default [
|
|
67
|
+
index("routes/home.tsx"),
|
|
68
|
+
route("/about", "routes/about.tsx"),
|
|
69
|
+
] satisfies RouteConfig;`;
|
|
70
|
+
fs.writeFileSync(routesConfigPath, routesContent);
|
|
71
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
72
|
+
// Check that both routes were added
|
|
73
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
74
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/sentry-example-page", "routes/sentry-example-page.tsx")');
|
|
75
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/api/sentry-example-api", "routes/api.sentry-example-api.ts")');
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.it)('should handle JavaScript projects correctly', async () => {
|
|
78
|
+
// Create a routes.ts file
|
|
79
|
+
const routesContent = `import type { RouteConfig } from "@react-router/dev/routes";
|
|
80
|
+
import { index, route } from "@react-router/dev/routes";
|
|
81
|
+
|
|
82
|
+
export default [
|
|
83
|
+
index("routes/home.jsx"),
|
|
84
|
+
] satisfies RouteConfig;`;
|
|
85
|
+
fs.writeFileSync(routesConfigPath, routesContent);
|
|
86
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, false); // JavaScript project
|
|
87
|
+
// Check that both routes were added with .jsx/.js extensions
|
|
88
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
89
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/sentry-example-page", "routes/sentry-example-page.jsx")');
|
|
90
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/api/sentry-example-api", "routes/api.sentry-example-api.js")');
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.it)('should not duplicate routes if they already exist', async () => {
|
|
93
|
+
// Create a routes.ts file with both routes already present
|
|
94
|
+
const routesContent = `import type { RouteConfig } from "@react-router/dev/routes";
|
|
95
|
+
import { index, route } from "@react-router/dev/routes";
|
|
96
|
+
|
|
97
|
+
export default [
|
|
98
|
+
index("routes/home.tsx"),
|
|
99
|
+
route("/sentry-example-page", "routes/sentry-example-page.tsx"),
|
|
100
|
+
route("/api/sentry-example-api", "routes/api.sentry-example-api.ts"),
|
|
101
|
+
] satisfies RouteConfig;`;
|
|
102
|
+
fs.writeFileSync(routesConfigPath, routesContent);
|
|
103
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
104
|
+
// Check that the routes were not duplicated
|
|
105
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
106
|
+
const pageRouteMatches = updatedContent.match(/route\("\/sentry-example-page"/g);
|
|
107
|
+
const apiRouteMatches = updatedContent.match(/route\("\/api\/sentry-example-api"/g);
|
|
108
|
+
(0, vitest_1.expect)(pageRouteMatches).toHaveLength(1);
|
|
109
|
+
(0, vitest_1.expect)(apiRouteMatches).toHaveLength(1);
|
|
110
|
+
});
|
|
111
|
+
(0, vitest_1.it)('should add route import when it does not exist', async () => {
|
|
112
|
+
// Create a routes.ts file without route import
|
|
113
|
+
const routesContent = `import type { RouteConfig } from "@react-router/dev/routes";
|
|
114
|
+
import { index } from "@react-router/dev/routes";
|
|
115
|
+
|
|
116
|
+
export default [
|
|
117
|
+
index("routes/home.tsx"),
|
|
118
|
+
] satisfies RouteConfig;`;
|
|
119
|
+
fs.writeFileSync(routesConfigPath, routesContent);
|
|
120
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
121
|
+
// Check that the route import was added
|
|
122
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
123
|
+
(0, vitest_1.expect)(updatedContent).toContain('route');
|
|
124
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/sentry-example-page", "routes/sentry-example-page.tsx")');
|
|
125
|
+
});
|
|
126
|
+
(0, vitest_1.it)('should create default export when it does not exist', async () => {
|
|
127
|
+
// Create a routes.ts file without default export
|
|
128
|
+
const routesContent = `import type { RouteConfig } from "@react-router/dev/routes";
|
|
129
|
+
import { index, route } from "@react-router/dev/routes";`;
|
|
130
|
+
fs.writeFileSync(routesConfigPath, routesContent);
|
|
131
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
132
|
+
// Check that the default export was created
|
|
133
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
134
|
+
(0, vitest_1.expect)(updatedContent).toContain('export default [');
|
|
135
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/sentry-example-page", "routes/sentry-example-page.tsx")');
|
|
136
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/api/sentry-example-api", "routes/api.sentry-example-api.ts")');
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.it)('should handle empty file gracefully', async () => {
|
|
139
|
+
// Create an empty routes.ts file
|
|
140
|
+
fs.writeFileSync(routesConfigPath, '');
|
|
141
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
142
|
+
// Check that everything was added from scratch
|
|
143
|
+
const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');
|
|
144
|
+
(0, vitest_1.expect)(updatedContent).toContain('import { route } from "@react-router/dev/routes";');
|
|
145
|
+
(0, vitest_1.expect)(updatedContent).toContain('export default [');
|
|
146
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/sentry-example-page", "routes/sentry-example-page.tsx")');
|
|
147
|
+
(0, vitest_1.expect)(updatedContent).toContain('route("/api/sentry-example-api", "routes/api.sentry-example-api.ts")');
|
|
148
|
+
});
|
|
149
|
+
(0, vitest_1.it)('should skip if file does not exist', async () => {
|
|
150
|
+
// Don't create the file
|
|
151
|
+
await (0, routes_config_1.addRoutesToConfig)(routesConfigPath, true);
|
|
152
|
+
// Should not create the file if it doesn't exist
|
|
153
|
+
(0, vitest_1.expect)(fs.existsSync(routesConfigPath)).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=routes-config.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-config.test.js","sourceRoot":"","sources":["../../../test/react-router/routes-config.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAyE;AACzE,uCAAyB;AACzB,2CAA6B;AAC7B,iFAAkF;AAElF,WAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC7B,MAAM,IAAI,GAAG;QACX,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 'vitest';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { addRoutesToConfig } from '../../src/react-router/codemods/routes-config';\n\nvi.mock('@clack/prompts', () => {\n const mock = {\n log: {\n warn: vi.fn(),\n info: vi.fn(),\n success: vi.fn(),\n },\n };\n return {\n default: mock,\n ...mock,\n };\n});\n\ndescribe('addRoutesToConfig codemod', () => {\n let tmpDir: string;\n let appDir: string;\n let routesConfigPath: string;\n\n beforeEach(() => {\n vi.clearAllMocks();\n\n // Create unique tmp directory for each test\n tmpDir = path.join(\n __dirname,\n 'tmp',\n `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,\n );\n appDir = path.join(tmpDir, 'app');\n routesConfigPath = path.join(appDir, 'routes.ts');\n\n fs.mkdirSync(appDir, { recursive: true });\n });\n\n afterEach(() => {\n // Clean up\n if (fs.existsSync(tmpDir)) {\n fs.rmSync(tmpDir, { recursive: true, force: true });\n }\n });\n\n it('should add routes to existing configuration', async () => {\n // Create a routes.ts file\n const routesContent = `import type { RouteConfig } from \"@react-router/dev/routes\";\nimport { index, route } from \"@react-router/dev/routes\";\n\nexport default [\n index(\"routes/home.tsx\"),\n route(\"/about\", \"routes/about.tsx\"),\n] satisfies RouteConfig;`;\n\n fs.writeFileSync(routesConfigPath, routesContent);\n\n await addRoutesToConfig(routesConfigPath, true);\n\n // Check that both routes were added\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n expect(updatedContent).toContain(\n 'route(\"/sentry-example-page\", \"routes/sentry-example-page.tsx\")',\n );\n expect(updatedContent).toContain(\n 'route(\"/api/sentry-example-api\", \"routes/api.sentry-example-api.ts\")',\n );\n });\n\n it('should handle JavaScript projects correctly', async () => {\n // Create a routes.ts file\n const routesContent = `import type { RouteConfig } from \"@react-router/dev/routes\";\nimport { index, route } from \"@react-router/dev/routes\";\n\nexport default [\n index(\"routes/home.jsx\"),\n] satisfies RouteConfig;`;\n\n fs.writeFileSync(routesConfigPath, routesContent);\n\n await addRoutesToConfig(routesConfigPath, false); // JavaScript project\n\n // Check that both routes were added with .jsx/.js extensions\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n expect(updatedContent).toContain(\n 'route(\"/sentry-example-page\", \"routes/sentry-example-page.jsx\")',\n );\n expect(updatedContent).toContain(\n 'route(\"/api/sentry-example-api\", \"routes/api.sentry-example-api.js\")',\n );\n });\n\n it('should not duplicate routes if they already exist', async () => {\n // Create a routes.ts file with both routes already present\n const routesContent = `import type { RouteConfig } from \"@react-router/dev/routes\";\nimport { index, route } from \"@react-router/dev/routes\";\n\nexport default [\n index(\"routes/home.tsx\"),\n route(\"/sentry-example-page\", \"routes/sentry-example-page.tsx\"),\n route(\"/api/sentry-example-api\", \"routes/api.sentry-example-api.ts\"),\n] satisfies RouteConfig;`;\n\n fs.writeFileSync(routesConfigPath, routesContent);\n\n await addRoutesToConfig(routesConfigPath, true);\n\n // Check that the routes were not duplicated\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n const pageRouteMatches = updatedContent.match(\n /route\\(\"\\/sentry-example-page\"/g,\n );\n const apiRouteMatches = updatedContent.match(\n /route\\(\"\\/api\\/sentry-example-api\"/g,\n );\n expect(pageRouteMatches).toHaveLength(1);\n expect(apiRouteMatches).toHaveLength(1);\n });\n\n it('should add route import when it does not exist', async () => {\n // Create a routes.ts file without route import\n const routesContent = `import type { RouteConfig } from \"@react-router/dev/routes\";\nimport { index } from \"@react-router/dev/routes\";\n\nexport default [\n index(\"routes/home.tsx\"),\n] satisfies RouteConfig;`;\n\n fs.writeFileSync(routesConfigPath, routesContent);\n\n await addRoutesToConfig(routesConfigPath, true);\n\n // Check that the route import was added\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n expect(updatedContent).toContain('route');\n expect(updatedContent).toContain(\n 'route(\"/sentry-example-page\", \"routes/sentry-example-page.tsx\")',\n );\n });\n\n it('should create default export when it does not exist', async () => {\n // Create a routes.ts file without default export\n const routesContent = `import type { RouteConfig } from \"@react-router/dev/routes\";\nimport { index, route } from \"@react-router/dev/routes\";`;\n\n fs.writeFileSync(routesConfigPath, routesContent);\n\n await addRoutesToConfig(routesConfigPath, true);\n\n // Check that the default export was created\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n expect(updatedContent).toContain('export default [');\n expect(updatedContent).toContain(\n 'route(\"/sentry-example-page\", \"routes/sentry-example-page.tsx\")',\n );\n expect(updatedContent).toContain(\n 'route(\"/api/sentry-example-api\", \"routes/api.sentry-example-api.ts\")',\n );\n });\n\n it('should handle empty file gracefully', async () => {\n // Create an empty routes.ts file\n fs.writeFileSync(routesConfigPath, '');\n\n await addRoutesToConfig(routesConfigPath, true);\n\n // Check that everything was added from scratch\n const updatedContent = fs.readFileSync(routesConfigPath, 'utf-8');\n expect(updatedContent).toContain(\n 'import { route } from \"@react-router/dev/routes\";',\n );\n expect(updatedContent).toContain('export default [');\n expect(updatedContent).toContain(\n 'route(\"/sentry-example-page\", \"routes/sentry-example-page.tsx\")',\n );\n expect(updatedContent).toContain(\n 'route(\"/api/sentry-example-api\", \"routes/api.sentry-example-api.ts\")',\n );\n });\n\n it('should skip if file does not exist', async () => {\n // Don't create the file\n await addRoutesToConfig(routesConfigPath, true);\n\n // Should not create the file if it doesn't exist\n expect(fs.existsSync(routesConfigPath)).toBe(false);\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|