@prosopo/config 2.5.5 → 3.1.1
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/CHANGELOG.md +42 -0
- package/dist/cjs/dependencies.cjs +155 -0
- package/dist/cjs/index.cjs +31 -0
- package/dist/cjs/vite/TsNoCheckPlugin.cjs +18 -0
- package/dist/cjs/vite/index.cjs +24 -0
- package/dist/cjs/vite/vite-plugin-close-and-copy.cjs +46 -0
- package/dist/cjs/vite/vite-plugin-copy.cjs +42 -0
- package/dist/cjs/vite/vite-plugin-fix-absolute-imports.cjs +26 -0
- package/dist/cjs/vite/vite-plugin-remove-unused-translations.cjs +81 -0
- package/dist/cjs/vite/vite-plugin-sourcemap-exclude.cjs +17 -0
- package/dist/cjs/vite/vite.backend.config.cjs +98 -0
- package/dist/cjs/vite/vite.commonjs.config.cjs +60 -0
- package/dist/cjs/vite/vite.esm.config.cjs +54 -0
- package/dist/cjs/vite/vite.frontend.config.cjs +182 -0
- package/dist/cjs/vite/vite.test.config.cjs +59 -0
- package/dist/cjs/webpack/index.cjs +2 -0
- package/dist/cjs/webpack/webpack.config.cjs +149 -0
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +134 -117
- package/dist/dependencies.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/dist/vite/NodejsPolarsDirnamePlugin.d.ts +1 -2
- package/dist/vite/NodejsPolarsDirnamePlugin.d.ts.map +1 -1
- package/dist/vite/NodejsPolarsDirnamePlugin.js +3 -3
- package/dist/vite/NodejsPolarsDirnamePlugin.js.map +1 -1
- package/dist/vite/NodejsPolarsNativeFilePlugin.d.ts +1 -2
- package/dist/vite/NodejsPolarsNativeFilePlugin.d.ts.map +1 -1
- package/dist/vite/NodejsPolarsNativeFilePlugin.js +5 -5
- package/dist/vite/NodejsPolarsNativeFilePlugin.js.map +1 -1
- package/dist/vite/TsNoCheckPlugin.js +17 -13
- package/dist/vite/index.d.ts +2 -0
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +24 -10
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/vite-plugin-close-and-copy.d.ts.map +1 -1
- package/dist/vite/vite-plugin-close-and-copy.js +41 -38
- package/dist/vite/vite-plugin-close-and-copy.js.map +1 -1
- package/dist/vite/vite-plugin-copy.d.ts +10 -0
- package/dist/vite/vite-plugin-copy.d.ts.map +1 -0
- package/dist/vite/vite-plugin-copy.js +43 -0
- package/dist/vite/vite-plugin-copy.js.map +1 -0
- package/dist/vite/vite-plugin-fix-absolute-imports.js +25 -20
- package/dist/vite/vite-plugin-remove-unused-translations.d.ts +4 -0
- package/dist/vite/vite-plugin-remove-unused-translations.d.ts.map +1 -1
- package/dist/vite/vite-plugin-remove-unused-translations.js +79 -46
- package/dist/vite/vite-plugin-remove-unused-translations.js.map +1 -1
- package/dist/vite/vite-plugin-sourcemap-exclude.js +17 -14
- package/dist/vite/vite.backend.config.d.ts +1 -1
- package/dist/vite/vite.backend.config.d.ts.map +1 -1
- package/dist/vite/vite.backend.config.js +91 -80
- package/dist/vite/vite.backend.config.js.map +1 -1
- package/dist/vite/vite.commonjs.config.d.ts.map +1 -1
- package/dist/vite/vite.commonjs.config.js +53 -43
- package/dist/vite/vite.commonjs.config.js.map +1 -1
- package/dist/vite/vite.esm.config.d.ts +3 -0
- package/dist/vite/vite.esm.config.d.ts.map +1 -0
- package/dist/vite/vite.esm.config.js +55 -0
- package/dist/vite/vite.esm.config.js.map +1 -0
- package/dist/vite/vite.frontend.config.d.ts.map +1 -1
- package/dist/vite/vite.frontend.config.js +172 -139
- package/dist/vite/vite.frontend.config.js.map +1 -1
- package/dist/vite/vite.test.config.d.ts +1 -1
- package/dist/vite/vite.test.config.d.ts.map +1 -1
- package/dist/vite/vite.test.config.js +56 -46
- package/dist/vite/vite.test.config.js.map +1 -1
- package/dist/webpack/index.js +1 -2
- package/dist/webpack/webpack.config.js +115 -109
- package/package.json +38 -32
- package/vite.cjs.config.ts +3 -4
- package/vite.esm.config.ts +19 -0
- package/dist/projectInfo.d.ts +0 -38
- package/dist/projectInfo.d.ts.map +0 -1
- package/dist/projectInfo.js +0 -38
- package/dist/projectInfo.js.map +0 -1
- package/dist/provider/index.d.ts +0 -2
- package/dist/provider/index.d.ts.map +0 -1
- package/dist/provider/index.js +0 -2
- package/dist/provider/index.js.map +0 -1
- package/dist/provider/test.d.ts +0 -101
- package/dist/provider/test.d.ts.map +0 -1
- package/dist/provider/test.js +0 -27
- package/dist/provider/test.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @prosopo/config
|
|
2
|
+
|
|
3
|
+
## 3.1.1
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 3573f0b: fix npm scripts bundle command
|
|
7
|
+
- 3573f0b: build using vite, typecheck using tsc
|
|
8
|
+
- 3573f0b: standardise all vite based npm scripts for bundling
|
|
9
|
+
- 2d0dd8a: Integration tests for UAPs
|
|
10
|
+
|
|
11
|
+
## 3.1.0
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 745cc89: Remove plugins from test config
|
|
15
|
+
|
|
16
|
+
## 3.0.1
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 5619b4b: Updating tsconfig paths
|
|
20
|
+
|
|
21
|
+
## 3.0.0
|
|
22
|
+
### Major Changes
|
|
23
|
+
|
|
24
|
+
- 64b5bcd: Access Controls
|
|
25
|
+
|
|
26
|
+
## 2.6.1
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 86c22b8: structured logging
|
|
30
|
+
|
|
31
|
+
## 2.6.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- a0bfc8a: bump all pkg versions since independent versioning applied
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [a0bfc8a]
|
|
40
|
+
- @prosopo/common@2.6.0
|
|
41
|
+
- @prosopo/types@2.6.0
|
|
42
|
+
- @prosopo/util@2.6.0
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
const { stdout, stderr } = await exec(cmd);
|
|
112
|
+
if (stderr) {
|
|
113
|
+
throw new Error("CONFIG.INVALID_PACKAGE_DIR");
|
|
114
|
+
}
|
|
115
|
+
const deps = [];
|
|
116
|
+
const peerDeps = [];
|
|
117
|
+
for (const line of stdout.split("\n")) {
|
|
118
|
+
if (line.includes("UNMET OPTIONAL DEPENDENCY")) {
|
|
119
|
+
const parts = line.match(peerDepsRegex);
|
|
120
|
+
if (parts && parts.length > 1) {
|
|
121
|
+
peerDeps.push(parts[1]);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
const parts = line.match(depsRegex);
|
|
125
|
+
if (parts && parts.length > 1) {
|
|
126
|
+
deps.push(parts[1]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
dependencies: deps.filter((x, i) => i === deps.indexOf(x)),
|
|
132
|
+
optionalPeerDependencies: peerDeps.filter(
|
|
133
|
+
(x, i) => i === peerDeps.indexOf(x)
|
|
134
|
+
)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function filterDependencies(deps, filters) {
|
|
138
|
+
const depsDeduped = deps.filter((x, i) => i === deps.indexOf(x));
|
|
139
|
+
const depsWithLength = depsDeduped.filter((dep) => dep.length > 0).sort();
|
|
140
|
+
const exclude = new RegExp(`${filters.join("|")}`);
|
|
141
|
+
const internal = [];
|
|
142
|
+
const external = [];
|
|
143
|
+
for (const dep of depsWithLength) {
|
|
144
|
+
if (exclude.test(dep)) {
|
|
145
|
+
external.push(dep);
|
|
146
|
+
} else {
|
|
147
|
+
internal.push(dep);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { internal, external };
|
|
151
|
+
}
|
|
152
|
+
exports.filterDependencies = filterDependencies;
|
|
153
|
+
exports.getDependencies = getDependencies;
|
|
154
|
+
exports.getExternalsFromReferences = getExternalsFromReferences;
|
|
155
|
+
exports.getTsConfigs = getTsConfigs;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 vitePluginSourcemapExclude = require("./vite/vite-plugin-sourcemap-exclude.cjs");
|
|
9
|
+
const vite_frontend_config = require("./vite/vite.frontend.config.cjs");
|
|
10
|
+
const vite_backend_config = require("./vite/vite.backend.config.cjs");
|
|
11
|
+
const vitePluginFixAbsoluteImports = require("./vite/vite-plugin-fix-absolute-imports.cjs");
|
|
12
|
+
const vite_commonjs_config = require("./vite/vite.commonjs.config.cjs");
|
|
13
|
+
const vite_esm_config = require("./vite/vite.esm.config.cjs");
|
|
14
|
+
const vitePluginRemoveUnusedTranslations = require("./vite/vite-plugin-remove-unused-translations.cjs");
|
|
15
|
+
const vitePluginCopy = require("./vite/vite-plugin-copy.cjs");
|
|
16
|
+
const TsNoCheckPlugin = require("./vite/TsNoCheckPlugin.cjs");
|
|
17
|
+
exports.filterDependencies = dependencies.filterDependencies;
|
|
18
|
+
exports.getDependencies = dependencies.getDependencies;
|
|
19
|
+
exports.getExternalsFromReferences = dependencies.getExternalsFromReferences;
|
|
20
|
+
exports.getTsConfigs = dependencies.getTsConfigs;
|
|
21
|
+
exports.VitePluginCloseAndCopy = vitePluginCloseAndCopy;
|
|
22
|
+
exports.ViteTestConfig = vite_test_config;
|
|
23
|
+
exports.VitePluginSourceMapExclude = vitePluginSourcemapExclude;
|
|
24
|
+
exports.ViteFrontendConfig = vite_frontend_config;
|
|
25
|
+
exports.ViteBackendConfig = vite_backend_config;
|
|
26
|
+
exports.VitePluginFixAbsoluteImports = vitePluginFixAbsoluteImports;
|
|
27
|
+
exports.ViteCommonJSConfig = vite_commonjs_config;
|
|
28
|
+
exports.ViteEsmConfig = vite_esm_config;
|
|
29
|
+
exports.VitePluginRemoveUnusedTranslations = vitePluginRemoveUnusedTranslations.default;
|
|
30
|
+
exports.VitePluginCopy = vitePluginCopy;
|
|
31
|
+
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,24 @@
|
|
|
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 vitePluginSourcemapExclude = require("./vite-plugin-sourcemap-exclude.cjs");
|
|
6
|
+
const vite_frontend_config = require("./vite.frontend.config.cjs");
|
|
7
|
+
const vite_backend_config = require("./vite.backend.config.cjs");
|
|
8
|
+
const vitePluginFixAbsoluteImports = require("./vite-plugin-fix-absolute-imports.cjs");
|
|
9
|
+
const vite_commonjs_config = require("./vite.commonjs.config.cjs");
|
|
10
|
+
const vite_esm_config = require("./vite.esm.config.cjs");
|
|
11
|
+
const vitePluginRemoveUnusedTranslations = require("./vite-plugin-remove-unused-translations.cjs");
|
|
12
|
+
const TsNoCheckPlugin = require("./TsNoCheckPlugin.cjs");
|
|
13
|
+
const vitePluginCopy = require("./vite-plugin-copy.cjs");
|
|
14
|
+
exports.VitePluginCloseAndCopy = vitePluginCloseAndCopy;
|
|
15
|
+
exports.ViteTestConfig = vite_test_config;
|
|
16
|
+
exports.VitePluginSourceMapExclude = vitePluginSourcemapExclude;
|
|
17
|
+
exports.ViteFrontendConfig = vite_frontend_config;
|
|
18
|
+
exports.ViteBackendConfig = vite_backend_config;
|
|
19
|
+
exports.VitePluginFixAbsoluteImports = vitePluginFixAbsoluteImports;
|
|
20
|
+
exports.ViteCommonJSConfig = vite_commonjs_config;
|
|
21
|
+
exports.ViteEsmConfig = vite_esm_config;
|
|
22
|
+
exports.VitePluginRemoveUnusedTranslations = vitePluginRemoveUnusedTranslations.default;
|
|
23
|
+
exports.tsNoCheckPlugin = TsNoCheckPlugin.tsNoCheckPlugin;
|
|
24
|
+
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,98 @@
|
|
|
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
|
+
plugins: [css(), pluginWasm.wasm(), nodeResolve.nodeResolve()]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
plugins: [
|
|
91
|
+
// plugin to replace stuff like import blah from string_encoder/lib/string_encoder.js with import blah from string_encoder
|
|
92
|
+
vitePluginFixAbsoluteImports(),
|
|
93
|
+
// plugin to close the bundle after build if not in serve mode
|
|
94
|
+
command !== "serve" ? vitePluginCloseAndCopy() : void 0
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
module.exports = vite_backend_config;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const node_module = require("node:module");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const replace = require("@rollup/plugin-replace");
|
|
5
|
+
const vite = require("vite");
|
|
6
|
+
const noBundlePlugin = require("vite-plugin-no-bundle");
|
|
7
|
+
const tsconfigPaths = require("vite-tsconfig-paths");
|
|
8
|
+
const dependencies = require("../dependencies.cjs");
|
|
9
|
+
const vitePluginCloseAndCopy = require("./vite-plugin-close-and-copy.cjs");
|
|
10
|
+
const vitePluginCopy = require("./vite-plugin-copy.cjs");
|
|
11
|
+
async function vite_commonjs_config(name, tsConfigPath, entry) {
|
|
12
|
+
console.info(`ViteCommonJSConfig: ${name}`);
|
|
13
|
+
const projectExternal = await dependencies.getExternalsFromReferences(tsConfigPath, [
|
|
14
|
+
/dev/
|
|
15
|
+
]);
|
|
16
|
+
const allExternal = [
|
|
17
|
+
...node_module.builtinModules,
|
|
18
|
+
...node_module.builtinModules.map((m) => `node:${m}`),
|
|
19
|
+
...projectExternal
|
|
20
|
+
];
|
|
21
|
+
return vite.defineConfig({
|
|
22
|
+
ssr: { external: allExternal },
|
|
23
|
+
plugins: [
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
replace({
|
|
26
|
+
"module": "module"
|
|
27
|
+
// Replaces ESM checks with CommonJS equivalent
|
|
28
|
+
}),
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
noBundlePlugin({
|
|
31
|
+
root: "src",
|
|
32
|
+
copy: "**/*.css"
|
|
33
|
+
}),
|
|
34
|
+
vitePluginCopy({
|
|
35
|
+
srcDir: "src",
|
|
36
|
+
destDir: "dist",
|
|
37
|
+
include: ["**/*.json"]
|
|
38
|
+
}),
|
|
39
|
+
tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }),
|
|
40
|
+
vitePluginCloseAndCopy()
|
|
41
|
+
],
|
|
42
|
+
build: {
|
|
43
|
+
emptyOutDir: false,
|
|
44
|
+
ssr: true,
|
|
45
|
+
target: "node18",
|
|
46
|
+
outDir: "dist/cjs",
|
|
47
|
+
lib: {
|
|
48
|
+
name,
|
|
49
|
+
formats: ["cjs"],
|
|
50
|
+
entry: entry || "src/index.ts"
|
|
51
|
+
// required
|
|
52
|
+
},
|
|
53
|
+
rollupOptions: {
|
|
54
|
+
treeshake: false,
|
|
55
|
+
external: allExternal
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
module.exports = vite_commonjs_config;
|