-
-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathbundle-yarn.js
56 lines (47 loc) · 1.39 KB
/
bundle-yarn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { execa } from "execa";
import { $, fs, globby, path } from "zx";
process.once("uncaughtException", (err) => {
process.exit(err.exitCode ?? 1);
});
function toJSON(obj) {
return JSON.stringify(obj, null, " ");
}
// Copy package.json file
const pkg = JSON.parse(await fs.readFile("./package.json", "utf-8"));
delete pkg.scripts;
delete pkg.devDependencies;
delete pkg.babel;
delete pkg.envars;
pkg.bundledDependencies?.forEach((name) => {
delete pkg.dependencies[name];
});
await fs.writeFile("./dist/package.json", toJSON(pkg), "utf-8");
// Copy Yarn files
const yarnFiles = await globby(
["../yarn.lock", "../.yarnrc.yml", "../.yarn/releases", "../.yarn/plugins"],
{ dot: true },
);
await Promise.all(
yarnFiles.map((file) => fs.copy(file, path.join("./dist/tmp", file))),
);
// Disable global cache in Yarn settings
await execa("yarn", ["config", "set", "enableGlobalCache", "false"], {
env: { ...$.env, NODE_OPTIONS: undefined },
stdio: "inherit",
cwd: "./dist",
});
// Install Yarn dependencies
await execa("yarn", ["install"], {
env: {
...$.env,
NODE_OPTIONS: undefined,
YARN_ENABLE_IMMUTABLE_INSTALLS: "false",
},
stdio: "inherit",
cwd: "./dist",
});
// Clean up the output directory
await fs.remove("./dist/.yarn/install-state.gz");
await fs.remove("./dist/.yarn/unplugged");