diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index af11100f..640ff864 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -48,12 +48,28 @@ jobs: test-integration: needs: build - name: Integration Tests - runs-on: ubuntu-latest + name: "Integration Tests (Node ${{ matrix.node-version }}, OS ${{ matrix.os }})" + strategy: + fail-fast: false + matrix: + node-version: [ + # nx uses a `yargs-parser` versision which isn't compatible with node 10 + # "10.24.1", + # vite uses optional chaining which isn't compatible with node 12 + # "12.22.12", + "14.21.1", + "16.18.1", + "18.12.1", + ] + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - uses: volta-cli/action@v3 - - run: yarn --frozen-lockfile + with: + node-version: ${{ matrix.node-version }} + # husky uses fs-extra which needs node >= 14 - we can ignore because its a dev dependency + - run: yarn --frozen-lockfile --ignore-engines - run: yarn test:integration test-e2e: diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index bbb87f47..7f28e9c5 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -22,6 +22,7 @@ import { createLogger, Logger } from "./sentry/logger"; import { InternalOptions, normalizeUserOptions, validateOptions } from "./options-mapping"; import { getSentryCli } from "./sentry/cli"; import { Hub, makeMain } from "@sentry/node"; +import path from "path"; // We prefix the polyfill id with \0 to tell other plugins not to try to load or transform it. // This hack is taken straight from https://rollupjs.org/guide/en/#resolveid. @@ -205,29 +206,34 @@ const unplugin = createUnplugin((options, unpluginMetaContext) => { transformInclude(id) { logger.debug('Called "transformInclude":', { id }); + // We normalize the id because vite always passes `id` as a unix style path which causes problems when a user passes + // a windows style path to `releaseInjectionTargets` + const normalizedId = path.normalize(id); + // We don't want to transform our injected code. - if (id === RELEASE_INJECTOR_ID) { + if (normalizedId === RELEASE_INJECTOR_ID) { return false; } if (internalOptions.releaseInjectionTargets) { // If there's an `releaseInjectionTargets` option transform (ie. inject the release varible) when the file path matches the option. if (typeof internalOptions.releaseInjectionTargets === "function") { - return internalOptions.releaseInjectionTargets(id); + return internalOptions.releaseInjectionTargets(normalizedId); } return internalOptions.releaseInjectionTargets.some((entry) => { if (entry instanceof RegExp) { - return entry.test(id); + return entry.test(normalizedId); } else { - return id === entry; + const normalizedEntry = path.normalize(entry); + return normalizedId === normalizedEntry; } }); } else { - const pathIsOrdinary = !id.includes("?") && !id.includes("#"); + const pathIsOrdinary = !normalizedId.includes("?") && !normalizedId.includes("#"); const pathHasAllowedFileEnding = ALLOWED_TRANSFORMATION_FILE_ENDINGS.some( - (allowedFileEnding) => id.endsWith(allowedFileEnding) + (allowedFileEnding) => normalizedId.endsWith(allowedFileEnding) ); return pathIsOrdinary && pathHasAllowedFileEnding; diff --git a/packages/e2e-tests/scenarios/basic-upload/config.ts b/packages/e2e-tests/scenarios/basic-upload/config.ts index b828c9a1..4544cb91 100644 --- a/packages/e2e-tests/scenarios/basic-upload/config.ts +++ b/packages/e2e-tests/scenarios/basic-upload/config.ts @@ -6,7 +6,7 @@ import * as path from "path"; */ export const pluginConfig: Options = { release: "basic-upload", - include: path.resolve(__dirname, "./out"), + include: path.resolve(__dirname, "out"), authToken: process.env["SENTRY_AUTH_TOKEN"] || "", org: "sentry-sdks", project: "js-bundler-plugin-e2e-tests", diff --git a/packages/e2e-tests/scenarios/basic-upload/setup.ts b/packages/e2e-tests/scenarios/basic-upload/setup.ts index 34cbb317..25a01f52 100644 --- a/packages/e2e-tests/scenarios/basic-upload/setup.ts +++ b/packages/e2e-tests/scenarios/basic-upload/setup.ts @@ -6,8 +6,8 @@ import { createCjsBundles } from "../../utils/create-cjs-bundles"; deleteAllReleases(pluginConfig.release || "") .then(() => { - const entryPointPath = path.resolve(__dirname, "./input/index.js"); - const outputDir = path.resolve(__dirname, "./out"); + const entryPointPath = path.resolve(__dirname, "input", "index.js"); + const outputDir = path.resolve(__dirname, "out"); createCjsBundles({ index: entryPointPath }, outputDir, pluginConfig); }) diff --git a/packages/e2e-tests/scripts/run-scenario-setups.ts b/packages/e2e-tests/scripts/run-scenario-setups.ts index 8bd7ff04..2d55a4b2 100644 --- a/packages/e2e-tests/scripts/run-scenario-setups.ts +++ b/packages/e2e-tests/scripts/run-scenario-setups.ts @@ -2,8 +2,8 @@ import fs from "fs"; import path from "path"; const scenarioPaths = fs - .readdirSync(path.join(__dirname, "../scenarios")) - .map((fixtureDir) => path.join(__dirname, "../scenarios", fixtureDir)); + .readdirSync(path.join(__dirname, "..", "scenarios")) + .map((fixtureDir) => path.join(__dirname, "..", "scenarios", fixtureDir)); scenarioPaths.forEach((fixturePath) => { require(path.join(fixturePath, "setup.ts")); diff --git a/packages/integration-tests/fixtures/array-entries-option/array-entries-option.test.ts b/packages/integration-tests/fixtures/array-entries-option/array-entries-option.test.ts index 09387344..eba6fde3 100644 --- a/packages/integration-tests/fixtures/array-entries-option/array-entries-option.test.ts +++ b/packages/integration-tests/fixtures/array-entries-option/array-entries-option.test.ts @@ -1,6 +1,7 @@ import childProcess from "child_process"; import path from "path"; import fs from "fs"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; function getBundleOutput(bundlePath: string): string { return childProcess.execSync(`node ${bundlePath}`, { encoding: "utf-8" }); @@ -12,67 +13,71 @@ function getFileContents(bundlePath: string): string { describe("`releaseInjectionTargets` option should work as expected when given an array of RegEx and strings", () => { test("esbuild bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("rollup bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/rollup/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("vite bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/vite/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "vite", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); - test("webpack 4 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint1.js"))).toBe( + testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint3.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getFileContents(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).not.toContain( + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint2.js"))).toBe(""); + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); + // eslint-disable-next-line jest/no-standalone-expect + expect( + getFileContents(path.join(__dirname, "out", "webpack4", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); test("webpack 5 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); + expect( + getFileContents(path.join(__dirname, "out", "webpack5", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); }); diff --git a/packages/integration-tests/fixtures/array-entries-option/setup.ts b/packages/integration-tests/fixtures/array-entries-option/setup.ts index a07cd847..1be984e4 100644 --- a/packages/integration-tests/fixtures/array-entries-option/setup.ts +++ b/packages/integration-tests/fixtures/array-entries-option/setup.ts @@ -2,10 +2,10 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPoint1Path = path.resolve(__dirname, "./input/entrypoint1.js"); -const entryPoint2Path = path.resolve(__dirname, "./input/entrypoint2.js"); -const entryPoint3Path = path.resolve(__dirname, "./input/entrypoint3.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPoint1Path = path.resolve(__dirname, "input", "entrypoint1.js"); +const entryPoint2Path = path.resolve(__dirname, "input", "entrypoint2.js"); +const entryPoint3Path = path.resolve(__dirname, "input", "entrypoint3.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles( { entrypoint1: entryPoint1Path, entrypoint2: entryPoint2Path, entrypoint3: entryPoint3Path }, diff --git a/packages/integration-tests/fixtures/basic-release-injection/basic-release-injection.test.ts b/packages/integration-tests/fixtures/basic-release-injection/basic-release-injection.test.ts index 7d889cec..db3bc356 100644 --- a/packages/integration-tests/fixtures/basic-release-injection/basic-release-injection.test.ts +++ b/packages/integration-tests/fixtures/basic-release-injection/basic-release-injection.test.ts @@ -1,5 +1,6 @@ import childProcess from "child_process"; import path from "path"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; /** * Runs a node file in a seprate process. @@ -27,7 +28,7 @@ test("vite bundle", () => { checkBundle(path.join(__dirname, "./out/vite/index.js")); }); -test("webpack 4 bundle", () => { +testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { expect.assertions(1); checkBundle(path.join(__dirname, "./out/webpack4/index.js")); }); diff --git a/packages/integration-tests/fixtures/basic-release-injection/setup.ts b/packages/integration-tests/fixtures/basic-release-injection/setup.ts index b9112296..5f0dc5fb 100644 --- a/packages/integration-tests/fixtures/basic-release-injection/setup.ts +++ b/packages/integration-tests/fixtures/basic-release-injection/setup.ts @@ -2,8 +2,8 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPointPath = path.resolve(__dirname, "./input/entrypoint.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPointPath = path.resolve(__dirname, "input", "entrypoint.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles({ index: entryPointPath }, outputDir, { release: "I AM A RELEASE!", diff --git a/packages/integration-tests/fixtures/function-entries-option/function-entries-option.test.ts b/packages/integration-tests/fixtures/function-entries-option/function-entries-option.test.ts index 11d2db88..28bdc4da 100644 --- a/packages/integration-tests/fixtures/function-entries-option/function-entries-option.test.ts +++ b/packages/integration-tests/fixtures/function-entries-option/function-entries-option.test.ts @@ -1,6 +1,7 @@ import childProcess from "child_process"; import path from "path"; import fs from "fs"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; function getBundleOutput(bundlePath: string): string { return childProcess.execSync(`node ${bundlePath}`, { encoding: "utf-8" }); @@ -12,67 +13,71 @@ function getFileContents(bundlePath: string): string { describe("`releaseInjectionTargets` option should work as expected when given a function", () => { test("esbuild bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("rollup bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/rollup/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("vite bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/vite/entrypoint2.js"))).not.toContain( + expect(getFileContents(path.join(__dirname, "out", "vite", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); - test("webpack 4 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint1.js"))).toBe( + testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint3.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getFileContents(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).not.toContain( + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint2.js"))).toBe(""); + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); + // eslint-disable-next-line jest/no-standalone-expect + expect( + getFileContents(path.join(__dirname, "out", "webpack4", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); test("webpack 5 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).toBe(""); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint3.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getFileContents(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint2.js"))).toBe(""); + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint3.js"))).toBe( "I AM A RELEASE!" ); + expect( + getFileContents(path.join(__dirname, "out", "webpack5", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); }); diff --git a/packages/integration-tests/fixtures/function-entries-option/setup.ts b/packages/integration-tests/fixtures/function-entries-option/setup.ts index 059b85c2..56c9dfb3 100644 --- a/packages/integration-tests/fixtures/function-entries-option/setup.ts +++ b/packages/integration-tests/fixtures/function-entries-option/setup.ts @@ -2,10 +2,10 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPoint1Path = path.resolve(__dirname, "./input/entrypoint1.js"); -const entryPoint2Path = path.resolve(__dirname, "./input/entrypoint2.js"); -const entryPoint3Path = path.resolve(__dirname, "./input/entrypoint3.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPoint1Path = path.resolve(__dirname, "input", "entrypoint1.js"); +const entryPoint2Path = path.resolve(__dirname, "input", "entrypoint2.js"); +const entryPoint3Path = path.resolve(__dirname, "input", "entrypoint3.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles( { entrypoint1: entryPoint1Path, entrypoint2: entryPoint2Path, entrypoint3: entryPoint3Path }, diff --git a/packages/integration-tests/fixtures/regex-entries-option/setup.ts b/packages/integration-tests/fixtures/regex-entries-option/setup.ts index a3e004e5..2ee0b77f 100644 --- a/packages/integration-tests/fixtures/regex-entries-option/setup.ts +++ b/packages/integration-tests/fixtures/regex-entries-option/setup.ts @@ -2,9 +2,9 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPoint1Path = path.resolve(__dirname, "./input/entrypoint1.js"); -const entryPoint2Path = path.resolve(__dirname, "./input/entrypoint2.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPoint1Path = path.resolve(__dirname, "input", "entrypoint1.js"); +const entryPoint2Path = path.resolve(__dirname, "input", "entrypoint2.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles({ entrypoint1: entryPoint1Path, entrypoint2: entryPoint2Path }, outputDir, { release: "I AM A RELEASE!", diff --git a/packages/integration-tests/fixtures/regex-entries-option/string-entries-option.test.ts b/packages/integration-tests/fixtures/regex-entries-option/string-entries-option.test.ts index b37e7f47..22f3efb7 100644 --- a/packages/integration-tests/fixtures/regex-entries-option/string-entries-option.test.ts +++ b/packages/integration-tests/fixtures/regex-entries-option/string-entries-option.test.ts @@ -1,6 +1,7 @@ import childProcess from "child_process"; import path from "path"; import fs from "fs"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; function getBundleOutput(bundlePath: string): string { return childProcess.execSync(`node ${bundlePath}`, { encoding: "utf-8" }); @@ -12,52 +13,55 @@ function getFileContents(bundlePath: string): string { describe("`releaseInjectionTargets` option should work as expected when given a regular expression", () => { test("esbuild bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("rollup bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/rollup/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("vite bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/vite/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "vite", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); - test("webpack 4 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).not.toContain( + testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint2.js"))).toBe(""); + // eslint-disable-next-line jest/no-standalone-expect + expect( + getFileContents(path.join(__dirname, "out", "webpack4", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); test("webpack 5 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint2.js"))).toBe(""); + expect( + getFileContents(path.join(__dirname, "out", "webpack5", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); }); diff --git a/packages/integration-tests/fixtures/releases-injection/releases-injection.test.ts b/packages/integration-tests/fixtures/releases-injection/releases-injection.test.ts index 7d889cec..5bb38d64 100644 --- a/packages/integration-tests/fixtures/releases-injection/releases-injection.test.ts +++ b/packages/integration-tests/fixtures/releases-injection/releases-injection.test.ts @@ -1,5 +1,6 @@ import childProcess from "child_process"; import path from "path"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; /** * Runs a node file in a seprate process. @@ -14,25 +15,25 @@ function checkBundle(bundlePath: string): void { test("esbuild bundle", () => { expect.assertions(1); - checkBundle(path.join(__dirname, "./out/esbuild/index.js")); + checkBundle(path.join(__dirname, "out", "esbuild", "index.js")); }); test("rollup bundle", () => { expect.assertions(1); - checkBundle(path.join(__dirname, "./out/rollup/index.js")); + checkBundle(path.join(__dirname, "out", "rollup", "index.js")); }); test("vite bundle", () => { expect.assertions(1); - checkBundle(path.join(__dirname, "./out/vite/index.js")); + checkBundle(path.join(__dirname, "out", "vite", "index.js")); }); -test("webpack 4 bundle", () => { +testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { expect.assertions(1); - checkBundle(path.join(__dirname, "./out/webpack4/index.js")); + checkBundle(path.join(__dirname, "out", "webpack4", "index.js")); }); test("webpack 5 bundle", () => { expect.assertions(1); - checkBundle(path.join(__dirname, "./out/webpack5/index.js")); + checkBundle(path.join(__dirname, "out", "webpack5", "index.js")); }); diff --git a/packages/integration-tests/fixtures/releases-injection/setup.ts b/packages/integration-tests/fixtures/releases-injection/setup.ts index 8807e676..cc875088 100644 --- a/packages/integration-tests/fixtures/releases-injection/setup.ts +++ b/packages/integration-tests/fixtures/releases-injection/setup.ts @@ -2,8 +2,8 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPointPath = path.resolve(__dirname, "./input/entrypoint.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPointPath = path.resolve(__dirname, "input", "entrypoint.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles({ index: entryPointPath }, outputDir, { release: "I AM A RELEASE!", diff --git a/packages/integration-tests/fixtures/string-entries-option/setup.ts b/packages/integration-tests/fixtures/string-entries-option/setup.ts index 7b07fb66..9601b7a5 100644 --- a/packages/integration-tests/fixtures/string-entries-option/setup.ts +++ b/packages/integration-tests/fixtures/string-entries-option/setup.ts @@ -2,9 +2,9 @@ import { Options } from "@sentry/bundler-plugin-core"; import * as path from "path"; import { createCjsBundles } from "../../utils/create-cjs-bundles"; -const entryPoint1Path = path.resolve(__dirname, "./input/entrypoint1.js"); -const entryPoint2Path = path.resolve(__dirname, "./input/entrypoint2.js"); -const outputDir = path.resolve(__dirname, "./out"); +const entryPoint1Path = path.resolve(__dirname, "input", "entrypoint1.js"); +const entryPoint2Path = path.resolve(__dirname, "input", "entrypoint2.js"); +const outputDir = path.resolve(__dirname, "out"); createCjsBundles({ entrypoint1: entryPoint1Path, entrypoint2: entryPoint2Path }, outputDir, { release: "I AM A RELEASE!", diff --git a/packages/integration-tests/fixtures/string-entries-option/string-entries-option.test.ts b/packages/integration-tests/fixtures/string-entries-option/string-entries-option.test.ts index caf0f9e1..33f29bb7 100644 --- a/packages/integration-tests/fixtures/string-entries-option/string-entries-option.test.ts +++ b/packages/integration-tests/fixtures/string-entries-option/string-entries-option.test.ts @@ -1,6 +1,7 @@ import childProcess from "child_process"; import path from "path"; import fs from "fs"; +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; function getBundleOutput(bundlePath: string): string { return childProcess.execSync(`node ${bundlePath}`, { encoding: "utf-8" }); @@ -12,52 +13,55 @@ function getFileContents(bundlePath: string): string { describe("`releaseInjectionTargets` option should work as expected when given a string", () => { test("esbuild bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/esbuild/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "esbuild", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("rollup bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/rollup/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/rollup/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "rollup", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); test("vite bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint1.js"))).toBe( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); - expect(getBundleOutput(path.join(__dirname, "./out/vite/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/vite/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "vite", "entrypoint2.js"))).toBe(""); + expect(getFileContents(path.join(__dirname, "out", "vite", "entrypoint2.js"))).not.toContain( "I AM A RELEASE!" ); }); - test("webpack 4 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/webpack4/entrypoint2.js"))).not.toContain( + testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); + // eslint-disable-next-line jest/no-standalone-expect + expect(getBundleOutput(path.join(__dirname, "out", "webpack4", "entrypoint2.js"))).toBe(""); + // eslint-disable-next-line jest/no-standalone-expect + expect( + getFileContents(path.join(__dirname, "out", "webpack4", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); test("webpack 5 bundle", () => { - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint1.js"))).toBe( - "I AM A RELEASE!" - ); - expect(getBundleOutput(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).toBe(""); - expect(getFileContents(path.join(__dirname, "./out/webpack5/entrypoint2.js"))).not.toContain( + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint1.js"))).toBe( "I AM A RELEASE!" ); + expect(getBundleOutput(path.join(__dirname, "out", "webpack5", "entrypoint2.js"))).toBe(""); + expect( + getFileContents(path.join(__dirname, "out", "webpack5", "entrypoint2.js")) + ).not.toContain("I AM A RELEASE!"); }); }); diff --git a/packages/integration-tests/scripts/run-fixture-setups.ts b/packages/integration-tests/scripts/run-fixture-setups.ts index 7ee1409f..0020b376 100644 --- a/packages/integration-tests/scripts/run-fixture-setups.ts +++ b/packages/integration-tests/scripts/run-fixture-setups.ts @@ -2,8 +2,8 @@ import fs from "fs"; import path from "path"; const fixturePaths = fs - .readdirSync(path.join(__dirname, "../fixtures")) - .map((fixtureDir) => path.join(__dirname, "../fixtures", fixtureDir)); + .readdirSync(path.join(__dirname, "..", "fixtures")) + .map((fixtureDir) => path.join(__dirname, "..", "fixtures", fixtureDir)); fixturePaths.forEach((fixturePath) => { require(path.join(fixturePath, "setup.ts")); diff --git a/packages/integration-tests/utils/create-cjs-bundles.ts b/packages/integration-tests/utils/create-cjs-bundles.ts index b8886064..16efaeaa 100644 --- a/packages/integration-tests/utils/create-cjs-bundles.ts +++ b/packages/integration-tests/utils/create-cjs-bundles.ts @@ -12,6 +12,8 @@ import { Options, } from "@sentry/bundler-plugin-core"; +const nodejsMajorversion = process.version.split(".")[0]; + export function createCjsBundles( entrypoints: { [name: string]: string }, outFolder: string, @@ -54,24 +56,27 @@ export function createCjsBundles( format: "cjs", }); - webpack4( - { - mode: "production", - entry: entrypoints, - cache: false, - output: { - path: path.join(outFolder, "webpack4"), - libraryTarget: "commonjs", + // Webpack 4 doesn't work on Node.js versions >= 18 + if (!nodejsMajorversion || parseInt(nodejsMajorversion) < 18) { + webpack4( + { + mode: "production", + entry: entrypoints, + cache: false, + output: { + path: path.join(outFolder, "webpack4"), + libraryTarget: "commonjs", + }, + target: "node", // needed for webpack 4 so we can access node api + plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], }, - target: "node", // needed for webpack 4 so we can access node api - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], - }, - (err) => { - if (err) { - throw err; + (err) => { + if (err) { + throw err; + } } - } - ); + ); + } webpack5( { diff --git a/packages/integration-tests/utils/testIf.ts b/packages/integration-tests/utils/testIf.ts new file mode 100644 index 00000000..ef64737c --- /dev/null +++ b/packages/integration-tests/utils/testIf.ts @@ -0,0 +1,21 @@ +// eslint-disable-next-line no-undef +export function testIf(condition: boolean): jest.It { + if (condition) { + // eslint-disable-next-line no-undef + return test; + } else { + // eslint-disable-next-line no-undef + return test.skip; + } +} + +/** + * Webpack 4 doesn't work for Node.js versions >= 18. + * We can use this function to skip tests on Webpack 4. + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-undef, @typescript-eslint/no-unsafe-assignment +export const testIfNodeMajorVersionIsLessThan18: jest.It = function () { + const nodejsMajorversion = process.version.split(".")[0]; + return testIf(!nodejsMajorversion || parseInt(nodejsMajorversion) < 18); + // eslint-disable-next-line @typescript-eslint/no-explicit-any +} as any; diff --git a/packages/playground/build-webpack4.js b/packages/playground/build-webpack4.js index 8cd29aff..e87386d8 100644 --- a/packages/playground/build-webpack4.js +++ b/packages/playground/build-webpack4.js @@ -11,7 +11,7 @@ webpack4( entry: "./src/entrypoint1.js", cache: false, output: { - path: path.resolve(__dirname, `./out/webpack4`), + path: path.resolve(__dirname, "out", "webpack4"), filename: "index.js", library: "ExampleBundle", libraryTarget: "commonjs", diff --git a/packages/playground/build-webpack5.js b/packages/playground/build-webpack5.js index 812dd5df..9aed0320 100644 --- a/packages/playground/build-webpack5.js +++ b/packages/playground/build-webpack5.js @@ -11,7 +11,7 @@ webpack5( entry: "./src/entrypoint1.js", output: { filename: "index.js", - path: path.resolve(__dirname, `./out/webpack5`), + path: path.resolve(__dirname, "out", "webpack5"), library: { type: "commonjs", name: "ExampleBundle", diff --git a/packages/playground/scripts/request-logger-proxy.ts b/packages/playground/scripts/request-logger-proxy.ts index bf078e55..e62a1f71 100644 --- a/packages/playground/scripts/request-logger-proxy.ts +++ b/packages/playground/scripts/request-logger-proxy.ts @@ -47,7 +47,7 @@ app.use(function (req, res, next) { )}\nResponse body:\n${Buffer.concat(resBody).toString()}`; fs.appendFileSync( - path.join(__dirname, `request-logger-logs/${now}.txt`), + path.join(__dirname, "request-logger-logs", `${now}.txt`), `>>>>>>>>>\n\n${reqLog}\n\n-----------\n\n${resLog}\n\n<<<<<<<<<\n\n`, { encoding: "utf-8", diff --git a/packages/playground/vite.config.js b/packages/playground/vite.config.js index a625bae9..2254398e 100644 --- a/packages/playground/vite.config.js +++ b/packages/playground/vite.config.js @@ -8,7 +8,7 @@ export default defineConfig({ build: { outDir: "./out/vite", lib: { - entry: path.resolve(__dirname, "./src/entrypoint1.js"), + entry: path.resolve(__dirname, "src", "entrypoint1.js"), name: "ExampleBundle", fileName: "index", formats: ["cjs"], diff --git a/packages/playground/vite.config.smallNodeApp.js b/packages/playground/vite.config.smallNodeApp.js index b9566f49..1b86efcd 100644 --- a/packages/playground/vite.config.smallNodeApp.js +++ b/packages/playground/vite.config.smallNodeApp.js @@ -7,7 +7,7 @@ export default defineConfig({ build: { outDir: "./out/vite-smallNodeApp", lib: { - entry: path.resolve(__dirname, "./src/smallNodeApp.js"), + entry: path.resolve(__dirname, "src", "smallNodeApp.js"), name: "ExampleBundle", fileName: "index", formats: ["cjs"],