Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable usage of this plugin by release-it's require based system #160

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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