@prosopo/config 3.4.2 → 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 (57) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +5 -8
  2. package/.turbo/turbo-build$colon$tsc.log +4 -7
  3. package/.turbo/turbo-build.log +6 -12
  4. package/CHANGELOG.md +13 -0
  5. package/LICENSE +201 -0
  6. package/dist/cjs/dependencies.cjs +86 -46
  7. package/dist/cjs/vite/vite.frontend.config.cjs +7 -0
  8. package/dist/cjs/webpack/webpack.config.cjs +8 -8
  9. package/dist/dependencies.d.ts.map +1 -1
  10. package/dist/dependencies.js +85 -44
  11. package/dist/dependencies.js.map +1 -1
  12. package/dist/getDependencies.test.js +151 -125
  13. package/dist/getDependencies.test.js.map +1 -1
  14. package/dist/vite/vite.frontend.config.d.ts.map +1 -1
  15. package/dist/vite/vite.frontend.config.js +8 -1
  16. package/dist/vite/vite.frontend.config.js.map +1 -1
  17. package/dist/webpack/webpack.config.d.ts +2 -0
  18. package/dist/webpack/webpack.config.d.ts.map +1 -1
  19. package/dist/webpack/webpack.config.js +8 -8
  20. package/dist/webpack/webpack.config.js.map +1 -1
  21. package/package.json +106 -103
  22. package/src/dependencies.test.ts +0 -249
  23. package/src/dependencies.ts +0 -259
  24. package/src/getDependencies.test.ts +0 -385
  25. package/src/index.ts +0 -16
  26. package/src/vite/CopyAssetsPlugin.ts +0 -49
  27. package/src/vite/NodejsPolarsDirnamePlugin.ts +0 -50
  28. package/src/vite/NodejsPolarsNativeFilePlugin.ts +0 -105
  29. package/src/vite/TsNoCheckPlugin.ts +0 -31
  30. package/src/vite/bundleConfigs.test.ts +0 -461
  31. package/src/vite/configs.test.ts +0 -223
  32. package/src/vite/index.ts +0 -30
  33. package/src/vite/modifyExportsFiles.test.ts +0 -56
  34. package/src/vite/plugins.test.ts +0 -365
  35. package/src/vite/testFileGlobs.test.ts +0 -162
  36. package/src/vite/testFileGlobs.ts +0 -57
  37. package/src/vite/translations.test.ts +0 -164
  38. package/src/vite/types.ts +0 -13
  39. package/src/vite/vite-plugin-close-and-copy.ts +0 -76
  40. package/src/vite/vite-plugin-copy.ts +0 -67
  41. package/src/vite/vite-plugin-externalize-obfuscator-deadcode.ts +0 -43
  42. package/src/vite/vite-plugin-fix-absolute-imports.ts +0 -40
  43. package/src/vite/vite-plugin-modify-exports-files.ts +0 -64
  44. package/src/vite/vite-plugin-remove-unused-translations.ts +0 -128
  45. package/src/vite/vite-plugin-sourcemap-exclude.ts +0 -36
  46. package/src/vite/vite.backend.config.ts +0 -172
  47. package/src/vite/vite.commonjs.config.ts +0 -98
  48. package/src/vite/vite.esm.config.ts +0 -99
  49. package/src/vite/vite.frontend.config.ts +0 -340
  50. package/src/vite/vite.test.config.ts +0 -115
  51. package/src/vite/vite.threads.test.config.ts +0 -100
  52. package/src/webpack/index.ts +0 -14
  53. package/src/webpack/webpack.config.ts +0 -159
  54. package/tsconfig.cjs.json +0 -9
  55. package/tsconfig.json +0 -17
  56. package/tsconfig.tsbuildinfo +0 -1
  57. package/tsconfig.types.json +0 -9
@@ -1,128 +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
- import fs from "node:fs/promises";
15
- import glob from "fast-glob";
16
- import type { Plugin } from "vite";
17
-
18
- const used = new Set<string>();
19
-
20
- export const flatten = (obj: object, prefix = ""): Record<string, string> => {
21
- const flattenedObj: Record<string, string> = {};
22
- for (const [key, value] of Object.entries(obj)) {
23
- if (value instanceof Object) {
24
- Object.assign(flattenedObj, flatten(value, `${prefix + key}.`));
25
- } else {
26
- flattenedObj[prefix + key] = value;
27
- }
28
- }
29
- return flattenedObj;
30
- };
31
-
32
- type UnflattenObject =
33
- | Record<string, string | number | boolean | undefined>
34
- | string[]
35
- | number[]
36
- | boolean[];
37
-
38
- export const unflatten = (
39
- obj: Record<string, string | number | boolean>,
40
- ): Record<string, string | number | boolean | UnflattenObject> => {
41
- const result: Record<string, string | number | boolean | UnflattenObject> =
42
- {};
43
-
44
- for (const [key, value] of Object.entries(obj)) {
45
- const keys = key.split(".");
46
- keys.reduce((acc, k, i) => {
47
- if (i === keys.length - 1) {
48
- (acc as Record<string, string | number | boolean | UnflattenObject>)[
49
- k
50
- ] = value;
51
- } else {
52
- if (!acc[k]) {
53
- acc[k] = Number.isNaN(Number(keys[i + 1])) ? {} : [];
54
- }
55
- }
56
- return acc[k] as Record<
57
- string,
58
- string | number | boolean | UnflattenObject
59
- >;
60
- }, result);
61
- }
62
-
63
- return result;
64
- };
65
-
66
- export default function VitePluginRemoveUnusedTranslations(
67
- translationKeys: string[],
68
- jsonPattern: string,
69
- ): Plugin {
70
- return {
71
- name: "remove-unused-translations",
72
- transform(code: string) {
73
- // Collect translation keys used in the source files
74
- for (const key of translationKeys) {
75
- if (code.includes(key) && !used.has(key)) {
76
- console.info(`Found key: ${key}`);
77
- used.add(key);
78
- }
79
- }
80
- return { code };
81
- },
82
- enforce: "post",
83
-
84
- async writeBundle() {
85
- // Find all matching JSON files
86
- const jsonFiles = await glob(jsonPattern, { absolute: true });
87
-
88
- console.info(`Found ${jsonFiles.length} JSON files at ${jsonPattern}`);
89
-
90
- const filePromises = [];
91
- for (const filePath of jsonFiles) {
92
- try {
93
- const content = await fs.readFile(filePath, "utf-8");
94
- const jsonData = JSON.parse(content);
95
- const jsonDataFlattened = flatten(jsonData);
96
-
97
- // Remove keys that are not in `used`
98
- const filteredData = Object.fromEntries(
99
- Object.entries(jsonDataFlattened).filter(([key]) => used.has(key)),
100
- );
101
-
102
- const unflattened = unflatten(filteredData);
103
-
104
- // log.info(unflattened);
105
-
106
- // Write back the filtered JSON
107
- filePromises.push(
108
- fs
109
- .writeFile(
110
- filePath,
111
- JSON.stringify(unflattened, null, 2),
112
- "utf-8",
113
- )
114
- .then(() => {
115
- console.info(`Updated ${filePath}`);
116
- })
117
- .catch((e) => {
118
- console.error(`Failed to update ${filePath}:`, e);
119
- }),
120
- );
121
- } catch (error: unknown) {
122
- console.error(`Failed to process ${filePath}:`, error);
123
- }
124
- }
125
- await Promise.all(filePromises);
126
- },
127
- };
128
- }
@@ -1,36 +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
- import type { Plugin } from "vite";
15
-
16
- interface SourcemapExclude {
17
- excludeNodeModules?: boolean;
18
- }
19
- // Taken from https://github.com/vitejs/vite/issues/2433#issuecomment-1487472995 to prevent memory leaks
20
- export default function VitePluginSourcemapExclude(
21
- opts?: SourcemapExclude,
22
- ): Plugin {
23
- return {
24
- name: "sourcemap-exclude",
25
- transform(code: string, id: string) {
26
- if (opts?.excludeNodeModules && id.includes("node_modules")) {
27
- return {
28
- code,
29
- // https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
30
- map: { mappings: "" },
31
- };
32
- }
33
- return;
34
- },
35
- };
36
- }
@@ -1,172 +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 { wasm } from "@rollup/plugin-wasm";
18
- import type { Drop } from "esbuild";
19
- import css from "rollup-plugin-import-css";
20
- import type { UserConfig } from "vite";
21
- import { filterDependencies, getDependencies } from "../dependencies.js";
22
- import { default as ClosePlugin } from "./vite-plugin-close-and-copy.js";
23
- import VitePluginExternalizeObfuscatorDeadCode from "./vite-plugin-externalize-obfuscator-deadcode.js";
24
- import VitePluginFixAbsoluteImports from "./vite-plugin-fix-absolute-imports.js";
25
-
26
- export default async function (
27
- packageName: string,
28
- packageVersion: string,
29
- bundleName: string,
30
- packageDir: string,
31
- entry: string | string[] | Record<string, string>,
32
- command?: string,
33
- mode?: string,
34
- outputDir?: string,
35
- ): Promise<UserConfig> {
36
- const isProduction = mode === "production";
37
-
38
- // Get all dependencies of the current package
39
- const { dependencies: deps, optionalPeerDependencies } =
40
- await getDependencies(packageName, true);
41
-
42
- // Output directory is custom or relative to directory of the package
43
- const outDir = outputDir
44
- ? path.resolve(outputDir)
45
- : path.resolve(packageDir, "dist/bundle");
46
-
47
- // Get rid of any dependencies we don't want to bundle. `sharp` is a
48
- // native module — bundling its JS shim but not the platform-specific
49
- // binary in `@img/sharp-linux-x64/lib/sharp-linux-x64.node` produces a
50
- // runtime "Could not load the sharp module" in the provider Docker
51
- // image, so it stays external and is installed at container-build time
52
- // via the generated package.json in docker/images/provider/dist/.
53
- const { external, internal } = filterDependencies(deps, [
54
- "aws",
55
- "webpack",
56
- "vite",
57
- "biome",
58
- "sharp",
59
- "@img/",
60
- ]);
61
-
62
- // `punycode` is a deprecated Node builtin that the userland npm package
63
- // shadows. Rolldown prefix-matches string externals, so listing the builtin
64
- // also externalises deep imports like "punycode/punycode.es6.js" (which
65
- // uri-js pulls in). Rollup did not, so this only bites under Vite 8. The
66
- // provider image ships the bundle with no node_modules, so an external
67
- // subpath is an immediate "Cannot find module" at boot. Bare "punycode"
68
- // stays external via the node: alias below.
69
- const bundledBuiltins = builtinModules.filter((m) => m !== "punycode");
70
-
71
- // Add the node builtins (path, fs, os, etc.) to the external list
72
- const allExternal = [
73
- ...bundledBuiltins,
74
- ...builtinModules.map((m) => `node:${m}`),
75
- ...external,
76
- ...optionalPeerDependencies,
77
- ];
78
-
79
- console.info(
80
- `Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`,
81
- );
82
-
83
- const define = {
84
- "process.env.WS_NO_BUFFER_UTIL": "true",
85
- "process.env.WS_NO_UTF_8_VALIDATE": "true",
86
- "process.env.PROSOPO_PACKAGE_VERSION": JSON.stringify(packageVersion),
87
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
88
- ...(process.env.PROSOPO_DEFAULT_ENVIRONMENT && {
89
- "process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
90
- process.env.PROSOPO_DEFAULT_ENVIRONMENT,
91
- ),
92
- }),
93
- };
94
-
95
- console.info(`Defined vars ${JSON.stringify(define, null, 2)}`);
96
-
97
- let entriesAbsolute: string[];
98
- if (typeof entry === "string") {
99
- entriesAbsolute = [path.resolve(packageDir, entry)];
100
- } else if (Array.isArray(entry)) {
101
- entriesAbsolute = entry.map((e) => path.resolve(packageDir, e));
102
- } else {
103
- entriesAbsolute = Object.fromEntries(
104
- Object.entries(entry).map(([key, value]) => [
105
- key,
106
- path.resolve(packageDir, value),
107
- ]),
108
- ) as unknown as string[];
109
- }
110
-
111
- // drop console logs if in production mode
112
- const drop: Drop[] | undefined =
113
- mode === "production" ? ["console", "debugger"] : undefined;
114
-
115
- return {
116
- ssr: {
117
- noExternal: true,
118
- external: allExternal,
119
- },
120
- optimizeDeps: {
121
- include: ["linked-dep", "node_modules"],
122
- esbuildOptions: {
123
- loader: {
124
- ".node": "file",
125
- },
126
- },
127
- },
128
- esbuild: {
129
- platform: "node",
130
- target: "node24",
131
- // drop,
132
- legalComments: "none",
133
- },
134
- define,
135
- build: {
136
- outDir,
137
- minify: isProduction,
138
- ssr: true,
139
- target: "node24",
140
- lib: {
141
- entry: entriesAbsolute,
142
- name: bundleName,
143
- fileName: `${bundleName}.[name].bundle.js`,
144
- formats: ["es"],
145
- },
146
- modulePreload: { polyfill: false },
147
- rollupOptions: {
148
- treeshake: {
149
- // Rolldown has no `preset` support, so Rollup's "smallest" could
150
- // not be carried over. Honouring pure annotations recovers part
151
- // of that without the risk of moduleSideEffects: false.
152
- annotations: true,
153
- moduleSideEffects: true,
154
- },
155
- external: allExternal,
156
- watch: false,
157
- output: {
158
- entryFileNames: `${bundleName}.[name].bundle.js`,
159
- },
160
- // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
161
- plugins: [css() as any, wasm() as any],
162
- },
163
- },
164
- plugins: [
165
- VitePluginExternalizeObfuscatorDeadCode(),
166
- // plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
167
- VitePluginFixAbsoluteImports(),
168
- // plugin to close the bundle after build if not in serve mode
169
- command !== "serve" ? ClosePlugin() : undefined,
170
- ],
171
- };
172
- }
@@ -1,98 +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 { 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
- import VitePluginExternalizeObfuscatorDeadCode from "./vite-plugin-externalize-obfuscator-deadcode.js";
24
-
25
- export default async function (
26
- name: string,
27
- tsConfigPath: string,
28
- entry?: string | string[] | Record<string, string>,
29
- ): Promise<UserConfig> {
30
- console.info(`ViteCommonJSConfig: ${name}`);
31
- const projectExternal = await getExternalsFromReferences(tsConfigPath, [
32
- /dev/,
33
- ]);
34
- const allExternal = [
35
- ...builtinModules,
36
- ...builtinModules.map((m) => `node:${m}`),
37
- ...projectExternal,
38
- ];
39
- return defineConfig({
40
- ssr: { external: allExternal },
41
- plugins: [
42
- VitePluginExternalizeObfuscatorDeadCode(),
43
- // @ts-ignore
44
- {
45
- name: "string-replace-import.meta.url",
46
- generateBundle(_, bundle) {
47
- for (const fileName in bundle) {
48
- const chunk = bundle[fileName];
49
- if (
50
- chunk &&
51
- chunk.type === "chunk" &&
52
- "code" in chunk &&
53
- chunk.code
54
- ) {
55
- chunk.code = chunk.code.replace(
56
- /import\.meta\.url/g,
57
- "require('url').pathToFileURL(__filename).href",
58
- );
59
- }
60
- }
61
- },
62
- },
63
- // @ts-ignore
64
- noBundlePlugin({
65
- root: "src",
66
- copy: "**/*.css",
67
- }),
68
- VitePluginCopy({
69
- srcDir: "src",
70
- destDir: "dist",
71
- include: ["**/*.json"],
72
- }),
73
- tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }),
74
- VitePluginCloseAndCopy(),
75
- ],
76
- build: {
77
- emptyOutDir: false,
78
- ssr: true,
79
- target: "node24",
80
- outDir: "dist/cjs",
81
- lib: {
82
- name,
83
- formats: ["cjs"],
84
- entry: entry || "src/index.ts", // required
85
- },
86
- rollupOptions: {
87
- treeshake: false,
88
- external: allExternal,
89
- },
90
- },
91
- esbuild: {
92
- jsx: "automatic",
93
- // Use standard React JSX for library packages
94
- // Frontend apps using ViteFrontendConfig will override to Emotion
95
- jsxDev: process.env.NODE_ENV === "development",
96
- },
97
- });
98
- }
@@ -1,99 +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 { 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
- import VitePluginExternalizeObfuscatorDeadCode from "./vite-plugin-externalize-obfuscator-deadcode.js";
24
-
25
- export default async function (
26
- name: string,
27
- tsConfigPath: string,
28
- entry?: string | string[] | Record<string, string>,
29
- ): Promise<UserConfig> {
30
- console.info(`ViteEsmConfig: ${name}`);
31
- const projectExternal = await getExternalsFromReferences(tsConfigPath, [
32
- /dev/,
33
- ]);
34
- const allExternal = [
35
- ...builtinModules,
36
- ...builtinModules.map((m) => `node:${m}`),
37
- ...projectExternal,
38
- // Webpack dependencies - should not be bundled by Vite
39
- "html-webpack-plugin",
40
- "mini-css-extract-plugin",
41
- "node-polyfill-webpack-plugin",
42
- "terser-webpack-plugin",
43
- "webpack",
44
- "webpack-dev-server",
45
- "webpack-json-access-optimizer",
46
- "babel-loader",
47
- "css-loader",
48
- "string-replace-loader",
49
- ];
50
- return defineConfig({
51
- ssr: { external: allExternal },
52
- plugins: [
53
- VitePluginExternalizeObfuscatorDeadCode(),
54
- // @ts-ignore
55
- noBundlePlugin({
56
- root: "src",
57
- copy: "**/*.css",
58
- }),
59
- VitePluginCopy({
60
- srcDir: "src",
61
- destDir: "dist",
62
- include: ["**/*.json"],
63
- }),
64
- tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }),
65
- VitePluginCloseAndCopy(),
66
- ],
67
- build: {
68
- emptyOutDir: false,
69
- ssr: true,
70
- target: "node24",
71
- outDir: "dist",
72
- lib: {
73
- name,
74
- formats: ["es"],
75
- entry: entry || "src/index.ts", // required
76
- },
77
- rollupOptions: {
78
- treeshake: false,
79
- external: allExternal,
80
- output: {
81
- // Rolldown otherwise emits a CJS-interop runtime that does
82
- // `createRequire(import.meta.url)` from "node:module" at module
83
- // scope. That is fatal in a browser: anything importing such a
84
- // package (e.g. catcher-demo importing @prosopo/util) dies with
85
- // 'Module "node:module" has been externalized for browser
86
- // compatibility' before React can mount. Rollup emitted no such
87
- // runtime, so this only bites under Vite 8.
88
- polyfillRequire: false,
89
- },
90
- },
91
- },
92
- esbuild: {
93
- jsx: "automatic",
94
- // Use standard React JSX for library packages
95
- // Frontend apps using ViteFrontendConfig will override to Emotion
96
- jsxDev: process.env.NODE_ENV === "development",
97
- },
98
- });
99
- }