From c565e690abd4fe7525a0b9d4052207130cb9b2a3 Mon Sep 17 00:00:00 2001 From: "george.tsopanoglou" Date: Tue, 7 May 2024 00:36:56 +0300 Subject: [PATCH] Re-write resolved filenames regardless of tracing specifiers --- README.md | 1 + package-lock.json | 4 ++-- package.json | 2 +- package/plugin/index.js | 2 ++ spec/import-cases.spec.js | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6ab73c7..baa1e45 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ Any import statements within this particular file will not be re-written. - 0.1.12 Performance increase, tracing prioritization and defensive try/catch ✅ - 0.1.13 Pre-commit lint, format test and github action to test again. ✅ - 0.1.14 Expose ready-made transformer to relief the user from having to pass in the jestConfig object. ✅ +- 0.1.15 Performance improvements ✅ - 0.1.16 Ensure all different `jest.mock` calls are properly treated. - 0.1.17 Expose debugging options to the user (like printing which imports are being rewritten, or the transpiled output of a particular file). - 0.1.17 Expose a jest reporter to print a high-level overview of what the plugin did within the run (and potientialy report barel file statistics) diff --git a/package-lock.json b/package-lock.json index f891e50..baa7069 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gtsopanoglou/babel-jest-boost", - "version": "0.1.14", + "version": "0.1.15", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gtsopanoglou/babel-jest-boost", - "version": "0.1.14", + "version": "0.1.15", "license": "AGPL-3.0-or-later", "dependencies": { "app-root-dir": "^1.0.2", diff --git a/package.json b/package.json index f5d0892..3c015bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gtsopanoglou/babel-jest-boost", - "version": "0.1.14", + "version": "0.1.15", "description": "Babel plugin to boost jest performance by skipping intermediate imports", "scripts": { "format:check": "prettier . --check", diff --git a/package/plugin/index.js b/package/plugin/index.js index a477315..36337a4 100644 --- a/package/plugin/index.js +++ b/package/plugin/index.js @@ -185,6 +185,8 @@ module.exports = function babelPlugin(babel) { ]); toRemove.push(index); } + } else { + path.node.source = babel.types.stringLiteral(importedFrom); } } }); diff --git a/spec/import-cases.spec.js b/spec/import-cases.spec.js index 73e85fc..2c8c9a7 100644 --- a/spec/import-cases.spec.js +++ b/spec/import-cases.spec.js @@ -31,14 +31,14 @@ describe("babel-jest-boost plugin import cases", () => { "import { one, two, target } from './test_tree/library';", ` import { target } from "${__dirname}/test_tree/library/library.js"; - import { one, two } from './test_tree/library'; + import { one, two } from "${__dirname}/test_tree/library/index.js"; `, ); expectTransform( "import { one, two, target as three } from './test_tree/library';", ` import { target as three } from "${__dirname}/test_tree/library/library.js"; - import { one, two } from './test_tree/library'; + import { one, two } from "${__dirname}/test_tree/library/index.js"; `, ); expectTransform(