@freshpack/webpack 1.0.0 → 1.0.1

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 (56) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +13 -12
  3. package/denoEnv.d.ts +12 -0
  4. package/denoEnv.js +61 -0
  5. package/fresh.d.ts +39 -0
  6. package/fresh.js +268 -0
  7. package/mod.d.ts +7 -0
  8. package/mod.js +7 -0
  9. package/package.json +60 -8
  10. package/prefresh-forked/index.d.ts +15 -0
  11. package/prefresh-forked/index.js +57 -0
  12. package/prefresh-forked/loader/index.d.ts +2 -0
  13. package/prefresh-forked/loader/index.js +4 -0
  14. package/prefresh-forked/utils/Runtime.d.ts +5 -0
  15. package/prefresh-forked/utils/Runtime.js +52 -0
  16. package/prefresh-forked/utils/constants.d.ts +8 -0
  17. package/prefresh-forked/utils/{constants.ts → constants.js} +8 -20
  18. package/prefresh-forked/utils/prefresh.d.ts +5 -0
  19. package/prefresh-forked/utils/prefresh.js +47 -0
  20. package/quasiquote.d.ts +9 -0
  21. package/quasiquote.js +30 -0
  22. package/rawBytesLoader.d.ts +5 -0
  23. package/rawBytesLoader.js +12 -0
  24. package/rawImports.d.ts +13 -0
  25. package/rawImports.js +44 -0
  26. package/requireHook.d.ts +1 -0
  27. package/requireHook.js +16 -0
  28. package/resolve.d.ts +11 -0
  29. package/resolve.js +405 -0
  30. package/transpileLoader.d.ts +9 -0
  31. package/transpileLoader.js +38 -0
  32. package/unmap.d.ts +9 -0
  33. package/unmap.js +96 -0
  34. package/util.d.ts +9 -0
  35. package/util.js +54 -0
  36. package/viteComment.d.ts +8 -0
  37. package/viteComment.js +30 -0
  38. package/buildCacheUtil.ts +0 -11
  39. package/denoEnv.ts +0 -78
  40. package/fresh.ts +0 -391
  41. package/mod.ts +0 -7
  42. package/prefresh-forked/index.ts +0 -114
  43. package/prefresh-forked/loader/index.ts +0 -10
  44. package/prefresh-forked/utils/Runtime.ts +0 -79
  45. package/prefresh-forked/utils/createTemplate.ts +0 -76
  46. package/prefresh-forked/utils/injectEntry.ts +0 -28
  47. package/prefresh-forked/utils/prefresh.ts +0 -59
  48. package/quasiquote.ts +0 -44
  49. package/rawBytesLoader.ts +0 -17
  50. package/rawImports.ts +0 -85
  51. package/requireHook.ts +0 -22
  52. package/resolve.ts +0 -588
  53. package/transpileLoader.ts +0 -59
  54. package/unmap.ts +0 -154
  55. package/util.ts +0 -58
  56. package/viteComment.ts +0 -41
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # @freshpack/webpack
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - prepack
8
+
9
+ - Updated dependencies:
10
+ - @freshpack/core@3.0.2
package/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Lach and Fresh authors
3
+ Copyright (c) 2026 Yaroslav Bolyukin <iam@lach.pw>
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/denoEnv.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { type Compiler } from "webpack";
2
+ export type DenoEnvOptions = {
3
+ allowedEnv?: (string | RegExp)[];
4
+ };
5
+ /**
6
+ * DenoEnvPlugin replaces calls to `Deno.env.get` with a constant expression of environment variable name.
7
+ */
8
+ export declare class DenoEnvPlugin {
9
+ #private;
10
+ constructor(opts?: DenoEnvOptions);
11
+ apply(compiler: Compiler): void;
12
+ }
package/denoEnv.js ADDED
@@ -0,0 +1,61 @@
1
+ import Webpack from "webpack";
2
+ const NAME = "DenoEnvPlugin";
3
+ const PARSER_TYPES = [
4
+ "javascript/auto",
5
+ "javascript/dynamic",
6
+ "javascript/esm",
7
+ ];
8
+ /**
9
+ * DenoEnvPlugin replaces calls to `Deno.env.get` with a constant expression of environment variable name.
10
+ */
11
+ export class DenoEnvPlugin {
12
+ #allowed;
13
+ constructor(opts = {}) {
14
+ this.#allowed = [
15
+ ...opts.allowedEnv ?? [],
16
+ /^FRESH_PUBLIC_/,
17
+ "NODE_ENV",
18
+ "DENO_DEPLOYMENT_ID",
19
+ "GITHUB_SHA",
20
+ "CI_COMMIT_SHA",
21
+ "CI",
22
+ ];
23
+ }
24
+ #isAllowed(name) {
25
+ return this.#allowed.some((allowed) => allowed instanceof RegExp ? allowed.test(name) : allowed === name);
26
+ }
27
+ #value(name, compiler) {
28
+ if (name === "NODE_ENV") {
29
+ const mode = compiler.options.mode;
30
+ if (mode !== undefined && mode !== "none")
31
+ return mode;
32
+ }
33
+ return Deno.env.get(name);
34
+ }
35
+ apply(compiler) {
36
+ compiler.hooks.compilation.tap(NAME, (_compilation, { normalModuleFactory }) => {
37
+ const handler = (parser) => {
38
+ parser.hooks.call.for("Deno.env.get").tap(NAME, (expr) => {
39
+ const [arg] = expr.arguments;
40
+ if (expr.arguments.length !== 1 || arg.type !== "Literal" ||
41
+ typeof arg.value !== "string") {
42
+ return;
43
+ }
44
+ const name = arg.value;
45
+ if (!this.#isAllowed(name)) {
46
+ throw new Error(`Env var is not allowed in bundling: ${name}`);
47
+ }
48
+ const value = this.#value(name, compiler);
49
+ const dep = new Webpack.dependencies.ConstDependency(value === undefined ? "undefined" : JSON.stringify(value), expr.range);
50
+ if (expr.loc)
51
+ dep.loc = expr.loc;
52
+ parser.state.module.addPresentationalDependency(dep);
53
+ return true;
54
+ });
55
+ };
56
+ for (const type of PARSER_TYPES) {
57
+ normalModuleFactory.hooks.parser.for(type).tap(NAME, handler);
58
+ }
59
+ });
60
+ }
61
+ }
package/fresh.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type FsRouteFileNoMod } from "@freshpack/core/internal-dev";
2
+ import Webpack from "webpack";
3
+ import { ProdBuildCache } from "@freshpack/core/internal";
4
+ import { type DenoEnvOptions } from "./denoEnv.js";
5
+ import { type RawImportsOptions } from "./rawImports.js";
6
+ interface WebpackFreshCompilation extends Webpack.Compilation {
7
+ freshRoutes: FsRouteFileNoMod<unknown>[];
8
+ freshIslands: {
9
+ entryName: string;
10
+ filePath: string;
11
+ }[];
12
+ freshRoot: string;
13
+ buildId: string;
14
+ prodBuildCache: ProdBuildCache<unknown>;
15
+ }
16
+ export declare function assertFreshCompilation(compilation: Webpack.Compilation): asserts compilation is WebpackFreshCompilation;
17
+ export declare class FreshPlugin {
18
+ #private;
19
+ baseUrl: URL;
20
+ importHelper: (path: string) => Promise<Record<string, unknown>>;
21
+ options: {
22
+ env?: DenoEnvOptions;
23
+ rawImports?: RawImportsOptions;
24
+ };
25
+ /**
26
+ * @param baseUrl Location of fresh project root directory, you can specify it as `new URL('.', import.meta.url)` in build.ts
27
+ * @param importHelper JSR dynamic file import workaround: You should pass `(path) => import(path)` here, where the function
28
+ * should be defined anywhere outside of JSR published package. See this for details: https://github.com/denoland/deno/discussions/26266
29
+ * This function will always be called with absolute path.
30
+ */
31
+ constructor(baseUrl: URL, importHelper: (path: string) => Promise<Record<string, unknown>>, options?: {
32
+ env?: DenoEnvOptions;
33
+ rawImports?: RawImportsOptions;
34
+ });
35
+ pathRelativeToBase(path: string): string;
36
+ pathRelativeToDist(path: string): string;
37
+ apply(compiler: Webpack.Compiler): void;
38
+ }
39
+ export {};
package/fresh.js ADDED
@@ -0,0 +1,268 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { crawlFsItem, } from "@freshpack/core/internal-dev";
10
+ import Webpack from "webpack";
11
+ import { assertAbsolutePath, assertDirURL, manglePath, stripFileUrl, } from "./util.js";
12
+ import { assert } from "@std/assert";
13
+ import { IslandPreparer, ProdBuildCache } from "@freshpack/core/internal";
14
+ import { extname as extnamePosix, join as joinPosix, relative as relativePosix, } from "@std/path/posix";
15
+ import { contentType as getStdContentType } from "@std/media-types/content-type";
16
+ import { encodeHex } from "@std/encoding";
17
+ import { UnmapPlugin } from "./unmap.js";
18
+ import { DenoEnvPlugin } from "./denoEnv.js";
19
+ import { ViteIgnorePlugin } from "./viteComment.js";
20
+ import { RawImportsPlugin } from "./rawImports.js";
21
+ import { js, toJsRaw } from "./quasiquote.js";
22
+ export function assertFreshCompilation(compilation) {
23
+ assert("freshRoutes" in compilation && "freshIslands" in compilation &&
24
+ "freshRoot" in compilation, "missing fresh data in compilation, did you add WebpackFreshEntries plugin?");
25
+ }
26
+ function getMainChunkName(basePath, e) {
27
+ const entryChunk = e.getEntrypointChunk();
28
+ const files = [...entryChunk.files].map((v) => joinPosix(basePath, v));
29
+ return files[0];
30
+ }
31
+ function getChunkFiles(basePath, e) {
32
+ return e.getFiles().map((v) => joinPosix(basePath, v));
33
+ }
34
+ export class FreshPlugin {
35
+ baseUrl;
36
+ importHelper;
37
+ options;
38
+ /**
39
+ * @param baseUrl Location of fresh project root directory, you can specify it as `new URL('.', import.meta.url)` in build.ts
40
+ * @param importHelper JSR dynamic file import workaround: You should pass `(path) => import(path)` here, where the function
41
+ * should be defined anywhere outside of JSR published package. See this for details: https://github.com/denoland/deno/discussions/26266
42
+ * This function will always be called with absolute path.
43
+ */
44
+ constructor(baseUrl, importHelper, options = {}) {
45
+ this.baseUrl = baseUrl;
46
+ this.importHelper = importHelper;
47
+ this.options = options;
48
+ assertDirURL(this.baseUrl);
49
+ if (!importHelper) {
50
+ console.warn("[FreshPlugin]", "importHelper is not set, jsr release of @freshpack/webpack doesn't work without it: https://github.com/denoland/deno/discussions/26266#discussioncomment-12198284");
51
+ this.importHelper = (path) => import(__rewriteRelativeImportExtension(path));
52
+ }
53
+ }
54
+ pathRelativeToBase(path) {
55
+ return relativePosix(this.baseUrl.pathname, path);
56
+ }
57
+ #dist;
58
+ pathRelativeToDist(path) {
59
+ assert(this.#dist, "dist path was not determined yet");
60
+ return relativePosix(this.#dist, path);
61
+ }
62
+ apply(compiler) {
63
+ {
64
+ // HACK: Webpack does not export EntryDependency, and it is impossible to use EntryPlugin, as
65
+ // it wants to modify make stage, yet we have already reached this stage when we want to use
66
+ // this plugin.
67
+ //
68
+ // Solvable by creating custom dependency plugin, or requiring user to manually specify
69
+ // at least one entry... Or by registering EntryDependency manually as done here.
70
+ const EntryDependency = Webpack.EntryPlugin.createDependency(`dummy`, {}).constructor;
71
+ compiler.hooks.compilation.tap(FreshPlugin.name, (compilation, { normalModuleFactory }) => {
72
+ compilation.dependencyFactories.set(EntryDependency, normalModuleFactory);
73
+ });
74
+ }
75
+ (new UnmapPlugin()).apply(compiler);
76
+ (new DenoEnvPlugin(this.options.env)).apply(compiler);
77
+ (new ViteIgnorePlugin()).apply(compiler);
78
+ (new RawImportsPlugin(this.options.rawImports)).apply(compiler);
79
+ // Some @std and other packages detect deno on presence of Deno global, dead-code-elimnate this stuff
80
+ (new Webpack.DefinePlugin({ Deno: "undefined" })).apply(compiler);
81
+ compiler.hooks.make.tapPromise(FreshPlugin.name, async (_compilation) => {
82
+ const compilation = _compilation;
83
+ this.#dist = compilation.outputOptions.path;
84
+ const compilationId = Date.now().toString(36);
85
+ // Ensure hot chunks are resolved from correct path, they can't contain compilationId in name
86
+ compilation.outputOptions.publicPath = "/";
87
+ {
88
+ // Chunks are content-addressed in prod, and have readable names using standard fresh cache pruning in dev
89
+ if (compiler.options.mode === "production") {
90
+ compilation.outputOptions.filename =
91
+ `_fresh/js/c/[contenthash].mjs`;
92
+ compilation.outputOptions.chunkFilename =
93
+ `_fresh/js/c/[contenthash].mjs`;
94
+ compilation.outputOptions.workerChunkFilename =
95
+ `_fresh/js/c/[contenthash].mjs`;
96
+ }
97
+ else {
98
+ compilation.outputOptions.filename =
99
+ `_fresh/js/${compilationId}/[id].mjs`;
100
+ compilation.outputOptions.chunkFilename =
101
+ `_fresh/js/${compilationId}/[id].mjs`;
102
+ compilation.outputOptions.workerChunkFilename =
103
+ `_fresh/js/${compilationId}/[id].mjs`;
104
+ }
105
+ // Assets are always content-addressed
106
+ compilation.outputOptions.assetModuleFilename =
107
+ `_fresh/js/c/[hash][ext][query]`;
108
+ compilation.outputOptions.webassemblyModuleFilename =
109
+ `_fresh/js/c/[hash].wasm`;
110
+ }
111
+ compilation.hooks.processAssets.tapPromise({
112
+ name: FreshPlugin.name,
113
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
114
+ }, async (assets) => {
115
+ compilation.getAssets();
116
+ const cacheOut = [
117
+ js `import{IslandPreparer,ProdBuildCache}from"@freshpack/core/internal"`,
118
+ js `const islands=new Map()`,
119
+ js `const islandPreparer=new IslandPreparer()`,
120
+ ];
121
+ const staticFiles = new Map();
122
+ const islands = new Map();
123
+ const islandPreparer = new IslandPreparer();
124
+ for (const island of compilation.freshIslands) {
125
+ const entrypoint = compilation.entrypoints.get(island.entryName);
126
+ assert(entrypoint, `unable to find island entrypoint: ${island.entryName}`);
127
+ const file = getMainChunkName(`/`, entrypoint);
128
+ islandPreparer.prepare(islands, await this.importHelper(island.filePath), file, island.entryName, []);
129
+ const importPath = this.pathRelativeToDist(island.filePath);
130
+ cacheOut.push(js `islandPreparer.prepare(islands,await import(${importPath}),${file},${island.entryName},[])`);
131
+ }
132
+ const fsRoutesOut = [];
133
+ const fsRoutes = await Promise.all(compilation.freshRoutes.map(async (v) => {
134
+ const importPath = this.pathRelativeToDist(v.filePath);
135
+ fsRoutesOut.push(toJsRaw({
136
+ id: v.id,
137
+ mod: v.lazy
138
+ ? js `()=>import(${importPath})`
139
+ : js `await import(${importPath})`,
140
+ type: v.type,
141
+ pattern: v.pattern,
142
+ routePattern: v.routePattern,
143
+ }));
144
+ assertAbsolutePath(v.filePath);
145
+ return {
146
+ ...v,
147
+ mod: v.lazy
148
+ ? () => this.importHelper(v.filePath)
149
+ : await this.importHelper(v.filePath),
150
+ };
151
+ }));
152
+ cacheOut.push(js `const fsRoutes=${fsRoutesOut}`);
153
+ const clientEntrypoint = compilation.entrypoints.get("client-entry");
154
+ assert(clientEntrypoint, `unable to find client entrypoint`);
155
+ const clientEntry = getMainChunkName(`/`, clientEntrypoint);
156
+ const clientEntryAssets = getChunkFiles(`/`, clientEntrypoint);
157
+ const staticFilesOut = new Map();
158
+ for (const _asset of compilation.getAssets()) {
159
+ const asset = compilation.getAsset(_asset.name);
160
+ const file_ = assets[asset.name]
161
+ .buffer();
162
+ const file = file_;
163
+ const hash = await crypto.subtle.digest("SHA-1", file.buffer);
164
+ const ext = extnamePosix(asset.name);
165
+ const contentType = getStdContentType(ext) ?? "text/plain";
166
+ const name = "/" + asset.name;
167
+ staticFiles.set(name, {
168
+ name,
169
+ filePath: asset.name,
170
+ contentType,
171
+ hash: encodeHex(hash),
172
+ data: file,
173
+ size: file.length,
174
+ });
175
+ staticFilesOut.set(name, toJsRaw({
176
+ name,
177
+ filePath: js `new URL(${asset.name}, import.meta.url).pathname`,
178
+ hash: encodeHex(hash),
179
+ contentType,
180
+ }));
181
+ }
182
+ cacheOut.push(js `const staticFiles=${staticFilesOut}`);
183
+ cacheOut.push(js `export default new ProdBuildCache(${compilation.freshRoot}, ${({
184
+ version: compilationId,
185
+ clientEntry,
186
+ entryAssets: toJsRaw(clientEntryAssets),
187
+ islands: js `islands`,
188
+ fsRoutes: js `fsRoutes`,
189
+ staticFiles: js `staticFiles`,
190
+ })})`);
191
+ // Here ProdBuildCache is being used as MemoryBuildCache from fresh
192
+ const cache = new ProdBuildCache(compilation.freshRoot, {
193
+ version: compilationId,
194
+ clientEntry,
195
+ fsRoutes,
196
+ staticFiles,
197
+ islands,
198
+ entryAssets: clientEntryAssets,
199
+ });
200
+ cache.readFile = (pathname) => {
201
+ const st = staticFiles.get(pathname);
202
+ if (!st) {
203
+ return Promise.resolve(null);
204
+ }
205
+ return Promise.resolve({
206
+ contentType: st.contentType,
207
+ hash: st.hash,
208
+ readable: new ReadableStream({
209
+ start(v) {
210
+ v.enqueue(st.data);
211
+ v.close();
212
+ },
213
+ }),
214
+ size: st.size,
215
+ close() { },
216
+ });
217
+ };
218
+ compilation.prodBuildCache = cache;
219
+ compilation.emitAsset("./cache.mjs", new compiler.webpack.sources.RawSource(cacheOut.map((v) => v._jsRaw).join("\n")));
220
+ });
221
+ const item = await crawlFsItem({
222
+ islandDir: stripFileUrl(new URL("islands", this.baseUrl).href),
223
+ routeDir: stripFileUrl(new URL("routes", this.baseUrl).href),
224
+ ignore: [],
225
+ });
226
+ compilation.freshRoutes = item.routes;
227
+ compilation.freshIslands = [];
228
+ compilation.freshRoot = this.pathRelativeToBase(".");
229
+ const addEntryPromises = [];
230
+ let isId = 0;
231
+ for (const island of item.islands) {
232
+ const name = compiler.options.mode === "production"
233
+ ? `is${isId++}`
234
+ : manglePath(island);
235
+ compilation.freshIslands.push({ entryName: name, filePath: island });
236
+ addEntryPromises.push(new Promise((res, rej) => compilation.addEntry("", Webpack.EntryPlugin.createDependency(`${island}`, {
237
+ name,
238
+ }), {
239
+ name,
240
+ library: {
241
+ type: "module",
242
+ },
243
+ }, (err) => {
244
+ if (err)
245
+ return rej(err);
246
+ res();
247
+ })));
248
+ }
249
+ {
250
+ const name = "client-entry";
251
+ const file = stripFileUrl(new URL("./client.ts", this.baseUrl).href);
252
+ addEntryPromises.push(new Promise((res, rej) => compilation.addEntry("", Webpack.EntryPlugin.createDependency(file, {
253
+ name,
254
+ }), {
255
+ name,
256
+ library: {
257
+ type: "module",
258
+ },
259
+ }, (e) => {
260
+ if (e)
261
+ return rej(e);
262
+ res();
263
+ })));
264
+ }
265
+ await Promise.all(addEntryPromises);
266
+ });
267
+ }
268
+ }
package/mod.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { DenoEnvPlugin } from "./denoEnv.js";
2
+ export { FreshPlugin } from "./fresh.js";
3
+ export { ViteIgnorePlugin } from "./viteComment.js";
4
+ export { DenoPreactRefreshPlugin } from "./prefresh-forked/index.js";
5
+ export { DenoLoaderPlugin } from "./resolve.js";
6
+ export { type RawImportsOptions, RawImportsPlugin } from "./rawImports.js";
7
+ export { UnmapPlugin } from "./unmap.js";
package/mod.js ADDED
@@ -0,0 +1,7 @@
1
+ export { DenoEnvPlugin } from "./denoEnv.js";
2
+ export { FreshPlugin } from "./fresh.js";
3
+ export { ViteIgnorePlugin } from "./viteComment.js";
4
+ export { DenoPreactRefreshPlugin } from "./prefresh-forked/index.js";
5
+ export { DenoLoaderPlugin } from "./resolve.js";
6
+ export { RawImportsPlugin } from "./rawImports.js";
7
+ export { UnmapPlugin } from "./unmap.js";
package/package.json CHANGED
@@ -1,22 +1,74 @@
1
1
  {
2
2
  "name": "@freshpack/webpack",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": "./mod.ts",
7
- "./fresh": "./fresh.ts",
8
- "./util": "./util.ts",
9
- "./unmap": "./unmap.ts",
10
- "./requireHook": "./requireHook.ts"
6
+ ".": {
7
+ "types": "./mod.d.ts",
8
+ "default": "./mod.js"
9
+ },
10
+ "./fresh": {
11
+ "types": "./fresh.d.ts",
12
+ "default": "./fresh.js"
13
+ },
14
+ "./util": {
15
+ "types": "./util.d.ts",
16
+ "default": "./util.js"
17
+ },
18
+ "./unmap": {
19
+ "types": "./unmap.d.ts",
20
+ "default": "./unmap.js"
21
+ },
22
+ "./requireHook": {
23
+ "types": "./requireHook.d.ts",
24
+ "default": "./requireHook.js"
25
+ }
11
26
  },
12
27
  "dependencies": {
13
28
  "@deno/loader": "npm:@jsr/deno__loader@^0.5.0",
14
- "@freshpack/core": "3.0.1",
29
+ "@freshpack/core": "3.0.2",
15
30
  "@prefresh/utils": "^1.2.1",
16
31
  "@std/assert": "npm:@jsr/std__assert@^1.0.19",
17
32
  "@std/encoding": "npm:@jsr/std__encoding@^1.0.11",
18
33
  "@std/media-types": "npm:@jsr/std__media-types@^1.1.0",
19
34
  "@std/path": "npm:@jsr/std__path@^1.1.6",
20
35
  "webpack": "^5.111.1"
21
- }
36
+ },
37
+ "files": [
38
+ "denoEnv.d.ts",
39
+ "denoEnv.js",
40
+ "fresh.d.ts",
41
+ "fresh.js",
42
+ "mod.d.ts",
43
+ "mod.js",
44
+ "prefresh-forked/index.d.ts",
45
+ "prefresh-forked/index.js",
46
+ "prefresh-forked/loader/index.d.ts",
47
+ "prefresh-forked/loader/index.js",
48
+ "prefresh-forked/loader/runtime.js",
49
+ "prefresh-forked/utils/Runtime.d.ts",
50
+ "prefresh-forked/utils/Runtime.js",
51
+ "prefresh-forked/utils/constants.d.ts",
52
+ "prefresh-forked/utils/constants.js",
53
+ "prefresh-forked/utils/prefresh.d.ts",
54
+ "prefresh-forked/utils/prefresh.js",
55
+ "quasiquote.d.ts",
56
+ "quasiquote.js",
57
+ "rawBytesLoader.d.ts",
58
+ "rawBytesLoader.js",
59
+ "rawImports.d.ts",
60
+ "rawImports.js",
61
+ "requireHook.d.ts",
62
+ "requireHook.js",
63
+ "resolve.d.ts",
64
+ "resolve.js",
65
+ "transpileLoader.d.ts",
66
+ "transpileLoader.js",
67
+ "unmap.d.ts",
68
+ "unmap.js",
69
+ "util.d.ts",
70
+ "util.js",
71
+ "viteComment.d.ts",
72
+ "viteComment.js"
73
+ ]
22
74
  }
@@ -0,0 +1,15 @@
1
+ import Webpack from "webpack";
2
+ type Options = {
3
+ overlay?: {
4
+ module: string;
5
+ };
6
+ entryOptions?: string | Webpack.EntryOptions;
7
+ };
8
+ export declare class DenoPreactRefreshPlugin {
9
+ options: Options;
10
+ matcher: (str: string) => boolean;
11
+ constructor(options: Options);
12
+ webpack5(compiler: Webpack.Compiler, RuntimeGlobals: typeof Webpack.RuntimeGlobals): void;
13
+ apply(compiler: Webpack.Compiler): void;
14
+ }
15
+ export {};
@@ -0,0 +1,57 @@
1
+ /* FIXME: Typings are awful in this file, the port was very crude */
2
+ import Webpack from "webpack";
3
+ import { injectRefreshFunctions, matcherOptions, NAME, prefreshUtils, } from "./utils/constants.js";
4
+ import { PrefreshRuntimeModule } from "./utils/Runtime.js";
5
+ import { defineRequire } from "../requireHook.js";
6
+ const internalPrefreshLoader = defineRequire("@freshpack/webpack/internal-prefresh-loader", await import("./loader/index.js"));
7
+ export class DenoPreactRefreshPlugin {
8
+ options;
9
+ matcher;
10
+ constructor(options) {
11
+ this.options = options;
12
+ this.matcher = Webpack.ModuleFilenameHelpers.matchObject.bind(undefined, matcherOptions);
13
+ }
14
+ webpack5(compiler, RuntimeGlobals) {
15
+ compiler.hooks.compilation.tap(NAME, (compilation, { normalModuleFactory }) => {
16
+ if (compilation.compiler !== compiler) {
17
+ return;
18
+ }
19
+ injectRefreshFunctions(compilation);
20
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(NAME, (chunk, runtimeRequirements) => {
21
+ runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);
22
+ compilation.addRuntimeModule(chunk, new PrefreshRuntimeModule());
23
+ });
24
+ normalModuleFactory.hooks.afterResolve.tap(NAME, ({ createData: data }) => {
25
+ if (this.matcher(data.resource) &&
26
+ !data.resource.includes("@prefresh") &&
27
+ !data.resource.includes("/prefresh-forked/loader/") &&
28
+ !data.resource.includes("/prefresh-forked/utils/")) {
29
+ data.loaders.unshift({
30
+ loader: internalPrefreshLoader,
31
+ options: undefined,
32
+ });
33
+ }
34
+ });
35
+ });
36
+ }
37
+ apply(compiler) {
38
+ if (compiler.options.mode === "production") {
39
+ return;
40
+ }
41
+ const provide = {
42
+ [prefreshUtils]: import.meta.resolve("./utils/prefresh.js"),
43
+ };
44
+ if (this.options.overlay) {
45
+ provide.__prefresh_errors__ = import.meta.resolve(this.options.overlay.module);
46
+ }
47
+ const providePlugin = new Webpack.ProvidePlugin(provide);
48
+ providePlugin.apply(compiler);
49
+ const dependency = Webpack.EntryPlugin.createDependency("@prefresh/core", { name: "@prefresh/core" });
50
+ compiler.hooks.make.tapAsync(NAME, (compilation, callback) => {
51
+ compilation.addEntry(compiler.context, dependency, this.options.entryOptions ?? {}, callback);
52
+ });
53
+ this.webpack5(compiler, compiler.webpack
54
+ ? compiler.webpack.RuntimeGlobals
55
+ : Webpack.RuntimeGlobals);
56
+ }
57
+ }
@@ -0,0 +1,2 @@
1
+ import type Webpack from "webpack";
2
+ export default function RefreshHotLoader(this: any, source: Webpack.sources.SourceMapSource, inputSourceMap: Webpack.sources.SourceMapSource["source"]): void;
@@ -0,0 +1,4 @@
1
+ import runtimeText from "./runtime.js" with { type: "text" };
2
+ export default function RefreshHotLoader(source, inputSourceMap) {
3
+ this.callback(null, source + "\n\n" + runtimeText, inputSourceMap);
4
+ }
@@ -0,0 +1,5 @@
1
+ import Webpack from "webpack";
2
+ export declare class PrefreshRuntimeModule extends Webpack.RuntimeModule {
3
+ constructor();
4
+ generate(): string;
5
+ }