From ee611b9093cfb7342312d7f1604c19b2a0c3b14c Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Wed, 17 Sep 2025 03:45:34 -0700 Subject: [PATCH 1/2] Use static string path imports to load the platform-specific implementations. This allows the imports to be statically analyzed and bundled by the widest variety of tooling. Closes: https://github.com/sindresorhus/trash/issues/130 --- index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b8215a5..02be903 100644 --- a/index.js +++ b/index.js @@ -61,11 +61,22 @@ export default async function trash(paths, options = {}) { return; } - // Load platform-specific implementation - const platform = process.platform === 'darwin' - ? 'macos' - : (process.platform === 'win32' ? 'windows' : 'linux'); - - const {default: trashFunction} = await import(`./lib/${platform}.js`); + const {default: trashFunction} = await platformSpecificImplementation(); return trashFunction(resolvedPaths); } + +async function platformSpecificImplementation() { + switch (process.platform) { + case 'darwin': { + return import('./lib/macos.js'); + } + + case 'win32': { + return import('./lib/windows.js'); + } + + default: { + return import('./lib/linux.js'); + } + } +} From 35ab1ce17d472393e35eead3e612ec1865734e66 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 18 Sep 2025 11:15:46 +0700 Subject: [PATCH 2/2] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 02be903..1ad2ab9 100644 --- a/index.js +++ b/index.js @@ -65,6 +65,7 @@ export default async function trash(paths, options = {}) { return trashFunction(resolvedPaths); } +// We use static imports so it can be statically analyzed. async function platformSpecificImplementation() { switch (process.platform) { case 'darwin': {