import type { HeftConfiguration, IHeftTaskPlugin, IHeftTaskSession } from '@rushstack/heft'; /** * The EjectWebpackPlugin is responsible for ejecting the webpack config in the Heft-based SPFx project tooling. */ export default class EjectWebpackPlugin implements IHeftTaskPlugin { /** * The in-memory file system used to store the changes made by the eject script. * This file system is used to track changes to the project files and commit them at the end of the eject process. * This is so we don't leave the project in a dirty state if the eject fails. */ private _fs; private _terminal; private _heftConfiguration; apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration): void; /** * Ejects the project from Heft to Webpack. * This method updates the heft.json, package.json, and .yo-rc.json files, * and creates a new webpack.config.js file. * It also cleans up unused config files. * At the end it runs npm install (un) */ private _ejectAsync; /** * Updates the heft.json file. * This method attempts to preserve the existing heft.json configuration, * but it may overwrite custom modifications. * * - Removes the "extends" property so that the config no longer extends the SPFx heft config * - Adds (or updates) the build phase with the following: * - Removes the "copy-strings" task from the build phase, if it exists * - Sets the cleanFiles property of the build so that the dist folder is cleaned * - Adds (or updates) the build phase with a few tasks: * - lint: runs the heft-lint-plugin * - webpack: runs the heft-webpack5-plugin * - Adds (or updates) the package-solution phase with the heft-spfx-plugin * - Adds (or updates) the test phase with the heft-jest-plugin */ private _updateHeftJsonAsync; /** * Adds a new Webpack config file to the project. * The config file is generated using a template, incorporating existing bundle information from the config.json file. * Also converts localized .js files to .resjson files containing only the JSON. */ private _addWebpackConfigAsync; /** * Cleans up no-longer-needed config files. * * @remarks * With Heft, we have a lot of config files that direct the rig on what to do. * With Webpack, we specify most of these options directly to the webpack plugins (in the webpack.config.js file). */ private _cleanupUnusedConfigsAsync; /** * Updates the package.json file. * This adds several dependencies to the package.json file, including: * - Heft webpack plugins: * - heft-webpack5-plugin * - heft-lint-plugin * - heft-sass-plugin * - heft-typescript-plugin * - heft-dev-cert-plugin * - heft-jest-plugin * - heft-webpack5-plugin * - Webpack plugins: * - sass-loader * - style-loader * - ts-loader * - Dependencies: * - cors * - express * - glob * - sass * - typescript * - webpack * * @remarks * These dependencies are gathered from \@microsoft/spfx-heft-eject's package.json, where * they are listed as optionalDependencies. * This is done so that they are automatically kept in-sync with the tooling used in other places in SPFx * in future releases of the eject script. */ private _updatePackageJsonAsync; /** * Updates the .yo-rc.json file. * We store a boolean indicating this project has been ejected, in case the yeoman generator * is attempted to be used on this project in the future. * * The Yeoman generator will stop working for this project after ejecting. */ private _updateYeomanAsync; /** * Runs npm install to install the new dependencies added to the package.json file. * This is done using the spawnSync method, which runs the command synchronously for simplicity. */ private _npmInstallAsync; /** * Performs a deep merge of two objects. * The target object is modified and returned. * Arrays are replaced entirely rather than merged. */ private _deepMerge; /** * Checks if a value is a plain object (not an array or null) */ private _isObject; /** * Utility function to show the user which files in the in-memory file system are pending changes. */ private _printFileChanges; } //# sourceMappingURL=EjectWebpackPlugin.d.ts.map