diff --git a/packages/artifact/package.json b/packages/artifact/package.json index 80e91ac1..44180270 100644 --- a/packages/artifact/package.json +++ b/packages/artifact/package.json @@ -39,7 +39,7 @@ "audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json", "test": "cd ../../ && npm run test ./packages/artifact", "bootstrap": "cd ../../ && npm run bootstrap", - "tsc-run": "tsc", + "tsc-run": "tsc && cp src/internal/shared/package-version.cjs lib/internal/shared/", "tsc": "npm run bootstrap && npm run tsc-run", "gen:docs": "typedoc --plugin typedoc-plugin-markdown --out docs/generated src/artifact.ts --githubPages false --readme none" }, diff --git a/packages/artifact/src/internal/shared/package-version.cjs b/packages/artifact/src/internal/shared/package-version.cjs new file mode 100644 index 00000000..bd43fc1b --- /dev/null +++ b/packages/artifact/src/internal/shared/package-version.cjs @@ -0,0 +1,7 @@ +// This file exists as a CommonJS module to read the version from package.json. +// In an ESM package, using `require()` directly in .ts files requires disabling +// ESLint rules and doesn't work reliably across all Node.js versions. +// By keeping this as a .cjs file, we can use require() naturally and export +// the version for the ESM modules to import. +const packageJson = require('../../../package.json') +module.exports = { version: packageJson.version } diff --git a/packages/artifact/src/internal/shared/user-agent.ts b/packages/artifact/src/internal/shared/user-agent.ts index 94c07e89..e4815d43 100644 --- a/packages/artifact/src/internal/shared/user-agent.ts +++ b/packages/artifact/src/internal/shared/user-agent.ts @@ -1,9 +1,8 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -const packageJson = require('../../../package.json') +import {version} from './package-version.cjs' /** * Ensure that this User Agent String is used in all HTTP calls so that we can monitor telemetry between different versions of this package */ export function getUserAgentString(): string { - return `@actions/artifact-${packageJson.version}` + return `@actions/artifact-${version}` }