@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/unmap.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type * as Webpack from "webpack";
|
|
2
|
-
import { assert } from "@std/assert";
|
|
3
|
-
|
|
4
|
-
interface UnmapCompilation extends Webpack.Compilation {
|
|
5
|
-
unmapping: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function assertUnmapCompilation(
|
|
9
|
-
compilation: Webpack.Compilation,
|
|
10
|
-
): asserts compilation is UnmapCompilation {
|
|
11
|
-
assert(
|
|
12
|
-
"unmapping" in compilation,
|
|
13
|
-
"missing fresh data in compilation, did you add WebpackFreshEntries plugin?",
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
export class UnmapPlugin {
|
|
17
|
-
apply(compiler: Webpack.Compiler) {
|
|
18
|
-
const mappings = new Map<
|
|
19
|
-
string,
|
|
20
|
-
{ name: string; module: Webpack.Module; loc: Webpack.Dependency["loc"] }
|
|
21
|
-
>();
|
|
22
|
-
const nameToRequest = new Map<string, string>();
|
|
23
|
-
const nameToAsset = new Map<string, string>();
|
|
24
|
-
|
|
25
|
-
compiler.hooks.compilation.tap(
|
|
26
|
-
UnmapPlugin.name,
|
|
27
|
-
(compilation, { normalModuleFactory }) => {
|
|
28
|
-
normalModuleFactory.hooks.parser.for("javascript/auto").tap(
|
|
29
|
-
UnmapPlugin.name,
|
|
30
|
-
(parser) => {
|
|
31
|
-
parser.hooks.call.for("unmap").tap(UnmapPlugin.name, (expr) => {
|
|
32
|
-
const error = (msg: string) => {
|
|
33
|
-
const err = new compiler.webpack.WebpackError(msg);
|
|
34
|
-
err.loc = expr.loc!;
|
|
35
|
-
parser.state.module.addError(
|
|
36
|
-
err,
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
if (expr.arguments.length !== 2) {
|
|
40
|
-
return error(`unmap requires (name, new URL()) arguments`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const nameArg = parser.evaluateExpression(expr.arguments[0]);
|
|
44
|
-
if (!nameArg.isString()) {
|
|
45
|
-
return error(
|
|
46
|
-
`first argument for unmap should be a static string`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const urlExpr = expr.arguments[1];
|
|
51
|
-
if (
|
|
52
|
-
urlExpr.type !== "NewExpression" ||
|
|
53
|
-
urlExpr.callee.type !== "Identifier" ||
|
|
54
|
-
urlExpr.callee.name !== "URL"
|
|
55
|
-
) {
|
|
56
|
-
return error(
|
|
57
|
-
`second argument for unmap should be new URL() expression`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const key = `${parser.state.module.identifier()}:${
|
|
61
|
-
urlExpr.range![0]
|
|
62
|
-
}`;
|
|
63
|
-
mappings.set(key, {
|
|
64
|
-
name: nameArg.string!,
|
|
65
|
-
module: parser.state.module,
|
|
66
|
-
loc: expr.loc!,
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
compilation.hooks.afterOptimizeModules.tap(
|
|
73
|
-
UnmapPlugin.name,
|
|
74
|
-
() => {
|
|
75
|
-
for (const module of compilation.modules) {
|
|
76
|
-
if (!module.dependencies) return;
|
|
77
|
-
|
|
78
|
-
for (const dep of module.dependencies) {
|
|
79
|
-
if (dep.constructor.name !== "URLDependency") continue;
|
|
80
|
-
const dep_ = dep as unknown as { outerRange: [number, number] };
|
|
81
|
-
|
|
82
|
-
const key = `${module.identifier()}:${dep_.outerRange[0]}`;
|
|
83
|
-
const name = mappings.get(key);
|
|
84
|
-
|
|
85
|
-
if (!name) continue;
|
|
86
|
-
|
|
87
|
-
const error = (msg: string) => {
|
|
88
|
-
const err = new compiler.webpack.WebpackError(
|
|
89
|
-
msg,
|
|
90
|
-
);
|
|
91
|
-
err.module = name.module;
|
|
92
|
-
err.loc = name.loc;
|
|
93
|
-
compilation.errors.push(err);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const connection = compilation.moduleGraph.getConnection(
|
|
97
|
-
dep,
|
|
98
|
-
);
|
|
99
|
-
if (!connection || !connection.module) {
|
|
100
|
-
error("unable to find connection for url dependency");
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const mod = connection.module as {
|
|
104
|
-
resource?: string;
|
|
105
|
-
userRequest?: string;
|
|
106
|
-
};
|
|
107
|
-
const request = mod.resource ?? mod.userRequest;
|
|
108
|
-
if (!request) {
|
|
109
|
-
error(`unable to resolve unmap request`);
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
const oldV = nameToRequest.get(name.name);
|
|
115
|
-
if (oldV !== undefined && oldV !== request) {
|
|
116
|
-
error(
|
|
117
|
-
`ResolutionConflict: unmap(${
|
|
118
|
-
JSON.stringify(name.name)
|
|
119
|
-
}, ${
|
|
120
|
-
JSON.stringify(request)
|
|
121
|
-
}) was previously resolved to ${oldV}, use a different unmapping`,
|
|
122
|
-
);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
nameToRequest.set(name.name, request);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
compilation.hooks.processAssets.tap(UnmapPlugin.name, (assets) => {
|
|
132
|
-
for (const [name, request] of nameToRequest.entries()) {
|
|
133
|
-
for (const [assetName, _asset] of Object.entries(assets)) {
|
|
134
|
-
const info = compilation.assetsInfo.get(assetName);
|
|
135
|
-
if (
|
|
136
|
-
info?.sourceFilename && request.endsWith(info.sourceFilename)
|
|
137
|
-
) {
|
|
138
|
-
nameToAsset.set(name, assetName);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const unmapping = Object.fromEntries(nameToAsset);
|
|
144
|
-
const json = JSON.stringify(unmapping);
|
|
145
|
-
compilation.emitAsset(
|
|
146
|
-
"mapped.json",
|
|
147
|
-
new compiler.webpack.sources.RawSource(json),
|
|
148
|
-
);
|
|
149
|
-
(compilation as UnmapCompilation).unmapping = unmapping;
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
package/viteComment.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type Webpack from "webpack";
|
|
2
|
-
import type { Compiler } from "webpack";
|
|
3
|
-
|
|
4
|
-
type JavascriptParser = Webpack.javascript.JavascriptParser;
|
|
5
|
-
|
|
6
|
-
const NAME = "ViteIgnorePlugin";
|
|
7
|
-
|
|
8
|
-
const PARSER_TYPES = [
|
|
9
|
-
"javascript/auto",
|
|
10
|
-
"javascript/dynamic",
|
|
11
|
-
"javascript/esm",
|
|
12
|
-
] as const;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* ViteIgnorePlugin skips parsing of `import` calls that contain `@vite-inore` in inline comment, similarly
|
|
16
|
-
* to webpack built-in `webpackIgnore: true` annotation
|
|
17
|
-
*/
|
|
18
|
-
export class ViteIgnorePlugin {
|
|
19
|
-
apply(compiler: Compiler) {
|
|
20
|
-
compiler.hooks.compilation.tap(
|
|
21
|
-
NAME,
|
|
22
|
-
(_compilation, { normalModuleFactory }) => {
|
|
23
|
-
const handler = (parser: JavascriptParser) => {
|
|
24
|
-
parser.hooks.importCall.tap({ name: NAME, stage: -10 }, (expr) => {
|
|
25
|
-
const ignored = parser.getComments([
|
|
26
|
-
expr.range![0],
|
|
27
|
-
expr.source.range![1],
|
|
28
|
-
]).some((comment) =>
|
|
29
|
-
comment.type === "Block" &&
|
|
30
|
-
comment.value.includes("@vite-ignore")
|
|
31
|
-
);
|
|
32
|
-
if (ignored) return false;
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
for (const type of PARSER_TYPES) {
|
|
36
|
-
normalModuleFactory.hooks.parser.for(type).tap(NAME, handler);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
}
|