UNPKG

@rushstack/heft

Version:

Build all your JavaScript projects the same way: A way that works.

26 lines 1.25 kB
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. import * as path from 'node:path'; const PLUGIN_NAME = 'run-script-plugin'; export default class RunScriptPlugin { apply(heftTaskSession, heftConfiguration, pluginOptions) { heftTaskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions) => { await this._runScriptAsync(heftTaskSession, heftConfiguration, pluginOptions, runOptions); }); } async _runScriptAsync(heftTaskSession, heftConfiguration, pluginOptions, runOptions) { const resolvedModulePath = path.resolve(heftConfiguration.buildFolderPath, pluginOptions.scriptPath); const runScript = await import(resolvedModulePath); if (!runScript.runAsync) { throw new Error(`The script at ${JSON.stringify(resolvedModulePath)} doesn\'t export a "runAsync" function.`); } const runScriptOptions = { heftTaskSession, heftConfiguration, runOptions, scriptOptions: pluginOptions.scriptOptions }; await runScript.runAsync(runScriptOptions); } } //# sourceMappingURL=RunScriptPlugin.js.map