Socket
Socket
Sign inDemoInstall

@aem-vite/import-rewriter

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aem-vite/import-rewriter - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

15

CHANGELOG.md

@@ -0,1 +1,8 @@

## [4.1.1](https://github.com/aem-vite/import-rewriter/compare/v4.1.0...v4.1.1) (2022-01-19)
### Bug Fixes
* resolve import paths with caching enabled ([f5c2a35](https://github.com/aem-vite/import-rewriter/commit/f5c2a357b9f7c0f4d748969caa47eb49f0287944))
# [4.1.0](https://github.com/aem-vite/import-rewriter/compare/v4.0.0...v4.1.0) (2021-12-29)

@@ -13,2 +20,10 @@

### BREAKING CHANGES
* The default export has been replaced with a named export
* The `aemViteCSSImportRewriter` export has been renamed to `cssImportRewriter`
To better align with community standards, the default export has been changed to a named export called `bundlesImportRewriter`.
# [4.0.0](https://github.com/aem-vite/import-rewriter/compare/v3.0.1...v4.0.0) (2021-12-28)

@@ -15,0 +30,0 @@

57

lib/index.js

@@ -44,6 +44,11 @@ var __create = Object.create;

var import_crypto = require("crypto");
var import_debug = __toESM(require("debug"));
var import_fs = require("fs");
var import_path = require("path");
var debug = (0, import_debug.default)("aem-vite-import-rewriter");
var mainEntryPath;
var relativePathPattern = /([.]{1,2}\/)+/;
function logger(...args) {
debug(args);
}
function hasMainEntryPath() {

@@ -99,2 +104,3 @@ return mainEntryPath && mainEntryPath.length > 0 || false;

if (options.mainEntryPath || chunk.isEntry && chunk.facadeModuleId && /(ts|js)x?$/.test(chunk.facadeModuleId) && !hasMainEntryPath()) {
logger("setting main entry path", options.mainEntryPath || chunk.fileName);
setMainEntryPath(options.mainEntryPath || chunk.fileName);

@@ -117,2 +123,3 @@ }

if (dynamicIndex === -1 && importPath && relativePathPattern.test(importPath)) {
logger("render chunk (dynamic import)", importPath, getReplacementPath(importPath, options, chunk.imports));
str().overwrite(start, end, getReplacementPath(importPath, options, chunk.imports));

@@ -131,2 +138,3 @@ }

const mainEntryPath2 = getMainEntryPath();
const mainEntryAEMPath = getAEMImportFilePath(mainEntryPath2, options);
for (const [fileName, chunk] of Object.entries(bundles)) {

@@ -137,31 +145,30 @@ if (!isOutputChunk(chunk) || !chunk.code) {

const source = chunk.code;
if (mainEntryPath2 === fileName && options.caching && options.caching.enabled) {
const mainEntryAEMPath = getAEMImportFilePath(mainEntryPath2, options);
const mainEntryAEMPathWithHash = getAEMImportFilePath(mainEntryPath2, options, true, rollupOptions);
(0, import_fs2.writeFileSync)((0, import_path2.join)(rollupOptions.dir, fileName), source.replace(mainEntryAEMPath, mainEntryAEMPathWithHash));
} else {
await import_es_module_lexer.init;
let imports = [];
try {
imports = (0, import_es_module_lexer.parse)(source)[0];
} catch (e) {
this.error(e, e.idx);
await import_es_module_lexer.init;
let imports = [];
try {
imports = (0, import_es_module_lexer.parse)(source)[0];
} catch (e) {
this.error(e, e.idx);
}
if (!imports.length) {
continue;
}
let s;
const str = () => s || (s = new import_magic_string.default(source));
for (let index = 0; index < imports.length; index++) {
const { e: end, d: dynamicIndex, n: importPath, s: start } = imports[index];
logger("write bundle (dynamic import)", importPath);
if (dynamicIndex === -1 && importPath && importPath.substring(importPath.lastIndexOf("/") + 1) === mainEntryAEMPath) {
const mainEntryAEMPathWithHash = getAEMImportFilePath(mainEntryPath2, options, true, rollupOptions);
str().overwrite(start, end, importPath.substring(0, importPath.lastIndexOf("/") + 1) + mainEntryAEMPathWithHash);
}
if (!imports.length) {
continue;
}
let s;
const str = () => s || (s = new import_magic_string.default(source));
for (let index = 0; index < imports.length; index++) {
const { e: end, d: dynamicIndex } = imports[index];
if (dynamicIndex > -1) {
const dynamicEnd = source.indexOf(")", end) + 1;
const original = source.slice(dynamicIndex + 8, dynamicEnd - 2);
if (!original.startsWith("/")) {
str().overwrite(dynamicIndex + 8, dynamicEnd - 2, getReplacementPath(original, options, chunk.dynamicImports));
}
if (dynamicIndex > -1) {
const dynamicEnd = source.indexOf(")", end) + 1;
const original = source.slice(dynamicIndex + 8, dynamicEnd - 2);
if (!original.startsWith("/")) {
str().overwrite(dynamicIndex + 8, dynamicEnd - 2, getReplacementPath(original, options, chunk.dynamicImports));
}
}
(0, import_fs2.writeFileSync)((0, import_path2.join)(rollupOptions.dir, fileName), s && s.toString() || source);
}
(0, import_fs2.writeFileSync)((0, import_path2.join)(rollupOptions.dir, fileName), s && s.toString() || source);
}

@@ -168,0 +175,0 @@ }

@@ -14,3 +14,3 @@ {

},
"version": "4.1.0",
"version": "4.1.1",
"engines": {

@@ -65,2 +65,3 @@ "node": ">= 12"

"dependencies": {
"debug": "^4.3.3",
"es-module-lexer": "^0.9.3",

@@ -75,2 +76,3 @@ "magic-string": "^0.25.7",

"@semantic-release/git": "^9.0.1",
"@types/debug": "^4.1.7",
"@types/node": "^12.20.39",

@@ -77,0 +79,0 @@ "@typescript-eslint/eslint-plugin": "^5.8.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc