Skip to content

Commit

Permalink
Merge pull request #976 from godaddy/cherry-picks
Browse files Browse the repository at this point in the history
Cherry picks from lts
  • Loading branch information
agerard-godaddy authored Nov 20, 2024
2 parents 8b73429 + d940d5e commit bf3dbe7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 138 deletions.
126 changes: 6 additions & 120 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/gasket-plugin-express/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@gasket/plugin-express`

### 7.0.14

- Switch to `http2-express` to address vulnerabilities ([#959])

### 7.0.12

- remove tsconfig.test from fastify, tune glob ignores ([#969])
Expand Down Expand Up @@ -127,7 +131,9 @@
[#695]: https://github.com/godaddy/gasket/pull/695
[#708]: https://github.com/godaddy/gasket/pull/708
[#736]: https://github.com/godaddy/gasket/pull/736
[#892]: https://github.com/godaddy/gasket/pull/892
[#958]: https://github.com/godaddy/gasket/pull/958
[#966]: https://github.com/godaddy/gasket/pull/966
[#967]: https://github.com/godaddy/gasket/pull/967
[#959]: https://github.com/godaddy/gasket/pull/959
[#969]: https://github.com/godaddy/gasket/pull/969
2 changes: 1 addition & 1 deletion packages/gasket-plugin-express/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const plugin = {
getExpressApp(gasket) {
const express = require('express');
const { http2 } = gasket.config;
app ??= http2 ? require('http2-express-bridge')(express) : express();
app ??= http2 ? require('http2-express')(express) : express();

return app;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"cookie-parser": "^1.4.6",
"diagnostics": "^2.0.2",
"glob": "^8.1.0",
"http2-express-bridge": "^1.0.7"
"http2-express": "^1.0.0"
},
"devDependencies": {
"@gasket/core": "^7.0.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-express/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const compressionMiddleware = jest.fn();
const mockCompression = jest.fn().mockReturnValue(compressionMiddleware);

jest.mock('express', () => mockExpress);
jest.mock('http2-express-bridge', () => mockExpressBridge);
jest.mock('http2-express', () => mockExpressBridge);
jest.mock('cookie-parser', () => mockCookieParser);
jest.mock('compression', () => mockCompression);

Expand Down
5 changes: 5 additions & 0 deletions packages/gasket-redux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@gasket/redux`

### 7.0.14

- Add configureMakeStore options callback to allow for per-request configuration ([#974])

### 7.0.0

- See [Version 7 Upgrade Guide] for overall changes
Expand Down Expand Up @@ -95,3 +99,4 @@
[#457]: https://github.com/godaddy/gasket/pull/457
[#670]: https://github.com/godaddy/gasket/pull/670
[#693]: https://github.com/godaddy/gasket/pull/693
[#974]: https://github.com/godaddy/gasket/pull/974
3 changes: 3 additions & 0 deletions packages/gasket-redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Set up Redux store configuration and return a `makeStore` function
**Signature**

- `configureMakeStore(options, [postCreate]): makeStore`
- `configureMakeStore(optionsFn, [postCreate]): makeStore`

**Props**

Expand All @@ -30,8 +31,10 @@ Set up Redux store configuration and return a `makeStore` function
- `enhancers` - (function[]) Any other redux store enhancers
- `logging` - (boolean) set to true if you want to enable redux logger.
(default: false)
- `optionsFn` - (function) function that returns the options object.
- `postCreate` - (function) Executed after the store is create the resulting
store as the argument
-

**Return Value**

Expand Down
20 changes: 10 additions & 10 deletions packages/gasket-redux/src/configure-make-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ export function prepareReducer(allReducers, rootReducer) {
* @type {import('./index').configureMakeStore}
*/
export default function configureMakeStore(makeStoreOptions = {}, postCreate) {
const {
thunkMiddleware = thunk,
middleware = [],
logging = false,
enhancers = [(f) => f],
reducers = {},
rootReducer,
initialState = {}
} = makeStoreOptions;

/**
* Wrapper for store create to create instance with SSR and to hydrate in
* browser.
* @type {import('./index').MakeStoreFn}
*/
// eslint-disable-next-line max-statements
function makeStore(state = {}, options = {}) {
const { req, logger = console } = options;
const {
thunkMiddleware = thunk,
middleware = [],
logging = false,
enhancers = [(f) => f],
reducers = {},
rootReducer,
initialState = {}
} = typeof makeStoreOptions === 'function' ? makeStoreOptions(options) : makeStoreOptions;

// Use existing redux store if it has been already been instantiated by
// redux-plugin
Expand Down
12 changes: 7 additions & 5 deletions packages/gasket-redux/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ declare module 'http' {
}
}

export type MakeStoreFnOptions = {
logger?: Console | Logger;
req?: IncomingMessage;
}

/**
* Wrapper for store create to create instance with SSR and to hydrate in
* browser.
Expand All @@ -16,10 +21,7 @@ export type MakeStoreFn = {
(
/** The initial redux state */
state: any,
options: {
logger?: Console | Logger;
req?: IncomingMessage;
}
options: MakeStoreFnOptions
): Store;
};

Expand Down Expand Up @@ -53,7 +55,7 @@ export function prepareReducer(
* Set up redux store configuration and return a makeStore function
*/
export function configureMakeStore(
options?: ConfigureMakeStoreOptions,
options?: ConfigureMakeStoreOptions | ((options: MakeStoreFnOptions) => ConfigureMakeStoreOptions),
postCreate?: Function
): MakeStoreFn;

Expand Down
27 changes: 27 additions & 0 deletions packages/gasket-redux/test/configure-make-store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const mockEnhancer = jest.fn(createStore => (reducer, initialState, enhancer) =>
const mockPostCreate = jest.fn();


// eslint-disable-next-line max-statements
describe('configureMakeStore', () => {
const mockReducers = {
reducer1: f => f || {}
Expand Down Expand Up @@ -47,6 +48,18 @@ describe('configureMakeStore', () => {
expect(result).toBeInstanceOf(Function);
});

it('accepts callback optionsFn', () => {
result = configureMakeStore(() => {});
expect(result).toBeInstanceOf(Function);
});

it('accepts callback optionsFn called with makeStoreOptions', () => {
const mockMakeOptions = { logger: {}, req: {} };
const mockOptionsFn = jest.fn().mockReturnValue({});
configureMakeStore(mockOptionsFn)({}, mockMakeOptions);
expect(mockOptionsFn).toHaveBeenCalledWith(mockMakeOptions);
});

it('allows custom initial state', () => {
store = configureMakeStore({ initialState: mockInitialState })();
const state = store.getState();
Expand All @@ -56,11 +69,25 @@ describe('configureMakeStore', () => {
}
});

it('allows custom initial state from callback optionsFn', () => {
store = configureMakeStore(() => ({ initialState: mockInitialState }))();
const state = store.getState();

for (const [key, value] of Object.entries(mockInitialState)) {
expect(state).toHaveProperty(key, value);
}
});

it('allows custom middleware', () => {
configureMakeStore({ middleware: [mockMiddleware] })();
expect(applyMiddlewareSpy.mock.calls[0][1]).toBe(mockMiddleware);
});

it('allows custom middleware from callback optionsFn', () => {
configureMakeStore(() => ({ middleware: [mockMiddleware] }))();
expect(applyMiddlewareSpy.mock.calls[0][1]).toBe(mockMiddleware);
});

it('adds thunk and logger middleware if enabled', () => {
configureMakeStore({ logging: true })();
expect(applyMiddlewareSpy.mock.calls[0]).toHaveLength(2);
Expand Down

0 comments on commit bf3dbe7

Please sign in to comment.