A collection of reusable tooling for webpack repos
Add this repo as dev dependency:
"devDependencies": {
"tooling": "webpack/tooling"
}
The lockfile will take care pinning the version.
Run yarn upgrade tooling
to upgrade the to latest version.
Add two scripts to the package.json:
"scripts": {
"special-lint": "...",
"special-lint-fix": "..."
}
Add all tooling that should be used to these scripts (concatenated with &&
). In the special-lint-fix
version pass --write
to all tooling.
Example:
"scripts": {
"special-lint": "node node_modules/tooling/compile-to-definitions",
"special-lint-fix": "node node_modules/tooling/compile-to-definitions --write"
}
By default all tooling checks if affected files are up-to-date, so it can be added as linting step in CI.
Use --write
to switch to updating mode.
In this mode affected files are updated to the fixed version when possible.
By default all tooling will operate in the root directory of the calling project.
Use --root some/dir
to operate in a different directory.
Some tooling displays more information when --verbose
is used.
Most tooling uses prettier to format generated files, so a prettier config is needed and prettier need to be installed.
node node_modules/tooling/lockfile-lint
Verifies the correctness of a yarn lockfile. Makes sure that all dependencies are provided from npm (e. g. not github dependencies). This is important as some users might not be able to access github.
yarn.lock
must be present in root directory.
node node_modules/tooling/schemas-lint
Verifies the correctness of all JSON schemas.
- Definitions and properties need to a
description
in the correct format. - Only allowed properties are used.
$ref
must be the only property when provided.tsType
is needed wheninstanceof
is used.type: "string"
is needed whenabsolutePath
is used.additionalProperties
is needed whenproperties
are used.
--schemas ./schemas/**/*.json
Glob to the schemas that should be processed.
node node_modules/tooling/compile-to-definitions
Generates typescript declaration files from JSON schemas.
--schemas ./schemas/**/*.json
Glob to the schemas that should be processed.
---declarations declarations
Output folder of the generated declaration files.
node node_modules/tooling/precompile-schemas
Generate .check.js
files next to the JSON schemas.
They export a single function which returned a boolean whether the object is validate according to the schema.
This function doesn't do error handling, so run a real schema validation when it returns false.
It will also generate a .check.d.ts
file with type declarations.
--schemas ./schemas/**/*.json
Glob to the schemas that should be processed.
---declarations declarations
Folder of the generated declaration files.
node node_modules/tooling/inherit-types
Synchronize jsdoc method annotations in classes with jsdoc of the same method in base class.
This copies jsdoc one to one from base class, but omits @abstract
.
tsconfig.json
must be present in root directory and typescript must be installed.
node node_modules/tooling/format-file-header
Ensures that the starting of all source files follows the following convention:
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author ...
*/
"use strict";
const Import = require("./Import");
const SortedAlphabetically = require("./SortedAlphabetically");
/** @typedef {import("../TypeImport")} TypeImport */
/** @typedef {import("../SortedAlphabetically")} SortedAlphabetically */
--source ./lib/**/*.js
Glob to the source that should be processed.
node node_modules/tooling/format-schemas
Sort JSON schema according to convention.
--schemas ./schemas/**/*.json
Glob to the schemas that should be processed.
node node_modules/tooling/generate-types
Generate typescript types declarations file (types.d.ts
) from the visible types in the exposed main
(package.json) entry file.
This declaration file should be used as types
in package.json
.
When a declarations/index.d.ts
file exists, types from this are also exposed.
tsconfig.types.json
must be present in root directory and typescript must be installed.
--types types.d.ts
Path of the generated declarations file.
node node_modules/tooling/generate-types
Generates type coverage raw coverage data in the coverage
directory.
instanbul report
can be used to generate a readable report.
tsconfig.json
must be present in root directory and typescript must be installed.