-
Notifications
You must be signed in to change notification settings - Fork 11
Content Addressable Hashes #1
Comments
For my own education,
declare module 'X' {
export * from '../.store/klou3f3u34u982r04jdf.d.ts'
} where {
"files": {
"X": "<path to X definition (e.g. main.d.ts)>"
}
} or {
"files": [
"<path to somename.d.ts>"
]
} where |
Where |
Ar, of course. It's External Module. :P The question is we need some anchor point to determine the relative path. e.g. in the final "ambient" version (where declare module 'core-js' {
export * from '<X>';
}
declare module 'core-js/fn/array' {
export * from '<Y>';
} The {
files: {
"main": "X",
"main/fn/array": "Y",
"browser": "X",
"browser/fn/array": "Y"
}
} UPDATE: where |
Another solution, {
"main": {
"core-js": "X",
"./fn/array": "Y"
},
"browser": {
// if user should not get the module through main entry point due to impractical file size.
"core-js": false,
"./fn/array": "browser-Y"
}
} |
I might be missing something, but what are you trying to solve with this proposal? The relative names will always come from the filename relative to Aside from that, I didn't understand the "UPDATE". I don't ever want someone to actually reference the hashed files themselves, it's just an approach to fix some of the issues I'm seeing in the current Typings release. |
Sorry, may be my English is not doing me much good. 😏 What I tried to describe is a proposal on:
Let me try it again with an example. + --- main.d.ts
+ --- main.fn.array.d.ts
+ --- browser.fn.array.d.ts
+ --- typings.json While normally In the {
"main": {
"core-js": "main.d.ts",
"./fn/array": "main.fn.array.d.ts"
},
"browser": {
// if user should not get the module through main entry point due to impractical file size.
"core-js": false,
"./fn/array": "browser.fn.array.d.ts"
}
} In
declare module 'core' {
export * from '../.store/hashA.d.ts';
}
declare module 'core/fn/array' {
export * from '../.store/hashB.d.ts';
}
declare module 'core/fn/array' {
export * from '../.store/hashC.d.ts';
} Hope it is better this time. 😏 |
@unional To be honest, I don't think it's a useful change and will restrict use in the future. Is there a valuable reason you can't replicate the file structure? I'm not convinced it's a problem that needs solving. Edit: Just image having to maintain this with every feature going forward. Is this an override field? How does it integrate with other filesystem fields? What does main/browser point to? The original or the mapped value? Why does browser map from nice filename to real file instead of nice file to nice file or real file to real file? |
Are you referring to this?
I don't see it as override field, unless you mean the If we solely rely on the folder structure, how would the folder structure and |
@unional It's how it already works though? E.g. https://github.com/typings/typed-es6-promise the main typing is in |
Ok, I'm going to change this issue to be about content addressable hashes and make a new issue roadmap for 0.7 (or 0.8, etc). |
Um......still not seeing it. Sorry. 😢 using the + browser
+ fn
+ array.d.ts
+ main
+ fn
+ array.d.ts
+ main.d.ts and {
"main": [
"main.d.ts",
"main/fn/array.d.ts"
],
"browser": [
"browser/fn/array.d.ts"
]
} Or it's something else? |
In that case how to we describe "in browser the core (main.d.ts) is not available"? |
It currently works. Using your example above, I'll refactor to the proposed model (which doesn't actually relate to the original discussion anymore). {
"main": "main.d.ts",
"files": [
"main/fn/array.d.ts"
],
"browser": {
"main/fn/array.d.ts": "browser/fn/array.d.ts"
}
} Main will never be multiple aliases - you can't have two "main" files on import. |
Do you mean {
"main": "main.d.ts", // <-----
"files": [
"main/fn/array.d.ts"
],
"browser": {
"main.d.ts": false,
"main/fn/array.d.ts": "browser/fn/array.d.ts"
}
} |
I thought |
Yes, typo. Updated.
But they are aliases of multiple files with a single "main" entry. E.g. you have a bunch of |
I think I start getting what you mean. It a misconception on my side (as it should be 😏). When I think about multiple sub-path entry, I also think of them as isolated, as they are loaded separately from other part of the module. A better example would be UI library such as Since they are huge, and most application do not use every widget provided, the application will reference and load only the widget they use, e.g. So I always think the typed file should do the same. i.e. declare module 'material-ui/lib/grid' { export * from './lib/grid.d.ts' }
declare module 'material-ui/lib/checkbox' { export * from './lib/checkbox.d.ts' } However, it is a typed file so it does not need to do that. It can be (syntax likely not correct): declare module 'material-ui' {
declare module 'lib' {
export * from './lib/grid.d.ts' // export function grid() {...}
export * from './lib/checkbox.d.ts' // export function checkbox() {...}
}
} Simply because there is no taxing on loading (at least in |
Do you have plan on when this will go in? It's definitely a great idea. Currently we still have module name pollution: declare module 'assertion-error/main' { ... }
declare module 'assertion-error' {
export * from 'assertion-error/main';
} // consuming.ts
import {Assertion} from 'assertion-error';
import {Assertion} from 'assertion-error/main'; // pollution 😏 |
@unional I don't quite follow. The top level declarations are entirely intentional. You don't want them? |
It should be mirroring the actual module: https://github.com/chaijs/assertion-error/blob/master/package.json#L19. The idea is to expose the interfaces realistically and allowed "deep requires" - however frowned upon sometimes. |
Ar, I mean the second one. declare module 'chai~assertion-error/main' { ... } |
I see, so at least for the import {Assertion} from 'assertion-error/main`; I thought import abc = require('assertion-error/a/b/c/d/abc`);
// resolves to `node-modules/assertion-error/a/b/c/d/abc` |
Your first comment: declare module 'X' {
export * from '../.store/klou3f3u34u982r04jdf.d.ts'
} completely avoid this issue because there are no extra |
Oh, yeah. Sadly, there'll always be pollution until things are native in TypeScript. However, did you see #26? I still have a bit more work now thinking about it, but it's creating an extra name that'll be harder to run into. The |
You can do |
Um... in That's why I thought the syntax used here can avoid pollution. |
Doesn't the |
I still think the pollution is avoidable. Let me try it out first. |
Seems like the issue about Now all the extra Likely you have already fix it somehow. 🌹 |
Gone? Since when? I'm yet to merge all this new stuff, have to refactor the CLI in |
Probably sometime between |
Does it mean that |
Ideally, yes. It would be nice, but not required - not many people "deep require". On the failure, I don't think much changed between those versions except for supporting TS 1.8 module augmentation - is that related? |
Not sure, or may even because of TS upgrade from Will file issue if similar things pop up so I have a concrete case to present (instead of relying on memory, which can easily be corrupted. 😛 ) |
As I understand, this is blocked because we can't: declare namespace abc {
import main = require('~abc');
export = main; or something similar. Is there an issue opened on https://github.com/Microsoft/TypeScript can be referenced and tracked here? |
It can technically still be done using the name hacks we currently do, but I'd like to remove all the tilde hacks and use this instead. It's not tracked, I figure it's a feature limitation they have on purpose. |
Perhaps I should look around and open an issue just in case anyway? |
Yeah, because that means almost all typings need to be written twice. One for module one for script tag. |
Can you elaborate? This should not change anything behaviour-wise. |
Um......actually I don't get this part.... |
e.g. https://github.com/typed-contrib/knockout |
We can go This won't fix your ambient/non-ambient change. The only tweak I'd like to have is re-exporting from an external module in an ambient declaration. |
ar..I see. |
Created: typings/typings#402 |
I'm making this issue here because things may change and I don't want to notify a lot of people ahead of time with my thoughts.
Goals:
The idea:
Content addressable hashes. For the next version I'd really like to fix de-duping and re-writing of dependencies which causes issues on import still. I realised one way to solve all of the above is to use content hashes as the file names and just write wrappers to the content hashed
.d.ts
files. The structure will look more like:The stored content hashed files will be per-typed file and the nature of hashes will avoid duplicated dependencies. No more rewriting typings other than
import
/export
still, and writing a wrapper separately. This is a pretty big architectural change though, so I'll be working on it incore
first.The text was updated successfully, but these errors were encountered: