-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Typescript type #3094
Typescript type #3094
Conversation
Great work! Out of curiosity, since I'm new to typescript: How do you run the tests? Is a simple compile enough? |
@marvinhagemeister You can read more about here. You run test with a simple compile. It there are no errors like this
then definition is ok 😄 |
@TheLarkInn @sokra can you please check out TODO's in the code and tell me what to insert there. |
@@ -0,0 +1,19 @@ | |||
/// <reference path="webpack.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.
aggressive
(typo in the file name)
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.
Fixed
045a284
to
386fe25
Compare
@gajus can you also assist here. |
/* | ||
Set the value of `require.amd` and `define.amd`. | ||
*/ | ||
amd?: any; // TODO missing type |
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.
- Might change the comment on properties to JSDoc style. This enable better tooltip in editor. For exmaple
/**
*Set the value of `require.amd` and `define.amd`.
*/
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.
Good suggestion, changed.
/* | ||
Set the value of `require.amd` and `define.amd`. | ||
*/ | ||
amd?: any; // TODO missing type |
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.
amd?: "require.amd" | "define.amd"
;
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.
Added.
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.
@zhaoshengjun I am not so sure about these two strings anymore. If you checkout documentation you can see there is an object example.
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.
@TheLarkInn can you please clarify this property. Should be string literal here or object of some kind?
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.
Starting tracing the use of the config value from here: https://github.com/webpack/webpack/blob/master/lib/WebpackOptionsApply.js#L248
To:
https://github.com/webpack/webpack/blob/master/lib/dependencies/AMDPlugin.js#L92-L100
It appears that the default is an empty Object, and that it is {[key: string]: boolean}
if values are added. The key seems to represent the npm module/library name.
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.
Fixed
onlyModule?: boolean; | ||
} | ||
|
||
type EntryItem = string | string[]; |
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.
If the type is only used in one place, I would suggest to do them inline. It's also for better editor tooltips.
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.
It's not used only in one placed, that's why I added it to type.
entry: WebpackType.EntryItem | {[key: string]: WebpackType.EntryItem};
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.
My fault, pointed to the wrong line.
I mean for OutputLibraryTarget
, Stats
and Target
.
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.
Personally I prefer to have this long list of enums in separate variable, so it's a lot more readable for me.
Boolean: You can pass `false` to disable it. | ||
Object: You can pass an object to enable it and let webpack use the passed object as cache.This way you can share the cache object between multiple compiler calls. | ||
*/ | ||
cache?: (boolean | Object); |
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.
Suggest to add an Object interface. Reason is the current definition will let cache = "true"
pass, which should not.
interface Object {
[key: string]: any;
}
After adding this, the above statement will cause error.
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.
You are correct. Fixed
386fe25
to
ebf2008
Compare
Awesome work! |
I finished with this task, so I am just waiting for you guys to fill out the blanks (where is TODO) and check if everything is in order. I will remove WIP tag from the title. |
__filename?: boolean | "mock"; | ||
console?: boolean; | ||
global?: boolean; | ||
process?: boolean |
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.
Buffer
, console
and process
can also be "mock"
or "empty"
.
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.
In scheme.json which is a base line for this PR it's says only boolean.
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.
It's fixed now.
libraryTarget?: OutputLibraryTarget; | ||
|
||
// The output directory as **absolute path** (required). | ||
path?: string; |
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.
If it is required, it should not have a ?
.
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.
For now let's say it's required.
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.
@TheLarkInn Please clarify this, because I see a lot of examples where path is not in configuration of output, but in documentation it says to be required.
root?: string; | ||
} | ||
|
||
interface OutputDevtoolLineToLine { |
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.
Would be nice if this (and everything else using test/include/exclude) would work like a RuleSetConditionObject
, but that's outside this scope
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.
I am not sure what you mean by that
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.
They both have include
, exclude
and test
keys, but they don't necessarily seem to work the same. Would be nice if both the implementation and the object format were the same.
| "node" | ||
| "async-node" | ||
| "node-webkit" | ||
| "electron"; |
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.
"atom"
/ "electron-main"
are (possibly?) aliases to "electron"
. There is also a separate "electron-renderer"
target.
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 described here there are only these. Same is defined in the scheme.json
.
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.
I checked the source code itself; looks like an omission in the docs and scheme.json
.
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.
Let's create an issue for this for the JSON Schema so that once we fix it there, we fix it in both places.
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.
Will do and create PR for schema
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.
Created PR for it.
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.
Done and added to the definition.
* A developer tool to enhance debugging. | ||
* Note: Boolean can be used only with value `false`. | ||
*/ | ||
devtool?: string | boolean; |
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.
Would string | false
work, or are constants in types only allowed for strings?
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.
Sadly no.
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.
@mhegazy @DanielRosenwasser is there a better solution for this that you can think of?
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.
string | false
should be possible in TS 2.0
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.
Thank you @DanielRosenwasser for update, I was relaying to much on IDE-a for checking correction of definition. Added.
@sokra In documentation there is |
ebf2008
to
c082fd7
Compare
I would say we conform exactly with the JSON Validation Schema. If we need to change this, we'll need to change it in both places. I want to keep these things in sync as much as possible. |
Can these typings be added to the package.json? |
@ianks yes definitely. @NejcZdovc @zhaoshengjun add a new field called Here's an example PR of someone doing it. jeffbcross/angularfire2@b3a5a3a |
@TheLarkInn first I wanted to confirm location of definition file before adding it into package.json. So is the location correct or should we move it? |
@DanielRosenwasser is there any general recommendation in placement for type definitions files in a package, that would contradict where we are creating it now in this PR. |
In my opinion, the "schema" type should just be exposed as part of the webpack library import webpack = require("webpack");
let config: webpack.WebpackConfiguration = {
// ...
};
export = config; |
@DanielRosenwasser I am curious why not add it to DT, import it as AFAIK this is the only |
I think overall in the future if we transition this project to Typescript then each plugin technically will have a type. But for now we do not. I don't know if that answers the question for you. |
#3112 had been merged so you can update accordingly |
1a6a4e7
to
57ac4e0
Compare
Updated accordingly of the #3112 |
57ac4e0
to
4e700c8
Compare
stats?: WebpackType.Object | boolean | WebpackType.Stats; | ||
|
||
/** | ||
* TODO add description |
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.
You could use something like this. I don't have good wording ideas for the second sentence, but essentially trying to capture what happens here
Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target. Can also expose extra global variables into the webpack module scope (required for specific targets (IE:
electron
))
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.
Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target. Can also use predefined bootstrap functions based on targets such as
electron
,atom
, etc.
What about something like that?
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.
They are all predefined. So maybe that part is unnecessary (unless I'm misunderstanding).
I think:
Specifies webpack deployment target. This modifies how the webpack bootstrap function is generated based on each target.
Should be fine.
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 understand this is that you can specify string (predefined function as electron
) or you can specify completely custom function, which is called here.
That's why we have: target?: Function | WebpackType.Target;
This is the reason why I formatted my sentence like this.
4e700c8
to
f173a83
Compare
f173a83
to
04953b6
Compare
Ok, so AFAIK this is blocking merge of this PR
How can I help to resolve this two, so I can close this and go to another issue? @TheLarkInn @DanielRosenwasser |
type RuleSetRules = RuleSetRule[]; | ||
} | ||
|
||
interface Webpack { |
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.
This interface should be exported, no? Doesn't make much sense having a type definition otherwise.
Any plans to add matching flow type definitions? EDIT: Saw the linked issue, but will there be any process to keep them in sync in the future? If TS is a part of this repo, but flow is not. |
@NejcZdovc The most important CI builds failed. This way your PR can't be merged. Please take a look at the CI results from travis (error) and appveyor (failure) and fix these issues. |
old, controversal, there is typing in DT, closing |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior?
Does this PR introduce a breaking change?
If this PR contains a breaking change, please describe the following...
Other information:
This resolves issue #3045.