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

changelog Formatter in typescript don't work as expected #1323

Open
fauxbytes opened this issue Mar 12, 2024 · 0 comments
Open

changelog Formatter in typescript don't work as expected #1323

fauxbytes opened this issue Mar 12, 2024 · 0 comments

Comments

@fauxbytes
Copy link

Following this doc, I attempted to implement a changeset formatter:

config,json:

{
  "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
  "changelog": "./changelog-formatter.ts",
  "commit": false,
  "access": "restricted",
  "baseBranch": "master"
}

changelog-formatter.ts:

import orig from "@changesets/changelog-git";
import { ChangelogFunctions, NewChangesetWithCommit, VersionType } from "@changesets/types";

/**
 * override default formatting: mostly same as default, but with getReleaseLine() excluding commit SHAs 
 */
const defaultChangelogFunctions: ChangelogFunctions = {
    getReleaseLine: async (changeset: NewChangesetWithCommit, _type: VersionType) => {
        const [firstLine, ...futureLines] = changeset.summary.split("\n").map((l) => l.trimEnd());
        return `- ${firstLine}` + (futureLines.length > 0 ? `\n${futureLines.map((l) => `  ${l}`).join("\n")}` : "");
    },
    getDependencyReleaseLine: async (...args) => orig.getDependencyReleaseLine(...args),
};

export default defaultChangelogFunctions;
$ npx changeset version
🦋  error #####\.changeset\changelog-formatter.ts:1
🦋  error import orig from "@changesets/changelog-git";
🦋  error ^^^^^^
🦋  error
🦋  error SyntaxError: Cannot use import statement outside a module
🦋  error     at internalCompileFunction (node:internal/vm:73:18)
🦋  error     at wrapSafe (node:internal/modules/cjs/loader:1176:20)
🦋  error     at Module._compile (node:internal/modules/cjs/loader:1218:27)
🦋  error     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
🦋  error     at Module.load (node:internal/modules/cjs/loader:1117:32)
🦋  error     at Module._load (node:internal/modules/cjs/loader:958:12)
🦋  error     at Module.require (node:internal/modules/cjs/loader:1141:19)
🦋  error     at require (node:internal/modules/cjs/helpers:110:18)
🦋  error     at getNewChangelogEntry (#####\node_modules\@changesets\apply-release-plan\dist\changesets-apply-release-plan.cjs.js:372:31)
🦋  error     at Object.applyReleasePlan [as default] (#####\node_modules\@changesets\apply-release-plan\dist\changesets-apply-release-plan.cjs.js:280:37)

Possibly, there's more required to put together an working typescript formatter? A working sample would go a long way.
Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant