From e435bbc1cffcd61edaa2a5f52941c43a57059bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Zakrzewski?= Date: Mon, 12 Dec 2022 12:40:18 +0100 Subject: [PATCH] refactor(webpack/Compiler): remove duplicated assets in assetCache --- .changeset/ten-tigers-kiss.md | 5 +++++ packages/repack/src/webpack/Compiler.ts | 4 ++-- .../src/webpack/utils/adaptFilenameToPlatform.ts | 10 ++++++++++ packages/repack/src/webpack/utils/index.ts | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/ten-tigers-kiss.md create mode 100644 packages/repack/src/webpack/utils/adaptFilenameToPlatform.ts diff --git a/.changeset/ten-tigers-kiss.md b/.changeset/ten-tigers-kiss.md new file mode 100644 index 000000000..604120585 --- /dev/null +++ b/.changeset/ten-tigers-kiss.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": minor +--- + +Fix: assetsCache not available on Windows platform due to problem with path encoding diff --git a/packages/repack/src/webpack/Compiler.ts b/packages/repack/src/webpack/Compiler.ts index 7b30f1596..424c4c65a 100644 --- a/packages/repack/src/webpack/Compiler.ts +++ b/packages/repack/src/webpack/Compiler.ts @@ -8,6 +8,7 @@ import { SendProgress } from '@callstack/repack-dev-server'; import type { CliOptions, StartArguments } from '../types'; import type { LogType, Reporter } from '../logging'; import { VERBOSE_ENV_KEY, WORKER_ENV_KEY } from '../env'; +import { adaptFilenameToPlatform } from './utils'; export interface Asset { data: string | Buffer; @@ -118,8 +119,7 @@ export class Compiler extends EventEmitter { }; return { ...acc, - [filename]: asset, - [filename.replace(/\\/g, '/')]: asset, + [adaptFilenameToPlatform(filename)]: asset, }; }, {} diff --git a/packages/repack/src/webpack/utils/adaptFilenameToPlatform.ts b/packages/repack/src/webpack/utils/adaptFilenameToPlatform.ts new file mode 100644 index 000000000..facfce07a --- /dev/null +++ b/packages/repack/src/webpack/utils/adaptFilenameToPlatform.ts @@ -0,0 +1,10 @@ +import os from 'os'; + +const isWindows = os.platform() === 'win32'; + +export const adaptFilenameToPlatform = (filename: string) => { + if (isWindows) { + return filename.replace(/\\/g, '/'); + } + return filename; +}; diff --git a/packages/repack/src/webpack/utils/index.ts b/packages/repack/src/webpack/utils/index.ts index 82d87f7e6..6a712d542 100644 --- a/packages/repack/src/webpack/utils/index.ts +++ b/packages/repack/src/webpack/utils/index.ts @@ -4,3 +4,4 @@ export * from './getPublicPath'; export * from './assetExtensions'; export * from './getWebpackEnvOptions'; export * from './getDirname'; +export * from './adaptFilenameToPlatform';