gulp-rewrite-imports
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -14,4 +14,5 @@ /// <reference types="node" /> | ||
noRequire?: boolean; | ||
noExportFrom?: boolean; | ||
} | ||
declare const _default: (options: Options) => import("stream").Transform; | ||
export = _default; |
26
index.js
@@ -11,3 +11,3 @@ "use strict"; | ||
function createRegex() { | ||
return /(?:import(.*?)from ?(?:(?:"([^"]+)")|(?:'([^']+)'));?)|(?:require\((?:(?:"([^"]+)")|(?:'([^']+)'))\))|(?:import\((?:(?:"([^"]+)")|(?:'([^']+)'))\))/g; | ||
return /(?:import(.*?)from ?(?:(?:"([^"]+)")|(?:'([^']+)'));?)|(?:export(.*?)from ?(?:(?:"([^"]+)")|(?:'([^']+)'));?)|(?:require\((?:(?:"([^"]+)")|(?:'([^']+)'))\))|(?:import\((?:(?:"([^"]+)")|(?:'([^']+)'))\))/g; | ||
} | ||
@@ -32,2 +32,8 @@ function pipeRequireSQ(module) { | ||
} | ||
function pipeExportFromSQ(module, exports) { | ||
return "export " + exports + " from '" + module + "';"; | ||
} | ||
function pipeExportFromDQ(module, exports) { | ||
return "export " + exports + " from \"" + module + "\";"; | ||
} | ||
function resolveRelativePath(inPath, relativeTo, file) { | ||
@@ -69,6 +75,6 @@ if (!relativeTo) { | ||
var imports; | ||
if ((match[4] || match[5]) && !options.noRequire) { | ||
if ((match[7] || match[8]) && !options.noRequire) { | ||
// require(xxx) | ||
srcModule = match[4] || match[5]; | ||
importWriter = match[4] ? pipeRequireDQ : pipeRequireSQ; | ||
srcModule = match[7] || match[8]; | ||
importWriter = match[7] ? pipeRequireDQ : pipeRequireSQ; | ||
} | ||
@@ -81,6 +87,12 @@ else if ((match[2] || match[3]) && !options.noImportFrom) { | ||
} | ||
else if ((match[6] || match[7]) && !options.noImport) { | ||
else if ((match[5] || match[6]) && !options.noExportFrom) { | ||
// export xxx from yyy | ||
imports = match[4].trim(); | ||
srcModule = match[5] || match[6]; | ||
importWriter = match[5] ? pipeExportFromDQ : pipeExportFromSQ; | ||
} | ||
else if ((match[9] || match[20]) && !options.noImport) { | ||
// import(xxx) | ||
srcModule = match[6] || match[7]; | ||
importWriter = match[6] ? pipeImportDQ : pipeImportSQ; | ||
srcModule = match[9] || match[10]; | ||
importWriter = match[9] ? pipeImportDQ : pipeImportSQ; | ||
} | ||
@@ -87,0 +99,0 @@ else { |
{ | ||
"name": "gulp-rewrite-imports", | ||
"author": "kremi151", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": { |
# gulp-rewrite-imports | ||
![NPM](https://img.shields.io/npm/v/gulp-rewrite-imports?color=green) | ||
A gulp plugin which allows to rewrite `import` and `require` statements in JavaScript and TypeScript files. | ||
@@ -4,0 +6,0 @@ |
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
7536
146
41