Revamping to matrix style
This commit is contained in:
21
node_modules/@astrojs/check/LICENSE
generated
vendored
Normal file
21
node_modules/@astrojs/check/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 The Astro Technology Company
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1
node_modules/@astrojs/check/dist/bin.d.ts
generated
vendored
Normal file
1
node_modules/@astrojs/check/dist/bin.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
9
node_modules/@astrojs/check/dist/bin.js
generated
vendored
Executable file
9
node_modules/@astrojs/check/dist/bin.js
generated
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
import path from 'node:path';
|
||||
import { check, parseArgsAsCheckConfig } from './index.js';
|
||||
const args = parseArgsAsCheckConfig(process.argv);
|
||||
console.info(`Getting diagnostics for Astro files in ${path.resolve(args.root)}...`);
|
||||
const result = await check(args);
|
||||
if (typeof result === 'boolean') {
|
||||
process.exit(result ? 1 : 0);
|
||||
}
|
||||
//# sourceMappingURL=bin.js.map
|
||||
23
node_modules/@astrojs/check/dist/index.d.ts
generated
vendored
Normal file
23
node_modules/@astrojs/check/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { options } from './options.js';
|
||||
/**
|
||||
* Given a list of arguments from the command line (such as `process.argv`), return parsed and processed options
|
||||
*/
|
||||
export declare function parseArgsAsCheckConfig(args: string[]): {
|
||||
[x: string]: unknown;
|
||||
readonly root: string;
|
||||
readonly watch: boolean;
|
||||
readonly tsconfig: string | undefined;
|
||||
readonly minimumFailingSeverity: "error" | "warning" | "hint";
|
||||
readonly minimumSeverity: "error" | "warning" | "hint";
|
||||
readonly preserveWatchOutput: boolean;
|
||||
_: (string | number)[];
|
||||
$0: string;
|
||||
};
|
||||
export type Flags = Pick<ReturnType<typeof parseArgsAsCheckConfig>, keyof typeof options>;
|
||||
export declare function check(flags: Partial<Flags> & {
|
||||
watch: true;
|
||||
}): Promise<void>;
|
||||
export declare function check(flags: Partial<Flags> & {
|
||||
watch: false;
|
||||
}): Promise<boolean>;
|
||||
export declare function check(flags: Partial<Flags>): Promise<boolean | void>;
|
||||
99
node_modules/@astrojs/check/dist/index.js
generated
vendored
Normal file
99
node_modules/@astrojs/check/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
import { AstroCheck } from '@astrojs/language-server';
|
||||
import { watch } from 'chokidar';
|
||||
import { bold, dim, red, yellow } from 'kleur/colors';
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import { options } from './options.js';
|
||||
/**
|
||||
* Given a list of arguments from the command line (such as `process.argv`), return parsed and processed options
|
||||
*/
|
||||
export function parseArgsAsCheckConfig(args) {
|
||||
return yargs(hideBin(args)).options(options).parseSync();
|
||||
}
|
||||
/**
|
||||
* Print diagnostics according to the given flags, and return whether or not the program should exit with an error code.
|
||||
*/
|
||||
export async function check(flags) {
|
||||
const workspaceRoot = path.resolve(flags.root ?? process.cwd());
|
||||
const require = createRequire(import.meta.url);
|
||||
const checker = new AstroCheck(workspaceRoot, require.resolve('typescript'), flags.tsconfig);
|
||||
let req = 0;
|
||||
if (flags.watch) {
|
||||
function createWatcher(rootPath, extensions) {
|
||||
return watch(`${rootPath}/**/*{${extensions.join(',')}}`, {
|
||||
ignored: (ignoredPath) => ignoredPath.includes('node_modules'),
|
||||
ignoreInitial: true,
|
||||
});
|
||||
}
|
||||
// Dynamically get the list of extensions to watch from the files already included in the project
|
||||
const checkedExtensions = Array.from(new Set(checker.linter.languageHost.getScriptFileNames().map((fileName) => path.extname(fileName))));
|
||||
createWatcher(workspaceRoot, checkedExtensions)
|
||||
.on('add', (fileName) => {
|
||||
checker.linter.fileCreated(fileName);
|
||||
update();
|
||||
})
|
||||
.on('unlink', (fileName) => {
|
||||
checker.linter.fileDeleted(fileName);
|
||||
update();
|
||||
})
|
||||
.on('change', (fileName) => {
|
||||
checker.linter.fileUpdated(fileName);
|
||||
update();
|
||||
});
|
||||
}
|
||||
async function update() {
|
||||
if (!flags.preserveWatchOutput)
|
||||
process.stdout.write('\x1Bc');
|
||||
await lint();
|
||||
}
|
||||
async function lint() {
|
||||
const currentReq = ++req;
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
const isCanceled = () => currentReq !== req;
|
||||
if (isCanceled())
|
||||
return;
|
||||
const minimumSeverity = flags.minimumSeverity || 'hint';
|
||||
const result = await checker.lint({
|
||||
logErrors: {
|
||||
level: minimumSeverity,
|
||||
},
|
||||
cancel: isCanceled,
|
||||
});
|
||||
console.info([
|
||||
bold(`Result (${result.fileChecked} file${result.fileChecked === 1 ? '' : 's'}): `),
|
||||
['error', 'warning', 'hint'].includes(minimumSeverity)
|
||||
? bold(red(`${result.errors} ${result.errors === 1 ? 'error' : 'errors'}`))
|
||||
: undefined,
|
||||
['warning', 'hint'].includes(minimumSeverity)
|
||||
? bold(yellow(`${result.warnings} ${result.warnings === 1 ? 'warning' : 'warnings'}`))
|
||||
: undefined,
|
||||
['hint'].includes(minimumSeverity)
|
||||
? dim(`${result.hints} ${result.hints === 1 ? 'hint' : 'hints'}\n`)
|
||||
: undefined,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(`\n${dim('-')} `));
|
||||
if (flags.watch) {
|
||||
console.info('Watching for changes...');
|
||||
}
|
||||
else {
|
||||
switch (flags.minimumFailingSeverity) {
|
||||
case 'error':
|
||||
return result.errors > 0;
|
||||
case 'warning':
|
||||
return result.errors + result.warnings > 0;
|
||||
case 'hint':
|
||||
return result.errors + result.warnings + result.hints > 0;
|
||||
default:
|
||||
return result.errors > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Always lint on first run, even in watch mode.
|
||||
const lintResult = await lint();
|
||||
if (!flags.watch)
|
||||
return lintResult;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
32
node_modules/@astrojs/check/dist/options.d.ts
generated
vendored
Normal file
32
node_modules/@astrojs/check/dist/options.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export declare const options: {
|
||||
readonly root: {
|
||||
readonly type: "string";
|
||||
readonly default: string;
|
||||
readonly description: "Manually specify a root dir to check in. By default, the current working directory is used.";
|
||||
};
|
||||
readonly watch: {
|
||||
readonly type: "boolean";
|
||||
readonly default: false;
|
||||
readonly alias: "w";
|
||||
};
|
||||
readonly tsconfig: {
|
||||
readonly type: "string";
|
||||
readonly description: "Manually specify a path to a `tsconfig.json` or `jsconfig.json` to use. If not specified, the program will attempt to find a config, if it cannot it'll attempt to automatically infer the project's configuration.";
|
||||
readonly default: undefined;
|
||||
};
|
||||
readonly minimumFailingSeverity: {
|
||||
readonly choices: readonly ["error", "warning", "hint"];
|
||||
readonly description: "Minimum error severity needed to exit with an error code. Choosing 'hint' will for example cause the program to exit with an error if there's any unfixed hints.";
|
||||
readonly default: "error";
|
||||
};
|
||||
readonly minimumSeverity: {
|
||||
readonly choices: readonly ["error", "warning", "hint"];
|
||||
readonly description: "Minimum diagnostic severity to show. Choosing `warning` will, for example, show both errors and warnings, but not hints. ";
|
||||
readonly default: "hint";
|
||||
};
|
||||
readonly preserveWatchOutput: {
|
||||
readonly type: "boolean";
|
||||
readonly description: "If set to false, output won't be cleared between checks in watch mode.";
|
||||
readonly default: false;
|
||||
};
|
||||
};
|
||||
29
node_modules/@astrojs/check/dist/options.js
generated
vendored
Normal file
29
node_modules/@astrojs/check/dist/options.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
export const options = {
|
||||
root: {
|
||||
type: 'string',
|
||||
default: process.cwd(),
|
||||
description: 'Manually specify a root dir to check in. By default, the current working directory is used.',
|
||||
},
|
||||
watch: { type: 'boolean', default: false, alias: 'w' },
|
||||
tsconfig: {
|
||||
type: 'string',
|
||||
description: "Manually specify a path to a `tsconfig.json` or `jsconfig.json` to use. If not specified, the program will attempt to find a config, if it cannot it'll attempt to automatically infer the project's configuration.",
|
||||
default: undefined,
|
||||
},
|
||||
minimumFailingSeverity: {
|
||||
choices: ['error', 'warning', 'hint'],
|
||||
description: "Minimum error severity needed to exit with an error code. Choosing 'hint' will for example cause the program to exit with an error if there's any unfixed hints.",
|
||||
default: 'error',
|
||||
},
|
||||
minimumSeverity: {
|
||||
choices: ['error', 'warning', 'hint'],
|
||||
description: 'Minimum diagnostic severity to show. Choosing `warning` will, for example, show both errors and warnings, but not hints. ',
|
||||
default: 'hint',
|
||||
},
|
||||
preserveWatchOutput: {
|
||||
type: 'boolean',
|
||||
description: "If set to false, output won't be cleared between checks in watch mode.",
|
||||
default: false,
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=options.js.map
|
||||
47
node_modules/@astrojs/check/package.json
generated
vendored
Normal file
47
node_modules/@astrojs/check/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@astrojs/check",
|
||||
"version": "0.5.10",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/withastro/language-tools",
|
||||
"directory": "packages/astro-check"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"bin": {
|
||||
"astro-check": "./dist/bin.js"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"dist/**/*.js",
|
||||
"dist/**/*.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"@astrojs/language-server": "^2.8.4",
|
||||
"chokidar": "^3.5.3",
|
||||
"fast-glob": "^3.3.1",
|
||||
"kleur": "^4.1.5",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.17.8",
|
||||
"@types/yargs": "^17.0.24",
|
||||
"@types/chai": "^4.3.5",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"chai": "^4.3.7",
|
||||
"mocha": "^10.2.0",
|
||||
"tsx": "^3.12.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch",
|
||||
"test": "mocha --timeout 50000 --require tsx test/**/*.test.ts",
|
||||
"test:match": "pnpm run test -g"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user