Skip to content
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
22 changes: 19 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -205,29 +206,34 @@ const unplugin = createUnplugin<Options>((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;
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/scenarios/basic-upload/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/scenarios/basic-upload/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/scripts/run-scenario-setups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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" });
Expand All @@ -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!");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
Original file line number Diff line number Diff line change
@@ -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" });
Expand All @@ -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!");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
Loading