vite-plugin-dynamic-import
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -35,8 +35,13 @@ "use strict"; | ||
if (path_1.default.isAbsolute(replacement)) { | ||
const relative = path_1.default.posix.relative(/* 🚧 */ path_1.default.dirname(id), replacement); | ||
const relativeUrl = relative === '' | ||
? `./${url.replace(_find, '').replace(/^\//, '')}` | ||
: path_1.default.join(relative, url.replace(_find, '')); | ||
// Compatible with vite restrictions | ||
// https://github.com/vitejs/vite/blob/1e9615d8614458947a81e0d4753fe61f3a277cb3/packages/vite/src/node/plugins/importAnalysis.ts#L672 | ||
url = sColon + relativeUrl + eColon; | ||
let relativePath = path_1.default.posix.relative(/* 🚧 */ path_1.default.dirname(id), replacement); | ||
if (relativePath === '') { | ||
relativePath = '.'; | ||
} | ||
const relativeImportee = relativePath + '/' + url | ||
.replace(_find, '') | ||
// Remove the beginning / | ||
.replace(/^\//, ''); | ||
url = sColon + relativeImportee + eColon; | ||
} | ||
@@ -43,0 +48,0 @@ else { |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fixGlob = exports.DynamicImportVars = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
class DynamicImportVars { | ||
@@ -121,13 +125,21 @@ constructor(aliasContext) { | ||
function fixGlob(glob, deep = true) { | ||
const [, importPath] = glob.match(/(.*\w\/?)\*(.\w+)?/); | ||
const extname = path_1.default.extname(glob); | ||
// It could be `../views*.js`, which needs to be repaired to `../views/*.js` | ||
glob = glob.replace(extname, ''); | ||
const [, importPath] = glob.match(/(.*\w\/?)\*/); | ||
if (!importPath.endsWith('/')) { | ||
// fill necessary slash | ||
// `../views*` -> `../views/*` | ||
const fixedGlob = glob.replace(importPath, importPath + '/'); | ||
return deep | ||
let fixedGlob = glob.replace(importPath, importPath + '/'); | ||
fixedGlob = deep | ||
// match as far as possible | ||
// e.g. `../views/*` -> `../views/**/*` | ||
// `../views/*` -> `../views/**/*` | ||
? fixedGlob.replace(/^(.*)\/\*$/, '$1/**/*') | ||
: fixedGlob; | ||
// if it has a '.js' extension | ||
// `../views/*` -> `../views/*.js` | ||
fixedGlob += extname; | ||
return fixedGlob; | ||
} | ||
} | ||
exports.fixGlob = fixGlob; |
{ | ||
"name": "vite-plugin-dynamic-import", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Enhance Vite builtin dynamic import", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -45,9 +45,13 @@ import path from 'path' | ||
if (path.isAbsolute(replacement)) { | ||
const relative = path.posix.relative(/* 🚧 */path.dirname(id), replacement) | ||
const relativeUrl = relative === '' | ||
? `./${url.replace(_find, '').replace(/^\//, '')}` | ||
: path.join(relative, url.replace(_find, '')) | ||
// Compatible with vite restrictions | ||
// https://github.com/vitejs/vite/blob/1e9615d8614458947a81e0d4753fe61f3a277cb3/packages/vite/src/node/plugins/importAnalysis.ts#L672 | ||
url = sColon + relativeUrl + eColon | ||
let relativePath = path.posix.relative(/* 🚧 */path.dirname(id), replacement) | ||
if (relativePath === '') { | ||
relativePath = '.' | ||
} | ||
const relativeImportee = relativePath + '/' + url | ||
.replace(_find, '') | ||
// Remove the beginning / | ||
.replace(/^\//, '') | ||
url = sColon + relativeImportee + eColon | ||
} else { | ||
@@ -54,0 +58,0 @@ url = sColon + url.replace(_find, replacement) + eColon |
@@ -0,1 +1,2 @@ | ||
import path from 'path' | ||
import type { AliasContext, AliasReplaced } from './alias' | ||
@@ -171,13 +172,24 @@ import type { AcornNode } from './types' | ||
export function fixGlob(glob: string, deep = true): string | void { | ||
const [, importPath] = glob.match(/(.*\w\/?)\*(.\w+)?/) | ||
const extname = path.extname(glob) | ||
// It could be `../views*.js`, which needs to be repaired to `../views/*.js` | ||
glob = glob.replace(extname, '') | ||
const [, importPath] = glob.match(/(.*\w\/?)\*/) | ||
if (!importPath.endsWith('/')) { | ||
// fill necessary slash | ||
// `../views*` -> `../views/*` | ||
const fixedGlob = glob.replace(importPath, importPath + '/') | ||
let fixedGlob = glob.replace(importPath, importPath + '/') | ||
return deep | ||
fixedGlob = deep | ||
// match as far as possible | ||
// e.g. `../views/*` -> `../views/**/*` | ||
// `../views/*` -> `../views/**/*` | ||
? fixedGlob.replace(/^(.*)\/\*$/, '$1/**/*') | ||
: fixedGlob | ||
// if it has a '.js' extension | ||
// `../views/*` -> `../views/*.js` | ||
fixedGlob += extname | ||
return fixedGlob | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41406
901