@prosopo/config 3.3.0 → 3.3.2

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 (46) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +4 -4
  2. package/.turbo/turbo-build$colon$tsc.log +4 -4
  3. package/.turbo/turbo-build.log +5 -5
  4. package/.turbo/turbo-typecheck.log +1 -1
  5. package/CHANGELOG.md +10 -0
  6. package/dist/cjs/vite/vite.backend.config.cjs +8 -1
  7. package/dist/cjs/webpack/webpack.config.cjs +8 -6
  8. package/dist/vite/vite.backend.config.d.ts +1 -1
  9. package/dist/vite/vite.backend.config.d.ts.map +1 -1
  10. package/dist/vite/vite.backend.config.js +8 -1
  11. package/dist/vite/vite.backend.config.js.map +1 -1
  12. package/dist/vite/vite.commonjs.config.d.ts +1 -1
  13. package/dist/vite/vite.commonjs.config.d.ts.map +1 -1
  14. package/dist/vite/vite.commonjs.config.js.map +1 -1
  15. package/dist/vite/vite.esm.config.d.ts +1 -1
  16. package/dist/vite/vite.esm.config.d.ts.map +1 -1
  17. package/dist/vite/vite.esm.config.js.map +1 -1
  18. package/dist/webpack/webpack.config.d.ts +1 -6
  19. package/dist/webpack/webpack.config.d.ts.map +1 -1
  20. package/dist/webpack/webpack.config.js +8 -6
  21. package/dist/webpack/webpack.config.js.map +1 -1
  22. package/package.json +4 -3
  23. package/src/dependencies.ts +246 -0
  24. package/src/index.ts +16 -0
  25. package/src/vite/NodejsPolarsDirnamePlugin.ts +45 -0
  26. package/src/vite/NodejsPolarsNativeFilePlugin.ts +83 -0
  27. package/src/vite/TsNoCheckPlugin.ts +27 -0
  28. package/src/vite/index.ts +25 -0
  29. package/src/vite/types.ts +13 -0
  30. package/src/vite/vite-plugin-close-and-copy.ts +76 -0
  31. package/src/vite/vite-plugin-copy.ts +67 -0
  32. package/src/vite/vite-plugin-fix-absolute-imports.ts +40 -0
  33. package/src/vite/vite-plugin-remove-unused-translations.ts +128 -0
  34. package/src/vite/vite-plugin-sourcemap-exclude.ts +36 -0
  35. package/src/vite/vite.backend.config.ts +148 -0
  36. package/src/vite/vite.commonjs.config.ts +96 -0
  37. package/src/vite/vite.esm.config.ts +87 -0
  38. package/src/vite/vite.frontend.config.ts +265 -0
  39. package/src/vite/vite.test.config.ts +111 -0
  40. package/src/vite/vite.threads.test.config.ts +109 -0
  41. package/src/webpack/index.ts +14 -0
  42. package/src/webpack/webpack.config.ts +152 -0
  43. package/tsconfig.cjs.json +9 -0
  44. package/tsconfig.json +17 -0
  45. package/tsconfig.tsbuildinfo +1 -0
  46. package/tsconfig.types.json +9 -0
@@ -0,0 +1,96 @@
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 { type UserConfig, defineConfig } from "vite";
18
+ import { default as noBundlePlugin } from "vite-plugin-no-bundle";
19
+ import tsconfigPaths from "vite-tsconfig-paths";
20
+ import { getExternalsFromReferences } from "../dependencies.js";
21
+ import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
22
+ import VitePluginCopy from "./vite-plugin-copy.js";
23
+
24
+ export default async function (
25
+ name: string,
26
+ tsConfigPath: string,
27
+ entry?: string | string[] | Record<string, string>,
28
+ ): Promise<UserConfig> {
29
+ console.info(`ViteCommonJSConfig: ${name}`);
30
+ const projectExternal = await getExternalsFromReferences(tsConfigPath, [
31
+ /dev/,
32
+ ]);
33
+ const allExternal = [
34
+ ...builtinModules,
35
+ ...builtinModules.map((m) => `node:${m}`),
36
+ ...projectExternal,
37
+ ];
38
+ return defineConfig({
39
+ ssr: { external: allExternal },
40
+ plugins: [
41
+ // @ts-ignore
42
+ {
43
+ name: "string-replace-import.meta.url",
44
+ generateBundle(_, bundle) {
45
+ for (const fileName in bundle) {
46
+ const chunk = bundle[fileName];
47
+ if (
48
+ chunk &&
49
+ chunk.type === "chunk" &&
50
+ "code" in chunk &&
51
+ chunk.code
52
+ ) {
53
+ chunk.code = chunk.code.replace(
54
+ /import\.meta\.url/g,
55
+ "require('url').pathToFileURL(__filename).href",
56
+ );
57
+ }
58
+ }
59
+ },
60
+ },
61
+ // @ts-ignore
62
+ noBundlePlugin({
63
+ root: "src",
64
+ copy: "**/*.css",
65
+ }),
66
+ VitePluginCopy({
67
+ srcDir: "src",
68
+ destDir: "dist",
69
+ include: ["**/*.json"],
70
+ }),
71
+ tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }),
72
+ VitePluginCloseAndCopy(),
73
+ ],
74
+ build: {
75
+ emptyOutDir: false,
76
+ ssr: true,
77
+ target: "node24",
78
+ outDir: "dist/cjs",
79
+ lib: {
80
+ name,
81
+ formats: ["cjs"],
82
+ entry: entry || "src/index.ts", // required
83
+ },
84
+ rollupOptions: {
85
+ treeshake: false,
86
+ external: allExternal,
87
+ },
88
+ },
89
+ esbuild: {
90
+ jsx: "automatic",
91
+ // Use standard React JSX for library packages
92
+ // Frontend apps using ViteFrontendConfig will override to Emotion
93
+ jsxDev: process.env.NODE_ENV === "development",
94
+ },
95
+ });
96
+ }
@@ -0,0 +1,87 @@
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 { type UserConfig, defineConfig } from "vite";
18
+ import { default as noBundlePlugin } from "vite-plugin-no-bundle";
19
+ import tsconfigPaths from "vite-tsconfig-paths";
20
+ import { getExternalsFromReferences } from "../dependencies.js";
21
+ import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
22
+ import VitePluginCopy from "./vite-plugin-copy.js";
23
+
24
+ export default async function (
25
+ name: string,
26
+ tsConfigPath: string,
27
+ entry?: string | string[] | Record<string, string>,
28
+ ): Promise<UserConfig> {
29
+ console.info(`ViteEsmConfig: ${name}`);
30
+ const projectExternal = await getExternalsFromReferences(tsConfigPath, [
31
+ /dev/,
32
+ ]);
33
+ const allExternal = [
34
+ ...builtinModules,
35
+ ...builtinModules.map((m) => `node:${m}`),
36
+ ...projectExternal,
37
+ // Webpack dependencies - should not be bundled by Vite
38
+ "html-webpack-plugin",
39
+ "mini-css-extract-plugin",
40
+ "node-polyfill-webpack-plugin",
41
+ "terser-webpack-plugin",
42
+ "webpack",
43
+ "webpack-dev-server",
44
+ "webpack-json-access-optimizer",
45
+ "babel-loader",
46
+ "css-loader",
47
+ "string-replace-loader",
48
+ ];
49
+ return defineConfig({
50
+ ssr: { external: allExternal },
51
+ plugins: [
52
+ // @ts-ignore
53
+ noBundlePlugin({
54
+ root: "src",
55
+ copy: "**/*.css",
56
+ }),
57
+ VitePluginCopy({
58
+ srcDir: "src",
59
+ destDir: "dist",
60
+ include: ["**/*.json"],
61
+ }),
62
+ tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }),
63
+ VitePluginCloseAndCopy(),
64
+ ],
65
+ build: {
66
+ emptyOutDir: false,
67
+ ssr: true,
68
+ target: "node24",
69
+ outDir: "dist",
70
+ lib: {
71
+ name,
72
+ formats: ["es"],
73
+ entry: entry || "src/index.ts", // required
74
+ },
75
+ rollupOptions: {
76
+ treeshake: false,
77
+ external: allExternal,
78
+ },
79
+ },
80
+ esbuild: {
81
+ jsx: "automatic",
82
+ // Use standard React JSX for library packages
83
+ // Frontend apps using ViteFrontendConfig will override to Emotion
84
+ jsxDev: process.env.NODE_ENV === "development",
85
+ },
86
+ });
87
+ }
@@ -0,0 +1,265 @@
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 type { UserConfig } from "vite";
25
+ import { nodePolyfills } from "vite-plugin-node-polyfills";
26
+ import { filterDependencies, getDependencies } from "../dependencies.js";
27
+ import { VitePluginCloseAndCopy } from "./index.js";
28
+ import type { ClosePluginOptions } from "./vite-plugin-close-and-copy.js";
29
+
30
+ export default async function (
31
+ packageName: string,
32
+ bundleName: string,
33
+ dir: string,
34
+ entry: string,
35
+ command?: string,
36
+ mode?: string,
37
+ copyOptions?: ClosePluginOptions,
38
+ tsConfigPaths?: string[],
39
+ workspaceRoot?: string,
40
+ ): Promise<UserConfig> {
41
+ // Only development and production modes are allowed
42
+ if (mode !== "production") {
43
+ mode = "development";
44
+ }
45
+ // We don't have a default environment of, for example, `test` so we use the `mode` as the default
46
+ const allowedEnvironments = ["development", "staging", "production"];
47
+ const defaultEnvironment =
48
+ process.env.NODE_ENV && allowedEnvironments.includes(process.env.NODE_ENV)
49
+ ? process.env.NODE_ENV
50
+ : mode;
51
+
52
+ console.info(`Running at ${dir} in ${mode} mode`);
53
+ const isProduction = mode === "production";
54
+ // NODE_ENV must be wrapped in quotes.
55
+ // If NODE_ENV ends up out of sync (one set to development and the other set to production), it causes
56
+ // issues like this: https://github.com/hashicorp/next-mdx-remote/pull/323
57
+ process.env.NODE_ENV = `${process.env.NODE_ENV || mode}`;
58
+ console.info(`NODE_ENV: ${process.env.NODE_ENV}`);
59
+
60
+ // Set the env vars that we want to be available in the browser
61
+ const define = {
62
+ // used to stop websockets package from breaking
63
+ "process.env.WS_NO_BUFFER_UTIL": JSON.stringify("true"),
64
+ "process.env.WS_NO_UTF_8_VALIDATE": JSON.stringify("true"),
65
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
66
+ "process.env.PROSOPO_DEFAULT_ENVIRONMENT":
67
+ JSON.stringify(defaultEnvironment),
68
+ "process.env.PROSOPO_SERVER_URL": JSON.stringify(
69
+ process.env.PROSOPO_SERVER_URL,
70
+ ),
71
+ "process.env._DEV_ONLY_WATCH_EVENTS": JSON.stringify(
72
+ process.env._DEV_ONLY_WATCH_EVENTS,
73
+ ),
74
+ "process.env.PROSOPO_MONGO_EVENTS_URI": JSON.stringify(
75
+ process.env.PROSOPO_MONGO_EVENTS_URI,
76
+ ),
77
+ "process.env.PROSOPO_PACKAGE_VERSION": JSON.stringify(
78
+ process.env.PROSOPO_PACKAGE_VERSION,
79
+ ),
80
+ "process.env.PROSOPO_DOCS_URL": JSON.stringify(
81
+ process.env.PROSOPO_DOCS_URL,
82
+ ),
83
+ "process.env.PROSOPO_LOG_LEVEL": JSON.stringify(
84
+ process.env.PROSOPO_LOG_LEVEL,
85
+ ),
86
+ // only needed if bundling with a site key
87
+ "process.env.PROSOPO_SITE_KEY": JSON.stringify(
88
+ process.env.PROSOPO_SITE_KEY,
89
+ ),
90
+ };
91
+
92
+ console.info(`Env vars: ${JSON.stringify(define, null, 4)}`);
93
+
94
+ // Get all dependencies of the current package
95
+ const { dependencies: deps, optionalPeerDependencies } =
96
+ await getDependencies(packageName, isProduction);
97
+
98
+ // Get rid of any dependencies we don't want to bundle
99
+ const { external, internal } = filterDependencies(deps, [
100
+ "pm2",
101
+ "nodejs-polars",
102
+ "aws",
103
+ "webpack",
104
+ "vite",
105
+ "i18next-fs-backend",
106
+ ]);
107
+
108
+ // Add the node builtins (path, fs, os, etc.) to the external list
109
+ const allExternal = [
110
+ ...builtinModules,
111
+ ...builtinModules.map((m) => `node:${m}`),
112
+ ...external,
113
+ ...optionalPeerDependencies,
114
+ ];
115
+ console.debug(
116
+ `Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`,
117
+ );
118
+
119
+ // Required to print RegExp in console (e.g. alias keys)
120
+ // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
121
+ const proto = RegExp.prototype as any;
122
+ proto.toJSON = RegExp.prototype.toString;
123
+
124
+ // drop console logs if in production mode
125
+ let drop: undefined | Drop[];
126
+ let pure: string[] = [];
127
+ if (isProduction) {
128
+ drop = ["debugger"];
129
+ pure = ["console.log", "console.warn", "console.info", "console.debug"];
130
+ }
131
+
132
+ const rollupExternal: ExternalOption = allExternal;
133
+
134
+ console.info({ bundleName }, "Bundle name");
135
+ return {
136
+ server: {
137
+ host: "127.0.0.1",
138
+ },
139
+ mode: mode || "development",
140
+ optimizeDeps: {
141
+ include: ["node_modules"],
142
+ force: true,
143
+ },
144
+ worker: {
145
+ format: "es",
146
+ },
147
+ esbuild: {
148
+ platform: "browser",
149
+ target: [
150
+ "es2020",
151
+ "chrome60",
152
+ "edge18",
153
+ "firefox60",
154
+ "node24",
155
+ "safari11",
156
+ ],
157
+ drop,
158
+ pure,
159
+ legalComments: "none",
160
+ jsx: "automatic",
161
+ jsxImportSource: "@emotion/react",
162
+ jsxDev: process.env.NODE_ENV === "development",
163
+ },
164
+ define,
165
+
166
+ build: {
167
+ outDir: path.resolve(dir, "dist/bundle"),
168
+ minify: isProduction,
169
+ ssr: false,
170
+ lib: {
171
+ entry: path.resolve(dir, entry),
172
+ name: bundleName,
173
+ fileName: `${bundleName}.bundle.js`,
174
+ formats: ["es"],
175
+ },
176
+ modulePreload: { polyfill: true },
177
+ commonjsOptions: {
178
+ exclude: ["mongodb/*"],
179
+ transformMixedEsModules: true,
180
+ strictRequires: "debug",
181
+ },
182
+
183
+ rollupOptions: {
184
+ treeshake: {
185
+ annotations: false,
186
+ propertyReadSideEffects: false,
187
+ tryCatchDeoptimization: false,
188
+ moduleSideEffects: "no-external", //true,
189
+ preset: "smallest",
190
+ unknownGlobalSideEffects: false,
191
+ },
192
+ experimentalLogSideEffects: false,
193
+ external: rollupExternal,
194
+ watch: false,
195
+
196
+ output: {
197
+ dir: path.resolve(dir, "dist/bundle"),
198
+ entryFileNames: `${bundleName}.bundle.js`,
199
+ },
200
+
201
+ plugins: [
202
+ nodePolyfills({
203
+ include: ["crypto"],
204
+ }),
205
+ // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
206
+ css() as any,
207
+ // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
208
+ wasm() as any,
209
+ // @ts-ignore
210
+ nodeResolve({
211
+ browser: true,
212
+ preferBuiltins: false,
213
+ rootDir: path.resolve(dir, "../../"),
214
+ dedupe: ["react", "react-dom"],
215
+ modulesOnly: true,
216
+ // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
217
+ }) as any,
218
+ // String replacement plugin for fingerprinting code
219
+ {
220
+ name: "string-replace-fingerprint",
221
+ generateBundle(_, bundle) {
222
+ for (const fileName in bundle) {
223
+ const chunk = bundle[fileName];
224
+ if (
225
+ chunk &&
226
+ chunk.type === "chunk" &&
227
+ "code" in chunk &&
228
+ chunk.code
229
+ ) {
230
+ chunk.code = chunk.code.replace(
231
+ /var request = new XMLHttpRequest\(\);\s*request\.open\("get", "https:\/\/m1\.openfpcdn\.io\/fingerprintjs\/v"\.concat\(version, "\/npm-monitoring"\), true\);\s*request\.send\(\);/g,
232
+ "",
233
+ );
234
+ }
235
+ }
236
+ },
237
+ },
238
+ // visualizer({
239
+ // open: true,
240
+ // template: "treemap", //'list',
241
+ // gzipSize: true,
242
+ // brotliSize: true,
243
+ // }),
244
+ // I think we can use this plugin to build all packages instead of relying on the tsc step that's
245
+ // currently a precursor in package.json. However, it fails for the following reason:
246
+ // https://github.com/rollup/plugins/issues/243
247
+ // @ts-ignore
248
+ typescript({
249
+ tsconfig: path.resolve("./tsconfig.json"),
250
+ compilerOptions: { rootDir: path.resolve("./src") },
251
+ outDir: path.resolve(dir, "dist/bundle"),
252
+ }),
253
+ ],
254
+ },
255
+ },
256
+ plugins: [
257
+ // Not sure if we need this plugin or not, it works without it
258
+ // @ts-ignore
259
+ viteReact(),
260
+ // Closes the bundler and copies the bundle to the client-bundle-example project unless we're in serve
261
+ // mode, in which case we don't want to close the bundler because it will close the server
262
+ command !== "serve" ? VitePluginCloseAndCopy(copyOptions) : undefined,
263
+ ],
264
+ };
265
+ }
@@ -0,0 +1,111 @@
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
+ maxParallelFileOps: 1,
77
+ cache: false,
78
+ output: {
79
+ sourcemap: false,
80
+ },
81
+ },
82
+ },
83
+ test: {
84
+ //root: getRootDir(),
85
+ reporters: ["basic"],
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: "forks", // forks is slower than 'threads' but more compatible with low-level libs (e.g. bcrypt)
99
+ poolOptions: {
100
+ forks: {
101
+ isolate: true,
102
+ },
103
+ },
104
+ sequence: {
105
+ shuffle: true,
106
+ },
107
+ testTimeout: 10000,
108
+ },
109
+ plugins: plugins,
110
+ });
111
+ }
@@ -0,0 +1,109 @@
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
+ maxParallelFileOps: 1,
77
+ cache: false,
78
+ output: {
79
+ sourcemap: false,
80
+ },
81
+ },
82
+ },
83
+ test: {
84
+ //root: getRootDir(),
85
+ reporters: ["basic"],
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
+ poolOptions: {
100
+ threads: {
101
+ minThreads: 1,
102
+ maxThreads: 1,
103
+ },
104
+ },
105
+ testTimeout: 10000,
106
+ },
107
+ plugins: plugins,
108
+ });
109
+ }
@@ -0,0 +1,14 @@
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";