Open sergei-dyshel opened 2 weeks ago
This plugin doesn't differentiate between normal paths and package paths. From the perspective of the plugin you're trying to import from @sergei-dyshel/typescript/json
which I assume is the same as ../node/json
which is outside of the scope by default.
So you have the standard options:
..
in @sergei-dyshel/typescript/.scope.ts
)@sergei-dyshel/node
to import from the typescript
package.Please let me know if you feel this is not sufficient and a direct support for monorepo packages is required. I just think that the more scenarios can be resolved with generic solutions the better.
Hey Alex, thanks for quick response! Defining per-file or per-directory scopes is not appropriate, as I have many files/directories and imports from them. I'd like to use something like strictMode: false
from previous version. I tried putting .scope.ts
with export default "*"
in the root and src
folders in packages, but it didn't work. Any insights?
Would adding support for a new property inside the .scope.ts
files solve the problem?
// @/typescript/json/.scope.ts
export default '../..'; (or); export const exceptions = ['../../node']
export propagate = true;
// 👆 This would make even nested exports from `json` folder to be accessible from `@`
I just need to think about the performance of this solution and ergonomics.
/** @propagate */
export default '../..';;
export const exceptions = []
maybe this is better as it allows propagation of only some of the settings, but it introduces another annotation that only works in .scope.ts
files.
Why is new property needed? Isn't there an existing way to mark all exports in the package as importable for everyone?
.scope.ts
files only change the scope of exports declared in that folder. Any nested folders will have their own scopes and will ignore all parent .scope.ts
files.
So with this new property, you would be able to make everything under @sergei-dyshel/typescript
(including subdirs, that's what you want, right?) accessible from @sergei-dyshel/node
without making '*' the default scope for every single export in the project (which provides less safety).
Am I missing something?
Hmm, I supposed that .scope.ts
put in the root folder would achieve that. According to README:
Root .scope.ts file (next to package.json) sets the default for the whole project. Having export default '*' there will make all exports global by default if you prefer a less strict approach.
Or does it mean that exports will be visible to that package only, but not to other packages? If so, you need to change that behaviour because export visibility between packages should be controlled by package.json
only and not affected by the plugin.
It looks like I missed a test for this feature and it doesn't work in v2. Saying that I'm not sure I want it to work this way as:
.scope.ts
apply only to the current directory everywhere in the project apart from the root folder is inconsistent and might be confusing.A more granular solution that allows relaxing the scope only for some subdirs might be better.
const propagate = true;
// .scope.ts
export default '';
export const exceptions = [...]
export propagate = true; // 👈 this would change the scope for all subfolders in addition to the current folder
A problem: if the scope can be inherited from any of the parent .scope.ts
files, keeping track of the current scope might be harder for devs.
.children.scope.ts
Having a separate file for setting a new default scope for children might make it easier to keep track of the current scope.
// .children.scope.ts
export default '';
export const exceptions = [...]
What do you think?
I vote for propagate
option because using separate file for children seems overkill....
TBH I don't understand why you went with .scope.ts
files in the first place instead of plain JSON files (with defined schema).
Thank you for the feedback!
The JSON file would have to be manually updated every time folders/files are moved within the project which would make refactoring very annoying. .scope.ts
files are relative, so they can easily move with the folder.
I have an NPM workspace with multiple packages, say
@sergei-dyshel/typescript
and@sergei-dyshel/node
. I see that ESlint plugin triggers warning:while this symbol is imported from second package: