♻️ Guard dependencies in src/{context,core,preact}#33016
♻️ Guard dependencies in src/{context,core,preact}#33016rcebulko merged 16 commits intoampproject:masterfrom
src/{context,core,preact}#33016Conversation
|
Hey @jridgewell! These files were changed: |
| // Disallow importing AMP dependencies into core | ||
| 'target': 'src/core', | ||
| 'from': 'src', | ||
| 'except': ['./core'], |
There was a problem hiding this comment.
Paths for target and from are absolute; paths in except are relative to the from path. Weird, I know.
| 'error', | ||
| { | ||
| // Disallow importing dependencies from outside this directory | ||
| 'patterns': ['..'], |
There was a problem hiding this comment.
This did not work as desired with subfolders
src/.eslintrc.js
Outdated
| './context/scheduler.js', | ||
| './context/values.js', | ||
| ], | ||
| 'rules': {'import/no-restricted-paths': 1}, |
There was a problem hiding this comment.
Plan: Warning for now; once exclusions are migrated, everything errors.
src/preact/context.js
Outdated
|
|
||
| import * as Preact from './index'; | ||
| import {Loading, reducer as loadingReducer} from '../loading'; | ||
| import {Loading, reducer as loadingReducer} from './loading-instructions'; |
There was a problem hiding this comment.
This removes the only restricted dependency, so this file was removed from the allowlist
| */ | ||
|
|
||
| import {Loading, reducer as loadingReducer} from '../loading'; | ||
| import {Loading, reducer as loadingReducer} from './loading-instructions'; |
There was a problem hiding this comment.
This removes the only restricted dependency, so this file was removed from the allowlist
There was a problem hiding this comment.
Can we instead whitelist src/context and src/contextprops? Or move them to src/pure? They have been intentionally constructed as "pure". There might be some dependencies there now that have crept in, but I do think we can and should be "pure".
src/preact/slot.js
Outdated
| import {CanPlay, CanRender, LoadingProp} from '../contextprops'; | ||
| import {dev} from '../log'; | ||
| import {CanPlay, CanRender, LoadingProp} from './contextprops'; | ||
| import {devAssert} from '../core/assert'; |
There was a problem hiding this comment.
These removes the only restricted dependencies, so this file was removed from the allowlist.
| @@ -14,7 +14,7 @@ | |||
| * limitations under the License. | |||
| */ | |||
|
|
|||
| import {Loading, reducer as loadingReducer} from '../loading'; | |||
There was a problem hiding this comment.
I think these actually belong in src/core? They're meant to be used by both Bento and regular Components?
/cc @dvoytenko
There was a problem hiding this comment.
AFAICT is file is not imported anywhere else in the repo except the files in this PR
| */ | ||
|
|
||
| import {Loading, reducer as loadingReducer} from '../loading'; | ||
| import {Loading, reducer as loadingReducer} from './loading-instructions'; |
There was a problem hiding this comment.
Can we instead whitelist src/context and src/contextprops? Or move them to src/pure? They have been intentionally constructed as "pure". There might be some dependencies there now that have crept in, but I do think we can and should be "pure".
build-system/tasks/lint.js
Outdated
| ); | ||
| } | ||
| process.exitCode = 1; | ||
| process.exitCode = errorCount || !isCiBuild() ? 1 : 0; |
There was a problem hiding this comment.
Can you explain this change?
There was a problem hiding this comment.
Errors should always fail the build
Warnings (such as for the allowlisted imports) should not fail the build on CI
Chatted offline with @rsimha , looping in for approval on this file
There was a problem hiding this comment.
I didn't mean for this change to be made to lint.js. We want to continue failing CI builds when there are warnings.
Instead, you can change line 63 in src/.eslintrc.js as follows:
'rules': {'import/no-restricted-paths': isCiBuild() ? 0 : 1},This will let you see warnings within src when you're doing local development, but not let those warnings show up during CI. Meanwhile, PRs that introduce unaccounted for warnings in other directories will be flagged during CI.
There was a problem hiding this comment.
That makes sense; will do
There was a problem hiding this comment.
Necromancing this conversation thread for a moment. With this configuration, branches touching any files with warnings get picked up as build targets, and lint emits warnings which in turn fails the task with a non-zero exit code. This means during local development, amp pr-check gets held up by the warnings and can't be useful on these branches. @rsimha do you have any suggestions to work around this? I'd like warnings to be displayed without failing the whole set of checks if possible. Could warnings not fail lint on non-CI builds? I don't see any lint rules that are warnings currently
Addressed comments; approval from Justin
This PR:
import/no-restricted-pathseslint rulesrc/corefrom importing outside of itselfsrc/preactfrom importing outside of itself,src/core, orsrc/contextsrc/contextfrom importing outside of itself orsrc/coresrc/loading,src/contextprops) intosrc/preactsrc/preactandsrc/contextto use new helpersRemaining excluded files generate linter warnings:
