@freshpack/webpack 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +13 -12
- package/denoEnv.d.ts +12 -0
- package/denoEnv.js +49 -0
- package/denoEnv.js.map +1 -0
- package/fresh.d.ts +39 -0
- package/fresh.js +245 -0
- package/fresh.js.map +1 -0
- package/importMetaResolve.d.ts +4 -0
- package/importMetaResolve.js +50 -0
- package/importMetaResolve.js.map +1 -0
- package/mod.d.ts +8 -0
- package/mod.js +9 -0
- package/mod.js.map +1 -0
- package/package.json +81 -9
- package/prefresh-forked/index.d.ts +15 -0
- package/prefresh-forked/index.js +59 -0
- package/prefresh-forked/index.js.map +1 -0
- package/prefresh-forked/loader/index.d.ts +2 -0
- package/prefresh-forked/loader/index.js +5 -0
- package/prefresh-forked/loader/index.js.map +1 -0
- package/prefresh-forked/utils/Runtime.d.ts +5 -0
- package/prefresh-forked/utils/Runtime.js +27 -0
- package/prefresh-forked/utils/Runtime.js.map +1 -0
- package/prefresh-forked/utils/constants.d.ts +8 -0
- package/prefresh-forked/utils/constants.js +12 -0
- package/prefresh-forked/utils/constants.js.map +1 -0
- package/prefresh-forked/utils/prefresh.d.ts +5 -0
- package/prefresh-forked/utils/{prefresh.ts → prefresh.js} +8 -27
- package/prefresh-forked/utils/prefresh.js.map +1 -0
- package/quasiquote.d.ts +9 -0
- package/quasiquote.js +32 -0
- package/quasiquote.js.map +1 -0
- package/rawBytesLoader.d.ts +5 -0
- package/rawBytesLoader.js +10 -0
- package/rawBytesLoader.js.map +1 -0
- package/rawImports.d.ts +13 -0
- package/rawImports.js +44 -0
- package/rawImports.js.map +1 -0
- package/requireHook.d.ts +1 -0
- package/{requireHook.ts → requireHook.js} +5 -10
- package/requireHook.js.map +1 -0
- package/resolve.d.ts +11 -0
- package/resolve.js +395 -0
- package/resolve.js.map +1 -0
- package/transpileLoader.d.ts +9 -0
- package/transpileLoader.js +46 -0
- package/transpileLoader.js.map +1 -0
- package/unmap.d.ts +9 -0
- package/unmap.js +94 -0
- package/unmap.js.map +1 -0
- package/util.d.ts +9 -0
- package/{util.ts → util.js} +13 -19
- package/util.js.map +1 -0
- package/viteComment.d.ts +8 -0
- package/viteComment.js +28 -0
- package/viteComment.js.map +1 -0
- package/buildCacheUtil.ts +0 -11
- package/denoEnv.ts +0 -78
- package/fresh.ts +0 -391
- package/mod.ts +0 -7
- package/prefresh-forked/index.ts +0 -114
- package/prefresh-forked/loader/index.ts +0 -10
- package/prefresh-forked/utils/Runtime.ts +0 -79
- package/prefresh-forked/utils/constants.ts +0 -35
- package/prefresh-forked/utils/createTemplate.ts +0 -76
- package/prefresh-forked/utils/injectEntry.ts +0 -28
- package/quasiquote.ts +0 -44
- package/rawBytesLoader.ts +0 -17
- package/rawImports.ts +0 -85
- package/resolve.ts +0 -588
- package/transpileLoader.ts +0 -59
- package/unmap.ts +0 -154
- package/viteComment.ts +0 -41
package/resolve.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { RequestedModuleType, ResolutionMode, Workspace } from "@deno/loader";
|
|
2
|
+
import { assert, unreachable } from "@std/assert";
|
|
3
|
+
import Webpack from "webpack";
|
|
4
|
+
import { Buffer } from "node:buffer";
|
|
5
|
+
import { ensureModPath, stripFileUrl } from "./util.js";
|
|
6
|
+
import { dirname } from "@std/path";
|
|
7
|
+
import { defineRequire } from "./requireHook.js";
|
|
8
|
+
import { registerDenoLoader } from "./transpileLoader.js";
|
|
9
|
+
const internalTranspileLoader = defineRequire("@freshpack/webpack/internal-deno-transpile-loader", await import("./transpileLoader.js"));
|
|
10
|
+
function resolverSpan(logSuccess, name, ...args) {
|
|
11
|
+
let isResolved;
|
|
12
|
+
let timeoutId = setTimeout(() => {
|
|
13
|
+
console.error("[RESOLVE]", "possibly stuck at", name, ...args);
|
|
14
|
+
if (isResolved !== undefined) {
|
|
15
|
+
console.error(" ", "...but it was resolved:", ...isResolved);
|
|
16
|
+
}
|
|
17
|
+
}, 5000);
|
|
18
|
+
const cancelStuck = () => {
|
|
19
|
+
if (timeoutId !== undefined) {
|
|
20
|
+
clearTimeout(timeoutId);
|
|
21
|
+
timeoutId = undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
let postponed = false;
|
|
25
|
+
return {
|
|
26
|
+
simplify(...newArgs) {
|
|
27
|
+
args = newArgs;
|
|
28
|
+
},
|
|
29
|
+
errored(e, ...err) {
|
|
30
|
+
cancelStuck();
|
|
31
|
+
console.error("[RESOLVE]", "errored", name, ...args, "=>", e, ...err);
|
|
32
|
+
},
|
|
33
|
+
resolved(...out) {
|
|
34
|
+
cancelStuck();
|
|
35
|
+
if (isResolved === undefined) {
|
|
36
|
+
isResolved = out;
|
|
37
|
+
if (logSuccess) {
|
|
38
|
+
console.info("[RESOLVE]", name, ...args, "=>", ...out);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
console.error("[RESOLVE]", "resolved twice", name, ...args, "=>", ...out);
|
|
42
|
+
console.error(" ", "...previously resolved to:", ...isResolved);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
[Symbol.dispose]() {
|
|
46
|
+
if (postponed) return;
|
|
47
|
+
cancelStuck();
|
|
48
|
+
if (isResolved === undefined) {
|
|
49
|
+
console.error("[RESOLVE]", "missing resolved() call!", name, ...args);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
postpone() {
|
|
53
|
+
postponed = true;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const MATCH_RESOURCE = /^([^!]+)!=!/;
|
|
58
|
+
function requestedModuleType(type) {
|
|
59
|
+
if (type === "asset/source") return RequestedModuleType.Text;
|
|
60
|
+
if (type.startsWith("asset/")) return RequestedModuleType.Bytes;
|
|
61
|
+
return RequestedModuleType.Default;
|
|
62
|
+
}
|
|
63
|
+
async function simpleDenoResolve(loader, issuer, request, esm) {
|
|
64
|
+
const matchResource = MATCH_RESOURCE.exec(request);
|
|
65
|
+
if (matchResource) {
|
|
66
|
+
const resolved = await simpleDenoResolve(loader, issuer, request.slice(matchResource[0].length), esm);
|
|
67
|
+
return `${matchResource[0]}${resolved}`;
|
|
68
|
+
}
|
|
69
|
+
let resolution;
|
|
70
|
+
if (request.startsWith("/") && issuer.startsWith("https://")) {
|
|
71
|
+
resolution = new URL(request, new URL(issuer).origin).href;
|
|
72
|
+
} else if (request.startsWith("/")) {
|
|
73
|
+
resolution = `file://${request}`;
|
|
74
|
+
} else if (request === ".") {
|
|
75
|
+
resolution = `file://${dirname(issuer)}`;
|
|
76
|
+
} else {
|
|
77
|
+
resolution = await loader.resolve(request, issuer, esm ? ResolutionMode.Import : ResolutionMode.Require);
|
|
78
|
+
}
|
|
79
|
+
if (resolution.startsWith("node:")) {
|
|
80
|
+
// PASS: Fallback or external
|
|
81
|
+
} else if (resolution.startsWith("https:")) {
|
|
82
|
+
// PASS: https loader
|
|
83
|
+
} else if (resolution.startsWith("file:")) {
|
|
84
|
+
if (issuer.startsWith("https://")) {
|
|
85
|
+
// PASS: Disambiguate origin-relative,
|
|
86
|
+
// we don't want to convert /home/user/.cache/deno/npm/.../file.ts imported from
|
|
87
|
+
// https://esm.sh to become https://esm.sh/home/user/...
|
|
88
|
+
} else {
|
|
89
|
+
resolution = stripFileUrl(resolution);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
assert(false, `unexpected resolution: ${resolution}`);
|
|
93
|
+
}
|
|
94
|
+
return resolution;
|
|
95
|
+
}
|
|
96
|
+
class FixupResolvePlugin {
|
|
97
|
+
apply(resolver) {
|
|
98
|
+
const resolved = resolver.getHook("resolved");
|
|
99
|
+
for (const hook of ["resolve", "internal-resolve"]) {
|
|
100
|
+
resolver.getHook(hook).tapAsync({
|
|
101
|
+
name: "Ignore https requests",
|
|
102
|
+
stage: -100000
|
|
103
|
+
}, (req, ctx, cb) => {
|
|
104
|
+
if (req.path && req.path.startsWith("https://") && req.request === "." || req.request && req.request.startsWith("https://")) {
|
|
105
|
+
return resolver.doResolve(resolved, req, "context resolve", ctx, cb);
|
|
106
|
+
}
|
|
107
|
+
// console.log("DIR RESOLVE!!!", req);
|
|
108
|
+
return cb(null);
|
|
109
|
+
// return cb(null, ...args);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// resolver.hooks.result.tap({
|
|
113
|
+
// name: "resolvers in https requests",
|
|
114
|
+
// stage: -100000,
|
|
115
|
+
// }, (req, ctx) => {
|
|
116
|
+
// console.log("post resolve", req);
|
|
117
|
+
// return;
|
|
118
|
+
// });
|
|
119
|
+
// resolver.hooks.resolve.tap({ name: "Fixup" }, (req) => {
|
|
120
|
+
// console.log('fixup resolver', req.request);
|
|
121
|
+
// return req;
|
|
122
|
+
// });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class DenoResolvePlugin {
|
|
126
|
+
constructor(jsr) {
|
|
127
|
+
this.jsr = jsr;
|
|
128
|
+
}
|
|
129
|
+
apply(resolver) {
|
|
130
|
+
// console.log("HOOKS", resolver.hooks);
|
|
131
|
+
const source = resolver.getHook("resolve");
|
|
132
|
+
const target = resolver.getHook("resolved");
|
|
133
|
+
source.tapAsync({
|
|
134
|
+
name: "Deno"
|
|
135
|
+
}, async (request, ctx, cb) => {
|
|
136
|
+
using span = resolverSpan(this.jsr.opts.debug, "deno resolver", request, ctx);
|
|
137
|
+
try {
|
|
138
|
+
const loader = await this.jsr.loader;
|
|
139
|
+
let requestIssuer;
|
|
140
|
+
if (request.context && "issuer" in request.context) {
|
|
141
|
+
const issuer = request.context.issuer;
|
|
142
|
+
assert(typeof issuer === "string" || issuer === null, "invalid context issuer");
|
|
143
|
+
if (issuer !== "" && issuer !== null) {
|
|
144
|
+
requestIssuer = issuer;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (requestIssuer === undefined && request.path) {
|
|
148
|
+
requestIssuer = ensureModPath(request.path);
|
|
149
|
+
}
|
|
150
|
+
assert(requestIssuer !== undefined, "failed to determine requestIssuer");
|
|
151
|
+
const requestRequest = request.request;
|
|
152
|
+
assert(requestRequest !== undefined, "failed to determine requestRequest");
|
|
153
|
+
span.simplify(requestIssuer, requestRequest);
|
|
154
|
+
const resolution = await simpleDenoResolve(loader, requestIssuer, requestRequest, request.module ?? true);
|
|
155
|
+
const resolvedPath = resolution.startsWith("file://") ? stripFileUrl(resolution) : resolution;
|
|
156
|
+
return resolver.doResolve(target, Object.assign({}, request, {
|
|
157
|
+
path: resolvedPath,
|
|
158
|
+
request: undefined
|
|
159
|
+
}), `resolved by deno ${request.request} (from ${request.path})`, ctx, (err, result) => {
|
|
160
|
+
span.resolved("doResolve result", resolution, err, result);
|
|
161
|
+
if (err !== undefined || result !== undefined) {
|
|
162
|
+
return cb(err, result);
|
|
163
|
+
}
|
|
164
|
+
cb(null, null);
|
|
165
|
+
});
|
|
166
|
+
} catch (e) {
|
|
167
|
+
span.errored(e, request, ctx);
|
|
168
|
+
cb(e, null);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function fillResourceData(data, loader, url) {
|
|
174
|
+
data.__resolvedByFreshpack = {
|
|
175
|
+
data,
|
|
176
|
+
url,
|
|
177
|
+
loaded: undefined
|
|
178
|
+
};
|
|
179
|
+
if (url.protocol === "file:") {
|
|
180
|
+
data.resource = url.pathname;
|
|
181
|
+
data.path = url.pathname;
|
|
182
|
+
data.data.path = url.pathname;
|
|
183
|
+
data.context = dirname(url.pathname);
|
|
184
|
+
} else {
|
|
185
|
+
const loaded = await loader.load(url.href, RequestedModuleType.Default);
|
|
186
|
+
data.__resolvedByFreshpack.loaded = loaded;
|
|
187
|
+
data.resource = loaded.specifier;
|
|
188
|
+
data.path = loaded.specifier;
|
|
189
|
+
data.data.path = loaded.specifier;
|
|
190
|
+
data.context = new URL(".", url).href.slice(0, -1);
|
|
191
|
+
}
|
|
192
|
+
data.query = url.search;
|
|
193
|
+
data.data.query = url.search;
|
|
194
|
+
data.fragment = url.hash;
|
|
195
|
+
|
|
196
|
+
// data.type = "application/javascript";
|
|
197
|
+
}
|
|
198
|
+
function breakResourceData(data) {
|
|
199
|
+
data.path = "error";
|
|
200
|
+
data.context = "error";
|
|
201
|
+
data.resource = "error";
|
|
202
|
+
}
|
|
203
|
+
function ensurePluginList(resolver, list, append) {
|
|
204
|
+
if (resolver[list] === undefined) {
|
|
205
|
+
resolver[list] = [];
|
|
206
|
+
}
|
|
207
|
+
assert(Array.isArray(resolver[list]));
|
|
208
|
+
resolver[list].push(append);
|
|
209
|
+
}
|
|
210
|
+
export class DenoLoaderPlugin {
|
|
211
|
+
workspace;
|
|
212
|
+
#transpileLoaderId;
|
|
213
|
+
#loader;
|
|
214
|
+
get loader() {
|
|
215
|
+
return this.#loader ??= this.workspace.createLoader();
|
|
216
|
+
}
|
|
217
|
+
constructor(opts, patchImport = (_, v) => v) {
|
|
218
|
+
this.opts = opts;
|
|
219
|
+
this.patchImport = patchImport;
|
|
220
|
+
opts.noTranspile = false;
|
|
221
|
+
opts.preserveJsx = false;
|
|
222
|
+
opts.platform = "browser";
|
|
223
|
+
this.workspace = new Workspace(opts);
|
|
224
|
+
this.#transpileLoaderId = registerDenoLoader(() => this.loader);
|
|
225
|
+
}
|
|
226
|
+
apply(compiler) {
|
|
227
|
+
if (compiler.options.resolve.plugins === undefined) {
|
|
228
|
+
compiler.options.resolve.plugins = [];
|
|
229
|
+
}
|
|
230
|
+
assert(Array.isArray(compiler.options.resolve.plugins));
|
|
231
|
+
compiler.options.resolve.plugins.push(new FixupResolvePlugin());
|
|
232
|
+
if (compiler.options.resolveLoader.plugins === undefined) {
|
|
233
|
+
compiler.options.resolveLoader.plugins = [];
|
|
234
|
+
}
|
|
235
|
+
assert(Array.isArray(compiler.options.resolveLoader.plugins));
|
|
236
|
+
compiler.options.resolveLoader.plugins.push(new DenoResolvePlugin(this));
|
|
237
|
+
compiler.options.resolve.modules = [];
|
|
238
|
+
compiler.options.resolve.roots = [];
|
|
239
|
+
compiler.options.resolve.descriptionFiles = [];
|
|
240
|
+
compiler.options.resolveLoader.modules = [];
|
|
241
|
+
compiler.options.resolveLoader.descriptionFiles = [];
|
|
242
|
+
compiler.options.externalsPresets.web = false;
|
|
243
|
+
compiler.options.externalsPresets.webAsync = false;
|
|
244
|
+
if (!compiler.options.output.enabledLibraryTypes) {
|
|
245
|
+
compiler.options.output.enabledLibraryTypes = [];
|
|
246
|
+
}
|
|
247
|
+
if (!compiler.options.output.enabledLibraryTypes.includes("module")) {
|
|
248
|
+
compiler.options.output.enabledLibraryTypes.push("module");
|
|
249
|
+
}
|
|
250
|
+
compiler.options.output.library = {
|
|
251
|
+
type: "module"
|
|
252
|
+
};
|
|
253
|
+
compiler.options.output.module = true;
|
|
254
|
+
compiler.options.experiments.outputModule = true;
|
|
255
|
+
|
|
256
|
+
// Deno provides its own type-stripping when no ts loader is present
|
|
257
|
+
// It is not required since deno-loader handles typescript.
|
|
258
|
+
compiler.options.experiments.typescript = false;
|
|
259
|
+
compiler.hooks.compilation.tap("JsrPlugin", (compilation, {
|
|
260
|
+
normalModuleFactory
|
|
261
|
+
}) => {
|
|
262
|
+
normalModuleFactory.hooks.afterResolve.tap("JsrPlugin", ({
|
|
263
|
+
createData: data
|
|
264
|
+
}) => {
|
|
265
|
+
const resource = data.resource;
|
|
266
|
+
if (resource === undefined || resource.includes("://") || !/\.[cm]?[jt]sx?$/.test(resource)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
data.loaders.push({
|
|
270
|
+
loader: internalTranspileLoader,
|
|
271
|
+
options: {
|
|
272
|
+
id: this.#transpileLoaderId
|
|
273
|
+
},
|
|
274
|
+
ident: null,
|
|
275
|
+
type: null
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
normalModuleFactory.hooks.beforeResolve.tapPromise("JsrPlugin", async resolveData => {
|
|
279
|
+
using span = resolverSpan(this.opts.debug, "jsr beforeResolve", resolveData);
|
|
280
|
+
try {
|
|
281
|
+
// try {
|
|
282
|
+
const loader = await this.loader;
|
|
283
|
+
let requestIssuer;
|
|
284
|
+
if (resolveData.contextInfo.issuer !== "") {
|
|
285
|
+
requestIssuer = resolveData.contextInfo.issuer;
|
|
286
|
+
}
|
|
287
|
+
if (requestIssuer === undefined || requestIssuer === null) {
|
|
288
|
+
requestIssuer = ensureModPath(resolveData.context);
|
|
289
|
+
}
|
|
290
|
+
assert(requestIssuer != undefined, "failed to determine request issuer");
|
|
291
|
+
let requestRequest = resolveData.request;
|
|
292
|
+
const dependencyType = resolveData.dependencyType;
|
|
293
|
+
span.simplify({
|
|
294
|
+
requestIssuer,
|
|
295
|
+
requestRequest,
|
|
296
|
+
dependencyType
|
|
297
|
+
});
|
|
298
|
+
if (requestRequest.startsWith("data:") || requestRequest.startsWith("https:") && !requestRequest.startsWith("https://jsr.io/")) {
|
|
299
|
+
// IDK why those requests even land in this method in some circumstances, returning false
|
|
300
|
+
// here makes them being processed by the handlers below. Most probably I'm missing something,
|
|
301
|
+
// or this webpack api is not intended for such huge loaded replacements.
|
|
302
|
+
span.resolved("delegate-builtin");
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
if (dependencyType === "url" &&
|
|
306
|
+
// new URL() references are always relative, but import.meta.resolve() takes import specifiers.
|
|
307
|
+
resolveData.dependencies[0]?.type !== "import.meta.resolve()") {
|
|
308
|
+
requestRequest = "./" + requestRequest;
|
|
309
|
+
}
|
|
310
|
+
requestRequest = this.patchImport(requestIssuer, requestRequest);
|
|
311
|
+
const resolution = await simpleDenoResolve(loader, requestIssuer, requestRequest, true);
|
|
312
|
+
span.resolved(resolution);
|
|
313
|
+
resolveData.request = this.patchImport(requestIssuer, resolution);
|
|
314
|
+
} catch (e) {
|
|
315
|
+
span.errored(e);
|
|
316
|
+
throw e;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
normalModuleFactory.hooks.resolveForScheme.for("node").tapPromise("JsrPlugin", async (resourceData, resolveData) => {
|
|
320
|
+
using span = resolverSpan(this.opts.debug, "node resolveForScheme", resolveData.request);
|
|
321
|
+
resourceData.path = false;
|
|
322
|
+
resourceData.data.path = false;
|
|
323
|
+
span.resolved("stubbed: empty module");
|
|
324
|
+
return true;
|
|
325
|
+
});
|
|
326
|
+
normalModuleFactory.hooks.resolveForScheme.for("jsr").tapPromise("JsrPlugin", async (resourceData, resolveData) => {
|
|
327
|
+
using span = resolverSpan(this.opts.debug, "jsr resolveForScheme", resolveData);
|
|
328
|
+
breakResourceData(resourceData);
|
|
329
|
+
unreachable("jsr should be resolved to https by deno resolver");
|
|
330
|
+
});
|
|
331
|
+
normalModuleFactory.hooks.resolveForScheme.for("npm").tapPromise("JsrPlugin", async (resourceData, resolveData) => {
|
|
332
|
+
using span = resolverSpan(this.opts.debug, "npm resolveForScheme", resolveData);
|
|
333
|
+
breakResourceData(resourceData);
|
|
334
|
+
unreachable("npm should be resolved to files by deno resolver");
|
|
335
|
+
});
|
|
336
|
+
normalModuleFactory.hooks.resolveForScheme.for("https").tapPromise("JsrPlugin", async (resourceData, resolveData) => {
|
|
337
|
+
using span = resolverSpan(this.opts.debug, "https resolveForScheme", resolveData.request);
|
|
338
|
+
const loader = await this.loader;
|
|
339
|
+
// const newResourceData = {...resourceData};
|
|
340
|
+
await fillResourceData(resourceData, loader, new URL(resolveData.request));
|
|
341
|
+
span.resolved("done");
|
|
342
|
+
return true;
|
|
343
|
+
});
|
|
344
|
+
normalModuleFactory.hooks.resolveInScheme.for("https").tapPromise("JsrPlugin", async (resourceData, data) => {
|
|
345
|
+
using span = resolverSpan(this.opts.debug, "https resolveInScheme", resourceData, data.contextInfo, data.request);
|
|
346
|
+
try {
|
|
347
|
+
const loader = await this.loader;
|
|
348
|
+
const requestRequest = data.request;
|
|
349
|
+
if (requestRequest.startsWith("/")) {
|
|
350
|
+
const requestIssuer = data.contextInfo.issuer;
|
|
351
|
+
assert(requestIssuer && requestIssuer.startsWith("https://"), `unexpected /-prefixed request without https:// issuer: ${requestRequest}`);
|
|
352
|
+
const issuerUrl = new URL(requestIssuer);
|
|
353
|
+
const resolved = new URL(requestRequest, issuerUrl.origin);
|
|
354
|
+
span.resolved("origin-relative url", resolved.href);
|
|
355
|
+
await fillResourceData(resourceData, loader, resolved);
|
|
356
|
+
return true;
|
|
357
|
+
} else {
|
|
358
|
+
const requestIssuer = data.contextInfo.issuer;
|
|
359
|
+
assert(requestIssuer !== "");
|
|
360
|
+
const resolved = await loader.resolve(requestRequest, requestIssuer, ResolutionMode.Import);
|
|
361
|
+
span.resolved("url resolved", resolved);
|
|
362
|
+
assert(resolved.startsWith("https:"));
|
|
363
|
+
await fillResourceData(resourceData, loader, new URL(resolved));
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
} catch (e) {
|
|
367
|
+
span.errored(e);
|
|
368
|
+
breakResourceData(resourceData);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
const hooks = compiler.webpack.NormalModule.getCompilationHooks(compilation);
|
|
372
|
+
hooks.readResourceForScheme.for("node").tapAsync("JsrPlugin", async (_resource, _module, cb) => {
|
|
373
|
+
cb(null, Buffer.from("module.exports = {};"));
|
|
374
|
+
});
|
|
375
|
+
hooks.readResourceForScheme.for("jsr").tapPromise("JsrPlugin", async (resource, module) => {
|
|
376
|
+
using span = resolverSpan(this.opts.debug, "jsr loadResourceForScheme", resource);
|
|
377
|
+
unreachable("jsr should be resolved to https by deno resolver");
|
|
378
|
+
});
|
|
379
|
+
hooks.readResourceForScheme.for("https").tapAsync("JsrPlugin", async (resource, module, cb) => {
|
|
380
|
+
using span = resolverSpan(this.opts.debug, "https readResourceForScheme", resource, module.type);
|
|
381
|
+
try {
|
|
382
|
+
const loader = await this.loader;
|
|
383
|
+
const loaded = await loader.load(resource, requestedModuleType(module.type));
|
|
384
|
+
// TODO: Should import assertions be handled somehow?
|
|
385
|
+
span.resolved(loaded);
|
|
386
|
+
cb(null, Buffer.from(loaded.code));
|
|
387
|
+
} catch (e) {
|
|
388
|
+
span.errored(e);
|
|
389
|
+
cb(e);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=resolve.js.map
|
package/resolve.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["resolve.ts"],"sourcesContent":["import {\n type Loader,\n RequestedModuleType,\n ResolutionMode,\n Workspace,\n type WorkspaceOptions,\n} from \"@deno/loader\";\nimport { assert, unreachable } from \"@std/assert\";\nimport Webpack, { type Compiler } from \"webpack\";\nimport { Buffer } from \"node:buffer\";\nimport { ensureModPath, stripFileUrl } from \"./util.ts\";\nimport { dirname } from \"@std/path\";\nimport { defineRequire } from \"./requireHook.ts\";\nimport { registerDenoLoader } from \"./transpileLoader.ts\";\n\nconst internalTranspileLoader = defineRequire(\n \"@freshpack/webpack/internal-deno-transpile-loader\",\n await import(\"./transpileLoader.ts\"),\n);\n\nfunction resolverSpan(\n logSuccess: boolean | undefined,\n name: string,\n ...args: unknown[]\n) {\n let isResolved: undefined | unknown[];\n let timeoutId: NodeJS.Timeout | undefined = setTimeout(() => {\n console.error(\"[RESOLVE]\", \"possibly stuck at\", name, ...args);\n if (isResolved !== undefined) {\n console.error(\" \", \"...but it was resolved:\", ...isResolved);\n }\n }, 5000);\n const cancelStuck = () => {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n };\n let postponed = false;\n return {\n simplify(...newArgs: unknown[]) {\n args = newArgs;\n },\n errored(e: unknown, ...err: unknown[]) {\n cancelStuck();\n console.error(\"[RESOLVE]\", \"errored\", name, ...args, \"=>\", e, ...err);\n },\n resolved(...out: unknown[]) {\n cancelStuck();\n if (isResolved === undefined) {\n isResolved = out;\n if (logSuccess) {\n console.info(\"[RESOLVE]\", name, ...args, \"=>\", ...out);\n }\n } else {\n console.error(\n \"[RESOLVE]\",\n \"resolved twice\",\n name,\n ...args,\n \"=>\",\n ...out,\n );\n console.error(\" \", \"...previously resolved to:\", ...isResolved);\n }\n },\n [Symbol.dispose]() {\n if (postponed) return;\n cancelStuck();\n if (isResolved === undefined) {\n console.error(\"[RESOLVE]\", \"missing resolved() call!\", name, ...args);\n }\n },\n postpone() {\n postponed = true;\n },\n };\n}\n\nconst MATCH_RESOURCE = /^([^!]+)!=!/;\n\nfunction requestedModuleType(type: string): RequestedModuleType {\n if (type === \"asset/source\") return RequestedModuleType.Text;\n if (type.startsWith(\"asset/\")) return RequestedModuleType.Bytes;\n return RequestedModuleType.Default;\n}\n\nasync function simpleDenoResolve(\n loader: Loader,\n issuer: string,\n request: string,\n esm: boolean,\n): Promise<string> {\n const matchResource = MATCH_RESOURCE.exec(request);\n if (matchResource) {\n const resolved = await simpleDenoResolve(\n loader,\n issuer,\n request.slice(matchResource[0].length),\n esm,\n );\n return `${matchResource[0]}${resolved}`;\n }\n let resolution: string | undefined;\n if (request.startsWith(\"/\") && issuer.startsWith(\"https://\")) {\n resolution = new URL(request, new URL(issuer).origin).href;\n } else if (request.startsWith(\"/\")) {\n resolution = `file://${request}`;\n } else if (request === \".\") {\n resolution = `file://${dirname(issuer)}`;\n } else {\n resolution = await loader.resolve(\n request,\n issuer,\n esm ? ResolutionMode.Import : ResolutionMode.Require,\n );\n }\n if (resolution.startsWith(\"node:\")) {\n // PASS: Fallback or external\n } else if (\n resolution.startsWith(\"https:\")\n ) {\n // PASS: https loader\n } else if (resolution.startsWith(\"file:\")) {\n if (issuer.startsWith(\"https://\")) {\n // PASS: Disambiguate origin-relative,\n // we don't want to convert /home/user/.cache/deno/npm/.../file.ts imported from\n // https://esm.sh to become https://esm.sh/home/user/...\n } else {\n resolution = stripFileUrl(resolution);\n }\n } else {\n assert(false, `unexpected resolution: ${resolution}`);\n }\n return resolution;\n}\n\nclass FixupResolvePlugin {\n apply(resolver: Webpack.Resolver) {\n const resolved = resolver.getHook(\"resolved\");\n for (const hook of [\"resolve\", \"internal-resolve\"]) {\n resolver.getHook(hook).tapAsync({\n name: \"Ignore https requests\",\n stage: -100000,\n }, (req, ctx, cb) => {\n if (\n req.path && req.path.startsWith(\"https://\") && req.request === \".\" ||\n req.request && req.request.startsWith(\"https://\")\n ) {\n return resolver.doResolve(resolved, req, \"context resolve\", ctx, cb);\n }\n // console.log(\"DIR RESOLVE!!!\", req);\n return cb(null);\n // return cb(null, ...args);\n });\n }\n // resolver.hooks.result.tap({\n // name: \"resolvers in https requests\",\n // stage: -100000,\n // }, (req, ctx) => {\n // console.log(\"post resolve\", req);\n // return;\n // });\n // resolver.hooks.resolve.tap({ name: \"Fixup\" }, (req) => {\n // console.log('fixup resolver', req.request);\n // return req;\n // });\n }\n}\n\nclass DenoResolvePlugin {\n constructor(\n public jsr: DenoLoaderPlugin,\n ) {\n }\n apply(resolver: Webpack.Resolver) {\n // console.log(\"HOOKS\", resolver.hooks);\n const source = resolver.getHook(\"resolve\");\n const target = resolver.getHook(\"resolved\");\n source.tapAsync(\n { name: \"Deno\" },\n async (request, ctx, cb) => {\n using span = resolverSpan(\n this.jsr.opts.debug,\n \"deno resolver\",\n request,\n ctx,\n );\n try {\n const loader = await this.jsr.loader;\n let requestIssuer: string | undefined;\n if (request.context && \"issuer\" in request.context) {\n const issuer = request.context.issuer;\n assert(\n typeof issuer === \"string\" || issuer === null,\n \"invalid context issuer\",\n );\n if (issuer !== \"\" && issuer !== null) {\n requestIssuer = issuer;\n }\n }\n if (requestIssuer === undefined && request.path) {\n requestIssuer = ensureModPath(request.path);\n }\n assert(\n requestIssuer !== undefined,\n \"failed to determine requestIssuer\",\n );\n const requestRequest = request.request;\n assert(\n requestRequest !== undefined,\n \"failed to determine requestRequest\",\n );\n span.simplify(requestIssuer, requestRequest);\n const resolution = await simpleDenoResolve(\n loader,\n requestIssuer,\n requestRequest,\n request.module ?? true,\n );\n const resolvedPath = resolution.startsWith(\"file://\")\n ? stripFileUrl(resolution)\n : resolution;\n return resolver.doResolve(\n target,\n Object.assign({}, request, {\n path: resolvedPath,\n request: undefined,\n }),\n `resolved by deno ${request.request} (from ${request.path})`,\n ctx,\n (err, result) => {\n span.resolved(\"doResolve result\", resolution, err, result);\n if (err !== undefined || result !== undefined) {\n return cb(err, result);\n }\n cb(null, null);\n },\n );\n } catch (e: unknown) {\n span.errored(e, request, ctx);\n cb(e as Error, null);\n }\n },\n );\n }\n}\n\ntype ResourceData = {\n path?: string;\n context?: string;\n resource?: string;\n query?: string;\n fragment?: string;\n type?: string;\n data: { path?: string | false; query?: string };\n};\nasync function fillResourceData(data: ResourceData, loader: Loader, url: URL) {\n (data as any).__resolvedByFreshpack = { data, url, loaded: undefined };\n if (url.protocol === \"file:\") {\n data.resource = url.pathname;\n data.path = url.pathname;\n data.data.path = url.pathname;\n data.context = dirname(url.pathname);\n } else {\n const loaded = await loader.load(url.href, RequestedModuleType.Default);\n (data as any).__resolvedByFreshpack.loaded = loaded;\n data.resource = loaded.specifier;\n data.path = loaded.specifier;\n data.data.path = loaded.specifier;\n data.context = new URL(\".\", url).href.slice(0, -1);\n }\n data.query = url.search;\n data.data.query = url.search;\n data.fragment = url.hash;\n\n // data.type = \"application/javascript\";\n}\nfunction breakResourceData(data: ResourceData) {\n data.path = \"error\";\n data.context = \"error\";\n data.resource = \"error\";\n}\n\nfunction ensurePluginList(\n resolver: Record<string, unknown>,\n list: string,\n append: unknown,\n) {\n if (resolver[list] === undefined) {\n resolver[list] = [];\n }\n assert(Array.isArray(resolver[list]));\n resolver[list].push(append);\n}\n\nexport class DenoLoaderPlugin {\n workspace: Workspace;\n #transpileLoaderId: number;\n #loader?: Promise<Loader>;\n get loader(): Promise<Loader> {\n return (this.#loader ??= this.workspace.createLoader());\n }\n constructor(\n public opts: WorkspaceOptions,\n public patchImport: (f: string, v: string) => string = (_, v) => v,\n ) {\n opts.noTranspile = false;\n opts.preserveJsx = false;\n opts.platform = \"browser\";\n this.workspace = new Workspace(opts);\n this.#transpileLoaderId = registerDenoLoader(() => this.loader);\n }\n apply(compiler: Compiler) {\n if (compiler.options.resolve.plugins === undefined) {\n compiler.options.resolve.plugins = [];\n }\n assert(Array.isArray(compiler.options.resolve.plugins));\n compiler.options.resolve.plugins.push(new FixupResolvePlugin());\n\n if (compiler.options.resolveLoader.plugins === undefined) {\n compiler.options.resolveLoader.plugins = [];\n }\n assert(Array.isArray(compiler.options.resolveLoader.plugins));\n compiler.options.resolveLoader.plugins.push(new DenoResolvePlugin(this));\n\n compiler.options.resolve.modules = [];\n compiler.options.resolve.roots = [];\n compiler.options.resolve.descriptionFiles = [];\n compiler.options.resolveLoader.modules = [];\n compiler.options.resolveLoader.descriptionFiles = [];\n\n compiler.options.externalsPresets.web = false;\n compiler.options.externalsPresets.webAsync = false;\n\n if (!compiler.options.output.enabledLibraryTypes) {\n compiler.options.output.enabledLibraryTypes = [];\n }\n if (!compiler.options.output.enabledLibraryTypes.includes(\"module\")) {\n compiler.options.output.enabledLibraryTypes.push(\"module\");\n }\n compiler.options.output.library = { type: \"module\" };\n\n compiler.options.output.module = true;\n (compiler.options.experiments as { outputModule: boolean }).outputModule =\n true;\n\n // Deno provides its own type-stripping when no ts loader is present\n // It is not required since deno-loader handles typescript.\n compiler.options.experiments.typescript = false;\n\n compiler.hooks.compilation.tap(\n \"JsrPlugin\",\n (compilation, { normalModuleFactory }) => {\n normalModuleFactory.hooks.afterResolve.tap(\n \"JsrPlugin\",\n ({ createData: data }) => {\n const resource = data.resource;\n if (\n resource === undefined || resource.includes(\"://\") ||\n !/\\.[cm]?[jt]sx?$/.test(resource)\n ) {\n return;\n }\n data.loaders!.push({\n loader: internalTranspileLoader,\n options: { id: this.#transpileLoaderId },\n ident: null,\n type: null,\n });\n },\n );\n normalModuleFactory.hooks.beforeResolve.tapPromise(\n \"JsrPlugin\",\n async (resolveData) => {\n using span = resolverSpan(\n this.opts.debug,\n \"jsr beforeResolve\",\n resolveData,\n );\n\n try {\n // try {\n const loader = await this.loader;\n let requestIssuer: string | undefined | null;\n if (resolveData.contextInfo.issuer !== \"\") {\n requestIssuer = resolveData.contextInfo.issuer;\n }\n if (requestIssuer === undefined || requestIssuer === null) {\n requestIssuer = ensureModPath(resolveData.context);\n }\n assert(\n requestIssuer != undefined,\n \"failed to determine request issuer\",\n );\n let requestRequest = resolveData.request;\n const dependencyType = resolveData.dependencyType;\n span.simplify({\n requestIssuer,\n requestRequest,\n dependencyType,\n });\n\n if (\n requestRequest.startsWith(\"data:\") ||\n requestRequest.startsWith(\"https:\") &&\n !requestRequest.startsWith(\"https://jsr.io/\")\n ) {\n // IDK why those requests even land in this method in some circumstances, returning false\n // here makes them being processed by the handlers below. Most probably I'm missing something,\n // or this webpack api is not intended for such huge loaded replacements.\n span.resolved(\"delegate-builtin\");\n return false;\n }\n if (\n dependencyType === \"url\" &&\n // new URL() references are always relative, but import.meta.resolve() takes import specifiers.\n resolveData.dependencies[0]?.type !== \"import.meta.resolve()\"\n ) {\n requestRequest = \"./\" + requestRequest;\n }\n requestRequest = this.patchImport(requestIssuer, requestRequest);\n\n const resolution = await simpleDenoResolve(\n loader,\n requestIssuer,\n requestRequest,\n true,\n );\n span.resolved(resolution);\n resolveData.request = this.patchImport(requestIssuer, resolution);\n } catch (e) {\n span.errored(e);\n throw e;\n }\n },\n );\n\n normalModuleFactory.hooks.resolveForScheme.for(\"node\").tapPromise(\n \"JsrPlugin\",\n async (resourceData, resolveData) => {\n using span = resolverSpan(\n this.opts.debug,\n \"node resolveForScheme\",\n resolveData.request,\n );\n resourceData.path = false as any;\n resourceData.data.path = false;\n span.resolved(\"stubbed: empty module\");\n return true;\n },\n );\n normalModuleFactory.hooks.resolveForScheme.for(\"jsr\").tapPromise(\n \"JsrPlugin\",\n async (resourceData, resolveData) => {\n using span = resolverSpan(\n this.opts.debug,\n \"jsr resolveForScheme\",\n resolveData,\n );\n breakResourceData(resourceData);\n unreachable(\"jsr should be resolved to https by deno resolver\");\n },\n );\n normalModuleFactory.hooks.resolveForScheme.for(\"npm\").tapPromise(\n \"JsrPlugin\",\n async (resourceData, resolveData) => {\n using span = resolverSpan(\n this.opts.debug,\n \"npm resolveForScheme\",\n resolveData,\n );\n breakResourceData(resourceData);\n unreachable(\"npm should be resolved to files by deno resolver\");\n },\n );\n normalModuleFactory.hooks.resolveForScheme.for(\"https\").tapPromise(\n \"JsrPlugin\",\n async (resourceData, resolveData) => {\n using span = resolverSpan(\n this.opts.debug,\n \"https resolveForScheme\",\n resolveData.request,\n );\n const loader = await this.loader;\n // const newResourceData = {...resourceData};\n await fillResourceData(\n resourceData,\n loader,\n new URL(resolveData.request),\n );\n span.resolved(\"done\");\n return true;\n },\n );\n normalModuleFactory.hooks.resolveInScheme.for(\"https\").tapPromise(\n \"JsrPlugin\",\n async (resourceData, data) => {\n using span = resolverSpan(\n this.opts.debug,\n \"https resolveInScheme\",\n resourceData,\n data.contextInfo,\n data.request,\n );\n try {\n const loader = await this.loader;\n const requestRequest = data.request;\n if (requestRequest.startsWith(\"/\")) {\n const requestIssuer = data.contextInfo.issuer;\n assert(\n requestIssuer && requestIssuer.startsWith(\"https://\"),\n `unexpected /-prefixed request without https:// issuer: ${requestRequest}`,\n );\n const issuerUrl = new URL(requestIssuer);\n const resolved = new URL(requestRequest, issuerUrl.origin);\n span.resolved(\"origin-relative url\", resolved.href);\n await fillResourceData(resourceData, loader, resolved);\n return true;\n } else {\n const requestIssuer = data.contextInfo.issuer;\n assert(requestIssuer !== \"\");\n const resolved = await loader.resolve(\n requestRequest,\n requestIssuer,\n ResolutionMode.Import,\n );\n span.resolved(\"url resolved\", resolved);\n assert(resolved.startsWith(\"https:\"));\n await fillResourceData(resourceData, loader, new URL(resolved));\n return true;\n }\n } catch (e) {\n span.errored(e);\n breakResourceData(resourceData);\n }\n },\n );\n const hooks = compiler.webpack.NormalModule.getCompilationHooks(\n compilation,\n );\n\n hooks.readResourceForScheme.for(\"node\").tapAsync(\n \"JsrPlugin\",\n async (_resource, _module, cb) => {\n cb(null, Buffer.from(\"module.exports = {};\"));\n },\n );\n hooks.readResourceForScheme.for(\"jsr\").tapPromise(\n \"JsrPlugin\",\n async (resource, module) => {\n using span = resolverSpan(\n this.opts.debug,\n \"jsr loadResourceForScheme\",\n resource,\n );\n unreachable(\"jsr should be resolved to https by deno resolver\");\n },\n );\n hooks.readResourceForScheme.for(\"https\").tapAsync(\n \"JsrPlugin\",\n async (resource, module, cb) => {\n using span = resolverSpan(\n this.opts.debug,\n \"https readResourceForScheme\",\n resource,\n module.type,\n );\n try {\n const loader = await this.loader;\n const loaded = await loader.load(\n resource,\n requestedModuleType(module.type),\n );\n // TODO: Should import assertions be handled somehow?\n span.resolved(loaded);\n cb(\n null,\n Buffer.from((loaded as { code: Uint8Array | string }).code),\n );\n } catch (e) {\n span.errored(e);\n cb(e as Error);\n }\n },\n );\n },\n );\n }\n}\n"],"mappings":"AAAA,SAEE,mBAAmB,EACnB,cAAc,EACd,SAAS,QAEJ,cAAc;AACrB,SAAS,MAAM,EAAE,WAAW,QAAQ,aAAa;AACjD,OAAO,OAAO,MAAyB,SAAS;AAChD,SAAS,MAAM,QAAQ,aAAa;AACpC,SAAS,aAAa,EAAE,YAAY,QAAQ,WAAW;AACvD,SAAS,OAAO,QAAQ,WAAW;AACnC,SAAS,aAAa,QAAQ,kBAAkB;AAChD,SAAS,kBAAkB,QAAQ,sBAAsB;AAEzD,MAAM,uBAAuB,GAAG,aAAa,CAC3C,mDAAmD,EACnD,MAAM,OAAO,sBAAsB,CACrC,CAAC;AAED,SAAS,YAAY,CACnB,UAA+B,EAC/B,IAAY,EACZ,GAAG,IAAe,EAClB;EACA,IAAI,UAAiC;EACrC,IAAI,SAAqC,GAAG,UAAU,CAAC,MAAM;IAC3D,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,mBAAmB,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC9D,IAAI,UAAU,KAAK,SAAS,EAAE;MAC5B,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,yBAAyB,EAAE,GAAG,UAAU,CAAC;IACtE;EAC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,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Loader } from "@deno/loader";
|
|
2
|
+
import type { LoaderContext } from "webpack";
|
|
3
|
+
type Options = {
|
|
4
|
+
id: number;
|
|
5
|
+
};
|
|
6
|
+
type Context = LoaderContext<Options>;
|
|
7
|
+
export declare function registerDenoLoader(get: () => Promise<Loader>): number;
|
|
8
|
+
export default function denoTranspileLoader(this: Context, _source: string): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RequestedModuleType } from "@deno/loader";
|
|
2
|
+
import { toFileUrl } from "@std/path";
|
|
3
|
+
const registry = new Map();
|
|
4
|
+
let nextId = 0;
|
|
5
|
+
export function registerDenoLoader(get) {
|
|
6
|
+
const id = nextId++;
|
|
7
|
+
registry.set(id, get);
|
|
8
|
+
return id;
|
|
9
|
+
}
|
|
10
|
+
const INLINE_SOURCE_MAP = /\n?\/\/# sourceMappingURL=data:application\/json;base64,([A-Za-z0-9+/=]+)[\t ]*$/;
|
|
11
|
+
function splitSourceMap(code) {
|
|
12
|
+
const match = INLINE_SOURCE_MAP.exec(code);
|
|
13
|
+
if (!match) return {
|
|
14
|
+
code,
|
|
15
|
+
map: undefined
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
code: code.slice(0, match.index),
|
|
19
|
+
map: JSON.parse(atob(match[1]))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default function denoTranspileLoader(_source) {
|
|
23
|
+
const callback = this.async();
|
|
24
|
+
const {
|
|
25
|
+
id
|
|
26
|
+
} = this.getOptions();
|
|
27
|
+
const get = registry.get(id);
|
|
28
|
+
if (!get) {
|
|
29
|
+
callback(new Error(`deno loader ${id} is not registered`));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const resourcePath = this.resourcePath;
|
|
33
|
+
(async () => {
|
|
34
|
+
const loader = await get();
|
|
35
|
+
const specifier = toFileUrl(resourcePath).href;
|
|
36
|
+
const loaded = await loader.load(specifier, RequestedModuleType.Default);
|
|
37
|
+
if (loaded.kind !== "module") {
|
|
38
|
+
throw new Error(`deno loader returned ${loaded.kind} for ${specifier}`);
|
|
39
|
+
}
|
|
40
|
+
return splitSourceMap(new TextDecoder().decode(loaded.code));
|
|
41
|
+
})().then(({
|
|
42
|
+
code,
|
|
43
|
+
map
|
|
44
|
+
}) => callback(null, code, map), e => callback(e));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=transpileLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["transpileLoader.ts"],"sourcesContent":["import { type Loader, RequestedModuleType } from \"@deno/loader\";\nimport { toFileUrl } from \"@std/path\";\nimport type { LoaderContext } from \"webpack\";\n\ntype Options = { id: number };\ntype Context = LoaderContext<Options>;\ntype SourceMap = Exclude<\n Parameters<Context[\"callback\"]>[2],\n null | string | undefined\n>;\n\nconst registry = new Map<number, () => Promise<Loader>>();\nlet nextId = 0;\n\nexport function registerDenoLoader(get: () => Promise<Loader>): number {\n const id = nextId++;\n registry.set(id, get);\n return id;\n}\n\nconst INLINE_SOURCE_MAP =\n /\\n?\\/\\/# sourceMappingURL=data:application\\/json;base64,([A-Za-z0-9+/=]+)[\\t ]*$/;\n\nfunction splitSourceMap(\n code: string,\n): { code: string; map: SourceMap | undefined } {\n const match = INLINE_SOURCE_MAP.exec(code);\n if (!match) return { code, map: undefined };\n return {\n code: code.slice(0, match.index),\n map: JSON.parse(atob(match[1])) as SourceMap,\n };\n}\n\nexport default function denoTranspileLoader(\n this: Context,\n _source: string,\n): void {\n const callback = this.async();\n const { id } = this.getOptions();\n const get = registry.get(id);\n if (!get) {\n callback(new Error(`deno loader ${id} is not registered`));\n return;\n }\n const resourcePath = this.resourcePath;\n (async () => {\n const loader = await get();\n const specifier = toFileUrl(resourcePath).href;\n const loaded = await loader.load(specifier, RequestedModuleType.Default);\n if (loaded.kind !== \"module\") {\n throw new Error(`deno loader returned ${loaded.kind} for ${specifier}`);\n }\n return splitSourceMap(new TextDecoder().decode(loaded.code));\n })().then(\n ({ code, map }) => callback(null, code, map),\n (e) => callback(e),\n );\n}\n"],"mappings":"AAAA,SAAsB,mBAAmB,QAAQ,cAAc;AAC/D,SAAS,SAAS,QAAQ,WAAW;AAUrC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAgC,CAAC;AACzD,IAAI,MAAM,GAAG,CAAC;AAEd,OAAO,SAAS,kBAAkB,CAAC,GAA0B,EAAU;EACrE,MAAM,EAAE,GAAG,MAAM,EAAE;EACnB,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC;EACrB,OAAO,EAAE;AACX;AAEA,MAAM,iBAAiB,GACrB,kFAAkF;AAEpF,SAAS,cAAc,CACrB,IAAY,EACkC;EAC9C,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;EAC1C,IAAI,CAAC,KAAK,EAAE,OAAO;IAAE,IAAI;IAAE,GAAG,EAAE;EAAU,CAAC;EAC3C,OAAO;IACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC;IAChC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;EAChC,CAAC;AACH;AAEA,eAAe,SAAS,mBAAmB,CAEzC,OAAe,EACT;EACN,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;EAC7B,MAAM;IAAE;EAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;EAChC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;EAC5B,IAAI,CAAC,GAAG,EAAE;IACR,QAAQ,CAAC,IAAI,KAAK,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAAC;IAC1D;EACF;EACA,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY;EACtC,CAAC,YAAY;IACX,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC;IAC1B,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,IAAI;IAC9C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,OAAO,CAAC;IACxE,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE;MAC5B,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,CAAC,IAAI,QAAQ,SAAS,EAAE,CAAC;IACzE;IACA,OAAO,cAAc,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;EAC9D,CAAC,EAAE,CAAC,CAAC,IAAI,CACP,CAAC;IAAE,IAAI;IAAE;EAAI,CAAC,KAAK,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,EAC3C,CAAC,IAAK,QAAQ,CAAC,CAAC,CACnB,CAAC;AACH","ignoreList":[]}
|
package/unmap.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as Webpack from "webpack";
|
|
2
|
+
interface UnmapCompilation extends Webpack.Compilation {
|
|
3
|
+
unmapping: Record<string, string>;
|
|
4
|
+
}
|
|
5
|
+
export declare function assertUnmapCompilation(compilation: Webpack.Compilation): asserts compilation is UnmapCompilation;
|
|
6
|
+
export declare class UnmapPlugin {
|
|
7
|
+
apply(compiler: Webpack.Compiler): void;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
package/unmap.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { assert } from "@std/assert";
|
|
2
|
+
export function assertUnmapCompilation(compilation) {
|
|
3
|
+
assert("unmapping" in compilation, "missing fresh data in compilation, did you add WebpackFreshEntries plugin?");
|
|
4
|
+
}
|
|
5
|
+
export class UnmapPlugin {
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
const mappings = new Map();
|
|
8
|
+
const nameToRequest = new Map();
|
|
9
|
+
const nameToAsset = new Map();
|
|
10
|
+
compiler.hooks.compilation.tap(UnmapPlugin.name, (compilation, {
|
|
11
|
+
normalModuleFactory
|
|
12
|
+
}) => {
|
|
13
|
+
normalModuleFactory.hooks.parser.for("javascript/auto").tap(UnmapPlugin.name, parser => {
|
|
14
|
+
parser.hooks.call.for("unmap").tap(UnmapPlugin.name, expr => {
|
|
15
|
+
const error = msg => {
|
|
16
|
+
const err = new compiler.webpack.WebpackError(msg);
|
|
17
|
+
err.loc = expr.loc;
|
|
18
|
+
parser.state.module.addError(err);
|
|
19
|
+
};
|
|
20
|
+
if (expr.arguments.length !== 2) {
|
|
21
|
+
return error(`unmap requires (name, new URL()) arguments`);
|
|
22
|
+
}
|
|
23
|
+
const nameArg = parser.evaluateExpression(expr.arguments[0]);
|
|
24
|
+
if (!nameArg.isString()) {
|
|
25
|
+
return error(`first argument for unmap should be a static string`);
|
|
26
|
+
}
|
|
27
|
+
const urlExpr = expr.arguments[1];
|
|
28
|
+
if (urlExpr.type !== "NewExpression" || urlExpr.callee.type !== "Identifier" || urlExpr.callee.name !== "URL") {
|
|
29
|
+
return error(`second argument for unmap should be new URL() expression`);
|
|
30
|
+
}
|
|
31
|
+
const key = `${parser.state.module.identifier()}:${urlExpr.range[0]}`;
|
|
32
|
+
mappings.set(key, {
|
|
33
|
+
name: nameArg.string,
|
|
34
|
+
module: parser.state.module,
|
|
35
|
+
loc: expr.loc
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
compilation.hooks.afterOptimizeModules.tap(UnmapPlugin.name, () => {
|
|
40
|
+
for (const module of compilation.modules) {
|
|
41
|
+
if (!module.dependencies) return;
|
|
42
|
+
for (const dep of module.dependencies) {
|
|
43
|
+
if (dep.constructor.name !== "URLDependency") continue;
|
|
44
|
+
const dep_ = dep;
|
|
45
|
+
const key = `${module.identifier()}:${dep_.outerRange[0]}`;
|
|
46
|
+
const name = mappings.get(key);
|
|
47
|
+
if (!name) continue;
|
|
48
|
+
const error = msg => {
|
|
49
|
+
const err = new compiler.webpack.WebpackError(msg);
|
|
50
|
+
err.module = name.module;
|
|
51
|
+
err.loc = name.loc;
|
|
52
|
+
compilation.errors.push(err);
|
|
53
|
+
};
|
|
54
|
+
const connection = compilation.moduleGraph.getConnection(dep);
|
|
55
|
+
if (!connection || !connection.module) {
|
|
56
|
+
error("unable to find connection for url dependency");
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const mod = connection.module;
|
|
60
|
+
const request = mod.resource ?? mod.userRequest;
|
|
61
|
+
if (!request) {
|
|
62
|
+
error(`unable to resolve unmap request`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
{
|
|
66
|
+
const oldV = nameToRequest.get(name.name);
|
|
67
|
+
if (oldV !== undefined && oldV !== request) {
|
|
68
|
+
error(`ResolutionConflict: unmap(${JSON.stringify(name.name)}, ${JSON.stringify(request)}) was previously resolved to ${oldV}, use a different unmapping`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
nameToRequest.set(name.name, request);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
compilation.hooks.processAssets.tap(UnmapPlugin.name, assets => {
|
|
77
|
+
for (const [name, request] of nameToRequest.entries()) {
|
|
78
|
+
for (const [assetName, _asset] of Object.entries(assets)) {
|
|
79
|
+
const info = compilation.assetsInfo.get(assetName);
|
|
80
|
+
if (info?.sourceFilename && request.endsWith(info.sourceFilename)) {
|
|
81
|
+
nameToAsset.set(name, assetName);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const unmapping = Object.fromEntries(nameToAsset);
|
|
87
|
+
const json = JSON.stringify(unmapping);
|
|
88
|
+
compilation.emitAsset("mapped.json", new compiler.webpack.sources.RawSource(json));
|
|
89
|
+
compilation.unmapping = unmapping;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=unmap.js.map
|