@cypress/vite-dev-server
Advanced tools
Comparing version 3.4.0 to 4.0.0
@@ -6,3 +6,2 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const pathe_1 = require("pathe"); | ||
const node_html_parser_1 = require("node-html-parser"); | ||
@@ -12,3 +11,3 @@ const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const debug = (0, debug_1.default)('cypress:vite-dev-server:plugins:cypress'); | ||
const INIT_FILEPATH = (0, pathe_1.resolve)(__dirname, '../../client/initCypressTests.js'); | ||
const INIT_FILEPATH = path_1.default.resolve(__dirname, '../../client/initCypressTests.js'); | ||
const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50; | ||
@@ -49,3 +48,3 @@ function getSpecsPathsSet(specs) { | ||
}); | ||
const indexHtmlPath = (0, pathe_1.resolve)(projectRoot, indexHtmlFile); | ||
const indexHtmlPath = path_1.default.resolve(projectRoot, indexHtmlFile); | ||
debug('resolved the indexHtmlPath as', indexHtmlPath, 'from', indexHtmlFile); | ||
@@ -81,3 +80,3 @@ let indexHtmlContent = await fs_1.default.promises.readFile(indexHtmlPath, { encoding: 'utf8' }); | ||
// If the user provided IndexHtml is changed, do a full-reload | ||
if (vite.normalizePath(file) === (0, pathe_1.resolve)(projectRoot, indexHtmlFile)) { | ||
if (vite.normalizePath(file) === path_1.default.resolve(projectRoot, indexHtmlFile)) { | ||
server.ws.send({ | ||
@@ -84,0 +83,0 @@ type: 'full-reload', |
@@ -1,3 +0,2 @@ | ||
export * from './inspect'; | ||
export * from './cypress'; | ||
export * from './sourcemap'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./inspect"), exports); | ||
tslib_1.__exportStar(require("./cypress"), exports); | ||
tslib_1.__exportStar(require("./sourcemap"), exports); |
@@ -11,41 +11,53 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const local_pkg_1 = require("local-pkg"); | ||
const pathe_1 = require("pathe"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const constants_1 = require("./constants"); | ||
const index_1 = require("./plugins/index"); | ||
const dynamic_import_1 = require("./dynamic-import"); | ||
const debug = (0, debug_1.default)('cypress:vite-dev-server:resolve-config'); | ||
const createViteDevServerConfig = async (config, vite) => { | ||
const { specs, cypressConfig, viteConfig: viteOverrides } = config; | ||
const root = cypressConfig.projectRoot; | ||
const { default: findUp } = await (0, local_pkg_1.importModule)('find-up'); | ||
const configFile = await findUp(constants_1.configFiles, { cwd: root }); | ||
// INFO logging, a lot is logged here. | ||
// debug('all dev-server options are', options) | ||
if (configFile) { | ||
debug('resolved config file at', configFile, 'using root', root); | ||
const { viteConfig: inlineViteConfig, cypressConfig: { projectRoot } } = config; | ||
let resolvedOverrides = {}; | ||
if (inlineViteConfig) { | ||
debug(`Received a custom viteConfig`, inlineViteConfig); | ||
if (typeof inlineViteConfig === 'function') { | ||
resolvedOverrides = await inlineViteConfig(); | ||
} | ||
else if (typeof inlineViteConfig === 'object') { | ||
resolvedOverrides = inlineViteConfig; | ||
} | ||
// Set "configFile: false" to disable auto resolution of <project-root>/vite.config.js | ||
resolvedOverrides = Object.assign({ configFile: false }, resolvedOverrides); | ||
} | ||
else if (viteOverrides) { | ||
debug(`Couldn't find a Vite config file, however we received a custom viteConfig`, viteOverrides); | ||
} | ||
else { | ||
if (config.onConfigNotFound) { | ||
config.onConfigNotFound('vite', root, constants_1.configFiles); | ||
// The config process will be killed from the parent, but we want to early exit so we don't get | ||
// any additional errors related to not having a config | ||
process.exit(0); | ||
const { findUp } = await (0, dynamic_import_1.dynamicImport)('find-up'); | ||
const configFile = await findUp(constants_1.configFiles, { cwd: projectRoot }); | ||
if (!configFile) { | ||
if (config.onConfigNotFound) { | ||
config.onConfigNotFound('vite', projectRoot, constants_1.configFiles); | ||
// The config process will be killed from the parent, but we want to early exit so we don't get | ||
// any additional errors related to not having a config | ||
process.exit(0); | ||
} | ||
else { | ||
throw new Error(`Your component devServer config for vite is missing a required viteConfig property, since we could not automatically detect one.\n Please add one to your ${config.cypressConfig.configFile}`); | ||
} | ||
} | ||
else { | ||
throw new Error(`Your component devServer config for vite is missing a required viteConfig property, since we could not automatically detect one.\n Please add one to your ${config.cypressConfig.configFile}`); | ||
} | ||
debug('Resolved config file at', configFile, 'using root', projectRoot); | ||
resolvedOverrides = { configFile }; | ||
} | ||
const finalConfig = vite.mergeConfig(resolvedOverrides, makeCypressViteConfig(config, vite)); | ||
debug('The resolved server config is', JSON.stringify(finalConfig, null, 2)); | ||
return finalConfig; | ||
}; | ||
exports.createViteDevServerConfig = createViteDevServerConfig; | ||
function makeCypressViteConfig(config, vite) { | ||
const { cypressConfig: { projectRoot, devServerPublicPathRoute, supportFile, cypressBinaryRoot, isTextTerminal, }, specs, } = config; | ||
// Vite caches its output in the .vite directory in the node_modules where vite lives. | ||
// So we want to find that node_modules path and ensure it's added to the "allow" list | ||
const vitePathNodeModules = path_1.default.dirname(path_1.default.dirname(require.resolve(`vite/package.json`, { | ||
paths: [root], | ||
paths: [projectRoot], | ||
}))); | ||
const viteBaseConfig = { | ||
root, | ||
base: `${cypressConfig.devServerPublicPathRoute}/`, | ||
configFile, | ||
return { | ||
root: projectRoot, | ||
base: `${devServerPublicPathRoute}/`, | ||
optimizeDeps: { | ||
@@ -71,40 +83,20 @@ esbuildOptions: { | ||
entries: [ | ||
...specs.map((s) => (0, pathe_1.relative)(root, s.relative)), | ||
...(cypressConfig.supportFile ? [(0, pathe_1.resolve)(root, cypressConfig.supportFile)] : []), | ||
...specs.map((s) => path_1.default.relative(projectRoot, s.relative)), | ||
...(supportFile ? [path_1.default.resolve(projectRoot, supportFile)] : []), | ||
].filter((v) => v != null), | ||
}, | ||
server: { | ||
fs: { | ||
server: Object.assign({ fs: { | ||
allow: [ | ||
root, | ||
projectRoot, | ||
vitePathNodeModules, | ||
cypressConfig.cypressBinaryRoot, | ||
cypressBinaryRoot, | ||
], | ||
}, | ||
host: '127.0.0.1', | ||
}, | ||
}, host: '127.0.0.1' }, (isTextTerminal | ||
? { watch: { ignored: '**/*' }, hmr: false } | ||
: {})), | ||
plugins: [ | ||
(0, index_1.Cypress)(config, vite), | ||
(0, index_1.CypressInspect)(config), | ||
(0, index_1.CypressSourcemap)(config, vite), | ||
].filter((p) => p != null), | ||
], | ||
}; | ||
if (config.cypressConfig.isTextTerminal) { | ||
viteBaseConfig.server = Object.assign(Object.assign({}, (viteBaseConfig.server || {})), { | ||
// Disable file watching and HMR when executing tests in `run` mode | ||
watch: { | ||
ignored: '**/*', | ||
}, hmr: false }); | ||
} | ||
let resolvedOverrides = {}; | ||
if (typeof viteOverrides === 'function') { | ||
resolvedOverrides = await viteOverrides(); | ||
} | ||
else if (typeof viteOverrides === 'object') { | ||
resolvedOverrides = viteOverrides; | ||
} | ||
const finalConfig = vite.mergeConfig(viteBaseConfig, resolvedOverrides); | ||
debug('The resolved server config is', JSON.stringify(finalConfig, null, 2)); | ||
return finalConfig; | ||
}; | ||
exports.createViteDevServerConfig = createViteDevServerConfig; | ||
} |
{ | ||
"name": "@cypress/vite-dev-server", | ||
"version": "3.4.0", | ||
"version": "4.0.0", | ||
"description": "Launches Vite Dev Server for Component Testing", | ||
@@ -20,5 +20,3 @@ "main": "index.js", | ||
"find-up": "6.3.0", | ||
"local-pkg": "0.4.1", | ||
"node-html-parser": "5.3.3", | ||
"pathe": "0.2.0" | ||
"node-html-parser": "5.3.3" | ||
}, | ||
@@ -25,0 +23,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3
4
27335
479
- Removedlocal-pkg@0.4.1
- Removedpathe@0.2.0
- Removedlocal-pkg@0.4.1(transitive)
- Removedpathe@0.2.0(transitive)