-
Notifications
You must be signed in to change notification settings - Fork 203
feat(root): add glob support #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| "import" | ||
| ], | ||
| "dependencies": { | ||
| "glob": "^7.0.6", | ||
| "resolve": "^1.1.7" | ||
| }, | ||
| "devDependencies": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,27 @@ | ||
| /* eslint-env mocha */ | ||
| /* eslint-disable prefer-arrow-callback */ | ||
| /* eslint-disable func-names */ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you just name the anonym fn with "test" instead? You should be able to remove these 2 eslint rules after that
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still would warn me Also I'd need to give the upper scope functions ( |
||
| import assert from 'assert'; | ||
| import { transform } from 'babel-core'; // eslint-disable-line import/no-extraneous-dependencies | ||
| import plugin from '../src'; | ||
|
|
||
| function testRequireImport(source, output, transformerOpts) { | ||
| it('with a require statement', () => { | ||
| it('with a require statement', function () { | ||
| const code = `var something = require("${source}");`; | ||
| const result = transform(code, transformerOpts); | ||
|
|
||
| assert.strictEqual(result.code, `var something = require("${output}");`); | ||
| }); | ||
|
|
||
| it('with an import statement', () => { | ||
| it('with an import statement', function () { | ||
| const code = `import something from "${source}";`; | ||
| const result = transform(code, transformerOpts); | ||
|
|
||
| assert.strictEqual(result.code, `import something from "${output}";`); | ||
| }); | ||
| } | ||
|
|
||
| describe('root', () => { | ||
| describe('root', function () { | ||
| const transformerOpts = { | ||
| plugins: [ | ||
| [plugin, { | ||
|
|
@@ -28,48 +30,64 @@ describe('root', () => { | |
| ] | ||
| }; | ||
|
|
||
| describe('should rewrite the file path inside a root directory', () => { | ||
| const transformerOptsGlob = { | ||
| plugins: [ | ||
| [plugin, { | ||
| root: ['./test/**/components'] | ||
| }] | ||
| ] | ||
| }; | ||
|
|
||
| describe('should rewrite the file path inside a root directory', function () { | ||
| testRequireImport( | ||
| 'c1', | ||
| './test/examples/components/c1', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should rewrite the sub file path inside a root directory', () => { | ||
| describe('should rewrite the sub file path inside a root directory', function () { | ||
| testRequireImport( | ||
| 'sub/sub1', | ||
| './test/examples/components/sub/sub1', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should rewrite the file while keeping the extension', () => { | ||
| describe('should rewrite the file while keeping the extension', function () { | ||
| testRequireImport( | ||
| 'sub/sub1.css', | ||
| './test/examples/components/sub/sub1.css', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should rewrite the file with a filename containing a dot', () => { | ||
| describe('should rewrite the file with a filename containing a dot', function () { | ||
| testRequireImport( | ||
| 'sub/custom.modernizr3', | ||
| './test/examples/components/sub/custom.modernizr3', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should not rewrite a path outisde of the root directory', () => { | ||
| describe('should not rewrite a path outisde of the root directory', function () { | ||
| testRequireImport( | ||
| 'example-file', | ||
| 'example-file', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should rewrite the file path inside a root directory according to glob', function () { | ||
| testRequireImport( | ||
| 'c1', | ||
| './test/examples/components/c1', | ||
| transformerOptsGlob | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('alias', () => { | ||
| describe('alias', function () { | ||
| const transformerOpts = { | ||
| plugins: [ | ||
| [plugin, { | ||
|
|
@@ -83,17 +101,17 @@ describe('alias', () => { | |
| ] | ||
| }; | ||
|
|
||
| describe('should alias a known path', () => { | ||
| describe('using a simple exposed name', () => { | ||
| describe('when requiring the exact name', () => { | ||
| describe('should alias a known path', function () { | ||
| describe('using a simple exposed name', function () { | ||
| describe('when requiring the exact name', function () { | ||
| testRequireImport( | ||
| 'utils', | ||
| './src/mylib/subfolder/utils', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('when requiring a sub file of the exposed name', () => { | ||
| describe('when requiring a sub file of the exposed name', function () { | ||
| testRequireImport( | ||
| 'utils/my-util-file', | ||
| './src/mylib/subfolder/utils/my-util-file', | ||
|
|
@@ -102,16 +120,16 @@ describe('alias', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('using a "complex" exposed name', () => { | ||
| describe('when requiring the exact name', () => { | ||
| describe('using a "complex" exposed name', function () { | ||
| describe('when requiring the exact name', function () { | ||
| testRequireImport( | ||
| 'awesome/components', | ||
| './src/components', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('when requiring a sub file of the exposed name', () => { | ||
| describe('when requiring a sub file of the exposed name', function () { | ||
| testRequireImport( | ||
| 'awesome/components/my-comp', | ||
| './src/components/my-comp', | ||
|
|
@@ -120,7 +138,7 @@ describe('alias', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('with a dot in the filename', () => { | ||
| describe('with a dot in the filename', function () { | ||
| testRequireImport( | ||
| 'utils/custom.modernizr3', | ||
| './src/mylib/subfolder/utils/custom.modernizr3', | ||
|
|
@@ -129,24 +147,24 @@ describe('alias', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('should alias the path with its extension', () => { | ||
| describe('should alias the path with its extension', function () { | ||
| testRequireImport( | ||
| 'awesome/components/my-comp.css', | ||
| './src/components/my-comp.css', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should not alias a unknown path', () => { | ||
| describe('when requiring a node module', () => { | ||
| describe('should not alias a unknown path', function () { | ||
| describe('when requiring a node module', function () { | ||
| testRequireImport( | ||
| 'other-lib', | ||
| 'other-lib', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('when requiring a specific un-mapped file', () => { | ||
| describe('when requiring a specific un-mapped file', function () { | ||
| testRequireImport( | ||
| './l/otherLib', | ||
| './l/otherLib', | ||
|
|
@@ -155,15 +173,15 @@ describe('alias', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('(legacy) should support aliasing a node module with "npm:"', () => { | ||
| describe('(legacy) should support aliasing a node module with "npm:"', function () { | ||
| testRequireImport( | ||
| 'abstract/thing', | ||
| 'concrete/thing', | ||
| transformerOpts | ||
| ); | ||
| }); | ||
|
|
||
| describe('should support aliasing a node modules', () => { | ||
| describe('should support aliasing a node modules', function () { | ||
| testRequireImport( | ||
| 'underscore/map', | ||
| 'lodash/map', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting!
Is it executed once per execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know yes.