@prosopo/config 3.1.3 → 3.1.21

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 (63) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/cjs/dependencies.cjs +156 -0
  3. package/dist/cjs/index.cjs +33 -0
  4. package/dist/cjs/vite/TsNoCheckPlugin.cjs +18 -0
  5. package/dist/cjs/vite/index.cjs +26 -0
  6. package/dist/cjs/vite/vite-plugin-close-and-copy.cjs +46 -0
  7. package/dist/cjs/vite/vite-plugin-copy.cjs +42 -0
  8. package/dist/cjs/vite/vite-plugin-fix-absolute-imports.cjs +26 -0
  9. package/dist/cjs/vite/vite-plugin-remove-unused-translations.cjs +81 -0
  10. package/dist/cjs/vite/vite-plugin-sourcemap-exclude.cjs +17 -0
  11. package/dist/cjs/vite/vite.backend.config.cjs +99 -0
  12. package/dist/cjs/vite/vite.commonjs.config.cjs +65 -0
  13. package/dist/cjs/vite/vite.esm.config.cjs +70 -0
  14. package/dist/cjs/vite/vite.frontend.config.cjs +203 -0
  15. package/dist/cjs/vite/vite.test.config.cjs +78 -0
  16. package/dist/cjs/vite/vite.threads.test.config.cjs +79 -0
  17. package/dist/cjs/webpack/index.cjs +2 -0
  18. package/dist/cjs/webpack/webpack.config.cjs +149 -0
  19. package/dist/dependencies.d.ts.map +1 -1
  20. package/dist/dependencies.js +7 -6
  21. package/dist/index.js +18 -16
  22. package/dist/vite/index.d.ts +1 -0
  23. package/dist/vite/index.d.ts.map +1 -1
  24. package/dist/vite/index.js +18 -16
  25. package/dist/vite/vite.backend.config.d.ts.map +1 -1
  26. package/dist/vite/vite.backend.config.js +1 -0
  27. package/dist/vite/vite.commonjs.config.d.ts +1 -1
  28. package/dist/vite/vite.commonjs.config.d.ts.map +1 -1
  29. package/dist/vite/vite.commonjs.config.js +5 -0
  30. package/dist/vite/vite.esm.config.d.ts +1 -1
  31. package/dist/vite/vite.esm.config.d.ts.map +1 -1
  32. package/dist/vite/vite.esm.config.js +17 -1
  33. package/dist/vite/vite.frontend.config.d.ts.map +1 -1
  34. package/dist/vite/vite.frontend.config.js +22 -1
  35. package/dist/vite/vite.test.config.d.ts.map +1 -1
  36. package/dist/vite/vite.test.config.js +26 -7
  37. package/dist/vite/vite.threads.test.config.d.ts +2 -0
  38. package/dist/vite/vite.threads.test.config.d.ts.map +1 -0
  39. package/dist/vite/vite.threads.test.config.js +80 -0
  40. package/package.json +27 -30
  41. package/vite.cjs.config.ts +22 -0
  42. package/dist/dependencies.js.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/vite/NodejsPolarsDirnamePlugin.js +0 -22
  45. package/dist/vite/NodejsPolarsDirnamePlugin.js.map +0 -1
  46. package/dist/vite/NodejsPolarsNativeFilePlugin.js +0 -58
  47. package/dist/vite/NodejsPolarsNativeFilePlugin.js.map +0 -1
  48. package/dist/vite/TsNoCheckPlugin.js.map +0 -1
  49. package/dist/vite/index.js.map +0 -1
  50. package/dist/vite/types.js +0 -2
  51. package/dist/vite/types.js.map +0 -1
  52. package/dist/vite/vite-plugin-close-and-copy.js.map +0 -1
  53. package/dist/vite/vite-plugin-copy.js.map +0 -1
  54. package/dist/vite/vite-plugin-fix-absolute-imports.js.map +0 -1
  55. package/dist/vite/vite-plugin-remove-unused-translations.js.map +0 -1
  56. package/dist/vite/vite-plugin-sourcemap-exclude.js.map +0 -1
  57. package/dist/vite/vite.backend.config.js.map +0 -1
  58. package/dist/vite/vite.commonjs.config.js.map +0 -1
  59. package/dist/vite/vite.esm.config.js.map +0 -1
  60. package/dist/vite/vite.frontend.config.js.map +0 -1
  61. package/dist/vite/vite.test.config.js.map +0 -1
  62. package/dist/webpack/index.js.map +0 -1
  63. package/dist/webpack/webpack.config.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,101 @@
1
1
  # @prosopo/config
2
2
 
3
+ ## 3.1.21
4
+ ### Patch Changes
5
+
6
+ - b8185a4: feat/uap-rules-syncer
7
+
8
+ ## 3.1.20
9
+ ### Patch Changes
10
+
11
+ - 1e3a838: making webpack stuff external in vite config
12
+
13
+ ## 3.1.19
14
+ ### Patch Changes
15
+
16
+ - 5659b24: Release 3.4.4
17
+
18
+ ## 3.1.18
19
+ ### Patch Changes
20
+
21
+ - 50c4120: Release 3.4.3
22
+
23
+ ## 3.1.17
24
+ ### Patch Changes
25
+
26
+ - 618703f: Release 3.4.2
27
+
28
+ ## 3.1.16
29
+ ### Patch Changes
30
+
31
+ - 11303d9: Release 3.4.0
32
+ - 18cb28b: Release 3.4.1
33
+
34
+ ## 3.1.15
35
+ ### Patch Changes
36
+
37
+ - f3f7aec: Release 3.4.0
38
+
39
+ ## 3.1.14
40
+ ### Patch Changes
41
+
42
+ - Release 3.3.1
43
+ - 0824221: Release 3.2.4
44
+
45
+ ## 3.1.13
46
+ ### Patch Changes
47
+
48
+ - 008d112: Release 3.3.0
49
+
50
+ ## 3.1.12
51
+ ### Patch Changes
52
+
53
+ - 0824221: Release 3.2.4
54
+
55
+ ## 3.1.11
56
+ ### Patch Changes
57
+
58
+ - 1a23649: Release 3.2.3
59
+
60
+ ## 3.1.10
61
+ ### Patch Changes
62
+
63
+ - 657a827: Release 3.2.2
64
+
65
+ ## 3.1.9
66
+ ### Patch Changes
67
+
68
+ - 4440947: fix type-only tsc compilation
69
+ - 7bdaca6: Release 3.2.1
70
+ - 809b984: make vite set esbuild jsx config based on env
71
+ - 809b984: set jsx config for esbuild from vite configs to avoid jsxDEV import bug
72
+
73
+ ## 3.1.8
74
+ ### Patch Changes
75
+
76
+ - 6fe8570: Release 3.2.0
77
+
78
+ ## 3.1.7
79
+ ### Patch Changes
80
+
81
+ - f304be9: Release 3.1.13
82
+
83
+ ## 3.1.6
84
+ ### Patch Changes
85
+
86
+ - 9eed772: Release 3.1.12
87
+
88
+ ## 3.1.5
89
+ ### Patch Changes
90
+
91
+ - 30e7d4d: Fixing coverage report and more damn linting
92
+
93
+ ## 3.1.4
94
+ ### Patch Changes
95
+
96
+ - 44ffda2: Dropping monitoring calls
97
+ - a49b538: Extra tests
98
+
3
99
  ## 3.1.3
4
100
  ### Patch Changes
5
101
 
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const child_process = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+ const util = require("node:util");
7
+ const exec = util.promisify(child_process.exec);
8
+ const tsConfigRegex = /\/[A-Za-z.]*\.json$/;
9
+ const peerDepsRegex = /UNMET\sOPTIONAL\sDEPENDENCY\s+(@*[\w\-/.]+)@/;
10
+ const depsRegex = /\s+(@*[\w\-/.]+)@/;
11
+ async function getPackageDir(packageName) {
12
+ let pkg = packageName;
13
+ if (packageName && !packageName.startsWith("@prosopo/")) {
14
+ pkg = `@prosopo/${packageName}`;
15
+ }
16
+ const pkgCommand = `npm list ${pkg} -ap`;
17
+ console.info(`Running command ${pkgCommand}`);
18
+ const { stdout: packageDir, stderr } = await exec(pkgCommand);
19
+ if (stderr) {
20
+ if (stderr.includes("ERR!")) {
21
+ throw new Error("CONFIG.INVALID_PACKAGE_DIR");
22
+ }
23
+ }
24
+ return packageDir.trim() || path.resolve();
25
+ }
26
+ function getReferenceTsConfigPath(initialTsConfigPath, reference) {
27
+ let refTSConfigPath = path.resolve(
28
+ initialTsConfigPath.replace(tsConfigRegex, ""),
29
+ reference.path
30
+ );
31
+ if (!refTSConfigPath.endsWith(".json")) {
32
+ refTSConfigPath = path.resolve(refTSConfigPath, "tsconfig.json");
33
+ }
34
+ return refTSConfigPath;
35
+ }
36
+ function getTsConfigs(tsConfigPath, ignorePatterns = [], tsConfigPaths = [], includeInitialTsConfig = true) {
37
+ let tsConfigs = [...tsConfigPaths];
38
+ const references = JSON.parse(
39
+ fs.readFileSync(tsConfigPath).toString()
40
+ ).references;
41
+ if (!tsConfigs.includes(tsConfigPath)) {
42
+ if (references) {
43
+ const ignore = ignorePatterns && ignorePatterns.length > 0 ? new RegExp(`${ignorePatterns.join("|")}`) : void 0;
44
+ if (includeInitialTsConfig) {
45
+ tsConfigs.push(tsConfigPath);
46
+ }
47
+ const filteredReferences = references.filter(
48
+ (reference) => ignore ? !ignore.test(reference.path) : false
49
+ );
50
+ for (const reference of filteredReferences) {
51
+ const refTSConfigPath = getReferenceTsConfigPath(
52
+ tsConfigPath,
53
+ reference
54
+ );
55
+ const newTsConfigs = getTsConfigs(
56
+ refTSConfigPath,
57
+ ignorePatterns,
58
+ tsConfigs
59
+ );
60
+ if (newTsConfigs.length > 0) {
61
+ const distinctTsConfigPaths = new Set(tsConfigs.concat(newTsConfigs));
62
+ tsConfigs = [...distinctTsConfigPaths];
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return tsConfigs;
68
+ }
69
+ async function getExternalsFromReferences(tsConfigPath, ignorePatterns = []) {
70
+ const tsConfigPaths = getTsConfigs(tsConfigPath, ignorePatterns, [], false);
71
+ console.debug({ tsConfigPaths });
72
+ const promises = [];
73
+ for (const refTsConfigPath of tsConfigPaths) {
74
+ const packageJsonPath = path.resolve(
75
+ refTsConfigPath.replace(tsConfigRegex, ""),
76
+ "package.json"
77
+ );
78
+ promises.push(
79
+ new Promise((resolve, reject) => {
80
+ fs.stat(packageJsonPath, (err) => {
81
+ if (err) {
82
+ reject(err);
83
+ }
84
+ fs.readFile(
85
+ new URL(packageJsonPath, module),
86
+ (err2, buffer) => {
87
+ if (err2) {
88
+ reject(err2);
89
+ } else {
90
+ const packageJson = JSON.parse(buffer.toString());
91
+ const pkg = packageJson.name;
92
+ resolve(pkg);
93
+ }
94
+ }
95
+ );
96
+ });
97
+ })
98
+ );
99
+ }
100
+ const externals = await Promise.all(promises);
101
+ console.debug({ externals });
102
+ return externals;
103
+ }
104
+ async function getDependencies(packageName, production) {
105
+ let cmd = production ? "npm ls -a --silent --omit=dev --package-lock-only" : "npm ls --silent -a --package-lock-only";
106
+ if (packageName) {
107
+ const packageDir = await getPackageDir(packageName);
108
+ cmd = `cd ${packageDir.trim()} && ${cmd}`;
109
+ console.info(`Running command ${cmd} in ${packageDir}`);
110
+ }
111
+ let concat = "";
112
+ const { stdout, stderr } = await exec(cmd);
113
+ concat = stdout + stderr;
114
+ let deps = [];
115
+ let peerDeps = [];
116
+ for (const line of concat.split("\n")) {
117
+ if (line.includes("UNMET OPTIONAL DEPENDENCY")) {
118
+ const parts = line.match(peerDepsRegex);
119
+ if (parts && parts.length > 1) {
120
+ peerDeps.push(parts[1]);
121
+ }
122
+ } else {
123
+ const parts = line.match(depsRegex);
124
+ if (parts && parts.length > 1) {
125
+ deps.push(parts[1]);
126
+ }
127
+ }
128
+ }
129
+ deps = [...new Set(deps)];
130
+ peerDeps = [...new Set(peerDeps)];
131
+ return {
132
+ dependencies: deps.filter((x, i) => i === deps.indexOf(x)),
133
+ optionalPeerDependencies: peerDeps.filter(
134
+ (x, i) => i === peerDeps.indexOf(x)
135
+ )
136
+ };
137
+ }
138
+ function filterDependencies(deps, filters) {
139
+ const depsDeduped = deps.filter((x, i) => i === deps.indexOf(x));
140
+ const depsWithLength = depsDeduped.filter((dep) => dep.length > 0).sort();
141
+ const exclude = new RegExp(`${filters.join("|")}`);
142
+ const internal = [];
143
+ const external = [];
144
+ for (const dep of depsWithLength) {
145
+ if (exclude.test(dep)) {
146
+ external.push(dep);
147
+ } else {
148
+ internal.push(dep);
149
+ }
150
+ }
151
+ return { internal, external };
152
+ }
153
+ exports.filterDependencies = filterDependencies;
154
+ exports.getDependencies = getDependencies;
155
+ exports.getExternalsFromReferences = getExternalsFromReferences;
156
+ exports.getTsConfigs = getTsConfigs;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./vite/index.cjs");
4
+ const dependencies = require("./dependencies.cjs");
5
+ require("./webpack/index.cjs");
6
+ const vitePluginCloseAndCopy = require("./vite/vite-plugin-close-and-copy.cjs");
7
+ const vite_test_config = require("./vite/vite.test.config.cjs");
8
+ const vite_threads_test_config = require("./vite/vite.threads.test.config.cjs");
9
+ const vitePluginSourcemapExclude = require("./vite/vite-plugin-sourcemap-exclude.cjs");
10
+ const vite_frontend_config = require("./vite/vite.frontend.config.cjs");
11
+ const vite_backend_config = require("./vite/vite.backend.config.cjs");
12
+ const vitePluginFixAbsoluteImports = require("./vite/vite-plugin-fix-absolute-imports.cjs");
13
+ const vite_commonjs_config = require("./vite/vite.commonjs.config.cjs");
14
+ const vite_esm_config = require("./vite/vite.esm.config.cjs");
15
+ const vitePluginRemoveUnusedTranslations = require("./vite/vite-plugin-remove-unused-translations.cjs");
16
+ const vitePluginCopy = require("./vite/vite-plugin-copy.cjs");
17
+ const TsNoCheckPlugin = require("./vite/TsNoCheckPlugin.cjs");
18
+ exports.filterDependencies = dependencies.filterDependencies;
19
+ exports.getDependencies = dependencies.getDependencies;
20
+ exports.getExternalsFromReferences = dependencies.getExternalsFromReferences;
21
+ exports.getTsConfigs = dependencies.getTsConfigs;
22
+ exports.VitePluginCloseAndCopy = vitePluginCloseAndCopy;
23
+ exports.ViteTestConfig = vite_test_config;
24
+ exports.ViteThreadsTestConfig = vite_threads_test_config;
25
+ exports.VitePluginSourceMapExclude = vitePluginSourcemapExclude;
26
+ exports.ViteFrontendConfig = vite_frontend_config;
27
+ exports.ViteBackendConfig = vite_backend_config;
28
+ exports.VitePluginFixAbsoluteImports = vitePluginFixAbsoluteImports;
29
+ exports.ViteCommonJSConfig = vite_commonjs_config;
30
+ exports.ViteEsmConfig = vite_esm_config;
31
+ exports.VitePluginRemoveUnusedTranslations = vitePluginRemoveUnusedTranslations.default;
32
+ exports.VitePluginCopy = vitePluginCopy;
33
+ exports.tsNoCheckPlugin = TsNoCheckPlugin.tsNoCheckPlugin;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function tsNoCheckPlugin() {
4
+ return {
5
+ name: "vite-plugin-ts-nocheck",
6
+ // biome-ignore lint/suspicious/noExplicitAny: TODO not sure of options/bundle type (same as NodejsPolarsNativeFilePlugin)
7
+ generateBundle(_, bundle) {
8
+ for (const fileName in bundle) {
9
+ const chunk = bundle[fileName];
10
+ if (chunk.type === "chunk" && chunk.code) {
11
+ chunk.code = `// @ts-nocheck
12
+ ${chunk.code}`;
13
+ }
14
+ }
15
+ }
16
+ };
17
+ }
18
+ exports.tsNoCheckPlugin = tsNoCheckPlugin;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vitePluginCloseAndCopy = require("./vite-plugin-close-and-copy.cjs");
4
+ const vite_test_config = require("./vite.test.config.cjs");
5
+ const vite_threads_test_config = require("./vite.threads.test.config.cjs");
6
+ const vitePluginSourcemapExclude = require("./vite-plugin-sourcemap-exclude.cjs");
7
+ const vite_frontend_config = require("./vite.frontend.config.cjs");
8
+ const vite_backend_config = require("./vite.backend.config.cjs");
9
+ const vitePluginFixAbsoluteImports = require("./vite-plugin-fix-absolute-imports.cjs");
10
+ const vite_commonjs_config = require("./vite.commonjs.config.cjs");
11
+ const vite_esm_config = require("./vite.esm.config.cjs");
12
+ const vitePluginRemoveUnusedTranslations = require("./vite-plugin-remove-unused-translations.cjs");
13
+ const TsNoCheckPlugin = require("./TsNoCheckPlugin.cjs");
14
+ const vitePluginCopy = require("./vite-plugin-copy.cjs");
15
+ exports.VitePluginCloseAndCopy = vitePluginCloseAndCopy;
16
+ exports.ViteTestConfig = vite_test_config;
17
+ exports.ViteThreadsTestConfig = vite_threads_test_config;
18
+ exports.VitePluginSourceMapExclude = vitePluginSourcemapExclude;
19
+ exports.ViteFrontendConfig = vite_frontend_config;
20
+ exports.ViteBackendConfig = vite_backend_config;
21
+ exports.VitePluginFixAbsoluteImports = vitePluginFixAbsoluteImports;
22
+ exports.ViteCommonJSConfig = vite_commonjs_config;
23
+ exports.ViteEsmConfig = vite_esm_config;
24
+ exports.VitePluginRemoveUnusedTranslations = vitePluginRemoveUnusedTranslations.default;
25
+ exports.tsNoCheckPlugin = TsNoCheckPlugin.tsNoCheckPlugin;
26
+ exports.VitePluginCopy = vitePluginCopy;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+ function VitePluginCloseAndCopy(options) {
5
+ const __dirname = path.resolve();
6
+ return {
7
+ name: "close-plugin",
8
+ // required, will show up in warnings and errors
9
+ buildStart() {
10
+ console.info("Bundle build started");
11
+ },
12
+ buildEnd(error) {
13
+ console.info("Build end");
14
+ if (error) {
15
+ console.log(error);
16
+ console.error(error);
17
+ }
18
+ },
19
+ closeBundle() {
20
+ if (options) {
21
+ for (const destDir of options.destDir) {
22
+ clearOutputDirJS(__dirname, destDir);
23
+ console.info(`Bundle cleared from ${options.destDir}`);
24
+ copyBundle(__dirname, options.srcDir, destDir);
25
+ console.info(`Bundle copied to ${options.destDir}`);
26
+ }
27
+ console.info("Bundle closed");
28
+ }
29
+ }
30
+ };
31
+ }
32
+ const clearOutputDirJS = (__dirname, destDir) => fs.readdirSync(path.resolve(__dirname, destDir)).filter((file) => file.endsWith("js")).map((file) => {
33
+ fs.rmSync(path.resolve(__dirname, destDir, file));
34
+ });
35
+ const copyBundle = (__dirname, srcDir, destDir) => {
36
+ console.info(
37
+ "Copying",
38
+ path.resolve(__dirname, srcDir),
39
+ "to",
40
+ path.resolve(__dirname, destDir)
41
+ );
42
+ fs.cpSync(path.resolve(__dirname, srcDir), path.resolve(__dirname, destDir), {
43
+ recursive: true
44
+ });
45
+ };
46
+ module.exports = VitePluginCloseAndCopy;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+ const fg = require("fast-glob");
5
+ function ensureDirExists(filePath) {
6
+ const dir = path.dirname(filePath);
7
+ if (!fs.existsSync(dir)) {
8
+ fs.mkdirSync(dir, { recursive: true });
9
+ }
10
+ }
11
+ function VitePluginCopy(options) {
12
+ const __dirname = path.resolve();
13
+ return {
14
+ name: "copy-plugin",
15
+ async closeBundle() {
16
+ const srcAbs = path.resolve(__dirname, options.srcDir);
17
+ const destAbs = path.resolve(__dirname, options.destDir);
18
+ const include = options.include && options.include.length > 0 ? options.include : void 0;
19
+ const exclude = options.exclude || [];
20
+ if (!include) {
21
+ console.info(
22
+ "[copy-plugin] No include globs specified, nothing to copy."
23
+ );
24
+ return;
25
+ }
26
+ const files = await fg(include, {
27
+ cwd: srcAbs,
28
+ ignore: exclude,
29
+ onlyFiles: true,
30
+ absolute: false
31
+ });
32
+ for (const relFile of files) {
33
+ const srcFile = path.join(srcAbs, relFile);
34
+ const destFile = path.join(destAbs, relFile);
35
+ ensureDirExists(destFile);
36
+ console.info(`[copy-plugin] copying ${srcFile} to ${destFile}`);
37
+ fs.copyFileSync(srcFile, destFile);
38
+ }
39
+ }
40
+ };
41
+ }
42
+ module.exports = VitePluginCopy;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ const node_module = require("node:module");
3
+ function VitePluginFixAbsoluteImports() {
4
+ return {
5
+ name: "fix-absolute-imports",
6
+ transform(code, id) {
7
+ for (const module2 of node_module.builtinModules) {
8
+ const moduleImportRegex = new RegExp(
9
+ `from "(${module2}(/.*)*/.*.js)";`,
10
+ "g"
11
+ );
12
+ const matches = code.match(moduleImportRegex);
13
+ if (matches) {
14
+ for (const match of matches) {
15
+ code = code.replace(match, `from "${module2}";`);
16
+ }
17
+ }
18
+ }
19
+ return {
20
+ code
21
+ };
22
+ },
23
+ enforce: "post"
24
+ };
25
+ }
26
+ module.exports = VitePluginFixAbsoluteImports;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const fs = require("node:fs/promises");
4
+ const fg = require("fast-glob");
5
+ const used = /* @__PURE__ */ new Set();
6
+ const flatten = (obj, prefix = "") => {
7
+ const flattenedObj = {};
8
+ for (const [key, value] of Object.entries(obj)) {
9
+ if (value instanceof Object) {
10
+ Object.assign(flattenedObj, flatten(value, `${prefix + key}.`));
11
+ } else {
12
+ flattenedObj[prefix + key] = value;
13
+ }
14
+ }
15
+ return flattenedObj;
16
+ };
17
+ const unflatten = (obj) => {
18
+ const result = {};
19
+ for (const [key, value] of Object.entries(obj)) {
20
+ const keys = key.split(".");
21
+ keys.reduce((acc, k, i) => {
22
+ if (i === keys.length - 1) {
23
+ acc[k] = value;
24
+ } else {
25
+ if (!acc[k]) {
26
+ acc[k] = Number.isNaN(Number(keys[i + 1])) ? {} : [];
27
+ }
28
+ }
29
+ return acc[k];
30
+ }, result);
31
+ }
32
+ return result;
33
+ };
34
+ function VitePluginRemoveUnusedTranslations(translationKeys, jsonPattern) {
35
+ return {
36
+ name: "remove-unused-translations",
37
+ transform(code) {
38
+ for (const key of translationKeys) {
39
+ if (code.includes(key) && !used.has(key)) {
40
+ console.info(`Found key: ${key}`);
41
+ used.add(key);
42
+ }
43
+ }
44
+ return { code };
45
+ },
46
+ enforce: "post",
47
+ async writeBundle() {
48
+ const jsonFiles = await fg(jsonPattern, { absolute: true });
49
+ console.info(`Found ${jsonFiles.length} JSON files at ${jsonPattern}`);
50
+ const filePromises = [];
51
+ for (const filePath of jsonFiles) {
52
+ try {
53
+ const content = await fs.readFile(filePath, "utf-8");
54
+ const jsonData = JSON.parse(content);
55
+ const jsonDataFlattened = flatten(jsonData);
56
+ const filteredData = Object.fromEntries(
57
+ Object.entries(jsonDataFlattened).filter(([key]) => used.has(key))
58
+ );
59
+ const unflattened = unflatten(filteredData);
60
+ filePromises.push(
61
+ fs.writeFile(
62
+ filePath,
63
+ JSON.stringify(unflattened, null, 2),
64
+ "utf-8"
65
+ ).then(() => {
66
+ console.info(`Updated ${filePath}`);
67
+ }).catch((e) => {
68
+ console.error(`Failed to update ${filePath}:`, e);
69
+ })
70
+ );
71
+ } catch (error) {
72
+ console.error(`Failed to process ${filePath}:`, error);
73
+ }
74
+ }
75
+ await Promise.all(filePromises);
76
+ }
77
+ };
78
+ }
79
+ exports.default = VitePluginRemoveUnusedTranslations;
80
+ exports.flatten = flatten;
81
+ exports.unflatten = unflatten;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ function VitePluginSourcemapExclude(opts) {
3
+ return {
4
+ name: "sourcemap-exclude",
5
+ transform(code, id) {
6
+ if (opts?.excludeNodeModules && id.includes("node_modules")) {
7
+ return {
8
+ code,
9
+ // https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
10
+ map: { mappings: "" }
11
+ };
12
+ }
13
+ return;
14
+ }
15
+ };
16
+ }
17
+ module.exports = VitePluginSourcemapExclude;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ const node_module = require("node:module");
3
+ const path = require("node:path");
4
+ const nodeResolve = require("@rollup/plugin-node-resolve");
5
+ const pluginWasm = require("@rollup/plugin-wasm");
6
+ const css = require("rollup-plugin-import-css");
7
+ const dependencies = require("../dependencies.cjs");
8
+ const vitePluginCloseAndCopy = require("./vite-plugin-close-and-copy.cjs");
9
+ const vitePluginFixAbsoluteImports = require("./vite-plugin-fix-absolute-imports.cjs");
10
+ async function vite_backend_config(packageName, packageVersion, bundleName, packageDir, entry, command, mode, outputDir) {
11
+ const isProduction = mode === "production";
12
+ const { dependencies: deps, optionalPeerDependencies } = await dependencies.getDependencies(packageName, true);
13
+ const outDir = outputDir ? path.resolve(outputDir) : path.resolve(packageDir, "dist/bundle");
14
+ const { external, internal } = dependencies.filterDependencies(deps, [
15
+ "aws",
16
+ "webpack",
17
+ "vite",
18
+ "biome"
19
+ ]);
20
+ const allExternal = [
21
+ ...node_module.builtinModules,
22
+ ...node_module.builtinModules.map((m) => `node:${m}`),
23
+ ...external,
24
+ ...optionalPeerDependencies
25
+ ];
26
+ console.info(
27
+ `Bundling. ${JSON.stringify(internal.slice(0, 10), null, 2)}... ${internal.length} deps`
28
+ );
29
+ const define = {
30
+ "process.env.WS_NO_BUFFER_UTIL": "true",
31
+ "process.env.WS_NO_UTF_8_VALIDATE": "true",
32
+ "process.env.PROSOPO_PACKAGE_VERSION": JSON.stringify(packageVersion),
33
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || mode),
34
+ ...process.env.PROSOPO_DEFAULT_ENVIRONMENT && {
35
+ "process.env.PROSOPO_DEFAULT_ENVIRONMENT": JSON.stringify(
36
+ process.env.PROSOPO_DEFAULT_ENVIRONMENT
37
+ )
38
+ }
39
+ };
40
+ console.info(`Defined vars ${JSON.stringify(define, null, 2)}`);
41
+ let entriesAbsolute;
42
+ if (typeof entry === "string") {
43
+ entriesAbsolute = [path.resolve(packageDir, entry)];
44
+ } else {
45
+ entriesAbsolute = entry.map((e) => path.resolve(packageDir, e));
46
+ }
47
+ const drop = mode === "production" ? ["console", "debugger"] : void 0;
48
+ return {
49
+ ssr: {
50
+ noExternal: internal,
51
+ external: allExternal
52
+ },
53
+ optimizeDeps: {
54
+ include: ["linked-dep", "node_modules"],
55
+ esbuildOptions: {
56
+ loader: {
57
+ ".node": "file"
58
+ }
59
+ }
60
+ },
61
+ esbuild: {
62
+ platform: "node",
63
+ target: "node18",
64
+ // drop,
65
+ legalComments: "none"
66
+ },
67
+ define,
68
+ build: {
69
+ outDir,
70
+ minify: isProduction,
71
+ ssr: true,
72
+ target: "node18",
73
+ lib: {
74
+ entry: entriesAbsolute,
75
+ name: bundleName,
76
+ fileName: `${bundleName}.[name].bundle.js`,
77
+ formats: ["es"]
78
+ },
79
+ modulePreload: { polyfill: false },
80
+ rollupOptions: {
81
+ treeshake: "smallest",
82
+ external: allExternal,
83
+ watch: false,
84
+ output: {
85
+ entryFileNames: `${bundleName}.[name].bundle.js`
86
+ },
87
+ // biome-ignore lint/suspicious/noExplicitAny: has to be any to represent object prototype
88
+ plugins: [css(), pluginWasm.wasm(), nodeResolve.nodeResolve()]
89
+ }
90
+ },
91
+ plugins: [
92
+ // plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
93
+ vitePluginFixAbsoluteImports(),
94
+ // plugin to close the bundle after build if not in serve mode
95
+ command !== "serve" ? vitePluginCloseAndCopy() : void 0
96
+ ]
97
+ };
98
+ }
99
+ module.exports = vite_backend_config;