@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/package.json CHANGED
@@ -1,22 +1,94 @@
1
1
  {
2
2
  "name": "@freshpack/webpack",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
- "webpack": "^5.111.1"
21
- }
35
+ "webpack": "^5.112.0"
36
+ },
37
+ "files": [
38
+ "denoEnv.d.ts",
39
+ "denoEnv.js",
40
+ "denoEnv.js.map",
41
+ "fresh.d.ts",
42
+ "fresh.js",
43
+ "fresh.js.map",
44
+ "importMetaResolve.d.ts",
45
+ "importMetaResolve.js",
46
+ "importMetaResolve.js.map",
47
+ "mod.d.ts",
48
+ "mod.js",
49
+ "mod.js.map",
50
+ "prefresh-forked/index.d.ts",
51
+ "prefresh-forked/index.js",
52
+ "prefresh-forked/index.js.map",
53
+ "prefresh-forked/loader/index.d.ts",
54
+ "prefresh-forked/loader/index.js",
55
+ "prefresh-forked/loader/index.js.map",
56
+ "prefresh-forked/loader/runtime.js",
57
+ "prefresh-forked/utils/Runtime.d.ts",
58
+ "prefresh-forked/utils/Runtime.js",
59
+ "prefresh-forked/utils/Runtime.js.map",
60
+ "prefresh-forked/utils/constants.d.ts",
61
+ "prefresh-forked/utils/constants.js",
62
+ "prefresh-forked/utils/constants.js.map",
63
+ "prefresh-forked/utils/prefresh.d.ts",
64
+ "prefresh-forked/utils/prefresh.js",
65
+ "prefresh-forked/utils/prefresh.js.map",
66
+ "quasiquote.d.ts",
67
+ "quasiquote.js",
68
+ "quasiquote.js.map",
69
+ "rawBytesLoader.d.ts",
70
+ "rawBytesLoader.js",
71
+ "rawBytesLoader.js.map",
72
+ "rawImports.d.ts",
73
+ "rawImports.js",
74
+ "rawImports.js.map",
75
+ "requireHook.d.ts",
76
+ "requireHook.js",
77
+ "requireHook.js.map",
78
+ "resolve.d.ts",
79
+ "resolve.js",
80
+ "resolve.js.map",
81
+ "transpileLoader.d.ts",
82
+ "transpileLoader.js",
83
+ "transpileLoader.js.map",
84
+ "unmap.d.ts",
85
+ "unmap.js",
86
+ "unmap.js.map",
87
+ "util.d.ts",
88
+ "util.js",
89
+ "util.js.map",
90
+ "viteComment.d.ts",
91
+ "viteComment.js",
92
+ "viteComment.js.map"
93
+ ]
22
94
  }
@@ -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,59 @@
1
+ /* FIXME: Typings are awful in this file, the port was very crude */
2
+
3
+ import Webpack from "webpack";
4
+ import { injectRefreshFunctions, matcherOptions, NAME, prefreshUtils } from "./utils/constants.js";
5
+ import { PrefreshRuntimeModule } from "./utils/Runtime.js";
6
+ import { defineRequire } from "../requireHook.js";
7
+ const internalPrefreshLoader = defineRequire("@freshpack/webpack/internal-prefresh-loader", await import("./loader/index.js"));
8
+ export class DenoPreactRefreshPlugin {
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, {
16
+ normalModuleFactory
17
+ }) => {
18
+ if (compilation.compiler !== compiler) {
19
+ return;
20
+ }
21
+ injectRefreshFunctions(compilation);
22
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(NAME, (chunk, runtimeRequirements) => {
23
+ runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);
24
+ compilation.addRuntimeModule(chunk, new PrefreshRuntimeModule());
25
+ });
26
+ normalModuleFactory.hooks.afterResolve.tap(NAME, ({
27
+ createData: data
28
+ }) => {
29
+ if (this.matcher(data.resource) && !data.resource.includes("@prefresh") && !data.resource.includes("/prefresh-forked/loader/") && !data.resource.includes("/prefresh-forked/utils/")) {
30
+ data.loaders.unshift({
31
+ loader: internalPrefreshLoader,
32
+ options: undefined
33
+ });
34
+ }
35
+ });
36
+ });
37
+ }
38
+ apply(compiler) {
39
+ if (compiler.options.mode === "production") {
40
+ return;
41
+ }
42
+ const provide = {
43
+ [prefreshUtils]: import.meta.resolve("./utils/prefresh.js")
44
+ };
45
+ if (this.options.overlay) {
46
+ provide.__prefresh_errors__ = import.meta.resolve(this.options.overlay.module);
47
+ }
48
+ const providePlugin = new Webpack.ProvidePlugin(provide);
49
+ providePlugin.apply(compiler);
50
+ const dependency = Webpack.EntryPlugin.createDependency("@prefresh/core", {
51
+ name: "@prefresh/core"
52
+ });
53
+ compiler.hooks.make.tapAsync(NAME, (compilation, callback) => {
54
+ compilation.addEntry(compiler.context, dependency, this.options.entryOptions ?? {}, callback);
55
+ });
56
+ this.webpack5(compiler, compiler.webpack ? compiler.webpack.RuntimeGlobals : Webpack.RuntimeGlobals);
57
+ }
58
+ }
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["/* FIXME: Typings are awful in this file, the port was very crude */\n\nimport Webpack from \"webpack\";\nimport {\n injectRefreshFunctions,\n matcherOptions,\n NAME,\n prefreshUtils,\n} from \"./utils/constants.ts\";\nimport { PrefreshRuntimeModule } from \"./utils/Runtime.ts\";\nimport { defineRequire } from \"../requireHook.ts\";\n\ntype Options = {\n overlay?: {\n module: string;\n };\n entryOptions?: string | Webpack.EntryOptions;\n};\n\nconst internalPrefreshLoader = defineRequire(\n \"@freshpack/webpack/internal-prefresh-loader\",\n await import(\"./loader/index.ts\"),\n);\n\nexport class DenoPreactRefreshPlugin {\n matcher;\n constructor(public options: Options) {\n this.matcher = Webpack.ModuleFilenameHelpers.matchObject.bind(\n undefined,\n matcherOptions,\n );\n }\n\n webpack5(\n compiler: Webpack.Compiler,\n RuntimeGlobals: typeof Webpack.RuntimeGlobals,\n ) {\n compiler.hooks.compilation.tap(\n NAME,\n (compilation, { normalModuleFactory }) => {\n if (compilation.compiler !== compiler) {\n return;\n }\n\n injectRefreshFunctions(compilation);\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n NAME,\n (chunk, runtimeRequirements) => {\n runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);\n compilation.addRuntimeModule(chunk, new PrefreshRuntimeModule());\n },\n );\n\n normalModuleFactory.hooks.afterResolve.tap(\n NAME,\n ({ createData: data }) => {\n if (\n this.matcher(data.resource!) &&\n !data.resource!.includes(\"@prefresh\") &&\n !data.resource!.includes(\"/prefresh-forked/loader/\") &&\n !data.resource!.includes(\"/prefresh-forked/utils/\")\n ) {\n data.loaders!.unshift({\n loader: internalPrefreshLoader,\n options: undefined,\n });\n }\n },\n );\n },\n );\n }\n\n apply(compiler: Webpack.Compiler) {\n if (\n compiler.options.mode === \"production\"\n ) {\n return;\n }\n\n const provide = {\n [prefreshUtils]: import.meta.resolve(\"./utils/prefresh.ts\"),\n };\n\n if (this.options.overlay) {\n (provide as any).__prefresh_errors__ = import.meta.resolve(\n this.options.overlay.module,\n );\n }\n\n const providePlugin = new Webpack.ProvidePlugin(provide);\n providePlugin.apply(compiler);\n const dependency = Webpack.EntryPlugin.createDependency(\n \"@prefresh/core\",\n { name: \"@prefresh/core\" },\n );\n compiler.hooks.make.tapAsync(NAME, (compilation, callback) => {\n compilation.addEntry(\n compiler.context,\n dependency,\n this.options.entryOptions ?? {},\n callback as any,\n );\n });\n\n this.webpack5(\n compiler,\n compiler.webpack\n ? compiler.webpack.RuntimeGlobals\n : Webpack.RuntimeGlobals,\n );\n }\n}\n"],"mappings":"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","ignoreList":[]}
@@ -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,5 @@
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
+ }
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import type Webpack from \"webpack\";\nimport runtimeText from \"./runtime.js\" with { type: \"text\" };\n\nexport default function RefreshHotLoader(\n this: any,\n source: Webpack.sources.SourceMapSource,\n inputSourceMap: Webpack.sources.SourceMapSource[\"source\"],\n) {\n this.callback(null, source + \"\\n\\n\" + runtimeText, inputSourceMap);\n}\n"],"mappings":"AACA,OAAO,WAAW,MAAM,cAAc,QAAQ,IAAI,EAAE,MAAM;AAE1D,eAAe,SAAS,gBAAgB,CAEtC,MAAuC,EACvC,cAAyD,EACzD;EACA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,EAAE,cAAc,CAAC;AACpE","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ import Webpack from "webpack";
2
+ export declare class PrefreshRuntimeModule extends Webpack.RuntimeModule {
3
+ constructor();
4
+ generate(): string;
5
+ }
@@ -0,0 +1,27 @@
1
+ import Webpack from "webpack";
2
+ const NAMESPACE = "__PREFRESH__";
3
+ const beforeModule = `
4
+ self.$RefreshSig$ = function() {
5
+ var status = 'begin';
6
+ var savedType;
7
+
8
+ return function(type, key, forceReset, getCustomHooks) {
9
+ if (!savedType) savedType = type;
10
+ status = self.${NAMESPACE}.sign(type || savedType, key, forceReset, getCustomHooks, status);
11
+ return type;
12
+ }
13
+ }
14
+ `;
15
+ export class PrefreshRuntimeModule extends Webpack.RuntimeModule {
16
+ constructor() {
17
+ super("prefresh", 5);
18
+ }
19
+ generate() {
20
+ const {
21
+ runtimeTemplate
22
+ } = this.compilation;
23
+ const declare = runtimeTemplate.supportsConst() ? "const" : "var";
24
+ return Webpack.Template.asString([`${Webpack.RuntimeGlobals.interceptModuleExecution}.push(${runtimeTemplate.basicFunction("options", [`${declare} originalFactory = options.factory;`, `options.factory = ${runtimeTemplate.basicFunction("moduleObject, moduleExports, webpackRequire", [`if (typeof self !== "undefined" && typeof self.${NAMESPACE} !== "undefined") {`, Webpack.Template.indent([`${declare} prevRefreshReg = self.$RefreshReg$;`, `${declare} prevRefreshSig = self.$RefreshSig$;`, beforeModule, `${declare} reg = ${runtimeTemplate.basicFunction("currentModuleId", ["self.$RefreshReg$ = function(type, id) {", Webpack.Template.indent(`self.${NAMESPACE}.register(type, currentModuleId + ' ' + id);`), "};"])}`, "reg()", "try {", Webpack.Template.indent("originalFactory.call(this, moduleObject, moduleExports, webpackRequire);"), "} finally {", Webpack.Template.indent("self.$RefreshReg$ = prevRefreshReg;"), Webpack.Template.indent("self.$RefreshSig$ = prevRefreshSig;"), "}"]), "} else {", Webpack.Template.indent("originalFactory.call(this, moduleObject, moduleExports, webpackRequire);"), "}"])}`])})`, ""]);
25
+ }
26
+ }
27
+ //# sourceMappingURL=Runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["Runtime.ts"],"sourcesContent":["import Webpack from \"webpack\";\n\nconst NAMESPACE = \"__PREFRESH__\";\n\nconst beforeModule = `\nself.$RefreshSig$ = function() {\n var status = 'begin';\n var savedType;\n\n return function(type, key, forceReset, getCustomHooks) {\n if (!savedType) savedType = type;\n status = self.${NAMESPACE}.sign(type || savedType, key, forceReset, getCustomHooks, status);\n return type;\n }\n}\n`;\n\nexport class PrefreshRuntimeModule extends Webpack.RuntimeModule {\n constructor() {\n super(\"prefresh\", 5);\n }\n\n override generate() {\n const { runtimeTemplate } = this.compilation as any;\n const declare = runtimeTemplate.supportsConst() ? \"const\" : \"var\";\n\n return Webpack.Template.asString([\n `${Webpack.RuntimeGlobals.interceptModuleExecution}.push(${\n runtimeTemplate.basicFunction(\"options\", [\n `${declare} originalFactory = options.factory;`,\n `options.factory = ${\n runtimeTemplate.basicFunction(\n \"moduleObject, moduleExports, webpackRequire\",\n [\n `if (typeof self !== \"undefined\" && typeof self.${NAMESPACE} !== \"undefined\") {`,\n Webpack.Template.indent([\n `${declare} prevRefreshReg = self.$RefreshReg$;`,\n `${declare} prevRefreshSig = self.$RefreshSig$;`,\n beforeModule,\n `${declare} reg = ${\n runtimeTemplate.basicFunction(\n \"currentModuleId\",\n [\n \"self.$RefreshReg$ = function(type, id) {\",\n Webpack.Template.indent(\n `self.${NAMESPACE}.register(type, currentModuleId + ' ' + id);`,\n ),\n \"};\",\n ],\n )\n }`,\n \"reg()\",\n \"try {\",\n Webpack.Template.indent(\n \"originalFactory.call(this, moduleObject, moduleExports, webpackRequire);\",\n ),\n \"} finally {\",\n Webpack.Template.indent(\n \"self.$RefreshReg$ = prevRefreshReg;\",\n ),\n Webpack.Template.indent(\n \"self.$RefreshSig$ = prevRefreshSig;\",\n ),\n \"}\",\n ]),\n \"} else {\",\n Webpack.Template.indent(\n \"originalFactory.call(this, moduleObject, moduleExports, webpackRequire);\",\n ),\n \"}\",\n ],\n )\n }`,\n ])\n })`,\n \"\",\n ]);\n }\n}\n"],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS;AAE7B,MAAM,SAAS,GAAG,cAAc;AAEhC,MAAM,YAAY,GAAG;AACrB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,SAAS;AAC7B;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAM,qBAAqB,SAAS,OAAO,CAAC,aAAa,CAAC;EAC/D,WAAW,GAAG;IACZ,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;EACtB;EAES,QAAQ,GAAG;IAClB,MAAM;MAAE;IAAgB,CAAC,GAAG,IAAI,CAAC,WAAkB;IACnD,MAAM,OAAO,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,KAAK;IAEjE,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAC/B,GAAG,OAAO,CAAC,cAAc,CAAC,wBAAwB,SAChD,eAAe,CAAC,aAAa,CAAC,SAAS,EAAE,CACvC,GAAG,OAAO,qCAAqC,EAC/C,qBACE,eAAe,CAAC,aAAa,CAC3B,6CAA6C,EAC7C,CACE,kDAAkD,SAAS,qBAAqB,EAChF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CACtB,GAAG,OAAO,sCAAsC,EAChD,GAAG,OAAO,sCAAsC,EAChD,YAAY,EACZ,GAAG,OAAO,UACR,eAAe,CAAC,aAAa,CAC3B,iBAAiB,EACjB,CACE,0CAA0C,EAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,QAAQ,SAAS,8CACnB,CAAC,EACD,IAAI,CAER,CAAC,EACD,EACF,OAAO,EACP,OAAO,EACP,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,0EACF,CAAC,EACD,aAAa,EACb,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,qCACF,CAAC,EACD,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,qCACF,CAAC,EACD,GAAG,CACJ,CAAC,EACF,UAAU,EACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,0EACF,CAAC,EACD,GAAG,CAEP,CAAC,EACD,CACH,CAAC,GACD,EACH,EAAE,CACH,CAAC;EACJ;AACF","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import Webpack from "webpack";
2
+ export declare const prefreshUtils = "__prefresh_utils__";
3
+ export declare const NAME = "PrefreshWebpackPlugin";
4
+ export declare const matcherOptions: {
5
+ include: RegExp;
6
+ exclude: RegExp;
7
+ };
8
+ export declare function injectRefreshFunctions(compilation: Webpack.Compilation): void;
@@ -0,0 +1,12 @@
1
+ import Webpack from "webpack";
2
+ export const prefreshUtils = "__prefresh_utils__";
3
+ export const NAME = "PrefreshWebpackPlugin";
4
+ export const matcherOptions = {
5
+ include: /\.([jt]sx?)$/,
6
+ exclude: /node_modules|\/deno\/npm\//
7
+ };
8
+ export function injectRefreshFunctions(compilation) {
9
+ const hookVars = compilation.mainTemplate.hooks.localVars;
10
+ hookVars.tap("ReactFreshWebpackPlugin", source => Webpack.Template.asString([source, "", "// noop fns to prevent runtime errors during initialization", 'if (typeof self !== "undefined") {', Webpack.Template.indent("self.$RefreshReg$ = function () {};"), Webpack.Template.indent("self.$RefreshSig$ = function () {"), Webpack.Template.indent(Webpack.Template.indent("return function (type) {")), Webpack.Template.indent(Webpack.Template.indent(Webpack.Template.indent("return type;"))), Webpack.Template.indent(Webpack.Template.indent("};")), Webpack.Template.indent("};"), "}"]));
11
+ }
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["constants.ts"],"sourcesContent":["import Webpack from \"webpack\";\n\nexport const prefreshUtils = \"__prefresh_utils__\";\nexport const NAME = \"PrefreshWebpackPlugin\";\n\nexport const matcherOptions = {\n include: /\\.([jt]sx?)$/,\n exclude: /node_modules|\\/deno\\/npm\\//,\n};\n\nexport function injectRefreshFunctions(compilation: Webpack.Compilation) {\n const hookVars = compilation.mainTemplate.hooks.localVars;\n\n hookVars.tap(\n \"ReactFreshWebpackPlugin\",\n (source) =>\n Webpack.Template.asString([\n source,\n \"\",\n \"// noop fns to prevent runtime errors during initialization\",\n 'if (typeof self !== \"undefined\") {',\n Webpack.Template.indent(\"self.$RefreshReg$ = function () {};\"),\n Webpack.Template.indent(\"self.$RefreshSig$ = function () {\"),\n Webpack.Template.indent(\n Webpack.Template.indent(\"return function (type) {\"),\n ),\n Webpack.Template.indent(\n Webpack.Template.indent(Webpack.Template.indent(\"return type;\")),\n ),\n Webpack.Template.indent(Webpack.Template.indent(\"};\")),\n Webpack.Template.indent(\"};\"),\n \"}\",\n ]),\n );\n}\n"],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS;AAE7B,OAAO,MAAM,aAAa,GAAG,oBAAoB;AACjD,OAAO,MAAM,IAAI,GAAG,uBAAuB;AAE3C,OAAO,MAAM,cAAc,GAAG;EAC5B,OAAO,EAAE,cAAc;EACvB,OAAO,EAAE;AACX,CAAC;AAED,OAAO,SAAS,sBAAsB,CAAC,WAAgC,EAAE;EACvE,MAAM,QAAQ,GAAG,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS;EAEzD,QAAQ,CAAC,GAAG,CACV,yBAAyB,EACxB,MAAM,IACL,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxB,MAAM,EACN,EAAE,EACF,6DAA6D,EAC7D,oCAAoC,EACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,qCAAqC,CAAC,EAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,mCAAmC,CAAC,EAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,0BAA0B,CACpD,CAAC,EACD,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CACjE,CAAC,EACD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAC7B,GAAG,CACJ,CACL,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ import { flush } from "@prefresh/utils";
2
+ export declare const getExports: (m: any) => any;
3
+ export declare function registerExports(moduleExports: any, moduleId: string): void;
4
+ export declare const shouldBind: (m: any) => boolean;
5
+ export { flush };
@@ -1,24 +1,14 @@
1
1
  import { flush, isComponent } from "@prefresh/utils";
2
2
 
3
3
  // eslint-disable-next-line
4
- export const getExports = (m: any) => m.exports || m.__proto__.exports;
5
-
6
- function isSafeExport(key: string) {
7
- return (
8
- key === "__esModule" ||
9
- key === "__N_SSG" ||
10
- key === "__N_SSP" ||
11
- key === "config"
12
- );
4
+ export const getExports = m => m.exports || m.__proto__.exports;
5
+ function isSafeExport(key) {
6
+ return key === "__esModule" || key === "__N_SSG" || key === "__N_SSP" || key === "config";
13
7
  }
14
-
15
- export function registerExports(moduleExports: any, moduleId: string) {
16
- if (
17
- typeof self !== "undefined" && typeof self["__PREFRESH__"] !== "undefined"
18
- ) {
8
+ export function registerExports(moduleExports, moduleId) {
9
+ if (typeof self !== "undefined" && typeof self["__PREFRESH__"] !== "undefined") {
19
10
  self["__PREFRESH__"].register(moduleExports, moduleId + " %exports%");
20
11
  if (moduleExports == null || typeof moduleExports !== "object") return;
21
-
22
12
  for (const key in moduleExports) {
23
13
  if (isSafeExport(key)) continue;
24
14
  const exportValue = moduleExports[key];
@@ -27,33 +17,24 @@ export function registerExports(moduleExports: any, moduleId: string) {
27
17
  }
28
18
  }
29
19
  }
30
-
31
- export const shouldBind = (m: any) => {
20
+ export const shouldBind = m => {
32
21
  let isCitizen = false;
33
22
  const moduleExports = getExports(m);
34
-
35
23
  if (isComponent(moduleExports)) {
36
24
  isCitizen = true;
37
25
  }
38
-
39
- if (
40
- moduleExports === undefined ||
41
- moduleExports === null ||
42
- typeof moduleExports !== "object"
43
- ) {
26
+ if (moduleExports === undefined || moduleExports === null || typeof moduleExports !== "object") {
44
27
  isCitizen = isCitizen || false;
45
28
  } else {
46
29
  for (const key in moduleExports) {
47
30
  if (key === "__esModule") continue;
48
-
49
31
  const exportValue = moduleExports[key];
50
32
  if (isComponent(exportValue)) {
51
33
  isCitizen = isCitizen || true;
52
34
  }
53
35
  }
54
36
  }
55
-
56
37
  return isCitizen;
57
38
  };
58
-
59
39
  export { flush };
40
+ //# sourceMappingURL=prefresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["prefresh.ts"],"sourcesContent":["import { flush, isComponent } from \"@prefresh/utils\";\n\n// eslint-disable-next-line\nexport const getExports = (m: any) => m.exports || m.__proto__.exports;\n\nfunction isSafeExport(key: string) {\n return (\n key === \"__esModule\" ||\n key === \"__N_SSG\" ||\n key === \"__N_SSP\" ||\n key === \"config\"\n );\n}\n\nexport function registerExports(moduleExports: any, moduleId: string) {\n if (\n typeof self !== \"undefined\" && typeof self[\"__PREFRESH__\"] !== \"undefined\"\n ) {\n self[\"__PREFRESH__\"].register(moduleExports, moduleId + \" %exports%\");\n if (moduleExports == null || typeof moduleExports !== \"object\") return;\n\n for (const key in moduleExports) {\n if (isSafeExport(key)) continue;\n const exportValue = moduleExports[key];\n const typeID = moduleId + \" %exports% \" + key;\n self[\"__PREFRESH__\"].register(exportValue, typeID);\n }\n }\n}\n\nexport const shouldBind = (m: any) => {\n let isCitizen = false;\n const moduleExports = getExports(m);\n\n if (isComponent(moduleExports)) {\n isCitizen = true;\n }\n\n if (\n moduleExports === undefined ||\n moduleExports === null ||\n typeof moduleExports !== \"object\"\n ) {\n isCitizen = isCitizen || false;\n } else {\n for (const key in moduleExports) {\n if (key === \"__esModule\") continue;\n\n const exportValue = moduleExports[key];\n if (isComponent(exportValue)) {\n isCitizen = isCitizen || true;\n }\n }\n }\n\n return isCitizen;\n};\n\nexport { flush };\n"],"mappings":"AAAA,SAAS,KAAK,EAAE,WAAW,QAAQ,iBAAiB;;AAEpD;AACA,OAAO,MAAM,UAAU,GAAI,CAAM,IAAK,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,SAAS,CAAC,OAAO;AAEtE,SAAS,YAAY,CAAC,GAAW,EAAE;EACjC,OACE,GAAG,KAAK,YAAY,IACpB,GAAG,KAAK,SAAS,IACjB,GAAG,KAAK,SAAS,IACjB,GAAG,KAAK,QAAQ;AAEpB;AAEA,OAAO,SAAS,eAAe,CAAC,aAAkB,EAAE,QAAgB,EAAE;EACpE,IACE,OAAO,IAAI,KAAK,WAAW,IAAI,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,WAAW,EAC1E;IACA,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,YAAY,CAAC;IACrE,IAAI,aAAa,IAAI,IAAI,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;IAEhE,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;MAC/B,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;MACvB,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC;MACtC,MAAM,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,GAAG;MAC7C,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IACpD;EACF;AACF;AAEA,OAAO,MAAM,UAAU,GAAI,CAAM,IAAK;EACpC,IAAI,SAAS,GAAG,KAAK;EACrB,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC;EAEnC,IAAI,WAAW,CAAC,aAAa,CAAC,EAAE;IAC9B,SAAS,GAAG,IAAI;EAClB;EAEA,IACE,aAAa,KAAK,SAAS,IAC3B,aAAa,KAAK,IAAI,IACtB,OAAO,aAAa,KAAK,QAAQ,EACjC;IACA,SAAS,GAAG,SAAS,IAAI,KAAK;EAChC,CAAC,MAAM;IACL,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;MAC/B,IAAI,GAAG,KAAK,YAAY,EAAE;MAE1B,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC;MACtC,IAAI,WAAW,CAAC,WAAW,CAAC,EAAE;QAC5B,SAAS,GAAG,SAAS,IAAI,IAAI;MAC/B;IACF;EACF;EAEA,OAAO,SAAS;AAClB,CAAC;AAED,SAAS,KAAK","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ export type JsRaw = {
2
+ _jsRaw: string;
3
+ };
4
+ type ToJsRaw = string | JsRaw | (ToJsRaw[]) | Record<string, string | JsRaw> | Map<string, JsRaw> | undefined;
5
+ export declare function toJsRaw(v: ToJsRaw): JsRaw;
6
+ export declare const js: (template: TemplateStringsArray, ...subs: ToJsRaw[]) => {
7
+ _jsRaw: string;
8
+ };
9
+ export {};
package/quasiquote.js ADDED
@@ -0,0 +1,32 @@
1
+ export function toJsRaw(v) {
2
+ if (typeof v === "string") {
3
+ return {
4
+ _jsRaw: JSON.stringify(v)
5
+ };
6
+ }
7
+ if (v instanceof Array) {
8
+ return {
9
+ _jsRaw: "[" + v.map(v => toJsRaw(v)._jsRaw).join(v.length > 5 ? ",\n" : ",") + "]"
10
+ };
11
+ }
12
+ if (v instanceof Map) {
13
+ return js`new Map(${v.entries().map(([name, v]) => js`[${name},${v}]`).toArray()})`;
14
+ }
15
+ if (typeof v === "object" && !("_jsRaw" in v)) {
16
+ const entries = Object.entries(v);
17
+ return {
18
+ _jsRaw: "{" + entries.map(([name, v]) => `${name}:${toJsRaw(v)._jsRaw}`).join(entries.length > 10 ? ",\n" : ",") + "}"
19
+ };
20
+ }
21
+ if (typeof v === "undefined") {
22
+ return js`undefined`;
23
+ }
24
+ if (v === null) {
25
+ return js`null`;
26
+ }
27
+ return v;
28
+ }
29
+ export const js = (template, ...subs) => ({
30
+ _jsRaw: String.raw(template, ...subs.map(v => toJsRaw(v)._jsRaw))
31
+ });
32
+ //# sourceMappingURL=quasiquote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["quasiquote.ts"],"sourcesContent":["export type JsRaw = { _jsRaw: string };\ntype ToJsRaw =\n | string\n | JsRaw\n | (ToJsRaw[])\n | Record<string, string | JsRaw>\n | Map<string, JsRaw>\n | undefined;\nexport function toJsRaw(v: ToJsRaw): JsRaw {\n if (typeof v === \"string\") {\n return { _jsRaw: JSON.stringify(v) };\n }\n if (v instanceof Array) {\n return {\n _jsRaw: \"[\" + v.map((v) =>\n toJsRaw(v)._jsRaw\n ).join(v.length > 5 ? \",\\n\" : \",\") +\n \"]\",\n };\n }\n if (v instanceof Map) {\n return js`new Map(${\n v.entries().map(([name, v]) => js`[${name},${v}]`).toArray()\n })`;\n }\n if (typeof v === \"object\" && !(\"_jsRaw\" in v)) {\n const entries = Object.entries(v);\n return {\n _jsRaw: \"{\" + entries.map(([name, v]) =>\n `${name}:${toJsRaw(v)._jsRaw}`\n ).join(entries.length > 10 ? \",\\n\" : \",\") + \"}\",\n };\n }\n if (typeof v === \"undefined\") {\n return js`undefined`;\n }\n if (v === null) {\n return js`null`;\n }\n return v as JsRaw;\n}\nexport const js = (template: TemplateStringsArray, ...subs: ToJsRaw[]) => ({\n _jsRaw: String.raw(template, ...subs.map((v) => toJsRaw(v)._jsRaw)),\n});\n"],"mappings":"AAQA,OAAO,SAAS,OAAO,CAAC,CAAU,EAAS;EACzC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;IACzB,OAAO;MAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAAE,CAAC;EACtC;EACA,IAAI,CAAC,YAAY,KAAK,EAAE;IACtB,OAAO;MACL,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAE,CAAC,IACpB,OAAO,CAAC,CAAC,CAAC,CAAC,MACb,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,GAChC;IACJ,CAAC;EACH;EACA,IAAI,CAAC,YAAY,GAAG,EAAE;IACpB,OAAO,EAAE,WACP,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAC3D;EACL;EACA,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,EAAE,QAAQ,IAAI,CAAC,CAAC,EAAE;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACjC,OAAO;MACL,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAClC,GAAG,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAC9B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC,GAAG;IAC9C,CAAC;EACH;EACA,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE;IAC5B,OAAO,EAAE,WAAW;EACtB;EACA,IAAI,CAAC,KAAK,IAAI,EAAE;IACd,OAAO,EAAE,MAAM;EACjB;EACA,OAAO,CAAC;AACV;AACA,OAAO,MAAM,EAAE,GAAG,CAAC,QAA8B,EAAE,GAAG,IAAe,MAAM;EACzE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,CAAE,CAAC,IAAK,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACpE,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from "webpack";
2
+ type Context = LoaderContext<Record<never, never>>;
3
+ export declare function pitch(this: Context): string;
4
+ export default function rawBytesLoader(this: Context, source: string): string;
5
+ export {};
@@ -0,0 +1,10 @@
1
+ export function pitch() {
2
+ const resource = this.resourcePath;
3
+ this.addDependency(resource);
4
+ const request = `${resource}.webpack[asset/resource]!=!${resource}`;
5
+ return [`import url from ${JSON.stringify(request)};`, `export default new Uint8Array(await (await fetch(url)).arrayBuffer());`].join("\n");
6
+ }
7
+ export default function rawBytesLoader(source) {
8
+ return source;
9
+ }
10
+ //# sourceMappingURL=rawBytesLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["rawBytesLoader.ts"],"sourcesContent":["import type { LoaderContext } from \"webpack\";\n\ntype Context = LoaderContext<Record<never, never>>;\n\nexport function pitch(this: Context): string {\n const resource = this.resourcePath;\n this.addDependency(resource);\n const request = `${resource}.webpack[asset/resource]!=!${resource}`;\n return [\n `import url from ${JSON.stringify(request)};`,\n `export default new Uint8Array(await (await fetch(url)).arrayBuffer());`,\n ].join(\"\\n\");\n}\n\nexport default function rawBytesLoader(this: Context, source: string): string {\n return source;\n}\n"],"mappings":"AAIA,OAAO,SAAS,KAAK,GAAwB;EAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY;EAClC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;EAC5B,MAAM,OAAO,GAAG,GAAG,QAAQ,8BAA8B,QAAQ,EAAE;EACnE,OAAO,CACL,mBAAmB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAC7C,wEAAwE,CACzE,CAAC,IAAI,CAAC,IAAI,CAAC;AACd;AAEA,eAAe,SAAS,cAAc,CAAgB,MAAc,EAAU;EAC5E,OAAO,MAAM;AACf","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { Compiler } from "webpack";
2
+ export interface RawImportsOptions {
3
+ /**
4
+ * "resource" (default) emits a bytes import as a standalone asset fetched at runtime,
5
+ * "inline" embeds it into the importing chunk as base64.
6
+ */
7
+ bytes?: "resource" | "inline";
8
+ }
9
+ export declare class RawImportsPlugin {
10
+ options: RawImportsOptions;
11
+ constructor(options?: RawImportsOptions);
12
+ apply(compiler: Compiler): void;
13
+ }
package/rawImports.js ADDED
@@ -0,0 +1,44 @@
1
+ import { defineRequire } from "./requireHook.js";
2
+ const NAME = "RawImportsPlugin";
3
+ const internalRawBytesLoader = defineRequire("@freshpack/webpack/internal-raw-bytes-loader", await import("./rawBytesLoader.js"));
4
+ function setModuleType(factory, data, type) {
5
+ data.type = type;
6
+ data.settings.type = type;
7
+ data.parser = factory.getParser(type);
8
+ data.parserOptions = undefined;
9
+ data.generator = factory.getGenerator(type);
10
+ data.generatorOptions = undefined;
11
+ }
12
+ export class RawImportsPlugin {
13
+ constructor(options = {}) {
14
+ this.options = options;
15
+ }
16
+ apply(compiler) {
17
+ compiler.hooks.compilation.tap(NAME, (_compilation, {
18
+ normalModuleFactory
19
+ }) => {
20
+ normalModuleFactory.hooks.afterResolve.tap(NAME, resolveData => {
21
+ const attributes = resolveData.dependencies[0]?.attributes;
22
+ const data = resolveData.createData;
23
+ if (attributes?.type === "text") {
24
+ setModuleType(normalModuleFactory, data, "asset/source");
25
+ data.loaders = [];
26
+ } else if (attributes?.type === "bytes") {
27
+ if (this.options.bytes === "inline") {
28
+ setModuleType(normalModuleFactory, data, "asset/bytes");
29
+ data.loaders = [];
30
+ } else {
31
+ setModuleType(normalModuleFactory, data, "javascript/esm");
32
+ data.loaders = [{
33
+ loader: internalRawBytesLoader,
34
+ options: {},
35
+ ident: null,
36
+ type: null
37
+ }];
38
+ }
39
+ }
40
+ });
41
+ });
42
+ }
43
+ }
44
+ //# sourceMappingURL=rawImports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["rawImports.ts"],"sourcesContent":["import type { Compiler } from \"webpack\";\nimport { defineRequire } from \"./requireHook.ts\";\n\nconst NAME = \"RawImportsPlugin\";\n\nconst internalRawBytesLoader = defineRequire(\n \"@freshpack/webpack/internal-raw-bytes-loader\",\n await import(\"./rawBytesLoader.ts\"),\n);\n\ntype ModuleFactory = {\n getParser(type: string): unknown;\n getGenerator(type: string): unknown;\n};\n\ntype CreateData = {\n type: string;\n settings: { type?: string };\n parser?: unknown;\n parserOptions?: unknown;\n generator?: unknown;\n generatorOptions?: unknown;\n loaders?: {\n loader: string;\n options: unknown;\n ident: string | null;\n type: string | null;\n }[];\n};\n\nexport interface RawImportsOptions {\n /**\n * \"resource\" (default) emits a bytes import as a standalone asset fetched at runtime,\n * \"inline\" embeds it into the importing chunk as base64.\n */\n bytes?: \"resource\" | \"inline\";\n}\n\nfunction setModuleType(\n factory: ModuleFactory,\n data: CreateData,\n type: string,\n) {\n data.type = type;\n data.settings.type = type;\n data.parser = factory.getParser(type);\n data.parserOptions = undefined;\n data.generator = factory.getGenerator(type);\n data.generatorOptions = undefined;\n}\n\nexport class RawImportsPlugin {\n constructor(public options: RawImportsOptions = {}) {}\n\n apply(compiler: Compiler) {\n compiler.hooks.compilation.tap(\n NAME,\n (_compilation, { normalModuleFactory }) => {\n normalModuleFactory.hooks.afterResolve.tap(NAME, (resolveData) => {\n const attributes = (resolveData.dependencies[0] as undefined | {\n attributes?: { type?: string };\n })?.attributes;\n const data = resolveData.createData as unknown as CreateData;\n if (attributes?.type === \"text\") {\n setModuleType(normalModuleFactory, data, \"asset/source\");\n data.loaders = [];\n } else if (attributes?.type === \"bytes\") {\n if (this.options.bytes === \"inline\") {\n setModuleType(normalModuleFactory, data, \"asset/bytes\");\n data.loaders = [];\n } else {\n setModuleType(normalModuleFactory, data, \"javascript/esm\");\n data.loaders = [{\n loader: internalRawBytesLoader,\n options: {},\n ident: null,\n type: null,\n }];\n }\n }\n });\n },\n );\n }\n}\n"],"mappings":"AACA,SAAS,aAAa,QAAQ,kBAAkB;AAEhD,MAAM,IAAI,GAAG,kBAAkB;AAE/B,MAAM,sBAAsB,GAAG,aAAa,CAC1C,8CAA8C,EAC9C,MAAM,OAAO,qBAAqB,CACpC,CAAC;AA8BD,SAAS,aAAa,CACpB,OAAsB,EACtB,IAAgB,EAChB,IAAY,EACZ;EACA,IAAI,CAAC,IAAI,GAAG,IAAI;EAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI;EACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;EACrC,IAAI,CAAC,aAAa,GAAG,SAAS;EAC9B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC;EAC3C,IAAI,CAAC,gBAAgB,GAAG,SAAS;AACnC;AAEA,OAAO,MAAM,gBAAgB,CAAC;EAC5B,WAAW,CAAQ,OAA0B,GAAG,CAAC,CAAC,EAAE;IAAA,KAAjC,OAA0B,GAA1B,OAA0B;EAAQ;EAErD,KAAK,CAAC,QAAkB,EAAE;IACxB,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAC5B,IAAI,EACJ,CAAC,YAAY,EAAE;MAAE;IAAoB,CAAC,KAAK;MACzC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAG,WAAW,IAAK;QAChE,MAAM,UAAU,GAAI,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,EAE3C,UAAU;QACd,MAAM,IAAI,GAAG,WAAW,CAAC,UAAmC;QAC5D,IAAI,UAAU,EAAE,IAAI,KAAK,MAAM,EAAE;UAC/B,aAAa,CAAC,mBAAmB,EAAE,IAAI,EAAE,cAAc,CAAC;UACxD,IAAI,CAAC,OAAO,GAAG,EAAE;QACnB,CAAC,MAAM,IAAI,UAAU,EAAE,IAAI,KAAK,OAAO,EAAE;UACvC,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;YACnC,aAAa,CAAC,mBAAmB,EAAE,IAAI,EAAE,aAAa,CAAC;YACvD,IAAI,CAAC,OAAO,GAAG,EAAE;UACnB,CAAC,MAAM;YACL,aAAa,CAAC,mBAAmB,EAAE,IAAI,EAAE,gBAAgB,CAAC;YAC1D,IAAI,CAAC,OAAO,GAAG,CAAC;cACd,MAAM,EAAE,sBAAsB;cAC9B,OAAO,EAAE,CAAC,CAAC;cACX,KAAK,EAAE,IAAI;cACX,IAAI,EAAE;YACR,CAAC,CAAC;UACJ;QACF;MACF,CAAC,CAAC;IACJ,CACF,CAAC;EACH;AACF","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare function defineRequire(name: string, module: Record<string, unknown>): string;
@@ -1,22 +1,17 @@
1
1
  import Module from "node:module";
2
-
3
- const overrides = new Map<string, Record<string, unknown>>();
2
+ const overrides = new Map();
4
3
  let overrideId = 0;
5
-
6
4
  const originalLoad = Module.prototype.require;
7
- Module.prototype.require = function hookedRequire(id: string) {
5
+ Module.prototype.require = function hookedRequire(id) {
8
6
  const override = overrides.get(id);
9
7
  if (override) {
10
8
  return override;
11
9
  }
12
- return originalLoad.apply(this, arguments as any);
10
+ return originalLoad.apply(this, arguments);
13
11
  };
14
-
15
- export function defineRequire(
16
- name: string,
17
- module: Record<string, unknown>,
18
- ): string {
12
+ export function defineRequire(name, module) {
19
13
  const generatedName = `override:${name}/${overrideId++}`;
20
14
  overrides.set(generatedName, module);
21
15
  return generatedName;
22
16
  }
17
+ //# sourceMappingURL=requireHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["requireHook.ts"],"sourcesContent":["import Module from \"node:module\";\n\nconst overrides = new Map<string, Record<string, unknown>>();\nlet overrideId = 0;\n\nconst originalLoad = Module.prototype.require;\nModule.prototype.require = function hookedRequire(id: string) {\n const override = overrides.get(id);\n if (override) {\n return override;\n }\n return originalLoad.apply(this, arguments as any);\n};\n\nexport function defineRequire(\n name: string,\n module: Record<string, unknown>,\n): string {\n const generatedName = `override:${name}/${overrideId++}`;\n overrides.set(generatedName, module);\n return generatedName;\n}\n"],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa;AAEhC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAkC,CAAC;AAC5D,IAAI,UAAU,GAAG,CAAC;AAElB,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO;AAC7C,MAAM,CAAC,SAAS,CAAC,OAAO,GAAG,SAAS,aAAa,CAAC,EAAU,EAAE;EAC5D,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;EAClC,IAAI,QAAQ,EAAE;IACZ,OAAO,QAAQ;EACjB;EACA,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,SAAgB,CAAC;AACnD,CAAC;AAED,OAAO,SAAS,aAAa,CAC3B,IAAY,EACZ,MAA+B,EACvB;EACR,MAAM,aAAa,GAAG,YAAY,IAAI,IAAI,UAAU,EAAE,EAAE;EACxD,SAAS,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC;EACpC,OAAO,aAAa;AACtB","ignoreList":[]}
package/resolve.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { type Loader, Workspace, type WorkspaceOptions } from "@deno/loader";
2
+ import { type Compiler } from "webpack";
3
+ export declare class DenoLoaderPlugin {
4
+ #private;
5
+ opts: WorkspaceOptions;
6
+ patchImport: (f: string, v: string) => string;
7
+ workspace: Workspace;
8
+ get loader(): Promise<Loader>;
9
+ constructor(opts: WorkspaceOptions, patchImport?: (f: string, v: string) => string);
10
+ apply(compiler: Compiler): void;
11
+ }