@nx/storybook
Version:
36 lines (35 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.editRootTsConfig = editRootTsConfig;
const devkit_1 = require("@nx/devkit");
const js_1 = require("@nx/js");
/**
* This is a temporary fix for Storybook to support TypeScript configuration files.
* The issue is that if there is a root tsconfig.json file, Storybook will use it, and
* ignore the tsconfig.json file in the .storybook folder. This results in module being set
* to esnext, and Storybook does not recognise the main.ts code as a module.
*/
function editRootTsConfig(tree) {
if (!tree.exists('tsconfig.json')) {
return;
}
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
json['ts-node'] ??= {};
json['ts-node'].compilerOptions ??= {};
json['ts-node'].compilerOptions.module = 'commonjs';
json['ts-node'].compilerOptions.moduleResolution = 'node10';
if (json.compilerOptions?.customConditions) {
json['ts-node'].compilerOptions.customConditions = null;
}
else {
const rootTsconfigFile = (0, js_1.getRootTsConfigFileName)(tree);
if (rootTsconfigFile) {
const rootTsconfigJson = (0, devkit_1.readJson)(tree, rootTsconfigFile);
if (rootTsconfigJson.compilerOptions?.customConditions) {
json['ts-node'].compilerOptions.customConditions = null;
}
}
}
return json;
});
}