From dbe1cd5ced6fae4651d480f8ce58bc25469535e1 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 11 Oct 2022 20:57:55 +0800 Subject: [PATCH] wip(uts): compiler --- .../__tests__/__snapshots__/uts.spec.ts.snap | 46 ++++++++---------- .../uni-stacktracey/__tests__/uts.spec.ts | 48 ++++++++----------- .../dist/uni-stacktracey.cjs.js | 12 ++++- .../dist/uni-stacktracey.es.js | 11 ++++- packages/uni-stacktracey/src/index.ts | 3 +- packages/uni-stacktracey/src/utils.ts | 21 +++++++- .../test-uts1/utssdk/app-ios/index.swift.map | 1 + .../app/utssdk/test/app-android/index.kt.map | 2 +- .../app/utssdk/test/app-ios/index.swift.map | 1 + .../app/utssdk/test2/app-ios/index.swift.map | 1 + 10 files changed, 85 insertions(+), 61 deletions(-) create mode 100644 packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uts1/utssdk/app-ios/index.swift.map create mode 100644 packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-ios/index.swift.map create mode 100644 packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test2/app-ios/index.swift.map diff --git a/packages/uni-stacktracey/__tests__/__snapshots__/uts.spec.ts.snap b/packages/uni-stacktracey/__tests__/__snapshots__/uts.spec.ts.snap index 7ddc088b4..35af7cda4 100644 --- a/packages/uni-stacktracey/__tests__/__snapshots__/uts.spec.ts.snap +++ b/packages/uni-stacktracey/__tests__/__snapshots__/uts.spec.ts.snap @@ -10,20 +10,7 @@ at uni_modules/test-uts1/utssdk/index.uts:2:10 4 | -FAILURE: Build failed with an exception. - -* What went wrong: -Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'. -> Compilation error. See log for more details - -* Try: -> Run with --stacktrace option to get the stack trace. -> Run with --info or --debug option to get more log output. -> Run with --scan to get full insights. - -* Get more help at https://help.gradle.org - -BUILD FAILED in 50s" +FAILURE: Build failed with an exception." `; exports[`code-frame-uts android 2`] = ` @@ -36,18 +23,27 @@ at utssdk/test2/index.uts:2:10 4 | -FAILURE: Build failed with an exception. - -* What went wrong: -Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'. -> Compilation error. See log for more details +FAILURE: Build failed with an exception." +`; -* Try: -> Run with --stacktrace option to get the stack trace. -> Run with --info or --debug option to get more log output. -> Run with --scan to get full insights. +exports[`code-frame-uts ios 1`] = ` +"CompileSwift normal armv7 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS') +error: cannot convert return expression of type 'Int' to return type 'String' +at uni_modules/test-uts1/utssdk/app-ios/index.uts:2:10 +1 | export function test(): string { +2 | return 1; + | ^ +3 | } +4 | -* Get more help at https://help.gradle.org -BUILD FAILED in 50s" +CompileSwift normal arm64 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS') +error: cannot convert return expression of type 'Int' to return type 'String' +at uni_modules/test-uts1/utssdk/app-ios/index.uts:2:10 +1 | export function test(): string { +2 | return 1; + | ^ +3 | } +4 | +" `; diff --git a/packages/uni-stacktracey/__tests__/uts.spec.ts b/packages/uni-stacktracey/__tests__/uts.spec.ts index 3731767a3..63b9341c8 100644 --- a/packages/uni-stacktracey/__tests__/uts.spec.ts +++ b/packages/uni-stacktracey/__tests__/uts.spec.ts @@ -1,7 +1,8 @@ import path from 'path' const { - generateCodeFrameWithAndroidStacktrace, + generateCodeFrameWithKotlinStacktrace, + generateCodeFrameWithSwiftStacktrace, } = require('../dist/uni-stacktracey.cjs.js') const utsProjectDir = path.resolve(__dirname, '../test/uts') @@ -9,52 +10,41 @@ const utsProjectDir = path.resolve(__dirname, '../test/uts') describe('code-frame-uts', () => { test('android', async () => { expect( - await generateCodeFrameWithAndroidStacktrace(androidUniModulesError, { + await generateCodeFrameWithKotlinStacktrace(androidUniModulesError, { name: 'uni_modules/test-uts1', inputDir: '/Users/fxy/DCloud/test-uts', outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'), }) ).toMatchSnapshot() expect( - await generateCodeFrameWithAndroidStacktrace(androidUtssdkError, { + await generateCodeFrameWithKotlinStacktrace(androidUtssdkError, { name: 'utssdk/test2', inputDir: '/Users/fxy/DCloud/test-uts', outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'), }) ).toMatchSnapshot() }) + test('ios', async () => { + expect( + await generateCodeFrameWithSwiftStacktrace(iosUniModulesError, { + name: 'uni_modules/test-uts1', + inputDir: '/Users/fxy/DCloud/test-uts', + outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'), + }) + ).toMatchSnapshot() + }) }) const androidUniModulesError = `e: uni_modules/test-uts1/utssdk/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String -FAILURE: Build failed with an exception. - -* What went wrong: -Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'. -> Compilation error. See log for more details - -* Try: -> Run with --stacktrace option to get the stack trace. -> Run with --info or --debug option to get more log output. -> Run with --scan to get full insights. - -* Get more help at https://help.gradle.org - -BUILD FAILED in 50s` +FAILURE: Build failed with an exception.` const androidUtssdkError = `e: utssdk/test2/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String -FAILURE: Build failed with an exception. - -* What went wrong: -Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'. -> Compilation error. See log for more details - -* Try: -> Run with --stacktrace option to get the stack trace. -> Run with --info or --debug option to get more log output. -> Run with --scan to get full insights. +FAILURE: Build failed with an exception.` -* Get more help at https://help.gradle.org +const iosUniModulesError = `CompileSwift normal armv7 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS') +uni_modules/test-uts1/utssdk/app-ios/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String' -BUILD FAILED in 50s` +CompileSwift normal arm64 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS') +uni_modules/test-uts1/utssdk/app-ios/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String'` diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js index 35c46ed87..daae8da66 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js @@ -3712,13 +3712,20 @@ function resolveSourceMapPath(sourceMapFilename, name, outputDir) { const is_uni_modules = path__default["default"].basename(path__default["default"].dirname(name)) === 'uni_modules'; return path__default["default"].resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename); } -function generateCodeFrameWithAndroidStacktrace(stacktrace, { name, inputDir, outputDir }) { +function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) { const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir); return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, { sourceRoot: inputDir, sourceMapFilename, }); } +function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) { + const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir); + return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, { + sourceRoot: inputDir, + sourceMapFilename, + }); +} function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, }) { return new Promise((resolve) => { initConsumer(sourceMapFilename).then((consumer) => { @@ -4070,8 +4077,9 @@ ${_stack.errMsg}`; exports.SourceMapConsumer = SourceMapConsumer; exports.generateCodeFrame = generateCodeFrame; exports.generateCodeFrameSourceMapConsumer = generateCodeFrameSourceMapConsumer; -exports.generateCodeFrameWithAndroidStacktrace = generateCodeFrameWithAndroidStacktrace; +exports.generateCodeFrameWithKotlinStacktrace = generateCodeFrameWithKotlinStacktrace; exports.generateCodeFrameWithSourceMapPath = generateCodeFrameWithSourceMapPath; +exports.generateCodeFrameWithSwiftStacktrace = generateCodeFrameWithSwiftStacktrace; exports.stacktracey = stacktracey; exports.uniStracktraceyPreset = uniStracktraceyPreset; exports.utsStracktraceyPreset = utsStracktraceyPreset; diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.es.js b/packages/uni-stacktracey/dist/uni-stacktracey.es.js index 0b7c77ce3..41223d3e0 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.es.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.es.js @@ -3695,13 +3695,20 @@ function resolveSourceMapPath(sourceMapFilename, name, outputDir) { const is_uni_modules = path.basename(path.dirname(name)) === 'uni_modules'; return path.resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename); } -function generateCodeFrameWithAndroidStacktrace(stacktrace, { name, inputDir, outputDir }) { +function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) { const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir); return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, { sourceRoot: inputDir, sourceMapFilename, }); } +function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) { + const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir); + return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, { + sourceRoot: inputDir, + sourceMapFilename, + }); +} function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, }) { return new Promise((resolve) => { initConsumer(sourceMapFilename).then((consumer) => { @@ -4060,4 +4067,4 @@ ${_stack.errMsg}`; }; } -export { SourceMapConsumer, generateCodeFrame, generateCodeFrameSourceMapConsumer, generateCodeFrameWithAndroidStacktrace, generateCodeFrameWithSourceMapPath, stacktracey, uniStracktraceyPreset, utsStracktraceyPreset }; +export { SourceMapConsumer, generateCodeFrame, generateCodeFrameSourceMapConsumer, generateCodeFrameWithKotlinStacktrace, generateCodeFrameWithSourceMapPath, generateCodeFrameWithSwiftStacktrace, stacktracey, uniStracktraceyPreset, utsStracktraceyPreset }; diff --git a/packages/uni-stacktracey/src/index.ts b/packages/uni-stacktracey/src/index.ts index 0650affdf..70362ed4a 100644 --- a/packages/uni-stacktracey/src/index.ts +++ b/packages/uni-stacktracey/src/index.ts @@ -14,7 +14,8 @@ export { generateCodeFrame, generateCodeFrameSourceMapConsumer, generateCodeFrameWithSourceMapPath, - generateCodeFrameWithAndroidStacktrace, + generateCodeFrameWithKotlinStacktrace, + generateCodeFrameWithSwiftStacktrace, } from './utils' // @ts-ignore if (__PLATFORM_WEB__) { diff --git a/packages/uni-stacktracey/src/utils.ts b/packages/uni-stacktracey/src/utils.ts index dd3d126a1..e7192d444 100644 --- a/packages/uni-stacktracey/src/utils.ts +++ b/packages/uni-stacktracey/src/utils.ts @@ -185,7 +185,7 @@ function resolveSourceMapPath( ) } -export function generateCodeFrameWithAndroidStacktrace( +export function generateCodeFrameWithKotlinStacktrace( stacktrace: string, { name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions ) { @@ -204,6 +204,25 @@ export function generateCodeFrameWithAndroidStacktrace( ) } +export function generateCodeFrameWithSwiftStacktrace( + stacktrace: string, + { name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions +) { + const sourceMapFilename = resolveSourceMapPath( + 'app-ios/index.swift.map', + name, + outputDir + ) + return generateCodeFrameWithStacktrace( + stacktrace, + /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, + { + sourceRoot: inputDir, + sourceMapFilename, + } + ) +} + function generateCodeFrameWithStacktrace( stacktrace: string, regexp: RegExp, diff --git a/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uts1/utssdk/app-ios/index.swift.map b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uts1/utssdk/app-ios/index.swift.map new file mode 100644 index 000000000..b444ec787 --- /dev/null +++ b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/uni_modules/test-uts1/utssdk/app-ios/index.swift.map @@ -0,0 +1 @@ +{"version":3,"sources":["/Users/fxy/DCloud/test-uts/uni_modules/test-uts1/utssdk/app-ios/index.uts"],"sourcesContent":["export function test(): string {\n return 1;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,MAAM;eAAd"} \ No newline at end of file diff --git a/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-android/index.kt.map b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-android/index.kt.map index 2d98ea224..88bde2889 100644 --- a/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-android/index.kt.map +++ b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-android/index.kt.map @@ -1 +1 @@ -{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-android/index.uts"],"sourcesContent":["export function test(): string {\n return 2;\n}\n"],"names":[],"mappings":";;;;;;AAAO,IAAS,QAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV"} \ No newline at end of file +{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-android/index.uts"],"sourcesContent":["export function test(): number {\n return 2.0.toFloat();\n}\n"],"names":[],"mappings":";;;;;;AAAO,IAAS,QAAQ,MAAM,CAAC;IAC7B,OAAO,GAAG,CAAC,OAAO;AACpB"} \ No newline at end of file diff --git a/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-ios/index.swift.map b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-ios/index.swift.map new file mode 100644 index 000000000..6f46848cb --- /dev/null +++ b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test/app-ios/index.swift.map @@ -0,0 +1 @@ +{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-ios/index.uts"],"sourcesContent":["export function test(): number {\n return 1;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,QAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,QAAM;eAAd"} \ No newline at end of file diff --git a/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test2/app-ios/index.swift.map b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test2/app-ios/index.swift.map new file mode 100644 index 000000000..808647199 --- /dev/null +++ b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app/utssdk/test2/app-ios/index.swift.map @@ -0,0 +1 @@ +{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test2/index.uts"],"sourcesContent":["export function test(): string {\n return 2;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,MAAM;eAAd"} \ No newline at end of file -- GitLab