@a-la/import
Advanced tools
Comparing version 1.9.0 to 1.9.1
@@ -60,7 +60,8 @@ const getRequire = (quotes, src) => { | ||
/** | ||
* @param {string} name | ||
* @param {!_alamode.Config} config | ||
*/ | ||
const isAlamodeModule = (config = { | ||
const isAlamodeModule = (name, config = { | ||
import: {}, | ||
}, name) => { | ||
}) => { | ||
try { | ||
@@ -67,0 +68,0 @@ return config.import.alamodeModules.includes(name) |
@@ -5,3 +5,3 @@ const { | ||
} = require('./'); | ||
const fpj = require('fpj'); | ||
let fpj = require('fpj'); if (fpj && fpj.__esModule) fpj = fpj.default; | ||
const { dirname } = require('path'); | ||
@@ -46,3 +46,3 @@ const { builtinModules } = require('module'); | ||
*/ | ||
async function replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) { | ||
function replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) { | ||
const realSrc = ld | ||
@@ -61,3 +61,13 @@ ? this.markers.literals.map[ld] | ||
if (!this.isLocalCache) this.isLocalCache = {} | ||
const isLocal = await getIsLocal(source, this.config, this.file, this.isLocalCache) | ||
if (this.async) { | ||
return getIsLocal(source, this.config, this.file, this.isLocalCache) | ||
.then((isLocal) => { | ||
return finish(namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) | ||
}) | ||
} | ||
const isLocal = syncGetIsLocal(source, this.config) | ||
return finish(namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) | ||
} | ||
const finish = (namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) => { | ||
const { t, ifES } = getDef(defSeg, defName, quotes, source, isLocal) | ||
@@ -73,7 +83,12 @@ const replacedNamed = getNamed(namedSeg, fromSeg, quotes, source, defName) | ||
const getIsLocal = async (source, config, file, cache) => { | ||
const syncGetIsLocal = (source, config) => { | ||
if (alwaysCheckES(config)) return false | ||
if (isLib(source)) return true | ||
if (builtinModules.includes(source)) return true | ||
if (isAlamodeModule(config, source)) return true | ||
if (isAlamodeModule(source, config)) return true | ||
} | ||
const getIsLocal = async (source, config, file, cache) => { | ||
const sync = syncGetIsLocal(source, config) | ||
if (sync) return true | ||
if (source in cache) return cache[source] | ||
@@ -80,0 +95,0 @@ if (file) try { |
## 16 May 2019 | ||
### [1.9.1](https://github.com/a-la/import/compare/v1.9.0...v1.9.1) | ||
- [fix] Only make async rule when the stream supports it. | ||
### [1.9.0](https://github.com/a-la/import/compare/v1.8.1...v1.9.0) | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "@a-la/import", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "RegExp rules to transpile import statements into require calls (used in ÀLaMode).", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -60,7 +60,8 @@ export const getRequire = (quotes, src) => { | ||
/** | ||
* @param {string} name | ||
* @param {!_alamode.Config} config | ||
*/ | ||
export const isAlamodeModule = (config = { | ||
export const isAlamodeModule = (name, config = { | ||
import: {}, | ||
}, name) => { | ||
}) => { | ||
try { | ||
@@ -67,0 +68,0 @@ return config.import.alamodeModules.includes(name) |
@@ -45,3 +45,3 @@ import { | ||
*/ | ||
async function replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) { | ||
function replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) { | ||
const realSrc = ld | ||
@@ -60,3 +60,13 @@ ? this.markers.literals.map[ld] | ||
if (!this.isLocalCache) this.isLocalCache = {} | ||
const isLocal = await getIsLocal(source, this.config, this.file, this.isLocalCache) | ||
if (this.async) { | ||
return getIsLocal(source, this.config, this.file, this.isLocalCache) | ||
.then((isLocal) => { | ||
return finish(namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) | ||
}) | ||
} | ||
const isLocal = syncGetIsLocal(source, this.config) | ||
return finish(namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) | ||
} | ||
const finish = (namedSeg, fromSeg, defSeg, defName, quotes, source, isLocal) => { | ||
const { t, ifES } = getDef(defSeg, defName, quotes, source, isLocal) | ||
@@ -72,7 +82,12 @@ const replacedNamed = getNamed(namedSeg, fromSeg, quotes, source, defName) | ||
const getIsLocal = async (source, config, file, cache) => { | ||
const syncGetIsLocal = (source, config) => { | ||
if (alwaysCheckES(config)) return false | ||
if (isLib(source)) return true | ||
if (builtinModules.includes(source)) return true | ||
if (isAlamodeModule(config, source)) return true | ||
if (isAlamodeModule(source, config)) return true | ||
} | ||
const getIsLocal = async (source, config, file, cache) => { | ||
const sync = syncGetIsLocal(source, config) | ||
if (sync) return true | ||
if (source in cache) return cache[source] | ||
@@ -79,0 +94,0 @@ if (file) try { |
27633
494