Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: makes generated .mjs schemas smaller #934

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"configs/plugins/",
"src",
"!src/**/*.json",
"!src/**/*.ts",
"!src/**/*.md",
"!**/*.DS_Store",
"types/**/*.d.mts",
Expand Down
51 changes: 19 additions & 32 deletions src/cli/init-config/config-template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = {
severity: 'error',
from: {},
to: {
path: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx|ls|coffee|litcoffee|coffee[.]md)$'
path: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$'
}
},
{
Expand All @@ -150,7 +150,7 @@ module.exports = {
'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
from: {
path: '{{sourceLocationRE}}',
pathNot: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx|ls|coffee|litcoffee|coffee[.]md)$'
pathNot: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$'
},
to: {
dependencyTypes: [
Expand Down Expand Up @@ -216,12 +216,6 @@ module.exports = {
*/
// includeOnly : [''],

/* dependency-cruiser will include modules matching against the focus
regular expression in its output, as well as their direct neighbours
(dependencies and dependents)
*/
// focus : '',

/* List of module systems to cruise.
When left out dependency-cruiser will fall back to the list of _all_
module systems it knows of. It's the default because it's the safe option
Expand All @@ -234,7 +228,7 @@ module.exports = {

// moduleSystems: ['cjs', 'es6'],

/* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/develop/'
/* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/main/'
to open it on your online repo or \`vscode://file/$\{process.cwd()}/\` to
open it in visual studio code),
*/
Expand Down Expand Up @@ -277,15 +271,14 @@ 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
your webpack config is a function and takes them (see webpack documentation
for details)
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)
*/
{{webpackConfigAttribute}}

/* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use
for compilation (and whatever other naughty things babel plugins do to
source code).
for compilation
*/
{{babelConfigAttribute}}

Expand Down Expand Up @@ -313,21 +306,20 @@ module.exports = {
/*
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
_your_ environment. If that list is larger than you need you can pass
_your_ environment). If that list is larger than you need you can pass
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.
up module resolution, which is the most expensive step.
*/
{{extensionsAttribute}}
/* What to consider a 'main' field in package.json */
{{mainFieldsAttribute}}
/*
A list of alias fields in package.jsons
See [this specification](https://github.com/defunctzombie/package-browser-field-spec) and
the [resolve.alias](https://webpack.js.org/configuration/resolve/#resolvealiasfields)
documentation in the webpack docs.
the webpack [resolve.alias](https://webpack.js.org/configuration/resolve/#resolvealiasfields)
documentation

Defaults to an empty array (don't use any alias fields).
Defaults to an empty array (= don't use alias fields).
*/
// aliasFields: ["browser"],
},
Expand All @@ -336,21 +328,19 @@ module.exports = {
/* pattern of modules that can be consolidated in the detailed
graphical dependency graph. The default pattern in this configuration
collapses everything in node_modules to one folder deep so you see
the external modules, but not the innards your app depends upon.
the external modules, but their innards.
*/
collapsePattern: 'node_modules/(?:@[^/]+/[^/]+|[^/]+)',

/* Options to tweak the appearance of your graph.See
https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions
for details and some examples. If you don't specify a theme
don't worry - dependency-cruiser will fall back to the default one.
dependency-cruiser falls back to a built-in one.
*/
// theme: {
// graph: {
// /* splines: "ortho" will give you straight lines at the expense of
// being slow to render on big graphs
// splines: "true" will give you bezier curves which are faster
// but might not look as nice
// /* splines: "ortho" gives straight lines, but is slow on big graphs
// splines: "true" gives bezier curves (fast, not as nice as ortho)
// */
// splines: "true"
// },
Expand All @@ -364,14 +354,11 @@ module.exports = {
*/
collapsePattern: '^(?:packages|src|lib(s?)|app(s?)|bin|test(s?)|spec(s?))/[^/]+|node_modules/(?:@[^/]+/[^/]+|[^/]+)',

/* Options to tweak the appearance of your graph.See
https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions
for details and some examples. If you don't specify a theme
for 'archi' dependency-cruiser will use the one specified in the
/* Options to tweak the appearance of your graph. If you don't specify a
theme for 'archi' dependency-cruiser will use the one specified in the
dot section above and otherwise use the default one.
*/
// theme: {
// },
// theme: { },
},
"text": {
"highlightFocused": true
Expand Down
3 changes: 0 additions & 3 deletions src/main/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
// workaround to nodenext shenanigans with the TypeScript compiler
// see https://github.com/sverweij/dependency-cruiser/issues/754
// eslint-disable-next-line node/no-unpublished-import
export type * from "../../types/dependency-cruiser.mjs";
2 changes: 1 addition & 1 deletion src/schema/baseline-violations.schema.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/schema/configuration.schema.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/schema/cruise-result.schema.mjs

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/validate/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable node/no-unpublished-import */
import type {
IDependency,
IFolder,
Expand Down Expand Up @@ -37,7 +36,7 @@ export interface IValidationResult {
*/
export function module(
pRuleSet: IFlattenedRuleSet,
pModule: IModule
pModule: IModule,
): IValidationResult;

/**
Expand All @@ -47,7 +46,7 @@ export function module(
export function dependency(
pRuleSet: IFlattenedRuleSet,
pFrom: IModule,
pTo: IDependency
pTo: IDependency,
): IValidationResult;

/**
Expand All @@ -57,5 +56,5 @@ export function dependency(
export function folder(
pRuleSet: IFlattenedRuleSet,
pFromFolder: IFolder,
pToFolder: IFolderDependency
pToFolder: IFolderDependency,
): IValidationResult;
21 changes: 11 additions & 10 deletions tools/generate-schemas.utl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { writeFileSync } from "node:fs";
import { extname } from "node:path";
import prettier from "prettier";
import babel from "@babel/core";

function stripAttribute(pObject, pAttribute) {
const lObject = structuredClone(pObject);
Expand All @@ -19,23 +20,23 @@ function stripAttribute(pObject, pAttribute) {
function emitConsolidatedSchema(pOutputFileName) {
if (extname(pOutputFileName) === ".json") {
return async (pJSONSchemaObject) => {
const lData = await prettier.format(
const lFormattedJSON = await prettier.format(
JSON.stringify(pJSONSchemaObject.default),
{
parser: "json",
},
);
writeFileSync(pOutputFileName, lData, "utf8");
writeFileSync(pOutputFileName, lFormattedJSON, "utf8");
};
}
return (pJSONSchemaObject) => {
writeFileSync(
pOutputFileName,
`/* generated - don't edit */export default ${JSON.stringify(
stripAttribute(pJSONSchemaObject.default, "description"),
)}`,
"utf8",
);
return async (pJSONSchemaObject) => {
const lUnMinified = `/* generated - don't edit */export default ${JSON.stringify(
stripAttribute(pJSONSchemaObject.default, "description"),
)}`;
// to strip quoted attributes {"thing": 481} => {thing: 481}
const lFormatted = await prettier.format(lUnMinified, { parser: "babel" });
const lMinified = babel.transformSync(lFormatted, { minified: true }).code;
writeFileSync(pOutputFileName, lMinified, "utf8");
};
}

Expand Down