Skip to content

Commit

Permalink
Merge pull request #160 from rwjblue/add-cjs-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Oct 15, 2021
2 parents 05972a5 + 5d8def5 commit 237a61f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ module.exports = {
rules: {
'prettier/prettier': 'error',
},
overrides: [
{
files: ['**/*.cjs'],
parserOptions: {
sourceType: 'script',
},
},
],
};
23 changes: 23 additions & 0 deletions cjs-wrapper.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// this will be populated inside the static `isEnabled` method just below
let RealPlugin;

module.exports = class FakeCJSWrapperPlugin {
static async isEnabled() {
// we use the async of this method to enable us to absorb the dynamic
// import statement

// dynamic `import()` statements work on Node ^12.17.0 and >= 14; which
// is within our support range; we can remove this inline disable
// when https://github.com/mysticatea/eslint-plugin-node/pull/256 (or another
// PR like it) lands

// eslint-disable-next-line node/no-unsupported-features/es-syntax
let RealPluginModule = await import('./index.js');
RealPlugin = RealPluginModule.default;
}

constructor(...args) {
// now we just use the "real plugin" as is
return new RealPlugin(...args);
}
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"release-it": "^14.11.6",
"sinon": "^11.1.2"
},
"exports": {
".": {
"import": "./index.js",
"require": "./cjs-wrapper.cjs"
}
},
"peerDependencies": {
"release-it": "^14.0.0"
},
Expand All @@ -54,7 +60,7 @@
},
"release-it": {
"plugins": {
"./index.js": {
"./cjs-wrapper.cjs": {
"infile": "CHANGELOG.md",
"launchEditor": true
}
Expand Down

0 comments on commit 237a61f

Please sign in to comment.