From 621a9cac4e6644b29517a64e6435e27c67a36b92 Mon Sep 17 00:00:00 2001 From: "yansen.lei" Date: Tue, 20 Sep 2022 23:07:18 +0800 Subject: [PATCH 1/2] fix: get unique module-id by the hash resourcePath --- src/index.ts | 5 ++--- test/utils.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index d7d43700e..f46e4f809 100644 --- a/src/index.ts +++ b/src/index.ts @@ -113,11 +113,10 @@ export default function loader( const rawShortFilePath = path .relative(rootContext || process.cwd(), filename) .replace(/^(\.\.[\/\\])+/, '') - const shortFilePath = rawShortFilePath.replace(/\\/g, '/') const id = hash( isProduction - ? shortFilePath + '\n' + source.replace(/\r\n/g, '\n') - : shortFilePath + ? resourcePath + '\n' + source.replace(/\r\n/g, '\n') + : resourcePath ) // if the query has a type field, this is a language block request diff --git a/test/utils.ts b/test/utils.ts index 13261b4c2..0c60ba4c7 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -163,7 +163,7 @@ export function normalizeNewline(input: string): string { } // see the logic at src/index.ts -// in non-production environment, shortFilePath is used to generate scope id +// in non-production environment, resourcePath is used to generate scope id export function genId(fixtureName: string): string { return hash(path.join('test', 'fixtures', fixtureName).replace(/\\/g, '/')) } From 3bbb8c8e02cb1f09178345e21526943143fcc4be Mon Sep 17 00:00:00 2001 From: "yansen.lei" Date: Wed, 21 Sep 2022 00:03:26 +0800 Subject: [PATCH 2/2] test: add dirname to genId --- test/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.ts b/test/utils.ts index 0c60ba4c7..b59267383 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -165,7 +165,7 @@ export function normalizeNewline(input: string): string { // see the logic at src/index.ts // in non-production environment, resourcePath is used to generate scope id export function genId(fixtureName: string): string { - return hash(path.join('test', 'fixtures', fixtureName).replace(/\\/g, '/')) + return hash(path.join(__dirname, 'fixtures', fixtureName).replace(/\\/g, '/')) } export { mfs }