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

import-all.macro

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-all.macro - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

5

CHANGELOG.md
# CHANGELOG
The changelog is automatically updated using [semantic-release](https://github.com/semantic-release/semantic-release).
You can see it on the [releases page](../../releases).
The changelog is automatically updated using
[semantic-release](https://github.com/semantic-release/semantic-release). You
can see it on the [releases page](../../releases).

3

dist/index.js

@@ -1,5 +0,4 @@

'use strict';
"use strict";
/* istanbul ignore next */
module.exports = require('./macro');

@@ -1,27 +0,38 @@

'use strict';
"use strict";
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const path = require('path'); // const printAST = require('ast-pretty-print')
var path = require('path');
// const printAST = require('ast-pretty-print')
var _require = require('babel-plugin-macros'),
createMacro = _require.createMacro;
const {
createMacro
} = require('babel-plugin-macros');
var glob = require('glob');
const glob = require('glob');
module.exports = createMacro(prevalMacros);
function prevalMacros(_ref) {
var references = _ref.references,
state = _ref.state,
babel = _ref.babel;
references.default.forEach(function (referencePath) {
function prevalMacros({
references,
state,
babel
}) {
references.default.forEach(referencePath => {
if (referencePath.parentPath.type === 'CallExpression') {
asyncVersion({ referencePath, state, babel });
asyncVersion({
referencePath,
state,
babel
});
} else if (referencePath.parentPath.type === 'MemberExpression' && referencePath.parentPath.node.property.name === 'sync') {
syncVersion({ referencePath, state, babel });
syncVersion({
referencePath,
state,
babel
});
} else if (referencePath.parentPath.type === 'MemberExpression' && referencePath.parentPath.node.property.name === 'deferred') {
deferredVersion({ referencePath, state, babel });
deferredVersion({
referencePath,
state,
babel
});
} else {

@@ -33,38 +44,53 @@ throw new Error(`This is not supported: \`${referencePath.findParent(babel.types.isExpression).getSource()}\`. Please see the import-all.macro documentation`);

function syncVersion(_ref2) {
var _program$node$body;
var referencePath = _ref2.referencePath,
state = _ref2.state,
babel = _ref2.babel;
var t = babel.types;
var filename = state.file.opts.filename;
var importSources = getImportSources(referencePath.parentPath.parentPath, path.dirname(filename));
var _importSources$reduce = importSources.reduce(function (all, source) {
var id = referencePath.scope.generateUidIdentifier(source);
function syncVersion({
referencePath,
state,
babel
}) {
const {
types: t
} = babel;
const {
file: {
opts: {
filename
}
}
} = state;
const importSources = getImportSources(referencePath.parentPath.parentPath, path.dirname(filename));
const {
importNodes,
objectProperties
} = importSources.reduce((all, source) => {
const id = referencePath.scope.generateUidIdentifier(source);
all.importNodes.push(t.importDeclaration([t.importNamespaceSpecifier(id)], t.stringLiteral(source)));
all.objectProperties.push(t.objectProperty(t.stringLiteral(source), id));
return all;
}, { importNodes: [], objectProperties: [] }),
importNodes = _importSources$reduce.importNodes,
objectProperties = _importSources$reduce.objectProperties;
var objectExpression = t.objectExpression(objectProperties);
var program = state.file.path;
(_program$node$body = program.node.body).unshift.apply(_program$node$body, _toConsumableArray(importNodes));
}, {
importNodes: [],
objectProperties: []
});
const objectExpression = t.objectExpression(objectProperties);
const program = state.file.path;
program.node.body.unshift(...importNodes);
referencePath.parentPath.parentPath.replaceWith(objectExpression);
}
function asyncVersion(_ref3) {
var referencePath = _ref3.referencePath,
state = _ref3.state,
babel = _ref3.babel;
var t = babel.types,
template = babel.template;
var filename = state.file.opts.filename;
var promiseTemplate = template(`
function asyncVersion({
referencePath,
state,
babel
}) {
const {
types: t,
template
} = babel;
const {
file: {
opts: {
filename
}
}
} = state;
const promiseTemplate = template(`
Promise.all(ALL_IMPORTS).then(function importAllHandler(importVals) {

@@ -74,13 +100,14 @@ return IMPORT_OBJ

`);
var importSources = getImportSources(referencePath.parentPath, path.dirname(filename));
var _importSources$reduce2 = importSources.reduce(function (all, source, index) {
const importSources = getImportSources(referencePath.parentPath, path.dirname(filename));
const {
dynamicImports,
objectProperties
} = importSources.reduce((all, source, index) => {
all.dynamicImports.push(t.callExpression(t.import(), [t.stringLiteral(source)]));
all.objectProperties.push(t.objectProperty(t.stringLiteral(source), t.memberExpression(t.identifier('importVals'), t.numericLiteral(index), true)));
return all;
}, { dynamicImports: [], objectProperties: [] }),
dynamicImports = _importSources$reduce2.dynamicImports,
objectProperties = _importSources$reduce2.objectProperties;
}, {
dynamicImports: [],
objectProperties: []
});
referencePath.parentPath.replaceWith(promiseTemplate({

@@ -92,17 +119,22 @@ ALL_IMPORTS: t.arrayExpression(dynamicImports),

function deferredVersion(_ref4) {
var referencePath = _ref4.referencePath,
state = _ref4.state,
babel = _ref4.babel;
var t = babel.types;
var filename = state.file.opts.filename;
var importSources = getImportSources(referencePath.parentPath.parentPath, path.dirname(filename));
var objectProperties = importSources.map(function (source) {
function deferredVersion({
referencePath,
state,
babel
}) {
const {
types: t
} = babel;
const {
file: {
opts: {
filename
}
}
} = state;
const importSources = getImportSources(referencePath.parentPath.parentPath, path.dirname(filename));
const objectProperties = importSources.map(source => {
return t.objectProperty(t.stringLiteral(source), t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.callExpression(t.import(), [t.stringLiteral(source)]))])));
});
var objectExpression = t.objectExpression(objectProperties);
const objectExpression = t.objectExpression(objectProperties);
referencePath.parentPath.parentPath.replaceWith(objectExpression);

@@ -112,9 +144,10 @@ }

function getImportSources(callExpressionPath, cwd) {
var globValue = void 0;
let globValue;
try {
globValue = callExpressionPath.get('arguments')[0].evaluate().value;
} catch (error) {
// ignore the error
} catch (error) {// ignore the error
// add a console.log here if you need to know more specifically what's up...
}
if (!globValue) {

@@ -124,3 +157,5 @@ throw new Error(`There was a problem evaluating the value of the argument for the code: ${callExpressionPath.getSource()}. ` + `If the value is dynamic, please make sure that its value is statically deterministic.`);

return glob.sync(globValue, { cwd });
return glob.sync(globValue, {
cwd
});
}

@@ -1,1 +0,59 @@

{"name":"import-all.macro","version":"2.0.3","description":"A macro for babel-plugin-macros that allows you to import all files that match a glob","main":"dist/index.js","engines":{"node":"> 4","npm":"> 3"},"scripts":{"add-contributor":"kcd-scripts contributors add","build":"kcd-scripts build","lint":"kcd-scripts lint","test":"kcd-scripts test","test:update":"npm test -- --updateSnapshot --coverage","validate":"kcd-scripts validate","precommit":"kcd-scripts precommit"},"files":["dist"],"keywords":["babel-plugin-macros"],"author":"Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)","license":"MIT","dependencies":{"babel-plugin-macros":"^2.0.0","glob":"^7.1.2"},"devDependencies":{"ast-pretty-print":"^2.0.1","babel-plugin-tester":"^5.0.0","kcd-scripts":"^0.32.1","prettier":"^1.10.2"},"eslintConfig":{"extends":"./node_modules/kcd-scripts/eslint.js","rules":{"complexity":["error",12]}},"eslintIgnore":["node_modules","coverage","dist"],"repository":{"type":"git","url":"https://github.com/kentcdodds/import-all.macro.git"},"bugs":{"url":"https://github.com/kentcdodds/import-all.macro/issues"},"homepage":"https://github.com/kentcdodds/import-all.macro#readme"}
{
"name": "import-all.macro",
"version": "3.0.0",
"description": "A macro for babel-plugin-macros that allows you to import all files that match a glob",
"main": "dist/index.js",
"engines": {
"node": ">=10",
"npm": ">=6"
},
"scripts": {
"build": "kcd-scripts build",
"lint": "kcd-scripts lint",
"setup": "npm install && npm run validate -s",
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate"
},
"files": [
"dist"
],
"keywords": [
"babel-plugin-macros"
],
"author": "Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.9.2",
"babel-plugin-macros": "^2.8.0",
"glob": "^7.1.6"
},
"devDependencies": {
"ast-pretty-print": "^2.0.1",
"babel-plugin-tester": "^8.0.1",
"kcd-scripts": "^5.6.0",
"prettier": "2.0.1"
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js",
"rules": {
"complexity": [
"error",
12
]
}
},
"eslintIgnore": [
"node_modules",
"coverage",
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/kentcdodds/import-all.macro"
},
"bugs": {
"url": "https://github.com/kentcdodds/import-all.macro/issues"
},
"homepage": "https://github.com/kentcdodds/import-all.macro#readme"
}

@@ -7,4 +7,5 @@ <div align="center">

<hr />
---
<!-- prettier-ignore-start -->
[![Build Status][build-badge]][build]

@@ -16,11 +17,10 @@ [![Code Coverage][coverage-badge]][coverage]

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
[![Babel Macro][macros-badge]][babel-plugin-macros]
<!-- prettier-ignore-end -->
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
## The problem

@@ -33,6 +33,6 @@

This is a [babel-plugin-macro][babel-plugin-macros] which allows you to import files that
match a glob. It supports `import` statements for synchronous resolution as well
as dynamic `import()` for deferred resolution (for code splitting with react
router for example).
This is a [babel-plugin-macro][babel-plugin-macros] which allows you to import
files that match a glob. It supports `import` statements for synchronous
resolution as well as dynamic `import()` for deferred resolution (for code
splitting with react router for example).

@@ -42,12 +42,14 @@ ## Table of Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
* [Installation](#installation)
* [Usage](#usage)
* [Caveats](#caveats)
* [Inspiration](#inspiration)
* [Other Solutions](#other-solutions)
* [Contributors](#contributors)
* [LICENSE](#license)
- [Installation](#installation)
- [Usage](#usage)
- [Caveats](#caveats)
- [Inspiration](#inspiration)
- [Other Solutions](#other-solutions)
- [Issues](#issues)
- [πŸ› Bugs](#-bugs)
- [πŸ’‘ Feature Requests](#-feature-requests)
- [Contributors ✨](#contributors-)
- [LICENSE](#license)

@@ -67,4 +69,5 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

Once you've [configured `babel-plugin-macros`][https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md] you can
import/require `import-all.macro`.
Once you've
[configured `babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md)
you can import/require `import-all.macro`.

@@ -74,4 +77,4 @@ The `importAll` functions accept a [`glob`][glob] and will transpile your code

Let's imagine you have a directory called `my-files` with the files
`a.js`, `b.js`, `c.js`, and `d.js`.
Let's imagine you have a directory called `my-files` with the files `a.js`,
`b.js`, `c.js`, and `d.js`.

@@ -81,5 +84,3 @@ Here are a few before/after examples:

<!-- SNAP_TO_README:START -->
<!-- This section is generated by the other/snap-to-readme.js script. -->
<!-- Do not edit directly. -->

@@ -121,3 +122,4 @@

**`importAll.sync` uses static imports: README:2 `importAll.sync` uses static imports**
**`importAll.sync` uses static imports: README:2 `importAll.sync` uses static
imports**

@@ -135,3 +137,2 @@ ```javascript

import * as _filesDJs from './files/d.js'
const a = {

@@ -145,3 +146,4 @@ './files/a.js': _filesAJs,

**`importAll.deferred` gives an object with dynamic imports: README:3 `importAll.deferred` gives an object with dynamic imports**
**`importAll.deferred` gives an object with dynamic imports: README:3
`importAll.deferred` gives an object with dynamic imports**

@@ -175,6 +177,6 @@ ```javascript

Some static analysis tools (like ESLint, Flow, and Jest) wont like this very much
without a little additional work. So Jest's watch mode may not pick up all your
tests that are relevant based on changes and some ESLint plugins
(like `eslint-plugin-import`) will probably fail on this.
Some static analysis tools (like ESLint, Flow, and Jest) wont like this very
much without a little additional work. So Jest's watch mode may not pick up all
your tests that are relevant based on changes and some ESLint plugins (like
`eslint-plugin-import`) will probably fail on this.

@@ -190,12 +192,39 @@ ## Inspiration

## Contributors
## Issues
_Looking to contribute? Look for the [Good First Issue][good-first-issue]
label._
### πŸ› Bugs
Please file an issue for bugs, missing documentation, or unexpected behavior.
[**See Bugs**][bugs]
### πŸ’‘ Feature Requests
Please file an issue to suggest new features. Vote on feature requests by adding
a πŸ‘. This helps maintainers prioritize what to work on.
[**See Feature Requests**][requests]
## Contributors ✨
Thanks goes to these people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;" alt=""/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds" title="Code">πŸ’»</a> <a href="https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds" title="Documentation">πŸ“–</a> <a href="#infra-kentcdodds" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds" title="Tests">⚠️</a></td>
<td align="center"><a href="http://jonathantneal.com"><img src="https://avatars0.githubusercontent.com/u/188426?v=4" width="100px;" alt=""/><br /><sub><b>Jonathan Neal</b></sub></a><br /><a href="https://github.com/kentcdodds/import-all.macro/commits?author=jonathantneal" title="Documentation">πŸ“–</a></td>
<td align="center"><a href="https://fatfisz.com"><img src="https://avatars0.githubusercontent.com/u/6004414?v=4" width="100px;" alt=""/><br /><sub><b>RafaΕ‚ RuciΕ„ski</b></sub></a><br /><a href="https://github.com/kentcdodds/import-all.macro/issues?q=author%3Afatfisz" title="Bug reports">πŸ›</a> <a href="https://github.com/kentcdodds/import-all.macro/commits?author=fatfisz" title="Code">πŸ’»</a></td>
<td align="center"><a href="https://stackshare.io/jdorfman/decisions"><img src="https://avatars1.githubusercontent.com/u/398230?v=4" width="100px;" alt=""/><br /><sub><b>Justin Dorfman</b></sub></a><br /><a href="#fundingFinding-jdorfman" title="Funding Finding">πŸ”</a></td>
<td align="center"><a href="https://michaeldeboey.be"><img src="https://avatars3.githubusercontent.com/u/6643991?v=4" width="100px;" alt=""/><br /><sub><b>MichaΓ«l De Boey</b></sub></a><br /><a href="https://github.com/kentcdodds/import-all.macro/commits?author=MichaelDeBoey" title="Code">πŸ’»</a></td>
</tr>
</table>
<!-- prettier-ignore -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[πŸ’»](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Tests") | [<img src="https://avatars0.githubusercontent.com/u/188426?v=4" width="100px;"/><br /><sub><b>Jonathan Neal</b></sub>](http://jonathantneal.com)<br />[πŸ“–](https://github.com/kentcdodds/import-all.macro/commits?author=jonathantneal "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/6004414?v=4" width="100px;"/><br /><sub><b>RafaΕ‚ RuciΕ„ski</b></sub>](https://fatfisz.com)<br />[πŸ›](https://github.com/kentcdodds/import-all.macro/issues?q=author%3Afatfisz "Bug reports") [πŸ’»](https://github.com/kentcdodds/import-all.macro/commits?author=fatfisz "Code") |
| :---: | :---: | :---: |
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

@@ -210,3 +239,4 @@

[npm]: https://www.npmjs.com/
<!-- prettier-ignore-start -->
[npm]: https://www.npmjs.com
[node]: https://nodejs.org

@@ -230,12 +260,10 @@ [build-badge]: https://img.shields.io/travis/kentcdodds/import-all.macro.svg?style=flat-square

[babel-plugin-macros]: https://github.com/kentcdodds/babel-plugin-macros
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/import-all.macro.svg?style=social
[github-watch]: https://github.com/kentcdodds/import-all.macro/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/import-all.macro.svg?style=social
[github-star]: https://github.com/kentcdodds/import-all.macro/stargazers
[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20import-all.macro%20by%20%40kentcdodds%20https%3A%2F%2Fgithub.com%2Fkentcdodds%2Fimport-all.macro%20%F0%9F%91%8D
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/import-all.macro.svg?style=social
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
[all-contributors]: https://github.com/kentcdodds/all-contributors
[babel-plugin-macros-user]: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md
[emojis]: https://github.com/all-contributors/all-contributors#emoji-key
[all-contributors]: https://github.com/all-contributors/all-contributors
[bugs]: https://github.com/kentcdodds/import-all.macro/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug
[requests]: https://github.com/kentcdodds/import-all.macro/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement
[good-first-issue]: https://github.com/kentcdodds/import-all.macro/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22
[glob]: https://www.npmjs.com/package/glob
[sunil-tweet]: https://twitter.com/threepointone/status/908290510225330176
<!-- prettier-ignore-end -->
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