Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit a370274

Browse files
committed
Move files around and change entry point
1 parent c397431 commit a370274

8 files changed

+37
-40
lines changed

__snapshots__/require-context.macro.test.js.snap

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`macros 1. macros: 1. macros 1`] = `
4+
"
5+
import requireContext from '../require-context.macro';
6+
7+
requireContext('../src/components', true, /.stories.js$/);
8+
9+
↓ ↓ ↓ ↓ ↓ ↓
10+
11+
\\"use strict\\";
12+
13+
require('require-context.macro/context')(__dirname, '../src/components', true, /.stories.js$/);
14+
"
15+
`;
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pluginTester from 'babel-plugin-tester';
2+
import plugin from 'babel-plugin-macros';
3+
4+
pluginTester({
5+
plugin,
6+
snapshot: true,
7+
babelOptions: { filename: __filename },
8+
tests: [
9+
`
10+
import requireContext from '../require-context.macro';
11+
12+
requireContext('../src/components', true, /\.stories\.js$/);
13+
`,
14+
],
15+
});

macro/context.js context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ function context(basedir, directory, useSubdirectories = false, regExp = /^\.\//
3434
return requireContext;
3535
}
3636

37-
module.exports = context;
37+
module.exports = { context };

index.js

-1
This file was deleted.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "require-context.macro",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A Babel Macro for the require-context plugin",
5-
"main": "macro/index.js",
5+
"main": "require-context.macro.js",
66
"scripts": {
77
"test": "jest"
88
},

macro/index.js require-context.macro.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const { createMacro } = require('babel-plugin-macros');
22

3-
module.exports = createMacro(requireContextMacro);
4-
53
// Credit https://github.com/smrq/babel-plugin-require-context-hook
6-
function requireContextMacro({ references, state, babel: { types: t } }) {
4+
function requireContext({ references, state, babel: { types: t } }) {
75
if (process.env.NODE_ENV === 'test') {
86
references.default.forEach(path =>
97
path.parentPath.replaceWith(
10-
t.callExpression(t.identifier("require('require-context.macro/macro/context')"), [
8+
t.callExpression(t.identifier("require('require-context.macro/context')"), [
119
t.identifier('__dirname'),
1210
...path.parent.arguments,
1311
])
@@ -21,3 +19,5 @@ function requireContextMacro({ references, state, babel: { types: t } }) {
2119
);
2220
}
2321
}
22+
23+
module.exports = createMacro(requireContext);

require-context.macro.test.js

-17
This file was deleted.

0 commit comments

Comments
 (0)