@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.
- package/CHANGELOG.md +10 -0
- package/LICENSE +13 -12
- package/denoEnv.d.ts +12 -0
- package/denoEnv.js +61 -0
- package/fresh.d.ts +39 -0
- package/fresh.js +268 -0
- package/mod.d.ts +7 -0
- package/mod.js +7 -0
- package/package.json +60 -8
- package/prefresh-forked/index.d.ts +15 -0
- package/prefresh-forked/index.js +57 -0
- package/prefresh-forked/loader/index.d.ts +2 -0
- package/prefresh-forked/loader/index.js +4 -0
- package/prefresh-forked/utils/Runtime.d.ts +5 -0
- package/prefresh-forked/utils/Runtime.js +52 -0
- package/prefresh-forked/utils/constants.d.ts +8 -0
- package/prefresh-forked/utils/{constants.ts → constants.js} +8 -20
- package/prefresh-forked/utils/prefresh.d.ts +5 -0
- package/prefresh-forked/utils/prefresh.js +47 -0
- package/quasiquote.d.ts +9 -0
- package/quasiquote.js +30 -0
- package/rawBytesLoader.d.ts +5 -0
- package/rawBytesLoader.js +12 -0
- package/rawImports.d.ts +13 -0
- package/rawImports.js +44 -0
- package/requireHook.d.ts +1 -0
- package/requireHook.js +16 -0
- package/resolve.d.ts +11 -0
- package/resolve.js +405 -0
- package/transpileLoader.d.ts +9 -0
- package/transpileLoader.js +38 -0
- package/unmap.d.ts +9 -0
- package/unmap.js +96 -0
- package/util.d.ts +9 -0
- package/util.js +54 -0
- package/viteComment.d.ts +8 -0
- package/viteComment.js +30 -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/createTemplate.ts +0 -76
- package/prefresh-forked/utils/injectEntry.ts +0 -28
- package/prefresh-forked/utils/prefresh.ts +0 -59
- package/quasiquote.ts +0 -44
- package/rawBytesLoader.ts +0 -17
- package/rawImports.ts +0 -85
- package/requireHook.ts +0 -22
- package/resolve.ts +0 -588
- package/transpileLoader.ts +0 -59
- package/unmap.ts +0 -154
- package/util.ts +0 -58
- package/viteComment.ts +0 -41
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { Template } = require("webpack");
|
|
2
|
-
|
|
3
|
-
const NAMESPACE = "__PREFRESH__";
|
|
4
|
-
|
|
5
|
-
const beforeModule = `
|
|
6
|
-
var prevRefreshReg = self.$RefreshReg$;
|
|
7
|
-
var prevRefreshSig = self.$RefreshSig$;
|
|
8
|
-
|
|
9
|
-
self.$RefreshSig$ = function() {
|
|
10
|
-
var status = 'begin';
|
|
11
|
-
var savedType;
|
|
12
|
-
return function(type, key, forceReset, getCustomHooks) {
|
|
13
|
-
if (!savedType) savedType = type;
|
|
14
|
-
status = self.${NAMESPACE}.sign(type || savedType, key, forceReset, getCustomHooks, status);
|
|
15
|
-
return type;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
self.$RefreshReg$ = function(type, id) {
|
|
20
|
-
self.${NAMESPACE}.register(type, module.id + ' ' + id);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
const afterModule = `
|
|
27
|
-
} finally {
|
|
28
|
-
self.$RefreshReg$ = prevRefreshReg;
|
|
29
|
-
self.$RefreshSig$ = prevRefreshSig;
|
|
30
|
-
}
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
export function createRefreshTemplate(
|
|
34
|
-
source,
|
|
35
|
-
chunk,
|
|
36
|
-
hash,
|
|
37
|
-
mainTemplate,
|
|
38
|
-
options,
|
|
39
|
-
) {
|
|
40
|
-
let filename = mainTemplate.outputOptions.filename;
|
|
41
|
-
if (typeof filename === "function") {
|
|
42
|
-
filename = filename({
|
|
43
|
-
chunk,
|
|
44
|
-
hash,
|
|
45
|
-
contentHashType: "javascript",
|
|
46
|
-
hashWithLength: (length) =>
|
|
47
|
-
mainTemplate.renderCurrentHashCode(hash, length),
|
|
48
|
-
noChunkHash: mainTemplate.useChunkHash(chunk),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!filename || !filename.includes(".js")) {
|
|
53
|
-
return source;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const lines = source.split("\n");
|
|
57
|
-
|
|
58
|
-
// Webpack generates this line whenever the mainTemplate is called
|
|
59
|
-
const moduleInitializationLineNumber = lines.findIndex((line) =>
|
|
60
|
-
options.runsInNextJs
|
|
61
|
-
? line.includes("modules[moduleId].call(")
|
|
62
|
-
: line.startsWith("modules[moduleId].call")
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (moduleInitializationLineNumber === -1) {
|
|
66
|
-
return source;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return Template.asString([
|
|
70
|
-
...lines.slice(0, moduleInitializationLineNumber),
|
|
71
|
-
beforeModule,
|
|
72
|
-
Template.indent(lines[moduleInitializationLineNumber]),
|
|
73
|
-
afterModule,
|
|
74
|
-
...lines.slice(moduleInitializationLineNumber + 1, lines.length),
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export function injectEntry(originalEntry: any): any {
|
|
2
|
-
const entryInjects = [require.resolve("@prefresh/core")];
|
|
3
|
-
|
|
4
|
-
if (typeof originalEntry === "string") {
|
|
5
|
-
return [...entryInjects, originalEntry];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(originalEntry)) {
|
|
9
|
-
return [...entryInjects, ...originalEntry];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof originalEntry === "object") {
|
|
13
|
-
return Object.entries(originalEntry).reduce(
|
|
14
|
-
(acc, [curKey, curEntry]) => ({
|
|
15
|
-
...acc,
|
|
16
|
-
[curKey]: injectEntry(curEntry),
|
|
17
|
-
}),
|
|
18
|
-
{},
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof originalEntry === "function") {
|
|
23
|
-
return (...args: any[]) =>
|
|
24
|
-
Promise.resolve(originalEntry(...args)).then(injectEntry);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
throw new Error("Can't detect valid entry point.");
|
|
28
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { flush, isComponent } from "@prefresh/utils";
|
|
2
|
-
|
|
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
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function registerExports(moduleExports: any, moduleId: string) {
|
|
16
|
-
if (
|
|
17
|
-
typeof self !== "undefined" && typeof self["__PREFRESH__"] !== "undefined"
|
|
18
|
-
) {
|
|
19
|
-
self["__PREFRESH__"].register(moduleExports, moduleId + " %exports%");
|
|
20
|
-
if (moduleExports == null || typeof moduleExports !== "object") return;
|
|
21
|
-
|
|
22
|
-
for (const key in moduleExports) {
|
|
23
|
-
if (isSafeExport(key)) continue;
|
|
24
|
-
const exportValue = moduleExports[key];
|
|
25
|
-
const typeID = moduleId + " %exports% " + key;
|
|
26
|
-
self["__PREFRESH__"].register(exportValue, typeID);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const shouldBind = (m: any) => {
|
|
32
|
-
let isCitizen = false;
|
|
33
|
-
const moduleExports = getExports(m);
|
|
34
|
-
|
|
35
|
-
if (isComponent(moduleExports)) {
|
|
36
|
-
isCitizen = true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
moduleExports === undefined ||
|
|
41
|
-
moduleExports === null ||
|
|
42
|
-
typeof moduleExports !== "object"
|
|
43
|
-
) {
|
|
44
|
-
isCitizen = isCitizen || false;
|
|
45
|
-
} else {
|
|
46
|
-
for (const key in moduleExports) {
|
|
47
|
-
if (key === "__esModule") continue;
|
|
48
|
-
|
|
49
|
-
const exportValue = moduleExports[key];
|
|
50
|
-
if (isComponent(exportValue)) {
|
|
51
|
-
isCitizen = isCitizen || true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return isCitizen;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export { flush };
|
package/quasiquote.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export type JsRaw = { _jsRaw: string };
|
|
2
|
-
type ToJsRaw =
|
|
3
|
-
| string
|
|
4
|
-
| JsRaw
|
|
5
|
-
| (ToJsRaw[])
|
|
6
|
-
| Record<string, string | JsRaw>
|
|
7
|
-
| Map<string, JsRaw>
|
|
8
|
-
| undefined;
|
|
9
|
-
export function toJsRaw(v: ToJsRaw): JsRaw {
|
|
10
|
-
if (typeof v === "string") {
|
|
11
|
-
return { _jsRaw: JSON.stringify(v) };
|
|
12
|
-
}
|
|
13
|
-
if (v instanceof Array) {
|
|
14
|
-
return {
|
|
15
|
-
_jsRaw: "[" + v.map((v) =>
|
|
16
|
-
toJsRaw(v)._jsRaw
|
|
17
|
-
).join(v.length > 5 ? ",\n" : ",") +
|
|
18
|
-
"]",
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
if (v instanceof Map) {
|
|
22
|
-
return js`new Map(${
|
|
23
|
-
v.entries().map(([name, v]) => js`[${name},${v}]`).toArray()
|
|
24
|
-
})`;
|
|
25
|
-
}
|
|
26
|
-
if (typeof v === "object" && !("_jsRaw" in v)) {
|
|
27
|
-
const entries = Object.entries(v);
|
|
28
|
-
return {
|
|
29
|
-
_jsRaw: "{" + entries.map(([name, v]) =>
|
|
30
|
-
`${name}:${toJsRaw(v)._jsRaw}`
|
|
31
|
-
).join(entries.length > 10 ? ",\n" : ",") + "}",
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (typeof v === "undefined") {
|
|
35
|
-
return js`undefined`;
|
|
36
|
-
}
|
|
37
|
-
if (v === null) {
|
|
38
|
-
return js`null`;
|
|
39
|
-
}
|
|
40
|
-
return v as JsRaw;
|
|
41
|
-
}
|
|
42
|
-
export const js = (template: TemplateStringsArray, ...subs: ToJsRaw[]) => ({
|
|
43
|
-
_jsRaw: String.raw(template, ...subs.map((v) => toJsRaw(v)._jsRaw)),
|
|
44
|
-
});
|
package/rawBytesLoader.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { LoaderContext } from "webpack";
|
|
2
|
-
|
|
3
|
-
type Context = LoaderContext<Record<never, never>>;
|
|
4
|
-
|
|
5
|
-
export function pitch(this: Context): string {
|
|
6
|
-
const resource = this.resourcePath;
|
|
7
|
-
this.addDependency(resource);
|
|
8
|
-
const request = `${resource}.webpack[asset/resource]!=!${resource}`;
|
|
9
|
-
return [
|
|
10
|
-
`import url from ${JSON.stringify(request)};`,
|
|
11
|
-
`export default new Uint8Array(await (await fetch(url)).arrayBuffer());`,
|
|
12
|
-
].join("\n");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default function rawBytesLoader(this: Context, source: string): string {
|
|
16
|
-
return source;
|
|
17
|
-
}
|
package/rawImports.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { Compiler } from "webpack";
|
|
2
|
-
import { defineRequire } from "./requireHook.ts";
|
|
3
|
-
|
|
4
|
-
const NAME = "RawImportsPlugin";
|
|
5
|
-
|
|
6
|
-
const internalRawBytesLoader = defineRequire(
|
|
7
|
-
"@freshpack/webpack/internal-raw-bytes-loader",
|
|
8
|
-
await import("./rawBytesLoader.ts"),
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
type ModuleFactory = {
|
|
12
|
-
getParser(type: string): unknown;
|
|
13
|
-
getGenerator(type: string): unknown;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type CreateData = {
|
|
17
|
-
type: string;
|
|
18
|
-
settings: { type?: string };
|
|
19
|
-
parser?: unknown;
|
|
20
|
-
parserOptions?: unknown;
|
|
21
|
-
generator?: unknown;
|
|
22
|
-
generatorOptions?: unknown;
|
|
23
|
-
loaders?: {
|
|
24
|
-
loader: string;
|
|
25
|
-
options: unknown;
|
|
26
|
-
ident: string | null;
|
|
27
|
-
type: string | null;
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export interface RawImportsOptions {
|
|
32
|
-
/**
|
|
33
|
-
* "resource" (default) emits a bytes import as a standalone asset fetched at runtime,
|
|
34
|
-
* "inline" embeds it into the importing chunk as base64.
|
|
35
|
-
*/
|
|
36
|
-
bytes?: "resource" | "inline";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function setModuleType(
|
|
40
|
-
factory: ModuleFactory,
|
|
41
|
-
data: CreateData,
|
|
42
|
-
type: string,
|
|
43
|
-
) {
|
|
44
|
-
data.type = type;
|
|
45
|
-
data.settings.type = type;
|
|
46
|
-
data.parser = factory.getParser(type);
|
|
47
|
-
data.parserOptions = undefined;
|
|
48
|
-
data.generator = factory.getGenerator(type);
|
|
49
|
-
data.generatorOptions = undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class RawImportsPlugin {
|
|
53
|
-
constructor(public options: RawImportsOptions = {}) {}
|
|
54
|
-
|
|
55
|
-
apply(compiler: Compiler) {
|
|
56
|
-
compiler.hooks.compilation.tap(
|
|
57
|
-
NAME,
|
|
58
|
-
(_compilation, { normalModuleFactory }) => {
|
|
59
|
-
normalModuleFactory.hooks.afterResolve.tap(NAME, (resolveData) => {
|
|
60
|
-
const attributes = (resolveData.dependencies[0] as undefined | {
|
|
61
|
-
attributes?: { type?: string };
|
|
62
|
-
})?.attributes;
|
|
63
|
-
const data = resolveData.createData as unknown as CreateData;
|
|
64
|
-
if (attributes?.type === "text") {
|
|
65
|
-
setModuleType(normalModuleFactory, data, "asset/source");
|
|
66
|
-
data.loaders = [];
|
|
67
|
-
} else if (attributes?.type === "bytes") {
|
|
68
|
-
if (this.options.bytes === "inline") {
|
|
69
|
-
setModuleType(normalModuleFactory, data, "asset/bytes");
|
|
70
|
-
data.loaders = [];
|
|
71
|
-
} else {
|
|
72
|
-
setModuleType(normalModuleFactory, data, "javascript/esm");
|
|
73
|
-
data.loaders = [{
|
|
74
|
-
loader: internalRawBytesLoader,
|
|
75
|
-
options: {},
|
|
76
|
-
ident: null,
|
|
77
|
-
type: null,
|
|
78
|
-
}];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
package/requireHook.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Module from "node:module";
|
|
2
|
-
|
|
3
|
-
const overrides = new Map<string, Record<string, unknown>>();
|
|
4
|
-
let overrideId = 0;
|
|
5
|
-
|
|
6
|
-
const originalLoad = Module.prototype.require;
|
|
7
|
-
Module.prototype.require = function hookedRequire(id: string) {
|
|
8
|
-
const override = overrides.get(id);
|
|
9
|
-
if (override) {
|
|
10
|
-
return override;
|
|
11
|
-
}
|
|
12
|
-
return originalLoad.apply(this, arguments as any);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function defineRequire(
|
|
16
|
-
name: string,
|
|
17
|
-
module: Record<string, unknown>,
|
|
18
|
-
): string {
|
|
19
|
-
const generatedName = `override:${name}/${overrideId++}`;
|
|
20
|
-
overrides.set(generatedName, module);
|
|
21
|
-
return generatedName;
|
|
22
|
-
}
|