-
Notifications
You must be signed in to change notification settings - Fork 15
fix(devtools): opt-in lambda.keepNestedNodeModules ships nested node_modules in Lambda packages #645
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
Merged
Merged
fix(devtools): opt-in lambda.keepNestedNodeModules ships nested node_modules in Lambda packages #645
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/devtools/infrastructure/domains/shared/utilities/nested-node-modules.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * Nested node_modules packaging patterns | ||
| * | ||
| * Utility Layer - Hexagonal Architecture | ||
| * | ||
| * npm nests a package only when the root copy cannot satisfy the dependant's | ||
| * range. Excluding every nested node_modules from a Lambda package therefore | ||
| * rewires module resolution to whatever is hoisted, and drops a package | ||
| * outright when the root copy is dev-only. Apps opt in to shipping the tree | ||
| * the way npm resolved it with `lambda.keepNestedNodeModules: true`. Nested | ||
| * copies of Frigg packages, the AWS SDK and Prisma stay excluded because the | ||
| * app's single core, the Lambda runtime and the Prisma layer provide them. | ||
| */ | ||
|
|
||
| const ALL_NESTED_NODE_MODULES = 'node_modules/**/node_modules/**'; | ||
|
|
||
| /** | ||
| * @param {Object} appDefinition | ||
| * @returns {boolean} | ||
| */ | ||
| function keepsNestedNodeModules(appDefinition = {}) { | ||
| return appDefinition.lambda?.keepNestedNodeModules === true; | ||
| } | ||
|
|
||
| /** | ||
| * Package exclude patterns for nested node_modules directories. | ||
| * | ||
| * @param {Object} appDefinition | ||
| * @param {boolean} usePrismaLayer - Whether Prisma ships via the Lambda Layer | ||
| * @returns {string[]} | ||
| */ | ||
| function nestedNodeModulesExcludes(appDefinition, usePrismaLayer = true) { | ||
| if (!keepsNestedNodeModules(appDefinition)) { | ||
| return [ALL_NESTED_NODE_MODULES]; | ||
| } | ||
| return [ | ||
| 'node_modules/**/node_modules/@friggframework/**', | ||
| 'node_modules/**/node_modules/aws-sdk/**', | ||
| 'node_modules/**/node_modules/@aws-sdk/**', | ||
| ...(usePrismaLayer | ||
| ? [ | ||
| 'node_modules/**/node_modules/@prisma/**', | ||
| 'node_modules/**/node_modules/.prisma/**', | ||
| ] | ||
| : []), | ||
| ]; | ||
| } | ||
|
|
||
| module.exports = { | ||
| ALL_NESTED_NODE_MODULES, | ||
| keepsNestedNodeModules, | ||
| nestedNodeModulesExcludes, | ||
| }; | ||
61 changes: 61 additions & 0 deletions
61
packages/devtools/infrastructure/domains/shared/utilities/nested-node-modules.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** | ||
| * Tests for nested node_modules packaging patterns | ||
| */ | ||
|
|
||
| const { | ||
| ALL_NESTED_NODE_MODULES, | ||
| keepsNestedNodeModules, | ||
| nestedNodeModulesExcludes, | ||
| } = require('./nested-node-modules'); | ||
|
|
||
| describe('nestedNodeModulesExcludes', () => { | ||
| it('excludes every nested node_modules by default', () => { | ||
| expect(nestedNodeModulesExcludes({}, true)).toEqual([ | ||
| 'node_modules/**/node_modules/**', | ||
| ]); | ||
| expect(ALL_NESTED_NODE_MODULES).toBe('node_modules/**/node_modules/**'); | ||
| }); | ||
|
|
||
| it('keeps nested node_modules when the app opts in, except Frigg, AWS SDK and Prisma copies', () => { | ||
| const appDefinition = { lambda: { keepNestedNodeModules: true } }; | ||
|
|
||
| const excludes = nestedNodeModulesExcludes(appDefinition, true); | ||
|
|
||
| expect(excludes).not.toContain('node_modules/**/node_modules/**'); | ||
| expect(excludes).toEqual([ | ||
| 'node_modules/**/node_modules/@friggframework/**', | ||
| 'node_modules/**/node_modules/aws-sdk/**', | ||
| 'node_modules/**/node_modules/@aws-sdk/**', | ||
| 'node_modules/**/node_modules/@prisma/**', | ||
| 'node_modules/**/node_modules/.prisma/**', | ||
| ]); | ||
| }); | ||
|
|
||
| it('keeps nested Prisma copies when the app bundles Prisma instead of using the layer', () => { | ||
| const appDefinition = { lambda: { keepNestedNodeModules: true } }; | ||
|
|
||
| const excludes = nestedNodeModulesExcludes(appDefinition, false); | ||
|
|
||
| expect(excludes).toEqual([ | ||
| 'node_modules/**/node_modules/@friggframework/**', | ||
| 'node_modules/**/node_modules/aws-sdk/**', | ||
| 'node_modules/**/node_modules/@aws-sdk/**', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('keepsNestedNodeModules', () => { | ||
| it('is only enabled by the boolean true', () => { | ||
| expect( | ||
| keepsNestedNodeModules({ lambda: { keepNestedNodeModules: true } }) | ||
| ).toBe(true); | ||
| expect( | ||
| keepsNestedNodeModules({ | ||
| lambda: { keepNestedNodeModules: 'true' }, | ||
| }) | ||
| ).toBe(false); | ||
| expect(keepsNestedNodeModules({ lambda: {} })).toBe(false); | ||
| expect(keepsNestedNodeModules({})).toBe(false); | ||
| expect(keepsNestedNodeModules()).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an app definition containing this documented opt-in is passed through
@friggframework/schemas'svalidateAppDefinition, validation rejects it as an unknown property becausepackages/schemas/schemas/app-definition.schema.jsonallows onlylambda.scopedEnvironmentand setsadditionalProperties: falseonlambda. AddkeepNestedNodeModulesas a boolean schema property so schema-valid workflows can enable the new packaging behavior.Useful? React with 👍 / 👎.