@prosopo/config 3.4.1 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +9 -11
  2. package/.turbo/turbo-build$colon$tsc.log +4 -7
  3. package/.turbo/turbo-build.log +10 -15
  4. package/CHANGELOG.md +18 -0
  5. package/LICENSE +201 -0
  6. package/dist/cjs/dependencies.cjs +86 -46
  7. package/dist/cjs/vite/testFileGlobs.cjs +31 -0
  8. package/dist/cjs/vite/vite.frontend.config.cjs +7 -0
  9. package/dist/cjs/vite/vite.test.config.cjs +9 -8
  10. package/dist/cjs/vite/vite.threads.test.config.cjs +9 -8
  11. package/dist/cjs/webpack/webpack.config.cjs +8 -8
  12. package/dist/dependencies.d.ts.map +1 -1
  13. package/dist/dependencies.js +85 -44
  14. package/dist/dependencies.js.map +1 -1
  15. package/dist/getDependencies.test.js +151 -125
  16. package/dist/getDependencies.test.js.map +1 -1
  17. package/dist/vite/configs.test.js +6 -19
  18. package/dist/vite/configs.test.js.map +1 -1
  19. package/dist/vite/testFileGlobs.d.ts +8 -0
  20. package/dist/vite/testFileGlobs.d.ts.map +1 -0
  21. package/dist/vite/testFileGlobs.js +29 -0
  22. package/dist/vite/testFileGlobs.js.map +1 -0
  23. package/dist/vite/testFileGlobs.test.d.ts +2 -0
  24. package/dist/vite/testFileGlobs.test.d.ts.map +1 -0
  25. package/dist/vite/testFileGlobs.test.js +113 -0
  26. package/dist/vite/testFileGlobs.test.js.map +1 -0
  27. package/dist/vite/vite.frontend.config.d.ts.map +1 -1
  28. package/dist/vite/vite.frontend.config.js +8 -1
  29. package/dist/vite/vite.frontend.config.js.map +1 -1
  30. package/dist/vite/vite.test.config.d.ts.map +1 -1
  31. package/dist/vite/vite.test.config.js +9 -8
  32. package/dist/vite/vite.test.config.js.map +1 -1
  33. package/dist/vite/vite.threads.test.config.d.ts.map +1 -1
  34. package/dist/vite/vite.threads.test.config.js +9 -8
  35. package/dist/vite/vite.threads.test.config.js.map +1 -1
  36. package/dist/webpack/webpack.config.d.ts +2 -0
  37. package/dist/webpack/webpack.config.d.ts.map +1 -1
  38. package/dist/webpack/webpack.config.js +8 -8
  39. package/dist/webpack/webpack.config.js.map +1 -1
  40. package/package.json +106 -103
  41. package/src/dependencies.test.ts +0 -249
  42. package/src/dependencies.ts +0 -259
  43. package/src/getDependencies.test.ts +0 -385
  44. package/src/index.ts +0 -16
  45. package/src/vite/CopyAssetsPlugin.ts +0 -49
  46. package/src/vite/NodejsPolarsDirnamePlugin.ts +0 -50
  47. package/src/vite/NodejsPolarsNativeFilePlugin.ts +0 -105
  48. package/src/vite/TsNoCheckPlugin.ts +0 -31
  49. package/src/vite/bundleConfigs.test.ts +0 -461
  50. package/src/vite/configs.test.ts +0 -235
  51. package/src/vite/index.ts +0 -30
  52. package/src/vite/modifyExportsFiles.test.ts +0 -56
  53. package/src/vite/plugins.test.ts +0 -365
  54. package/src/vite/translations.test.ts +0 -164
  55. package/src/vite/types.ts +0 -13
  56. package/src/vite/vite-plugin-close-and-copy.ts +0 -76
  57. package/src/vite/vite-plugin-copy.ts +0 -67
  58. package/src/vite/vite-plugin-externalize-obfuscator-deadcode.ts +0 -43
  59. package/src/vite/vite-plugin-fix-absolute-imports.ts +0 -40
  60. package/src/vite/vite-plugin-modify-exports-files.ts +0 -64
  61. package/src/vite/vite-plugin-remove-unused-translations.ts +0 -128
  62. package/src/vite/vite-plugin-sourcemap-exclude.ts +0 -36
  63. package/src/vite/vite.backend.config.ts +0 -172
  64. package/src/vite/vite.commonjs.config.ts +0 -98
  65. package/src/vite/vite.esm.config.ts +0 -99
  66. package/src/vite/vite.frontend.config.ts +0 -340
  67. package/src/vite/vite.test.config.ts +0 -121
  68. package/src/vite/vite.threads.test.config.ts +0 -106
  69. package/src/webpack/index.ts +0 -14
  70. package/src/webpack/webpack.config.ts +0 -159
  71. package/tsconfig.cjs.json +0 -9
  72. package/tsconfig.json +0 -17
  73. package/tsconfig.tsbuildinfo +0 -1
  74. package/tsconfig.types.json +0 -9
@@ -1,340 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { builtinModules } from "node:module";
16
- import path from "node:path";
17
- import nodeResolve from "@rollup/plugin-node-resolve";
18
- import typescript from "@rollup/plugin-typescript";
19
- import { wasm } from "@rollup/plugin-wasm";
20
- import { default as viteReact } from "@vitejs/plugin-react";
21
- import type { Drop } from "esbuild";
22
- import type { ExternalOption } from "rollup";
23
- import css from "rollup-plugin-import-css";
24
- import { visualizer } from "rollup-plugin-visualizer";
25
- import type { UserConfig } from "vite";
26
- import { nodePolyfills } from "vite-plugin-node-polyfills";
27
- import { filterDependencies, getDependencies } from "../dependencies.js";
28
- import { VitePluginCloseAndCopy } from "./index.js";
29
- import type { ClosePluginOptions } from "./vite-plugin-close-and-copy.js";
30
- import VitePluginExternalizeObfuscatorDeadCode from "./vite-plugin-externalize-obfuscator-deadcode.js";
31
-
32
- export default async function (
33
- packageName: string,
34
- bundleName: string,
35
- dir: string,
36
- entry: string,
37
- command?: string,
38
- mode?: string,
39
- copyOptions?: ClosePluginOptions,
40
- tsConfigPaths?: string[],
41
- workspaceRoot?: string,
42
- ): Promise<UserConfig> {
43
- // Only development and production modes are allowed
44
- if (mode !== "production") {
45
- mode = "development";
46
- }
47
- // We don't have a default environment of, for example, `test` so we use the `mode` as the default
48
- const allowedEnvironments = ["development", "staging", "production"];
49
- const defaultEnvironment =
50
- process.env.NODE_ENV && allowedEnvironments.includes(process.env.NODE_ENV)
51
- ? process.env.NODE_ENV
52
- : mode;
53
-
54
- console.info(`Running at ${dir} in ${mode} mode`);
55
- const isProduction = mode === "production";
56
- // Rollup bundle stats (rollup-plugin-visualizer treemap). Off by default —
57
- // set PROSOPO_BUNDLE_STATS=true to generate the stats page and open it in
58
- // the browser once the bundle has been built.
59
- const openBundleStats =
60
- process.env.PROSOPO_BUNDLE_STATS?.trim().toLowerCase() === "true";
61
- // NODE_ENV must be wrapped in quotes.
62
- // If NODE_ENV ends up out of sync (one set to development and the other set to production), it causes
63
- // issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
64
- process.env.NODE_ENV = `${process.env.NODE_ENV || mode}`;
65
- console.info(`NODE_ENV: ${process.env.NODE_ENV}`);
66
-
67
- // Set the env vars that we want to be available in the browser
68
- const define = {
69
- // used to stop websockets package from breaking
70
- "process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
71
- "process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
72
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
73
- "process.env.PROSOPO_DEFAULT_ENVIRONMENT":
74
- JSON.stringify(defaultEnvironment),
75
- "process.env.PROSOPO_SERVER_URL": JSON.stringify(
76
- process.env.PROSOPO_SERVER_URL,
77
- ),
78
- // Lets a development widget reach a provider that is not on the machine
79
- // serving the page — a phone or simulator testing over the LAN would
80
- // otherwise resolve the default `localhost` to itself.
81
- "process.env.PROSOPO_PROVIDER_URL_DEVELOPMENT": JSON.stringify(
82
- process.env.PROSOPO_PROVIDER_URL_DEVELOPMENT,
83
- ),
84
- // Points a self-hosted build at its own providers regardless of
85
- // environment, so a production bundle no longer has to masquerade as a
86
- // development build to be redirected.
87
- "process.env.PROSOPO_PROVIDER_LIST": JSON.stringify(
88
- process.env.PROSOPO_PROVIDER_LIST,
89
- ),
90
- "process.env._DEV_ONLY_WATCH_EVENTS": JSON.stringify(
91
- process.env._DEV_ONLY_WATCH_EVENTS,
92
- ),
93
- "process.env.PROSOPO_MONGO_EVENTS_URI": JSON.stringify(
94
- process.env.PROSOPO_MONGO_EVENTS_URI,
95
- ),
96
- "process.env.PROSOPO_PACKAGE_VERSION": JSON.stringify(
97
- process.env.PROSOPO_PACKAGE_VERSION,
98
- ),
99
- "process.env.PROSOPO_DOCS_URL": JSON.stringify(
100
- process.env.PROSOPO_DOCS_URL,
101
- ),
102
- "process.env.PROSOPO_LOG_LEVEL": JSON.stringify(
103
- process.env.PROSOPO_LOG_LEVEL,
104
- ),
105
- // only needed if bundling with a site key
106
- "process.env.PROSOPO_SITE_KEY": JSON.stringify(
107
- process.env.PROSOPO_SITE_KEY,
108
- ),
109
- };
110
-
111
- console.info(`Env vars: ${JSON.stringify(define, null, 4)}`);
112
-
113
- // Get all dependencies of the current package
114
- const { dependencies: deps, optionalPeerDependencies } =
115
- await getDependencies(packageName, isProduction);
116
-
117
- // Get rid of any dependencies we don't want to bundle.
118
- // The two i18next entries are server-only: the fs backend reads locale JSON
119
- // off disk and the middleware is Express request handling. Neither can run
120
- // in a browser — `i18nBackend.ts` also imports `node:path`, which is already
121
- // external — so they are pure weight in a frontend bundle. The other
122
- // i18next-* packages (http-backend, browser-languagedetector,
123
- // chained-backend, resources-to-backend) ARE used in the browser and must
124
- // stay bundled; these filters are substring matches, so they catch only
125
- // themselves.
126
- const { external, internal } = filterDependencies(deps, [
127
- "pm2",
128
- "nodejs-polars",
129
- "aws",
130
- "webpack",
131
- "vite",
132
- "i18next-fs-backend",
133
- "i18next-http-middleware",
134
- ]);
135
-
136
- // `external` only ever matches a specifier exactly, so listing a package by
137
- // name does nothing for a subpath import of it. `i18next-fs-backend` has
138
- // been on the exclusion list above for a long time, but `i18nBackend.ts`
139
- // imports `i18next-fs-backend/cjs` (see i18next/i18next-fs-backend#57) —
140
- // a different string — so it was bundled anyway, dragging its YAML, JSON5
141
- // and JSONC parsers into the browser artifact.
142
- //
143
- // Listed literally rather than by matching `pkg/*` against the whole
144
- // exclusion list: that broader rule also catches
145
- // `vite-plugin-node-polyfills/shims/process` (the `vite` filter is a
146
- // substring match, so it selects the plugin package too). That specifier is
147
- // injected into the served and IIFE bundles as a bare import, and
148
- // externalising it leaves the browser unable to resolve it — the widget dies
149
- // on load with "Failed to resolve module specifier".
150
- const serverOnlySubpaths = ["i18next-fs-backend/cjs"];
151
-
152
- // Add the node builtins (path, fs, os, etc.) to the external list
153
- const allExternal = [
154
- ...builtinModules,
155
- ...builtinModules.map((m) => `node:${m}`),
156
- ...external,
157
- ...optionalPeerDependencies,
158
- ...serverOnlySubpaths,
159
- ];
160
- console.debug(
161
- `Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`,
162
- );
163
-
164
- // Required to print RegExp in console (e.g. alias keys)
165
- // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
166
- const proto = RegExp.prototype as any;
167
- proto.toJSON = RegExp.prototype.toString;
168
-
169
- // drop console logs if in production mode
170
- let drop: undefined | Drop[];
171
- let pure: string[] = [];
172
- if (isProduction) {
173
- drop = ["debugger"];
174
- pure = ["console.log", "console.warn", "console.info", "console.debug"];
175
- }
176
-
177
- const rollupExternal: ExternalOption = allExternal;
178
-
179
- console.info({ bundleName }, "Bundle name");
180
- return {
181
- server: {
182
- host: "127.0.0.1",
183
- },
184
- mode: mode || "development",
185
- optimizeDeps: {
186
- include: ["node_modules"],
187
- force: true,
188
- },
189
- worker: {
190
- format: "es",
191
- },
192
- esbuild: {
193
- platform: "browser",
194
- target: [
195
- "es2020",
196
- "chrome60",
197
- "edge18",
198
- "firefox60",
199
- "node24",
200
- "safari11",
201
- ],
202
- drop,
203
- pure,
204
- legalComments: "none",
205
- jsx: "automatic",
206
- jsxImportSource: "@emotion/react",
207
- jsxDev: process.env.NODE_ENV === "development",
208
- },
209
- define,
210
-
211
- build: {
212
- outDir: path.resolve(dir, "dist/bundle"),
213
- minify: isProduction,
214
- ssr: false,
215
- lib: {
216
- entry: path.resolve(dir, entry),
217
- name: bundleName,
218
- fileName: `${bundleName}.bundle.js`,
219
- formats: ["es"],
220
- },
221
- modulePreload: { polyfill: true },
222
- commonjsOptions: {
223
- exclude: ["mongodb/*"],
224
- transformMixedEsModules: true,
225
- strictRequires: "debug",
226
- },
227
-
228
- rollupOptions: {
229
- treeshake: {
230
- // Respect /*#__PURE__*/ annotations. Ignoring them retained
231
- // dead library calls that every consumer then shipped;
232
- // honouring them cuts ~17KB gzip off the widget bundle with
233
- // a byte-identical detector.
234
- annotations: true,
235
- propertyReadSideEffects: false,
236
- // Measured alternatives, both rejected:
237
- // moduleSideEffects: false -> widget 8KB gzip LARGER
238
- // propertyWriteSideEffects: false -> detector dies on load
239
- // ("Maximum call stack
240
- // size exceeded")
241
- moduleSideEffects: "no-external",
242
- unknownGlobalSideEffects: false,
243
- },
244
- external: rollupExternal,
245
- watch: false,
246
-
247
- output: {
248
- dir: path.resolve(dir, "dist/bundle"),
249
- entryFileNames: `${bundleName}.bundle.js`,
250
- // For a lib + es build, Vite downgrades `build.minify: true` to
251
- // `{ compress, mangle, codegen: false }`, which leaves the output
252
- // pretty-printed. Set it here to get whitespace removal too;
253
- // output options win over the build-level default.
254
- ...(isProduction
255
- ? {
256
- minify: {
257
- compress: true,
258
- mangle: true,
259
- codegen: true,
260
- },
261
- }
262
- : {}),
263
- },
264
-
265
- plugins: [
266
- // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
267
- css() as any,
268
- // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
269
- wasm() as any,
270
- // @ts-ignore
271
- nodeResolve({
272
- browser: true,
273
- preferBuiltins: false,
274
- rootDir: path.resolve(dir, "../../"),
275
- dedupe: ["react", "react-dom"],
276
- modulesOnly: true,
277
- // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
278
- }) as any,
279
- // String replacement plugin for fingerprinting code
280
- {
281
- name: "string-replace-fingerprint",
282
- generateBundle(_, bundle) {
283
- for (const fileName in bundle) {
284
- const chunk = bundle[fileName];
285
- if (
286
- chunk &&
287
- chunk.type === "chunk" &&
288
- "code" in chunk &&
289
- chunk.code
290
- ) {
291
- chunk.code = chunk.code.replace(
292
- /var request = new XMLHttpRequest\(\);\s*request\.open\("get", "https:\/\/m1\.openfpcdn\.io\/fingerprintjs\/v"\.concat\(version, "\/npm-monitoring"\), true\);\s*request\.send\(\);/g,
293
- "",
294
- );
295
- }
296
- }
297
- },
298
- },
299
- // Bundle stats page — only wired in (and opened in the
300
- // browser) when PROSOPO_BUNDLE_STATS=true. Defaults off so
301
- // normal builds neither emit the report nor pop a window.
302
- ...(openBundleStats
303
- ? [
304
- visualizer({
305
- open: true,
306
- template: "treemap",
307
- gzipSize: true,
308
- brotliSize: true,
309
- }),
310
- ]
311
- : []),
312
- // I think we can use this plugin to build all packages instead of relying on the tsc step that's
313
- // currently a precursor in package.json. However, it fails for the following reason:
314
- // https://github.com/rollup/plugins/issues/243
315
- // @ts-ignore
316
- typescript({
317
- tsconfig: path.resolve("./tsconfig.json"),
318
- compilerOptions: { rootDir: path.resolve("./src") },
319
- outDir: path.resolve(dir, "dist/bundle"),
320
- }),
321
- ],
322
- },
323
- },
324
- plugins: [
325
- VitePluginExternalizeObfuscatorDeadCode(),
326
- // node polyfills must be a top-level Vite plugin (not inside
327
- // build.rollupOptions.plugins) so its inject sub-plugin initialises
328
- // before transform runs under Rolldown/Vite 8.
329
- nodePolyfills({
330
- include: ["crypto"],
331
- }),
332
- // Not sure if we need this plugin or not, it works without it
333
- // @ts-ignore
334
- viteReact(),
335
- // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
336
- // mode, in which case we don't want to close the bundler because it will close the server
337
- command !== "serve" ? VitePluginCloseAndCopy(copyOptions) : undefined,
338
- ],
339
- };
340
- }
@@ -1,121 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import fs from "node:fs";
16
- import path from "node:path";
17
- import tsconfigPaths from "vite-tsconfig-paths";
18
- import { defineConfig } from "vitest/config";
19
- import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
20
- import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
21
-
22
- export default function (tsConfigPath?: string) {
23
- const testTypeEnv = process.env.TEST_TYPE || undefined;
24
- console.log(`TEST_TYPE environment variable: ${testTypeEnv}`);
25
- const testTypes = testTypeEnv ? testTypeEnv.trim().split(",") : [];
26
- // @(|) globs any tests which don't have their type specified, e.g. myTest.test.ts. These are included even when filtering by test type because we don't know what type of test they are. Really, they should have their type specified.
27
- // If we drop ^, there's a chance the tests with no type specified get ignored by accident, which we want to avoid. Ergo, include them by default.
28
- const testTypeGlob =
29
- testTypes.length > 0
30
- ? `@(${testTypes.map((t) => `.${t}`).join("|")})`
31
- : "@(|)";
32
- console.log(`Filtering tests by type: ${testTypeGlob}`);
33
-
34
- // Determine coverage include paths based on current working directory.
35
- //
36
- // Detected by looking for a package alongside the cwd rather than by
37
- // matching "/packages/" in the path: workspaces also live in dev/, demos/
38
- // and integration/, and those were falling through to the repo-root globs
39
- // below, which match `packages/*/src/**` only — so they reported 0/0
40
- // coverage no matter what their tests exercised. Neither repo root has a
41
- // `src` directory, so this cannot misfire in the other direction.
42
- const cwd = process.cwd();
43
- const isRunningFromPackage =
44
- fs.existsSync(path.join(cwd, "package.json")) &&
45
- fs.existsSync(path.join(cwd, "src"));
46
-
47
- // If running from a package directory, include local src files
48
- // If running from repo root, include all package src files
49
- const coverageInclude = isRunningFromPackage
50
- ? ["src/**/*.ts", "src/**/*.js", "src/**/*.tsx", "src/**/*.jsx"]
51
- : ["packages/*/src/**", "captcha/packages/*/src/**"];
52
-
53
- const coverageExclude = isRunningFromPackage
54
- ? [
55
- "src/tests/**/*",
56
- "src/**/*.d.ts",
57
- "src/**/*.test.ts",
58
- "src/**/*.spec.ts",
59
- "src/**/*.test.tsx",
60
- "src/**/*.spec.tsx",
61
- // Type-test files are compiled by the typecheck pass, never
62
- // executed, so they can only ever report 0% and drag the real
63
- // figure down. `*.d.ts` above does not match `*.test-d.ts`.
64
- "src/**/*.test-d.ts",
65
- "src/**/*.test-d.tsx",
66
- ]
67
- : [
68
- "**/tests/**/*",
69
- "**/*.d.ts",
70
- "**/*.test.*",
71
- "**/*.spec.*",
72
- "**/node_modules/**",
73
- "**/dist/**",
74
- ];
75
- const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
76
- const plugins = [
77
- VitePluginSourcemapExclude({ excludeNodeModules: true }),
78
- VitePluginCloseAndCopy(),
79
- ];
80
-
81
- if (tsConfigPath) {
82
- plugins.push(tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }));
83
- }
84
-
85
- return defineConfig({
86
- build: {
87
- minify: false,
88
- sourcemap: false,
89
- rollupOptions: {
90
- output: {
91
- sourcemap: false,
92
- },
93
- },
94
- },
95
- test: {
96
- //root: getRootDir(),
97
- // vitest 4 removed the "basic" reporter; the default reporter with
98
- // summary disabled reproduces its terse output.
99
- reporters: [["default", { summary: false }]],
100
- include: [include],
101
- watch: false,
102
- exclude: ["**/node_modules/**", "**/dist/**"],
103
- logHeapUsage: true,
104
- coverage: {
105
- enabled: true,
106
- include: coverageInclude,
107
- exclude: coverageExclude,
108
- },
109
- typecheck: {
110
- enabled: true,
111
- },
112
- pool: "forks", // forks is slower than 'threads' but more compatible with low-level libs (e.g. bcrypt)
113
- isolate: true,
114
- sequence: {
115
- shuffle: true,
116
- },
117
- testTimeout: 10000,
118
- },
119
- plugins: plugins,
120
- });
121
- }
@@ -1,106 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import path from "node:path";
16
- import tsconfigPaths from "vite-tsconfig-paths";
17
- import { defineConfig } from "vitest/config";
18
- import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
19
- import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
20
-
21
- export default function (tsConfigPath?: string) {
22
- const testTypeEnv = process.env.TEST_TYPE || undefined;
23
- console.log(`TEST_TYPE environment variable: ${testTypeEnv}`);
24
- const testTypes = testTypeEnv ? testTypeEnv.trim().split(",") : [];
25
- // @(|) globs any tests which don't have their type specified, e.g. myTest.test.ts. These are included even when filtering by test type because we don't know what type of test they are. Really, they should have their type specified.
26
- // If we drop ^, there's a chance the tests with no type specified get ignored by accident, which we want to avoid. Ergo, include them by default.
27
- const testTypeGlob =
28
- testTypes.length > 0
29
- ? `@(${testTypes.map((t) => `.${t}`).join("|")})`
30
- : "@(|)";
31
- console.log(`Filtering tests by type: ${testTypeGlob}`);
32
-
33
- // Determine coverage include paths based on current working directory
34
- const cwd = process.cwd();
35
- const isRunningFromPackage =
36
- cwd.includes("/packages/") && cwd.includes("/src") === false;
37
-
38
- // If running from a package directory, include local src files
39
- // If running from repo root, include all package src files
40
- const coverageInclude = isRunningFromPackage
41
- ? ["src/**/*.ts", "src/**/*.js", "src/**/*.tsx", "src/**/*.jsx"]
42
- : ["packages/*/src/**", "captcha/packages/*/src/**"];
43
-
44
- const coverageExclude = isRunningFromPackage
45
- ? [
46
- "src/tests/**/*",
47
- "src/**/*.d.ts",
48
- "src/**/*.test.ts",
49
- "src/**/*.spec.ts",
50
- "src/**/*.test.tsx",
51
- "src/**/*.spec.tsx",
52
- ]
53
- : [
54
- "**/tests/**/*",
55
- "**/*.d.ts",
56
- "**/*.test.*",
57
- "**/*.spec.*",
58
- "**/node_modules/**",
59
- "**/dist/**",
60
- ];
61
- const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
62
- const plugins = [
63
- VitePluginSourcemapExclude({ excludeNodeModules: true }),
64
- VitePluginCloseAndCopy(),
65
- ];
66
-
67
- if (tsConfigPath) {
68
- plugins.push(tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }));
69
- }
70
-
71
- return defineConfig({
72
- build: {
73
- minify: false,
74
- sourcemap: false,
75
- rollupOptions: {
76
- output: {
77
- sourcemap: false,
78
- },
79
- },
80
- },
81
- test: {
82
- //root: getRootDir(),
83
- // vitest 4 removed the "basic" reporter; the default reporter with
84
- // summary disabled reproduces its terse output.
85
- reporters: [["default", { summary: false }]],
86
- include: [include],
87
- watch: false,
88
- exclude: ["**/node_modules/**", "**/dist/**"],
89
- logHeapUsage: true,
90
- coverage: {
91
- enabled: true,
92
- include: coverageInclude,
93
- exclude: coverageExclude,
94
- },
95
- typecheck: {
96
- enabled: true,
97
- },
98
- pool: "threads", // use threads for tests that should be run sequentially
99
- // vitest 4 removed poolOptions; sequential execution is now expressed via
100
- // fileParallelism instead of min/maxThreads.
101
- fileParallelism: false,
102
- testTimeout: 10000,
103
- },
104
- plugins: plugins,
105
- });
106
- }
@@ -1,14 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- export * from "./webpack.config.js";