Skip to content

Commit

Permalink
NodeServicePlugin now supports "--serve" and fails if this parameter …
Browse files Browse the repository at this point in the history
…is used without a config file
  • Loading branch information
octogonz committed Jun 7, 2023
1 parent 5c98ded commit 31d1ee5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
30 changes: 23 additions & 7 deletions apps/heft/src/plugins/NodeServicePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { IScopedLogger } from '../pluginFramework/logging/ScopedLogger';
import { CoreConfigFiles } from '../utilities/CoreConfigFiles';

const PLUGIN_NAME: 'node-service-plugin' = 'node-service-plugin';
const SERVE_PARAMETER_LONG_NAME: '--serve' = '--serve';

export interface INodeServicePluginCompleteConfiguration {
commandName: string;
Expand Down Expand Up @@ -92,9 +93,24 @@ export default class NodeServicePlugin implements IHeftTaskPlugin {
// Set this immediately to make it available to the internal methods that use it
this._logger = taskSession.logger;

taskSession.hooks.run.tapPromise(PLUGIN_NAME, async () => {
taskSession.logger.terminal.writeWarningLine('Node services can only be run in watch mode.');
});
const isServeMode: boolean = taskSession.parameters.getFlagParameter(SERVE_PARAMETER_LONG_NAME).value;

if (isServeMode && !taskSession.parameters.watch) {
throw new Error(
`The ${JSON.stringify(
SERVE_PARAMETER_LONG_NAME
)} parameter is only available when running in watch mode.` +
` Try replacing "${taskSession.parsedCommandLine?.unaliasedCommandName}" with` +
` "${taskSession.parsedCommandLine?.unaliasedCommandName}-watch" in your Heft command line.`
);
}

if (!isServeMode) {
taskSession.logger.terminal.writeVerboseLine(
`Not launching the service because the "${SERVE_PARAMETER_LONG_NAME}" parameter was not specified`
);
return;
}

taskSession.hooks.runIncremental.tapPromise(
PLUGIN_NAME,
Expand Down Expand Up @@ -148,20 +164,20 @@ export default class NodeServicePlugin implements IHeftTaskPlugin {
if (this._shellCommand === undefined) {
if (this._configuration.ignoreMissingScript) {
taskSession.logger.terminal.writeLine(
`The plugin is disabled because the project's package.json` +
`The node service cannot be started because the project's package.json` +
` does not have a "${this._configuration.commandName}" script`
);
} else {
throw new Error(
`The node-service task cannot start because the project's package.json ` +
`The node service cannot be started because the project's package.json ` +
`does not have a "${this._configuration.commandName}" script`
);
}
this._pluginEnabled = false;
}
} else {
taskSession.logger.terminal.writeVerboseLine(
'The plugin is disabled because its config file was not found: ' +
throw new Error(
'The node service cannot be started because the task config file was not found: ' +
CoreConfigFiles.nodeServiceConfigurationFile.projectRelativeFilePath
);
}
Expand Down
11 changes: 3 additions & 8 deletions build-tests/heft-fastify-test/config/heft.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
"taskPlugin": {
"pluginPackage": "@rushstack/heft-lint-plugin"
}
}
}
},

"serve": {
"phaseDependencies": ["build"],
"tasksByName": {
"fastify": {
},
"node-service": {
"taskDependencies": ["typescript"],
"taskEvent": {
"eventKind": "nodeService"
}
Expand Down
2 changes: 1 addition & 1 deletion build-tests/heft-fastify-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"scripts": {
"build": "heft build --clean",
"start": "heft serve-watch",
"start": "heft build-watch --serve",
"serve": "node lib/start.js",
"_phase:build": "heft run --only build -- --clean"
},
Expand Down

0 comments on commit 31d1ee5

Please sign in to comment.