-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat: loader support custom extension #156
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7c202b2
feat: loader support custom extension
whxaxes 030e489
feat: remove require.extensions
whxaxes 49d967e
refactor: refactor to require.extensions
whxaxes e710e8c
test: add unittest for ts
whxaxes 1073043
chore: remove tsconfig.json
whxaxes b9795ca
test: add d.ts
whxaxes e718758
test: test loadCustomApp and loadCustomAgent
whxaxes c85b114
test: add more test for custom extend
whxaxes 88117fb
fix: spelling mistake
whxaxes 47635fc
feat: add typescript options
whxaxes 5dc16bd
docs: update typescript opt to docs
whxaxes 12307ec
chore: update comment
whxaxes 8ce0beb
test: add more unittest for ts
whxaxes 9b26274
refactor: code optimization
whxaxes c37fdb9
chore: update error msg
whxaxes 5363b4a
test: change beforeEach/afterEach to before/after
whxaxes 46dc810
feat: add ts check in loadFile
whxaxes 50d2d6e
feat: move resolveModule to egg_loader
whxaxes c51ae2d
fix: lint fix
whxaxes 8f2c5b3
refactor: code optimization
whxaxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ coverage | |
.logs | ||
npm-debug.log | ||
.vscode | ||
.DS_Store | ||
.DS_Store | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ const defaults = { | |
directory: null, | ||
target: null, | ||
match: undefined, | ||
typescript: false, | ||
ignore: undefined, | ||
lowercaseFirst: false, | ||
caseStyle: 'camel', | ||
|
@@ -37,6 +38,7 @@ class FileLoader { | |
* @param {String|Array} options.directory - directories to be loaded | ||
* @param {Object} options.target - attach the target object from loaded files | ||
* @param {String} options.match - match the files when load, support glob, default to all js files | ||
* @param {Boolean} options.typescript - whether support typescript, default to false | ||
* @param {String} options.ignore - ignore the files when load, support glob | ||
* @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` | ||
* @param {Boolean} options.call - determine whether invoke when exports is function | ||
|
@@ -48,6 +50,9 @@ class FileLoader { | |
constructor(options) { | ||
assert(options.directory, 'options.directory is required'); | ||
assert(options.target, 'options.target is required'); | ||
if (options.typescript) { | ||
assert(require.extensions['.ts'], '`require.extensions` should contains `.ts` while `options.typescript` was true'); | ||
} | ||
this.options = Object.assign({}, defaults, options); | ||
|
||
// compatible old options _lowercaseFirst_ | ||
|
@@ -120,8 +125,14 @@ class FileLoader { | |
* @since 1.0.0 | ||
*/ | ||
parse() { | ||
let files = this.options.match || [ '**/*.js' ]; | ||
files = Array.isArray(files) ? files : [ files ]; | ||
let files = this.options.match; | ||
if (!files) { | ||
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. 这里不能用原来的逻辑? 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. 如果用了 defaultMatch,就不需要再做 isArray 的判断了吧,因为就已经是 Array 了 |
||
files = this.options.typescript | ||
? [ '**/*.(js|ts)', '!**/*.d.ts' ] | ||
: [ '**/*.js' ]; | ||
} else { | ||
files = Array.isArray(files) ? files : [ files ]; | ||
} | ||
|
||
let ignore = this.options.ignore; | ||
if (ignore) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
egg 的 d.ts 有没有这个的,回头要顺便加下
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.
这个 typescript 会加载吧,不需要 loader 吧
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.
这个意思是?
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.
这个文件不需要我们去 require