@webiny/build-tools 0.0.0-unstable.3c5210ad37
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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import readJson from "read-json-sync";
|
|
2
|
+
import findUp from "find-up";
|
|
3
|
+
|
|
4
|
+
export class PackageJson {
|
|
5
|
+
filePath;
|
|
6
|
+
json;
|
|
7
|
+
|
|
8
|
+
static fromFile(filePath) {
|
|
9
|
+
return new PackageJson(filePath, readJson(filePath));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static async findClosest(fromPath) {
|
|
13
|
+
const closestPackageJson = await findUp("package.json", { cwd: fromPath });
|
|
14
|
+
if (!closestPackageJson) {
|
|
15
|
+
throw Error(`Failed to find ${fromPath}`);
|
|
16
|
+
}
|
|
17
|
+
return PackageJson.fromFile(closestPackageJson);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static async fromPackage(packageName, cwd) {
|
|
21
|
+
const jsonPath = await findUp(`node_modules/${packageName}/package.json`, {
|
|
22
|
+
cwd: cwd ?? process.cwd()
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!jsonPath) {
|
|
26
|
+
throw Error(`Failed to find package ${packageName}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return PackageJson.fromFile(jsonPath);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor(filePath, json) {
|
|
33
|
+
this.filePath = filePath;
|
|
34
|
+
this.json = json;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getLocation() {
|
|
38
|
+
return this.filePath;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getJson() {
|
|
42
|
+
return this.json;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/utils.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import merge from "lodash/merge.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prepares the options object, sent to build and watch functions.
|
|
5
|
+
* @param config
|
|
6
|
+
* @param options
|
|
7
|
+
* @returns {Promise<{overrides}|*>}
|
|
8
|
+
*/
|
|
9
|
+
export const prepareOptions = ({ config, options }) => {
|
|
10
|
+
const mergedOptions = merge({}, config, options);
|
|
11
|
+
|
|
12
|
+
// If it doesn't exist, ensure `overrides` is an empty object.
|
|
13
|
+
if (!mergedOptions.overrides) {
|
|
14
|
+
mergedOptions.overrides = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// We want to have debug logs disabled by default.
|
|
18
|
+
mergedOptions.debug = mergedOptions.debug === true;
|
|
19
|
+
|
|
20
|
+
return mergedOptions;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculates time difference between the initial `getDuration`
|
|
25
|
+
* invocation and the invocation of the returned callback function.
|
|
26
|
+
* @returns {function(): string}
|
|
27
|
+
*/
|
|
28
|
+
export const getDuration = () => {
|
|
29
|
+
const start = new Date();
|
|
30
|
+
return () => {
|
|
31
|
+
return (new Date() - start) / 1000;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import getYarnWorkspaces from "get-yarn-workspaces";
|
|
4
|
+
export { linkWorkspaces } from "./linkWorkspaces";
|
|
5
|
+
|
|
6
|
+
const hasPackageJson = p => fs.existsSync(p + "/package.json");
|
|
7
|
+
|
|
8
|
+
export const allWorkspaces = () => {
|
|
9
|
+
return getYarnWorkspaces()
|
|
10
|
+
.filter(hasPackageJson)
|
|
11
|
+
.map(pkg => pkg.replace(/\//g, path.sep));
|
|
12
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This tool will re-link monorepo packages to one of the following directories (by priority):
|
|
3
|
+
* - {package}/package.json -> publishConfig.directory
|
|
4
|
+
* - lerna.json -> command.publish.contents
|
|
5
|
+
* - package root directory
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import "tsx";
|
|
9
|
+
|
|
10
|
+
import path from "path";
|
|
11
|
+
import get from "lodash/get.js";
|
|
12
|
+
import fs from "fs-extra";
|
|
13
|
+
import * as rimraf from "rimraf";
|
|
14
|
+
import readJsonSync from "read-json-sync";
|
|
15
|
+
|
|
16
|
+
async function symlink(src, dest) {
|
|
17
|
+
if (process.platform !== "win32") {
|
|
18
|
+
// use relative paths otherwise which will be retained if the directory is moved
|
|
19
|
+
src = path.relative(path.dirname(dest), src);
|
|
20
|
+
// When path.relative returns an empty string for the current directory, we should instead use
|
|
21
|
+
// '.', which is a valid fs.symlink target.
|
|
22
|
+
src = src || ".";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const stats = await fs.lstat(dest);
|
|
27
|
+
if (stats.isSymbolicLink()) {
|
|
28
|
+
const resolved = dest;
|
|
29
|
+
if (resolved === src) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (err.code !== "ENOENT") {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// We use rimraf for unlink which never throws an ENOENT on missing target
|
|
39
|
+
rimraf.sync(dest);
|
|
40
|
+
|
|
41
|
+
if (process.platform === "win32") {
|
|
42
|
+
// use directory junctions if possible on win32, this requires absolute paths
|
|
43
|
+
await fs.symlink(src, dest, "junction");
|
|
44
|
+
} else {
|
|
45
|
+
await fs.symlink(src, dest);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const defaults = {
|
|
50
|
+
whitelist: [],
|
|
51
|
+
blacklist: []
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const linkWorkspaces = async ({ whitelist, blacklist } = defaults) => {
|
|
55
|
+
console.log(`Linking project workspaces...`);
|
|
56
|
+
//eslint-disable-next-line import/dynamic-import-chunkname
|
|
57
|
+
const { PackageJson } = await import("../utils/PackageJson.js");
|
|
58
|
+
|
|
59
|
+
whitelist = (whitelist || []).map(p => path.resolve(p));
|
|
60
|
+
blacklist = (blacklist || []).map(p => path.resolve(p));
|
|
61
|
+
// Filter packages to only those in the whitelisted folders
|
|
62
|
+
//eslint-disable-next-line import/dynamic-import-chunkname
|
|
63
|
+
const getYarnWorkspaces = await import("get-yarn-workspaces").then(m => m.default ?? m);
|
|
64
|
+
const packages = getYarnWorkspaces(process.cwd())
|
|
65
|
+
.map(pkg => pkg.replace(/\//g, path.sep))
|
|
66
|
+
.filter(pkg => {
|
|
67
|
+
const isBlacklisted = blacklist.some(b => pkg.startsWith(b));
|
|
68
|
+
if (isBlacklisted) {
|
|
69
|
+
return false;
|
|
70
|
+
} else if (whitelist.length === 0) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return whitelist.some(w => pkg.startsWith(w));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const lernaJson = path.resolve("lerna.json");
|
|
77
|
+
const lerna = fs.existsSync(lernaJson) ? readJsonSync(lernaJson) : null;
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < packages.length; i++) {
|
|
80
|
+
const packageJson = path.resolve(packages[i], "package.json");
|
|
81
|
+
if (!fs.existsSync(packageJson)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const pkgJson = await PackageJson.fromFile(packageJson);
|
|
86
|
+
const pkg = pkgJson.getJson();
|
|
87
|
+
|
|
88
|
+
let targetDirectory = get(pkg, "publishConfig.directory");
|
|
89
|
+
if (!targetDirectory && lerna) {
|
|
90
|
+
targetDirectory = get(lerna, "command.publish.contents");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const link = path.resolve("node_modules", pkg.name);
|
|
94
|
+
const target = path.resolve(packages[i], targetDirectory || ".");
|
|
95
|
+
|
|
96
|
+
if (!fs.existsSync(target)) {
|
|
97
|
+
fs.mkdirpSync(target);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await fs.mkdirp(path.dirname(link));
|
|
102
|
+
await symlink(target, link);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.log(`Failed ${pkg.name}: ${err.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|