Skip to content

Commit af37269

Browse files
authored
fix: revert the esm migration for now (#253)
1 parent a773c8b commit af37269

17 files changed

+78
-106
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ With this configuration:
162162

163163
##### External package / file
164164

165-
`releaseRules` can also reference a module, either by it's `npm` name or path. Note that the path must include the `.js` extension.
166-
165+
`releaseRules` can also reference a module, either by it's `npm` name or path:
167166
```json
168167
{
169168
"plugins": [
@@ -175,12 +174,9 @@ With this configuration:
175174
]
176175
}
177176
```
178-
179-
The file must be an ES Module exporting an array as default
180-
181177
```js
182178
// File: config/release-rules.js
183-
export default [
179+
module.exports = [
184180
{type: 'docs', scope: 'README', release: 'patch'},
185181
{type: 'refactor', scope: 'core-*', release: 'minor'},
186182
{type: 'refactor', release: 'patch'},

index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import lodash from 'lodash';
2-
const {isUndefined} = lodash;
3-
import {sync as parser} from 'conventional-commits-parser';
4-
import filter from 'conventional-commits-filter';
5-
import debug from 'debug';
6-
import loadParserConfig from './lib/load-parser-config.js';
7-
import loadReleaseRules from './lib/load-release-rules.js';
8-
import analyzeCommit from './lib/analyze-commit.js';
9-
import compareReleaseTypes from './lib/compare-release-types.js';
10-
import RELEASE_TYPES from './lib/default-release-types.js';
11-
import DEFAULT_RELEASE_RULES from './lib/default-release-rules.js';
12-
13-
debug('semantic-release:commit-analyzer');
1+
const {isUndefined} = require('lodash');
2+
const parser = require('conventional-commits-parser').sync;
3+
const filter = require('conventional-commits-filter');
4+
const debug = require('debug')('semantic-release:commit-analyzer');
5+
const loadParserConfig = require('./lib/load-parser-config');
6+
const loadReleaseRules = require('./lib/load-release-rules');
7+
const analyzeCommit = require('./lib/analyze-commit');
8+
const compareReleaseTypes = require('./lib/compare-release-types');
9+
const RELEASE_TYPES = require('./lib/default-release-types');
10+
const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules');
1411

1512
/**
1613
* Determine the type of release to create based on a list of commits.
@@ -28,7 +25,7 @@ debug('semantic-release:commit-analyzer');
2825
*/
2926
async function analyzeCommits(pluginConfig, context) {
3027
const {commits, logger} = context;
31-
const releaseRules = await loadReleaseRules(pluginConfig, context);
28+
const releaseRules = loadReleaseRules(pluginConfig, context);
3229
const config = await loadParserConfig(pluginConfig, context);
3330
let releaseType = null;
3431

@@ -82,4 +79,4 @@ async function analyzeCommits(pluginConfig, context) {
8279
return releaseType;
8380
}
8481

85-
export {analyzeCommits};
82+
module.exports = {analyzeCommits};

lib/analyze-commit.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import lodash from 'lodash';
2-
import micromatch from 'micromatch';
3-
import debug from 'debug';
4-
import RELEASE_TYPES from './default-release-types.js';
5-
import compareReleaseTypes from './compare-release-types.js';
6-
const {isMatchWith, isString} = lodash;
7-
const {isMatch} = micromatch;
8-
debug('semantic-release:commit-analyzer');
1+
const {isMatchWith, isString} = require('lodash');
2+
const micromatch = require('micromatch');
3+
const debug = require('debug')('semantic-release:commit-analyzer');
4+
const RELEASE_TYPES = require('./default-release-types');
5+
const compareReleaseTypes = require('./compare-release-types');
96

107
/**
118
* Find all the rules matching and return the highest release type of the matching rules.
@@ -14,7 +11,7 @@ debug('semantic-release:commit-analyzer');
1411
* @param {Commit} commit a parsed commit.
1512
* @return {string} the highest release type of the matching rules or `undefined` if no rule match the commit.
1613
*/
17-
export default (releaseRules, commit) => {
14+
module.exports = (releaseRules, commit) => {
1815
let releaseType;
1916

2017
releaseRules
@@ -26,7 +23,7 @@ export default (releaseRules, commit) => {
2623
(!revert || commit.revert) &&
2724
// Otherwise match the regular rules
2825
isMatchWith(commit, rule, (object, src) =>
29-
isString(src) && isString(object) ? isMatch(object, src) : undefined
26+
isString(src) && isString(object) ? micromatch.isMatch(object, src) : undefined
3027
)
3128
)
3229
.every(match => {

lib/compare-release-types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import RELEASE_TYPES from './default-release-types.js';
1+
const RELEASE_TYPES = require('./default-release-types');
22

33
/**
44
* Test if a realease type is of higher level than a given one.
@@ -7,5 +7,5 @@ import RELEASE_TYPES from './default-release-types.js';
77
* @param {string} releaseType the release type to compare with.
88
* @return {Boolean} true if `releaseType` is higher than `currentReleaseType`.
99
*/
10-
export default (currentReleaseType, releaseType) =>
10+
module.exports = (currentReleaseType, releaseType) =>
1111
!currentReleaseType || RELEASE_TYPES.indexOf(releaseType) < RELEASE_TYPES.indexOf(currentReleaseType);

lib/default-release-rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @type {Array}
55
*/
6-
export default [
6+
module.exports = [
77
{breaking: true, release: 'major'},
88
{revert: true, release: 'patch'},
99
// Angular

lib/default-release-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
*
44
* @type {Array}
55
*/
6-
export default ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
6+
module.exports = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];

lib/esm-import.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/load-parser-config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {promisify} from 'util';
2-
import lodash from 'lodash';
3-
const {isPlainObject} = lodash;
4-
import {esmImport} from './esm-import.js';
1+
const {promisify} = require('util');
2+
const {isPlainObject} = require('lodash');
3+
const importFrom = require('import-from');
4+
const conventionalChangelogAngular = require('conventional-changelog-angular');
55

66
/**
77
* Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
@@ -14,16 +14,16 @@ import {esmImport} from './esm-import.js';
1414
* @param {String} context.cwd The current working directory.
1515
* @return {Promise<Object>} a `Promise` that resolve to the `conventional-changelog-parser` options.
1616
*/
17-
export default async ({preset, config, parserOpts, presetConfig}, {_}) => {
17+
module.exports = async ({preset, config, parserOpts, presetConfig}, {cwd}) => {
1818
let loadedConfig;
1919

2020
if (preset) {
2121
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
22-
loadedConfig = await esmImport(presetPackage);
22+
loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(cwd, presetPackage);
2323
} else if (config) {
24-
loadedConfig = await esmImport(config);
24+
loadedConfig = importFrom.silent(__dirname, config) || importFrom(cwd, config);
2525
} else {
26-
loadedConfig = await esmImport('conventional-changelog-angular');
26+
loadedConfig = conventionalChangelogAngular;
2727
}
2828

2929
loadedConfig = await (typeof loadedConfig === 'function'

lib/load-release-rules.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import lodash from 'lodash';
2-
const {isUndefined} = lodash;
3-
import {esmImport} from './esm-import.js';
4-
import RELEASE_TYPES from './default-release-types.js';
5-
import {resolve} from 'path';
6-
import {pathToFileURL} from 'url';
1+
const {isUndefined} = require('lodash');
2+
const importFrom = require('import-from');
3+
const RELEASE_TYPES = require('./default-release-types');
74

85
/**
96
* Load and validate the `releaseRules` rules.
@@ -18,12 +15,14 @@ import {pathToFileURL} from 'url';
1815
*
1916
* @return {Array} the loaded and validated `releaseRules`.
2017
*/
21-
export default async ({releaseRules}, {cwd}) => {
18+
module.exports = ({releaseRules}, {cwd}) => {
2219
let loadedReleaseRules;
2320

2421
if (releaseRules) {
2522
loadedReleaseRules =
26-
typeof releaseRules === 'string' ? await esmImport(pathToFileURL(resolve(cwd, releaseRules)).href) : releaseRules;
23+
typeof releaseRules === 'string'
24+
? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
25+
: releaseRules;
2726

2827
if (!Array.isArray(loadedReleaseRules)) {
2928
throw new TypeError('Error in commit-analyzer configuration: "releaseRules" must be an array of rules');

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "@semantic-release/commit-analyzer",
3-
"type": "module",
43
"description": "semantic-release plugin to analyze commits with conventional-changelog",
54
"version": "0.0.0-development",
65
"author": "Pierre Vanduynslager (https://twitter.com/@pvdlg_)",
@@ -57,7 +56,7 @@
5756
"semantic-release"
5857
],
5958
"license": "MIT",
60-
"exports": "./index.js",
59+
"main": "index.js",
6160
"nyc": {
6261
"include": [
6362
"lib/**/*.js",
@@ -95,11 +94,7 @@
9594
"prettier": true,
9695
"space": true,
9796
"rules": {
98-
"unicorn/string-content": "off",
99-
"unicorn/import-index": "off",
100-
"import/extensions": "off",
101-
"import/no-useless-path-segments": "off",
102-
"node/no-unsupported-features/es-syntax": "off"
97+
"unicorn/string-content": "off"
10398
}
10499
},
105100
"renovate": {

test/analyze-commit.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from 'ava';
2-
import analyzeCommit from '../lib/analyze-commit.js';
1+
const test = require('ava');
2+
const analyzeCommit = require('../lib/analyze-commit');
33

44
test('Match breaking change', t => {
55
const commit = {

test/compare-release-types.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import test from 'ava';
2-
import compareReleaseTypes from '../lib/compare-release-types.js';
1+
const test = require('ava');
2+
const compareReleaseTypes = require('../lib/compare-release-types');
33

44
test('Compares release types', t => {
55
t.true(compareReleaseTypes('patch', 'minor'));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default 42;
1+
module.exports = 42;

test/fixtures/release-rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default [
1+
module.exports = [
22
{breaking: true, release: 'major'},
33
{type: 'feat', release: 'minor'},
44
{type: 'fix', release: 'patch'},

test/integration.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import test from 'ava';
2-
import sinon from 'sinon';
3-
import {analyzeCommits} from '../index.js';
1+
const test = require('ava');
2+
const {stub} = require('sinon');
3+
const {analyzeCommits} = require('..');
44

55
const cwd = process.cwd();
66

77
test.beforeEach(t => {
8-
const log = sinon.stub();
8+
const log = stub();
99
t.context.log = log;
1010
t.context.logger = {log};
1111
});
@@ -117,7 +117,7 @@ test('Accept a "releaseRules" option that reference a requierable module', async
117117
{hash: '456', message: 'feat(scope2): Second feature'},
118118
];
119119
const releaseType = await analyzeCommits(
120-
{releaseRules: './test/fixtures/release-rules.js'},
120+
{releaseRules: './test/fixtures/release-rules'},
121121
{cwd, commits, logger: t.context.logger}
122122
);
123123

@@ -357,7 +357,7 @@ test('Throw error if "releaseRules" is not an Array or a String', async t => {
357357
});
358358

359359
test('Throw error if "releaseRules" option reference a requierable module that is not an Array or a String', async t => {
360-
await t.throwsAsync(analyzeCommits({releaseRules: './test/fixtures/release-rules-invalid.js'}, {cwd}), {
360+
await t.throwsAsync(analyzeCommits({releaseRules: './test/fixtures/release-rules-invalid'}, {cwd}), {
361361
message: /Error in commit-analyzer configuration: "releaseRules" must be an array of rules/,
362362
});
363363
});

test/load-parser-config.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import test from 'ava';
2-
import loadParserConfig from '../lib/load-parser-config.js';
3-
import conventionalChangelogAngular from 'conventional-changelog-angular';
1+
const test = require('ava');
2+
const loadParserConfig = require('../lib/load-parser-config');
43

54
const cwd = process.cwd();
65

@@ -35,7 +34,7 @@ async function loadConfig(t, config, pluginOptions) {
3534
loadConfig.title = (providedTitle, config) => `${providedTitle} Load "${config}" config`.trim();
3635

3736
test('Load "conventional-changelog-angular" by default', async t => {
38-
t.deepEqual(await loadParserConfig({}, {cwd}), (await conventionalChangelogAngular).parserOpts);
37+
t.deepEqual(await loadParserConfig({}, {cwd}), (await require('conventional-changelog-angular')).parserOpts);
3938
});
4039

4140
test('Accept a "parserOpts" object as option', async t => {

test/load-release-rules.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import test from 'ava';
2-
import loadReleaseRules from '../lib/load-release-rules.js';
3-
import testReleaseRules from './fixtures/release-rules.js';
1+
const test = require('ava');
2+
const loadReleaseRules = require('../lib/load-release-rules');
3+
const testReleaseRules = require('./fixtures/release-rules');
44

55
const cwd = process.cwd();
66

7-
test('Accept a "releaseRules" option', async t => {
8-
const releaseRules = await loadReleaseRules({releaseRules: testReleaseRules}, {cwd});
7+
test('Accept a "releaseRules" option', t => {
8+
const releaseRules = loadReleaseRules({releaseRules: testReleaseRules}, {cwd});
99

1010
t.deepEqual(releaseRules, testReleaseRules);
1111
});
1212

13-
test('Accept a "releaseRules" option that reference a requierable module', async t => {
14-
const releaseRules = await loadReleaseRules({releaseRules: './test/fixtures/release-rules.js'}, {cwd});
13+
test('Accept a "releaseRules" option that reference a requierable module', t => {
14+
const releaseRules = loadReleaseRules({releaseRules: './test/fixtures/release-rules'}, {cwd});
1515

1616
t.deepEqual(releaseRules, testReleaseRules);
1717
});
1818

19-
test('Return undefined if "releaseRules" not set', async t => {
20-
const releaseRules = await loadReleaseRules({}, {cwd});
19+
test('Return undefined if "releaseRules" not set', t => {
20+
const releaseRules = loadReleaseRules({}, {cwd});
2121

2222
t.is(releaseRules, undefined);
2323
});
2424

25-
test('Preserve release rules set to "false" or "null"', async t => {
26-
const releaseRules = await loadReleaseRules(
25+
test('Preserve release rules set to "false" or "null"', t => {
26+
const releaseRules = loadReleaseRules(
2727
{
2828
releaseRules: [
2929
{type: 'feat', release: false},
@@ -39,32 +39,32 @@ test('Preserve release rules set to "false" or "null"', async t => {
3939
]);
4040
});
4141

42-
test('Throw error if "releaseRules" reference invalid commit type', async t => {
43-
await t.throwsAsync(() => loadReleaseRules({releaseRules: [{tag: 'Update', release: 'invalid'}]}, {cwd}), {
42+
test('Throw error if "releaseRules" reference invalid commit type', t => {
43+
t.throws(() => loadReleaseRules({releaseRules: [{tag: 'Update', release: 'invalid'}]}, {cwd}), {
4444
message: /Error in commit-analyzer configuration: "invalid" is not a valid release type\. Valid values are:\[?.*]/,
4545
});
4646
});
4747

48-
test('Throw error if a rule in "releaseRules" does not have a release type', async t => {
49-
await t.throwsAsync(() => loadReleaseRules({releaseRules: [{tag: 'Update'}]}, {cwd}), {
48+
test('Throw error if a rule in "releaseRules" does not have a release type', t => {
49+
t.throws(() => loadReleaseRules({releaseRules: [{tag: 'Update'}]}, {cwd}), {
5050
message: /Error in commit-analyzer configuration: rules must be an object with a "release" property/,
5151
});
5252
});
5353

54-
test('Throw error if "releaseRules" is not an Array or a String', async t => {
55-
await t.throwsAsync(() => loadReleaseRules({releaseRules: {}}, {cwd}), {
54+
test('Throw error if "releaseRules" is not an Array or a String', t => {
55+
t.throws(() => loadReleaseRules({releaseRules: {}}, {cwd}), {
5656
message: /Error in commit-analyzer configuration: "releaseRules" must be an array of rules/,
5757
});
5858
});
5959

60-
test('Throw error if "releaseRules" option reference a requierable module that is not an Array or a String', async t => {
61-
await t.throwsAsync(() => loadReleaseRules({releaseRules: './test/fixtures/release-rules-invalid.js'}, {cwd}), {
60+
test('Throw error if "releaseRules" option reference a requierable module that is not an Array or a String', t => {
61+
t.throws(() => loadReleaseRules({releaseRules: './test/fixtures/release-rules-invalid'}, {cwd}), {
6262
message: /Error in commit-analyzer configuration: "releaseRules" must be an array of rules/,
6363
});
6464
});
6565

66-
test('Throw error if "releaseRules" contains an undefined rule', async t => {
67-
await t.throwsAsync(() => loadReleaseRules({releaseRules: [{type: 'feat', release: 'minor'}, undefined]}, {cwd}), {
66+
test('Throw error if "releaseRules" contains an undefined rule', t => {
67+
t.throws(() => loadReleaseRules({releaseRules: [{type: 'feat', release: 'minor'}, undefined]}, {cwd}), {
6868
message: /Error in commit-analyzer configuration: rules must be an object with a "release" property/,
6969
});
7070
});

0 commit comments

Comments
 (0)