@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.
Files changed (74) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +13 -12
  3. package/denoEnv.d.ts +12 -0
  4. package/denoEnv.js +49 -0
  5. package/denoEnv.js.map +1 -0
  6. package/fresh.d.ts +39 -0
  7. package/fresh.js +245 -0
  8. package/fresh.js.map +1 -0
  9. package/importMetaResolve.d.ts +4 -0
  10. package/importMetaResolve.js +50 -0
  11. package/importMetaResolve.js.map +1 -0
  12. package/mod.d.ts +8 -0
  13. package/mod.js +9 -0
  14. package/mod.js.map +1 -0
  15. package/package.json +81 -9
  16. package/prefresh-forked/index.d.ts +15 -0
  17. package/prefresh-forked/index.js +59 -0
  18. package/prefresh-forked/index.js.map +1 -0
  19. package/prefresh-forked/loader/index.d.ts +2 -0
  20. package/prefresh-forked/loader/index.js +5 -0
  21. package/prefresh-forked/loader/index.js.map +1 -0
  22. package/prefresh-forked/utils/Runtime.d.ts +5 -0
  23. package/prefresh-forked/utils/Runtime.js +27 -0
  24. package/prefresh-forked/utils/Runtime.js.map +1 -0
  25. package/prefresh-forked/utils/constants.d.ts +8 -0
  26. package/prefresh-forked/utils/constants.js +12 -0
  27. package/prefresh-forked/utils/constants.js.map +1 -0
  28. package/prefresh-forked/utils/prefresh.d.ts +5 -0
  29. package/prefresh-forked/utils/{prefresh.ts → prefresh.js} +8 -27
  30. package/prefresh-forked/utils/prefresh.js.map +1 -0
  31. package/quasiquote.d.ts +9 -0
  32. package/quasiquote.js +32 -0
  33. package/quasiquote.js.map +1 -0
  34. package/rawBytesLoader.d.ts +5 -0
  35. package/rawBytesLoader.js +10 -0
  36. package/rawBytesLoader.js.map +1 -0
  37. package/rawImports.d.ts +13 -0
  38. package/rawImports.js +44 -0
  39. package/rawImports.js.map +1 -0
  40. package/requireHook.d.ts +1 -0
  41. package/{requireHook.ts → requireHook.js} +5 -10
  42. package/requireHook.js.map +1 -0
  43. package/resolve.d.ts +11 -0
  44. package/resolve.js +395 -0
  45. package/resolve.js.map +1 -0
  46. package/transpileLoader.d.ts +9 -0
  47. package/transpileLoader.js +46 -0
  48. package/transpileLoader.js.map +1 -0
  49. package/unmap.d.ts +9 -0
  50. package/unmap.js +94 -0
  51. package/unmap.js.map +1 -0
  52. package/util.d.ts +9 -0
  53. package/{util.ts → util.js} +13 -19
  54. package/util.js.map +1 -0
  55. package/viteComment.d.ts +8 -0
  56. package/viteComment.js +28 -0
  57. package/viteComment.js.map +1 -0
  58. package/buildCacheUtil.ts +0 -11
  59. package/denoEnv.ts +0 -78
  60. package/fresh.ts +0 -391
  61. package/mod.ts +0 -7
  62. package/prefresh-forked/index.ts +0 -114
  63. package/prefresh-forked/loader/index.ts +0 -10
  64. package/prefresh-forked/utils/Runtime.ts +0 -79
  65. package/prefresh-forked/utils/constants.ts +0 -35
  66. package/prefresh-forked/utils/createTemplate.ts +0 -76
  67. package/prefresh-forked/utils/injectEntry.ts +0 -28
  68. package/quasiquote.ts +0 -44
  69. package/rawBytesLoader.ts +0 -17
  70. package/rawImports.ts +0 -85
  71. package/resolve.ts +0 -588
  72. package/transpileLoader.ts +0 -59
  73. package/unmap.ts +0 -154
  74. 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
- }