jsii 5.9.44 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -285
- package/lib/assembler.js +95 -46
- package/lib/assembler.js.map +1 -1
- package/lib/case.js +13 -10
- package/lib/case.js.map +1 -1
- package/lib/common/find-utils.js +35 -2
- package/lib/common/find-utils.js.map +1 -1
- package/lib/common/symbol-id.js +39 -7
- package/lib/common/symbol-id.js.map +1 -1
- package/lib/compiler.js +51 -8
- package/lib/compiler.js.map +1 -1
- package/lib/directives.js +48 -16
- package/lib/directives.js.map +1 -1
- package/lib/docs.js +36 -4
- package/lib/docs.js.map +1 -1
- package/lib/helpers.js +38 -4
- package/lib/helpers.js.map +1 -1
- package/lib/jsii-diagnostic.js +524 -497
- package/lib/jsii-diagnostic.js.map +1 -1
- package/lib/literate.js +35 -2
- package/lib/literate.js.map +1 -1
- package/lib/main.js +100 -13
- package/lib/main.js.map +1 -1
- package/lib/project-info.d.ts +1 -1
- package/lib/project-info.js +41 -11
- package/lib/project-info.js.map +1 -1
- package/lib/support.js +7 -4
- package/lib/support.js.map +1 -1
- package/lib/transforms/deprecated-remover.js +65 -23
- package/lib/transforms/deprecated-remover.js.map +1 -1
- package/lib/transforms/deprecation-warnings.js +50 -10
- package/lib/transforms/deprecation-warnings.js.map +1 -1
- package/lib/transforms/runtime-info.js +36 -2
- package/lib/transforms/runtime-info.js.map +1 -1
- package/lib/tsconfig/compiler-options.js +40 -5
- package/lib/tsconfig/compiler-options.js.map +1 -1
- package/lib/tsconfig/rule-set-format.d.ts +34 -0
- package/lib/tsconfig/rule-set-format.js +101 -0
- package/lib/tsconfig/rule-set-format.js.map +1 -0
- package/lib/tsconfig/rulesets/configurable-options.js +10 -1
- package/lib/tsconfig/rulesets/configurable-options.js.map +1 -1
- package/lib/tsconfig/rulesets/deprecated-options.js +16 -1
- package/lib/tsconfig/rulesets/deprecated-options.js.map +1 -1
- package/lib/tsconfig/rulesets/generated.public.js +7 -2
- package/lib/tsconfig/rulesets/generated.public.js.map +1 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js +0 -1
- package/lib/tsconfig/rulesets/jsii-configured-options.js.map +1 -1
- package/lib/tsconfig/rulesets/minimal.public.js +4 -1
- package/lib/tsconfig/rulesets/minimal.public.js.map +1 -1
- package/lib/tsconfig/rulesets/strict.public.js +12 -9
- package/lib/tsconfig/rulesets/strict.public.js.map +1 -1
- package/lib/tsconfig/tsconfig-validator.d.ts +39 -0
- package/lib/tsconfig/tsconfig-validator.js +124 -3
- package/lib/tsconfig/tsconfig-validator.js.map +1 -1
- package/lib/tsconfig/validator.d.ts +39 -0
- package/lib/tsconfig/validator.js +65 -16
- package/lib/tsconfig/validator.js.map +1 -1
- package/lib/type-analysis.js +39 -3
- package/lib/type-analysis.js.map +1 -1
- package/lib/type-reference.js +34 -1
- package/lib/type-reference.js.map +1 -1
- package/lib/type-tracker.js +35 -4
- package/lib/type-tracker.js.map +1 -1
- package/lib/type-visitor.js +34 -1
- package/lib/type-visitor.js.map +1 -1
- package/lib/utils.js +37 -2
- package/lib/utils.js.map +1 -1
- package/lib/validator.js +49 -11
- package/lib/validator.js.map +1 -1
- package/lib/version.d.ts +3 -3
- package/lib/version.js +2 -2
- package/lib/version.js.map +1 -1
- package/lib/warnings.js +34 -1
- package/lib/warnings.js.map +1 -1
- package/package.json +5 -7
- package/releases.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-set-format.js","sourceRoot":"","sources":["../../src/tsconfig/rule-set-format.ts"],"names":[],"mappings":";;;;;;AA8BA,sCAyCC;AAQD,4CAkBC;AASD,0CAGC;AA7GD,kDAA0B;AAC1B,wBAAsD;AACtD,6DAAkF;AAClF,2CAAwD;AAExD;;;;;GAKG;AACU,QAAA,qBAAqB,GAE9B;IACF,CAAC,oCAAiC,CAAC,MAAM,CAAC,EACxC,uGAAuG;IACzG,CAAC,oCAAiC,CAAC,SAAS,CAA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nimport { describeRuleSet, getCompilerOptionsRuleSet } from './tsconfig-validator';\nimport { RuleDescription, RuleType } from './validator';\n\n/**\n * Human-readable descriptions for each tsconfig validation rule set.\n *\n * These are surfaced both as CLI option help (e.g. for `--validate-tsconfig` and\n * `--rule-set`) and as the heading when printing a rule set via `formatRuleSet`.\n */\nexport const RULE_SET_DESCRIPTIONS: {\n [choice in TypeScriptConfigValidationRuleSet]: string;\n} = {\n [TypeScriptConfigValidationRuleSet.STRICT]:\n 'Validates the provided config against a strict rule set designed for maximum backwards-compatibility.',\n [TypeScriptConfigValidationRuleSet.GENERATED]:\n 'Enforces a config as created by --generate-tsconfig. Use this to stay compatible with the generated config, but have full ownership over the file.',\n [TypeScriptConfigValidationRuleSet.MINIMAL]:\n 'Only enforce options that are known to be incompatible with jsii. This rule set is likely to be incomplete and new rules will be added without notice as incompatibilities emerge.',\n [TypeScriptConfigValidationRuleSet.NONE]:\n 'Disables all config validation, including options that are known to be incompatible with jsii. Intended for experimentation only. Use at your own risk.',\n};\n\n/**\n * Render a single rule set (its `compilerOptions` rules) as a human-readable block.\n *\n * @param ruleSet the rule set to render\n * @returns a multi-line string suitable for printing to the console\n */\nexport function formatRuleSet(ruleSet: TypeScriptConfigValidationRuleSet): string {\n const lines: string[] = [`${chalk.bold('Rule set:')} ${chalk.bold.cyan(ruleSet)}`];\n\n const description = RULE_SET_DESCRIPTIONS[ruleSet];\n if (description) {\n lines.push(chalk.dim(description));\n }\n\n const rules = describeRuleSet(ruleSet);\n if (rules.length === 0) {\n lines.push('');\n lines.push(chalk.dim(' No rules. Configuration validation is disabled for this rule set.'));\n return lines.join('\\n');\n }\n\n const unknownRejected = getCompilerOptionsRuleSet(ruleSet).options.unexpectedFields === RuleType.FAIL;\n lines.push('');\n lines.push(chalk.dim(`Applies to: compilerOptions (other options: ${unknownRejected ? 'rejected' : 'allowed'})`));\n lines.push('');\n\n // Group rules by field, preserving the order in which each field first appears.\n const byField = new Map<string, RuleDescription[]>();\n for (const rule of rules) {\n const list = byField.get(rule.field) ?? [];\n list.push(rule);\n byField.set(rule.field, list);\n }\n\n const width = Math.max(...[...byField.keys()].map((field) => field.length));\n for (const [field, fieldRules] of byField) {\n const phrases = fieldRules.map(formatConstraint);\n // A required field is surfaced as an explicit \"required\" constraint at the front.\n if (fieldRules.some((rule) => rule.required)) {\n phrases.unshift(chalk.italic('required'));\n }\n // Dedupe identical phrases (some fields are constrained by several rules that overlap).\n const constraints = [...new Set(phrases)].join('; ');\n lines.push(` ${chalk.bold(field.padEnd(width))} ${constraints}`);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Render a single rule's constraint as a human-readable phrase.\n *\n * @param rule the rule description to render\n * @returns a phrase such as `must be one of: es2022, es2023` or `not allowed`\n */\nexport function formatConstraint(rule: RuleDescription): string {\n const { type, values } = rule;\n\n // No hints means the matcher accepts anything (e.g. Match.ANY).\n if (values === undefined) {\n return type === RuleType.PASS ? chalk.italic('any value') : 'must not be set to the matched value';\n }\n\n // Only null/undefined hints means the option must be absent (e.g. Match.MISSING).\n if (values.length > 0 && values.every((value) => value == null)) {\n return chalk.italic('not allowed');\n }\n\n const formatted = values.map(formatRuleValue);\n if (type === RuleType.FAIL) {\n return formatted.length > 1 ? `must not be one of: ${formatted.join(', ')}` : `must not be ${formatted[0]}`;\n }\n return formatted.length > 1 ? `must be one of: ${formatted.join(', ')}` : `must be ${formatted[0]}`;\n}\n\n/**\n * Render a single hinted value as a highlighted code literal. Strings are shown\n * verbatim (as a user writes them in tsconfig.json), everything else is JSON-encoded.\n *\n * @param value the hinted value to render\n * @returns the value as a (possibly colorized) code literal\n */\nexport function formatRuleValue(value: any): string {\n const literal = typeof value === 'string' ? value : JSON.stringify(value);\n return chalk.cyan(literal);\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsii_configured_options_1 = require("./jsii-configured-options");
|
|
6
|
+
const jsii_configured_options_1 = __importDefault(require("./jsii-configured-options"));
|
|
4
7
|
const validator_1 = require("../validator");
|
|
5
8
|
// A rule set defining all compilerOptions that can be configured by users with or without constraints.
|
|
6
9
|
// These are options jsii doesn't have a particular opinion about
|
|
@@ -19,5 +22,11 @@ configurableOptions.shouldPass('noFallthroughCasesInSwitch', validator_1.Match.A
|
|
|
19
22
|
configurableOptions.shouldPass('verbatimModuleSyntax', validator_1.Match.ANY);
|
|
20
23
|
configurableOptions.shouldPass('isolatedModules', validator_1.Match.ANY);
|
|
21
24
|
configurableOptions.shouldPass('isolatedDeclarations', validator_1.Match.ANY);
|
|
25
|
+
configurableOptions.shouldPass('useDefineForClassFields', validator_1.Match.ANY);
|
|
26
|
+
// Authoring options the user may opt into; some jsii language features won't be
|
|
27
|
+
// usable under them, but that is the user's choice (TS reports any violations).
|
|
28
|
+
configurableOptions.shouldPass('erasableSyntaxOnly', validator_1.Match.ANY);
|
|
29
|
+
configurableOptions.shouldPass('allowImportingTsExtensions', validator_1.Match.ANY);
|
|
30
|
+
configurableOptions.shouldPass('rewriteRelativeImportExtensions', validator_1.Match.ANY);
|
|
22
31
|
exports.default = configurableOptions;
|
|
23
32
|
//# sourceMappingURL=configurable-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurable-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/configurable-options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configurable-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/configurable-options.ts"],"names":[],"mappings":";;;;;AAAA,wFAA8D;AAC9D,4CAA8C;AAE9C,uGAAuG;AACvG,iEAAiE;AACjE,qEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE1C,6DAA6D;AAC7D,mBAAmB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ptions from './jsii-configured-options';\nimport { Match, RuleSet } from '../validator';\n\n// A rule set defining all compilerOptions that can be configured by users with or without constraints.\n// These are options jsii doesn't have a particular opinion about\n// This is an internal rule set, that may be used by other rule sets.\n\nconst configurableOptions = new RuleSet();\n\n// import all options that are configurable via jsii settings\nconfigurableOptions.import(jsiiConfiguredOptions);\n\n// options jsii allows to be configured\nconfigurableOptions.shouldPass('incremental', Match.ANY);\nconfigurableOptions.shouldPass('noImplicitReturns', Match.ANY);\nconfigurableOptions.shouldPass('noUnusedLocals', Match.ANY);\nconfigurableOptions.shouldPass('noUnusedParameters', Match.ANY);\nconfigurableOptions.shouldPass('resolveJsonModule', Match.ANY);\nconfigurableOptions.shouldPass('experimentalDecorators', Match.ANY);\nconfigurableOptions.shouldPass('noFallthroughCasesInSwitch', Match.ANY);\nconfigurableOptions.shouldPass('verbatimModuleSyntax', Match.ANY);\nconfigurableOptions.shouldPass('isolatedModules', Match.ANY);\nconfigurableOptions.shouldPass('isolatedDeclarations', Match.ANY);\nconfigurableOptions.shouldPass('useDefineForClassFields', Match.ANY);\n// Authoring options the user may opt into; some jsii language features won't be\n// usable under them, but that is the user's choice (TS reports any violations).\nconfigurableOptions.shouldPass('erasableSyntaxOnly', Match.ANY);\nconfigurableOptions.shouldPass('allowImportingTsExtensions', Match.ANY);\nconfigurableOptions.shouldPass('rewriteRelativeImportExtensions', Match.ANY);\n\nexport default configurableOptions;\n"]}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const validator_1 = require("../validator");
|
|
4
|
-
// A rule set for deprecated compilerOptions that should not be used with jsii
|
|
4
|
+
// A rule set for deprecated compilerOptions that should not be used with jsii.
|
|
5
|
+
// These options are deprecated in TypeScript 6.0 and will be removed in TypeScript 7.0.
|
|
5
6
|
// This is an internal rule set, that may be used by other rule sets.
|
|
6
7
|
const deprecatedOptions = new validator_1.RuleSet();
|
|
7
8
|
deprecatedOptions.shouldPass('prepend', validator_1.Match.MISSING);
|
|
9
|
+
deprecatedOptions.shouldPass('downlevelIteration', validator_1.Match.MISSING);
|
|
10
|
+
deprecatedOptions.shouldPass('outFile', validator_1.Match.MISSING);
|
|
11
|
+
deprecatedOptions.shouldPass('baseUrl', validator_1.Match.MISSING);
|
|
12
|
+
// esModuleInterop: false and allowSyntheticDefaultImports: false are deprecated
|
|
13
|
+
deprecatedOptions.shouldPass('esModuleInterop', validator_1.Match.optional(validator_1.Match.TRUE));
|
|
14
|
+
deprecatedOptions.shouldPass('allowSyntheticDefaultImports', validator_1.Match.optional(validator_1.Match.TRUE));
|
|
15
|
+
// alwaysStrict: false is deprecated
|
|
16
|
+
deprecatedOptions.shouldPass('alwaysStrict', validator_1.Match.optional(validator_1.Match.TRUE));
|
|
17
|
+
// target: es5 is deprecated
|
|
18
|
+
deprecatedOptions.shouldFail('target', validator_1.Match.eq('es5'));
|
|
19
|
+
// Deprecated module values: amd, umd, systemjs, none
|
|
20
|
+
deprecatedOptions.shouldFail('module', validator_1.Match.oneOf('amd', 'umd', 'systemjs', 'none'));
|
|
21
|
+
// Deprecated moduleResolution values: node (node10), classic
|
|
22
|
+
deprecatedOptions.shouldFail('moduleResolution', validator_1.Match.oneOf('node', 'node10', 'classic'));
|
|
8
23
|
exports.default = deprecatedOptions;
|
|
9
24
|
//# sourceMappingURL=deprecated-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecated-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/deprecated-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,
|
|
1
|
+
{"version":3,"file":"deprecated-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/deprecated-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,+EAA+E;AAC/E,wFAAwF;AACxF,qEAAqE;AACrE,MAAM,iBAAiB,GAAG,IAAI,mBAAO,EAAE,CAAC;AACxC,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,OAAO,CAAC,CAAC;AACvD,iBAAiB,CAAC,UAAU,CAAC,oBAAoB,EAAE,iBAAK,CAAC,OAAO,CAAC,CAAC;AAClE,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,OAAO,CAAC,CAAC;AACvD,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,OAAO,CAAC,CAAC;AAEvD,gFAAgF;AAChF,iBAAiB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5E,iBAAiB,CAAC,UAAU,CAAC,8BAA8B,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAEzF,oCAAoC;AACpC,iBAAiB,CAAC,UAAU,CAAC,cAAc,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAEzE,4BAA4B;AAC5B,iBAAiB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAExD,qDAAqD;AACrD,iBAAiB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtF,6DAA6D;AAC7D,iBAAiB,CAAC,UAAU,CAAC,kBAAkB,EAAE,iBAAK,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3F,kBAAe,iBAAiB,CAAC","sourcesContent":["import { Match, RuleSet } from '../validator';\n\n// A rule set for deprecated compilerOptions that should not be used with jsii.\n// These options are deprecated in TypeScript 6.0 and will be removed in TypeScript 7.0.\n// This is an internal rule set, that may be used by other rule sets.\nconst deprecatedOptions = new RuleSet();\ndeprecatedOptions.shouldPass('prepend', Match.MISSING);\ndeprecatedOptions.shouldPass('downlevelIteration', Match.MISSING);\ndeprecatedOptions.shouldPass('outFile', Match.MISSING);\ndeprecatedOptions.shouldPass('baseUrl', Match.MISSING);\n\n// esModuleInterop: false and allowSyntheticDefaultImports: false are deprecated\ndeprecatedOptions.shouldPass('esModuleInterop', Match.optional(Match.TRUE));\ndeprecatedOptions.shouldPass('allowSyntheticDefaultImports', Match.optional(Match.TRUE));\n\n// alwaysStrict: false is deprecated\ndeprecatedOptions.shouldPass('alwaysStrict', Match.optional(Match.TRUE));\n\n// target: es5 is deprecated\ndeprecatedOptions.shouldFail('target', Match.eq('es5'));\n\n// Deprecated module values: amd, umd, systemjs, none\ndeprecatedOptions.shouldFail('module', Match.oneOf('amd', 'umd', 'systemjs', 'none'));\n\n// Deprecated moduleResolution values: node (node10), classic\ndeprecatedOptions.shouldFail('moduleResolution', Match.oneOf('node', 'node10', 'classic'));\n\nexport default deprecatedOptions;\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsii_configured_options_1 = require("./jsii-configured-options");
|
|
6
|
+
const jsii_configured_options_1 = __importDefault(require("./jsii-configured-options"));
|
|
4
7
|
const compiler_options_1 = require("../compiler-options");
|
|
5
8
|
const validator_1 = require("../validator");
|
|
6
9
|
// The public rule set used for the "generated" tsconfig validation setting.\
|
|
@@ -12,7 +15,9 @@ const generated = new validator_1.RuleSet({
|
|
|
12
15
|
});
|
|
13
16
|
// import all options that are configurable via jsii settings
|
|
14
17
|
generated.import(jsii_configured_options_1.default);
|
|
15
|
-
// ... and all generated options
|
|
18
|
+
// ... and all generated options. Deprecated options need no explicit handling here: this is a
|
|
19
|
+
// closed whitelist, so any deprecated option is either pinned to its generated value below or
|
|
20
|
+
// rejected as an unexpected field.
|
|
16
21
|
for (const [field, value] of Object.entries((0, compiler_options_1.convertForJson)(compiler_options_1.BASE_COMPILER_OPTIONS))) {
|
|
17
22
|
if (typeof value === 'string') {
|
|
18
23
|
generated.shouldPass(field, validator_1.Match.strEq(value, true));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/generated.public.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generated.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/generated.public.ts"],"names":[],"mappings":";;;;;AAAA,wFAA8D;AAC9D,0DAA4E;AAC5E,4CAAwD;AAExD,6EAA6E;AAC7E,+GAA+G;AAC/G,qFAAqF;AACrF,iGAAiG;AACjG,MAAM,SAAS,GAAG,IAAI,mBAAO,CAAC;IAC5B,gBAAgB,EAAE,oBAAQ,CAAC,IAAI;CAChC,CAAC,CAAC;AAEH,6DAA6D;AAC7D,SAAS,CAAC,MAAM,CAAC,iCAAqB,CAAC,CAAC;AAExC,8FAA8F;AAC9F,8FAA8F;AAC9F,mCAAmC;AACnC,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAA,iCAAc,EAAC,wCAAqB,CAAC,CAAC,EAAE,CAAC;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACtD,SAAS;IACX,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,SAAS;IACX,CAAC;IAED,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,kBAAe,SAAS,CAAC","sourcesContent":["import jsiiConfiguredOptions from './jsii-configured-options';\nimport { BASE_COMPILER_OPTIONS, convertForJson } from '../compiler-options';\nimport { Match, RuleSet, RuleType } from '../validator';\n\n// The public rule set used for the \"generated\" tsconfig validation setting.\\\n// The goal of this rule set is to ensure a tsconfig is compatible to the one jsii would generate for the user.\n// It is explicitly enforcing option values that are used for the generated tsconfig,\n// as well as options that can be configured via jsii settings. All other options are disallowed.\nconst generated = new RuleSet({\n unexpectedFields: RuleType.FAIL,\n});\n\n// import all options that are configurable via jsii settings\ngenerated.import(jsiiConfiguredOptions);\n\n// ... and all generated options. Deprecated options need no explicit handling here: this is a\n// closed whitelist, so any deprecated option is either pinned to its generated value below or\n// rejected as an unexpected field.\nfor (const [field, value] of Object.entries(convertForJson(BASE_COMPILER_OPTIONS))) {\n if (typeof value === 'string') {\n generated.shouldPass(field, Match.strEq(value, true));\n continue;\n }\n\n if (Array.isArray(value)) {\n generated.shouldPass(field, Match.arrEq(value));\n continue;\n }\n\n generated.shouldPass(field, Match.eq(value));\n}\n\nexport default generated;\n"]}
|
|
@@ -13,7 +13,6 @@ jsiiConfiguredOptions.shouldPass('inlineSourceMap', validator_1.Match.ANY);
|
|
|
13
13
|
jsiiConfiguredOptions.shouldPass('inlineSources', validator_1.Match.ANY);
|
|
14
14
|
jsiiConfiguredOptions.shouldPass('sourceMap', validator_1.Match.ANY);
|
|
15
15
|
jsiiConfiguredOptions.shouldPass('types', validator_1.Match.ANY);
|
|
16
|
-
jsiiConfiguredOptions.shouldPass('baseUrl', validator_1.Match.ANY);
|
|
17
16
|
jsiiConfiguredOptions.shouldPass('paths', validator_1.Match.ANY);
|
|
18
17
|
jsiiConfiguredOptions.shouldPass('composite', validator_1.Match.ANY); // configured via projectReferences
|
|
19
18
|
jsiiConfiguredOptions.shouldPass('tsBuildInfoFile', validator_1.Match.ANY);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsii-configured-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/jsii-configured-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,mGAAmG;AACnG,qEAAqE;AACrE,gCAAgC;AAChC,MAAM,qBAAqB,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC5C,qBAAqB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACtD,qBAAqB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACvD,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAChF,qBAAqB,CAAC,UAAU,CAAC,gBAAgB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC9D,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC/D,qBAAqB,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC7D,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACzD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"jsii-configured-options.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/jsii-configured-options.ts"],"names":[],"mappings":";;AAAA,4CAA8C;AAE9C,mGAAmG;AACnG,qEAAqE;AACrE,gCAAgC;AAChC,MAAM,qBAAqB,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC5C,qBAAqB,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACtD,qBAAqB,CAAC,UAAU,CAAC,SAAS,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACvD,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAChF,qBAAqB,CAAC,UAAU,CAAC,gBAAgB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC9D,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC/D,qBAAqB,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAC7D,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACzD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AACrD,qBAAqB,CAAC,UAAU,CAAC,WAAW,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAmC;AAC7F,qBAAqB,CAAC,UAAU,CAAC,iBAAiB,EAAE,iBAAK,CAAC,GAAG,CAAC,CAAC;AAE/D,kBAAe,qBAAqB,CAAC","sourcesContent":["import { Match, RuleSet } from '../validator';\n\n// A rule set defining all compilerOptions that are configurable via the jsii field in package.json\n// This is an internal rule set, that may be used by other rule sets.\n// We accept all value for these\nconst jsiiConfiguredOptions = new RuleSet();\njsiiConfiguredOptions.shouldPass('outDir', Match.ANY);\njsiiConfiguredOptions.shouldPass('rootDir', Match.ANY);\njsiiConfiguredOptions.shouldPass('forceConsistentCasingInFileNames', Match.ANY);\njsiiConfiguredOptions.shouldPass('declarationMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('inlineSourceMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('inlineSources', Match.ANY);\njsiiConfiguredOptions.shouldPass('sourceMap', Match.ANY);\njsiiConfiguredOptions.shouldPass('types', Match.ANY);\njsiiConfiguredOptions.shouldPass('paths', Match.ANY);\njsiiConfiguredOptions.shouldPass('composite', Match.ANY); // configured via projectReferences\njsiiConfiguredOptions.shouldPass('tsBuildInfoFile', Match.ANY);\n\nexport default jsiiConfiguredOptions;\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const incompatible_options_1 = require("./incompatible-options");
|
|
6
|
+
const incompatible_options_1 = __importDefault(require("./incompatible-options"));
|
|
4
7
|
const validator_1 = require("../validator");
|
|
5
8
|
// The public rule set used for the "minimal" tsconfig validation setting
|
|
6
9
|
// To goal of this rule set is to only prevent obvious misconfigurations,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minimal.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/minimal.public.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"minimal.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/minimal.public.ts"],"names":[],"mappings":";;;;;AAAA,kFAAyD;AACzD,4CAAuC;AAEvC,yEAAyE;AACzE,yEAAyE;AACzE,gDAAgD;AAChD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,OAAO,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEpC,kBAAe,OAAO,CAAC","sourcesContent":["import incompatibleOptions from './incompatible-options';\nimport { RuleSet } from '../validator';\n\n// The public rule set used for the \"minimal\" tsconfig validation setting\n// To goal of this rule set is to only prevent obvious misconfigurations,\n// while leaving everything else up to the user.\nconst minimal = new RuleSet();\nminimal.import(incompatibleOptions);\n\nexport default minimal;\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const configurable_options_1 = require("./configurable-options");
|
|
4
|
-
const deprecated_options_1 = require("./deprecated-options");
|
|
5
|
-
const incompatible_options_1 = require("./incompatible-options");
|
|
6
|
-
const strict_family_options_1 = require("./strict-family-options");
|
|
6
|
+
const configurable_options_1 = __importDefault(require("./configurable-options"));
|
|
7
|
+
const deprecated_options_1 = __importDefault(require("./deprecated-options"));
|
|
8
|
+
const incompatible_options_1 = __importDefault(require("./incompatible-options"));
|
|
9
|
+
const strict_family_options_1 = __importDefault(require("./strict-family-options"));
|
|
7
10
|
const validator_1 = require("../validator");
|
|
8
11
|
// The public rule set used for the "strict" tsconfig validation setting.
|
|
9
12
|
// The goal of this rule set is to ensure a tsconfig that is following best practices for jsii.
|
|
@@ -19,15 +22,15 @@ strict.import(incompatible_options_1.default);
|
|
|
19
22
|
// strict family options
|
|
20
23
|
strict.import(strict_family_options_1.default);
|
|
21
24
|
// Best practice rules
|
|
22
|
-
strict.shouldPass('target', validator_1.Match.
|
|
23
|
-
strict.shouldPass('lib', validator_1.Match.arrEq(['es2022'])); // node18
|
|
24
|
-
strict.shouldPass('module', validator_1.Match.oneOf('node16', 'commonjs'));
|
|
25
|
-
strict.shouldPass('moduleResolution', validator_1.Match.optional(validator_1.Match.oneOf('
|
|
26
|
-
strict.shouldPass('esModuleInterop', validator_1.Match.TRUE);
|
|
25
|
+
strict.shouldPass('target', validator_1.Match.oneOf('es2022', 'es2023', 'esnext')); // node18+
|
|
26
|
+
strict.shouldPass('lib', validator_1.Match.anyOf(validator_1.Match.arrEq(['es2022']), validator_1.Match.arrEq(['es2023']), validator_1.Match.arrEq(['esnext']))); // node18+
|
|
27
|
+
strict.shouldPass('module', validator_1.Match.oneOf('node16', 'node18', 'node20', 'nodenext', 'commonjs'));
|
|
28
|
+
strict.shouldPass('moduleResolution', validator_1.Match.optional(validator_1.Match.oneOf('node16', 'nodenext', 'bundler')));
|
|
27
29
|
strict.shouldPass('skipLibCheck', validator_1.Match.TRUE);
|
|
28
30
|
strict.shouldPass('stripInternal', validator_1.Match.optional(validator_1.Match.FALSE));
|
|
29
31
|
strict.shouldPass('noEmitOnError', validator_1.Match.TRUE);
|
|
30
32
|
strict.shouldPass('declaration', validator_1.Match.TRUE);
|
|
33
|
+
strict.shouldPass('noUncheckedSideEffectImports', validator_1.Match.optional(validator_1.Match.TRUE));
|
|
31
34
|
// Deprecated ts options that should not be used with jsii
|
|
32
35
|
strict.import(deprecated_options_1.default);
|
|
33
36
|
exports.default = strict;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/strict.public.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strict.public.js","sourceRoot":"","sources":["../../../src/tsconfig/rulesets/strict.public.ts"],"names":[],"mappings":";;;;;AAAA,kFAAyD;AACzD,8EAAqD;AACrD,kFAAyD;AACzD,oFAA0D;AAC1D,4CAAwD;AAExD,yEAAyE;AACzE,+FAA+F;AAC/F,8HAA8H;AAC9H,0DAA0D;AAC1D,MAAM,MAAM,GAAG,IAAI,mBAAO,CAAC;IACzB,gBAAgB,EAAE,oBAAQ,CAAC,IAAI;CAChC,CAAC,CAAC;AAEH,2CAA2C;AAC3C,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEnC,sDAAsD;AACtD,MAAM,CAAC,MAAM,CAAC,8BAAmB,CAAC,CAAC;AAEnC,wBAAwB;AACxB,MAAM,CAAC,MAAM,CAAC,+BAAmB,CAAC,CAAC;AAEnC,sBAAsB;AACtB,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU;AAClF,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAK,CAAC,KAAK,CAAC,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU;AAC5H,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAC/F,MAAM,CAAC,UAAU,CAAC,kBAAkB,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACpG,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC9C,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAChE,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC/C,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,iBAAK,CAAC,IAAI,CAAC,CAAC;AAC7C,MAAM,CAAC,UAAU,CAAC,8BAA8B,EAAE,iBAAK,CAAC,QAAQ,CAAC,iBAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAE9E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,CAAC,4BAAiB,CAAC,CAAC;AAEjC,kBAAe,MAAM,CAAC","sourcesContent":["import configurableOptions from './configurable-options';\nimport deprecatedOptions from './deprecated-options';\nimport incompatibleOptions from './incompatible-options';\nimport strictFamilyOptions from './strict-family-options';\nimport { Match, RuleSet, RuleType } from '../validator';\n\n// The public rule set used for the \"strict\" tsconfig validation setting.\n// The goal of this rule set is to ensure a tsconfig that is following best practices for jsii.\n// In practice, this is a combination of known incompatible options, known configurable options and additional best practices.\n// The rule set also explicitly disallows unknown options.\nconst strict = new RuleSet({\n unexpectedFields: RuleType.FAIL,\n});\n\n// import all options that are configurable\nstrict.import(configurableOptions);\n\n// import all options that are definitely incompatible\nstrict.import(incompatibleOptions);\n\n// strict family options\nstrict.import(strictFamilyOptions);\n\n// Best practice rules\nstrict.shouldPass('target', Match.oneOf('es2022', 'es2023', 'esnext')); // node18+\nstrict.shouldPass('lib', Match.anyOf(Match.arrEq(['es2022']), Match.arrEq(['es2023']), Match.arrEq(['esnext']))); // node18+\nstrict.shouldPass('module', Match.oneOf('node16', 'node18', 'node20', 'nodenext', 'commonjs'));\nstrict.shouldPass('moduleResolution', Match.optional(Match.oneOf('node16', 'nodenext', 'bundler')));\nstrict.shouldPass('skipLibCheck', Match.TRUE);\nstrict.shouldPass('stripInternal', Match.optional(Match.FALSE));\nstrict.shouldPass('noEmitOnError', Match.TRUE);\nstrict.shouldPass('declaration', Match.TRUE);\nstrict.shouldPass('noUncheckedSideEffectImports', Match.optional(Match.TRUE));\n\n// Deprecated ts options that should not be used with jsii\nstrict.import(deprecatedOptions);\n\nexport default strict;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TypeScriptConfig, TypeScriptConfigValidationRuleSet } from '.';
|
|
2
|
+
import { RuleDescription, RuleSet, Violation } from './validator';
|
|
2
3
|
export declare class TypeScriptConfigValidator {
|
|
3
4
|
ruleSet: TypeScriptConfigValidationRuleSet;
|
|
4
5
|
private readonly validator;
|
|
@@ -13,4 +14,42 @@ export declare class TypeScriptConfigValidator {
|
|
|
13
14
|
*/
|
|
14
15
|
validate(tsconfig: TypeScriptConfig): void;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the `compilerOptions` rule set that backs the given validation setting.
|
|
19
|
+
*
|
|
20
|
+
* These are the substantive, set-specific rules (the top-level rules such as
|
|
21
|
+
* `files`/`include`/`exclude` are identical across all sets). The `off` rule set
|
|
22
|
+
* is empty, as it disables validation.
|
|
23
|
+
*
|
|
24
|
+
* @param ruleSet the validation setting to look up
|
|
25
|
+
* @returns the `RuleSet` applied to `compilerOptions`
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCompilerOptionsRuleSet(ruleSet: TypeScriptConfigValidationRuleSet): RuleSet;
|
|
28
|
+
/**
|
|
29
|
+
* Produces a human-readable description of every `compilerOptions` rule in a rule set.
|
|
30
|
+
*
|
|
31
|
+
* @param ruleSet the validation setting to describe
|
|
32
|
+
* @returns a description for every rule in the set
|
|
33
|
+
*/
|
|
34
|
+
export declare function describeRuleSet(ruleSet: TypeScriptConfigValidationRuleSet): RuleDescription[];
|
|
35
|
+
/**
|
|
36
|
+
* Reads and parses a `tsconfig.json` file from disk into the format expected by
|
|
37
|
+
* the validator. This resolves `extends` and normalizes the options the same way
|
|
38
|
+
* the compiler does, so validation behaves identically to a real compilation.
|
|
39
|
+
*
|
|
40
|
+
* @param configPath the path to the tsconfig file to read
|
|
41
|
+
* @throws {@link JsiiError} if the file cannot be read or parsed
|
|
42
|
+
* @returns the parsed TypeScript configuration
|
|
43
|
+
*/
|
|
44
|
+
export declare function readTypeScriptConfig(configPath: string): TypeScriptConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Reads a `tsconfig.json` file from disk and validates its `compilerOptions`
|
|
47
|
+
* against the given rule set, without running a compilation.
|
|
48
|
+
*
|
|
49
|
+
* @param configPath the path to the tsconfig file to validate
|
|
50
|
+
* @param ruleSet the rule set to validate against
|
|
51
|
+
* @throws {@link JsiiError} if the file cannot be read or parsed
|
|
52
|
+
* @returns the list of rule violations (empty if the config is valid)
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateTypeScriptConfigFile(configPath: string, ruleSet: TypeScriptConfigValidationRuleSet): Violation[];
|
|
16
55
|
//# sourceMappingURL=tsconfig-validator.d.ts.map
|
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.TypeScriptConfigValidator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
40
|
+
exports.getCompilerOptionsRuleSet = getCompilerOptionsRuleSet;
|
|
41
|
+
exports.describeRuleSet = describeRuleSet;
|
|
42
|
+
exports.readTypeScriptConfig = readTypeScriptConfig;
|
|
43
|
+
exports.validateTypeScriptConfigFile = validateTypeScriptConfigFile;
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const ts = __importStar(require("typescript"));
|
|
46
|
+
const compiler_options_1 = require("./compiler-options");
|
|
47
|
+
const utils_1 = require("../utils");
|
|
48
|
+
const generated_public_1 = __importDefault(require("./rulesets/generated.public"));
|
|
49
|
+
const minimal_public_1 = __importDefault(require("./rulesets/minimal.public"));
|
|
50
|
+
const strict_public_1 = __importDefault(require("./rulesets/strict.public"));
|
|
7
51
|
const validator_1 = require("./validator");
|
|
8
52
|
const RuleSets = {
|
|
9
53
|
generated: generated_public_1.default,
|
|
@@ -12,6 +56,9 @@ const RuleSets = {
|
|
|
12
56
|
off: new validator_1.RuleSet(),
|
|
13
57
|
};
|
|
14
58
|
class TypeScriptConfigValidator {
|
|
59
|
+
ruleSet;
|
|
60
|
+
validator;
|
|
61
|
+
compilerOptions;
|
|
15
62
|
constructor(ruleSet) {
|
|
16
63
|
this.ruleSet = ruleSet;
|
|
17
64
|
const topLevelRules = new validator_1.RuleSet({
|
|
@@ -43,4 +90,78 @@ class TypeScriptConfigValidator {
|
|
|
43
90
|
}
|
|
44
91
|
}
|
|
45
92
|
exports.TypeScriptConfigValidator = TypeScriptConfigValidator;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the `compilerOptions` rule set that backs the given validation setting.
|
|
95
|
+
*
|
|
96
|
+
* These are the substantive, set-specific rules (the top-level rules such as
|
|
97
|
+
* `files`/`include`/`exclude` are identical across all sets). The `off` rule set
|
|
98
|
+
* is empty, as it disables validation.
|
|
99
|
+
*
|
|
100
|
+
* @param ruleSet the validation setting to look up
|
|
101
|
+
* @returns the `RuleSet` applied to `compilerOptions`
|
|
102
|
+
*/
|
|
103
|
+
function getCompilerOptionsRuleSet(ruleSet) {
|
|
104
|
+
return RuleSets[ruleSet];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Produces a human-readable description of every `compilerOptions` rule in a rule set.
|
|
108
|
+
*
|
|
109
|
+
* @param ruleSet the validation setting to describe
|
|
110
|
+
* @returns a description for every rule in the set
|
|
111
|
+
*/
|
|
112
|
+
function describeRuleSet(ruleSet) {
|
|
113
|
+
return getCompilerOptionsRuleSet(ruleSet).describe();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Reads and parses a `tsconfig.json` file from disk into the format expected by
|
|
117
|
+
* the validator. This resolves `extends` and normalizes the options the same way
|
|
118
|
+
* the compiler does, so validation behaves identically to a real compilation.
|
|
119
|
+
*
|
|
120
|
+
* @param configPath the path to the tsconfig file to read
|
|
121
|
+
* @throws {@link JsiiError} if the file cannot be read or parsed
|
|
122
|
+
* @returns the parsed TypeScript configuration
|
|
123
|
+
*/
|
|
124
|
+
function readTypeScriptConfig(configPath) {
|
|
125
|
+
const absolutePath = path.resolve(configPath);
|
|
126
|
+
const { config, error } = ts.readConfigFile(absolutePath, ts.sys.readFile);
|
|
127
|
+
if (error) {
|
|
128
|
+
throw new utils_1.JsiiError(`Failed to read tsconfig at "${configPath}": ${ts.flattenDiagnosticMessageText(error.messageText, '\n')}`);
|
|
129
|
+
}
|
|
130
|
+
const basePath = path.dirname(absolutePath);
|
|
131
|
+
const extended = ts.parseJsonConfigFileContent(config, ts.sys, basePath);
|
|
132
|
+
// the tsconfig parser adds this in, but it is not an expected compilerOption
|
|
133
|
+
delete extended.options.configFilePath;
|
|
134
|
+
return {
|
|
135
|
+
compilerOptions: extended.options,
|
|
136
|
+
watchOptions: extended.watchOptions,
|
|
137
|
+
include: extended.fileNames,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Reads a `tsconfig.json` file from disk and validates its `compilerOptions`
|
|
142
|
+
* against the given rule set, without running a compilation.
|
|
143
|
+
*
|
|
144
|
+
* @param configPath the path to the tsconfig file to validate
|
|
145
|
+
* @param ruleSet the rule set to validate against
|
|
146
|
+
* @throws {@link JsiiError} if the file cannot be read or parsed
|
|
147
|
+
* @returns the list of rule violations (empty if the config is valid)
|
|
148
|
+
*/
|
|
149
|
+
function validateTypeScriptConfigFile(configPath, ruleSet) {
|
|
150
|
+
const config = readTypeScriptConfig(configPath);
|
|
151
|
+
const validator = new TypeScriptConfigValidator(ruleSet);
|
|
152
|
+
try {
|
|
153
|
+
validator.validate({
|
|
154
|
+
...config,
|
|
155
|
+
// convert the internal format to the user format which is what the validator operates on
|
|
156
|
+
compilerOptions: (0, compiler_options_1.convertForJson)(config.compilerOptions),
|
|
157
|
+
});
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof validator_1.ValidationError) {
|
|
162
|
+
return error.violations;
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
46
167
|
//# sourceMappingURL=tsconfig-validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig-validator.js","sourceRoot":"","sources":["../../src/tsconfig/tsconfig-validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tsconfig-validator.js","sourceRoot":"","sources":["../../src/tsconfig/tsconfig-validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,8DAEC;AAQD,0CAEC;AAWD,oDAmBC;AAWD,oEAmBC;AA1ID,gDAAkC;AAClC,+CAAiC;AAEjC,yDAAoD;AACpD,oCAAqC;AACrC,mFAAoD;AACpD,+EAAgD;AAChD,6EAA8C;AAC9C,2CAAqH;AAErH,MAAM,QAAQ,GAEV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UAAkB,EAClB,OAA0C;IAE1C,MAAM,MAAM,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,SAAS,CAAC,QAAQ,CAAC;YACjB,GAAG,MAAM;YACT,yFAAyF;YACzF,eAAe,EAAE,IAAA,iCAAc,EAAC,MAAM,CAAC,eAAe,CAAC;SACxD,CAAC,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,2BAAe,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC,UAAU,CAAC;QAC1B,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import * as path from 'node:path';\nimport * as ts from 'typescript';\nimport { TypeScriptConfig, TypeScriptConfigValidationRuleSet } from '.';\nimport { convertForJson } from './compiler-options';\nimport { JsiiError } from '../utils';\nimport generated from './rulesets/generated.public';\nimport minimal from './rulesets/minimal.public';\nimport strict from './rulesets/strict.public';\nimport { Match, ObjectValidator, RuleDescription, RuleSet, RuleType, ValidationError, Violation } from './validator';\n\nconst RuleSets: {\n [name in TypeScriptConfigValidationRuleSet]: RuleSet;\n} = {\n generated,\n strict,\n minimal,\n off: new RuleSet(),\n};\n\nexport class TypeScriptConfigValidator {\n private readonly validator: ObjectValidator;\n private readonly compilerOptions: ObjectValidator;\n\n public constructor(public ruleSet: TypeScriptConfigValidationRuleSet) {\n const topLevelRules = new RuleSet({\n unexpectedFields: RuleType.PASS,\n });\n topLevelRules.shouldPass('files', Match.ANY);\n topLevelRules.shouldPass('extends', Match.ANY);\n topLevelRules.shouldPass('include', Match.ANY);\n topLevelRules.shouldPass('exclude', Match.ANY);\n topLevelRules.shouldPass('references', Match.ANY);\n topLevelRules.shouldPass('watchOptions', Match.ANY);\n topLevelRules.shouldPass('typeAcquisition', Match.MISSING);\n\n this.compilerOptions = new ObjectValidator(RuleSets[ruleSet], 'compilerOptions');\n topLevelRules.shouldPass('compilerOptions', (compilerOptions) => {\n this.compilerOptions.validate(compilerOptions);\n return true;\n });\n\n this.validator = new ObjectValidator(topLevelRules, 'tsconfig');\n }\n\n /**\n * Validated the provided config against the set of rules.\n *\n * @throws when the config is invalid\n *\n * @param tsconfig the tsconfig to be validated, this MUST be a tsconfig as a user would have written it in tsconfig.\n */\n public validate(tsconfig: TypeScriptConfig) {\n this.validator.validate(tsconfig);\n }\n}\n\n/**\n * Returns the `compilerOptions` rule set that backs the given validation setting.\n *\n * These are the substantive, set-specific rules (the top-level rules such as\n * `files`/`include`/`exclude` are identical across all sets). The `off` rule set\n * is empty, as it disables validation.\n *\n * @param ruleSet the validation setting to look up\n * @returns the `RuleSet` applied to `compilerOptions`\n */\nexport function getCompilerOptionsRuleSet(ruleSet: TypeScriptConfigValidationRuleSet): RuleSet {\n return RuleSets[ruleSet];\n}\n\n/**\n * Produces a human-readable description of every `compilerOptions` rule in a rule set.\n *\n * @param ruleSet the validation setting to describe\n * @returns a description for every rule in the set\n */\nexport function describeRuleSet(ruleSet: TypeScriptConfigValidationRuleSet): RuleDescription[] {\n return getCompilerOptionsRuleSet(ruleSet).describe();\n}\n\n/**\n * Reads and parses a `tsconfig.json` file from disk into the format expected by\n * the validator. This resolves `extends` and normalizes the options the same way\n * the compiler does, so validation behaves identically to a real compilation.\n *\n * @param configPath the path to the tsconfig file to read\n * @throws {@link JsiiError} if the file cannot be read or parsed\n * @returns the parsed TypeScript configuration\n */\nexport function readTypeScriptConfig(configPath: string): TypeScriptConfig {\n const absolutePath = path.resolve(configPath);\n const { config, error } = ts.readConfigFile(absolutePath, ts.sys.readFile);\n if (error) {\n throw new JsiiError(\n `Failed to read tsconfig at \"${configPath}\": ${ts.flattenDiagnosticMessageText(error.messageText, '\\n')}`,\n );\n }\n\n const basePath = path.dirname(absolutePath);\n const extended = ts.parseJsonConfigFileContent(config, ts.sys, basePath);\n // the tsconfig parser adds this in, but it is not an expected compilerOption\n delete extended.options.configFilePath;\n\n return {\n compilerOptions: extended.options,\n watchOptions: extended.watchOptions,\n include: extended.fileNames,\n };\n}\n\n/**\n * Reads a `tsconfig.json` file from disk and validates its `compilerOptions`\n * against the given rule set, without running a compilation.\n *\n * @param configPath the path to the tsconfig file to validate\n * @param ruleSet the rule set to validate against\n * @throws {@link JsiiError} if the file cannot be read or parsed\n * @returns the list of rule violations (empty if the config is valid)\n */\nexport function validateTypeScriptConfigFile(\n configPath: string,\n ruleSet: TypeScriptConfigValidationRuleSet,\n): Violation[] {\n const config = readTypeScriptConfig(configPath);\n const validator = new TypeScriptConfigValidator(ruleSet);\n try {\n validator.validate({\n ...config,\n // convert the internal format to the user format which is what the validator operates on\n compilerOptions: convertForJson(config.compilerOptions),\n });\n return [];\n } catch (error: unknown) {\n if (error instanceof ValidationError) {\n return error.violations;\n }\n throw error;\n }\n}\n"]}
|
|
@@ -42,6 +42,30 @@ interface Rule {
|
|
|
42
42
|
type: RuleType;
|
|
43
43
|
matcher: Matcher;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* A human-readable description of a single rule.
|
|
47
|
+
* Intended for displaying a rule set to a user, e.g. via the CLI.
|
|
48
|
+
*/
|
|
49
|
+
export interface RuleDescription {
|
|
50
|
+
/**
|
|
51
|
+
* The field (compilerOption) the rule applies to.
|
|
52
|
+
*/
|
|
53
|
+
readonly field: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the value must match (`PASS`) or must not match (`FAIL`) the constraint.
|
|
56
|
+
*/
|
|
57
|
+
readonly type: RuleType;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the field is required to be present for the rule to pass.
|
|
60
|
+
*/
|
|
61
|
+
readonly required: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The values the matcher offered as hints.
|
|
64
|
+
* For `PASS` rules these are allowed values, for `FAIL` rules these are disallowed values.
|
|
65
|
+
* `undefined` when the matcher did not offer any hints (e.g. any value is accepted).
|
|
66
|
+
*/
|
|
67
|
+
readonly values?: any[];
|
|
68
|
+
}
|
|
45
69
|
export declare class RuleSet {
|
|
46
70
|
readonly options: RuleSetOptions;
|
|
47
71
|
private _rules;
|
|
@@ -93,12 +117,27 @@ export declare class RuleSet {
|
|
|
93
117
|
* @returns A record of fields and allowed values
|
|
94
118
|
*/
|
|
95
119
|
getFieldHints(): Record<string, any[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Produces a human-readable description of every rule in the set.
|
|
122
|
+
*
|
|
123
|
+
* This is derived directly from the rules (it does not duplicate them), so it
|
|
124
|
+
* stays in sync as rules are added or changed. It is primarily intended for
|
|
125
|
+
* surfacing a rule set to a user, e.g. via the CLI.
|
|
126
|
+
*
|
|
127
|
+
* @returns A description for every rule, in the order the rules were added.
|
|
128
|
+
*/
|
|
129
|
+
describe(): RuleDescription[];
|
|
96
130
|
}
|
|
97
131
|
export declare class Match {
|
|
98
132
|
/**
|
|
99
133
|
* Value is optional, but if present should match
|
|
100
134
|
*/
|
|
101
135
|
static optional(matcher: Matcher): Matcher;
|
|
136
|
+
/**
|
|
137
|
+
* Value must match at least one of the provided matchers.
|
|
138
|
+
* All matchers are evaluated (no short-circuit) so their hints are collected.
|
|
139
|
+
*/
|
|
140
|
+
static anyOf(...matchers: Matcher[]): Matcher;
|
|
102
141
|
/**
|
|
103
142
|
* Value must be one of the allowed options
|
|
104
143
|
*/
|