From 20ed2e8a5014fd6fe4563a3712dac9ef13b6b55e Mon Sep 17 00:00:00 2001 From: Joakim Carlstein Date: Thu, 7 Dec 2023 14:33:01 +0100 Subject: [PATCH] fix(plugin-tools): prioritize prefixed plugin names over non-prefixed names when importing plugins This is to not accidentally importing for instance the "pino" package if reporter is set to just "pino" and instead import the "@emigrate/reporter-pino" package if that's the case. --- .changeset/proud-numbers-jam.md | 5 +++++ packages/plugin-tools/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/proud-numbers-jam.md diff --git a/.changeset/proud-numbers-jam.md b/.changeset/proud-numbers-jam.md new file mode 100644 index 0000000..c1483bc --- /dev/null +++ b/.changeset/proud-numbers-jam.md @@ -0,0 +1,5 @@ +--- +'@emigrate/plugin-tools': patch +--- + +Try importing plugins (and reporters) using prefixes before importing without, this is to avoid issue with accidentaly importing other non-emigrate related packages. E.g. setting the reporter to "pino" would import the "pino" package without this fix and will import "@emigrate/reporter-pino" with this fix. diff --git a/packages/plugin-tools/src/index.ts b/packages/plugin-tools/src/index.ts index 91d30f2..4b96c71 100644 --- a/packages/plugin-tools/src/index.ts +++ b/packages/plugin-tools/src/index.ts @@ -184,7 +184,7 @@ const load = async ( ): Promise => { const importFromEsm = await getImportFromEsm(); - const importsToTry = name.startsWith('.') ? [name] : [name, ...prefixes.map((prefix) => `${prefix}${name}`)]; + const importsToTry = name.startsWith('.') ? [name] : [...prefixes.map((prefix) => `${prefix}${name}`), name]; for await (const importPath of importsToTry) { try {