diff --git a/.dependency-cruiser-known-violations.json b/.dependency-cruiser-known-violations.json new file mode 100644 index 000000000000..a968a6d6454a --- /dev/null +++ b/.dependency-cruiser-known-violations.json @@ -0,0 +1,11 @@ +[ + { + "type": "module", + "from": "packages/mocker/dist/auto-register.d.ts", + "to": "packages/mocker/dist/auto-register.d.ts", + "rule": { + "severity": "warn", + "name": "no-orphans-in-dist" + } + } +] diff --git a/.dependency-cruiser.cjs b/.dependency-cruiser.cjs new file mode 100644 index 000000000000..e3643b382a44 --- /dev/null +++ b/.dependency-cruiser.cjs @@ -0,0 +1,339 @@ +const { globSync, readFileSync } = require('node:fs') +const path = require('node:path') + +const toPosixPath = path.sep === '/' ? x => x : x => x.replaceAll(path.sep, '/') +const escapeRegex = value => value.replace(/[|/\\{}()[\]^$+?.*]/g, '\\$&') +const valuesRec = value => typeof value === 'string' ? [value] : Object.values(value ?? {}).flatMap(valuesRec) + +function expandPackageEntry(packageRoot, entry) { + if (/\/\.\.?(?:$|\/)/.test(entry)) { + throw new Error(`Invalid entry "${entry}" in package "${packageRoot}". Entries must not contain "." or ".." segments.`) + } + return `^${escapeRegex(path.posix.join(packageRoot, entry)).replace('\\*', '.*')}$` +} + +function expandFacadeDeclarationEntry(packageRoot, entry) { + if (!entry.endsWith('.d.ts')) { + return [] + } + + const facadePath = path.join(__dirname, packageRoot, entry) + const facadeSource = readFileSync(facadePath, 'utf8') + return Array.from(new Set( + facadeSource.matchAll(/from ['"](\.\/dist\/[^'"]+)\.js['"]/g) + .map(([, target]) => expandPackageEntry(packageRoot, `${target}.d.ts`)), + )) +} + +const publicFiles = globSync('packages/*/package.json', { cwd: __dirname }).flatMap((packageJsonPath) => { + const packageRoot = toPosixPath(path.dirname(packageJsonPath)) + const packageJson = require(path.join(__dirname, packageJsonPath)) + return Array.from(new Set(valuesRec(packageJson.exports))).flatMap(target => [ + expandPackageEntry(packageRoot, target), + ...expandFacadeDeclarationEntry(packageRoot, target), + ]) +}) + +const orphanPathIgnorePatterns = Array.from(new Set([ + ...publicFiles, + expandPackageEntry('packages/ui', 'dist/client/assets/*'), + expandPackageEntry('packages/browser', 'dist/client/__vitest__/assets/*'), +])).sort() + +const distPaths = ['^packages/[^/]+/dist/.*[.](?:js|d[.]ts)$'] + +/** @type {import('dependency-cruiser').IConfiguration} */ +module.exports = { + forbidden: [ + { + name: 'no-unresolved-in-dist', + comment: + 'This module in dist depends on a module that can\'t be resolved. Either fix the dependency or - if it\'s a ' + + 'false positive - add an exception for it in your dependency-cruiser configuration.', + severity: 'error', + from: { path: distPaths }, + to: { + couldNotResolve: true, + }, + }, + { + name: 'no-npm-dev-or-unknown-in-dist', + comment: + 'This module in dist depends on a module that is either an npm devDependency or an npm dependency that\'s not in the package.json.\n' + + 'Either add the dependency to your package.json or - if it\'s a false positive - add an exception for it in your dependency-cruiser configuration.', + severity: 'error', + from: { path: distPaths }, + to: { + couldNotResolve: false, + ancestor: false, + dependencyTypesNot: [ + 'core', + 'local', + 'localmodule', + 'deprecated', + 'npm', + 'npm-optional', + 'npm-peer', + 'undetermined', + ], + }, + }, + { + name: 'no-sharp-import-in-dist', + comment: + 'This module in dist depends on an internal module defined in imports field of a package.json. These are meant for use by the package itself and not for external consumption. Either change the dependency to point to a module that\'s meant for external consumption or - if it\'s a false positive - add an exception for it in your dependency-cruiser configuration.', + severity: 'error', + from: { path: distPaths }, + to: { + couldNotResolve: false, + path: ['^#'], + }, + }, + { + name: 'no-ancestor-npm-in-dist', + comment: + 'This module in dist depends on a module that is either an npm devDependency or an npm dependency that\'s not in the package.json.\n' + + 'Either add the dependency to your package.json or - if it\'s a false positive - add an exception for it in your dependency-cruiser configuration.', + severity: 'error', + from: { path: distPaths }, + to: { + couldNotResolve: false, + ancestor: true, + dependencyTypesNot: [ + 'local', + 'localmodule', + 'aliased', + ], + }, + }, + { + name: 'no-circular-in-dist', + severity: 'error', + comment: + 'This dependency in dist is part of a circular relationship. You might want to revise ' + + 'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ', + from: { path: distPaths }, + to: { + circular: true, + viaOnly: { + dependencyTypesNot: ['type-only', 'dynamic-import'], + }, + }, + }, + { + name: 'no-orphans-in-dist', + comment: + 'This is an orphan module - it\'s likely not used (anymore?). Either use it or ' + + 'remove it. If it\'s logical this module is an orphan (i.e. it\'s a config file), ' + + 'add an exception for it in your dependency-cruiser configuration.', + severity: 'warn', + from: { + orphan: true, + path: distPaths, + pathNot: [ + ...orphanPathIgnorePatterns, + '^packages/browser/dist/state[.]js$', // packages/browser/src/node/projectParent.ts + '^packages/browser/dist/client/esm-client-injector[.]js$', // packages/browser/src/node/projectParent.ts + ], + }, + to: {}, + }, + { + name: 'not-to-deprecated-in-dist', + comment: + 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' + + 'version of that module, or find an alternative. Deprecated modules are a security risk.', + severity: 'warn', + from: { path: distPaths }, + to: { + dependencyTypes: [ + 'deprecated', + ], + }, + }, + { + name: 'no-undetermined-in-dist', + comment: + 'This module has an undetermined dependency. Check your configuration or the module itself.', + severity: 'warn', + from: { path: distPaths }, + to: { + dependencyTypes: [ + 'undetermined', + ], + }, + + }, + ], + options: { + // Which modules not to follow further when encountered + doNotFollow: { + // path: an array of regular expressions in strings to match against + path: ['node_modules'], + }, + + // Which modules to exclude + // exclude : { + // // path: an array of regular expressions in strings to match against + // path: '', + // }, + + // Which modules to exclusively include (array of regular expressions in strings) + // dependency-cruiser will skip everything that doesn't match this pattern + // includeOnly : [''], + + // List of module systems to cruise. + // When left out dependency-cruiser will fall back to the list of _all_ + // module systems it knows of ('amd', 'cjs', 'es6', 'tsd']). It's the + // default because it's the safe option. It comes at a performance penalty, though + // As in practice only commonjs ('cjs') and ecmascript modules ('es6') + // are in wide use, you can limit the moduleSystems to those. + moduleSystems: ['cjs', 'es6'], + + // false: don't look at JSDoc imports (the default) + // true: detect dependencies in JSDoc-style import statements. + // Implies parser: 'tsc', which a.o. means the typescript compiler will need + // to be installed in the same spot you run dependency-cruiser from. + detectJSDocImports: true, + + // false: don't look at process.getBuiltinModule calls (the default) + // true: dependency-cruiser will detect calls to process.getBuiltinModule/ + // globalThis.process.getBuiltinModule as imports. + detectProcessBuiltinModuleCalls: true, + + // prefix for links in html, d2, mermaid and dot/ svg output (e.g. 'https://github.com/you/yourrepo/blob/main/' + // to open it on your online repo or `vscode://file/${process.cwd()}/` to + // open it in visual studio code), + // prefix: `vscode://file/${process.cwd()}/`, + + // suffix for links in output. E.g. put .html here if you use it to link to + // your coverage reports. + // suffix: '.html', + + // false (the default): ignore dependencies that only exist before typescript-to-javascript compilation + // true: also detect dependencies that only exist before typescript-to-javascript compilation + // 'specify': for each dependency identify whether it only exists before compilation or also after + tsPreCompilationDeps: false, + + // list of extensions to scan that aren't javascript or compile-to-javascript. + // Empty by default. Only put extensions in here that you want to take into + // account that are _not_ parsable. + // extraExtensionsToScan: ['.json', '.jpg', '.png', '.svg', '.webp'], + + // if true combines the package.jsons found from the module up to the base + // folder the cruise is initiated from. Useful for how (some) mono-repos + // manage dependencies & dependency definitions. + combinedDependencies: false, + + // if true leave symlinks untouched, otherwise use the realpath + preserveSymlinks: true, + + // TypeScript project file ('tsconfig.json') to use for + // (1) compilation and + // (2) resolution (e.g. with the paths property) + // + // The (optional) fileName attribute specifies which file to take (relative to + // dependency-cruiser's current working directory). When not provided + // defaults to './tsconfig.json'. + tsConfig: { + fileName: 'tsconfig.check.json', + }, + + // Webpack configuration to use to get resolve options from. + // + // The (optional) fileName attribute specifies which file to take (relative + // to dependency-cruiser's current working directory. When not provided defaults + // to './webpack.conf.js'. + // + // The (optional) 'env' and 'arguments' attributes contain the parameters + // to be passed if your webpack config is a function and takes them (see + // webpack documentation for details) + // webpackConfig: { + // fileName: 'webpack.config.js', + // env: {}, + // arguments: {} + // }, + + // Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use + // for compilation + // babelConfig: { + // fileName: '.babelrc', + // }, + + // List of strings you have in use in addition to cjs/ es6 requires + // & imports to declare module dependencies. Use this e.g. if you've + // re-declared require, use a require-wrapper or use window.require as + // a hack. + // exoticRequireStrings: [], + + // options to pass on to enhanced-resolve, the package dependency-cruiser + // uses to resolve module references to disk. The values below should be + // suitable for most situations + // + // If you use webpack: you can also set these in webpack.conf.js. The set + // there will override the ones specified here. + enhancedResolveOptions: { + // What to consider as an 'exports' field in package.jsons + exportsFields: ['exports'], + + // List of conditions to check for in the exports field. + // Only works when the 'exportsFields' array is non-empty. + conditionNames: ['import', 'require', 'node', 'default', 'types'], + + // The extensions, by default are the same as the ones dependency-cruiser + // can access (run `npx depcruise --info` to see which ones that are in + // _your_ environment). If that list is larger than you need you can pass + // the extensions you actually use (e.g. ['.js', '.jsx']). This can speed + // up module resolution, which is the most expensive step. + // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], + + // What to consider a 'main' field in package.json + mainFields: ['module', 'main', 'types', 'typings'], + + // A list of alias fields in package.jsons + // See https://github.com/defunctzombie/package-browser-field-spec and + // the webpack [resolve.alias](https://webpack.js.org/configuration/resolve/#resolvealiasfields) + // documentation. + // Defaults to an empty array (= don't use alias fields). + // aliasFields: ['browser'], + }, + + // skipAnalysisNotInRules will make dependency-cruiser execute + // analysis strictly necessary for checking the rule set only. + // See https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#skipanalysisnotinrules + skipAnalysisNotInRules: true, + + reporterOptions: { + dot: { + // Pattern of modules to consolidate to. The default pattern in this configuration + // collapses everything in node_modules to one folder deep so you see + // the external modules, but not their innards. + collapsePattern: 'node_modules/(?:@[^/]+/[^/]+|[^/]+)', + + // Options to tweak the appearance of your graph. See + // https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions + // If you don't specify a theme dependency-cruiser falls back to a built-in one. + // theme: { + // graph: { + // // splines: 'ortho' - straight lines; slow on big graphs + // // splines: 'true' - bezier curves; fast but not as nice as ortho + // splines: 'true' + // }, + // }, + }, + archi: { + // Pattern of modules to consolidate to. + collapsePattern: '^(?:packages|src|lib(s?)|app(s?)|bin|test(s?)|spec(s?))/[^/]+|node_modules/(?:@[^/]+/[^/]+|[^/]+)', + + // Options to tweak the appearance of your graph. If you don't specify a + // theme for 'archi' dependency-cruiser will use the one specified in the + // dot section above and otherwise use the default one. + // theme: { }, + }, + text: { + highlightFocused: true, + }, + }, + }, +} +// generated: dependency-cruiser@17.3.8 on 2026-03-05T13:00:09.606Z diff --git a/package.json b/package.json index 2f103ddf59ce..3c78ff76aad0 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "ci": "ni && nr typecheck && nr lint && nr build && nr test:ci", "ci:docs": "pnpm run build && pnpm run docs:build", "build": "pnpm -r --filter @vitest/ui --filter='./packages/**' run build", + "depcruise": "depcruise -c .dependency-cruiser.cjs packages --ignore-known", + "depcruise:baseline": "depcruise-baseline -c .dependency-cruiser.cjs packages", "dev": "NODE_OPTIONS=\"--max-old-space-size=8192\" pnpm -r --parallel --filter='./packages/**' run dev", "docs": "pnpm -C docs run dev", "docs:build": "ROLLDOWN_OPTIONS_VALIDATION=loose pnpm -C docs run build", @@ -54,6 +56,7 @@ "@vitest/ui": "workspace:*", "bumpp": "^10.4.1", "changelogithub": "^14.0.0", + "dependency-cruiser": "catalog:", "esbuild": "^0.27.3", "eslint": "^10.0.3", "magic-string": "^0.30.21", diff --git a/packages/browser-playwright/rollup.config.js b/packages/browser-playwright/rollup.config.js index 9f173ca3f8d9..7ee4f1c5a343 100644 --- a/packages/browser-playwright/rollup.config.js +++ b/packages/browser-playwright/rollup.config.js @@ -1,19 +1,12 @@ -import { createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies } from '../../scripts/build-utils.js' const external = [ - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, - 'vite', + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/browser-preview/rollup.config.js b/packages/browser-preview/rollup.config.js index 059c23eb2ece..7ee4f1c5a343 100644 --- a/packages/browser-preview/rollup.config.js +++ b/packages/browser-preview/rollup.config.js @@ -1,18 +1,12 @@ -import { createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies } from '../../scripts/build-utils.js' const external = [ - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/browser-webdriverio/rollup.config.js b/packages/browser-webdriverio/rollup.config.js index 059c23eb2ece..7ee4f1c5a343 100644 --- a/packages/browser-webdriverio/rollup.config.js +++ b/packages/browser-webdriverio/rollup.config.js @@ -1,18 +1,12 @@ -import { createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies } from '../../scripts/build-utils.js' const external = [ - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index b32c1783ec49..82805b00b1a1 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -1,29 +1,16 @@ -import { createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, - '@vitest/browser/utils', - '@vitest/browser/context', - '@vitest/browser/client', - 'vitest/browser', - 'worker_threads', - 'node:worker_threads', - 'vite', - 'vitest/internal/browser', + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url, { selfImportList: ['@vitest/browser/context'] }), ] -const dtsUtils = createDtsUtils() +const dtsUtils = createDtsUtils({ inputBase: 'src' }) const dtsUtilsClient = createDtsUtils({ // need extra depth to avoid output conflict isolatedDeclDir: '.types-client/tester', diff --git a/packages/coverage-istanbul/rollup.config.js b/packages/coverage-istanbul/rollup.config.js index e641d66f6db7..1eb165f5a0b8 100644 --- a/packages/coverage-istanbul/rollup.config.js +++ b/packages/coverage-istanbul/rollup.config.js @@ -1,14 +1,10 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import nodeResolve from '@rollup/plugin-node-resolve' import { join } from 'pathe' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { index: 'src/index.ts', @@ -16,13 +12,8 @@ const entries = { } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, - - // We bundle istanbul-lib-instrument but don't want to bundle its babel dependency - '@babel/core', + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/coverage-v8/rollup.config.js b/packages/coverage-v8/rollup.config.js index 083d2b01d84f..f0c095b832b7 100644 --- a/packages/coverage-v8/rollup.config.js +++ b/packages/coverage-v8/rollup.config.js @@ -1,13 +1,9 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import nodeResolve from '@rollup/plugin-node-resolve' import { join } from 'pathe' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { index: 'src/index.ts', @@ -16,11 +12,8 @@ const entries = { } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - 'node:inspector', - /^@?vitest(\/|$)/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/expect/rollup.config.js b/packages/expect/rollup.config.js index a675dd8b89ab..497ed4049f15 100644 --- a/packages/expect/rollup.config.js +++ b/packages/expect/rollup.config.js @@ -1,16 +1,10 @@ -import { builtinModules, createRequire } from 'node:module' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/mocker/rollup.config.js b/packages/mocker/rollup.config.js index 80d19d9ae187..cf25577e4c8c 100644 --- a/packages/mocker/rollup.config.js +++ b/packages/mocker/rollup.config.js @@ -1,13 +1,9 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { 'index': 'src/index.ts', @@ -21,10 +17,8 @@ const entries = { } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^msw/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/pretty-format/rollup.config.js b/packages/pretty-format/rollup.config.js index bbdc2f417fa2..375a04c8ee25 100644 --- a/packages/pretty-format/rollup.config.js +++ b/packages/pretty-format/rollup.config.js @@ -1,22 +1,17 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { index: 'src/index.ts', } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/runner/rollup.config.js b/packages/runner/rollup.config.js index b3e2ec683bde..2f8d2c5df75a 100644 --- a/packages/runner/rollup.config.js +++ b/packages/runner/rollup.config.js @@ -1,17 +1,11 @@ -import { builtinModules, createRequire } from 'node:module' import json from '@rollup/plugin-json' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const entries = { diff --git a/packages/snapshot/rollup.config.js b/packages/snapshot/rollup.config.js index fbaa4fda47b7..a5209c89cada 100644 --- a/packages/snapshot/rollup.config.js +++ b/packages/snapshot/rollup.config.js @@ -1,18 +1,12 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import nodeResolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const entries = { diff --git a/packages/spy/rollup.config.js b/packages/spy/rollup.config.js index 3f9e6e234d31..7ca08670ea29 100644 --- a/packages/spy/rollup.config.js +++ b/packages/spy/rollup.config.js @@ -1,16 +1,10 @@ -import { builtinModules, createRequire } from 'node:module' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - '@vitest/spy/optional-types.js', + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url, { selfImportList: ['@vitest/spy/optional-types.js'] }), ] const dtsUtils = createDtsUtils() diff --git a/packages/ui/client/global-setup.ts b/packages/ui/client/global-setup.ts index 356e1010bde9..3575a7659bcd 100644 --- a/packages/ui/client/global-setup.ts +++ b/packages/ui/client/global-setup.ts @@ -14,7 +14,7 @@ import 'codemirror/lib/codemirror.css' import 'codemirror-theme-vars/base.css' import './styles/main.css' import 'floating-vue/dist/style.css' -import 'uno.css' +import 'virtual:uno.css' export const directives: Record = { tooltip: vTooltip, diff --git a/packages/ui/rollup.config.js b/packages/ui/rollup.config.js index 59f5d15eea72..891124e7b180 100644 --- a/packages/ui/rollup.config.js +++ b/packages/ui/rollup.config.js @@ -1,22 +1,13 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies || {}), - 'worker_threads', - 'node:worker_threads', - /^@?vitest(\/|$)/, - 'vite', + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js index 773ea72346d2..f6315b577dfe 100644 --- a/packages/utils/rollup.config.js +++ b/packages/utils/rollup.config.js @@ -1,13 +1,9 @@ -import { builtinModules, createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { 'index': 'src/index.ts', @@ -26,9 +22,8 @@ const entries = { } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/vitest/rollup.config.js b/packages/vitest/rollup.config.js index 1766f7a66a38..4cdd2d483616 100644 --- a/packages/vitest/rollup.config.js +++ b/packages/vitest/rollup.config.js @@ -1,6 +1,4 @@ import fs from 'node:fs' -import { builtinModules, createRequire } from 'node:module' -import { fileURLToPath } from 'node:url' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import nodeResolve from '@rollup/plugin-node-resolve' @@ -10,10 +8,7 @@ import license from 'rollup-plugin-license' import { globSync } from 'tinyglobby' import c from 'tinyrainbow' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entries = { 'path': 'src/paths.ts', @@ -62,39 +57,13 @@ const dtsEntries = { } const external = [ - ...builtinModules, - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies), - 'worker_threads', - 'node:worker_threads', - 'node:fs', - 'node:os', - 'node:stream', - 'node:vm', - 'node:http', - 'node:console', - 'node:events', - 'inspector', - 'vitest/optional-runtime-types.js', - 'vitest/optional-types.js', - 'vitest/browser', - 'vite/module-runner', - '@vitest/mocker', - /@vitest\/mocker\/\w+/, - '@vitest/utils/diff', - '@vitest/utils/error', - '@vitest/utils/source-map', - '@vitest/runner/utils', - '@vitest/runner/types', - '@vitest/snapshot/environment', - '@vitest/snapshot/manager', - /@vitest\/utils\/\w+/, + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url, { selfImportList: ['vitest/optional-types.js', 'vitest/optional-runtime-types.js', 'vitest/browser'] }), '#module-evaluator', - '@opentelemetry/api', ] -const dir = dirname(fileURLToPath(import.meta.url)) +const dir = import.meta.dirname const dtsUtils = createDtsUtils() @@ -104,6 +73,21 @@ const plugins = [ }), json(), commonjs(), + oxc({ + include: [ + '/node_modules/ws/lib/buffer-util.js$', + '/node_modules/ws/lib/validation.js$', + ].map(pattern => new RegExp(pattern.replaceAll('/', '[\\\\/]').replaceAll('.', '[.]'))), + exclude: [], + transform: { + target: 'node20', + define: { + 'process.env.WS_NO_BUFFER_UTIL': 'true', + 'process.env.WS_NO_UTF_8_VALIDATE': 'true', + }, + }, + sourcemap: true, + }), oxc({ transform: { target: 'node20', diff --git a/packages/web-worker/rollup.config.js b/packages/web-worker/rollup.config.js index a3e4ae6b5f7a..1f900368cd91 100644 --- a/packages/web-worker/rollup.config.js +++ b/packages/web-worker/rollup.config.js @@ -1,13 +1,9 @@ -import { createRequire } from 'node:module' import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import nodeResolve from '@rollup/plugin-node-resolve' import { defineConfig } from 'rollup' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' - -const require = createRequire(import.meta.url) -const pkg = require('./package.json') +import { createDtsUtils, externalDependencies } from '../../scripts/build-utils.js' const entries = { index: 'src/index.ts', @@ -15,9 +11,7 @@ const entries = { } const external = [ - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - /^@?vitest(\/|$)/, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/packages/ws-client/package.json b/packages/ws-client/package.json index 4e3c1eb3e589..dde63b19c3c4 100644 --- a/packages/ws-client/package.json +++ b/packages/ws-client/package.json @@ -37,12 +37,19 @@ "dev": "rollup -c --watch --watch.include 'src/**'", "typecheck": "tsc --noEmit" }, + "peerDependencies": { + "vitest": "workspace:*" + }, + "peerDependenciesMeta": { + "vitest": { + "optional": true + } + }, "dependencies": { - "birpc": "catalog:", - "flatted": "catalog:", - "ws": "catalog:" + "birpc": "catalog:" }, "devDependencies": { - "@vitest/runner": "workspace:*" + "@vitest/runner": "workspace:*", + "flatted": "catalog:" } } diff --git a/packages/ws-client/rollup.config.js b/packages/ws-client/rollup.config.js index 1d34010bbd57..1d7db8a18ad6 100644 --- a/packages/ws-client/rollup.config.js +++ b/packages/ws-client/rollup.config.js @@ -2,21 +2,13 @@ import commonjs from '@rollup/plugin-commonjs' import json from '@rollup/plugin-json' import resolve from '@rollup/plugin-node-resolve' import oxc from 'unplugin-oxc/rollup' -import { createDtsUtils } from '../../scripts/build-utils.js' +import { createDtsUtils, externalDependencies, nodejsBuiltinModules } from '../../scripts/build-utils.js' const entry = ['src/index.ts'] const external = [ - 'ws', - 'birpc', - 'worker_threads', - 'node:worker_threads', - 'fs', - 'node:fs', - 'vitest', - 'inspector', - '@vitest/snapshot/environment', - '@vitest/snapshot/manager', + ...nodejsBuiltinModules, + ...externalDependencies(import.meta.url), ] const dtsUtils = createDtsUtils() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da59eedd0a83..7591c4b2c2e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -75,6 +75,9 @@ catalogs: chai: specifier: ^6.2.2 version: 6.2.2 + dependency-cruiser: + specifier: ^17.3.9 + version: 17.3.9 flatted: specifier: ^3.4.2 version: 3.4.2 @@ -233,6 +236,9 @@ importers: changelogithub: specifier: ^14.0.0 version: 14.0.0(magicast@0.3.5) + dependency-cruiser: + specifier: 'catalog:' + version: 17.3.9 esbuild: specifier: ^0.27.3 version: 0.27.3 @@ -1187,16 +1193,16 @@ importers: birpc: specifier: 'catalog:' version: 4.0.0 - flatted: - specifier: 'catalog:' - version: 3.4.2 - ws: - specifier: 'catalog:' - version: 8.19.0 + vitest: + specifier: workspace:* + version: link:../vitest devDependencies: '@vitest/runner': specifier: workspace:* version: link:../runner + flatted: + specifier: 'catalog:' + version: 3.4.2 test/browser: devDependencies: @@ -5863,11 +5869,18 @@ packages: peerDependencies: acorn: 8.11.3 + acorn-jsx-walk@2.0.0: + resolution: {integrity: sha512-uuo6iJj4D4ygkdzd6jPtcxs8vZgDX9YFIkqczGImoypX2fQ4dVImmu3UzA4ynixCIMTrEOWW+95M2HuBaCEOVA==} + acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: 8.11.3 + acorn-loose@8.5.2: + resolution: {integrity: sha512-PPvV6g8UGMGgjrMu+n/f9E/tCSkNQ2Y97eFvuVdJfG11+xdIeDcLyNdC8SHcrHbRqkfwLASdplyR6B6sKM1U4A==} + engines: {node: '>=0.4.0'} + acorn-walk@8.3.5: resolution: {integrity: sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==} engines: {node: '>=0.4.0'} @@ -6308,6 +6321,10 @@ packages: resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} engines: {node: '>=14'} + commander@14.0.3: + resolution: {integrity: sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==} + engines: {node: '>=20'} + commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} @@ -6617,6 +6634,11 @@ packages: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} + dependency-cruiser@17.3.9: + resolution: {integrity: sha512-LwaotlB9bZ8zhdFGGYf/g2oYkYj7YNxlqx1btL/XIYGob/aKRArsSwkLKo+ZrHiegsEArQVg4ZQ3NhAh8uk+hg==} + engines: {node: ^20.12||^22||>=24} + hasBin: true + dequal@2.0.3: resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} engines: {node: '>=6'} @@ -6740,6 +6762,10 @@ packages: resolution: {integrity: sha512-LgQMM4WXU3QI+SYgEc2liRgznaD5ojbmY3sb8LxyguVkIg5FxdpTkvk72te2R38/TGKxH634oLxXRGY6d7AP+Q==} engines: {node: '>=10.13.0'} + enhanced-resolve@5.20.0: + resolution: {integrity: sha512-/ce7+jQ1PQ6rVXwe+jKEg5hW5ciicHwIQUagZkp6IufBoY3YDgdTTY1azVs0qoRgVmvsNB+rbjLJxDAeHHtwsQ==} + engines: {node: '>=10.13.0'} + entities@2.2.0: resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==} @@ -7376,6 +7402,10 @@ packages: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me + global-directory@4.0.1: + resolution: {integrity: sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==} + engines: {node: '>=18'} + globals@15.15.0: resolution: {integrity: sha512-7ACyT3wmyp3I61S4fG682L0VA2RGD9otkqGJIwNUMF1SWUombIIk+af1unuDYgMm082aHYwD+mzJvv9Iu8dsgg==} engines: {node: '>=18'} @@ -7580,6 +7610,10 @@ packages: ini@1.3.8: resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} + ini@4.1.1: + resolution: {integrity: sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + inline-dep@file:test/config/deps/vite-ssr-resolve/inline-dep: resolution: {directory: test/config/deps/vite-ssr-resolve/inline-dep, type: directory} @@ -7587,6 +7621,10 @@ packages: resolution: {integrity: sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw==} engines: {node: '>= 0.4'} + interpret@3.1.1: + resolution: {integrity: sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==} + engines: {node: '>=10.13.0'} + ip-address@9.0.5: resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==} engines: {node: '>= 12'} @@ -7676,6 +7714,10 @@ packages: engines: {node: '>=14.16'} hasBin: true + is-installed-globally@1.0.0: + resolution: {integrity: sha512-K55T22lfpQ63N4KEN57jZUAaAYqYHEe8veb/TycJRk9DdSCLLcovXz/mL6mOnhQaZsQGwPhuFopdQIlqGSEjiQ==} + engines: {node: '>=18'} + is-map@2.0.3: resolution: {integrity: sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==} engines: {node: '>= 0.4'} @@ -7702,6 +7744,10 @@ packages: resolution: {integrity: sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==} engines: {node: '>=0.10.0'} + is-path-inside@4.0.0: + resolution: {integrity: sha512-lJJV/5dYS+RcL8uQdBDW9c9uWFLLBNRyFhnAKXw5tVqLlKZ4RMGZKv+YQ/IA3OhD+RpbJa1LLFM1FQPGyIXvOA==} + engines: {node: '>=12'} + is-plain-obj@4.1.0: resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==} engines: {node: '>=12'} @@ -8482,6 +8528,9 @@ packages: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@3.3.4: resolution: {integrity: sha512-I9WPbWHCGu8W+6k1ZiGpPu0GkoKBeorkfKNuAFBNS1HNFJvke82sxvI5bzcCNpWPorkOO5QQ+zomzzwRxejXiw==} engines: {node: '>=8'} @@ -9091,6 +9140,10 @@ packages: resolution: {integrity: sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==} engines: {node: '>= 12.13.0'} + rechoir@0.8.0: + resolution: {integrity: sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==} + engines: {node: '>= 10.13.0'} + redent@3.0.0: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} engines: {node: '>=8'} @@ -9266,6 +9319,9 @@ packages: safe-regex2@5.0.0: resolution: {integrity: sha512-YwJwe5a51WlK7KbOJREPdjNrpViQBI3p4T50lfwPuDhZnE3XGVTlGvi+aolc5+RvxDD6bnUmjVsU9n1eboLUYw==} + safe-regex@2.1.1: + resolution: {integrity: sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==} + safe-stable-stringify@2.3.1: resolution: {integrity: sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==} engines: {node: '>=10'} @@ -9713,6 +9769,10 @@ packages: resolution: {integrity: sha512-uCC2VHvQRYu+lMh4My/sFNmF2klFymLX1wHJeXnbEJERpV/ZsVuonzerjfrGpIGF7LBVa1O7i9kjiWvJiFck8g==} engines: {node: '>=0.10.0'} + strip-bom@3.0.0: + resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} + engines: {node: '>=4'} + strip-comments@2.0.1: resolution: {integrity: sha512-ZprKx+bBLXv067WTCALv8SSz5l2+XhpYCsVtSqlMnkAXMWDq+/ekVbl1ghqP9rUHTzv6sm/DwCOiYutU/yp1fw==} engines: {node: '>=10'} @@ -9955,6 +10015,14 @@ packages: peerDependencies: typescript: '>=4.0.0' + tsconfig-paths-webpack-plugin@4.2.0: + resolution: {integrity: sha512-zbem3rfRS8BgeNK50Zz5SIQgXzLafiHjOwUAvk/38/o1jHn/V5QAgVUcz884or7WYcPaH3N2CIfUc2u0ul7UcA==} + engines: {node: '>=10.13.0'} + + tsconfig-paths@4.2.0: + resolution: {integrity: sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==} + engines: {node: '>=6'} + tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -10437,6 +10505,11 @@ packages: engines: {node: '>=10'} hasBin: true + watskeburt@5.0.3: + resolution: {integrity: sha512-g9CXukMjazlJJVQ3OHzXsnG25KFYgSgKMIyoJrD8ggr0DbS9UNF7OzIqWmmKKBMedkxj3T01uqEaGnn+y7QhMA==} + engines: {node: ^20.12||^22.13||>=24.0} + hasBin: true + wbuf@1.7.3: resolution: {integrity: sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==} @@ -13090,7 +13163,7 @@ snapshots: extract-zip: 2.0.1 progress: 2.0.3 proxy-agent: 6.5.0 - semver: 7.7.3 + semver: 7.7.4 tar-fs: 3.0.8 yargs: 17.7.2 transitivePeerDependencies: @@ -13899,7 +13972,7 @@ snapshots: '@typescript-eslint/visitor-keys': 8.56.1 debug: 4.4.3 minimatch: 10.2.3 - semver: 7.7.3 + semver: 7.7.4 tinyglobby: 0.2.15 ts-api-utils: 2.4.0(typescript@5.9.3) typescript: 5.9.3 @@ -14470,10 +14543,16 @@ snapshots: dependencies: acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) + acorn-jsx-walk@2.0.0: {} + acorn-jsx@5.3.2(acorn@8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4)): dependencies: acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) + acorn-loose@8.5.2: + dependencies: + acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) + acorn-walk@8.3.5: dependencies: acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) @@ -14876,7 +14955,7 @@ snapshots: pathe: 1.1.2 pkg-types: 1.3.1 scule: 1.3.0 - semver: 7.7.3 + semver: 7.7.4 std-env: 3.10.0 yaml: 2.8.2 transitivePeerDependencies: @@ -14999,6 +15078,8 @@ snapshots: commander@10.0.1: {} + commander@14.0.3: {} + commander@2.20.3: {} commander@9.5.0: {} @@ -15290,6 +15371,27 @@ snapshots: depd@2.0.0: {} + dependency-cruiser@17.3.9: + dependencies: + acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) + acorn-jsx: 5.3.2(acorn@8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4)) + acorn-jsx-walk: 2.0.0 + acorn-loose: 8.5.2 + acorn-walk: 8.3.5 + commander: 14.0.3 + enhanced-resolve: 5.20.0 + ignore: 7.0.5 + interpret: 3.1.1 + is-installed-globally: 1.0.0 + json5: 2.2.3 + picomatch: 4.0.3 + prompts: 2.4.2 + rechoir: 0.8.0 + safe-regex: 2.1.1 + semver: 7.7.4 + tsconfig-paths-webpack-plugin: 4.2.0 + watskeburt: 5.0.3 + dequal@2.0.3: {} destr@2.0.5: {} @@ -15376,7 +15478,7 @@ snapshots: '@one-ini/wasm': 0.1.1 commander: 10.0.1 minimatch: 9.0.1 - semver: 7.7.3 + semver: 7.7.4 ee-first@1.1.1: {} @@ -15408,6 +15510,11 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.3.0 + enhanced-resolve@5.20.0: + dependencies: + graceful-fs: 4.2.11 + tapable: 2.3.0 + entities@2.2.0: {} entities@4.5.0: {} @@ -15604,7 +15711,7 @@ snapshots: eslint-compat-utils@0.5.1(eslint@10.0.3(jiti@2.6.1)): dependencies: eslint: 10.0.3(jiti@2.6.1) - semver: 7.7.3 + semver: 7.7.4 eslint-config-flat-gitignore@2.2.1(eslint@10.0.3(jiti@2.6.1)): dependencies: @@ -15694,7 +15801,7 @@ snapshots: globals: 15.15.0 globrex: 0.1.2 ignore: 5.3.2 - semver: 7.7.3 + semver: 7.7.4 ts-declaration-location: 1.0.7(typescript@5.9.3) transitivePeerDependencies: - typescript @@ -15760,7 +15867,7 @@ snapshots: pluralize: 8.0.0 regexp-tree: 0.1.27 regjsparser: 0.13.0 - semver: 7.7.3 + semver: 7.7.4 strip-indent: 4.1.1 eslint-plugin-unused-imports@4.4.1(@typescript-eslint/eslint-plugin@8.56.1(@typescript-eslint/parser@8.56.1(eslint@10.0.3(jiti@2.6.1))(typescript@5.9.3))(eslint@10.0.3(jiti@2.6.1))(typescript@5.9.3))(eslint@10.0.3(jiti@2.6.1)): @@ -15776,7 +15883,7 @@ snapshots: natural-compare: 1.4.0 nth-check: 2.1.1 postcss-selector-parser: 7.1.1 - semver: 7.7.3 + semver: 7.7.4 vue-eslint-parser: 10.4.0(eslint@10.0.3(jiti@2.6.1)) xml-name-validator: 4.0.0 optionalDependencies: @@ -16332,6 +16439,10 @@ snapshots: once: 1.4.0 path-is-absolute: 1.0.1 + global-directory@4.0.1: + dependencies: + ini: 4.1.1 + globals@15.15.0: {} globals@16.5.0: {} @@ -16549,6 +16660,8 @@ snapshots: ini@1.3.8: {} + ini@4.1.1: {} + inline-dep@file:test/config/deps/vite-ssr-resolve/inline-dep: {} internal-slot@1.1.0: @@ -16557,6 +16670,8 @@ snapshots: hasown: 2.0.2 side-channel: 1.1.0 + interpret@3.1.1: {} + ip-address@9.0.5: dependencies: jsbn: 1.1.0 @@ -16644,6 +16759,11 @@ snapshots: dependencies: is-docker: 3.0.0 + is-installed-globally@1.0.0: + dependencies: + global-directory: 4.0.1 + is-path-inside: 4.0.0 + is-map@2.0.3: {} is-module@1.0.0: {} @@ -16661,6 +16781,8 @@ snapshots: is-obj@1.0.1: {} + is-path-inside@4.0.0: {} + is-plain-obj@4.1.0: {} is-potential-custom-element-name@1.0.1: {} @@ -16899,7 +17021,7 @@ snapshots: dependencies: acorn: 8.11.3(patch_hash=62f89b815dbd769c8a4d5b19b1f6852f28922ecb581d876c8a8377d05c2483c4) eslint-visitor-keys: 5.0.0 - semver: 7.7.3 + semver: 7.7.4 jsonc-parser@3.3.1: {} @@ -17167,7 +17289,7 @@ snapshots: make-dir@4.0.0: dependencies: - semver: 7.7.3 + semver: 7.7.4 mark.js@8.11.1: {} @@ -17620,6 +17742,8 @@ snapshots: dependencies: brace-expansion: 2.0.1 + minimist@1.2.8: {} + minipass@3.3.4: dependencies: yallist: 4.0.0 @@ -18331,6 +18455,10 @@ snapshots: real-require@0.2.0: {} + rechoir@0.8.0: + dependencies: + resolve: 1.22.11 + redent@3.0.0: dependencies: indent-string: 4.0.0 @@ -18600,6 +18728,10 @@ snapshots: dependencies: ret: 0.5.0 + safe-regex@2.1.1: + dependencies: + regexp-tree: 0.1.27 + safe-stable-stringify@2.3.1: {} safer-buffer@2.1.2: {} @@ -18804,7 +18936,7 @@ snapshots: dependencies: color: 4.2.3 detect-libc: 2.0.4 - semver: 7.7.3 + semver: 7.7.4 optionalDependencies: '@img/sharp-darwin-arm64': 0.33.5 '@img/sharp-darwin-x64': 0.33.5 @@ -19125,6 +19257,8 @@ snapshots: strip-bom-string@1.0.0: {} + strip-bom@3.0.0: {} + strip-comments@2.0.1: {} strip-final-newline@3.0.0: {} @@ -19351,6 +19485,19 @@ snapshots: picomatch: 4.0.3 typescript: 5.9.3 + tsconfig-paths-webpack-plugin@4.2.0: + dependencies: + chalk: 4.1.2 + enhanced-resolve: 5.20.0 + tapable: 2.3.0 + tsconfig-paths: 4.2.0 + + tsconfig-paths@4.2.0: + dependencies: + json5: 2.2.3 + minimist: 1.2.8 + strip-bom: 3.0.0 + tslib@2.8.1: {} tsx@4.21.0: @@ -19825,7 +19972,7 @@ snapshots: eslint-visitor-keys: 5.0.0 espree: 11.1.0 esquery: 1.7.0 - semver: 7.7.3 + semver: 7.7.4 transitivePeerDependencies: - supports-color @@ -19895,6 +20042,8 @@ snapshots: transitivePeerDependencies: - supports-color + watskeburt@5.0.3: {} + wbuf@1.7.3: dependencies: minimalistic-assert: 1.0.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index c18207096e7e..4e69650c8dc1 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -66,6 +66,7 @@ catalog: birpc: ^4.0.0 cac: ^6.7.14 chai: ^6.2.2 + dependency-cruiser: ^17.3.9 flatted: ^3.4.2 istanbul-lib-coverage: ^3.2.2 istanbul-lib-report: ^3.0.1 diff --git a/scripts/build-utils.js b/scripts/build-utils.js index 23f387e6d5a2..59b14c8e55bf 100644 --- a/scripts/build-utils.js +++ b/scripts/build-utils.js @@ -1,12 +1,42 @@ // @ts-check import fs from 'node:fs' +import { builtinModules, createRequire } from 'node:module' import path from 'node:path' import dts from 'rollup-plugin-dts' import isolatedDecl from 'unplugin-isolated-decl/rollup' +/** + * Node.js builtin modules for rollup config. + * Unprefixed and "node:"-prefixed names are both included for compatibility with different import styles in source code. + * @type {string[]} + */ +export const nodejsBuiltinModules = builtinModules.flatMap(m => m.includes(':') ? m : [m, `node:${m}`]) +/** + * External dependencies for rollup config, which are union of dependencies, optionalDependencies, and peerDependencies from package.json. + * @param {string} importMetaUrl + * @param {{ selfImportList?: string[] }} options + * @returns {(RegExp|string)[]} external dependencies for rollup config + */ +export function externalDependencies(importMetaUrl, { selfImportList = [] } = {}) { + const _require = createRequire(importMetaUrl) + const pkg = _require('./package.json') + const wrongSelfImports = selfImportList.filter(p => !(`${p}/`).startsWith(`${pkg.name}/`)) + if (wrongSelfImports.length) { + throw new Error(`Invalid self-imports: ${wrongSelfImports.join(', ')}. They should start with "${pkg.name}/"`) + } + return [ + ...Object.keys(({ ...pkg.dependencies, ...pkg.optionalDependencies, ...pkg.peerDependencies })).map(key => new RegExp(`^${key}($|/)`)), + ...selfImportList, + ] +} + +/** + * @param {{ isolatedDeclDir?: string; cleanupDir?: string; inputBase?: string }} options + */ export function createDtsUtils({ isolatedDeclDir = '.types', cleanupDir = '.types', + inputBase, } = {}) { return { /** @@ -20,16 +50,8 @@ export function createDtsUtils({ // exclude direct imports to other package sources include: path.join(process.cwd(), '**/*.ts'), extraOutdir: isolatedDeclDir, + inputBase, }), - { - name: 'isolated-decl-dts-extra', - resolveId(source) { - // silence node-resolve error by isolated-decl transform of type import - if (source.startsWith('vite/types/')) { - return { id: '/node_modules/', external: true } - } - }, - }, ] }, /** diff --git a/tsconfig.base.json b/tsconfig.base.json index 41c24c2a7f41..5938783dea64 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -11,6 +11,7 @@ "@vitest/utils": ["./packages/utils/src/index.ts"], "@vitest/utils/*": ["./packages/utils/src/*"], "@vitest/spy": ["./packages/spy/src/index.ts"], + "@vitest/spy/optional-types.js": ["./packages/spy/optional-types.d.ts"], "@vitest/snapshot": ["./packages/snapshot/src/index.ts"], "@vitest/snapshot/*": ["./packages/snapshot/src/*"], "@vitest/expect": ["./packages/expect/src/index.ts"], @@ -23,6 +24,7 @@ "@vitest/browser-playwright": ["./packages/browser-playwright/src/index.ts"], "@vitest/browser": ["./packages/browser/src/node/index.ts"], "@vitest/browser/client": ["./packages/browser/src/client/client.ts"], + "@vitest/browser/context": ["./packages/browser/context.d.ts"], "~/*": ["./packages/ui/client/*"], "vitest": ["./packages/vitest/src/public/index.ts"], "vitest/internal/browser": ["./packages/vitest/src/public/browser.ts"],