vite-plugin-dynamic-import
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -53,5 +53,5 @@ import type { Plugin } from 'vite'; | ||
* β | ||
* import('@/viewsfoo.js') | ||
* import('@/views/foo.js') | ||
*/ | ||
normally?: string; | ||
} | undefined>; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const fastGlob = require("fast-glob"); | ||
const MagicString = require("magic-string"); | ||
const os = require("node:os"); | ||
@@ -26,37 +27,2 @@ const DEFAULT_EXTENSIONS = [ | ||
} | ||
class MagicString { | ||
constructor(str) { | ||
this.str = str; | ||
this.starts = ""; | ||
this.ends = ""; | ||
} | ||
append(content) { | ||
this.ends += content; | ||
return this; | ||
} | ||
prepend(content) { | ||
this.starts = content + this.starts; | ||
return this; | ||
} | ||
overwrite(start, end, content) { | ||
if (end < start) { | ||
throw new Error(`"end" con't be less than "start".`); | ||
} | ||
if (!this.overwrites) { | ||
this.overwrites = []; | ||
} | ||
this.overwrites.push({ loc: [start, end], content }); | ||
return this; | ||
} | ||
toString() { | ||
let str = this.str; | ||
if (this.overwrites) { | ||
const arr = [...this.overwrites].sort((a, b) => b.loc[0] - a.loc[0]); | ||
for (const { loc: [start, end], content } of arr) { | ||
str = str.slice(0, start) + content + str.slice(end); | ||
} | ||
} | ||
return this.starts + str + this.ends; | ||
} | ||
} | ||
function relativeify(relativePath) { | ||
@@ -367,3 +333,3 @@ if (relativePath === "") { | ||
} | ||
const contents = await transformDynamicImport({ | ||
const result = await transformDynamicImport({ | ||
options, | ||
@@ -375,5 +341,5 @@ code, | ||
}); | ||
if (contents != null) { | ||
if (result != null) { | ||
return { | ||
contents, | ||
contents: result.code, | ||
loader: id.slice(id.lastIndexOf(".") + 1) | ||
@@ -499,4 +465,8 @@ }; | ||
} | ||
const str = ms.toString(); | ||
return str !== code ? str : null; | ||
if (ms.hasChanged()) { | ||
return { | ||
code: ms.toString(), | ||
map: ms.generateMap({ hires: true, source: id }) | ||
}; | ||
} | ||
} | ||
@@ -503,0 +473,0 @@ async function globFiles({ |
{ | ||
"name": "vite-plugin-dynamic-import", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Enhance Vite builtin dynamic import", | ||
@@ -31,3 +31,4 @@ "main": "./dist/index.js", | ||
"es-module-lexer": "^1.2.1", | ||
"fast-glob": "^3.2.12" | ||
"fast-glob": "^3.2.12", | ||
"magic-string": "^0.30.1" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
48072
4
1233
+ Addedmagic-string@^0.30.1
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Addedmagic-string@0.30.12(transitive)