@storm-software/unbuild
Version:
A package containing `unbuild` utilities for building Storm Software libraries and applications
107 lines (87 loc) • 3.99 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
var _chunkOHNKWQUWcjs = require('./chunk-OHNKWQUW.cjs');
// src/plugins/tsc.ts
var _devkit = require('@nx/devkit');
var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
var _compilerhelperdependency = require('@nx/js/src/utils/compiler-helper-dependency');
var _rollupplugintypescript2 = require('rollup-plugin-typescript2'); var _rollupplugintypescript22 = _interopRequireDefault(_rollupplugintypescript2);
// src/utilities/helpers.ts
var _path = require('path');
var _url = require('url');
var _typescript = require('typescript'); var _typescript2 = _interopRequireDefault(_typescript);
async function loadConfig(configPath) {
if (!/\.(js|mjs)$/.test(_path.extname.call(void 0, configPath))) {
throw new Error("Unsupported config file format");
}
return Promise.resolve().then(() => _interopRequireWildcard(require(_url.pathToFileURL.call(void 0, configPath).toString()))).then(
(config) => config.default
);
}
async function createTsCompilerOptions(config, tsConfigPath, projectRoot, dependencies) {
const tsConfigFile = _typescript2.default.readConfigFile(
_devkit.joinPathFragments.call(void 0, config.workspaceRoot, projectRoot, tsConfigPath),
_typescript2.default.sys.readFile
);
const tsConfig = _typescript2.default.parseJsonConfigFileContent(
tsConfigFile.config,
_typescript2.default.sys,
_path.dirname.call(void 0, _devkit.joinPathFragments.call(void 0, config.workspaceRoot, projectRoot, tsConfigPath))
);
const compilerOptions = {
rootDir: projectRoot,
declaration: true,
paths: _buildablelibsutils.computeCompilerOptionsPaths.call(void 0, tsConfig, _nullishCoalesce(dependencies, () => ( [])))
};
_chunkOHNKWQUWcjs.writeTrace.call(void 0, compilerOptions, config);
return compilerOptions;
}
// src/plugins/tsc.ts
var tscPlugin = async (options) => {
let projectGraph;
try {
projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
} catch (e) {
await _devkit.createProjectGraphAsync.call(void 0, );
projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
}
if (!projectGraph) {
throw new Error(
"The build process failed because the project graph is not available. Please run the build command again."
);
}
const result = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0,
void 0,
projectGraph,
options.config.workspaceRoot,
options.projectName,
process.env.NX_TASK_TARGET_TARGET || "build",
process.env.NX_TASK_TARGET_CONFIGURATION || "production",
true
);
let dependencies = result.dependencies;
const tsLibDependency = _compilerhelperdependency.getHelperDependency.call(void 0,
_compilerhelperdependency.HelperDependency.tsc,
options.tsconfig,
dependencies,
projectGraph,
true
);
if (tsLibDependency) {
dependencies = dependencies.filter(
(deps) => deps.name !== tsLibDependency.name
);
dependencies.push(tsLibDependency);
}
const compilerOptions = await createTsCompilerOptions(
options.config,
options.tsconfig,
options.projectRoot,
dependencies
);
return _rollupplugintypescript22.default.call(void 0, {
check: options.declaration !== false,
tsconfig: options.tsconfig,
tsconfigOverride: compilerOptions
});
};
exports.loadConfig = loadConfig; exports.createTsCompilerOptions = createTsCompilerOptions; exports.tscPlugin = tscPlugin;