From 38817498e7403e5550fbfe089cad6fa62f9f98ad Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 10 Apr 2024 14:14:17 +0900 Subject: [PATCH 1/2] fix: regression triple slash including in `d.ts` --- packages/shared/test/replace.test.ts | 19 +++++++++++++++ rollup.config.mjs | 2 +- scripts/postprocess.ts | 35 +++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 packages/shared/test/replace.test.ts diff --git a/packages/shared/test/replace.test.ts b/packages/shared/test/replace.test.ts new file mode 100644 index 000000000..7f3f14213 --- /dev/null +++ b/packages/shared/test/replace.test.ts @@ -0,0 +1,19 @@ +import fs from 'node:fs/promises' +import path from 'node:path' + +test('replace', async () => { + const source = await fs.readFile( + path.resolve(__dirname, './fixtures/message-compiler.d.ts'), + 'utf-8' + ) + + const RE_TRIPLE_SLASH_REFERENCE = /\/\/\/ / + const i1 = RE_TRIPLE_SLASH_REFERENCE.exec(source) + const index = i1?.index || -1 + const matchLength = i1?.[0].length || 0 + console.log('number', i1) + const s = source + .replace(RE_TRIPLE_SLASH_REFERENCE, ``) + .replace(RE_TRIPLE_SLASH_REFERENCE, '') + expect(s).toMatchSnapshot() +}) diff --git a/rollup.config.mjs b/rollup.config.mjs index 638cc6f56..fee0f19b8 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -174,7 +174,7 @@ function createConfig(format, _output, plugins = []) { declaration: shouldEmitDeclarations, declarationMap: shouldEmitDeclarations }, - exclude: ['**/test', 'test-dts', 'e2e', 'scripts'] + exclude: ['**/test', 'test-dts', 'e2e', 'scripts', '*.config.ts'] } }) // we only need to check TS and generate declarations once for each build. diff --git a/scripts/postprocess.ts b/scripts/postprocess.ts index 132a4044d..97fd28c30 100644 --- a/scripts/postprocess.ts +++ b/scripts/postprocess.ts @@ -8,7 +8,7 @@ function replaceWithCompositionApi(source: string, target: string) { ) } -async function main() { +async function replaceVueI18nBridge() { let source = await fs.readFile( path.resolve( __dirname, @@ -37,6 +37,39 @@ async function main() { ) } +const RE_TRIPLE_SLASH_REFERENCE = /\/\/\/ / + +function replaceTripleSlashReference(source: string) { + return source + .replace(RE_TRIPLE_SLASH_REFERENCE, ``) + .replace(RE_TRIPLE_SLASH_REFERENCE, '') +} + +async function replaceMessageCompiler() { + let source = await fs.readFile( + path.resolve( + __dirname, + '../packages/message-compiler/dist/message-compiler.d.ts' + ), + 'utf8' + ) + + source = replaceTripleSlashReference(source) + + await fs.writeFile( + path.resolve( + __dirname, + '../packages/message-compiler/dist/message-compiler.d.ts' + ), + source + ) +} + +async function main() { + await replaceVueI18nBridge() + await replaceMessageCompiler() +} + main().catch(err => { console.error(err) process.exit(1) From 95d45fd6272b3448079cbdef109d5dd0a3e60ca7 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Wed, 10 Apr 2024 14:24:47 +0900 Subject: [PATCH 2/2] fix: remove unnecesary file --- packages/shared/test/replace.test.ts | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 packages/shared/test/replace.test.ts diff --git a/packages/shared/test/replace.test.ts b/packages/shared/test/replace.test.ts deleted file mode 100644 index 7f3f14213..000000000 --- a/packages/shared/test/replace.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import fs from 'node:fs/promises' -import path from 'node:path' - -test('replace', async () => { - const source = await fs.readFile( - path.resolve(__dirname, './fixtures/message-compiler.d.ts'), - 'utf-8' - ) - - const RE_TRIPLE_SLASH_REFERENCE = /\/\/\/ / - const i1 = RE_TRIPLE_SLASH_REFERENCE.exec(source) - const index = i1?.index || -1 - const matchLength = i1?.[0].length || 0 - console.log('number', i1) - const s = source - .replace(RE_TRIPLE_SLASH_REFERENCE, ``) - .replace(RE_TRIPLE_SLASH_REFERENCE, '') - expect(s).toMatchSnapshot() -})