-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (43 loc) · 1.34 KB
/
index.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
// @ts-check
import { readFile, copyFile} from "node:fs/promises";
import { dirname, join } from "node:path";
/**
* The shelljs package dynamically imports dependencies at runtime.
*
* This prevents esbuild from resolving the imports at compile-time which leads
* to runtime errors.
*
* To solve this issue, we replace the `shelljs/shell.js` file with our own
* file which imports the dependencies explicitely.
*
* @returns {import("esbuild").Plugin}
*/
export default function azurePipelinesTaskLibFix() {
return {
name: "shelljs-fix",
setup(build) {
build.onLoad(
{ filter: /node_modules[\/\\]azure-pipelines-task-lib/ },
async (args) => {
const src = join(dirname(args.path), "./lib.json");
const destDir = build.initialOptions.outfile
? dirname(build.initialOptions.outfile)
: build.initialOptions.outdir;
if (src && destDir) {
const dest = join(destDir, "./lib.json");
await copyFile(src, dest);
}
return undefined;
}
)
build.onLoad(
{ filter: /node_modules[\/\\]shelljs[\/\\]shell\.js/ },
async () => {
const filePath = new URL("./shell.js", import.meta.url);
const contents = await readFile(filePath, "utf8");
return { contents };
}
);
}
}
}