Skip to content
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

feat: add support for negative patterns #261

Merged
merged 11 commits into from
Dec 20, 2022
Merged

feat: add support for negative patterns #261

merged 11 commits into from
Dec 20, 2022

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Dec 16, 2022

Part of https://github.com/netlify/pillar-runtime/issues/615

This PR adds bundling support for negative patterns. Besides path and pattern, it adds excludedPath and excludedPattern, which will be interpreted similar to negative lookaheads by the runtime.

I intentionally de-scoped ISC and TOML-defined excludePatterns, given that Frameworks use the deploy config API. We can deliver them later, once Frameworks Pod is happy with this :)

}

type DeclarationWithPattern = BaseDeclaration & {
pattern: string
excludePattern?: string
Copy link
Member Author

@Skn0tt Skn0tt Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this will be the name of the field in the toml as well. from the docs, it looks like we're using camelCase there, but we should verify that before merging this.

@Skn0tt
Copy link
Member Author

Skn0tt commented Dec 16, 2022

ISC implementation is missing, and there's no obvious design for that. could be descoped for now until we come up with a design, as this already has support for toml-based + deploy config-based exclude patterns. For TOML-based config, we're still missing a PR to netlify/build though.

@Skn0tt Skn0tt marked this pull request as ready for review December 19, 2022 09:52
@Skn0tt Skn0tt requested a review from a team December 19, 2022 09:52
@Skn0tt Skn0tt added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Dec 19, 2022
@Skn0tt Skn0tt self-assigned this Dec 19, 2022
@@ -9,14 +9,19 @@ interface BaseDeclaration {

type DeclarationWithPath = BaseDeclaration & {
path: string
excludePath?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing properties are nouns and "exclude path" is a verbal form. I wonder if we could use excludedPath or negativePath instead? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 775a0da.

}

type Declaration = DeclarationWithPath | DeclarationWithPattern

const isDeclarationWithPattern = (declaration: Declaration): declaration is DeclarationWithPattern =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some context on why we need this additional function, as opposed to asking consumers to do the 'pattern' in declaration assertion themselves? They're already aware of the pattern property since they're using it, so I'm not sure I get the value of this layer of abstraction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration is DeclarationWithPattern return type informs Typescript about the type of declaration, which the previous didn't do (at least VSCode made it look like that). Happy to revert though!

Copy link
Member Author

@Skn0tt Skn0tt Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at it again, it seems like it did work 🤔 reverted in 889dc37.

node/manifest.test.ts Outdated Show resolved Hide resolved
node/manifest.ts Outdated
return pathToRegularExpression(declaration.path)
}

const getExcludeRegularExpression = (declaration: Declaration) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these branches a little bit confusing. I wonder if this would bit a bit easier to parse?

if (isDeclarationWithPattern(declaration) && declaration.excludePattern) {
  return new RegExp(declaration.excludePattern)
}

if ('excludePath' in declaration) {
  return pathToRegularExpression(declaration.excludePath)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. addressed through 3c6f835 and 889dc37!

Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kodiakhq kodiakhq bot merged commit 646631a into main Dec 20, 2022
@kodiakhq kodiakhq bot deleted the exclude-pattern branch December 20, 2022 11:56
Skn0tt added a commit to netlify/build that referenced this pull request Apr 23, 2024
* feat: update generateManifest to support excluded paths / patterns

* fix: ensure excludePath in deploy config is respected

* fix: test

* test: toml-defined declarations are respected

* fix: prettier

* Update node/manifest.test.ts

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* refactor: exclude -> excluded

* refactor: address eduardo's conditionals feedback

* refactor: revert type guard

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants