-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.js
executable file
·113 lines (101 loc) · 2.64 KB
/
build.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
// TODO: This borrows from '@yarnpkg/builder', but the only thing we add here
// is raw-loader for '.in` files.
const webpack = require(`webpack`);
const { RawSource } = require(`webpack-sources`);
const IS_PROD = process.argv[2] === `-p`;
const EXTERNALS = [
`@yarnpkg/core`,
`@yarnpkg/fslib`,
`@yarnpkg/plugin-patch`,
`@yarnpkg/plugin-pnp`,
`clipanion`,
`crypto`,
`os`,
`url`,
];
const compiler = webpack({
context: __dirname,
entry: `.`,
mode: IS_PROD ? `production` : `development`,
devtool: false,
node: {
__dirname: false,
__filename: false,
},
output: {
filename: IS_PROD ? `yarn-plugin-nixify.js` : `yarn-plugin-nixify.dev.js`,
libraryTarget: `var`,
library: `plugin`,
},
resolve: {
extensions: [`.mjs`, `.js`, `.ts`, `.tsx`, `.json`],
},
externals: (() => {
const res = {};
for (const name of EXTERNALS) {
res[name] = `commonjs ${name}`;
}
return res;
})(),
module: {
rules: [
{
test: /\.ts$/,
loader: `babel-loader`,
options: {
plugins: [
[`@babel/plugin-proposal-decorators`, { legacy: true }],
[`@babel/plugin-proposal-class-properties`, { loose: true }],
],
presets: ["@babel/preset-typescript"],
},
},
{
test: /\.in$/,
loader: `raw-loader`,
},
],
},
plugins: [
// This plugin wraps the generated bundle so that it doesn't actually
// get evaluated right now - until after we give it a custom require
// function that will be able to fetch the dynamic modules.
{
apply: (compiler) => {
compiler.hooks.compilation.tap(`WrapYarn`, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: `WrapYarn`,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
},
(assets) => {
for (const file in assets) {
assets[file] = new RawSource(
[
`module.exports = {`,
`name: "yarn-plugin-nixify",`,
`factory: function (require) {`,
assets[file].source(),
`return plugin;`,
`}`,
`};`,
].join(`\n`),
);
}
},
);
});
},
},
],
});
compiler.run((err, stats) => {
if (err) {
console.error(err);
process.exit(1);
} else if (stats && stats.compilation.errors.length > 0) {
console.error(stats.toString(`errors-only`));
process.exit(1);
}
});