New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@a-la/import

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@a-la/import - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

src/index.js

4

build/index.js

@@ -1,3 +0,3 @@

let rule = require('./lib/rule'); if (rule && rule.__esModule) rule = rule.default;
let importAs = require('./lib/import-as'); if (importAs && importAs.__esModule) importAs = importAs.default;
const rule = require('./lib/rule');
const importAs = require('./lib/import-as');

@@ -4,0 +4,0 @@ /**

@@ -1,2 +0,2 @@

const { replaceRequire, fromRe, getIfEsModule, alwaysCheckES } = require('.');
const { replaceRequire, fromRe, getIfEsModule, alwaysCheckES } = require('./');

@@ -6,27 +6,45 @@ const importRe = /( *import\s+(?:(.+?)\s*,\s*)?\*\s+as\s+(.+?))/

/** @type {_restream.Rule} */
const importAs = {
re,
replacement(match, importSeg, defName, varName, fromSeg, sd, ld) {
const realSrc = ld
? this.markers.literals.map[ld]
: this.markers.strings.map[sd]
const [, quotes, src] = /(["'`])(.+?)\1/.exec(realSrc)
const r = replaceRequire(fromSeg, quotes, src)
const { length } = importSeg.split('\n')
const ws = '\n'.repeat(length - 1)
let c
const isLocal = /^[./]/.test(src) && !alwaysCheckES(this.config)
const o = isLocal ? 'const' : 'let'
if (defName) {
c = [
`${ws}${o} ${varName} = ${defName}${r}`,
...(isLocal ? [] : [getIfEsModule(defName)]),
].join('; ')
} else {
c = `${ws}const ${varName}${r}`
}
return `${c};`
},
replacement,
}
/**
* @suppress {globalThis}
* @type {_alamode.ÀLaModeReplacer}
*/
function replacement(match, importSeg, defName, varName, fromSeg, sd, ld) {
const realSrc = ld
? this.markers.literals.map[ld]
: this.markers.strings.map[sd]
const [, quotes, src] = /** @type {!RegExpResult} */ (
/(["'`])(.+?)\1/.exec(realSrc)
)
const r = replaceRequire(fromSeg, quotes, src)
const { length } = importSeg.split('\n')
const ws = '\n'.repeat(length - 1)
let c
const isLocal = /^[./]/.test(src) && !alwaysCheckES(this.config)
const o = isLocal ? 'const' : 'let'
if (defName) {
c = [
`${ws}${o} ${varName} = ${defName}${r}`,
...(isLocal ? [] : [getIfEsModule(defName)]),
].join('; ')
} else {
c = `${ws}const ${varName}${r}`
}
return `${c};`
}
module.exports=importAs
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('restream').Rule} _restream.Rule
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('alamode').ÀLaModeReplacer} _alamode.ÀLaModeReplacer
*/
const getRequire = (quotes, src) => {
return `require(${quotes}${src}${quotes})`
return 'r' + `equire(${quotes}${src}${quotes})`
}

@@ -17,3 +17,3 @@

const replaceRequire = (seg, quotes, src, defName) => {
const replaceRequire = (seg, quotes, src, defName = null) => {
const eq = seg.replace(/(\s+)from(\s+)([\s\S])*/, (m, b, a) => {

@@ -46,5 +46,10 @@ return `${b}=${a}`

const alwaysCheckES = (config = {}) => {
/**
* @param {_alamode.Config} config
*/
const alwaysCheckES = (config = {
'import': {},
}) => {
try {
return config.import.esCheck == 'always'
return config['import']['esCheck'] == 'always'
} catch (err) {

@@ -55,2 +60,7 @@ return false

/**
* @suppress {nonStandardJsDocs}
* @typedef {import('alamode').Config} _alamode.Config
*/
module.exports.getRequire = getRequire

@@ -57,0 +67,0 @@ module.exports.getIfEsModule = getIfEsModule

const {
getRequire, getDefault, getSource, replaceRequire, fromRe, alwaysCheckES,
} = require('.');
} = require('./');

@@ -30,29 +30,37 @@ const importRe = /^ *import(\s+([^\s,]+)\s*,?)?(\s*{(?:[^}]+)})?/

* A rule to replace `import { method } from 'package'` statement.
* @type {import('restream').Rule}
* @type {_restream.Rule}
*/
const rule = {
re,
replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) {
const realSrc = ld
? this.markers.literals.map[ld]
: this.markers.strings.map[sd]
const [, quotes, src] = /(["'`])(.+?)\1/.exec(realSrc)
// a special case because regexes are replaced before literals
const s = src.replace(this.markers.regexes.regExp, (m, i) => {
const val = this.markers.regexes.map[i]
return val
})
const source = getSource(s, this.config)
const isLocal = /^[./]/.test(source) && !alwaysCheckES(this.config)
const { t, ifES } = getDef(defSeg, defName, quotes, source, isLocal)
const replacedNamed = getNamed(namedSeg, fromSeg, quotes, source, defName)
const res = [
t, replacedNamed, ...(isLocal ? [] : [ifES]),
]
.filter(a => a)
.join('; ')
return `${res};`
},
replacement,
}
/**
* @suppress {globalThis}
* @type {_alamode.ÀLaModeReplacer}
*/
function replacement(match, defSeg, defName, namedSeg, fromSeg, sd, ld) {
const realSrc = ld
? this.markers.literals.map[ld]
: this.markers.strings.map[sd]
const [, quotes, src] = /** @type {!RegExpResult} */(
/(["'`])(.+?)\1/.exec(realSrc)
)
// a special case because regexes are replaced before literals
const s = src.replace(this.markers.regexes.regExp, (m, i) => {
const val = this.markers.regexes.map[i]
return val
})
const source = getSource(s, this.config)
const isLocal = /^[./]/.test(source) && !alwaysCheckES(this.config)
const { t, ifES } = getDef(defSeg, defName, quotes, source, isLocal)
const replacedNamed = getNamed(namedSeg, fromSeg, quotes, source, defName)
const res = [
t, replacedNamed, ...(isLocal ? [] : [ifES]),
]
.filter(a => a)
.join('; ')
return `${res};`
}
const getDef = (defSeg, defName, quotes, src, isLocal) => {

@@ -79,2 +87,11 @@ if (!defSeg) return {}

/**
* @suppress {nonStandardJsDocs}
* @typedef {import('restream').Rule} _restream.Rule
*/
/**
* @suppress {nonStandardJsDocs}
* @typedef {import('alamode').ÀLaModeReplacer} _alamode.ÀLaModeReplacer
*/
module.exports.re = re

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

## 24 April 2019
### [1.8.0](https://github.com/a-la/import/compare/v1.7.0...v1.8.0)
- [types] Annotate with types.
- [package] Publish the `module` field.
## 8 October 2018

@@ -2,0 +9,0 @@

{
"name": "@a-la/import",
"version": "1.7.0",
"version": "1.8.0",
"description": "À La Regex to transpile the import statement into a require call.",
"main": "build",
"main": "build/index.js",
"module": "src/index.js",
"scripts": {

@@ -15,5 +16,4 @@ "t": "zoroaster -a",

"lint": "eslint .",
"doc": "NODE_DEBUG=doc doc documentary -o README.md",
"rec": "NODE_DEBUG=appshot appshot -T 23 -a Terminal -y 150 -f",
"e": "node example",
"doc": "NODE_DEBUG=doc doc -o README.md",
"e": "alanode",
"example/": "yarn e example/example.js",

@@ -24,3 +24,4 @@ "build": "yarn-s b doc",

"files": [
"build"
"build",
"src"
],

@@ -62,14 +63,13 @@ "repository": {

"devDependencies": {
"@a-la/context": "1.2.3",
"@a-la/context": "^1.2.4",
"@a-la/fixture-alamode": "1.0.0",
"@a-la/fixture-babel": "1.0.0",
"alamode": "1.5.1",
"catchment": "3.1.1",
"documentary": "1.20.1",
"alamode": "^1.9.3",
"catchment": "^3.3.0",
"documentary": "^1.24.1",
"eslint-config-artdeco": "1.0.1",
"restream": "3.2.1",
"restream": "^3.7.1",
"yarn-s": "1.1.0",
"zoroaster": "3.6.2"
},
"dependencies": {}
"zoroaster": "^3.11.6"
}
}

@@ -212,6 +212,20 @@ # @a-la/import

(c) [À La Mode][1] 2018
<table>
<tr>
<th>
<a href="https://artd.eco">
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco" />
</a>
</th>
<th>© <a href="https://artd.eco">Art Deco</a> for <a href="https://alamode.cc">À La Mode</a> 2019</th>
<th>
<a href="https://www.technation.sucks" title="Tech Nation Visa">
<img src="https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif"
alt="Tech Nation Visa" />
</a>
</th>
<th><a href="https://www.technation.sucks">Tech Nation Visa Sucks</a></th>
</tr>
</table>
[1]: https://alamode.cc
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/-1.svg?sanitize=true"></a></p>
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