@a-la/import
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -1,2 +0,2 @@ | ||
const { debuglog } = require('util') | ||
const { debuglog } = require('util'); | ||
let rule = require('./lib/rule'); if (rule && rule.__esModule) rule = rule.default; | ||
@@ -3,0 +3,0 @@ let importAs = require('./lib/import-as'); if (importAs && importAs.__esModule) importAs = importAs.default; |
@@ -1,2 +0,2 @@ | ||
const { replaceRequire } = require('.') | ||
const { replaceRequire, fromRe } = require('.'); | ||
@@ -8,6 +8,13 @@ const makeDefaultIf = (name) => { | ||
const importRe = /( *import\s+(?:(.+?)\s*,\s*)?\*\s+as\s+(.+?))/ | ||
const re = new RegExp(`${importRe.source}${fromRe.source}`, 'gm') | ||
const importAs = | ||
{ | ||
re: /( *import\s+(?:(.+?)\s*,\s*)?\*\s+as\s+(.+?))(\s+from\s+(["'])(.+?)\5)/gm, | ||
replacement(match, importSeg, defName, varName, fromSeg, quotes, src) { | ||
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) | ||
@@ -14,0 +21,0 @@ const { length } = importSeg.split('\n') |
@@ -37,2 +37,5 @@ const getRequire = (quotes, src) => { | ||
// temp solution, until restream markers can store only part of regex, e.g. '%RESTREAM_MARKER%' instead of %RESTREAM_MARKER% for a string. | ||
const fromRe = /(\s+from\s+)(?:%%_RESTREAM_STRINGS_REPLACEMENT_(\d+)_%%|%%_RESTREAM_LITERALS_REPLACEMENT_(\d+)_%%)/ | ||
module.exports.getRequire = getRequire | ||
@@ -43,2 +46,3 @@ module.exports.getIfEsModule = getIfEsModule | ||
module.exports.getSource = getSource | ||
module.exports.fromRe = fromRe | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,7 @@ | ||
const { getRequire, getDefault, getSource, replaceRequire } = require('.') | ||
const { | ||
getRequire, getDefault, getSource, replaceRequire, fromRe, | ||
} = require('.'); | ||
const re = /^ *import(\s+([^\s,]+)\s*,?)?(\s*{(?:[^}]+)})?(\s+from\s+(["'])(.+?)\5)/gm | ||
const importRe = /^ *import(\s+([^\s,]+)\s*,?)?(\s*{(?:[^}]+)})?/ | ||
const re = new RegExp(`${importRe.source}${fromRe.source}`, 'gm') | ||
@@ -31,3 +34,7 @@ /** | ||
re, | ||
replacement(match, defSeg, defName, namedSeg, fromSeg, quotes, src) { | ||
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) | ||
const source = getSource(src, this.config) | ||
@@ -34,0 +41,0 @@ const replacedDefault = getDef(defSeg, defName, quotes, source) |
@@ -0,1 +1,7 @@ | ||
## 1 September 2018 | ||
### 1.6.0 | ||
- [feature] Access string and literal markers from `alamode`. | ||
## 27 August 2018 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@a-la/import", | ||
"version": "1.5.0", | ||
"description": "À La Regex to transpile an import statement into require.", | ||
"version": "1.6.0", | ||
"description": "À La Regex to transpile the import statement into a require call.", | ||
"main": "build", | ||
@@ -58,8 +58,8 @@ "scripts": { | ||
"devDependencies": { | ||
"@a-la/context": "1.1.1", | ||
"alamode": "1.2.1", | ||
"catchment": "3.0.0", | ||
"@a-la/context": "1.2.0", | ||
"alamode": "1.3.0", | ||
"catchment": "3.0.1", | ||
"documentary": "1.10.0", | ||
"eslint-config-artdeco": "1.0.1", | ||
"restream": "3.1.0", | ||
"restream": "3.1.1", | ||
"yarn-s": "1.1.0", | ||
@@ -66,0 +66,0 @@ "zoroaster": "2.4.0" |
@@ -5,5 +5,5 @@ # @a-la/import | ||
`@a-la/import` is a a set of rules for [`alamode`](https://alamode.cc) to transpile an `import` statement into `require` in Node.js. | ||
`@a-la/import` is a a set of rules for [`alamode`](https://alamode.cc) to transpile the `import` statement into a `require` call in Node.js. | ||
_À La Mode_ is a RegExp-based transpiler which works faster than AST-based transpilers such as `@babel`, and occupies only 10KB of disk space. | ||
_À La Mode_ is a RegExp-based transpiler which works faster than AST-based transpilers such as `@babel`, has fewer dependencies, and occupies less disk space. | ||
@@ -25,2 +25,3 @@ ```sh | ||
- [Checklist](#checklist) | ||
- [TODO](#todo) | ||
- [Copyright](#copyright) | ||
@@ -38,7 +39,7 @@ | ||
The rule set exported as an array by `ALaImport` has multiple regexes and replacer functions to match all possible cases. | ||
The rule set exported as an array by `ALaImport` has multiple regexes and replacer functions to match all possible cases. The replacer functions expect to see the `matchers` property on the context, which is set by `alamode` to access cut out strings. The transform can be run using `@a-la/context` which is a lightweight version of `alamode` which mimics its stream functionality. | ||
```js | ||
/* yarn example/ */ | ||
import { Replaceable } from 'restream' | ||
import ALaContext from '@a-la/context' | ||
import ALaImport from '@a-la/import' | ||
@@ -52,10 +53,5 @@ | ||
;(async () => { | ||
const stream = new Replaceable([ | ||
...ALaImport, | ||
]) | ||
await new Promise((r, j) => { | ||
stream.end(STRING, r) | ||
stream.on('error', j) | ||
}) | ||
stream.pipe(process.stdout) | ||
const context = new ALaContext() | ||
const { result } = await context.stream(ALaImport, STRING) | ||
console.log(result) | ||
})() | ||
@@ -172,3 +168,3 @@ ``` | ||
- [x] `import defaultExport from "module-name"` | ||
- [ ] `import * as name from "module-name";` | ||
- [x] `import * as name from "module-name";` | ||
- [x] `import { export } from "module-name";` | ||
@@ -183,2 +179,7 @@ - [x] `import { export as alias } from "module-name";` | ||
## TODO | ||
- [ ] Add an option to ignore the `__esModule` check for specified packages. | ||
- [ ] Better `from 'package'` handling when matchers' logic is updated in the `restream`. | ||
## Copyright | ||
@@ -185,0 +186,0 @@ |
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
27318
143
184