From 053c89023607e02c70a2cd1dc829d756f9400eca Mon Sep 17 00:00:00 2001 From: sinclairzx81 Date: Thu, 16 Jan 2025 22:40:09 +0900 Subject: [PATCH] Revision 0.9.1 (#4) - Fix Esm Specifier Rewrite on Build --- package-lock.json | 4 ++-- package.json | 2 +- task/build/esm/convert-to-esm.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e23753d..3a22af4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sinclair/typebox-adapter", - "version": "0.9.0", + "version": "0.9.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sinclair/typebox-adapter", - "version": "0.9.0", + "version": "0.9.1", "license": "MIT", "devDependencies": { "@arethetypeswrong/cli": "^0.17.2", diff --git a/package.json b/package.json index 342149a..ebf3fb3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/typebox-adapter", - "version": "0.9.0", + "version": "0.9.1", "description": "Integrate Valibot and Zod with TypeBox", "author": "sinclairzx81", "license": "MIT", diff --git a/task/build/esm/convert-to-esm.ts b/task/build/esm/convert-to-esm.ts index ee1a37e..943f070 100644 --- a/task/build/esm/convert-to-esm.ts +++ b/task/build/esm/convert-to-esm.ts @@ -32,7 +32,15 @@ import * as Fs from 'node:fs' // ------------------------------------------------------------------ // Specifier Rewrite // ------------------------------------------------------------------ - +function shouldSkipSpecifier(captured: string) { + const specifier = captured.slice(1, captured.length - 1) + return ( + specifier.includes('.mjs') || // mitigate duplicate rewrite + specifier.startsWith("@sinclair/typebox") || + specifier.startsWith("valibot") || + specifier.startsWith("zod") + ) +} // prettier-ignore function replaceInlineImportSpecifiers(content: string): string { const pattern = /import\((.*?)\)/g @@ -40,7 +48,7 @@ function replaceInlineImportSpecifiers(content: string): string { const match = pattern.exec(content) if (match === null) return content const captured = match[1] - if(captured.includes('.mjs')) continue + if(shouldSkipSpecifier(captured)) continue const specifier = captured.slice(1, captured.length - 1) content = content.replace(captured, `"${specifier}.mjs"`) } @@ -52,6 +60,7 @@ function replaceExportSpecifiers(content: string): string { const match = pattern.exec(content) if(match === null) return content const captured = match[3] + if(shouldSkipSpecifier(captured)) continue const specifier = captured.slice(1, captured.length - 1) content = content.replace(captured, `'${specifier}.mjs'`) }