Skip to content

Commit 96f7e43

Browse files
Deprecate redux plugin (#1027)
* chore: add deprecation notices for redux plugin and lifecycles * chore: add npm deprecation notice for redux plugin * chore: support esm stores * docs: update with deprecations
1 parent 02c4748 commit 96f7e43

File tree

14 files changed

+230
-134
lines changed

14 files changed

+230
-134
lines changed

README.md

+77-77
Large diffs are not rendered by default.

docs/generated-docs/lifecycle-graphs.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ createServers -- exec --> fastify;
1818
gasket/plugin-data -- execWaterfall --> gasketData;
1919
gasket/plugin-https-proxy -- execWaterfall --> httpsProxy;
2020
gasket/core -- execSync --> init;
21-
middleware -- execWaterfall --> initReduxState;
22-
middleware -- exec --> initReduxStore;
21+
middleware -- execWaterfall --> initReduxState["initReduxState (deprecated)"];
22+
middleware -- exec --> initReduxStore["initReduxStore (deprecated)"];
2323
build-cmd(build) --> initWebpack;
2424
middleware -- execWaterfallSync --> intlLocale;
2525
middleware -- execWaterfall --> manifest;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"docs-view": "npm run generate-docs-index && cd site && docusaurus start",
2020
"generate-docs-index": "node scripts/generate-docs-index",
2121
"postinstall": "npm run build",
22+
"postpublish": "node scripts/mark-deprecated.mjs",
2223
"publish": "lerna publish",
2324
"publish:canary": "lerna publish --preid canary --dist-tag canary",
2425
"publish:next": "lerna publish prerelease --preid next --dist-tag next --force-publish --exact",

packages/gasket-plugin-redux/README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# @gasket/plugin-redux
22

3-
Gasket plugin to setup redux store available to express middleware.
3+
Gasket plugin to setup Redux store availability to Express middleware.
44

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

89
## Installation
910

1011
```
11-
npm i @gasket/plugin-redux
12+
npm i @gasket/plugin-redux @gasket/plugin-middleware
1213
```
1314

1415
Update your `gasket` file plugin configuration:
@@ -17,10 +18,12 @@ Update your `gasket` file plugin configuration:
1718
// gasket.js
1819

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

2123
export default makeGasket({
2224
plugins: [
23-
+ pluginRedux
25+
+ pluginRedux,
26+
+ pluginMiddleware
2427
]
2528
});
2629
```
@@ -243,4 +246,5 @@ will be replaced by the [EnvironmentPlugin].
243246
[pages router]:https://nextjs.org/docs/pages
244247
[custom server]:https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
245248
[@gasket/redux]:/packages/gasket-redux/README.md#gasketredux
249+
[@gasket/plugin-middleware]:/packages/gasket-plugin-middleware/README.md
246250
[EnvironmentPlugin]:https://webpack.js.org/plugins/environment-plugin/

packages/gasket-plugin-redux/lib/configure.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const fs = require('fs');
88
module.exports = function configure(gasket, baseConfig) {
99
const { root, redux: reduxConfig = {} } = baseConfig;
1010

11+
gasket.logger.warn(
12+
`DEPRECATED \`@gasket/plugin-redux\` will not be support in future major release.`
13+
);
14+
1115
let makeStorePath = reduxConfig.makeStore;
1216
if (makeStorePath) {
1317
makeStorePath = path.resolve(baseConfig.root, reduxConfig.makeStore);

packages/gasket-plugin-redux/lib/index.d.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { IncomingMessage, OutgoingMessage } from 'http';
22
import type { Store } from 'redux';
33
import type { MaybeAsync, Plugin } from '@gasket/core';
4+
import type { MakeStoreFn } from '@gasket/redux';
45
import { Logger } from '@gasket/plugin-logger';
56

67
/**
@@ -44,6 +45,13 @@ declare module 'http' {
4445
}
4546
}
4647

48+
export interface ReduxConfig {
49+
makeStore?: string;
50+
makeStorePath?: string;
51+
initState?: any;
52+
logger?: Console | Logger;
53+
}
54+
4755
declare module 'create-gasket-app' {
4856
export interface CreateContext {
4957
hasGasketRedux?: boolean;
@@ -54,11 +62,7 @@ declare module 'create-gasket-app' {
5462

5563
declare module '@gasket/core' {
5664
export interface GasketConfig {
57-
redux?: {
58-
makeStore?: string;
59-
initState?: any;
60-
logger?: Console | Logger;
61-
}
65+
redux?: ReduxConfig
6266
}
6367

6468
export interface HookExecTypes {

packages/gasket-plugin-redux/lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const plugin = {
1919
name,
2020
version,
2121
description,
22+
dependencies: ['@gasket/plugin-middleware'],
2223
hooks: {
2324
configure,
2425
prompt,
@@ -33,13 +34,15 @@ const plugin = {
3334
lifecycles: [
3435
{
3536
name: 'initReduxState',
37+
deprecated: true,
3638
method: 'execWaterfall',
3739
description: 'Initializes state of the Redux store',
3840
link: 'README.md#initReduxState',
3941
parent: 'middleware'
4042
},
4143
{
4244
name: 'initReduxStore',
45+
deprecated: true,
4346
method: 'exec',
4447
description: 'Plugin access to Redux store instance',
4548
link: 'README.md#initReduxStore',
@@ -57,6 +60,7 @@ const plugin = {
5760
configurations: [
5861
{
5962
name: 'redux',
63+
deprecated: true,
6064
link: 'README.md#configuration',
6165
description: 'Redux plugin config object',
6266
type: 'object'

packages/gasket-plugin-redux/lib/middleware.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Configure middleware
77
* @type {import('@gasket/core').HookHandler<'middleware'>}
88
*/
9-
module.exports = function middlewareHook(gasket) {
9+
module.exports = async function middlewareHook(gasket) {
1010
const { redux: reduxConfig = {} } = gasket.config;
1111

1212
if (!reduxConfig.makeStore) {
@@ -15,21 +15,29 @@ module.exports = function middlewareHook(gasket) {
1515
);
1616
}
1717

18+
const mod = await import(reduxConfig.makeStore);
1819
/** @type {import('@gasket/redux').MakeStoreFn} */
19-
const makeStore = require(reduxConfig.makeStore);
20+
const makeStore = mod.makeStore ?? mod.default;
2021

2122
/**
2223
* Middleware to attach the redux store to the req object for use in other
2324
* middleware
2425
* @type {import('./index').reduxMiddleware}
2526
*/
2627
return async function middleware(req, res, next) {
27-
const initState = await gasket.execWaterfall(
28+
const context = { req, res };
29+
let initState = reduxConfig.initState || {};
30+
31+
await gasket.execApply(
2832
'initReduxState',
29-
reduxConfig.initState || {},
30-
{
31-
req,
32-
res
33+
async (plugin, handler) => {
34+
const name = plugin ? plugin.name || 'unnamed plugin' : 'app lifecycles';
35+
gasket.logger.warn(
36+
`DEPRECATED \`initReduxState\` lifecycle in ${name} will not be support in future major release.`
37+
);
38+
39+
// eslint-disable-next-line require-atomic-updates
40+
initState = await handler(initState, context);
3341
}
3442
);
3543

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

41-
await gasket.exec('initReduxStore', store, { req, res });
49+
await gasket.execApply(
50+
'initReduxStore',
51+
async (plugin, handler) => {
52+
const name = plugin ? plugin.name || 'unnamed plugin' : 'app lifecycles';
53+
gasket.logger.warn(
54+
`DEPRECATED \`initReduxStore\` lifecycle in ${name} will not be support in future major release.`
55+
);
56+
57+
handler(store, context);
58+
}
59+
);
4260

4361
// eslint-disable-next-line require-atomic-updates
4462
req.store = store;

packages/gasket-plugin-redux/lib/webpack-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = function webpackConfigHook(
88
) {
99
const { redux: reduxConfig } = gasket.config;
1010

11+
if (!reduxConfig.makeStore) {
12+
return webpackConfig;
13+
}
14+
1115
return {
1216
...webpackConfig,
1317
plugins: [

packages/gasket-plugin-redux/package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@gasket/plugin-redux",
33
"version": "7.2.1",
4-
"description": "Gasket Redux Setup",
4+
"description": "DEPRECATED Gasket Redux Setup",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"files": [
@@ -11,9 +11,9 @@
1111
"scripts": {
1212
"lint": "eslint .",
1313
"lint:fix": "npm run lint -- --fix",
14-
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
15-
"test:watch": "jest --watchAll",
16-
"test:coverage": "jest --coverage",
14+
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict --experimental-vm-modules' jest",
15+
"test:watch": "npm run test -- --watchAll",
16+
"test:coverage": "npm run test -- --coverage",
1717
"posttest": "npm run lint && npm run typecheck",
1818
"typecheck": "tsc",
1919
"typecheck:watch": "tsc --watch"
@@ -39,6 +39,7 @@
3939
"devDependencies": {
4040
"@gasket/core": "^7.2.1",
4141
"@gasket/redux": "^7.2.0",
42+
"@gasket/plugin-middleware": "^7.2.0",
4243
"acorn": "^8.11.3",
4344
"cross-env": "^7.0.3",
4445
"eslint": "^8.56.0",
@@ -73,5 +74,6 @@
7374
},
7475
"eslintIgnore": [
7576
"generator/redux/store.js"
76-
]
77+
],
78+
"deprecated": "Package deprecated and will be removed in future major release."
7779
}

packages/gasket-plugin-redux/test/configure.spec.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ describe('configureHook', () => {
1313
root: rootPath
1414
};
1515
mockGasket = {
16-
config: mockConfig
16+
config: mockConfig,
17+
logger: {
18+
warn: jest.fn()
19+
}
1720
};
1821
});
1922

@@ -85,4 +88,11 @@ describe('configureHook', () => {
8588
spy.mockReset();
8689
spy.mockRestore();
8790
});
91+
92+
it('logs deprecation warning', () => {
93+
configureHook(mockGasket, mockConfig);
94+
expect(mockGasket.logger.warn).toHaveBeenCalledWith(
95+
expect.stringMatching(/DEPRECATED `@gasket\/plugin-redux` will not be support in future major release\./)
96+
);
97+
});
8898
});

0 commit comments

Comments
 (0)