From 8da70e8a2e49207c9f989eee6ca6b81a6a5cf3a0 Mon Sep 17 00:00:00 2001 From: Sander Verweij Date: Sun, 13 Aug 2023 20:40:51 +0200 Subject: [PATCH] refactor(cli): rewrites config scaffolding without handlebars (#830) ## Description - rewrites config scaffolding ('--init') without handlebars ## Motivation and Context - same as the other PR's replacing handlebars with vanilla js ## How Has This Been Tested? - [x] green ci ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [x] Refactor (non-breaking change which fixes an issue without changing functionality) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist - [x] :book: - My change doesn't require a documentation update, or ... - it _does_ and I have updated it - [x] :balance_scale: - The contribution will be subject to [The MIT license](https://github.com/sverweij/dependency-cruiser/blob/main/LICENSE), and I'm OK with that. - The contribution is my own original work. - I am ok with the stuff in [**CONTRIBUTING.md**](https://github.com/sverweij/dependency-cruiser/blob/main/.github/CONTRIBUTING.md). --- Makefile | 3 +- src/cli/init-config/build-config.mjs | 174 ++++++++++++++++-- ...ig.js.template.hbs => config-template.mjs} | 97 ++-------- src/cli/init-config/config.js.template.js | 1 - 4 files changed, 174 insertions(+), 101 deletions(-) rename src/cli/init-config/{config.js.template.hbs => config-template.mjs} (87%) delete mode 100644 src/cli/init-config/config.js.template.js diff --git a/Makefile b/Makefile index 54242fc0e..07297e598 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ .SUFFIXES: .js .css .html NODE=node RM=rm -f -GENERATED_SOURCES=src/cli/init-config/config.js.template.js \ - src/report/dot/dot.template.js \ +GENERATED_SOURCES=src/report/dot/dot.template.js \ src/schema/baseline-violations.schema.mjs \ src/schema/configuration.schema.mjs \ src/schema/cruise-result.schema.mjs \ diff --git a/src/cli/init-config/build-config.mjs b/src/cli/init-config/build-config.mjs index f7d2167be..f6a41a4bf 100644 --- a/src/cli/init-config/build-config.mjs +++ b/src/cli/init-config/build-config.mjs @@ -1,9 +1,6 @@ // @ts-check -import Handlebars from "handlebars/runtime.js"; import { folderNameArrayToRE } from "./utl.mjs"; - -/* eslint import/no-unassigned-import: 0 */ -await import("./config.js.template.js"); +import configTemplate from "./config-template.mjs"; /** * @param {string} pString @@ -24,25 +21,166 @@ function extensionsToString(pExtensions) { return ""; } +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildNotToTestRule(pInitOptions) { + const lNotToTestRule = `{ + name: 'not-to-test', + comment: + "This module depends on code within a folder that should only contain tests. As tests don't " + + "implement functionality this is odd. Either you're writing a test outside the test folder " + + "or there's something in the test folder that isn't a test.", + severity: 'error', + from: { + pathNot: '{{testLocationRE}}' + }, + to: { + path: '{{testLocationRE}}' + } + },`; + return pInitOptions.hasTestsOutsideSource + ? lNotToTestRule.replace( + /{{testLocationRE}}/g, + folderNameArrayToRE(pInitOptions?.testLocation ?? []), + ) + : ""; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildTsPreCompilationDepsAttribute(pInitOptions) { + return pInitOptions.tsPreCompilationDeps + ? "tsPreCompilationDeps: true," + : "// tsPreCompilationDeps: false,"; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildCombinedDependenciesAttribute(pInitOptions) { + return pInitOptions.combinedDependencies + ? "combinedDependencies: true," + : "// combinedDependencies: false,"; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildTsOrJsConfigAttribute(pInitOptions) { + if (pInitOptions.useTsConfig) { + return `tsConfig: { + fileName: '${pInitOptions.tsConfig}' + },`; + } + if (pInitOptions.useJsConfig) { + return `tsConfig: { + fileName: '${pInitOptions.jsConfig}' + },`; + } + return `// tsConfig: { + // fileName: 'tsconfig.json' + // },`; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildWebpackConfigAttribute(pInitOptions) { + return pInitOptions.webpackConfig + ? `webpackConfig: { + fileName: '${pInitOptions.webpackConfig}', + // env: {}, + // arguments: {} + },` + : `// webpackConfig: { + // fileName: 'webpack.config.js', + // env: {}, + // arguments: {} + // },`; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildBabelConfigAttribute(pInitOptions) { + return pInitOptions.babelConfig + ? `babelConfig: { + fileName: '${pInitOptions.babelConfig}' + },` + : `// babelConfig: { + // fileName: '.babelrc', + // },`; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildExtensionsAttribute(pInitOptions) { + return pInitOptions.specifyResolutionExtensions + ? `extensions: ${extensionsToString(pInitOptions.resolutionExtensions)},` + : `// extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],`; +} + +/** + * @param {import("./types.js").IInitConfig} pInitOptions + * @returns {string} + */ +function buildMainFieldsAttribute(pInitOptions) { + return pInitOptions.usesTypeScript + ? `mainFields: ["main", "types"],` + : `// mainFields: ["main", "types"],`; +} + /** * Creates a .dependency-cruiser config with a set of basic validations * to the current directory. * - * @param {import("./types.js").IInitConfig} pNormalizedInitOptions Options that influence the shape of + * @param {import("./types.js").IInitConfig} pInitOptions ('Normalized') options that influence the shape of * the configuration * @returns {string} the configuration as a string */ - -export default function buildConfig(pNormalizedInitOptions) { - return Handlebars.templates["config.js.template.hbs"]({ - ...pNormalizedInitOptions, - - sourceLocationRE: folderNameArrayToRE( - pNormalizedInitOptions.sourceLocation - ), - testLocationRE: folderNameArrayToRE(pNormalizedInitOptions.testLocation), - resolutionExtensionsAsString: extensionsToString( - pNormalizedInitOptions.resolutionExtensions - ), - }); +export default function buildConfig(pInitOptions) { + return configTemplate + .replace( + /{{sourceLocationRE}}/g, + folderNameArrayToRE(pInitOptions.sourceLocation), + ) + .replace( + /{{resolutionExtensionsAsString}}/g, + extensionsToString(pInitOptions.resolutionExtensions), + ) + .replace("{{notToTestRule}}", buildNotToTestRule(pInitOptions)) + .replace( + "{{tsPreCompilationDepsAttribute}}", + buildTsPreCompilationDepsAttribute(pInitOptions), + ) + .replace( + "{{combinedDependenciesAttribute}}", + buildCombinedDependenciesAttribute(pInitOptions), + ) + .replace( + "{{tsOrJsConfigAttribute}}", + buildTsOrJsConfigAttribute(pInitOptions), + ) + .replace( + "{{webpackConfigAttribute}}", + buildWebpackConfigAttribute(pInitOptions), + ) + .replace( + "{{babelConfigAttribute}}", + buildBabelConfigAttribute(pInitOptions), + ) + .replace("{{extensionsAttribute}}", buildExtensionsAttribute(pInitOptions)) + .replace("{{mainFieldsAttribute}}", buildMainFieldsAttribute(pInitOptions)) + .replace("{{version}}", pInitOptions.version) + .replace("{{date}}", pInitOptions.date); } diff --git a/src/cli/init-config/config.js.template.hbs b/src/cli/init-config/config-template.mjs similarity index 87% rename from src/cli/init-config/config.js.template.hbs rename to src/cli/init-config/config-template.mjs index 96ed1933e..6957053de 100644 --- a/src/cli/init-config/config.js.template.hbs +++ b/src/cli/init-config/config-template.mjs @@ -1,4 +1,5 @@ -/** @type {import('dependency-cruiser').IConfiguration} */ +/* eslint-disable max-lines, no-useless-escape */ +export default `/** @type {import('dependency-cruiser').IConfiguration} */ module.exports = { forbidden: [ { @@ -125,22 +126,7 @@ module.exports = { }, /* rules you might want to tweak for your specific situation: */ - {{#hasTestsOutsideSource}} - { - name: 'not-to-test', - comment: - "This module depends on code within a folder that should only contain tests. As tests don't " + - "implement functionality this is odd. Either you're writing a test outside the test folder " + - "or there's something in the test folder that isn't a test.", - severity: 'error', - from: { - pathNot: '{{testLocationRE}}' - }, - to: { - path: '{{testLocationRE}}' - } - }, - {{/hasTestsOutsideSource}} + {{notToTestRule}} { name: 'not-to-spec', comment: @@ -239,7 +225,7 @@ module.exports = { // moduleSystems: ['amd', 'cjs', 'es6', 'tsd'], /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/develop/' - to open it on your online repo or `vscode://file/${process.cwd()}/` to + to open it on your online repo or \`vscode://file/$\{process.cwd()}/\` to open it in visual studio code), */ // prefix: '', @@ -248,11 +234,7 @@ module.exports = { true: also detect dependencies that only exist before typescript-to-javascript compilation "specify": for each dependency identify whether it only exists before compilation or also after */ - {{#if tsPreCompilationDeps}} - tsPreCompilationDeps: true, - {{^}} - // tsPreCompilationDeps: false, - {{/if}} + {{tsPreCompilationDepsAttribute}} /* list of extensions to scan that aren't javascript or compile-to-javascript. @@ -265,11 +247,7 @@ module.exports = { folder the cruise is initiated from. Useful for how (some) mono-repos manage dependencies & dependency definitions. */ - {{#if combinedDependencies}} - combinedDependencies: true, - {{^}} - // combinedDependencies: false, - {{/if}} + {{combinedDependenciesAttribute}} /* if true leave symlinks untouched, otherwise use the realpath */ // preserveSymlinks: false, @@ -282,21 +260,7 @@ module.exports = { dependency-cruiser's current working directory). When not provided defaults to './tsconfig.json'. */ - {{#if useTsConfig}} - tsConfig: { - fileName: '{{tsConfig}}' - }, - {{^}} - {{#if useJsConfig}} - tsConfig: { - fileName: '{{jsConfig}}' - }, - {{^}} - // tsConfig: { - // fileName: './tsconfig.json' - // }, - {{/if}} - {{/if}} + {{tsOrJsConfigAttribute}} /* Webpack configuration to use to get resolve options from. @@ -304,23 +268,11 @@ module.exports = { to dependency-cruiser's current working directory. When not provided defaults to './webpack.conf.js'. - The (optional) `env` and `arguments` attributes contain the parameters to be passed if + The (optional) \`env\` and \`arguments\` attributes contain the parameters to be passed if your webpack config is a function and takes them (see webpack documentation for details) */ - {{#if useWebpackConfig}} - webpackConfig: { - fileName: '{{webpackConfig}}', - // env: {}, - // arguments: {}, - }, - {{^}} - // webpackConfig: { - // fileName: './webpack.config.js', - // env: {}, - // arguments: {}, - // }, - {{/if}} + {{webpackConfigAttribute}} /* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use for compilation (and whatever other naughty things babel plugins do to @@ -328,15 +280,7 @@ module.exports = { behavior a bit over time (e.g. more precise results for used module systems) without dependency-cruiser getting a major version bump. */ - {{#if useBabelConfig}} - babelConfig: { - fileName: '{{babelConfig}}' - }, - {{^}} - // babelConfig: { - // fileName: './.babelrc' - // }, - {{/if}} + {{babelConfigAttribute}} /* List of strings you have in use in addition to cjs/ es6 requires & imports to declare module dependencies. Use this e.g. if you've @@ -356,13 +300,13 @@ module.exports = { ['exports'] when you use packages that use such a field and your environment supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack). - If you have an `exportsFields` attribute in your webpack config, that one + If you have an \`exportsFields\` attribute in your webpack config, that one will have precedence over the one specified here. */ exportsFields: ["exports"], /* List of conditions to check for in the exports field. e.g. use ['imports'] if you're only interested in exposed es6 modules, ['require'] for commonjs, - or all conditions at once `(['import', 'require', 'node', 'default']`) + or all conditions at once \`(['import', 'require', 'node', 'default']\`) if anything goes for you. Only works when the 'exportsFields' array is non-empty. @@ -372,18 +316,14 @@ module.exports = { conditionNames: ["import", "require", "node", "default"], /* The extensions, by default are the same as the ones dependency-cruiser - can access (run `npx depcruise --info` to see which ones that are in + can access (run \`npx depcruise --info\` to see which ones that are in _your_ environment. If that list is larger than what you need (e.g. it contains .js, .jsx, .ts, .tsx, .cts, .mts - but you don't use TypeScript you can pass just the extensions you actually use (e.g. [".js", ".jsx"]). This can speed up the most expensive step in dependency cruising (module resolution) quite a bit. */ - {{#if specifyResolutionExtensions}} - extensions: {{{resolutionExtensionsAsString}}}, - {{^}} - // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], - {{/if}} + {{extensionsAttribute}} /* If your TypeScript project makes use of types specified in 'types' fields in package.jsons of external dependencies, specify "types" @@ -392,11 +332,7 @@ module.exports = { this if you're not sure, but still use TypeScript. In a future version of dependency-cruiser this will likely become the default. */ - {{#if usesTypeScript}} - mainFields: ["main", "types"], - {{^}} - // mainFields: ["main", "types"], - {{/if}} + {{mainFieldsAttribute}} }, reporterOptions: { dot: { @@ -483,7 +419,7 @@ module.exports = { archi: { /* pattern of modules that can be consolidated in the high level graphical dependency graph. If you use the high level graphical - dependency graph reporter (`archi`) you probably want to tweak + dependency graph reporter (\`archi\`) you probably want to tweak this collapsePattern to your situation. */ collapsePattern: '^(packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+|node_modules/(@[^/]+/[^/]+|[^/]+)', @@ -504,3 +440,4 @@ module.exports = { } }; // generated: dependency-cruiser@{{version}} on {{date}} +`; diff --git a/src/cli/init-config/config.js.template.js b/src/cli/init-config/config.js.template.js deleted file mode 100644 index 691b751ff..000000000 --- a/src/cli/init-config/config.js.template.js +++ /dev/null @@ -1 +0,0 @@ -var Handlebars=require("handlebars/runtime"),template=Handlebars.template,templates=Handlebars.templates=Handlebars.templates||{};templates["config.js.template.hbs"]=template({1:function(e,n,t,o,s){var i,r=null!=n?n:e.nullContext||{},a=e.hooks.helperMissing,l="function",c=e.escapeExpression,e=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" {\n name: 'not-to-test',\n comment:\n \"This module depends on code within a folder that should only contain tests. As tests don't \" +\n \"implement functionality this is odd. Either you're writing a test outside the test folder \" +\n \"or there's something in the test folder that isn't a test.\",\n severity: 'error',\n from: {\n pathNot: '"+c(typeof(i=null!=(i=e(t,"testLocationRE")||(null!=n?e(n,"testLocationRE"):n))?i:a)==l?i.call(r,{name:"testLocationRE",hash:{},data:s,loc:{start:{line:137,column:18},end:{line:137,column:36}}}):i)+"'\n },\n to: {\n path: '"+c(typeof(i=null!=(i=e(t,"testLocationRE")||(null!=n?e(n,"testLocationRE"):n))?i:a)==l?i.call(r,{name:"testLocationRE",hash:{},data:s,loc:{start:{line:140,column:15},end:{line:140,column:33}}}):i)+"'\n }\n },\n"},3:function(e,n,t,o,s){return" tsPreCompilationDeps: true,\n"},5:function(e,n,t,o,s){return" // tsPreCompilationDeps: false,\n"},7:function(e,n,t,o,s){return" combinedDependencies: true,\n"},9:function(e,n,t,o,s){return" // combinedDependencies: false,\n"},11:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" tsConfig: {\n fileName: '"+e.escapeExpression("function"==typeof(t=null!=(t=i(t,"tsConfig")||(null!=n?i(n,"tsConfig"):n))?t:e.hooks.helperMissing)?t.call(null!=n?n:e.nullContext||{},{name:"tsConfig",hash:{},data:s,loc:{start:{line:287,column:17},end:{line:287,column:29}}}):t)+"'\n },\n"},13:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return null!=(t=i(t,"if").call(null!=n?n:e.nullContext||{},null!=n?i(n,"useJsConfig"):n,{name:"if",hash:{},fn:e.program(14,s,0),inverse:e.program(16,s,0),data:s,loc:{start:{line:290,column:6},end:{line:298,column:13}}}))?t:""},14:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" tsConfig: {\n fileName: '"+e.escapeExpression("function"==typeof(t=null!=(t=i(t,"jsConfig")||(null!=n?i(n,"jsConfig"):n))?t:e.hooks.helperMissing)?t.call(null!=n?n:e.nullContext||{},{name:"jsConfig",hash:{},data:s,loc:{start:{line:292,column:17},end:{line:292,column:29}}}):t)+"'\n },\n"},16:function(e,n,t,o,s){return" // tsConfig: {\n // fileName: './tsconfig.json'\n // },\n"},18:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" webpackConfig: {\n fileName: '"+e.escapeExpression("function"==typeof(t=null!=(t=i(t,"webpackConfig")||(null!=n?i(n,"webpackConfig"):n))?t:e.hooks.helperMissing)?t.call(null!=n?n:e.nullContext||{},{name:"webpackConfig",hash:{},data:s,loc:{start:{line:313,column:17},end:{line:313,column:34}}}):t)+"',\n // env: {},\n // arguments: {},\n },\n"},20:function(e,n,t,o,s){return" // webpackConfig: {\n // fileName: './webpack.config.js',\n // env: {},\n // arguments: {},\n // },\n"},22:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" babelConfig: {\n fileName: '"+e.escapeExpression("function"==typeof(t=null!=(t=i(t,"babelConfig")||(null!=n?i(n,"babelConfig"):n))?t:e.hooks.helperMissing)?t.call(null!=n?n:e.nullContext||{},{name:"babelConfig",hash:{},data:s,loc:{start:{line:333,column:17},end:{line:333,column:32}}}):t)+"'\n },\n"},24:function(e,n,t,o,s){return" // babelConfig: {\n // fileName: './.babelrc'\n // },\n"},26:function(e,n,t,o,s){var i=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]};return" extensions: "+(null!=(i="function"==typeof(t=null!=(t=i(t,"resolutionExtensionsAsString")||(null!=n?i(n,"resolutionExtensionsAsString"):n))?t:e.hooks.helperMissing)?t.call(null!=n?n:e.nullContext||{},{name:"resolutionExtensionsAsString",hash:{},data:s,loc:{start:{line:383,column:18},end:{line:383,column:52}}}):t)?i:"")+",\n"},28:function(e,n,t,o,s){return' // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"],\n'},30:function(e,n,t,o,s){return' mainFields: ["main", "types"],\n'},32:function(e,n,t,o,s){return' // mainFields: ["main", "types"],\n'},compiler:[8,">= 4.3.0"],main:function(e,n,t,o,s){var i=null!=n?n:e.nullContext||{},r=e.hooks.helperMissing,a="function",l=e.escapeExpression,c=e.lookupProperty||function(e,n){if(Object.prototype.hasOwnProperty.call(e,n))return e[n]},p="/** @type {import('dependency-cruiser').IConfiguration} */\nmodule.exports = {\n forbidden: [\n {\n name: 'no-circular',\n severity: 'warn',\n comment:\n 'This dependency is part of a circular relationship. You might want to revise ' +\n 'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ',\n from: {},\n to: {\n circular: true\n }\n },\n {\n name: 'no-orphans',\n comment:\n \"This is an orphan module - it's likely not used (anymore?). Either use it or \" +\n \"remove it. If it's logical this module is an orphan (i.e. it's a config file), \" +\n \"add an exception for it in your dependency-cruiser configuration. By default \" +\n \"this rule does not scrutinize dot-files (e.g. .eslintrc.js), TypeScript declaration \" +\n \"files (.d.ts), tsconfig.json and some of the babel and webpack configs.\",\n severity: 'warn',\n from: {\n orphan: true,\n pathNot: [\n '(^|/)\\\\.[^/]+\\\\.(js|cjs|mjs|ts|json)$', // dot files\n '\\\\.d\\\\.ts$', // TypeScript declaration files\n '(^|/)tsconfig\\\\.json$', // TypeScript config\n '(^|/)(babel|webpack)\\\\.config\\\\.(js|cjs|mjs|ts|json)$' // other configs\n ]\n },\n to: {},\n },\n {\n name: 'no-deprecated-core',\n comment:\n 'A module depends on a node core module that has been deprecated. Find an alternative - these are ' +\n \"bound to exist - node doesn't deprecate lightly.\",\n severity: 'warn',\n from: {},\n to: {\n dependencyTypes: [\n 'core'\n ],\n path: [\n '^(v8\\/tools\\/codemap)$',\n '^(v8\\/tools\\/consarray)$',\n '^(v8\\/tools\\/csvparser)$',\n '^(v8\\/tools\\/logreader)$',\n '^(v8\\/tools\\/profile_view)$',\n '^(v8\\/tools\\/profile)$',\n '^(v8\\/tools\\/SourceMap)$',\n '^(v8\\/tools\\/splaytree)$',\n '^(v8\\/tools\\/tickprocessor-driver)$',\n '^(v8\\/tools\\/tickprocessor)$',\n '^(node-inspect\\/lib\\/_inspect)$',\n '^(node-inspect\\/lib\\/internal\\/inspect_client)$',\n '^(node-inspect\\/lib\\/internal\\/inspect_repl)$',\n '^(async_hooks)$',\n '^(punycode)$',\n '^(domain)$',\n '^(constants)$',\n '^(sys)$',\n '^(_linklist)$',\n '^(_stream_wrap)$'\n ],\n }\n },\n {\n name: 'not-to-deprecated',\n comment:\n 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' +\n 'version of that module, or find an alternative. Deprecated modules are a security risk.',\n severity: 'warn',\n from: {},\n to: {\n dependencyTypes: [\n 'deprecated'\n ]\n }\n },\n {\n name: 'no-non-package-json',\n severity: 'error',\n comment:\n \"This module depends on an npm package that isn't in the 'dependencies' section of your package.json. \" +\n \"That's problematic as the package either (1) won't be available on live (2 - worse) will be \" +\n \"available on live with an non-guaranteed version. Fix it by adding the package to the dependencies \" +\n \"in your package.json.\",\n from: {},\n to: {\n dependencyTypes: [\n 'npm-no-pkg',\n 'npm-unknown'\n ]\n }\n },\n {\n name: 'not-to-unresolvable',\n comment:\n \"This module depends on a module that cannot be found ('resolved to disk'). If it's an npm \" +\n 'module: add it to your package.json. In all other cases you likely already know what to do.',\n severity: 'error',\n from: {},\n to: {\n couldNotResolve: true\n }\n },\n {\n name: 'no-duplicate-dep-types',\n comment:\n \"Likely this module depends on an external ('npm') package that occurs more than once \" +\n \"in your package.json i.e. bot as a devDependencies and in dependencies. This will cause \" +\n \"maintenance problems later on.\",\n severity: 'warn',\n from: {},\n to: {\n moreThanOneDependencyType: true,\n // as it's pretty common to have a type import be a type only import \n // _and_ (e.g.) a devDependency - don't consider type-only dependency\n // types for this rule\n dependencyTypesNot: [\"type-only\"]\n }\n },\n\n /* rules you might want to tweak for your specific situation: */\n",u=null!=(u=c(t,"hasTestsOutsideSource")||(null!=n?c(n,"hasTestsOutsideSource"):n))?u:r,d={name:"hasTestsOutsideSource",hash:{},fn:e.program(1,s,0),inverse:e.noop,data:s,loc:{start:{line:128,column:4},end:{line:143,column:30}}},h=typeof u==a?u.call(i,d):u;return null!=(h=c(t,"hasTestsOutsideSource")?h:e.hooks.blockHelperMissing.call(n,h,d))&&(p+=h),p+" {\n name: 'not-to-spec',\n comment:\n 'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +\n \"If there's something in a spec that's of use to other modules, it doesn't have that single \" +\n 'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',\n severity: 'error',\n from: {},\n to: {\n path: '\\\\.(spec|test)\\\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\\\.md)$'\n }\n },\n {\n name: 'not-to-dev-dep',\n severity: 'error',\n comment:\n \"This module depends on an npm package from the 'devDependencies' section of your \" +\n 'package.json. It looks like something that ships to production, though. To prevent problems ' +\n \"with npm packages that aren't there on production declare it (only!) in the 'dependencies'\" +\n 'section of your package.json. If this module is development only - add it to the ' +\n 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',\n from: {\n path: '"+l(typeof(u=null!=(u=c(t,"sourceLocationRE")||(null!=n?c(n,"sourceLocationRE"):n))?u:r)==a?u.call(i,{name:"sourceLocationRE",hash:{},data:s,loc:{start:{line:166,column:15},end:{line:166,column:35}}}):u)+"',\n pathNot: '\\\\.(spec|test)\\\\.(js|mjs|cjs|ts|ls|coffee|litcoffee|coffee\\\\.md)$'\n },\n to: {\n dependencyTypes: [\n 'npm-dev'\n ]\n }\n },\n {\n name: 'optional-deps-used',\n severity: 'info',\n comment:\n \"This module depends on an npm package that is declared as an optional dependency \" +\n \"in your package.json. As this makes sense in limited situations only, it's flagged here. \" +\n \"If you're using an optional dependency here by design - add an exception to your\" +\n \"dependency-cruiser configuration.\",\n from: {},\n to: {\n dependencyTypes: [\n 'npm-optional'\n ]\n }\n },\n {\n name: 'peer-deps-used',\n comment:\n \"This module depends on an npm package that is declared as a peer dependency \" +\n \"in your package.json. This makes sense if your package is e.g. a plugin, but in \" +\n \"other cases - maybe not so much. If the use of a peer dependency is intentional \" +\n \"add an exception to your dependency-cruiser configuration.\",\n severity: 'warn',\n from: {},\n to: {\n dependencyTypes: [\n 'npm-peer'\n ]\n }\n }\n ],\n options: {\n\n /* conditions specifying which files not to follow further when encountered:\n - path: a regular expression to match\n - dependencyTypes: see https://github.com/sverweij/dependency-cruiser/blob/main/doc/rules-reference.md#dependencytypes-and-dependencytypesnot\n for a complete list\n */\n doNotFollow: {\n path: 'node_modules'\n },\n\n /* conditions specifying which dependencies to exclude\n - path: a regular expression to match\n - dynamic: a boolean indicating whether to ignore dynamic (true) or static (false) dependencies.\n leave out if you want to exclude neither (recommended!)\n */\n // exclude : {\n // path: '',\n // dynamic: true\n // },\n\n /* pattern specifying which files to include (regular expression)\n dependency-cruiser will skip everything not matching this pattern\n */\n // includeOnly : '',\n\n /* dependency-cruiser will include modules matching against the focus\n regular expression in its output, as well as their neighbours (direct\n dependencies and dependents)\n */\n // focus : '',\n\n /* list of module systems to cruise */\n // moduleSystems: ['amd', 'cjs', 'es6', 'tsd'],\n\n /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/develop/'\n to open it on your online repo or `vscode://file/${process.cwd()}/` to \n open it in visual studio code),\n */\n // prefix: '',\n\n /* false (the default): ignore dependencies that only exist before typescript-to-javascript compilation\n true: also detect dependencies that only exist before typescript-to-javascript compilation\n \"specify\": for each dependency identify whether it only exists before compilation or also after\n */\n"+(null!=(h=c(t,"if").call(i,null!=n?c(n,"tsPreCompilationDeps"):n,{name:"if",hash:{},fn:e.program(3,s,0),inverse:e.program(5,s,0),data:s,loc:{start:{line:251,column:4},end:{line:255,column:11}}}))?h:"")+' \n /* \n list of extensions to scan that aren\'t javascript or compile-to-javascript. \n Empty by default. Only put extensions in here that you want to take into\n account that are _not_ parsable. \n */\n // extraExtensionsToScan: [".json", ".jpg", ".png", ".svg", ".webp"],\n\n /* if true combines the package.jsons found from the module up to the base\n folder the cruise is initiated from. Useful for how (some) mono-repos\n manage dependencies & dependency definitions.\n */\n'+(null!=(h=c(t,"if").call(i,null!=n?c(n,"combinedDependencies"):n,{name:"if",hash:{},fn:e.program(7,s,0),inverse:e.program(9,s,0),data:s,loc:{start:{line:268,column:4},end:{line:272,column:11}}}))?h:"")+"\n /* if true leave symlinks untouched, otherwise use the realpath */\n // preserveSymlinks: false,\n\n /* TypeScript project file ('tsconfig.json') to use for\n (1) compilation and\n (2) resolution (e.g. with the paths property)\n\n The (optional) fileName attribute specifies which file to take (relative to\n dependency-cruiser's current working directory). When not provided\n defaults to './tsconfig.json'.\n */\n"+(null!=(h=c(t,"if").call(i,null!=n?c(n,"useTsConfig"):n,{name:"if",hash:{},fn:e.program(11,s,0),inverse:e.program(13,s,0),data:s,loc:{start:{line:285,column:4},end:{line:299,column:11}}}))?h:"")+"\n /* Webpack configuration to use to get resolve options from.\n\n The (optional) fileName attribute specifies which file to take (relative\n to dependency-cruiser's current working directory. When not provided defaults\n to './webpack.conf.js'.\n\n The (optional) `env` and `arguments` attributes contain the parameters to be passed if\n your webpack config is a function and takes them (see webpack documentation\n for details)\n */\n"+(null!=(h=c(t,"if").call(i,null!=n?c(n,"useWebpackConfig"):n,{name:"if",hash:{},fn:e.program(18,s,0),inverse:e.program(20,s,0),data:s,loc:{start:{line:311,column:4},end:{line:323,column:11}}}))?h:"")+"\n /* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use\n for compilation (and whatever other naughty things babel plugins do to\n source code). This feature is well tested and usable, but might change\n behavior a bit over time (e.g. more precise results for used module \n systems) without dependency-cruiser getting a major version bump.\n */\n"+(null!=(h=c(t,"if").call(i,null!=n?c(n,"useBabelConfig"):n,{name:"if",hash:{},fn:e.program(22,s,0),inverse:e.program(24,s,0),data:s,loc:{start:{line:331,column:4},end:{line:339,column:11}}}))?h:"")+"\n /* List of strings you have in use in addition to cjs/ es6 requires\n & imports to declare module dependencies. Use this e.g. if you've\n re-declared require, use a require-wrapper or use window.require as\n a hack.\n */\n // exoticRequireStrings: [],\n /* options to pass on to enhanced-resolve, the package dependency-cruiser\n uses to resolve module references to disk. You can set most of these\n options in a webpack.conf.js - this section is here for those\n projects that don't have a separate webpack config file.\n\n Note: settings in webpack.conf.js override the ones specified here.\n */\n enhancedResolveOptions: {\n /* List of strings to consider as 'exports' fields in package.json. Use\n ['exports'] when you use packages that use such a field and your environment\n supports it (e.g. node ^12.19 || >=14.7 or recent versions of webpack).\n\n If you have an `exportsFields` attribute in your webpack config, that one\n will have precedence over the one specified here.\n */ \n exportsFields: [\"exports\"],\n /* List of conditions to check for in the exports field. e.g. use ['imports']\n if you're only interested in exposed es6 modules, ['require'] for commonjs,\n or all conditions at once `(['import', 'require', 'node', 'default']`)\n if anything goes for you. Only works when the 'exportsFields' array is\n non-empty.\n\n If you have a 'conditionNames' attribute in your webpack config, that one will\n have precedence over the one specified here.\n */\n conditionNames: [\"import\", \"require\", \"node\", \"default\"],\n /*\n The extensions, by default are the same as the ones dependency-cruiser\n can access (run `npx depcruise --info` to see which ones that are in\n _your_ environment. If that list is larger than what you need (e.g. \n it contains .js, .jsx, .ts, .tsx, .cts, .mts - but you don't use \n TypeScript you can pass just the extensions you actually use (e.g. \n [\".js\", \".jsx\"]). This can speed up the most expensive step in \n dependency cruising (module resolution) quite a bit.\n */\n"+(null!=(h=c(t,"if").call(i,null!=n?c(n,"specifyResolutionExtensions"):n,{name:"if",hash:{},fn:e.program(26,s,0),inverse:e.program(28,s,0),data:s,loc:{start:{line:382,column:6},end:{line:386,column:13}}}))?h:"")+' /* \n If your TypeScript project makes use of types specified in \'types\'\n fields in package.jsons of external dependencies, specify "types"\n in addition to "main" in here, so enhanced-resolve (the resolver\n dependency-cruiser uses) knows to also look there. You can also do\n this if you\'re not sure, but still use TypeScript. In a future version\n of dependency-cruiser this will likely become the default.\n */\n'+(null!=(h=c(t,"if").call(i,null!=n?c(n,"usesTypeScript"):n,{name:"if",hash:{},fn:e.program(30,s,0),inverse:e.program(32,s,0),data:s,loc:{start:{line:395,column:6},end:{line:399,column:13}}}))?h:"")+' },\n reporterOptions: {\n dot: {\n /* pattern of modules that can be consolidated in the detailed\n graphical dependency graph. The default pattern in this configuration\n collapses everything in node_modules to one folder deep so you see\n the external modules, but not the innards your app depends upon.\n */\n collapsePattern: \'node_modules/(@[^/]+/[^/]+|[^/]+)\',\n\n /* Options to tweak the appearance of your graph.See\n https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions\n for details and some examples. If you don\'t specify a theme\n don\'t worry - dependency-cruiser will fall back to the default one.\n */\n // theme: {\n // graph: {\n // /* use splines: "ortho" for straight lines. Be aware though\n // graphviz might take a long time calculating ortho(gonal)\n // routings.\n // */\n // splines: "true"\n // },\n // modules: [\n // {\n // criteria: { matchesFocus: true },\n // attributes: {\n // fillcolor: "lime",\n // penwidth: 2,\n // },\n // },\n // {\n // criteria: { matchesFocus: false },\n // attributes: {\n // fillcolor: "lightgrey",\n // },\n // },\n // {\n // criteria: { matchesReaches: true },\n // attributes: {\n // fillcolor: "lime",\n // penwidth: 2,\n // },\n // },\n // {\n // criteria: { matchesReaches: false },\n // attributes: {\n // fillcolor: "lightgrey",\n // },\n // },\n // {\n // criteria: { source: "^src/model" },\n // attributes: { fillcolor: "#ccccff" }\n // },\n // {\n // criteria: { source: "^src/view" },\n // attributes: { fillcolor: "#ccffcc" }\n // },\n // ],\n // dependencies: [\n // {\n // criteria: { "rules[0].severity": "error" },\n // attributes: { fontcolor: "red", color: "red" }\n // },\n // {\n // criteria: { "rules[0].severity": "warn" },\n // attributes: { fontcolor: "orange", color: "orange" }\n // },\n // {\n // criteria: { "rules[0].severity": "info" },\n // attributes: { fontcolor: "blue", color: "blue" }\n // },\n // {\n // criteria: { resolved: "^src/model" },\n // attributes: { color: "#0000ff77" }\n // },\n // {\n // criteria: { resolved: "^src/view" },\n // attributes: { color: "#00770077" }\n // }\n // ]\n // }\n },\n archi: {\n /* pattern of modules that can be consolidated in the high level\n graphical dependency graph. If you use the high level graphical\n dependency graph reporter (`archi`) you probably want to tweak\n this collapsePattern to your situation.\n */\n collapsePattern: \'^(packages|src|lib|app|bin|test(s?)|spec(s?))/[^/]+|node_modules/(@[^/]+/[^/]+|[^/]+)\',\n\n /* Options to tweak the appearance of your graph.See\n https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions\n for details and some examples. If you don\'t specify a theme\n for \'archi\' dependency-cruiser will use the one specified in the\n dot section (see above), if any, and otherwise use the default one.\n */\n // theme: {\n // },\n },\n "text": {\n "highlightFocused": true\n },\n }\n }\n};\n// generated: dependency-cruiser@'+l(typeof(u=null!=(u=c(t,"version")||(null!=n?c(n,"version"):n))?u:r)==a?u.call(i,{name:"version",hash:{},data:s,loc:{start:{line:506,column:33},end:{line:506,column:44}}}):u)+" on "+l(typeof(u=null!=(u=c(t,"date")||(null!=n?c(n,"date"):n))?u:r)==a?u.call(i,{name:"date",hash:{},data:s,loc:{start:{line:506,column:48},end:{line:506,column:56}}}):u)+"\n"},useData:!0}); \ No newline at end of file