|
1
|
"use strict"; |
|
2
|
var __create = Object.create; |
|
3
|
var __defProp = Object.defineProperty; |
|
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
5
|
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
6
|
var __getProtoOf = Object.getPrototypeOf; |
|
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
8
|
var __export = (target, all) => { |
|
9
|
for (var name in all) |
|
10
|
__defProp(target, name, { get: all[name], enumerable: true }); |
|
11
|
}; |
|
12
|
var __copyProps = (to, from, except, desc) => { |
|
13
|
if (from && typeof from === "object" || typeof from === "function") { |
|
14
|
for (let key of __getOwnPropNames(from)) |
|
15
|
if (!__hasOwnProp.call(to, key) && key !== except) |
|
16
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
17
|
} |
|
18
|
return to; |
|
19
|
}; |
|
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
|
21
|
// If the importer is in node compatibility mode or this is not an ESM |
|
22
|
// file that has been converted to a CommonJS file using a Babel- |
|
23
|
// compatible transform (i.e. "__esModule" has not been set), then set |
|
24
|
// "default" to the CommonJS "module.exports" for node compatibility. |
|
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
|
26
|
mod |
|
27
|
)); |
|
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
29
|
var esmLoaderHost_exports = {}; |
|
30
|
__export(esmLoaderHost_exports, { |
|
31
|
configureESMLoader: () => configureESMLoader, |
|
32
|
configureESMLoaderTransformConfig: () => configureESMLoaderTransformConfig, |
|
33
|
incorporateCompilationCache: () => incorporateCompilationCache, |
|
34
|
registerESMLoader: () => registerESMLoader, |
|
35
|
startCollectingFileDeps: () => startCollectingFileDeps, |
|
36
|
stopCollectingFileDeps: () => stopCollectingFileDeps |
|
37
|
}); |
|
38
|
module.exports = __toCommonJS(esmLoaderHost_exports); |
|
39
|
var import_url = __toESM(require("url")); |
|
40
|
var import_compilationCache = require("../transform/compilationCache"); |
|
41
|
var import_portTransport = require("../transform/portTransport"); |
|
42
|
var import_transform = require("../transform/transform"); |
|
43
|
let loaderChannel; |
|
44
|
function registerESMLoader() { |
|
45
|
if (process.env.PW_DISABLE_TS_ESM) |
|
46
|
return true; |
|
47
|
if ("Bun" in globalThis) |
|
48
|
return true; |
|
49
|
if (loaderChannel) |
|
50
|
return true; |
|
51
|
const register = require("node:module").register; |
|
52
|
if (!register) |
|
53
|
return false; |
|
54
|
const { port1, port2 } = new MessageChannel(); |
|
55
|
register(import_url.default.pathToFileURL(require.resolve("../transform/esmLoader")), { |
|
56
|
data: { port: port2 }, |
|
57
|
transferList: [port2] |
|
58
|
}); |
|
59
|
loaderChannel = createPortTransport(port1); |
|
60
|
return true; |
|
61
|
} |
|
62
|
function createPortTransport(port) { |
|
63
|
return new import_portTransport.PortTransport(port, async (method, params) => { |
|
64
|
if (method === "pushToCompilationCache") |
|
65
|
(0, import_compilationCache.addToCompilationCache)(params.cache); |
|
66
|
}); |
|
67
|
} |
|
68
|
async function startCollectingFileDeps() { |
|
69
|
if (!loaderChannel) |
|
70
|
return; |
|
71
|
await loaderChannel.send("startCollectingFileDeps", {}); |
|
72
|
} |
|
73
|
async function stopCollectingFileDeps(file) { |
|
74
|
if (!loaderChannel) |
|
75
|
return; |
|
76
|
await loaderChannel.send("stopCollectingFileDeps", { file }); |
|
77
|
} |
|
78
|
async function incorporateCompilationCache() { |
|
79
|
if (!loaderChannel) |
|
80
|
return; |
|
81
|
const result = await loaderChannel.send("getCompilationCache", {}); |
|
82
|
(0, import_compilationCache.addToCompilationCache)(result.cache); |
|
83
|
} |
|
84
|
async function configureESMLoader() { |
|
85
|
if (!loaderChannel) |
|
86
|
return; |
|
87
|
await loaderChannel.send("setSingleTSConfig", { tsconfig: (0, import_transform.singleTSConfig)() }); |
|
88
|
await loaderChannel.send("addToCompilationCache", { cache: (0, import_compilationCache.serializeCompilationCache)() }); |
|
89
|
} |
|
90
|
async function configureESMLoaderTransformConfig() { |
|
91
|
if (!loaderChannel) |
|
92
|
return; |
|
93
|
await loaderChannel.send("setSingleTSConfig", { tsconfig: (0, import_transform.singleTSConfig)() }); |
|
94
|
await loaderChannel.send("setTransformConfig", { config: (0, import_transform.transformConfig)() }); |
|
95
|
} |
|
96
|
// Annotate the CommonJS export names for ESM import in node: |
|
97
|
0 && (module.exports = { |
|
98
|
configureESMLoader, |
|
99
|
configureESMLoaderTransformConfig, |
|
100
|
incorporateCompilationCache, |
|
101
|
registerESMLoader, |
|
102
|
startCollectingFileDeps, |
|
103
|
stopCollectingFileDeps |
|
104
|
}); |
|
105
|
|