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

Deprecate redux plugin #1027

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 77 additions & 77 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/generated-docs/lifecycle-graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ createServers -- exec --> fastify;
gasket/plugin-data -- execWaterfall --> gasketData;
gasket/plugin-https-proxy -- execWaterfall --> httpsProxy;
gasket/core -- execSync --> init;
middleware -- execWaterfall --> initReduxState;
middleware -- exec --> initReduxStore;
middleware -- execWaterfall --> initReduxState["initReduxState (deprecated)"];
middleware -- exec --> initReduxStore["initReduxStore (deprecated)"];
build-cmd(build) --> initWebpack;
middleware -- execWaterfallSync --> intlLocale;
middleware -- execWaterfall --> manifest;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"docs-view": "npm run generate-docs-index && cd site && docusaurus start",
"generate-docs-index": "node scripts/generate-docs-index",
"postinstall": "npm run build",
"postpublish": "node scripts/mark-deprecated.mjs",
"publish": "lerna publish",
"publish:canary": "lerna publish --preid canary --dist-tag canary",
"publish:next": "lerna publish prerelease --preid next --dist-tag next --force-publish --exact",
Expand Down
14 changes: 9 additions & 5 deletions packages/gasket-plugin-redux/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# @gasket/plugin-redux

Gasket plugin to setup redux store available to express middleware.
Gasket plugin to setup Redux store availability to Express middleware.

⚠️ _This plugin is only compatible with Gasket apps that use the [pages router]
in Next.js with a [custom server] and is intended to be deprecated._
⚠️ _DEPRECATED - This plugin will be removed in a future major version.
Compatability is limited to Next.js apps using [pages router] with [custom server]
and [@gasket/plugin-middleware]._

## Installation

```
npm i @gasket/plugin-redux
npm i @gasket/plugin-redux @gasket/plugin-middleware
```

Update your `gasket` file plugin configuration:
Expand All @@ -17,10 +18,12 @@ Update your `gasket` file plugin configuration:
// gasket.js

+ import pluginRedux from '@gasket/plugin-redux';
+ import pluginMiddleware from '@gasket/plugin-middleware';

export default makeGasket({
plugins: [
+ pluginRedux
+ pluginRedux,
+ pluginMiddleware
]
});
```
Expand Down Expand Up @@ -243,4 +246,5 @@ will be replaced by the [EnvironmentPlugin].
[pages router]:https://nextjs.org/docs/pages
[custom server]:https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
[@gasket/redux]:/packages/gasket-redux/README.md#gasketredux
[@gasket/plugin-middleware]:/packages/gasket-plugin-middleware/README.md
[EnvironmentPlugin]:https://webpack.js.org/plugins/environment-plugin/
4 changes: 4 additions & 0 deletions packages/gasket-plugin-redux/lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const fs = require('fs');
module.exports = function configure(gasket, baseConfig) {
const { root, redux: reduxConfig = {} } = baseConfig;

gasket.logger.warn(
`DEPRECATED \`@gasket/plugin-redux\` will not be support in future major release.`
);

let makeStorePath = reduxConfig.makeStore;
if (makeStorePath) {
makeStorePath = path.resolve(baseConfig.root, reduxConfig.makeStore);
Expand Down
14 changes: 9 additions & 5 deletions packages/gasket-plugin-redux/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IncomingMessage, OutgoingMessage } from 'http';
import type { Store } from 'redux';
import type { MaybeAsync, Plugin } from '@gasket/core';
import type { MakeStoreFn } from '@gasket/redux';
import { Logger } from '@gasket/plugin-logger';

/**
Expand Down Expand Up @@ -44,6 +45,13 @@ declare module 'http' {
}
}

export interface ReduxConfig {
makeStore?: string;
makeStorePath?: string;
initState?: any;
logger?: Console | Logger;
}

declare module 'create-gasket-app' {
export interface CreateContext {
hasGasketRedux?: boolean;
Expand All @@ -54,11 +62,7 @@ declare module 'create-gasket-app' {

declare module '@gasket/core' {
export interface GasketConfig {
redux?: {
makeStore?: string;
initState?: any;
logger?: Console | Logger;
}
redux?: ReduxConfig
}

export interface HookExecTypes {
Expand Down
4 changes: 4 additions & 0 deletions packages/gasket-plugin-redux/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const plugin = {
name,
version,
description,
dependencies: ['@gasket/plugin-middleware'],
hooks: {
configure,
prompt,
Expand All @@ -33,13 +34,15 @@ const plugin = {
lifecycles: [
{
name: 'initReduxState',
deprecated: true,
method: 'execWaterfall',
description: 'Initializes state of the Redux store',
link: 'README.md#initReduxState',
parent: 'middleware'
},
{
name: 'initReduxStore',
deprecated: true,
method: 'exec',
description: 'Plugin access to Redux store instance',
link: 'README.md#initReduxStore',
Expand All @@ -57,6 +60,7 @@ const plugin = {
configurations: [
{
name: 'redux',
deprecated: true,
link: 'README.md#configuration',
description: 'Redux plugin config object',
type: 'object'
Expand Down
34 changes: 26 additions & 8 deletions packages/gasket-plugin-redux/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Configure middleware
* @type {import('@gasket/core').HookHandler<'middleware'>}
*/
module.exports = function middlewareHook(gasket) {
module.exports = async function middlewareHook(gasket) {
const { redux: reduxConfig = {} } = gasket.config;

if (!reduxConfig.makeStore) {
Expand All @@ -15,21 +15,29 @@ module.exports = function middlewareHook(gasket) {
);
}

const mod = await import(reduxConfig.makeStore);
/** @type {import('@gasket/redux').MakeStoreFn} */
const makeStore = require(reduxConfig.makeStore);
const makeStore = mod.makeStore ?? mod.default;

/**
* Middleware to attach the redux store to the req object for use in other
* middleware
* @type {import('./index').reduxMiddleware}
*/
return async function middleware(req, res, next) {
const initState = await gasket.execWaterfall(
const context = { req, res };
let initState = reduxConfig.initState || {};

await gasket.execApply(
'initReduxState',
reduxConfig.initState || {},
{
req,
res
async (plugin, handler) => {
const name = plugin ? plugin.name || 'unnamed plugin' : 'app lifecycles';
gasket.logger.warn(
`DEPRECATED \`initReduxState\` lifecycle in ${name} will not be support in future major release.`
);

// eslint-disable-next-line require-atomic-updates
initState = await handler(initState, context);
}
);

Expand All @@ -38,7 +46,17 @@ module.exports = function middlewareHook(gasket) {
req
});

await gasket.exec('initReduxStore', store, { req, res });
await gasket.execApply(
'initReduxStore',
async (plugin, handler) => {
const name = plugin ? plugin.name || 'unnamed plugin' : 'app lifecycles';
gasket.logger.warn(
`DEPRECATED \`initReduxStore\` lifecycle in ${name} will not be support in future major release.`
);

handler(store, context);
}
);

// eslint-disable-next-line require-atomic-updates
req.store = store;
Expand Down
4 changes: 4 additions & 0 deletions packages/gasket-plugin-redux/lib/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = function webpackConfigHook(
) {
const { redux: reduxConfig } = gasket.config;

if (!reduxConfig.makeStore) {
return webpackConfig;
}

return {
...webpackConfig,
plugins: [
Expand Down
12 changes: 7 additions & 5 deletions packages/gasket-plugin-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gasket/plugin-redux",
"version": "7.2.1",
"description": "Gasket Redux Setup",
"description": "DEPRECATED Gasket Redux Setup",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
Expand All @@ -11,9 +11,9 @@
"scripts": {
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
"test:watch": "jest --watchAll",
"test:coverage": "jest --coverage",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
"test:watch": "npm run test -- --watchAll",
"test:coverage": "npm run test -- --coverage",
"posttest": "npm run lint && npm run typecheck",
"typecheck": "tsc",
"typecheck:watch": "tsc --watch"
Expand All @@ -39,6 +39,7 @@
"devDependencies": {
"@gasket/core": "^7.2.1",
"@gasket/redux": "^7.2.0",
"@gasket/plugin-middleware": "^7.2.0",
"acorn": "^8.11.3",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
Expand Down Expand Up @@ -73,5 +74,6 @@
},
"eslintIgnore": [
"generator/redux/store.js"
]
],
"deprecated": "Package deprecated and will be removed in future major release."
}
12 changes: 11 additions & 1 deletion packages/gasket-plugin-redux/test/configure.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ describe('configureHook', () => {
root: rootPath
};
mockGasket = {
config: mockConfig
config: mockConfig,
logger: {
warn: jest.fn()
}
};
});

Expand Down Expand Up @@ -85,4 +88,11 @@ describe('configureHook', () => {
spy.mockReset();
spy.mockRestore();
});

it('logs deprecation warning', () => {
configureHook(mockGasket, mockConfig);
expect(mockGasket.logger.warn).toHaveBeenCalledWith(
expect.stringMatching(/DEPRECATED `@gasket\/plugin-redux` will not be support in future major release\./)
);
});
});
Loading
Loading