You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
2.7 KiB

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeneratePackageJsonPlugin = void 0;
const devkit_1 = require("@nx/devkit");
const js_1 = require("@nx/js");
const core_1 = require("@rspack/core");
const pluginName = 'GeneratePackageJsonPlugin';
class GeneratePackageJsonPlugin {
constructor(options, context) {
this.options = options;
this.context = context;
this.projectGraph = context.projectGraph;
}
apply(compiler) {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.processAssets.tap({
name: pluginName,
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
}, () => {
const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.context.root, this.context.projectName, this.projectGraph);
const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
.importHelpers;
const shouldAddHelperDependency = importHelpers &&
helperDependencies.every((dep) => dep.target !== js_1.HelperDependency.tsc);
if (shouldAddHelperDependency) {
helperDependencies.push({
type: 'static',
source: this.context.projectName,
target: js_1.HelperDependency.tsc,
});
}
const packageJson = (0, js_1.createPackageJson)(this.context.projectName, this.projectGraph, {
target: this.context.targetName,
root: this.context.root,
isProduction: true,
helperDependencies: helperDependencies.map((dep) => dep.target),
});
packageJson.main = packageJson.main ?? this.options.outputFileName;
compilation.emitAsset('package.json', new core_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
if (packageManager === 'bun') {
compilation
.getLogger('GeneratePackageJsonPlugin')
.warn('Bun lockfile generation is not supported. Only package.json will be generated.');
}
else {
compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new core_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
}
});
});
}
}
exports.GeneratePackageJsonPlugin = GeneratePackageJsonPlugin;