From 44c2a9e9f40b82677fb933dd2ca085fd0f2620c8 Mon Sep 17 00:00:00 2001 From: pshu Date: Mon, 17 Apr 2023 17:13:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20dep=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E8=BF=87=E9=95=BF=20=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=20hash=20=EF=BC=8C=E4=BF=9D=E7=95=99=20200=20?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E7=AC=A6=E6=96=B9=E4=BE=BF=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E6=96=87=E4=BB=B6=E5=90=8D=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mfsu/src/dep/dep.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/mfsu/src/dep/dep.ts b/packages/mfsu/src/dep/dep.ts index bb7e34ded319..c86181ce0743 100644 --- a/packages/mfsu/src/dep/dep.ts +++ b/packages/mfsu/src/dep/dep.ts @@ -1,5 +1,6 @@ import { chalk, logger, pkgUp, winPath } from '@umijs/utils'; import assert from 'assert'; +import { createHash } from 'crypto'; import { readFileSync } from 'fs'; import { dirname, isAbsolute, join } from 'path'; import { MF_VA_PREFIX } from '../constants'; @@ -29,12 +30,25 @@ export class Dep { this.version = opts.version; this.cwd = opts.cwd; this.shortFile = this.file; - this.normalizedFile = this.shortFile.replace(/\//g, '_').replace(/:/g, '_'); + this.normalizedFile = this.normalizePath(this.shortFile); this.filePath = `${MF_VA_PREFIX}${this.normalizedFile}.js`; this.excludeNodeNatives = opts.excludeNodeNatives!; this.importer = opts.importer; } + private normalizePath(p: string): string { + const longPath = p.replace(/\//g, '_').replace(/:/g, '_'); + + if (longPath.length <= 200) { + return longPath; + } + + const hash = createHash('md5').update(longPath).digest('hex').slice(0, 16); + const post = longPath.slice(-200); + + return `${hash}_${post}`; + } + async buildExposeContent() { // node natives // @ts-ignore From e225a5d59c6f9b557640a4c5b00f7bbc4ed0ca7a Mon Sep 17 00:00:00 2001 From: pshu Date: Mon, 17 Apr 2023 17:44:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E7=A7=BB=E9=99=A4=20?= =?UTF-8?q?cwd=EF=BC=8C=E8=B7=AF=E5=BE=84=E5=B0=BD=E9=87=8F=E7=9F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mfsu/src/dep/dep.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/mfsu/src/dep/dep.ts b/packages/mfsu/src/dep/dep.ts index c86181ce0743..7f1a1d5afcb5 100644 --- a/packages/mfsu/src/dep/dep.ts +++ b/packages/mfsu/src/dep/dep.ts @@ -37,7 +37,12 @@ export class Dep { } private normalizePath(p: string): string { - const longPath = p.replace(/\//g, '_').replace(/:/g, '_'); + let longPath = p; + + if (longPath.startsWith(this.cwd)) { + longPath = longPath.slice(this.cwd.length); + } + longPath = longPath.replace(/\//g, '_').replace(/:/g, '_'); if (longPath.length <= 200) { return longPath;