@prosopo/config 3.3.1 → 3.3.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.
- package/.turbo/turbo-build$colon$cjs.log +2 -2
- package/.turbo/turbo-build$colon$tsc.log +4 -4
- package/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +11 -0
- package/package.json +5 -4
- package/src/dependencies.ts +246 -0
- package/src/index.ts +16 -0
- package/src/vite/NodejsPolarsDirnamePlugin.ts +45 -0
- package/src/vite/NodejsPolarsNativeFilePlugin.ts +83 -0
- package/src/vite/TsNoCheckPlugin.ts +27 -0
- package/src/vite/index.ts +25 -0
- package/src/vite/types.ts +13 -0
- package/src/vite/vite-plugin-close-and-copy.ts +76 -0
- package/src/vite/vite-plugin-copy.ts +67 -0
- package/src/vite/vite-plugin-fix-absolute-imports.ts +40 -0
- package/src/vite/vite-plugin-remove-unused-translations.ts +128 -0
- package/src/vite/vite-plugin-sourcemap-exclude.ts +36 -0
- package/src/vite/vite.backend.config.ts +148 -0
- package/src/vite/vite.commonjs.config.ts +96 -0
- package/src/vite/vite.esm.config.ts +87 -0
- package/src/vite/vite.frontend.config.ts +265 -0
- package/src/vite/vite.test.config.ts +111 -0
- package/src/vite/vite.threads.test.config.ts +109 -0
- package/src/webpack/index.ts +14 -0
- package/src/webpack/webpack.config.ts +152 -0
- package/tsconfig.cjs.json +9 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
|
@@ -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";
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { builtinModules } from "node:module";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
19
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
20
|
+
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
|
|
21
|
+
import TerserPlugin from "terser-webpack-plugin";
|
|
22
|
+
|
|
23
|
+
const moduleDirs = [path.resolve("./node_modules")];
|
|
24
|
+
|
|
25
|
+
function resolveEntryFile(): string {
|
|
26
|
+
const defaultEntry = "./src/index.tsx";
|
|
27
|
+
const supportedEntries = [defaultEntry, "./src/index.ts"];
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
supportedEntries.find((entry) => fs.existsSync(path.resolve(entry))) ||
|
|
31
|
+
defaultEntry
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const nodeExternals: Record<string, string> = {};
|
|
36
|
+
for (const m of builtinModules) {
|
|
37
|
+
const key = m.indexOf("node:") === -1 ? `node:${m}` : m;
|
|
38
|
+
nodeExternals[key] = `commonjs ${m}`;
|
|
39
|
+
nodeExternals[m] = `commonjs ${m}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default (mode: string) => {
|
|
43
|
+
const isProduction = mode === "production";
|
|
44
|
+
const libraryName = "react_app";
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
resolve: {
|
|
48
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".cjs"],
|
|
49
|
+
extensionAlias: {
|
|
50
|
+
".js": [".js", ".jsx", ".ts", ".tsx"],
|
|
51
|
+
},
|
|
52
|
+
modules: moduleDirs,
|
|
53
|
+
fullySpecified: false,
|
|
54
|
+
alias: {
|
|
55
|
+
"@polkadot/x-textdecoder": path.resolve(
|
|
56
|
+
"../../node_modules/@polkadot/util/node_modules/@polkadot/x-textdecoder",
|
|
57
|
+
),
|
|
58
|
+
"@polkadot/x-textencoder": path.resolve(
|
|
59
|
+
"../../node_modules/@polkadot/util/node_modules/@polkadot/x-textencoder",
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
externals: nodeExternals,
|
|
64
|
+
entry: resolveEntryFile(),
|
|
65
|
+
output: {
|
|
66
|
+
filename: `${libraryName}.[name].bundle.js`,
|
|
67
|
+
path: path.resolve("./dist"),
|
|
68
|
+
publicPath: "/",
|
|
69
|
+
},
|
|
70
|
+
module: {
|
|
71
|
+
rules: [
|
|
72
|
+
// instead of using .babelrc, we can use babel-loader options
|
|
73
|
+
{
|
|
74
|
+
test: /\.(m?js|jsx|tsx|ts)$/,
|
|
75
|
+
exclude: /node_modules/,
|
|
76
|
+
use: {
|
|
77
|
+
loader: "babel-loader",
|
|
78
|
+
options: {
|
|
79
|
+
plugins: [
|
|
80
|
+
"@babel/plugin-transform-runtime",
|
|
81
|
+
"@babel/transform-class-properties",
|
|
82
|
+
"@babel/transform-object-rest-spread",
|
|
83
|
+
"@babel/plugin-transform-react-jsx",
|
|
84
|
+
[
|
|
85
|
+
"@babel/plugin-syntax-import-attributes",
|
|
86
|
+
{ deprecatedAssertSyntax: true },
|
|
87
|
+
],
|
|
88
|
+
],
|
|
89
|
+
presets: ["@babel/preset-env", "@babel/preset-typescript"],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
include: /node_modules|src/,
|
|
95
|
+
test: /\.css$/,
|
|
96
|
+
resolve: {
|
|
97
|
+
fullySpecified: false,
|
|
98
|
+
},
|
|
99
|
+
sideEffects: true,
|
|
100
|
+
use: [
|
|
101
|
+
MiniCssExtractPlugin.loader,
|
|
102
|
+
{
|
|
103
|
+
loader: require.resolve("css-loader"),
|
|
104
|
+
options: {
|
|
105
|
+
url: false,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
test: /locale\.json$/, // match JSON files to optimize
|
|
112
|
+
loader: "webpack-json-access-optimizer",
|
|
113
|
+
},
|
|
114
|
+
// Fix for import.meta.url
|
|
115
|
+
{
|
|
116
|
+
test: /packageInfo.js$/,
|
|
117
|
+
loader: "string-replace-loader",
|
|
118
|
+
options: {
|
|
119
|
+
search: /import\.meta && import\.meta\.url/g,
|
|
120
|
+
replace: "false",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
plugins: [
|
|
127
|
+
new NodePolyfillPlugin(),
|
|
128
|
+
new HtmlWebpackPlugin({
|
|
129
|
+
template: "./src/index.html",
|
|
130
|
+
}),
|
|
131
|
+
new MiniCssExtractPlugin({
|
|
132
|
+
filename: "extr.[contenthash].css",
|
|
133
|
+
}),
|
|
134
|
+
],
|
|
135
|
+
optimization: {
|
|
136
|
+
noEmitOnErrors: true,
|
|
137
|
+
minimize: isProduction,
|
|
138
|
+
minimizer: isProduction
|
|
139
|
+
? [
|
|
140
|
+
new TerserPlugin({
|
|
141
|
+
terserOptions: {
|
|
142
|
+
compress: {
|
|
143
|
+
drop_console: true,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
]
|
|
148
|
+
: [],
|
|
149
|
+
usedExports: true,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.esm.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"types": ["vite/client"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"./src/**/*.ts",
|
|
10
|
+
"./src/**/*.d.ts",
|
|
11
|
+
"./src/**/*.tsx",
|
|
12
|
+
"src/**/*.ts",
|
|
13
|
+
"src/**/*.tsx",
|
|
14
|
+
"src/**/*.json",
|
|
15
|
+
"src/**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|