From ced84513a5d50dd118758db6f858f2f7048ffb1d Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Wed, 19 Jul 2023 17:21:54 +0530 Subject: [PATCH] abs resolution + default imports abs resolution + default imports --- e2e/.babelrc.js | 36 +++++++++++++++++++++++++----------- package-lock.json | 4 ++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/e2e/.babelrc.js b/e2e/.babelrc.js index e9bb71e44aa..f6dc71102e4 100644 --- a/e2e/.babelrc.js +++ b/e2e/.babelrc.js @@ -1,10 +1,25 @@ // https://github.com/viruscamp/babel-plugin-transform-imports#using-a-function-as-the-transformer const path = require('path'); -const siteDir = path.resolve('./e2e/site'); const testsDir = path.resolve('./e2e/tests'); const testsBuiltDir = path.resolve('./e2e/dist'); +function resolve(file) { + const found = ['', '.js', '/index.js'] + .map((resolution) => `${file}${resolution}`) + .find((file) => { + try { + return require.resolve(file); + } catch (error) { + return false; + } + }); + if (!found) { + throw new Error(`Failed to resolve ${file}`); + } + return require.resolve(file); +} + module.exports = { extends: '../.babelrcAlt', plugins: [ @@ -14,18 +29,17 @@ module.exports = { '\\..*': { skipDefaultConversion: true, transform: function (importName, matches, filename) { - const file = path.resolve( - path.dirname(filename), - `${matches[0]}.js` - ); - return path + const file = path.resolve(path.dirname(filename), `${matches[0]}`); + return `/${path .relative( - siteDir, - file.startsWith(testsDir) - ? path.resolve(testsBuiltDir, path.relative(testsDir, file)) - : file + process.cwd(), + resolve( + file.startsWith(testsDir) + ? path.resolve(testsBuiltDir, path.relative(testsDir, file)) + : file + ) ) - .replaceAll('\\', '/'); + .replaceAll('\\', '/')}`; }, }, }, diff --git a/package-lock.json b/package-lock.json index 6eb275b88f4..3fd18519fad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4002,7 +4002,7 @@ }, "node_modules/babel-plugin-transform-imports": { "version": "1.7.0", - "resolved": "git+https://git@github.com/ShaMan123/babel-plugin-transform-imports.git#b14734f4531642914c69a95b54ba4779ef8cce56", + "resolved": "git+https://git@github.com/ShaMan123/babel-plugin-transform-imports.git#e105857c5bbf5c1ecd0ea3ec5fe3f068ddd4739b", "dev": true, "license": "ISC", "dependencies": { @@ -15042,7 +15042,7 @@ } }, "babel-plugin-transform-imports": { - "version": "git+https://git@github.com/ShaMan123/babel-plugin-transform-imports.git#b14734f4531642914c69a95b54ba4779ef8cce56", + "version": "git+https://git@github.com/ShaMan123/babel-plugin-transform-imports.git#e105857c5bbf5c1ecd0ea3ec5fe3f068ddd4739b", "dev": true, "from": "babel-plugin-transform-imports@git+https://git@github.com/ShaMan123/babel-plugin-transform-imports.git", "requires": {