Skip to content

Commit

Permalink
build: use release-please for automating releases (istanbuljs#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Sep 13, 2021
1 parent 265d6b9 commit 091a183
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 92 deletions.
5 changes: 0 additions & 5 deletions babel.config.js

This file was deleted.

17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,30 @@
"version": "4.0.3",
"description": "Core istanbul API for JS code coverage",
"author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>",
"main": "dist/index.js",
"main": "src/index.js",
"files": [
"dist"
"src"
],
"scripts": {
"release": "babel src --out-dir dist && documentation build -f md -o api.md src",
"test": "nyc --nycrc-path=../../monorepo-per-package-nycrc.json --require=@babel/register --include=src mocha",
"prepublish": "npm run release"
"test": "nyc mocha"
},
"dependencies": {
"@babel/core": "^7.7.5",
"@babel/core": "^7.12.3",
"@babel/parser": "^7.14.7",
"@istanbuljs/schema": "^0.1.2",
"istanbul-lib-coverage": "^3.0.0",
"semver": "^6.3.0"
},
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/plugin-transform-modules-commonjs": "^7.7.5",
"@babel/register": "^7.7.4",
"chai": "^4.2.0",
"clone": "^2.1.2",
"debug": "^4.1.1",
"documentation": "^12.1.4",
"js-yaml": "^3.13.1",
"mocha": "^6.2.2",
"mocha": "^6.2.3",
"nopt": "^4.0.1",
"nyc": "^15.0.0-beta.2"
"nyc": "^15.1.0"
},
"license": "BSD-3-Clause",
"bugs": {
Expand Down
22 changes: 11 additions & 11 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createHash } from 'crypto';
import { major } from 'semver';
import { name, version } from '../package.json';
const { createHash } = require('crypto');
const { major } = require('semver');
const { name, version } = require('../package.json');

// function to use for creating hashes
export const SHA = 'sha1';
// name of coverage data magic key
export const MAGIC_KEY = '_coverageSchema';
// name of coverage data magic value
export const MAGIC_VALUE = createHash(SHA)
.update(name + '@' + major(version))
.digest('hex');
const SHA = 'sha1';
module.exports = {
SHA,
MAGIC_KEY: '_coverageSchema',
MAGIC_VALUE: createHash(SHA)
.update(name + '@' + major(version))
.digest('hex')
};
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defaults } from '@istanbuljs/schema';
import Instrumenter from './instrumenter';
import programVisitor from './visitor';
import readInitialCoverage from './read-coverage';
const { defaults } = require('@istanbuljs/schema');
const Instrumenter = require('./instrumenter');
const programVisitor = require('./visitor');
const readInitialCoverage = require('./read-coverage');

/**
* createInstrumenter creates a new instrumenter with the
Expand All @@ -13,8 +13,9 @@ function createInstrumenter(opts) {
return new Instrumenter(opts);
}

export { createInstrumenter };
export { programVisitor };
export { readInitialCoverage };

export const defaultOpts = defaults.instrumenter;
module.exports = {
createInstrumenter,
programVisitor,
readInitialCoverage,
defaultOpts: defaults.instrumenter
};
10 changes: 5 additions & 5 deletions src/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Copyright 2012-2015, Yahoo Inc.
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
import { transformSync } from '@babel/core';
import { defaults } from '@istanbuljs/schema';
import programVisitor from './visitor';
import readInitialCoverage from './read-coverage';
const { transformSync } = require('@babel/core');
const { defaults } = require('@istanbuljs/schema');
const programVisitor = require('./visitor');
const readInitialCoverage = require('./read-coverage');

/**
* Instrumenter is the public API for the instrument library.
Expand Down Expand Up @@ -155,4 +155,4 @@ class Instrumenter {
}
}

export default Instrumenter;
module.exports = Instrumenter;
10 changes: 5 additions & 5 deletions src/read-coverage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseSync, traverse } from '@babel/core';
import { defaults } from '@istanbuljs/schema';
import { MAGIC_KEY, MAGIC_VALUE } from './constants';
const { parseSync, traverse } = require('@babel/core');
const { defaults } = require('@istanbuljs/schema');
const { MAGIC_KEY, MAGIC_VALUE } = require('./constants');

function getAst(code) {
if (typeof code === 'object' && typeof code.type === 'string') {
Expand All @@ -26,7 +26,7 @@ function getAst(code) {
});
}

export default function readInitialCoverage(code) {
module.exports = function readInitialCoverage(code) {
const ast = getAst(code);

let covScope;
Expand Down Expand Up @@ -73,4 +73,4 @@ export default function readInitialCoverage(code) {
delete result.coverageData.hash;

return result;
}
};
4 changes: 2 additions & 2 deletions src/source-coverage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { classes } from 'istanbul-lib-coverage';
const { classes } = require('istanbul-lib-coverage');

function cloneLocation(loc) {
return {
Expand Down Expand Up @@ -106,4 +106,4 @@ class SourceCoverage extends classes.FileCoverage {
}
}

export { SourceCoverage };
module.exports = { SourceCoverage };
12 changes: 6 additions & 6 deletions src/visitor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createHash } from 'crypto';
import { template } from '@babel/core';
import { defaults } from '@istanbuljs/schema';
import { SourceCoverage } from './source-coverage';
import { SHA, MAGIC_KEY, MAGIC_VALUE } from './constants';
const { createHash } = require('crypto');
const { template } = require('@babel/core');
const { defaults } = require('@istanbuljs/schema');
const { SourceCoverage } = require('./source-coverage');
const { SHA, MAGIC_KEY, MAGIC_VALUE } = require('./constants');

// pattern for istanbul to ignore a section
const COMMENT_RE = /^\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/;
Expand Down Expand Up @@ -679,4 +679,4 @@ function programVisitor(types, sourceFilePath = 'unknown.js', opts = {}) {
};
}

export default programVisitor;
module.exports = programVisitor;
4 changes: 2 additions & 2 deletions test/already-instrumented.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals it */

import { assert } from 'chai';
import Instrumenter from '../src/instrumenter';
const { assert } = require('chai');
const Instrumenter = require('../src/instrumenter');

function instrument(code, inputSourceMap) {
const instrumenter = new Instrumenter({ compact: false });
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe, it */
import { assert } from 'chai';
import * as index from '../src/index';
const { assert } = require('chai');
const index = require('../src/index');

describe('external interface', () => {
it('exposes the correct objects', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/negative.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe, it */

import { assert } from 'chai';
import * as verifier from './util/verifier';
const { assert } = require('chai');
const verifier = require('./util/verifier');

describe('negative tests', () => {
it('should barf on junk code', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/plugins.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe, it, context */

import { assert } from 'chai';
import Instrumenter from '../src/instrumenter';
const { assert } = require('chai');
const Instrumenter = require('../src/instrumenter');

const codeNeedDecoratorPlugin = `
@decorator
Expand Down
12 changes: 6 additions & 6 deletions test/specs.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* globals describe, it */

import * as path from 'path';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import { assert } from 'chai';
import * as verifier from './util/verifier';
import * as guards from './util/guards';
const path = require('path');
const fs = require('fs');
const yaml = require('js-yaml');
const { assert } = require('chai');
const verifier = require('./util/verifier');
const guards = require('./util/guards');

const clone = require('clone');

Expand Down
2 changes: 1 addition & 1 deletion test/specs/if-hints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ name: ignore chained else
code: |
if (args[0] === 1) {
output = '1';
} /* istanbul ignore else */ else if (args[0] === 2) {
} else /* istanbul ignore else */ if (args[0] === 2) {
output = '2';
} else if (args[0] === 3) {
output = '3';
Expand Down
2 changes: 1 addition & 1 deletion test/specs/statement-hints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ tests:
---
name: ignore in complex logical expression
code: >
if (args[0] === 1 || /* istanbul ignore next */ (args[0] === 2 || args[0] === 3)) {
if (args[0] === 1 || (/* istanbul ignore next */ args[0] === 2 || args[0] === 3)) {
output = args[0] + 10;
} else {
output = 20;
Expand Down
45 changes: 31 additions & 14 deletions test/util/guards.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ function tryThis(str, feature, generateOnly) {
return true;
}

export function isYieldAvailable() {
function isYieldAvailable() {
return tryThis('function *foo() { yield 1; }', 'yield');
}

export function isClassPropAvailable() {
function isClassPropAvailable() {
return tryThis('class Foo { a = 1; }', 'class property');
}

export function isClassPrivatePropAvailable() {
function isClassPrivatePropAvailable() {
return tryThis('class Foo { #a = 1; }', 'class private property');
}

export function isForOfAvailable() {
function isForOfAvailable() {
return tryThis(
'function *foo() { yield 1; }\n' + 'for (var k of foo()) {}',
'for-of'
);
}

export function isArrowFnAvailable() {
function isArrowFnAvailable() {
return tryThis('[1 ,2, 3].map(x => x * x)', 'arrow function');
}

export function isObjectSpreadAvailable() {
function isObjectSpreadAvailable() {
return tryThis('const a = {...{b: 33}}', 'object-spread');
}

export function isObjectFreezeAvailable() {
function isObjectFreezeAvailable() {
if (!Object.freeze) {
return false;
}
Expand All @@ -54,34 +54,51 @@ export function isObjectFreezeAvailable() {
}
}

export function isOptionalCatchBindingAvailable() {
function isOptionalCatchBindingAvailable() {
return tryThis('try {} catch {}');
}

export function isImportAvailable() {
function isImportAvailable() {
return tryThis('import fs from "fs"', 'import', true);
}

export function isExportAvailable() {
function isExportAvailable() {
return tryThis('export default function foo() {}', 'export', true);
}

export function isDefaultArgsAvailable() {
function isDefaultArgsAvailable() {
return tryThis('function foo(a=1) { return a + 1; }', 'default args');
}

export function isInferredFunctionNameAvailable() {
function isInferredFunctionNameAvailable() {
return tryThis(
'const foo = function () {}; require("assert").equal(foo.name, "foo")'
);
}

export function isInferredClassNameAvailable() {
function isInferredClassNameAvailable() {
return tryThis(
'const foo = class {}; require("assert").equal(foo.name, "foo")'
);
}

export function isClassAvailable() {
function isClassAvailable() {
return tryThis("new Function('args', '{class Foo extends (Bar) {}}')");
}

module.exports = {
isClassAvailable,
isInferredClassNameAvailable,
isInferredFunctionNameAvailable,
isDefaultArgsAvailable,
isExportAvailable,
isImportAvailable,
isOptionalCatchBindingAvailable,
isObjectFreezeAvailable,
isYieldAvailable,
isClassPropAvailable,
isClassPrivatePropAvailable,
isForOfAvailable,
isArrowFnAvailable,
isObjectSpreadAvailable
};
12 changes: 6 additions & 6 deletions test/util/verifier.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { classes } from 'istanbul-lib-coverage';
import { assert } from 'chai';
import clone from 'clone';
import Instrumenter from '../../src/instrumenter';
import readInitialCoverage from '../../src/read-coverage';
const { classes } = require('istanbul-lib-coverage');
const { assert } = require('chai');
const clone = require('clone');
const Instrumenter = require('../../src/instrumenter');
const readInitialCoverage = require('../../src/read-coverage');

const FileCoverage = classes.FileCoverage;

Expand Down Expand Up @@ -189,4 +189,4 @@ function create(code, opts, instrumenterOpts, inputSourceMap) {
});
}

export { create };
module.exports = { create };
6 changes: 3 additions & 3 deletions test/varia.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* globals describe, it */

import { assert } from 'chai';
import Instrumenter from '../src/instrumenter';
import * as verifier from './util/verifier';
const { assert } = require('chai');
const Instrumenter = require('../src/instrumenter');
const verifier = require('./util/verifier');

describe('varia', () => {
it('debug/ walkDebug should not cause errors', () => {
Expand Down

0 comments on commit 091a183

Please sign in to comment.