check-side-effects
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -54,2 +54,3 @@ "use strict"; | ||
var path_1 = require("path"); | ||
var diff_1 = require("diff"); | ||
var minimist_1 = __importDefault(require("minimist")); | ||
@@ -59,3 +60,3 @@ var checker_1 = require("./checker"); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var options, testFilePath, testJson, testFileDir_1, failedExpectations, _i, _a, test, unresolvedEsModules, esModules, esModulesDescription, checkSideEffectsOptions, result, expectedOutputPath, expectedOutput, failedExpectationsDescription, esModules, checkSideEffectsOptions; | ||
var options, testFilePath, testJson, testFileDir_1, failedExpectations, _i, _a, test, unresolvedEsModules, esModules, modulesDescription, checkSideEffectsOptions, result, expectedOutputPath, expectedOutput, diff, esModules, checkSideEffectsOptions; | ||
return __generator(this, function (_b) { | ||
@@ -116,5 +117,5 @@ switch (_b.label) { | ||
esModules = unresolvedEsModules.map(function (esm) { return path_1.resolve(testFileDir_1, esm); }); | ||
esModulesDescription = unresolvedEsModules.join(' '); | ||
modulesDescription = unresolvedEsModules.join(' '); | ||
// These tests can take a while. Inform the user of progress. | ||
console.log("Testing " + esModulesDescription); | ||
console.log("Testing " + modulesDescription); | ||
checkSideEffectsOptions = __assign({ esModules: esModules, cwd: options.cwd }, test.options); | ||
@@ -135,3 +136,4 @@ return [4 /*yield*/, checker_1.checkSideEffects(checkSideEffectsOptions)]; | ||
if (result != expectedOutput) { | ||
failedExpectations.push(esModulesDescription); | ||
diff = diff_1.createPatch(expectedOutputPath, expectedOutput, result); | ||
failedExpectations.push(diff); | ||
if (options.update) { | ||
@@ -150,9 +152,13 @@ _recursiveMkDir(path_1.dirname(expectedOutputPath)); | ||
if (failedExpectations.length > 0) { | ||
failedExpectationsDescription = failedExpectations.map(function (s) { return " " + s; }).join('\n'); | ||
console.log('The following snapshots have changed:\n\n'); | ||
console.log(failedExpectations.map(function (diff) { return diff + "\n"; }).join('\n')); | ||
if (options.update) { | ||
console.log("Test expectations updated for modules:\n" + failedExpectationsDescription + "\n"); | ||
console.log(failedExpectations.length + " test expectations updated.\n"); | ||
} | ||
else { | ||
throw "Tests failed for modules:\n" + failedExpectationsDescription + "\n" + | ||
"\nTo update the expectations, run this command again with the --update flag.\n"; | ||
console.log(failedExpectations.length + " tests failed, see above for diffs."); | ||
console.log("To update the expectations, run this command again with the --update flag:"); | ||
console.log(""); | ||
console.log(" " + rawOpts.args.join(' ') + " --update"); | ||
throw ""; | ||
} | ||
@@ -159,0 +165,0 @@ } |
{ | ||
"name": "check-side-effects", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Check if a ES module has side effects.", | ||
@@ -21,2 +21,3 @@ "repository": "https://github.com/filipesilva/check-side-effects", | ||
"@angular-devkit/build-optimizer": "0.14.0-beta.5", | ||
"diff": "^4.0.1", | ||
"minimist": "~1.2.0", | ||
@@ -28,2 +29,3 @@ "rollup": "~1.11.3", | ||
"devDependencies": { | ||
"@types/diff": "^4.0.2", | ||
"@types/minimist": "~1.2.0", | ||
@@ -30,0 +32,0 @@ "@types/terser": "~3.8.0", |
@@ -131,2 +131,23 @@ # Check side effects | ||
## TSLint rules | ||
You can find a [TSLint](https://palantir.github.io/tslint/) rule to detect toplevel property access in the `tslint-no-toplevel-property-access` npm package. | ||
You can use it by adding the path below to `rulesDirectory` and the `no-toplevel-property-access` rule. Path fragments to include are optional and, if omitted, all TS files will be checked. | ||
```json | ||
{ | ||
"rulesDirectory": [ | ||
"node_modules/tslint-no-toplevel-property-access/rules" | ||
], | ||
"rules": { | ||
"no-toplevel-property-access": [ | ||
true, | ||
"/path/fragments/to/include/", | ||
"/another/path/fragment/to/include/" | ||
] | ||
} | ||
} | ||
``` | ||
## Developing on this repository | ||
@@ -133,0 +154,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35746
341
159
6
4
+ Addeddiff@^4.0.1
+ Addeddiff@4.0.2(transitive)