-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
[Feature Request] ESM Support #1180
Comments
I wasn't planning on moving danger, as you can't Though I think maybe supporting |
Right, I’m much newer to understanding the practical consequences of You said:
I probably should have specified: this ESM-only package could not be imported or used in my Dangerfile. It caused an error. It’s fine for now because I was able to downgrade, but that’s not a long-term solution. — I selected this library by scanning my yarn.lock for likely keywords so this library was already a transitive dependency. This means that now, I have a ticking time-bomb, where this dependency has consciously required ESM, and all my other dependencies that rely on it are A) prevented from upgrading it or B) will be forced to switch to a different provider of the feature, or C) it’s going to spread like a virus, forcing them to go ESM-only. Now maybe I’m totally confused, and there should be a way for DangerJS to import this ESM library — is that the case? |
the dangerfile would be interpreted as either cjs or mjs based on the "type" in your package.json in node, or by the filetype (.cjs/.mjs) - its not on danger to do any different work if you're in an mjs or cjs package as that's still node responsibility, you just hit the timebomb in the same way you would if any of your (cjs) script files would try to import it I could be wrong and you could be running with a package json as type: module, but I think you'd have added that context in the post |
Similar issue here - the latest packages of remark now require ESM.
I've added |
I think what I interpreted from your reply @orta is that DangerJS is fine staying with CJS for its own internals for now, and that DangerJS doesn't care if your repo is ESM or CJS -- evaluating the Dangerfile should work either way. At some point, we're going to need to upgrade one of our Dependencies because of security reasons, and that new version of the package might be ESM-only. I guess we can handle that when we have our first examples. |
Blockers we would have to resolve before we can make DangerJS be ESM:
|
Some libs that will need upgrading once we go to ESM:
(These libraries at older versions are all present in our yarn.lock) |
Actually, further investigation shows that DangerJS is using -- Note: the danger-js/source/runner/runners/inline.ts Lines 46 to 74 in a7355a3
|
I've subscribed to this issue and can explain any ts-node issues you may hit along the way. I'm not familiar with the way ts-node might be used here, if at all, but I see it mentioned above. |
@cspotcode thanks! ts-node is only used in 1 script and a comment, so I expect it will be minor compared to the other issues. Currently those other problems are serious enough that I doubt DangerJS is going to be ESM-compatible for a while. This worries me on DangerJS's behalf, but also I don't think it's DangerJS' fault. Maybe @orta has a clever idea on how to compile the Dangerfiles as ESM even if DangerJS is still CJS? |
Typically I would recommend using ts-node to execute an If we assume there are good reasons to avoid the above, then the next best thing I can think of is: write the compiled output to disk in the same directory as the dangerfile 1 and then
Footnotes
|
I'd assume there must be some new node APIs like |
Unfortunately node only allows getting into the ESM loading path via `--loader`
|
Actually that may not be entirely true. There are caveats and limitations but I think the |
Hello, guys! Do you have any news on this? I think it's no secret that
By the way, if the
Another reason why I think it's necessary to prioritize ESM modules is that DangerJS is often used with other linters, such as commitlint. It's common to want to describe, for example, the project prefix in one file to use it across two configurations. // project.config.js
const ProjectPrefix = {
APPS: [`wd`],
ENVIRONMENTS: [`production`, `development`],
} // commitlint.config.js
import { ProjectPrefix } from './project.config.js'
const configuration = {
extends: [`@commitlint/config-conventional`],
parserPreset: {
parserOpts: {
issuePrefixes: ProjectPrefix.APPS.map((it) => `${it}-`),
},
},
rules: {
'references-empty': [2, `never`],
},
} (The DangerJS part is currently not working.) // dangerfile.js
import { danger, fail } from 'danger'
import { ProjectPrefix } from './project.config.js'
const Config = {
BRANCH_PATTERN: new RegExp(
`^((${ProjectPrefix.APPS.join(`|`)})-[0-9]{1,6})-[a-zA-Z0-9-]+$|(${ProjectPrefix.ENVIRONMENTS.join(`|`)})$`,
),
}
const isTitleValid = Config.TITLE_PATTERN.test(danger.github.pr.title)
if (!isTitleValid) {
fail(
`Pull Request title should match the following pattern – ${Config.TITLE_PATTERN}.`,
)
} |
It would be great to have ESM support for danger-js. We are using https://github.com/semantic-release/semantic-release inside a dangerfile.js. semantic-release switched to ESM with version 20 (current one is 22). So we are stuck with an outdated version now. :( |
I agree this is important and valuable. I think this is going to take collaboration from the community. I did a light audit almost 2 years ago (above) and at least half of the problem issues I identified at the time are still open issues as of this writing (though they may have workarounds). Knowing what I know about the community using DangerJS, I’m not sure I would support an ESM-only build of DangerJS. I think that means that we need to expose CJS and ESM hooks and build the library to support either style of consumers. Somebody needs to make an attempt at getting DangerJS to treat the Dangerfiles as ESM, and that includes changing the Ideally, we wouldn’t have to make |
Wouldn't it solve most of the pains if for now dangerjs enables a way to import mjs from cjs? From my experience it's totally doable this way via dynamic import (so, This way danger can stay commonjs while surrounding tooling like semantic-release can be imported via ESM. |
Accidentally applied `es6` when compilerOptions.module was not defined.
…tion fix(node): #1180 - Adjust tsconfig compiler options
I got tripped up by a dependency that went "esm-only" today in their 7.x/latest version strip-ansi extra info from the maintainer.
Do we have a plan for ESM in DangerJS?
I'm not sure what this entails from DangerJS's perspective. I could write this off as an overly eager developer, but it smells like this is going to be an increasing question/stumbling block for people.
The text was updated successfully, but these errors were encountered: