Skip to content

Commit 237a61f

Browse files
authored
Merge pull request #160 from rwjblue/add-cjs-wrapper
2 parents 05972a5 + 5d8def5 commit 237a61f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: .eslintrc.cjs

+8
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ module.exports = {
1212
rules: {
1313
'prettier/prettier': 'error',
1414
},
15+
overrides: [
16+
{
17+
files: ['**/*.cjs'],
18+
parserOptions: {
19+
sourceType: 'script',
20+
},
21+
},
22+
],
1523
};

Diff for: cjs-wrapper.cjs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// this will be populated inside the static `isEnabled` method just below
2+
let RealPlugin;
3+
4+
module.exports = class FakeCJSWrapperPlugin {
5+
static async isEnabled() {
6+
// we use the async of this method to enable us to absorb the dynamic
7+
// import statement
8+
9+
// dynamic `import()` statements work on Node ^12.17.0 and >= 14; which
10+
// is within our support range; we can remove this inline disable
11+
// when https://github.com/mysticatea/eslint-plugin-node/pull/256 (or another
12+
// PR like it) lands
13+
14+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
15+
let RealPluginModule = await import('./index.js');
16+
RealPlugin = RealPluginModule.default;
17+
}
18+
19+
constructor(...args) {
20+
// now we just use the "real plugin" as is
21+
return new RealPlugin(...args);
22+
}
23+
};

Diff for: package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
"release-it": "^14.11.6",
4444
"sinon": "^11.1.2"
4545
},
46+
"exports": {
47+
".": {
48+
"import": "./index.js",
49+
"require": "./cjs-wrapper.cjs"
50+
}
51+
},
4652
"peerDependencies": {
4753
"release-it": "^14.0.0"
4854
},
@@ -54,7 +60,7 @@
5460
},
5561
"release-it": {
5662
"plugins": {
57-
"./index.js": {
63+
"./cjs-wrapper.cjs": {
5864
"infile": "CHANGELOG.md",
5965
"launchEditor": true
6066
}

0 commit comments

Comments
 (0)