@webiny/build-tools 0.0.0-unstable.61c048f412
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/.babelrc.js +1 -0
- package/.eslintrc.cjs +6 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/bundling/admin/createBuildAdmin.js +17 -0
- package/bundling/admin/createRsbuildConfig.js +142 -0
- package/bundling/admin/createWatchAdmin.js +14 -0
- package/bundling/admin/index.js +3 -0
- package/bundling/function/createBuildFunction.js +17 -0
- package/bundling/function/createRsbuildConfig.js +84 -0
- package/bundling/function/createWatchFunction.js +14 -0
- package/bundling/function/index.js +3 -0
- package/bundling/importValidatorPlugin.js +82 -0
- package/bundling/printBuildStats.js +44 -0
- package/index.d.ts +82 -0
- package/index.js +8 -0
- package/package.json +93 -0
- package/packages/buildPackage/babelCompile.js +103 -0
- package/packages/buildPackage/copyToDist.js +11 -0
- package/packages/buildPackage/tsAliasReplacer.js +39 -0
- package/packages/buildPackage/tsCompile.js +69 -0
- package/packages/buildPackage/validateEsmImports.js +91 -0
- package/packages/buildPackage.js +40 -0
- package/packages/createBabelConfigForNode.js +19 -0
- package/packages/createBabelConfigForReact.js +20 -0
- package/packages/createBuildPackage.js +7 -0
- package/packages/createSwcConfigForNode.js +45 -0
- package/packages/createWatchPackage.js +7 -0
- package/packages/index.js +6 -0
- package/packages/watchPackage.js +117 -0
- package/traverseLoaders.js +14 -0
- package/utils/PackageJson.backup.ts +46 -0
- package/utils/PackageJson.d.ts +33 -0
- package/utils/PackageJson.js +44 -0
- package/utils.js +33 -0
- package/workspaces/index.js +12 -0
- package/workspaces/linkWorkspaces.js +107 -0
package/.babelrc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./packages").createBabelConfigForNode({ path: __dirname });
|
package/.eslintrc.cjs
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/build-tools
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
2
|
+
import { createRsbuildConfig } from "./createRsbuildConfig.js";
|
|
3
|
+
import { printBuildStats } from "../printBuildStats.js";
|
|
4
|
+
|
|
5
|
+
export const createBuildAdmin =
|
|
6
|
+
() =>
|
|
7
|
+
async ({ cwd }) => {
|
|
8
|
+
process.env.NODE_ENV = "production";
|
|
9
|
+
|
|
10
|
+
const rsbuildConfig = createRsbuildConfig({ cwd });
|
|
11
|
+
|
|
12
|
+
const rsbuild = await createRsbuild({ rsbuildConfig });
|
|
13
|
+
|
|
14
|
+
rsbuild.onAfterBuild(printBuildStats({ cwd, label: "admin", extensions: [".js", ".css"] }));
|
|
15
|
+
|
|
16
|
+
await rsbuild.build();
|
|
17
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { pluginReact } from "@rsbuild/plugin-react";
|
|
4
|
+
import { pluginSvgr } from "@rsbuild/plugin-svgr";
|
|
5
|
+
import { pluginSass } from "@rsbuild/plugin-sass";
|
|
6
|
+
import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
|
|
7
|
+
import tailwindcss from "@tailwindcss/postcss";
|
|
8
|
+
import { createImportValidatorPlugin } from "../importValidatorPlugin.js";
|
|
9
|
+
|
|
10
|
+
export const createRsbuildConfig = ({ cwd }) => {
|
|
11
|
+
const paths = getPaths(cwd);
|
|
12
|
+
const envVars = getEnvVars();
|
|
13
|
+
const mode = getMode();
|
|
14
|
+
|
|
15
|
+
return /** @type {import("@rsbuild/core").RsbuildConfig} */ ({
|
|
16
|
+
source: {
|
|
17
|
+
entry: {
|
|
18
|
+
index: paths.admin.entryFile
|
|
19
|
+
},
|
|
20
|
+
define: envVars
|
|
21
|
+
},
|
|
22
|
+
resolve: {
|
|
23
|
+
alias: {
|
|
24
|
+
// This is a temporary fix, until we sort out the `react-butterfiles` dependency.
|
|
25
|
+
"react-butterfiles": "@webiny/app/react-butterfiles"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
output: { distPath: { root: paths.admin.outputFolder } },
|
|
29
|
+
mode,
|
|
30
|
+
dev: { hmr: true },
|
|
31
|
+
performance: {
|
|
32
|
+
printFileSize: false
|
|
33
|
+
},
|
|
34
|
+
tools: {
|
|
35
|
+
postcss: (_, { addPlugins }) => {
|
|
36
|
+
addPlugins(
|
|
37
|
+
tailwindcss({
|
|
38
|
+
base: getTailwindBasePath(paths.projectRootFolder)
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
server: { port: 3001 },
|
|
44
|
+
html: {
|
|
45
|
+
template: paths.projectRootFolder + "/public/index.html"
|
|
46
|
+
},
|
|
47
|
+
plugins: [
|
|
48
|
+
createImportValidatorPlugin(),
|
|
49
|
+
pluginTypeCheck({
|
|
50
|
+
tsCheckerOptions: {
|
|
51
|
+
typescript: { configFile: paths.admin.tsConfig },
|
|
52
|
+
async: mode === "development"
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
pluginReact({
|
|
56
|
+
splitChunks: false
|
|
57
|
+
}),
|
|
58
|
+
pluginSass(),
|
|
59
|
+
pluginSvgr({
|
|
60
|
+
mixedImport: true,
|
|
61
|
+
svgrOptions: {
|
|
62
|
+
exportType: "named",
|
|
63
|
+
svgoConfig: {
|
|
64
|
+
plugins: [
|
|
65
|
+
{
|
|
66
|
+
name: "pres" + "et-default",
|
|
67
|
+
params: { overrides: { removeViewBox: false } }
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getPaths = cwd => {
|
|
78
|
+
const adminRootFolderPath = cwd;
|
|
79
|
+
const adminOutputFolderPath = path.join(adminRootFolderPath, "build");
|
|
80
|
+
const adminEntryFilePath = path.join(adminRootFolderPath, "src", "index.tsx");
|
|
81
|
+
|
|
82
|
+
const adminTsConfigFilePath = path.join(adminRootFolderPath, "tsconfig.json");
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
projectRootFolder: process.cwd(),
|
|
86
|
+
admin: {
|
|
87
|
+
rootFolder: adminRootFolderPath,
|
|
88
|
+
tsConfig: adminTsConfigFilePath,
|
|
89
|
+
outputFolder: adminOutputFolderPath,
|
|
90
|
+
entryFile: adminEntryFilePath
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const getTailwindBasePath = projectRootFolderPath => {
|
|
96
|
+
const adminUiPkgPath = path.join(projectRootFolderPath, "packages", "admin-ui");
|
|
97
|
+
|
|
98
|
+
const isWebinyJsRepo = fs.existsSync(adminUiPkgPath);
|
|
99
|
+
|
|
100
|
+
if (isWebinyJsRepo) {
|
|
101
|
+
return path.join(projectRootFolderPath, "packages");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return path.join(projectRootFolderPath, "node_modules", "@webiny");
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const getEnvVars = () => {
|
|
108
|
+
const raw = Object.keys(process.env)
|
|
109
|
+
.filter(key => {
|
|
110
|
+
if (new RegExp(/^REACT_APP_/i).test(key)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return new RegExp(/^WEBINY_ADMIN_/i).test(key);
|
|
115
|
+
})
|
|
116
|
+
.reduce(
|
|
117
|
+
(env, key) => {
|
|
118
|
+
env[key] = process.env[key];
|
|
119
|
+
return env;
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
// Useful for determining whether we're running in production mode.
|
|
123
|
+
// Most importantly, it switches React into the correct mode.
|
|
124
|
+
NODE_ENV: process.env.NODE_ENV || "development"
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Stringify all values so we can feed into Webpack DefinePlugin.
|
|
129
|
+
// Provide values one by one, not as a single process.env object,
|
|
130
|
+
// because otherwise plugin will put a big JSON object every time process.env is used in code.
|
|
131
|
+
// This way minifier also removes redundant code on prod (like if(process.env.NODE_ENV === 'development')).
|
|
132
|
+
const envVarsAsStrings = {};
|
|
133
|
+
for (const key of Object.keys(raw)) {
|
|
134
|
+
envVarsAsStrings[`process.env.${key}`] = JSON.stringify(raw[key]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return envVarsAsStrings;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const getMode = () => {
|
|
141
|
+
return process.env.NODE_ENV === "production" ? "production" : "development";
|
|
142
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
2
|
+
import { createRsbuildConfig } from "./createRsbuildConfig.js";
|
|
3
|
+
|
|
4
|
+
export const createWatchAdmin =
|
|
5
|
+
() =>
|
|
6
|
+
async ({ cwd }) => {
|
|
7
|
+
process.env.NODE_ENV = "development";
|
|
8
|
+
|
|
9
|
+
const rsbuildConfig = createRsbuildConfig({ cwd });
|
|
10
|
+
|
|
11
|
+
const rsbuild = await createRsbuild({ rsbuildConfig });
|
|
12
|
+
|
|
13
|
+
await rsbuild.startDevServer();
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
2
|
+
import { createRsbuildConfig } from "./createRsbuildConfig.js";
|
|
3
|
+
import { printBuildStats } from "../printBuildStats.js";
|
|
4
|
+
|
|
5
|
+
export const createBuildFunction =
|
|
6
|
+
() =>
|
|
7
|
+
async ({ cwd }) => {
|
|
8
|
+
process.env.NODE_ENV = "production";
|
|
9
|
+
|
|
10
|
+
const rsbuildConfig = createRsbuildConfig({ cwd });
|
|
11
|
+
|
|
12
|
+
const rsbuild = await createRsbuild({ rsbuildConfig });
|
|
13
|
+
|
|
14
|
+
rsbuild.onAfterBuild(printBuildStats({ cwd, label: "node", extensions: [".mjs"] }));
|
|
15
|
+
|
|
16
|
+
await rsbuild.build();
|
|
17
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import rspack from "@rspack/core";
|
|
3
|
+
import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
|
|
4
|
+
import { createImportValidatorPlugin } from "../importValidatorPlugin.js";
|
|
5
|
+
|
|
6
|
+
export const createRsbuildConfig = ({ cwd }) => {
|
|
7
|
+
const paths = getPaths(cwd);
|
|
8
|
+
const mode = getMode();
|
|
9
|
+
|
|
10
|
+
return /** @type {import("@rsbuild/core").RsbuildConfig} */ ({
|
|
11
|
+
source: { entry: { index: paths.fn.entryFile } },
|
|
12
|
+
output: {
|
|
13
|
+
module: true,
|
|
14
|
+
target: "node",
|
|
15
|
+
sourceMap: {
|
|
16
|
+
js: process.env.DEBUG === "true" ? "source-map" : false
|
|
17
|
+
},
|
|
18
|
+
filename: {
|
|
19
|
+
js: pathData => {
|
|
20
|
+
if (pathData.chunk?.name === "index") {
|
|
21
|
+
return "handler.mjs";
|
|
22
|
+
}
|
|
23
|
+
return "[name].mjs";
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
distPath: { root: paths.fn.outputFolder }
|
|
27
|
+
},
|
|
28
|
+
performance: {
|
|
29
|
+
printFileSize: false
|
|
30
|
+
},
|
|
31
|
+
tools: {
|
|
32
|
+
rspack: {
|
|
33
|
+
externals: [/^@aws-sdk/, /^sharp$/],
|
|
34
|
+
plugins: [
|
|
35
|
+
// This is necessary to enable JSDOM usage in Lambda.
|
|
36
|
+
// https://rspack.dev/plugins/webpack/ignore-plugin
|
|
37
|
+
new rspack.IgnorePlugin({
|
|
38
|
+
resourceRegExp: /canvas/,
|
|
39
|
+
contextRegExp: /jsdom$/
|
|
40
|
+
})
|
|
41
|
+
],
|
|
42
|
+
resolve: {
|
|
43
|
+
fallback: {
|
|
44
|
+
// Disable optional native dependency used by 'ws' package for performance optimizations.
|
|
45
|
+
// Not needed in Lambda environment and can cause bundling/deployment issues.
|
|
46
|
+
bufferutil: false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
mode,
|
|
52
|
+
plugins: [
|
|
53
|
+
createImportValidatorPlugin(),
|
|
54
|
+
pluginTypeCheck({
|
|
55
|
+
tsCheckerOptions: {
|
|
56
|
+
typescript: { configFile: paths.fn.tsConfig },
|
|
57
|
+
async: mode === "development"
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getPaths = cwd => {
|
|
65
|
+
const fnRootFolderPath = cwd;
|
|
66
|
+
const fnOutputFolderPath = path.join(fnRootFolderPath, "build");
|
|
67
|
+
const fnEntryFilePath = path.join(fnRootFolderPath, "src", "index.ts");
|
|
68
|
+
|
|
69
|
+
const fnTsConfigFilePath = path.join(fnRootFolderPath, "tsconfig.json");
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
projectRootFolder: process.cwd(),
|
|
73
|
+
fn: {
|
|
74
|
+
rootFolder: fnRootFolderPath,
|
|
75
|
+
tsConfig: fnTsConfigFilePath,
|
|
76
|
+
outputFolder: fnOutputFolderPath,
|
|
77
|
+
entryFile: fnEntryFilePath
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const getMode = () => {
|
|
83
|
+
return process.env.NODE_ENV === "production" ? "production" : "development";
|
|
84
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRsbuild } from "@rsbuild/core";
|
|
2
|
+
import { createRsbuildConfig } from "./createRsbuildConfig.js";
|
|
3
|
+
|
|
4
|
+
export const createWatchFunction =
|
|
5
|
+
() =>
|
|
6
|
+
async ({ cwd }) => {
|
|
7
|
+
process.env.NODE_ENV = "development";
|
|
8
|
+
|
|
9
|
+
const rsbuildConfig = createRsbuildConfig({ cwd });
|
|
10
|
+
|
|
11
|
+
const rsbuild = await createRsbuild({ rsbuildConfig });
|
|
12
|
+
|
|
13
|
+
await rsbuild.build({ watch: true });
|
|
14
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// ANSI color codes
|
|
2
|
+
const red = "\x1b[31m";
|
|
3
|
+
const yellow = "\x1b[33m";
|
|
4
|
+
const cyan = "\x1b[36m";
|
|
5
|
+
const reset = "\x1b[0m";
|
|
6
|
+
const bold = "\x1b[1m";
|
|
7
|
+
|
|
8
|
+
const whitelist = ["@webiny/cognito", "@webiny/auth0", "@webiny/okta"];
|
|
9
|
+
|
|
10
|
+
export const createImportValidatorPlugin = () => {
|
|
11
|
+
return {
|
|
12
|
+
name: "extensions-import-validator",
|
|
13
|
+
setup(api) {
|
|
14
|
+
api.modifyRspackConfig(config => {
|
|
15
|
+
config.plugins = config.plugins || [];
|
|
16
|
+
config.plugins.push({
|
|
17
|
+
name: "ExtensionsImportValidatorPlugin",
|
|
18
|
+
apply(compiler) {
|
|
19
|
+
compiler.hooks.compilation.tap(
|
|
20
|
+
"ExtensionsImportValidatorPlugin",
|
|
21
|
+
(compilation, { normalModuleFactory }) => {
|
|
22
|
+
normalModuleFactory.hooks.beforeResolve.tap(
|
|
23
|
+
"ExtensionsImportValidatorPlugin",
|
|
24
|
+
resolveData => {
|
|
25
|
+
const request = resolveData.request;
|
|
26
|
+
const contextInfo = resolveData.contextInfo;
|
|
27
|
+
const issuer = contextInfo?.issuer;
|
|
28
|
+
|
|
29
|
+
// Check if the import request is a @webiny/* package
|
|
30
|
+
if (!request?.startsWith("@webiny/")) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Allow whitelisted packages
|
|
35
|
+
if (whitelist.some(pkg => request.startsWith(pkg))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Check if the import originates from extensions folder
|
|
40
|
+
if (!issuer) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const normalizedIssuer = issuer.replace(/\\/g, "/");
|
|
45
|
+
|
|
46
|
+
// Check if the issuer is within the extensions folder
|
|
47
|
+
if (!normalizedIssuer.includes("/extensions/")) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Check if the import is coming through the webiny parent package
|
|
52
|
+
// by checking if the issuer is from node_modules/webiny
|
|
53
|
+
const issuerModule = contextInfo?.issuerModule;
|
|
54
|
+
if (issuerModule) {
|
|
55
|
+
const moduleIdentifier =
|
|
56
|
+
issuerModule.identifier?.() || "";
|
|
57
|
+
if (
|
|
58
|
+
moduleIdentifier.includes("/node_modules/webiny/")
|
|
59
|
+
) {
|
|
60
|
+
return; // Allow imports through webiny package
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const error = new Error(
|
|
65
|
+
`${red}Direct imports of @webiny/* packages are not allowed. Import from "webiny" package instead.${reset}\n\n` +
|
|
66
|
+
`${bold}Location:${reset} ${cyan}${issuer.replace(process.cwd(), "")}${reset}\n` +
|
|
67
|
+
`${bold}Import:${reset} ${yellow}${request}${reset}\n`
|
|
68
|
+
);
|
|
69
|
+
error.name = "ExtensionsImportError";
|
|
70
|
+
error.hideStack = true;
|
|
71
|
+
|
|
72
|
+
compilation.errors.push(error);
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
|
|
4
|
+
export const printBuildStats =
|
|
5
|
+
({ cwd, label = "build", extensions = [".js", ".mjs", ".css"] }) =>
|
|
6
|
+
({ stats }) => {
|
|
7
|
+
if (!stats) return;
|
|
8
|
+
|
|
9
|
+
const statsJson = stats.toJson({ assets: true, children: false });
|
|
10
|
+
const assets = statsJson.assets || [];
|
|
11
|
+
|
|
12
|
+
// Compute cleaner display path
|
|
13
|
+
const projectRoot = process.cwd();
|
|
14
|
+
const outputPath = statsJson.outputPath || path.join(cwd, "build");
|
|
15
|
+
const webinyWorkspacePrefix = ".webiny/workspace/";
|
|
16
|
+
let displayPath = path.relative(projectRoot, outputPath);
|
|
17
|
+
|
|
18
|
+
if (displayPath.startsWith(webinyWorkspacePrefix)) {
|
|
19
|
+
displayPath = displayPath.slice(webinyWorkspacePrefix.length);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Sort assets by size for better readability
|
|
23
|
+
const sortedAssets = assets
|
|
24
|
+
.filter(asset => extensions.some(ext => asset.name.endsWith(ext)))
|
|
25
|
+
.sort((a, b) => a.size - b.size);
|
|
26
|
+
|
|
27
|
+
// Print header with blue color
|
|
28
|
+
console.log(
|
|
29
|
+
`\n${chalk.blue(`File (${label})`.padEnd(50))}${chalk.blue("Size".padStart(11))}`
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
let totalSize = 0;
|
|
33
|
+
for (const asset of sortedAssets) {
|
|
34
|
+
const fileName = path.basename(asset.name);
|
|
35
|
+
const sizeKB = (asset.size / 1024).toFixed(1);
|
|
36
|
+
totalSize += asset.size;
|
|
37
|
+
|
|
38
|
+
// Print filename in cyan
|
|
39
|
+
console.log(`${chalk.cyan(fileName.padEnd(50))}${sizeKB.padStart(10)} kB`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const totalSizeKB = (totalSize / 1024).toFixed(1);
|
|
43
|
+
console.log(`\n${chalk.magenta("Total:".padEnd(50))}${totalSizeKB.padStart(10)} kB\n`);
|
|
44
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Configuration as RspackConfig } from "@rspack/core";
|
|
2
|
+
|
|
3
|
+
export { RspackConfig };
|
|
4
|
+
|
|
5
|
+
// Build commands.
|
|
6
|
+
export type BuildCommand<TOptions = Record<string, any>> = (options: TOptions) => Promise<void>;
|
|
7
|
+
|
|
8
|
+
export interface BabelConfig {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SwcConfig {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DefinePluginOptions {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BuildAppConfigOverrides {
|
|
21
|
+
entry?: string;
|
|
22
|
+
openBrowser?: boolean;
|
|
23
|
+
babel?: (config: BabelConfig) => BabelConfig;
|
|
24
|
+
}
|
|
25
|
+
// Build commands - apps.
|
|
26
|
+
export interface BuildAppConfig {
|
|
27
|
+
cwd: string;
|
|
28
|
+
openBrowser?: boolean;
|
|
29
|
+
overrides?: BuildAppConfigOverrides;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createBuildAdmin(options: BuildAppConfig): BuildCommand;
|
|
33
|
+
export function createWatchAdmin(options: BuildAppConfig): BuildCommand;
|
|
34
|
+
|
|
35
|
+
// Build commands - functions.
|
|
36
|
+
interface BuildFunctionConfig {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
cwd: string;
|
|
39
|
+
logs?: boolean;
|
|
40
|
+
debug?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Enables or disables source map generation for the function.
|
|
43
|
+
* By default is set to `true`
|
|
44
|
+
*/
|
|
45
|
+
sourceMaps?: boolean;
|
|
46
|
+
overrides?: {
|
|
47
|
+
entry?: string;
|
|
48
|
+
output?: {
|
|
49
|
+
path?: string;
|
|
50
|
+
filename?: string;
|
|
51
|
+
};
|
|
52
|
+
define?: DefinePluginOptions;
|
|
53
|
+
rspack?: (config: RspackConfig) => RspackConfig;
|
|
54
|
+
babel?: (config: BabelConfig) => BabelConfig;
|
|
55
|
+
swc?: (config: SwcConfig) => SwcConfig;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createBuildFunction(options: BuildFunctionConfig): BuildCommand;
|
|
60
|
+
export function createWatchFunction(options: BuildFunctionConfig): BuildCommand;
|
|
61
|
+
|
|
62
|
+
// Build commands - packages.
|
|
63
|
+
interface BuildPackageConfig {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
cwd: string;
|
|
66
|
+
logs?: boolean;
|
|
67
|
+
debug?: boolean;
|
|
68
|
+
|
|
69
|
+
overrides?: {
|
|
70
|
+
tsConfig?: Record<string, any> | ((tsConfig: Record<string, any>) => Record<string, any>);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface BabelConfigParams {
|
|
75
|
+
path: string;
|
|
76
|
+
esm?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createBuildPackage(options: BuildPackageConfig): BuildCommand;
|
|
80
|
+
export function createWatchPackage(options: BuildPackageConfig): BuildCommand;
|
|
81
|
+
export function createBabelConfigForNode(options: BabelConfigParams): BabelConfig;
|
|
82
|
+
export function createBabelConfigForReact(options: BabelConfigParams): BabelConfig;
|
package/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createWatchAdmin, createBuildAdmin } from "./bundling/admin/index.js";
|
|
2
|
+
export { createBuildFunction, createWatchFunction } from "./bundling/function/index.js";
|
|
3
|
+
export {
|
|
4
|
+
createWatchPackage,
|
|
5
|
+
createBuildPackage,
|
|
6
|
+
createBabelConfigForNode,
|
|
7
|
+
createBabelConfigForReact
|
|
8
|
+
} from "./packages/index.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/build-tools",
|
|
3
|
+
"version": "0.0.0-unstable.61c048f412",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"description": "A collection of utilities for Webiny project.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Pavel Denisjuk <pavel@webiny.com>",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
14
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/core": "7.29.0",
|
|
18
|
+
"@babel/preset-env": "7.29.0",
|
|
19
|
+
"@babel/preset-react": "7.28.5",
|
|
20
|
+
"@babel/preset-typescript": "7.28.5",
|
|
21
|
+
"@babel/runtime": "7.28.6",
|
|
22
|
+
"@rsbuild/core": "1.7.3",
|
|
23
|
+
"@rsbuild/plugin-react": "1.4.5",
|
|
24
|
+
"@rsbuild/plugin-sass": "1.5.0",
|
|
25
|
+
"@rsbuild/plugin-svgr": "1.3.0",
|
|
26
|
+
"@rsbuild/plugin-type-check": "1.3.3",
|
|
27
|
+
"@rspack/core": "1.7.6",
|
|
28
|
+
"@svgr/webpack": "6.5.1",
|
|
29
|
+
"@swc/plugin-emotion": "11.5.0",
|
|
30
|
+
"@tailwindcss/postcss": "4.1.18",
|
|
31
|
+
"@types/webpack-env": "1.18.8",
|
|
32
|
+
"chalk": "4.1.2",
|
|
33
|
+
"chokidar": "4.0.3",
|
|
34
|
+
"css-loader": "7.1.3",
|
|
35
|
+
"eslint": "9.39.2",
|
|
36
|
+
"fast-glob": "3.3.3",
|
|
37
|
+
"find-up": "5.0.0",
|
|
38
|
+
"fs-extra": "11.3.3",
|
|
39
|
+
"get-yarn-workspaces": "1.0.2",
|
|
40
|
+
"lodash": "4.17.23",
|
|
41
|
+
"postcss-loader": "8.2.0",
|
|
42
|
+
"process": "0.11.10",
|
|
43
|
+
"raw-loader": "4.0.2",
|
|
44
|
+
"react-dom": "18.2.0",
|
|
45
|
+
"react-refresh": "0.11.0",
|
|
46
|
+
"read-json-sync": "2.0.1",
|
|
47
|
+
"rimraf": "6.1.2",
|
|
48
|
+
"sass": "1.97.3",
|
|
49
|
+
"sass-loader": "16.0.7",
|
|
50
|
+
"style-loader": "3.3.4",
|
|
51
|
+
"ts-morph": "27.0.2",
|
|
52
|
+
"tsx": "4.21.0",
|
|
53
|
+
"typescript": "5.9.3",
|
|
54
|
+
"url-loader": "4.1.1",
|
|
55
|
+
"utf-8-validate": "6.0.6"
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"adio": {
|
|
59
|
+
"ignore": {
|
|
60
|
+
"src": [
|
|
61
|
+
"@webiny/admin-ui",
|
|
62
|
+
"@webiny/app",
|
|
63
|
+
"!!raw-loader!"
|
|
64
|
+
],
|
|
65
|
+
"dependencies": [
|
|
66
|
+
"@babel/preset-react",
|
|
67
|
+
"@svgr/webpack",
|
|
68
|
+
"@babel/preset-env",
|
|
69
|
+
"@babel/preset-typescript",
|
|
70
|
+
"@swc/plugin-emotion",
|
|
71
|
+
"@types/webpack-env",
|
|
72
|
+
"postcss-loader",
|
|
73
|
+
"raw-loader",
|
|
74
|
+
"react-refresh",
|
|
75
|
+
"style-loader",
|
|
76
|
+
"typescript",
|
|
77
|
+
"eslint",
|
|
78
|
+
"process",
|
|
79
|
+
"sass-loader",
|
|
80
|
+
"sass",
|
|
81
|
+
"bufferutil",
|
|
82
|
+
"utf-8-validate",
|
|
83
|
+
"css-loader",
|
|
84
|
+
"url-loader"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public",
|
|
90
|
+
"directory": "."
|
|
91
|
+
},
|
|
92
|
+
"gitHead": "61c048f412d6b4aa70c1d105aab21e3fa69730f3"
|
|
93
|
+
}
|