UNPKG

nx

Version:

The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.

71 lines (70 loc) 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTreeWithEmptyWorkspace = createTreeWithEmptyWorkspace; exports.createTreeWithEmptyV1Workspace = createTreeWithEmptyV1Workspace; const tree_1 = require("../tree"); const workspace_root_1 = require("../../utils/workspace-root"); /** * Keyed by `FormatterType` so adding a formatter fails to compile here until * this helper can seed it, rather than silently producing a workspace with no * config. */ const formatterConfigFiles = { prettier: '.prettierrc', oxfmt: '.oxfmtrc.json', }; /** * Creates a host for testing. * * Defaults to oxfmt deliberately, so generator tests exercise the oxfmt path * rather than the create-nx-workspace default. oxfmt formats * JS, TS, JSON, YAML and Markdown - nothing filters by extension on the way in * - so any spec asserting on generated file *content* is affected. Pass `none` * to assert exactly what the generator wrote, or `prettier` only for a test * that is about prettier itself. */ function createTreeWithEmptyWorkspace(opts = {}) { const tree = new tree_1.FsTree('/virtual', false); // Our unit tests are all written as though they are at the root of a workspace // However, when they are run in a subdirectory of the workspaceRoot, // the relative path between workspaceRoot and the directory the tests are run // is prepended to the paths created in the virtual tree. // Setting this envVar to workspaceRoot prevents this behaviour process.env.INIT_CWD = workspace_root_1.workspaceRoot; return addCommonFiles(tree, opts.layout === 'apps-libs', opts.formatter); } /** * @deprecated use createTreeWithEmptyWorkspace instead */ function createTreeWithEmptyV1Workspace() { throw new Error('Use createTreeWithEmptyWorkspace instead of createTreeWithEmptyV1Workspace'); } function addCommonFiles(tree, addAppsAndLibsFolders, formatter = 'oxfmt') { if (formatter !== 'none') { tree.write(`./${formatterConfigFiles[formatter]}`, JSON.stringify({ singleQuote: true })); } tree.write('/package.json', JSON.stringify({ name: '@proj/source', dependencies: {}, devDependencies: {}, })); tree.write('/nx.json', JSON.stringify({ affected: { defaultBase: 'main', }, targetDefaults: { build: { cache: true, }, lint: { cache: true, }, }, })); tree.write('/tsconfig.base.json', JSON.stringify({ compilerOptions: { paths: {} } })); if (addAppsAndLibsFolders) { tree.write('/apps/.gitignore', ''); tree.write('/libs/.gitignore', ''); } return tree; }