@freshpack/webpack 1.0.1 → 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 +6 -0
- package/denoEnv.js +40 -52
- package/denoEnv.js.map +1 -0
- package/fresh.js +223 -246
- 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 +1 -0
- package/mod.js +2 -0
- package/mod.js.map +1 -0
- package/package.json +23 -3
- package/prefresh-forked/index.js +50 -48
- package/prefresh-forked/index.js.map +1 -0
- package/prefresh-forked/loader/index.js +2 -1
- package/prefresh-forked/loader/index.js.map +1 -0
- package/prefresh-forked/utils/Runtime.js +11 -36
- package/prefresh-forked/utils/Runtime.js.map +1 -0
- package/prefresh-forked/utils/constants.js +5 -16
- package/prefresh-forked/utils/constants.js.map +1 -0
- package/prefresh-forked/utils/prefresh.js +30 -37
- package/prefresh-forked/utils/prefresh.js.map +1 -0
- package/quasiquote.js +28 -26
- package/quasiquote.js.map +1 -0
- package/rawBytesLoader.js +6 -8
- package/rawBytesLoader.js.map +1 -0
- package/rawImports.js +37 -37
- package/rawImports.js.map +1 -0
- package/requireHook.js +9 -8
- package/requireHook.js.map +1 -0
- package/resolve.js +357 -367
- package/resolve.js.map +1 -0
- package/transpileLoader.js +34 -26
- package/transpileLoader.js.map +1 -0
- package/unmap.js +88 -90
- package/unmap.js.map +1 -0
- package/util.js +32 -34
- package/util.js.map +1 -0
- package/viteComment.js +20 -22
- package/viteComment.js.map +1 -0
package/rawBytesLoader.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export function pitch() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
`import url from ${JSON.stringify(request)};`,
|
|
7
|
-
`export default new Uint8Array(await (await fetch(url)).arrayBuffer());`,
|
|
8
|
-
].join("\n");
|
|
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");
|
|
9
6
|
}
|
|
10
7
|
export default function rawBytesLoader(source) {
|
|
11
|
-
|
|
8
|
+
return source;
|
|
12
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":[]}
|
package/rawImports.js
CHANGED
|
@@ -2,43 +2,43 @@ import { defineRequire } from "./requireHook.js";
|
|
|
2
2
|
const NAME = "RawImportsPlugin";
|
|
3
3
|
const internalRawBytesLoader = defineRequire("@freshpack/webpack/internal-raw-bytes-loader", await import("./rawBytesLoader.js"));
|
|
4
4
|
function setModuleType(factory, data, type) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
}
|
|
12
12
|
export class RawImportsPlugin {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
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
|
+
}
|
|
44
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":[]}
|
package/requireHook.js
CHANGED
|
@@ -3,14 +3,15 @@ const overrides = new Map();
|
|
|
3
3
|
let overrideId = 0;
|
|
4
4
|
const originalLoad = Module.prototype.require;
|
|
5
5
|
Module.prototype.require = function hookedRequire(id) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const override = overrides.get(id);
|
|
7
|
+
if (override) {
|
|
8
|
+
return override;
|
|
9
|
+
}
|
|
10
|
+
return originalLoad.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
export function defineRequire(name, module) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const generatedName = `override:${name}/${overrideId++}`;
|
|
14
|
+
overrides.set(generatedName, module);
|
|
15
|
+
return generatedName;
|
|
16
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":[]}
|