|
f7eb47b…
|
lmata
|
1 |
"use strict"; |
|
f7eb47b…
|
lmata
|
2 |
var __create = Object.create; |
|
f7eb47b…
|
lmata
|
3 |
var __defProp = Object.defineProperty; |
|
f7eb47b…
|
lmata
|
4 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
f7eb47b…
|
lmata
|
5 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
f7eb47b…
|
lmata
|
6 |
var __getProtoOf = Object.getPrototypeOf; |
|
f7eb47b…
|
lmata
|
7 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
f7eb47b…
|
lmata
|
8 |
var __copyProps = (to, from, except, desc) => { |
|
f7eb47b…
|
lmata
|
9 |
if (from && typeof from === "object" || typeof from === "function") { |
|
f7eb47b…
|
lmata
|
10 |
for (let key of __getOwnPropNames(from)) |
|
f7eb47b…
|
lmata
|
11 |
if (!__hasOwnProp.call(to, key) && key !== except) |
|
f7eb47b…
|
lmata
|
12 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
f7eb47b…
|
lmata
|
13 |
} |
|
f7eb47b…
|
lmata
|
14 |
return to; |
|
f7eb47b…
|
lmata
|
15 |
}; |
|
f7eb47b…
|
lmata
|
16 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
|
f7eb47b…
|
lmata
|
17 |
// If the importer is in node compatibility mode or this is not an ESM |
|
f7eb47b…
|
lmata
|
18 |
// file that has been converted to a CommonJS file using a Babel- |
|
f7eb47b…
|
lmata
|
19 |
// compatible transform (i.e. "__esModule" has not been set), then set |
|
f7eb47b…
|
lmata
|
20 |
// "default" to the CommonJS "module.exports" for node compatibility. |
|
f7eb47b…
|
lmata
|
21 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
|
f7eb47b…
|
lmata
|
22 |
mod |
|
f7eb47b…
|
lmata
|
23 |
)); |
|
f7eb47b…
|
lmata
|
24 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
25 |
var import_url = __toESM(require("url")); |
|
f7eb47b…
|
lmata
|
26 |
var import_compilationCache = require("./compilationCache"); |
|
f7eb47b…
|
lmata
|
27 |
var import_portTransport = require("./portTransport"); |
|
f7eb47b…
|
lmata
|
28 |
var import_transform = require("./transform"); |
|
f7eb47b…
|
lmata
|
29 |
var import_util = require("../util"); |
|
f7eb47b…
|
lmata
|
30 |
const esmPreflightExtension = ".esm.preflight"; |
|
f7eb47b…
|
lmata
|
31 |
async function resolve(originalSpecifier, context, defaultResolve) { |
|
f7eb47b…
|
lmata
|
32 |
let specifier = originalSpecifier.replace(esmPreflightExtension, ""); |
|
f7eb47b…
|
lmata
|
33 |
if (context.parentURL && context.parentURL.startsWith("file://")) { |
|
f7eb47b…
|
lmata
|
34 |
const filename = import_url.default.fileURLToPath(context.parentURL); |
|
f7eb47b…
|
lmata
|
35 |
const resolved = (0, import_transform.resolveHook)(filename, specifier); |
|
f7eb47b…
|
lmata
|
36 |
if (resolved !== void 0) |
|
f7eb47b…
|
lmata
|
37 |
specifier = import_url.default.pathToFileURL(resolved).toString(); |
|
f7eb47b…
|
lmata
|
38 |
} |
|
f7eb47b…
|
lmata
|
39 |
const result = await defaultResolve(specifier, context, defaultResolve); |
|
f7eb47b…
|
lmata
|
40 |
if (result?.url && result.url.startsWith("file://")) |
|
f7eb47b…
|
lmata
|
41 |
(0, import_compilationCache.currentFileDepsCollector)()?.add(import_url.default.fileURLToPath(result.url)); |
|
f7eb47b…
|
lmata
|
42 |
if (originalSpecifier.endsWith(esmPreflightExtension)) |
|
f7eb47b…
|
lmata
|
43 |
result.url = result.url + esmPreflightExtension; |
|
f7eb47b…
|
lmata
|
44 |
return result; |
|
f7eb47b…
|
lmata
|
45 |
} |
|
f7eb47b…
|
lmata
|
46 |
const kSupportedFormats = /* @__PURE__ */ new Map([ |
|
f7eb47b…
|
lmata
|
47 |
["commonjs", "commonjs"], |
|
f7eb47b…
|
lmata
|
48 |
["module", "module"], |
|
f7eb47b…
|
lmata
|
49 |
["commonjs-typescript", "commonjs"], |
|
f7eb47b…
|
lmata
|
50 |
["module-typescript", "module"], |
|
f7eb47b…
|
lmata
|
51 |
[null, null], |
|
f7eb47b…
|
lmata
|
52 |
[void 0, void 0] |
|
f7eb47b…
|
lmata
|
53 |
]); |
|
f7eb47b…
|
lmata
|
54 |
async function load(originalModuleUrl, context, defaultLoad) { |
|
f7eb47b…
|
lmata
|
55 |
const moduleUrl = originalModuleUrl.replace(esmPreflightExtension, ""); |
|
f7eb47b…
|
lmata
|
56 |
if (!kSupportedFormats.has(context.format)) |
|
f7eb47b…
|
lmata
|
57 |
return defaultLoad(moduleUrl, context, defaultLoad); |
|
f7eb47b…
|
lmata
|
58 |
if (!moduleUrl.startsWith("file://")) |
|
f7eb47b…
|
lmata
|
59 |
return defaultLoad(moduleUrl, context, defaultLoad); |
|
f7eb47b…
|
lmata
|
60 |
const filename = import_url.default.fileURLToPath(moduleUrl); |
|
f7eb47b…
|
lmata
|
61 |
if (!(0, import_transform.shouldTransform)(filename)) |
|
f7eb47b…
|
lmata
|
62 |
return defaultLoad(moduleUrl, context, defaultLoad); |
|
f7eb47b…
|
lmata
|
63 |
const code = import_fs.default.readFileSync(filename, "utf-8"); |
|
f7eb47b…
|
lmata
|
64 |
const transformed = (0, import_transform.transformHook)(code, filename, moduleUrl); |
|
f7eb47b…
|
lmata
|
65 |
if (transformed.serializedCache) |
|
f7eb47b…
|
lmata
|
66 |
transport?.post("pushToCompilationCache", { cache: transformed.serializedCache }); |
|
f7eb47b…
|
lmata
|
67 |
return { |
|
f7eb47b…
|
lmata
|
68 |
format: kSupportedFormats.get(context.format) || ((0, import_util.fileIsModule)(filename) ? "module" : "commonjs"), |
|
f7eb47b…
|
lmata
|
69 |
source: originalModuleUrl.endsWith(esmPreflightExtension) ? `void 0;` : transformed.code, |
|
f7eb47b…
|
lmata
|
70 |
shortCircuit: true |
|
f7eb47b…
|
lmata
|
71 |
}; |
|
f7eb47b…
|
lmata
|
72 |
} |
|
f7eb47b…
|
lmata
|
73 |
let transport; |
|
f7eb47b…
|
lmata
|
74 |
function initialize(data) { |
|
f7eb47b…
|
lmata
|
75 |
transport = createTransport(data?.port); |
|
f7eb47b…
|
lmata
|
76 |
} |
|
f7eb47b…
|
lmata
|
77 |
function createTransport(port) { |
|
f7eb47b…
|
lmata
|
78 |
return new import_portTransport.PortTransport(port, async (method, params) => { |
|
f7eb47b…
|
lmata
|
79 |
if (method === "setSingleTSConfig") { |
|
f7eb47b…
|
lmata
|
80 |
(0, import_transform.setSingleTSConfig)(params.tsconfig); |
|
f7eb47b…
|
lmata
|
81 |
return; |
|
f7eb47b…
|
lmata
|
82 |
} |
|
f7eb47b…
|
lmata
|
83 |
if (method === "setTransformConfig") { |
|
f7eb47b…
|
lmata
|
84 |
(0, import_transform.setTransformConfig)(params.config); |
|
f7eb47b…
|
lmata
|
85 |
return; |
|
f7eb47b…
|
lmata
|
86 |
} |
|
f7eb47b…
|
lmata
|
87 |
if (method === "addToCompilationCache") { |
|
f7eb47b…
|
lmata
|
88 |
(0, import_compilationCache.addToCompilationCache)(params.cache); |
|
f7eb47b…
|
lmata
|
89 |
return; |
|
f7eb47b…
|
lmata
|
90 |
} |
|
f7eb47b…
|
lmata
|
91 |
if (method === "getCompilationCache") |
|
f7eb47b…
|
lmata
|
92 |
return { cache: (0, import_compilationCache.serializeCompilationCache)() }; |
|
f7eb47b…
|
lmata
|
93 |
if (method === "startCollectingFileDeps") { |
|
f7eb47b…
|
lmata
|
94 |
(0, import_compilationCache.startCollectingFileDeps)(); |
|
f7eb47b…
|
lmata
|
95 |
return; |
|
f7eb47b…
|
lmata
|
96 |
} |
|
f7eb47b…
|
lmata
|
97 |
if (method === "stopCollectingFileDeps") { |
|
f7eb47b…
|
lmata
|
98 |
(0, import_compilationCache.stopCollectingFileDeps)(params.file); |
|
f7eb47b…
|
lmata
|
99 |
return; |
|
f7eb47b…
|
lmata
|
100 |
} |
|
f7eb47b…
|
lmata
|
101 |
}); |
|
f7eb47b…
|
lmata
|
102 |
} |
|
f7eb47b…
|
lmata
|
103 |
module.exports = { initialize, load, resolve }; |