-
Notifications
You must be signed in to change notification settings - Fork 604
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
[eslint-plugin] Proposal: "Packlets" model for lightweight package-like folders within a project #2254
Comments
❤️ |
sounds reasonable! tangential: curious about referencing packlets: is there something special about naming the entrypoint |
Sounds like a useful feature for staging library code without requiring the full NPM package overhead. |
Yes, import { ConsoleLogger } from "../packlets/logger"; instead of: import { ConsoleLogger } from "../packlets/logger/index"; |
Here's a PR: #2256 |
I should point out that resolution will, in general, be faster and more robust if you always reference |
Motivation
@bartvandenende-wm and @victor-wm came to our tools team with an cool idea for encouraging modularization of a large Rush project, without actually splitting the code into separate library projects. Why would we want to do that? In our scenario, creating a new Rush project brings some overhead:
Often you set out with only a rough idea of how new code should be organized. You want to experiment with it a bit before proposing a Rush project. We will probably make proper library packages later, but can we start with something more lightweight?
One idea is to simply organize the code into folders (
src/controls/
,src/styles/
, etc). But how do you clarify the public/private relationships? How do you prevent circular references?Proposed Design
Let's formalize the import relationships for these folders a bit. Then we can use ESLint to enforce the API contracts.
We're calling this formalization "packlets": They behave like NPM packages, but without the overhead of a real package.json file.
The lint rules and specification will go in a new NPM package
@rushstack/eslint-plugin-packlets
.It won't be tied specifically to Rush or Heft, though. The packlet system can be usefully adopted by any TypeScript project, even in a standalone Git repo. Just enable the ESLint rules.
5 rules for packlets
A "packlet" is defined to be a folder path
./src/packlets/<packlet-name>/index.ts
. The index.ts file will have the exported APIs. The<packlet-name>
name must follow NPM package naming rules (lower case words separated by hyphens).Example file paths:
Files outside the packlet folder can only import the packlet root index.ts:
src/example.ts
Files inside a packlet folder should import their siblings directly, not via their own index.ts (which might create a circular reference):
src/packlets/controls/CheckBox.ts
Packlets may reference other packlets, but NEVER in a way that would create a circular reference:
src/packlets/controls/Button.ts
src/packlets/logger/LogLevels.ts
Other source files are allowed outside the src/packlets folder. They may import a packlet, but packlets must only import from other packlets or NPM packages.
src/index.ts
src/packlets/controls/Button.ts
The text was updated successfully, but these errors were encountered: