@cara/porter
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -202,2 +202,3 @@ /* eslint-env browser */ | ||
if (id.slice(-1) == '/') return id + 'index.js'; | ||
id = id.replace(/\.(?:js|jsx|ts|tsx|mjs|cjs)$/, '.js'); | ||
return /\.(?:css|js|wasm)$/.test(id) ? id : id + '.js'; | ||
@@ -204,0 +205,0 @@ } |
{ | ||
"name": "@cara/porter", | ||
"description": "A middleware for web modules", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"main": "src/porter.js", | ||
@@ -43,3 +43,3 @@ "repository": { | ||
"license": "BSD-3-Clause", | ||
"gitHead": "912059582593582e7e7563efe1fbd94162e31b31" | ||
"gitHead": "7a7fd5addf84d047ab496eaa03bcdff303aa5677" | ||
} |
@@ -12,3 +12,3 @@ 'use strict'; | ||
const extMap = { | ||
'.js': [ '.js', '.jsx', '.ts', '.tsx', '.json' ], | ||
'.js': [ '.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.json' ], | ||
'.wasm': [ '.wasm' ], | ||
@@ -94,3 +94,3 @@ '.css': [ '.css', '.less' ], | ||
this.loaderConfig = loaderConfig; | ||
this.#entries = Array.isArray(entries) && entries.length > 0 ? entries : null; | ||
this.#entries = entries && entries.length > 0 ? [].concat(entries) : null; | ||
this.#loaderCache = {}; | ||
@@ -97,0 +97,0 @@ |
@@ -122,2 +122,29 @@ 'use strict'; | ||
/** | ||
* Find deps of code and compare them with existing `this.deps` to see if there's | ||
* new dep to parse. Only the modules of the root packet are checked. | ||
* @param {Object} opts | ||
* @param {string} opts.code | ||
* @returns {Array} | ||
*/ | ||
async checkImports({ code, intermediate = false }) { | ||
const { imports = [], dynamicImports = [] } = this; | ||
this.matchImport(code); | ||
if (this.imports) { | ||
for (const dep of this.imports) { | ||
if (!imports.includes(dep)) await this.parseImport(dep); | ||
} | ||
} | ||
// when checking imports introduced by intermediate code, dynamic imports need reset | ||
// import(specifier) -> Promise.resolve(require(specifier)) | ||
if (intermediate) { | ||
for (let i = this.imports.length; i >= 0; i--) { | ||
const specifier = this.imports[i]; | ||
if (dynamicImports.includes(specifier)) this.imports.splice(i, 1); | ||
} | ||
this.dynamicImports = dynamicImports; | ||
} | ||
} | ||
async minify() { | ||
@@ -124,0 +151,0 @@ if (this.cache && this.cache.minified) return this.cache; |
@@ -210,18 +210,9 @@ 'use strict'; | ||
*/ | ||
async checkImports({ code, intermediate = false }) { | ||
const { imports, dynamicImports = [] } = this; | ||
async checkImports({ code }) { | ||
const { imports } = this; | ||
this.matchImport(code); | ||
for (const dep of this.imports) { | ||
if (!imports.includes(dep)) await this.parseImport(dep); | ||
} | ||
// when checking imports introduced by intermediate code, dynamic imports need reset | ||
// import(specifier) -> Promise.resolve(require(specifier)) | ||
if (intermediate) { | ||
for (let i = this.imports.length; i >= 0; i--) { | ||
const specifier = this.imports[i]; | ||
if (dynamicImports.includes(specifier)) this.imports.splice(i, 1); | ||
if (this.imports) { | ||
for (const dep of this.imports) { | ||
if (!imports.includes(dep)) await this.parseImport(dep); | ||
} | ||
this.dynamicImports = dynamicImports; | ||
} | ||
@@ -228,0 +219,0 @@ } |
@@ -41,2 +41,4 @@ 'use strict'; | ||
case '.jsx': | ||
case '.mjs': | ||
case '.cjs': | ||
return new JsModule(opts); | ||
@@ -43,0 +45,0 @@ case '.less': |
121337
3189
23