Skip to content

Commit

Permalink
Remove @cypress/browserify-preprocessor as a peerDep
Browse files Browse the repository at this point in the history
The user will have to do themselves what the exported `preprocessor`
function used to do.
  • Loading branch information
badeball committed Sep 19, 2024
1 parent b6b6f0a commit b34a609
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 44 deletions.
8 changes: 6 additions & 2 deletions examples/browserify-cjs/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const { defineConfig } = require("cypress");
const browserify = require("@cypress/browserify-preprocessor");
const {
addCucumberPreprocessorPlugin,
} = require("@badeball/cypress-cucumber-preprocessor");
const {
preprocessor,
preprendTransformerToOptions,
} = require("@badeball/cypress-cucumber-preprocessor/browserify");

async function setupNodeEvents(on, config) {
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await addCucumberPreprocessorPlugin(on, config);

on("file:preprocessor", preprocessor(config));
on(
"file:preprocessor",
browserify(preprendTransformerToOptions(config, browserify.defaultOptions)),
);

// Make sure to return the config object as it might have been modified by the plugin.
return config;
Expand Down
8 changes: 6 additions & 2 deletions examples/browserify-esm/cypress.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { defineConfig } from "cypress";
import browserify from "@cypress/browserify-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import { preprocessor } from "@badeball/cypress-cucumber-preprocessor/browserify";
import { preprendTransformerToOptions } from "@badeball/cypress-cucumber-preprocessor/browserify";

export async function setupNodeEvents(on, config) {
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await addCucumberPreprocessorPlugin(on, config);

on("file:preprocessor", preprocessor(config));
on(
"file:preprocessor",
browserify(preprendTransformerToOptions(config, browserify.defaultOptions)),
);

// Make sure to return the config object as it might have been modified by the plugin.
return config;
Expand Down
6 changes: 4 additions & 2 deletions examples/browserify-ts/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from "cypress";
import browserify from "@cypress/browserify-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import { preprocessor } from "@badeball/cypress-cucumber-preprocessor/browserify";
import { preprendTransformerToOptions } from "@badeball/cypress-cucumber-preprocessor/browserify";

async function setupNodeEvents(
on: Cypress.PluginEvents,
Expand All @@ -11,7 +12,8 @@ async function setupNodeEvents(

on(
"file:preprocessor",
preprocessor(config, {
browserify({
...preprendTransformerToOptions(config, browserify.defaultOptions),
typescript: require.resolve("typescript"),
}),
);
Expand Down
35 changes: 3 additions & 32 deletions lib/subpath-entrypoints/browserify.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { PassThrough, Transform, TransformCallback } from "stream";

import { EventEmitter } from "events";

import browserify from "@cypress/browserify-preprocessor";

import { ICypressConfiguration } from "@badeball/cypress-configuration";

import debug from "../helpers/debug";

import { compile } from "../template";

export function transform(
export default function transform(
configuration: ICypressConfiguration,
filepath: string,
) {
Expand Down Expand Up @@ -42,14 +38,9 @@ export function transform(
});
}

// https://docs.cypress.io/api/plugins/preprocessors-api.html#File-object
type ICypressPreprocessorFile = EventEmitter & {
filePath: string;
outputPath: string;
shouldWatch: boolean;
};
export { transform };

function preprendTransformerToOptions(
export function preprendTransformerToOptions(
configuration: ICypressConfiguration,
options: any,
) {
Expand All @@ -75,23 +66,3 @@ function preprendTransformerToOptions(
},
};
}

export function preprocessor(
configuration: ICypressConfiguration,
options = browserify.defaultOptions,
{ prependTransform = true }: { prependTransform?: boolean } = {},
) {
if (prependTransform) {
options = preprendTransformerToOptions(configuration, options);
}

return function (file: ICypressPreprocessorFile) {
return browserify(options)(file);
};
}

export { ICypressConfiguration };

export { compile };

export default preprocessor;
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@
"webpack": "^5.93.0"
},
"peerDependencies": {
"@cypress/browserify-preprocessor": "^3.0.1",
"cypress": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0"
},
"peerDependenciesMeta": {
"@cypress/browserify-preprocessor": {
"optional": true
}
},
"engines": {
"node": ">=18.0.0"
}
Expand Down

0 comments on commit b34a609

Please sign in to comment.