novemberborn / babel-plugin-import-glob Goto Github PK
View Code? Open in Web Editor NEWBabel plugin to enable importing modules using a glob pattern
License: ISC License
Babel plugin to enable importing modules using a glob pattern
License: ISC License
I need to convert the following into the appropriate syntax
if (module && module.hot)
module.hot.accept('./reducers', () =>
store.replaceReducer(nextRootReducer = require('./reducers').default)
);
nothing i've tried has worked so far
We have a need to import all files in a folder that exist in a child installed node module.
We expect this...
import intlMessages from '@scopeName/packageName/intl/*.json';
...to resolve to here...
currentWorkingDirectory/node_modules/@scopeName/packageName/intl/*.json
...but instead, it tries to resolve to here...
currentWorkingDirectory/sourceFilePath/@scopeName/packageName/intl/*.json
...which of course breaks because the path doesn't exist.
One simple fix might be to do the following in index.js
...
let files = glob.sync(pattern, {strict: true, nodir: true});
if (files.length === 0) {
pattern = 'node_modules/' + path.node.source.value;
files = glob.sync(pattern, {strict: true, nodir: true});
}
I've tested this locally and it appears to work against relative paths, regular node module paths, and scoped npm package paths.
Thanks!
@jhicken Thanks for the help digging into this issue!
Hey everyone,
I needed some new features from this repo and since it seems to have stagnated, I have taken the existing code and done a complete simplification/refactor as well as added those features I needed. You can check it out here:
#35
i can't found fix "import/no-extraneous-dependencies"
I need your help
but can fix "no-unresolved"
// file: '.eslintrc'
// fix: no-unresolved
{
"extends": "airbnb",
"rules": {
"import/no-unresolved": [
"error",
{
"ignore": [
"^glob:"
]
}
]
}
}
Love this plugin! Would be great to allow export
syntax. Eg:
export { foo, bar } from 'glob:*';
Awesome module but I'm having a bit of trouble getting it working. I was using glob before like this:
const files = glob.sync(
./dist/api/**/*[Controller].js);
and I converted it to your code like:
import * as filesz from 'glob:./dist/api/**/*[Controller].js';
but the result is this from the console:
info: import globs {}
info: globs [ './dist/api/ApplicationController.js',
'./dist/api/RecordController.js',
'./dist/api/SearchController.js' ]
Your exports are pretty specific to your use case, I think it could benefit from making it more generic. Also you don't really explain the difference between what 'main' and '_partial' is. Is partial the 'resolved' file? If so I'd recommend making a separate extension for that.
also would be cool to see integration with this: https://github.com/tleunen/babel-plugin-module-alias
Plugins like https://github.com/novemberborn/babel-plugin-files also support glob patterns in the import paths. import-glob
picks up those import statements. We should have an option to disable the automatic glob detection, and require the glob:
prefix.
Hi, thanks for the really helpful plugin.
i cannot however import named exports from a module file. The plugin only imports the default export.
example:
//cool.module.js
export const awesome = 'yay'
export default 'not so yay'
//index.js
import { awesome } from './**/*.module.js'
//Syntax error: Could not match import 'watchers' to a module. Available members are 'cool'
this would import the default import:
//index.js
import * as default from './**/*.module.js'
//default === 'not so yay'
For some reason, when I add a new file in my folder (note that it is inside a node_modules folder), on rebuild it's not detected. For some reason I need to change the glob (for instance switch between
whatever/* and whatever/*.js).
So is there some sort of cache in your implementation that could cause that?
The bug happens with webpack and babel on my project. I don't really have time to create a standalone reproduce of the bug, but I just like to understand what might be causing it.
Branch | Build failing π¨ |
---|---|
Dependency | codecov |
Current Version | 2.2.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As codecov is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
The new version differs by 6 commits.
7e39f19
v2.3.0
489ec49
Adding AppVeyor badge
8e31537
Coverage upload on Windows - fixes #61 (#62)
12a5193
Update package.json (#67)
2e40593
Update README.md
d2a021d
Update README.md
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
Hi
My file structure is as following:
src
|- root.js
|- components
|- foo.js
|- bar.js
|- baz
|- baz.js
|- baz.css
In root.js
I use the following import:
import * as Components from "./components/**/*.js";
which partially works, as Components
only contains baz.js
.
I would expect foo.js
and bar.js
to also be imported.
It looks like this plugin strips a "common prefix" and "common extension". This works well if your file naming conventions use .
for a common suffix, such as in your example .handlebars.js
. However, if you prefer to use -
or _
instead, you end up with the common bit in the identifier.
It looks like this project uses two custom dependencies:
"common-extname": "^1.0.0",
"common-path-prefix": "^1.0.0",
So changing this becomes a bit tricky. Do I need to add a third common-path-suffix
repo?
I think a common suffix would probably be more helpful, as the common suffix will likely be in the pattern anyway. Of course there could be a configuration option to toggle the behavior.
message: ''glob:routes' should be listed in the project's dependencies. Run 'npm i -S glob:routes' to add it (import/no-extraneous-dependencies)'at: '2,1' source: 'eslint'
I would like to be able to exclude .test.js files
I've tried the following:
https://stackoverflow.com/questions/26639236/node-glob-pattern-for-every-js-file-except-spec-js
https://stackoverflow.com/questions/35415301/make-babel-exclude-test-files?rq=1
But couldn't get either to work, any ideas?
So on windows the importing looks like this if i have the following directory structure:
- source/
- app/
-controllers/
- a.js
- b.js
- c.js
import * as whatever from "app/**/*.js";
I receive an object that looks like this:
controllersa, controllersb, contorllersc ...
however on linux the output is
controllers$a, controllers$b, controllers$c, ...
I am not sure what is the reason behind this, but is there a way with your plugin to have the import mappings work such as
whatever.controllers.a
whatever.controllers.b
whatever.controllers.c
or something similar?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.