From c380187106571733459eda065a66cff7e0d03544 Mon Sep 17 00:00:00 2001 From: Michael Mason <105235096+mmason2-godaddy@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:33:22 -0800 Subject: [PATCH] Command plugin fixup (#989) * [PFX-813] ESM: Port plugin-metadata (#978) * chore: convert to esm * tests: added vitest * chore: update changelog; remove jest deps * fix: test * chore: remove unused space * [PFX-793] Dynamic plugins (#970) * feat: dynamic plugins * chore: add cjs tranpilation * tests: default-plugins * tests: core * tests: dynamic index * tests: prepare hook * fix: lint * chore: add types for dynamic plugins * docs: dynamic plugins * chore: update package.json * docs: update changelog * chore: switch to utilize sub-environments * chore: add metadata * fix: lint * fix: test * chore: remove cjs transpilation * docs: update dynamic and core * fix: test * Update packages/gasket-plugin-dynamic-plugins/README.md Co-authored-by: Andrew Gerard <63810935+agerard-godaddy@users.noreply.github.com> --------- Co-authored-by: Andrew Gerard <63810935+agerard-godaddy@users.noreply.github.com> * chore: remove depreacted http2 dep (#981) * Normalized gasket request (#973) * feat: normalized gasket request * fix: attempt types adjustments * fix: types adjustments * test: the things * docs: package docs * fix: docs * fix: one way to make * fix: ensure expected defaults * fix: better types * fix: handle parallel executions * fix: next request helper * test: adjustments * fix: unused import * feat: add WeakPromiseKeeper for consistent promise to value caching * fix: types * fix: docs * feat: handle IncomingMessage url * fix: tighten types * fix: test cruft * docs: fix * fix: only parse url when needed * test: using gasket.symbol as weakmap key (#964) * Separate https-proxy plugin (#982) * feat: separate https-proxy plugin * feat: use https-proxy with prompts * fix: typos and grammar * fix: avoid default export * fix: return proxy server * chore: upgrade lerna * fix: publish issues for command plugin * docs: next.config.js (#987) * [PFX-507] Add DocSearch to Gasket Site (#984) * change dynamic require to string interpolation (#985) * pin react-intl version to 6.6.X (#988) * feat: initial fixup for getting command name early and using prepare lifecycle as an async config * Fix typo * Tune types * Opt for sync configure hook * Clean up old references to command.id * Add isReady, update command property * Update readme * Tune command plugin functionality * Add temp logging for debug * Cleanup debugs * Persist commands config when commandId is undefined * Tune tests * lockfile * remove duplicate tests from merge * lockfile * lockfile * feat: initial fixup for getting command name early and using prepare lifecycle as an async config * Fix typo * Tune types * Opt for sync configure hook * Clean up old references to command.id * Add isReady, update command property * Update readme * Tune command plugin functionality * Add temp logging for debug * Cleanup debugs * Persist commands config when commandId is undefined * Tune tests * Import plugin command types * Relax the regex for gasket file in argv * Remove timing from ready hook * fix test --------- Co-authored-by: Jordan Pina <106619535+jpina1-godaddy@users.noreply.github.com> Co-authored-by: Andrew Gerard <63810935+agerard-godaddy@users.noreply.github.com> Co-authored-by: Andrew Gerard Co-authored-by: Kawika Bader <76699310+kbader-godaddy@users.noreply.github.com> Co-authored-by: bbetts-godaddy <104379885+bbetts-godaddy@users.noreply.github.com> --- README.md | 11 ++++ docs/generated-docs/lifecycle-graphs.md | 1 + packages/gasket-core/lib/gasket.js | 3 +- packages/gasket-core/lib/index.d.ts | 5 +- packages/gasket-nextjs/README.md | 5 +- packages/gasket-plugin-command/README.md | 22 ++++++++ .../gasket-plugin-command/lib/configure.js | 37 +++++++++++++ packages/gasket-plugin-command/lib/index.d.ts | 5 ++ packages/gasket-plugin-command/lib/index.js | 6 +- packages/gasket-plugin-command/lib/ready.js | 18 ++---- .../test/configure.test.js | 55 +++++++++++++++++++ .../gasket-plugin-command/test/ready.test.js | 28 +++------- packages/gasket-plugin-data/lib/configure.js | 5 +- packages/gasket-plugin-data/lib/index.d.ts | 5 +- .../gasket-plugin-data/test/configure.test.js | 6 +- .../gasket-plugin-https-proxy/lib/actions.js | 1 + packages/gasket-plugin-https/lib/index.js | 1 + .../lib/webpack-config.js | 4 +- .../test/webpack-config.spec.js | 2 +- .../gasket-preset-nextjs/lib/preset-config.js | 4 ++ .../test/engine.spec.ts | 2 +- packages/gasket-utils/lib/config.js | 7 ++- packages/gasket-utils/test/config.test.js | 21 +++++++ 23 files changed, 196 insertions(+), 58 deletions(-) create mode 100644 packages/gasket-plugin-command/lib/configure.js create mode 100644 packages/gasket-plugin-command/test/configure.test.js diff --git a/README.md b/README.md index ad4bf4f49..cc8a7fbe1 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Available actions | [getPublicGasketData] | Get the public Gasket data | | [getSWRegisterScript] | Get the service worker registration script | | [getWebpackConfig] | Get the webpack config | +| [startProxyServer] | Start the proxy server | | [startServer] | Start the server | ## Lifecycles @@ -107,6 +108,7 @@ Available lifecycles | [express] | Modify the Express instance to for adding endpoints | | [fastify] | Modify the Fastify instance to for adding endpoints | | [gasketData] | Adjust app level data after merged for the env | +| [httpsProxy] | Setup the httpsProxy options | | [initReduxState] | Initializes state of the Redux store | | [initReduxStore] | Plugin access to Redux store instance | | [initWebpack] | Create a webpack config | @@ -224,6 +226,7 @@ Available configuration options in the `gasket.js` | [docusaurus.host] | Hostname to serve the docs from | string | localhost | | [docusaurus.port] | Port number to serve docs site | number | 3000 | | [docusaurus.rootDir] | Root Docusaurus directory | string | .docs | +| [dynamicPlugins] | Specify which plugins to load dynamically into gasket | array | | | [elasticAPM] | Configuration to provide additional setup helpers | object | | | [elasticAPM.sensitiveCookies] | List of sensitive cookies to filter | string[] | [] | | [express][6] | Express plugin configuration | object | | @@ -236,6 +239,7 @@ Available configuration options in the `gasket.js` | [http] | HTTP port or config object | number | object | | | [http2] | HTTP2 config object | object | | | [https] | HTTPS config object | object | | +| [httpsProxy][8] | http-proxy config object | object | | | [intl] | Intl config object | object | | | [intl.defaultLocale] | Locale to fallback to when loading files | string | en | | [intl.defaultLocaleFilePath] | Lookup path to locale files | string | locales | @@ -301,6 +305,7 @@ Available configuration options in the `gasket.js` [getPublicGasketData]:/packages/gasket-plugin-data/README.md#getPublicGasketData [getSWRegisterScript]:/packages/gasket-plugin-service-worker/README.md#getSWRegisterScript [getWebpackConfig]:/packages/gasket-plugin-webpack/README.md#getWebpackConfig +[startProxyServer]:/packages/gasket-plugin-https-proxy/README.md#startProxyServer [startServer]:/packages/gasket-plugin-https/README.md#startServer [apmTransaction]:/packages/gasket-plugin-elastic-apm/README.md#apmtransaction [1]:/packages/gasket-plugin-command/README.md#build @@ -317,6 +322,7 @@ Available configuration options in the `gasket.js` [express]:/packages/gasket-plugin-express/README.md#express [fastify]:/packages/gasket-plugin-fastify/README.md#express [gasketData]:/packages/gasket-plugin-data/README.md#gasketData +[httpsProxy]:/packages/gasket-plugin-https-proxy/README.md#httpsProxy [initReduxState]:/packages/gasket-plugin-redux/README.md#initReduxState [initReduxStore]:/packages/gasket-plugin-redux/README.md#initReduxStore [initWebpack]:/packages/gasket-plugin-webpack/README.md#initwebpack @@ -356,12 +362,14 @@ Available configuration options in the `gasket.js` [@gasket/plugin-docs]:/packages/gasket-plugin-docs/README.md [@gasket/plugin-docs-graphs]:/packages/gasket-plugin-docs-graphs/README.md [@gasket/plugin-docusaurus]:/packages/gasket-plugin-docusaurus/README.md +[@gasket/plugin-dynamic-plugins]:/packages/gasket-plugin-dynamic-plugins/README.md [@gasket/plugin-elastic-apm]:/packages/gasket-plugin-elastic-apm/README.md [@gasket/plugin-express]:/packages/gasket-plugin-express/README.md [@gasket/plugin-fastify]:/packages/gasket-plugin-fastify/README.md [@gasket/plugin-git]:/packages/gasket-plugin-git/README.md [@gasket/plugin-happyfeet]:/packages/gasket-plugin-happyfeet/README.md [@gasket/plugin-https]:/packages/gasket-plugin-https/README.md +[@gasket/plugin-https-proxy]:/packages/gasket-plugin-https-proxy/README.md [@gasket/plugin-intl]:/packages/gasket-plugin-intl/README.md [@gasket/plugin-jest]:/packages/gasket-plugin-jest/README.md [@gasket/plugin-lint]:/packages/gasket-plugin-lint/README.md @@ -386,6 +394,7 @@ Available configuration options in the `gasket.js` [@gasket/nextjs]:/packages/gasket-nextjs/README.md [@gasket/react-intl]:/packages/gasket-react-intl/README.md [@gasket/redux]:/packages/gasket-redux/README.md +[@gasket/request]:/packages/gasket-request/README.md [@gasket/utils]:/packages/gasket-utils/README.md [bundleAnalyzerConfig]:/packages/gasket-plugin-analyze/README.md#configuration [5]:/packages/gasket-plugin-docs/README.md#configuration @@ -395,6 +404,7 @@ Available configuration options in the `gasket.js` [docusaurus.host]:/packages/gasket-plugin-docusaurus/README.md#configuration [docusaurus.port]:/packages/gasket-plugin-docusaurus/README.md#configuration [docusaurus.rootDir]:/packages/gasket-plugin-docusaurus/README.md#configuration +[dynamicPlugins]:/packages/gasket-plugin-dynamic-plugins/README.md#configuration [elasticAPM]:/packages/gasket-plugin-elastic-apm/README.md#configuration [elasticAPM.sensitiveCookies]:/packages/gasket-plugin-elastic-apm/README.md#configuration [6]:/packages/gasket-plugin-express/README.md#configuration @@ -407,6 +417,7 @@ Available configuration options in the `gasket.js` [http]:/packages/gasket-plugin-https/README.md#configuration [http2]:/packages/gasket-plugin-https/README.md#configuration [https]:/packages/gasket-plugin-https/README.md#configuration +[8]:/packages/gasket-plugin-https-proxy/README.md#configuration [intl]:/packages/gasket-plugin-intl/README.md#configuration [intl.defaultLocale]:/packages/gasket-plugin-intl/README.md#configuration [intl.defaultLocaleFilePath]:/packages/gasket-plugin-intl/README.md#configuration diff --git a/docs/generated-docs/lifecycle-graphs.md b/docs/generated-docs/lifecycle-graphs.md index de88e7b6a..17c87c641 100644 --- a/docs/generated-docs/lifecycle-graphs.md +++ b/docs/generated-docs/lifecycle-graphs.md @@ -15,6 +15,7 @@ createServers -- exec --> errorMiddleware; createServers -- exec --> express; createServers -- exec --> fastify; gasket/plugin-data -- execWaterfall --> gasketData; +gasket/plugin-https-proxy -- execWaterfall --> httpsProxy; middleware -- execWaterfall --> initReduxState; middleware -- exec --> initReduxStore; build-cmd(build) --> initWebpack; diff --git a/packages/gasket-core/lib/gasket.js b/packages/gasket-core/lib/gasket.js index 06f00ad73..8865a56f5 100644 --- a/packages/gasket-core/lib/gasket.js +++ b/packages/gasket-core/lib/gasket.js @@ -53,7 +53,6 @@ export class Gasket { this.hook = this.engine.hook.bind(this.engine); this.config = config; - this.command = null; // Can be used as a key to identify a gasket instance this.symbol = Symbol('gasket'); @@ -66,7 +65,7 @@ export class Gasket { this.isReady = new Promise((resolve) => { (async () => { // @ts-ignore - attached lifecycle trace methods - await this.exec('prepare'); + this.config = await this.execWaterfall('prepare', this.config); // @ts-ignore - attached lifecycle trace methods await this.exec('ready'); resolve(); diff --git a/packages/gasket-core/lib/index.d.ts b/packages/gasket-core/lib/index.d.ts index 66fd46f01..7d7cb520a 100644 --- a/packages/gasket-core/lib/index.d.ts +++ b/packages/gasket-core/lib/index.d.ts @@ -116,9 +116,8 @@ declare module '@gasket/core' { constructor(config: GasketConfigDefinition); new (config: GasketConfigDefinition): Gasket - command: { - id: string; - }; + isReady: Promise; + command: string; config: GasketConfig; engine: GasketEngine; symbol: Symbol; diff --git a/packages/gasket-nextjs/README.md b/packages/gasket-nextjs/README.md index d69fb5b85..f6744720c 100644 --- a/packages/gasket-nextjs/README.md +++ b/packages/gasket-nextjs/README.md @@ -81,7 +81,7 @@ the [@gasket/data] package. **Props** - `[options]` - (object) Optional configuration - - `index` - (number) Force the script to be inject at a certain child index of the body + - `index` - (number) Force the script to be inject at a certain child index of the body #### Example @@ -141,7 +141,6 @@ In this example, the `gasketData` script will be injected after the custom This is especially useful if you are somehow nesting or extending the `
` and `` components and the decorator cannot find the right place to inject the script. - --- ### withGasketDataProvider @@ -174,7 +173,6 @@ Use this hook to access the gasketData provided by the `withGasketDataProvider` #### Example - ```jsx // MyComponent.js import { useGasketData } from '@gasket/nextjs'; @@ -202,7 +200,6 @@ The `useGasketData` will provided access to the gasket data within the context o > Please see @gasket/data docs for examples on adding data during SSR lifecycle - ## License [MIT](./LICENSE.md) diff --git a/packages/gasket-plugin-command/README.md b/packages/gasket-plugin-command/README.md index 64eafcd9b..25f6cba59 100644 --- a/packages/gasket-plugin-command/README.md +++ b/packages/gasket-plugin-command/README.md @@ -229,5 +229,27 @@ export default { }; ``` +### Command-based Configuration + +The commands property in the `gasket.js` file allows you to define configurations that are specific to individual commands. This means that when a particular command is executed, the corresponding configuration values will be applied, ensuring that each command can have its own tailored settings. This helps in managing command-specific behaviors and settings efficiently within your Gasket application. + +#### Example + +Define a command-based configuration in the `gasket.js` file: + +```js +// gasket.js +import { makeGasket } from '@gasket/core'; + +export default makeGasket({ + message: 'Default message', + commands: { + 'example-cmd': { + message: 'Hello, World!' // when the `example-cmd` command is executed, this message will be displayed + } + } +}); +``` + [Commander.js]: https://github.com/tj/commander.js?tab=readme-ov-file#commanderjs diff --git a/packages/gasket-plugin-command/lib/configure.js b/packages/gasket-plugin-command/lib/configure.js new file mode 100644 index 000000000..90c0d89c0 --- /dev/null +++ b/packages/gasket-plugin-command/lib/configure.js @@ -0,0 +1,37 @@ +// @ts-nocheck +/* eslint-disable no-unused-vars, no-sync */ +import { applyConfigOverrides } from '@gasket/utils'; +import { gasketBin, processCommand } from './cli.js'; +const isGasketCommand = /gasket[.-\w]*\.(js|ts|cjs|mjs)$/; + +export default { + timing: { + first: true + }, + /** @type {import('@gasket/core').HookHandler<'configure'>} */ + handler: function configure(gasket, config) { + const hasGasket = process.argv.some(arg => isGasketCommand.test(arg)); + + if (hasGasket) { + const cmds = gasket.execSync('commands'); + const commandIds = cmds.reduce((acc, cmd) => { + acc[cmd.id] = true; + return acc; + }, Object()); + + cmds.forEach(cmd => { + const { command, hidden, isDefault } = processCommand(cmd); + gasketBin.addCommand(command, { hidden, isDefault }); + }); + + const commandId = [...process.argv].filter(arg => commandIds[arg])[0]; + return { + command: commandId, + ...applyConfigOverrides(config, { env: gasket.config.env, commandId }) + }; + } + + return config; + } +}; + diff --git a/packages/gasket-plugin-command/lib/index.d.ts b/packages/gasket-plugin-command/lib/index.d.ts index 5dc3b2947..4d2c18d7f 100644 --- a/packages/gasket-plugin-command/lib/index.d.ts +++ b/packages/gasket-plugin-command/lib/index.d.ts @@ -28,6 +28,11 @@ export interface GasketCommandDefinition { } declare module '@gasket/core' { + /* Custom command name/id */ + export interface GasketConfig { + command?: string; + } + interface HookExecTypes { commands(): GasketCommandDefinition; build(): void; diff --git a/packages/gasket-plugin-command/lib/index.js b/packages/gasket-plugin-command/lib/index.js index da44159b2..fb80efe12 100644 --- a/packages/gasket-plugin-command/lib/index.js +++ b/packages/gasket-plugin-command/lib/index.js @@ -1,8 +1,9 @@ /// import create from './create.js'; -import ready from './ready.js'; +import configure from './configure.js'; import commands from './commands.js'; +import ready from './ready.js'; import { createRequire } from 'module'; const require = createRequire(import.meta.url); const { name, version, description } = require('../package.json'); @@ -14,8 +15,9 @@ export default { description, hooks: { create, - ready, + configure, commands, + ready, metadata(gasket, meta) { return { ...meta, diff --git a/packages/gasket-plugin-command/lib/ready.js b/packages/gasket-plugin-command/lib/ready.js index cf98ff2ff..11fe282ef 100644 --- a/packages/gasket-plugin-command/lib/ready.js +++ b/packages/gasket-plugin-command/lib/ready.js @@ -1,18 +1,8 @@ -/* eslint-disable no-unused-vars, no-sync */ -import { gasketBin, processCommand } from './cli.js'; -const isGasketCommand = /\/gasket\.(js|ts|cjs|mjs)$/; +import { gasketBin } from './cli.js'; /** @type {import('@gasket/core').HookHandler<'ready'>} */ -export default async function readyHook(gasket) { - const hasGasket = process.argv.some(arg => isGasketCommand.test(arg)); - - if (hasGasket) { - const cmds = await gasket.exec('commands'); - cmds.forEach(cmd => { - const { command, hidden, isDefault } = processCommand(cmd); - gasketBin.addCommand(command, { hidden, isDefault }); - }); - +export default async function ready(gasket) { + gasket.isReady.then(() => { gasketBin.parse(); - } + }); } diff --git a/packages/gasket-plugin-command/test/configure.test.js b/packages/gasket-plugin-command/test/configure.test.js new file mode 100644 index 000000000..019a4fea8 --- /dev/null +++ b/packages/gasket-plugin-command/test/configure.test.js @@ -0,0 +1,55 @@ +/* eslint-disable no-sync */ +import { jest } from '@jest/globals'; + +const mockAddCommand = jest.fn(); +const mockParse = jest.fn(); +const mockProcessCommand = jest.fn(); + +jest.unstable_mockModule('../lib/cli.js', () => { + + return { + gasketBin: { + addCommand: mockAddCommand, + parse: mockParse + }, + processCommand: mockProcessCommand.mockReturnValue({ command: 'test', hidden: false, isDefault: false }) + }; +}); + +const configure = ((await import('../lib/configure.js')).default).handler; + +describe('configure', () => { + let mockGasket, mockConfig; + + beforeEach(() => { + jest.clearAllMocks(); + mockGasket = { + execSync: jest.fn().mockReturnValue([{ id: 'test', description: 'test', action: jest.fn() }]), + config: { + env: 'development' + } + }; + mockConfig = {}; + }); + + it('should be a function', () => { + expect(configure).toEqual(expect.any(Function)); + }); + + it('should not exec commands if not a gasket command', () => { + configure(mockGasket, mockConfig); + expect(mockGasket.execSync).not.toHaveBeenCalled(); + }); + + it('should execute on gasket command', () => { + process.argv = ['node', '/path/to/gasket.js']; + configure(mockGasket, mockConfig); + expect(mockGasket.execSync).toHaveBeenCalled(); + }); + + it('should add commands to gasketBin', () => { + process.argv = ['node', '/path/to/gasket.js']; + configure(mockGasket, mockConfig); + expect(mockAddCommand).toHaveBeenCalled(); + }); +}); diff --git a/packages/gasket-plugin-command/test/ready.test.js b/packages/gasket-plugin-command/test/ready.test.js index a25012159..5df3cae7c 100644 --- a/packages/gasket-plugin-command/test/ready.test.js +++ b/packages/gasket-plugin-command/test/ready.test.js @@ -1,4 +1,3 @@ -/* eslint-disable no-sync */ import { jest } from '@jest/globals'; const mockAddCommand = jest.fn(); @@ -24,7 +23,11 @@ describe('ready', () => { beforeEach(() => { jest.clearAllMocks(); mockGasket = { - exec: jest.fn().mockReturnValue([{ id: 'test', description: 'test', action: jest.fn() }]) + isReady: Promise.resolve(), + execSync: jest.fn().mockReturnValue([{ id: 'test', description: 'test', action: jest.fn() }]), + config: { + env: 'development' + } }; }); @@ -32,26 +35,13 @@ describe('ready', () => { expect(ready).toEqual(expect.any(Function)); }); - it('should not exec commands if not a gasket command', () => { - ready(mockGasket); - expect(mockGasket.exec).not.toHaveBeenCalled(); - }); - - it('should execute on gasket command', () => { - process.argv = ['node', '/path/to/gasket.js']; - ready(mockGasket); - expect(mockGasket.exec).toHaveBeenCalled(); - }); - - it('should add commands to gasketBin', async () => { - process.argv = ['node', '/path/to/gasket.js']; + it('should parse gasketBin', async () => { await ready(mockGasket); - expect(mockAddCommand).toHaveBeenCalled(); + expect(mockParse).toHaveBeenCalled(); }); - it('should parse commands', async () => { - process.argv = ['node', '/path/to/gasket.js']; + it('should wait for gasket to be ready', async () => { await ready(mockGasket); - expect(mockParse).toHaveBeenCalled(); + await expect(mockGasket.isReady).resolves.toBeUndefined(); }); }); diff --git a/packages/gasket-plugin-data/lib/configure.js b/packages/gasket-plugin-data/lib/configure.js index a72175f40..84f08bb9d 100644 --- a/packages/gasket-plugin-data/lib/configure.js +++ b/packages/gasket-plugin-data/lib/configure.js @@ -5,12 +5,11 @@ const { baseDataMap } = require('./actions'); * @type {import('@gasket/core').HookHandler<'configure'>} */ function configure(gasket, baseConfig) { - const { command, config: { env } } = gasket; - const commandId = command && command.id; + const { config: { env, command } } = gasket; if ('data' in baseConfig) { const data = applyConfigOverrides( baseConfig.data, - { env, commandId } + { env, commandId: command } ); baseDataMap.set(gasket.symbol, data); diff --git a/packages/gasket-plugin-data/lib/index.d.ts b/packages/gasket-plugin-data/lib/index.d.ts index fc1534e28..d19901c98 100644 --- a/packages/gasket-plugin-data/lib/index.d.ts +++ b/packages/gasket-plugin-data/lib/index.d.ts @@ -1,5 +1,6 @@ +/// + import { Plugin } from '@gasket/core'; -import { withGasketRequestCache } from '@gasket/request'; export interface PublicGasketData extends Record { } @@ -17,7 +18,7 @@ declare module '@gasket/core' { import { RequestLike, GasketRequest } from '@gasket/request'; export interface GasketConfig { - data?: GasketDataDefinition + data?: GasketDataDefinition; } export interface GasketActions { diff --git a/packages/gasket-plugin-data/test/configure.test.js b/packages/gasket-plugin-data/test/configure.test.js index 04ed32797..87786850e 100644 --- a/packages/gasket-plugin-data/test/configure.test.js +++ b/packages/gasket-plugin-data/test/configure.test.js @@ -11,12 +11,10 @@ describe('configure hook', () => { beforeEach(() => { gasket = { symbol: Symbol('gasket'), - command: { - id: 'commandId' - }, config: { env: 'test', - root: 'root' + root: 'root', + command: 'commandId' } }; config = { diff --git a/packages/gasket-plugin-https-proxy/lib/actions.js b/packages/gasket-plugin-https-proxy/lib/actions.js index a4dc13565..a8098e66e 100644 --- a/packages/gasket-plugin-https-proxy/lib/actions.js +++ b/packages/gasket-plugin-https-proxy/lib/actions.js @@ -4,6 +4,7 @@ import proxy from 'http-proxy'; /** @type {import('@gasket/core').ActionHandler<'startProxyServer'>} */ export async function startProxyServer(gasket) { + await gasket.isReady; const { httpsProxy } = gasket.config; const { logger } = gasket; diff --git a/packages/gasket-plugin-https/lib/index.js b/packages/gasket-plugin-https/lib/index.js index 722dd228c..3abf4fe07 100644 --- a/packages/gasket-plugin-https/lib/index.js +++ b/packages/gasket-plugin-https/lib/index.js @@ -72,6 +72,7 @@ function getRawServerConfig(gasket) { * @public */ async function startServer(gasket) { + await gasket.isReady; const { terminus, env, devProxy } = gasket.config; const { logger } = gasket; diff --git a/packages/gasket-plugin-service-worker/lib/webpack-config.js b/packages/gasket-plugin-service-worker/lib/webpack-config.js index 29c582896..954dde62c 100644 --- a/packages/gasket-plugin-service-worker/lib/webpack-config.js +++ b/packages/gasket-plugin-service-worker/lib/webpack-config.js @@ -7,14 +7,14 @@ const { getSWConfig } = require('./utils/utils'); * @type {import('@gasket/core').HookHandler<'webpackConfig'>} */ module.exports = function webpackConfigHook(gasket, webpackConfig, data) { - const { command } = gasket; + const { config: { command } } = gasket; const swConfig = getSWConfig(gasket); const { webpackRegister } = swConfig; const { isServer } = data; // Do not register the service worker for local development or if webpackRegister is false - if (webpackRegister !== false && !isServer && command.id !== 'local') { + if (webpackRegister !== false && !isServer && command !== 'local') { const WebpackInjectPlugin = require('webpack-inject-plugin').default; const { loadRegisterScript } = require('./utils/utils'); diff --git a/packages/gasket-plugin-service-worker/test/webpack-config.spec.js b/packages/gasket-plugin-service-worker/test/webpack-config.spec.js index 4d06c0e0b..79da5c5e0 100644 --- a/packages/gasket-plugin-service-worker/test/webpack-config.spec.js +++ b/packages/gasket-plugin-service-worker/test/webpack-config.spec.js @@ -32,7 +32,7 @@ describe('webpackConfig', () => { }); it('does not add WebpackInjectPlugin if local command', () => { - mockGasket.command.id = 'local'; + mockGasket.config.command = 'local'; results = webpack(mockGasket, mockWebpackConfig, mockNextData); expect(results).toBe(mockWebpackConfig); }); diff --git a/packages/gasket-preset-nextjs/lib/preset-config.js b/packages/gasket-preset-nextjs/lib/preset-config.js index 936c21f76..c58f03dda 100644 --- a/packages/gasket-preset-nextjs/lib/preset-config.js +++ b/packages/gasket-preset-nextjs/lib/preset-config.js @@ -32,6 +32,10 @@ export default async function presetConfig(gasket, context) { plugins.push(pluginHttpsProxy); } + if (context.nextDevProxy) { + plugins.push(pluginHttpsProxy); + } + if ('testPlugins' in context && context.testPlugins.length > 0) { await Promise.all(context.testPlugins.map(async (testPlugin) => { const plugin = await import(testPlugin); diff --git a/packages/gasket-typescript-tests/test/engine.spec.ts b/packages/gasket-typescript-tests/test/engine.spec.ts index 610d5fa42..fced9ff3c 100644 --- a/packages/gasket-typescript-tests/test/engine.spec.ts +++ b/packages/gasket-typescript-tests/test/engine.spec.ts @@ -95,7 +95,7 @@ describe('@gasket/core', () => { gasket.hook({ event: 'example', handler(_gasket) { - return _gasket.command.id === 'start'; + return _gasket.config.command === 'start'; } }); }); diff --git a/packages/gasket-utils/lib/config.js b/packages/gasket-utils/lib/config.js index 2fb28fb91..8865eeba7 100644 --- a/packages/gasket-utils/lib/config.js +++ b/packages/gasket-utils/lib/config.js @@ -27,7 +27,12 @@ function *getPotentialConfigs(config, { env, commandId }) { const { environments = {}, commands = {}, ...baseConfig } = config; const isLocalEnv = env === 'local'; - yield* getCommandOverrides(commands, commandId); + // Keep commands unless a command id is passed + if (commandId) { + yield* getCommandOverrides(commands, commandId); + } else { + baseConfig.commands = commands; + } yield* getSubEnvironmentOverrides(env, environments); yield* getDevOverrides(isLocalEnv, environments); yield baseConfig; diff --git a/packages/gasket-utils/test/config.test.js b/packages/gasket-utils/test/config.test.js index 2f6642e51..ec6168163 100644 --- a/packages/gasket-utils/test/config.test.js +++ b/packages/gasket-utils/test/config.test.js @@ -227,5 +227,26 @@ describe('applyConfigOverrides', () => { } }); }); + + it('persists commands config if commandId is undefined', () => { + mockConfig.commands = { + start: { + someService: { + url: 'https://some-dev-test.url/' + } + } + }; + + // eslint-disable-next-line no-undefined + mockContext.commandId = undefined; + results = applyConfigOverrides(mockConfig, mockContext); + expect(results).toHaveProperty('commands', { + start: { + someService: { + url: 'https://some-dev-test.url/' + } + } + }); + }) }); });