@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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +13 -12
- package/denoEnv.d.ts +12 -0
- package/denoEnv.js +49 -0
- package/denoEnv.js.map +1 -0
- package/fresh.d.ts +39 -0
- package/fresh.js +245 -0
- 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 +8 -0
- package/mod.js +9 -0
- package/mod.js.map +1 -0
- package/package.json +81 -9
- package/prefresh-forked/index.d.ts +15 -0
- package/prefresh-forked/index.js +59 -0
- package/prefresh-forked/index.js.map +1 -0
- package/prefresh-forked/loader/index.d.ts +2 -0
- package/prefresh-forked/loader/index.js +5 -0
- package/prefresh-forked/loader/index.js.map +1 -0
- package/prefresh-forked/utils/Runtime.d.ts +5 -0
- package/prefresh-forked/utils/Runtime.js +27 -0
- package/prefresh-forked/utils/Runtime.js.map +1 -0
- package/prefresh-forked/utils/constants.d.ts +8 -0
- package/prefresh-forked/utils/constants.js +12 -0
- package/prefresh-forked/utils/constants.js.map +1 -0
- package/prefresh-forked/utils/prefresh.d.ts +5 -0
- package/prefresh-forked/utils/{prefresh.ts → prefresh.js} +8 -27
- package/prefresh-forked/utils/prefresh.js.map +1 -0
- package/quasiquote.d.ts +9 -0
- package/quasiquote.js +32 -0
- package/quasiquote.js.map +1 -0
- package/rawBytesLoader.d.ts +5 -0
- package/rawBytesLoader.js +10 -0
- package/rawBytesLoader.js.map +1 -0
- package/rawImports.d.ts +13 -0
- package/rawImports.js +44 -0
- package/rawImports.js.map +1 -0
- package/requireHook.d.ts +1 -0
- package/{requireHook.ts → requireHook.js} +5 -10
- package/requireHook.js.map +1 -0
- package/resolve.d.ts +11 -0
- package/resolve.js +395 -0
- package/resolve.js.map +1 -0
- package/transpileLoader.d.ts +9 -0
- package/transpileLoader.js +46 -0
- package/transpileLoader.js.map +1 -0
- package/unmap.d.ts +9 -0
- package/unmap.js +94 -0
- package/unmap.js.map +1 -0
- package/util.d.ts +9 -0
- package/{util.ts → util.js} +13 -19
- package/util.js.map +1 -0
- package/viteComment.d.ts +8 -0
- package/viteComment.js +28 -0
- package/viteComment.js.map +1 -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/constants.ts +0 -35
- package/prefresh-forked/utils/createTemplate.ts +0 -76
- package/prefresh-forked/utils/injectEntry.ts +0 -28
- package/quasiquote.ts +0 -44
- package/rawBytesLoader.ts +0 -17
- package/rawImports.ts +0 -85
- package/resolve.ts +0 -588
- package/transpileLoader.ts +0 -59
- package/unmap.ts +0 -154
- package/viteComment.ts +0 -41
package/CHANGELOG.md
ADDED
package/LICENSE
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
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
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
the Software without restriction, including without limitation the rights
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
the Software, and to permit persons to whom the Software is
|
|
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,
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
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,49 @@
|
|
|
1
|
+
import Webpack from "webpack";
|
|
2
|
+
const NAME = "DenoEnvPlugin";
|
|
3
|
+
const PARSER_TYPES = ["javascript/auto", "javascript/dynamic", "javascript/esm"];
|
|
4
|
+
/**
|
|
5
|
+
* DenoEnvPlugin replaces calls to `Deno.env.get` with a constant expression of environment variable name.
|
|
6
|
+
*/
|
|
7
|
+
export class DenoEnvPlugin {
|
|
8
|
+
#allowed;
|
|
9
|
+
constructor(opts = {}) {
|
|
10
|
+
this.#allowed = [...(opts.allowedEnv ?? []), /^FRESH_PUBLIC_/, "NODE_ENV", "DENO_DEPLOYMENT_ID", "GITHUB_SHA", "CI_COMMIT_SHA", "CI"];
|
|
11
|
+
}
|
|
12
|
+
#isAllowed(name) {
|
|
13
|
+
return this.#allowed.some(allowed => allowed instanceof RegExp ? allowed.test(name) : allowed === name);
|
|
14
|
+
}
|
|
15
|
+
#value(name, compiler) {
|
|
16
|
+
if (name === "NODE_ENV") {
|
|
17
|
+
const mode = compiler.options.mode;
|
|
18
|
+
if (mode !== undefined && mode !== "none") return mode;
|
|
19
|
+
}
|
|
20
|
+
return Deno.env.get(name);
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
compiler.hooks.compilation.tap(NAME, (_compilation, {
|
|
24
|
+
normalModuleFactory
|
|
25
|
+
}) => {
|
|
26
|
+
const handler = parser => {
|
|
27
|
+
parser.hooks.call.for("Deno.env.get").tap(NAME, expr => {
|
|
28
|
+
const [arg] = expr.arguments;
|
|
29
|
+
if (expr.arguments.length !== 1 || arg.type !== "Literal" || typeof arg.value !== "string") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const name = arg.value;
|
|
33
|
+
if (!this.#isAllowed(name)) {
|
|
34
|
+
throw new Error(`Env var is not allowed in bundling: ${name}`);
|
|
35
|
+
}
|
|
36
|
+
const value = this.#value(name, compiler);
|
|
37
|
+
const dep = new Webpack.dependencies.ConstDependency(value === undefined ? "undefined" : JSON.stringify(value), expr.range);
|
|
38
|
+
if (expr.loc) dep.loc = expr.loc;
|
|
39
|
+
parser.state.module.addPresentationalDependency(dep);
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
for (const type of PARSER_TYPES) {
|
|
44
|
+
normalModuleFactory.hooks.parser.for(type).tap(NAME, handler);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=denoEnv.js.map
|
package/denoEnv.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["denoEnv.ts"],"sourcesContent":["import Webpack, { type Compiler } from \"webpack\";\n\ntype JavascriptParser = Webpack.javascript.JavascriptParser;\n\nconst NAME = \"DenoEnvPlugin\";\n\nconst PARSER_TYPES = [\n \"javascript/auto\",\n \"javascript/dynamic\",\n \"javascript/esm\",\n] as const;\n\nexport type DenoEnvOptions = {\n allowedEnv?: (string | RegExp)[];\n};\n\n/**\n * DenoEnvPlugin replaces calls to `Deno.env.get` with a constant expression of environment variable name.\n */\nexport class DenoEnvPlugin {\n #allowed: (string | RegExp)[];\n constructor(opts: DenoEnvOptions = {}) {\n this.#allowed = [\n ...opts.allowedEnv ?? [],\n /^FRESH_PUBLIC_/,\n \"NODE_ENV\",\n \"DENO_DEPLOYMENT_ID\",\n \"GITHUB_SHA\",\n \"CI_COMMIT_SHA\",\n \"CI\",\n ];\n }\n #isAllowed(name: string) {\n return this.#allowed.some((allowed) =>\n allowed instanceof RegExp ? allowed.test(name) : allowed === name\n );\n }\n #value(name: string, compiler: Compiler) {\n if (name === \"NODE_ENV\") {\n const mode = compiler.options.mode;\n if (mode !== undefined && mode !== \"none\") return mode;\n }\n return Deno.env.get(name);\n }\n apply(compiler: Compiler) {\n compiler.hooks.compilation.tap(\n NAME,\n (_compilation, { normalModuleFactory }) => {\n const handler = (parser: JavascriptParser) => {\n parser.hooks.call.for(\"Deno.env.get\").tap(NAME, (expr) => {\n const [arg] = expr.arguments;\n if (\n expr.arguments.length !== 1 || arg.type !== \"Literal\" ||\n typeof arg.value !== \"string\"\n ) {\n return;\n }\n const name = arg.value;\n if (!this.#isAllowed(name)) {\n throw new Error(`Env var is not allowed in bundling: ${name}`);\n }\n const value = this.#value(name, compiler);\n const dep = new Webpack.dependencies.ConstDependency(\n value === undefined ? \"undefined\" : JSON.stringify(value),\n expr.range!,\n );\n if (expr.loc) dep.loc = expr.loc;\n parser.state.module.addPresentationalDependency(dep);\n return true;\n });\n };\n for (const type of PARSER_TYPES) {\n normalModuleFactory.hooks.parser.for(type).tap(NAME, handler);\n }\n },\n );\n }\n}\n"],"mappings":"AAAA,OAAO,OAAO,MAAyB,SAAS;AAIhD,MAAM,IAAI,GAAG,eAAe;AAE5B,MAAM,YAAY,GAAG,CACnB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,CACR;AAMV;AACA;AACA;AACA,OAAO,MAAM,aAAa,CAAC;EACzB,CAAC,OAAO;EACR,WAAW,CAAC,IAAoB,GAAG,CAAC,CAAC,EAAE;IACrC,IAAI,CAAC,CAAC,OAAO,GAAG,CACd,IAAG,IAAI,CAAC,UAAU,IAAI,EAAE,GACxB,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,IAAI,CACL;EACH;EACA,CAAC,SAAS,CAAC,IAAY,EAAE;IACvB,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAE,OAAO,IAChC,OAAO,YAAY,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,KAAK,IAC/D,CAAC;EACH;EACA,CAAC,KAAK,CAAC,IAAY,EAAE,QAAkB,EAAE;IACvC,IAAI,IAAI,KAAK,UAAU,EAAE;MACvB,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO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ACb,CAAC,CAAC;MACJ,CAAC;MACD,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE;QAC/B,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC;MAC/D;IACF,CACF,CAAC;EACH;AACF","ignoreList":[]}
|
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,245 @@
|
|
|
1
|
+
import { crawlFsItem } from "@freshpack/core/internal-dev";
|
|
2
|
+
import Webpack from "webpack";
|
|
3
|
+
import { assertAbsolutePath, assertDirURL, manglePath, stripFileUrl } from "./util.js";
|
|
4
|
+
import { assert } from "@std/assert";
|
|
5
|
+
import { IslandPreparer, ProdBuildCache } from "@freshpack/core/internal";
|
|
6
|
+
import { extname as extnamePosix, join as joinPosix, relative as relativePosix } from "@std/path/posix";
|
|
7
|
+
import { contentType as getStdContentType } from "@std/media-types/content-type";
|
|
8
|
+
import { encodeHex } from "@std/encoding";
|
|
9
|
+
import { UnmapPlugin } from "./unmap.js";
|
|
10
|
+
import { DenoEnvPlugin } from "./denoEnv.js";
|
|
11
|
+
import { ViteIgnorePlugin } from "./viteComment.js";
|
|
12
|
+
import { RawImportsPlugin } from "./rawImports.js";
|
|
13
|
+
import { ImportMetaResolveAssetPlugin } from "./importMetaResolve.js";
|
|
14
|
+
import { js, toJsRaw } from "./quasiquote.js";
|
|
15
|
+
export function assertFreshCompilation(compilation) {
|
|
16
|
+
assert("freshRoutes" in compilation && "freshIslands" in compilation && "freshRoot" in compilation, "missing fresh data in compilation, did you add WebpackFreshEntries plugin?");
|
|
17
|
+
}
|
|
18
|
+
function getMainChunkName(basePath, e) {
|
|
19
|
+
const entryChunk = e.getEntrypointChunk();
|
|
20
|
+
const files = [...entryChunk.files].map(v => joinPosix(basePath, v));
|
|
21
|
+
return files[0];
|
|
22
|
+
}
|
|
23
|
+
function getChunkFiles(basePath, e) {
|
|
24
|
+
return e.getFiles().map(v => joinPosix(basePath, v));
|
|
25
|
+
}
|
|
26
|
+
export class FreshPlugin {
|
|
27
|
+
/**
|
|
28
|
+
* @param baseUrl Location of fresh project root directory, you can specify it as `new URL('.', import.meta.url)` in build.ts
|
|
29
|
+
* @param importHelper JSR dynamic file import workaround: You should pass `(path) => import(path)` here, where the function
|
|
30
|
+
* should be defined anywhere outside of JSR published package. See this for details: https://github.com/denoland/deno/discussions/26266
|
|
31
|
+
* This function will always be called with absolute path.
|
|
32
|
+
*/
|
|
33
|
+
constructor(baseUrl, importHelper, options = {}) {
|
|
34
|
+
this.baseUrl = baseUrl;
|
|
35
|
+
this.importHelper = importHelper;
|
|
36
|
+
this.options = options;
|
|
37
|
+
assertDirURL(this.baseUrl);
|
|
38
|
+
if (!importHelper) {
|
|
39
|
+
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");
|
|
40
|
+
this.importHelper = path => import(path);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
pathRelativeToBase(path) {
|
|
44
|
+
return relativePosix(this.baseUrl.pathname, path);
|
|
45
|
+
}
|
|
46
|
+
#dist;
|
|
47
|
+
pathRelativeToDist(path) {
|
|
48
|
+
assert(this.#dist, "dist path was not determined yet");
|
|
49
|
+
return relativePosix(this.#dist, path);
|
|
50
|
+
}
|
|
51
|
+
apply(compiler) {
|
|
52
|
+
{
|
|
53
|
+
// HACK: Webpack does not export EntryDependency, and it is impossible to use EntryPlugin, as
|
|
54
|
+
// it wants to modify make stage, yet we have already reached this stage when we want to use
|
|
55
|
+
// this plugin.
|
|
56
|
+
//
|
|
57
|
+
// Solvable by creating custom dependency plugin, or requiring user to manually specify
|
|
58
|
+
// at least one entry... Or by registering EntryDependency manually as done here.
|
|
59
|
+
const EntryDependency = Webpack.EntryPlugin.createDependency(`dummy`, {}).constructor;
|
|
60
|
+
compiler.hooks.compilation.tap(FreshPlugin.name, (compilation, {
|
|
61
|
+
normalModuleFactory
|
|
62
|
+
}) => {
|
|
63
|
+
compilation.dependencyFactories.set(EntryDependency, normalModuleFactory);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
new UnmapPlugin().apply(compiler);
|
|
67
|
+
new DenoEnvPlugin(this.options.env).apply(compiler);
|
|
68
|
+
new ViteIgnorePlugin().apply(compiler);
|
|
69
|
+
new RawImportsPlugin(this.options.rawImports).apply(compiler);
|
|
70
|
+
new ImportMetaResolveAssetPlugin().apply(compiler);
|
|
71
|
+
// Some @std and other packages detect deno on presence of Deno global, dead-code-elimnate this stuff
|
|
72
|
+
new Webpack.DefinePlugin({
|
|
73
|
+
Deno: "undefined"
|
|
74
|
+
}).apply(compiler);
|
|
75
|
+
compiler.hooks.make.tapPromise(FreshPlugin.name, async _compilation => {
|
|
76
|
+
const compilation = _compilation;
|
|
77
|
+
this.#dist = compilation.outputOptions.path;
|
|
78
|
+
const compilationId = Date.now().toString(36);
|
|
79
|
+
|
|
80
|
+
// Ensure hot chunks are resolved from correct path, they can't contain compilationId in name
|
|
81
|
+
compilation.outputOptions.publicPath = "/";
|
|
82
|
+
{
|
|
83
|
+
// Chunks are content-addressed in prod, and have readable names using standard fresh cache pruning in dev
|
|
84
|
+
if (compiler.options.mode === "production") {
|
|
85
|
+
compilation.outputOptions.filename = `_fresh/js/c/[contenthash].mjs`;
|
|
86
|
+
compilation.outputOptions.chunkFilename = `_fresh/js/c/[contenthash].mjs`;
|
|
87
|
+
compilation.outputOptions.workerChunkFilename = `_fresh/js/c/[contenthash].mjs`;
|
|
88
|
+
} else {
|
|
89
|
+
compilation.outputOptions.filename = `_fresh/js/${compilationId}/[id].mjs`;
|
|
90
|
+
compilation.outputOptions.chunkFilename = `_fresh/js/${compilationId}/[id].mjs`;
|
|
91
|
+
compilation.outputOptions.workerChunkFilename = `_fresh/js/${compilationId}/[id].mjs`;
|
|
92
|
+
}
|
|
93
|
+
// Assets are always content-addressed
|
|
94
|
+
compilation.outputOptions.assetModuleFilename = `_fresh/js/c/[hash][ext][query]`;
|
|
95
|
+
compilation.outputOptions.webassemblyModuleFilename = `_fresh/js/c/[hash].wasm`;
|
|
96
|
+
}
|
|
97
|
+
compilation.hooks.processAssets.tapPromise({
|
|
98
|
+
name: FreshPlugin.name,
|
|
99
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
100
|
+
}, async assets => {
|
|
101
|
+
compilation.getAssets();
|
|
102
|
+
const cacheOut = [js`import{IslandPreparer,ProdBuildCache}from"@freshpack/core/internal"`, js`const islands=new Map()`, js`const islandPreparer=new IslandPreparer()`];
|
|
103
|
+
const staticFiles = new Map();
|
|
104
|
+
const islands = new Map();
|
|
105
|
+
const islandPreparer = new IslandPreparer();
|
|
106
|
+
for (const island of compilation.freshIslands) {
|
|
107
|
+
const entrypoint = compilation.entrypoints.get(island.entryName);
|
|
108
|
+
assert(entrypoint, `unable to find island entrypoint: ${island.entryName}`);
|
|
109
|
+
const file = getMainChunkName(`/`, entrypoint);
|
|
110
|
+
islandPreparer.prepare(islands, await this.importHelper(island.filePath), file, island.entryName, []);
|
|
111
|
+
const importPath = this.pathRelativeToDist(island.filePath);
|
|
112
|
+
cacheOut.push(js`islandPreparer.prepare(islands,await import(${importPath}),${file},${island.entryName},[])`);
|
|
113
|
+
}
|
|
114
|
+
const fsRoutesOut = [];
|
|
115
|
+
const fsRoutes = await Promise.all(compilation.freshRoutes.map(async v => {
|
|
116
|
+
const importPath = this.pathRelativeToDist(v.filePath);
|
|
117
|
+
fsRoutesOut.push(toJsRaw({
|
|
118
|
+
id: v.id,
|
|
119
|
+
mod: v.lazy ? js`()=>import(${importPath})` : js`await import(${importPath})`,
|
|
120
|
+
type: v.type,
|
|
121
|
+
pattern: v.pattern,
|
|
122
|
+
routePattern: v.routePattern
|
|
123
|
+
}));
|
|
124
|
+
assertAbsolutePath(v.filePath);
|
|
125
|
+
return {
|
|
126
|
+
...v,
|
|
127
|
+
mod: v.lazy ? () => this.importHelper(v.filePath) : await this.importHelper(v.filePath)
|
|
128
|
+
};
|
|
129
|
+
}));
|
|
130
|
+
cacheOut.push(js`const fsRoutes=${fsRoutesOut}`);
|
|
131
|
+
const clientEntrypoint = compilation.entrypoints.get("client-entry");
|
|
132
|
+
assert(clientEntrypoint, `unable to find client entrypoint`);
|
|
133
|
+
const clientEntry = getMainChunkName(`/`, clientEntrypoint);
|
|
134
|
+
const clientEntryAssets = getChunkFiles(`/`, clientEntrypoint);
|
|
135
|
+
const staticFilesOut = new Map();
|
|
136
|
+
for (const _asset of compilation.getAssets()) {
|
|
137
|
+
const asset = compilation.getAsset(_asset.name);
|
|
138
|
+
const file_ = assets[asset.name].buffer();
|
|
139
|
+
const file = file_;
|
|
140
|
+
const hash = await crypto.subtle.digest("SHA-1", file.buffer);
|
|
141
|
+
const ext = extnamePosix(asset.name);
|
|
142
|
+
const contentType = getStdContentType(ext) ?? "text/plain";
|
|
143
|
+
const name = "/" + asset.name;
|
|
144
|
+
staticFiles.set(name, {
|
|
145
|
+
name,
|
|
146
|
+
filePath: asset.name,
|
|
147
|
+
contentType,
|
|
148
|
+
hash: encodeHex(hash),
|
|
149
|
+
data: file,
|
|
150
|
+
size: file.length
|
|
151
|
+
});
|
|
152
|
+
staticFilesOut.set(name, toJsRaw({
|
|
153
|
+
name,
|
|
154
|
+
filePath: js`new URL(${asset.name}, import.meta.url).pathname`,
|
|
155
|
+
hash: encodeHex(hash),
|
|
156
|
+
contentType
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
cacheOut.push(js`const staticFiles=${staticFilesOut}`);
|
|
160
|
+
cacheOut.push(js`export default new ProdBuildCache(${compilation.freshRoot}, ${{
|
|
161
|
+
version: compilationId,
|
|
162
|
+
clientEntry,
|
|
163
|
+
entryAssets: toJsRaw(clientEntryAssets),
|
|
164
|
+
islands: js`islands`,
|
|
165
|
+
fsRoutes: js`fsRoutes`,
|
|
166
|
+
staticFiles: js`staticFiles`
|
|
167
|
+
}})`);
|
|
168
|
+
// Here ProdBuildCache is being used as MemoryBuildCache from fresh
|
|
169
|
+
const cache = new ProdBuildCache(compilation.freshRoot, {
|
|
170
|
+
version: compilationId,
|
|
171
|
+
clientEntry,
|
|
172
|
+
fsRoutes,
|
|
173
|
+
staticFiles,
|
|
174
|
+
islands,
|
|
175
|
+
entryAssets: clientEntryAssets
|
|
176
|
+
});
|
|
177
|
+
cache.readFile = pathname => {
|
|
178
|
+
const st = staticFiles.get(pathname);
|
|
179
|
+
if (!st) {
|
|
180
|
+
return Promise.resolve(null);
|
|
181
|
+
}
|
|
182
|
+
return Promise.resolve({
|
|
183
|
+
contentType: st.contentType,
|
|
184
|
+
hash: st.hash,
|
|
185
|
+
readable: new ReadableStream({
|
|
186
|
+
start(v) {
|
|
187
|
+
v.enqueue(st.data);
|
|
188
|
+
v.close();
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
size: st.size,
|
|
192
|
+
close() {}
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
compilation.prodBuildCache = cache;
|
|
196
|
+
compilation.emitAsset("./cache.mjs", new compiler.webpack.sources.RawSource(cacheOut.map(v => v._jsRaw).join("\n")));
|
|
197
|
+
});
|
|
198
|
+
const item = await crawlFsItem({
|
|
199
|
+
islandDir: stripFileUrl(new URL("islands", this.baseUrl).href),
|
|
200
|
+
routeDir: stripFileUrl(new URL("routes", this.baseUrl).href),
|
|
201
|
+
ignore: []
|
|
202
|
+
});
|
|
203
|
+
compilation.freshRoutes = item.routes;
|
|
204
|
+
compilation.freshIslands = [];
|
|
205
|
+
compilation.freshRoot = this.pathRelativeToBase(".");
|
|
206
|
+
const addEntryPromises = [];
|
|
207
|
+
let isId = 0;
|
|
208
|
+
for (const island of item.islands) {
|
|
209
|
+
const name = compiler.options.mode === "production" ? `is${isId++}` : manglePath(island);
|
|
210
|
+
compilation.freshIslands.push({
|
|
211
|
+
entryName: name,
|
|
212
|
+
filePath: island
|
|
213
|
+
});
|
|
214
|
+
addEntryPromises.push(new Promise((res, rej) => compilation.addEntry("", Webpack.EntryPlugin.createDependency(`${island}`, {
|
|
215
|
+
name
|
|
216
|
+
}), {
|
|
217
|
+
name,
|
|
218
|
+
library: {
|
|
219
|
+
type: "module"
|
|
220
|
+
}
|
|
221
|
+
}, err => {
|
|
222
|
+
if (err) return rej(err);
|
|
223
|
+
res();
|
|
224
|
+
})));
|
|
225
|
+
}
|
|
226
|
+
{
|
|
227
|
+
const name = "client-entry";
|
|
228
|
+
const file = stripFileUrl(new URL("./client.ts", this.baseUrl).href);
|
|
229
|
+
addEntryPromises.push(new Promise((res, rej) => compilation.addEntry("", Webpack.EntryPlugin.createDependency(file, {
|
|
230
|
+
name
|
|
231
|
+
}), {
|
|
232
|
+
name,
|
|
233
|
+
library: {
|
|
234
|
+
type: "module"
|
|
235
|
+
}
|
|
236
|
+
}, e => {
|
|
237
|
+
if (e) return rej(e);
|
|
238
|
+
res();
|
|
239
|
+
})));
|
|
240
|
+
}
|
|
241
|
+
await Promise.all(addEntryPromises);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=fresh.js.map
|
package/fresh.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["fresh.ts"],"sourcesContent":["import {\n crawlFsItem,\n type FsRouteFileNoMod,\n} from \"@freshpack/core/internal-dev\";\nimport Webpack from \"webpack\";\nimport {\n assertAbsolutePath,\n assertDirURL,\n manglePath,\n stripFileUrl,\n} from \"./util.ts\";\nimport { assert } from \"@std/assert\";\nimport { IslandPreparer, ProdBuildCache } from \"@freshpack/core/internal\";\nimport {\n extname as extnamePosix,\n join as joinPosix,\n relative as relativePosix,\n} from \"@std/path/posix\";\nimport { contentType as getStdContentType } from \"@std/media-types/content-type\";\nimport { encodeHex } from \"@std/encoding\";\nimport { UnmapPlugin } from \"./unmap.ts\";\nimport { type DenoEnvOptions, DenoEnvPlugin } from \"./denoEnv.ts\";\nimport { ViteIgnorePlugin } from \"./viteComment.ts\";\nimport { type RawImportsOptions, RawImportsPlugin } from \"./rawImports.ts\";\nimport { ImportMetaResolveAssetPlugin } from \"./importMetaResolve.ts\";\nimport { js, type JsRaw, toJsRaw } from \"./quasiquote.ts\";\n\ninterface WebpackFreshCompilation extends Webpack.Compilation {\n freshRoutes: FsRouteFileNoMod<unknown>[];\n freshIslands: { entryName: string; filePath: string }[];\n freshRoot: string;\n buildId: string;\n\n prodBuildCache: ProdBuildCache<unknown>;\n}\n\nexport function assertFreshCompilation(\n compilation: Webpack.Compilation,\n): asserts compilation is WebpackFreshCompilation {\n assert(\n \"freshRoutes\" in compilation && \"freshIslands\" in compilation &&\n \"freshRoot\" in compilation,\n \"missing fresh data in compilation, did you add WebpackFreshEntries plugin?\",\n );\n}\n\ntype CacheStaticFile = {\n name: string;\n filePath: string;\n contentType: string;\n hash: string;\n data: Uint8Array;\n size: number;\n};\n\nfunction getMainChunkName(\n basePath: string,\n e: Webpack.Entrypoint,\n): string {\n const entryChunk = e.getEntrypointChunk();\n const files = [...entryChunk.files].map((v) => joinPosix(basePath, v));\n return files[0];\n}\nfunction getChunkFiles(\n basePath: string,\n e: Webpack.Entrypoint,\n): string[] {\n return e.getFiles().map((v) => joinPosix(basePath, v));\n}\n\nexport class FreshPlugin {\n /**\n * @param baseUrl Location of fresh project root directory, you can specify it as `new URL('.', import.meta.url)` in build.ts\n * @param importHelper JSR dynamic file import workaround: You should pass `(path) => import(path)` here, where the function\n * should be defined anywhere outside of JSR published package. See this for details: https://github.com/denoland/deno/discussions/26266\n * This function will always be called with absolute path.\n */\n constructor(\n public baseUrl: URL,\n public importHelper: (path: string) => Promise<Record<string, unknown>>,\n public options: { env?: DenoEnvOptions; rawImports?: RawImportsOptions } =\n {},\n ) {\n assertDirURL(this.baseUrl);\n if (!importHelper) {\n console.warn(\n \"[FreshPlugin]\",\n \"importHelper is not set, jsr release of @freshpack/webpack doesn't work without it: https://github.com/denoland/deno/discussions/26266#discussioncomment-12198284\",\n );\n this.importHelper = (path: string) => import(path);\n }\n }\n pathRelativeToBase(path: string) {\n return relativePosix(this.baseUrl.pathname, path);\n }\n #dist?: string;\n pathRelativeToDist(path: string) {\n assert(this.#dist, \"dist path was not determined yet\");\n return relativePosix(this.#dist, path);\n }\n\n apply(compiler: Webpack.Compiler) {\n {\n // HACK: Webpack does not export EntryDependency, and it is impossible to use EntryPlugin, as\n // it wants to modify make stage, yet we have already reached this stage when we want to use\n // this plugin.\n //\n // Solvable by creating custom dependency plugin, or requiring user to manually specify\n // at least one entry... Or by registering EntryDependency manually as done here.\n const EntryDependency =\n Webpack.EntryPlugin.createDependency(`dummy`, {}).constructor;\n\n compiler.hooks.compilation.tap(\n FreshPlugin.name,\n (compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n EntryDependency as any,\n normalModuleFactory,\n );\n },\n );\n }\n\n (new UnmapPlugin()).apply(compiler);\n (new DenoEnvPlugin(this.options.env)).apply(compiler);\n (new ViteIgnorePlugin()).apply(compiler);\n (new RawImportsPlugin(this.options.rawImports)).apply(compiler);\n (new ImportMetaResolveAssetPlugin()).apply(compiler);\n // Some @std and other packages detect deno on presence of Deno global, dead-code-elimnate this stuff\n (new Webpack.DefinePlugin({ Deno: \"undefined\" })).apply(compiler);\n\n compiler.hooks.make.tapPromise(\n FreshPlugin.name,\n async (_compilation: Webpack.Compilation) => {\n const compilation = _compilation as WebpackFreshCompilation;\n this.#dist = compilation.outputOptions.path;\n\n const compilationId = Date.now().toString(36);\n\n // Ensure hot chunks are resolved from correct path, they can't contain compilationId in name\n compilation.outputOptions.publicPath = \"/\";\n {\n // Chunks are content-addressed in prod, and have readable names using standard fresh cache pruning in dev\n if (compiler.options.mode === \"production\") {\n compilation.outputOptions.filename =\n `_fresh/js/c/[contenthash].mjs`;\n compilation.outputOptions.chunkFilename =\n `_fresh/js/c/[contenthash].mjs`;\n compilation.outputOptions.workerChunkFilename =\n `_fresh/js/c/[contenthash].mjs`;\n } else {\n compilation.outputOptions.filename =\n `_fresh/js/${compilationId}/[id].mjs`;\n compilation.outputOptions.chunkFilename =\n `_fresh/js/${compilationId}/[id].mjs`;\n compilation.outputOptions.workerChunkFilename =\n `_fresh/js/${compilationId}/[id].mjs`;\n }\n // Assets are always content-addressed\n compilation.outputOptions.assetModuleFilename =\n `_fresh/js/c/[hash][ext][query]`;\n compilation.outputOptions.webassemblyModuleFilename =\n `_fresh/js/c/[hash].wasm`;\n }\n\n compilation.hooks.processAssets.tapPromise(\n {\n name: FreshPlugin.name,\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,\n },\n async (assets) => {\n compilation.getAssets();\n\n const cacheOut: JsRaw[] = [\n js`import{IslandPreparer,ProdBuildCache}from\"@freshpack/core/internal\"`,\n js`const islands=new Map()`,\n js`const islandPreparer=new IslandPreparer()`,\n ];\n\n const staticFiles = new Map<string, CacheStaticFile>();\n\n const islands = new Map();\n const islandPreparer = new IslandPreparer();\n for (const island of compilation.freshIslands) {\n const entrypoint = compilation.entrypoints.get(island.entryName);\n assert(\n entrypoint,\n `unable to find island entrypoint: ${island.entryName}`,\n );\n const file = getMainChunkName(\n `/`,\n entrypoint,\n );\n\n islandPreparer.prepare(\n islands,\n await this.importHelper(island.filePath),\n file,\n island.entryName,\n [],\n );\n const importPath = this.pathRelativeToDist(island.filePath);\n cacheOut.push(\n js`islandPreparer.prepare(islands,await import(${importPath}),${file},${island.entryName},[])`,\n );\n }\n\n const fsRoutesOut: JsRaw[] = [];\n const fsRoutes = await Promise.all(\n compilation.freshRoutes.map(async (v) => {\n const importPath = this.pathRelativeToDist(v.filePath);\n fsRoutesOut.push(toJsRaw({\n id: v.id,\n mod: v.lazy\n ? js`()=>import(${importPath})`\n : js`await import(${importPath})`,\n type: v.type,\n pattern: v.pattern,\n routePattern: v.routePattern,\n }));\n assertAbsolutePath(v.filePath);\n return {\n ...v,\n mod: v.lazy\n ? () => this.importHelper(v.filePath)\n : await this.importHelper(v.filePath),\n };\n }),\n );\n cacheOut.push(js`const fsRoutes=${fsRoutesOut}`);\n\n const clientEntrypoint = compilation.entrypoints.get(\n \"client-entry\",\n );\n assert(\n clientEntrypoint,\n `unable to find client entrypoint`,\n );\n const clientEntry = getMainChunkName(\n `/`,\n clientEntrypoint,\n );\n const clientEntryAssets = getChunkFiles(\n `/`,\n clientEntrypoint,\n );\n const staticFilesOut = new Map<string, JsRaw>();\n for (const _asset of compilation.getAssets()) {\n const asset = compilation.getAsset(_asset.name)!;\n const file_: Uint8Array<ArrayBufferLike> = assets[asset.name]\n .buffer();\n const file = file_ as Uint8Array<ArrayBuffer>;\n const hash = await crypto.subtle.digest(\"SHA-1\", file.buffer);\n\n const ext = extnamePosix(asset.name);\n const contentType = getStdContentType(ext) ?? \"text/plain\";\n\n const name = \"/\" + asset.name;\n staticFiles.set(name, {\n name,\n filePath: asset.name,\n contentType,\n hash: encodeHex(hash),\n data: file,\n size: file.length,\n });\n staticFilesOut.set(\n name,\n toJsRaw({\n name,\n filePath:\n js`new URL(${asset.name}, import.meta.url).pathname`,\n hash: encodeHex(hash),\n contentType,\n }),\n );\n }\n cacheOut.push(js`const staticFiles=${staticFilesOut}`);\n\n cacheOut.push(\n js`export default new ProdBuildCache(${compilation.freshRoot}, ${({\n version: compilationId,\n clientEntry,\n entryAssets: toJsRaw(clientEntryAssets),\n islands: js`islands`,\n fsRoutes: js`fsRoutes`,\n staticFiles: js`staticFiles`,\n })})`,\n );\n // Here ProdBuildCache is being used as MemoryBuildCache from fresh\n const cache = new ProdBuildCache(compilation.freshRoot, {\n version: compilationId,\n clientEntry,\n fsRoutes,\n staticFiles,\n islands,\n entryAssets: clientEntryAssets,\n });\n cache.readFile = (pathname) => {\n const st = staticFiles.get(pathname);\n if (!st) {\n return Promise.resolve(null);\n }\n return Promise.resolve({\n contentType: st.contentType,\n hash: st.hash,\n readable: new ReadableStream({\n start(v) {\n v.enqueue(st.data);\n v.close();\n },\n }),\n size: st.size,\n close() {},\n });\n };\n compilation.prodBuildCache = cache;\n\n compilation.emitAsset(\n \"./cache.mjs\",\n new compiler.webpack.sources.RawSource(\n cacheOut.map((v) => v._jsRaw).join(\"\\n\"),\n ),\n );\n },\n );\n\n const item = await crawlFsItem({\n islandDir: stripFileUrl(new URL(\"islands\", this.baseUrl).href),\n routeDir: stripFileUrl(new URL(\"routes\", this.baseUrl).href),\n ignore: [],\n });\n compilation.freshRoutes = item.routes;\n compilation.freshIslands = [];\n compilation.freshRoot = this.pathRelativeToBase(\".\");\n\n const addEntryPromises = [];\n let isId = 0;\n for (const island of item.islands) {\n const name = compiler.options.mode === \"production\"\n ? `is${isId++}`\n : manglePath(island);\n compilation.freshIslands.push({ entryName: name, filePath: island });\n addEntryPromises.push(\n new Promise<void>((res, rej) =>\n compilation.addEntry(\n \"\",\n Webpack.EntryPlugin.createDependency(`${island}`, {\n name,\n }),\n {\n name,\n library: {\n type: \"module\",\n },\n },\n (err) => {\n if (err) return rej(err);\n res();\n },\n )\n ),\n );\n }\n {\n const name = \"client-entry\";\n const file = stripFileUrl(new URL(\"./client.ts\", this.baseUrl).href);\n addEntryPromises.push(\n new Promise<void>((res, rej) =>\n compilation.addEntry(\n \"\",\n Webpack.EntryPlugin.createDependency(file, {\n name,\n }),\n {\n name,\n library: {\n type: \"module\",\n },\n },\n (e) => {\n if (e) return rej(e);\n res();\n },\n )\n ),\n );\n }\n await Promise.all(addEntryPromises);\n },\n );\n }\n}\n"],"mappings":"AAAA,SACE,WAAW,QAEN,8BAA8B;AACrC,OAAO,OAAO,MAAM,SAAS;AAC7B,SACE,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,YAAY,QACP,WAAW;AAClB,SAAS,MAAM,QAAQ,aAAa;AACpC,SAAS,cAAc,EAAE,cAAc,QAAQ,0BAA0B;AACzE,SACE,OAAO,IAAI,YAAY,EACvB,IAAI,IAAI,SAAS,EAC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AI;UAAE,QAAQ,EAAE;QAAO,CAAC,CAAC;QACpE,gBAAgB,CAAC,IAAI,CACnB,IAAI,OAAO,CAAO,CAAC,GAAG,EAAE,GAAG,KACzB,WAAW,CAAC,QAAQ,CAClB,EAAE,EACF,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,MAAM,EAAE,EAAE;UAChD;QACF,CAAC,CAAC,EACF;UACE,IAAI;UACJ,OAAO,EAAE;YACP,IAAI,EAAE;UACR;QACF,CAAC,EACA,GAAG,IAAK;UACP,IAAI,GAAG,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC;UACxB,GAAG,CAAC,CAAC;QACP,CACF,CACF,CACF,CAAC;MACH;MACA;QACE,MAAM,IAAI,GAAG,cAAc;QAC3B,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;QACpE,gBAAgB,CAAC,IAAI,CACnB,IAAI,OAAO,CAAO,CAAC,GAAG,EAAE,GAAG,KACzB,WAAW,CAAC,QAAQ,CAClB,EAAE,EACF,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,EAAE;UACzC;QACF,CAAC,CAAC,EACF;UACE,IAAI;UACJ,OAAO,EAAE;YACP,IAAI,EAAE;UACR;QACF,CAAC,EACA,CAAC,IAAK;UACL,IAAI,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;UACpB,GAAG,CAAC,CAAC;QACP,CACF,CACF,CACF,CAAC;MACH;MACA,MAAM,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACrC,CACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const NAME = "ImportMetaResolveAssetPlugin";
|
|
2
|
+
export class ImportMetaResolveAssetPlugin {
|
|
3
|
+
apply(compiler) {
|
|
4
|
+
const {
|
|
5
|
+
RuntimeGlobals
|
|
6
|
+
} = compiler.webpack;
|
|
7
|
+
compiler.hooks.compilation.tap({
|
|
8
|
+
name: NAME,
|
|
9
|
+
stage: 100
|
|
10
|
+
}, compilation => {
|
|
11
|
+
const ctor = [...compilation.dependencyFactories.keys()].find(c => c.name === "ImportMetaResolveDependency");
|
|
12
|
+
if (!ctor) return;
|
|
13
|
+
const templates = compilation.dependencyTemplates;
|
|
14
|
+
const original = templates.get(ctor);
|
|
15
|
+
if (!original) return;
|
|
16
|
+
compilation.hooks.succeedModule.tap(NAME, module => {
|
|
17
|
+
for (const dep of module.dependencies) {
|
|
18
|
+
if (dep.constructor === ctor) {
|
|
19
|
+
module.addCodeGenerationDependency(dep);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
templates.set(ctor, {
|
|
24
|
+
apply(dep, source, ctx) {
|
|
25
|
+
const {
|
|
26
|
+
outerRange,
|
|
27
|
+
relative
|
|
28
|
+
} = dep;
|
|
29
|
+
const module = ctx.moduleGraph.getModule(dep);
|
|
30
|
+
const active = ctx.moduleGraph.getConnection(dep)?.isTargetActive(ctx.runtime) ?? true;
|
|
31
|
+
const filename = active && module && !module.getSourceTypes().has("javascript") && ctx.codeGenerationResults.has(module, ctx.runtime) ? ctx.codeGenerationResults.getData(module, ctx.runtime, "filename") : undefined;
|
|
32
|
+
if (typeof filename !== "string") {
|
|
33
|
+
original.apply(dep, source, ctx);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
ctx.runtimeRequirements.add(RuntimeGlobals.publicPath);
|
|
37
|
+
const url = `${RuntimeGlobals.publicPath} + ${JSON.stringify(filename)}`;
|
|
38
|
+
if (relative) {
|
|
39
|
+
ctx.runtimeRequirements.add(RuntimeGlobals.relativeUrl);
|
|
40
|
+
source.replace(outerRange[0], outerRange[1] - 1, `(new ${RuntimeGlobals.relativeUrl}(/* asset import */ ${url})).href`);
|
|
41
|
+
} else {
|
|
42
|
+
ctx.runtimeRequirements.add(RuntimeGlobals.baseURI);
|
|
43
|
+
source.replace(outerRange[0], outerRange[1] - 1, `(new URL(/* asset import */ ${url}, ${RuntimeGlobals.baseURI})).href`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=importMetaResolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["importMetaResolve.ts"],"sourcesContent":["import type { Compiler } from \"webpack\";\n\nconst NAME = \"ImportMetaResolveAssetPlugin\";\n\ntype Range = [number, number];\n\ntype ResolveDependency = {\n outerRange: Range;\n relative: boolean;\n};\n\ntype Source = {\n replace(start: number, end: number, content: string): void;\n};\n\ntype Module = {\n getSourceTypes(): Set<string>;\n};\n\ntype TemplateContext = {\n moduleGraph: {\n getModule(dep: unknown): Module | null;\n getConnection(\n dep: unknown,\n ): { isTargetActive(runtime: unknown): boolean } | undefined;\n };\n codeGenerationResults: {\n has(module: Module, runtime: unknown): boolean;\n getData(module: Module, runtime: unknown, key: string): unknown;\n };\n runtimeRequirements: Set<string>;\n runtime: unknown;\n};\n\ntype Template = {\n apply(dep: unknown, source: Source, ctx: TemplateContext): void;\n};\n\ntype Templates = {\n get(ctor: unknown): Template | undefined;\n set(ctor: unknown, template: Template): void;\n};\n\nexport class ImportMetaResolveAssetPlugin {\n apply(compiler: Compiler) {\n const { RuntimeGlobals } = compiler.webpack;\n compiler.hooks.compilation.tap(\n { name: NAME, stage: 100 },\n (compilation) => {\n const ctor = [...compilation.dependencyFactories.keys()].find((c) =>\n c.name === \"ImportMetaResolveDependency\"\n );\n if (!ctor) return;\n const templates = compilation\n .dependencyTemplates as unknown as Templates;\n const original = templates.get(ctor);\n if (!original) return;\n compilation.hooks.succeedModule.tap(NAME, (module) => {\n for (const dep of module.dependencies) {\n if (dep.constructor === ctor) {\n module.addCodeGenerationDependency(dep);\n }\n }\n });\n templates.set(ctor, {\n apply(dep, source, ctx) {\n const { outerRange, relative } = dep as ResolveDependency;\n const module = ctx.moduleGraph.getModule(dep);\n const active = ctx.moduleGraph.getConnection(dep)\n ?.isTargetActive(ctx.runtime) ?? true;\n const filename = active && module &&\n !module.getSourceTypes().has(\"javascript\") &&\n ctx.codeGenerationResults.has(module, ctx.runtime)\n ? ctx.codeGenerationResults.getData(\n module,\n ctx.runtime,\n \"filename\",\n )\n : undefined;\n if (typeof filename !== \"string\") {\n original.apply(dep, source, ctx);\n return;\n }\n ctx.runtimeRequirements.add(RuntimeGlobals.publicPath);\n const url = `${RuntimeGlobals.publicPath} + ${\n JSON.stringify(filename)\n }`;\n if (relative) {\n ctx.runtimeRequirements.add(RuntimeGlobals.relativeUrl);\n source.replace(\n outerRange[0],\n outerRange[1] - 1,\n `(new ${RuntimeGlobals.relativeUrl}(/* asset import */ ${url})).href`,\n );\n } else {\n ctx.runtimeRequirements.add(RuntimeGlobals.baseURI);\n source.replace(\n outerRange[0],\n outerRange[1] - 1,\n `(new URL(/* asset import */ ${url}, ${RuntimeGlobals.baseURI})).href`,\n );\n }\n },\n });\n },\n );\n }\n}\n"],"mappings":"AAEA,MAAM,IAAI,GAAG,8BAA8B;AAyC3C,OAAO,MAAM,4BAA4B,CAAC;EACxC,KAAK,CAAC,QAAkB,EAAE;IACxB,MAAM;MAAE;IAAe,CAAC,GAAG,QAAQ,CAAC,OAAO;IAC3C,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAC5B;MAAE,IAAI,EAAE,IAAI;MAAE,KAAK,EAAE;IAAI,CAAC,EACzB,WAAW,IAAK;MACf,MAAM,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC,IAC9D,CAAC,CAAC,IAAI,KAAK,6BACb,CAAC;MACD,IAAI,CAAC,IAAI,EAAE;MACX,MAAM,SAAS,GAAG,WAAW,CAC1B,mBAA2C;MAC9C,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG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,EACxB;UACF,IAAI,QAAQ,EAAE;YACZ,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,WAAW,CAAC;YACvD,MAAM,CAAC,OAAO,CACZ,UAAU,CAAC,CAAC,CAAC,EACb,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,EACjB,QAAQ,cAAc,CAAC,WAAW,uBAAuB,GAAG,SAC9D,CAAC;UACH,CAAC,MAAM;YACL,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC;YACnD,MAAM,CAAC,OAAO,CACZ,UAAU,CAAC,CAAC,CAAC,EACb,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,EACjB,+BAA+B,GAAG,KAAK,cAAc,CAAC,OAAO,SAC/D,CAAC;UACH;QACF;MACF,CAAC,CAAC;IACJ,CACF,CAAC;EACH;AACF","ignoreList":[]}
|
package/mod.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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 { ImportMetaResolveAssetPlugin } from "./importMetaResolve.js";
|
|
7
|
+
export { type RawImportsOptions, RawImportsPlugin } from "./rawImports.js";
|
|
8
|
+
export { UnmapPlugin } from "./unmap.js";
|
package/mod.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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 { ImportMetaResolveAssetPlugin } from "./importMetaResolve.js";
|
|
7
|
+
export { RawImportsPlugin } from "./rawImports.js";
|
|
8
|
+
export { UnmapPlugin } from "./unmap.js";
|
|
9
|
+
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["mod.ts"],"sourcesContent":["export { DenoEnvPlugin } from \"./denoEnv.ts\";\nexport { FreshPlugin } from \"./fresh.ts\";\nexport { ViteIgnorePlugin } from \"./viteComment.ts\";\nexport { DenoPreactRefreshPlugin } from \"./prefresh-forked/index.ts\";\nexport { DenoLoaderPlugin } from \"./resolve.ts\";\nexport { ImportMetaResolveAssetPlugin } from \"./importMetaResolve.ts\";\nexport { type RawImportsOptions, RawImportsPlugin } from \"./rawImports.ts\";\nexport { UnmapPlugin } from \"./unmap.ts\";\n"],"mappings":"AAAA,SAAS,aAAa,QAAQ,cAAc;AAC5C,SAAS,WAAW,QAAQ,YAAY;AACxC,SAAS,gBAAgB,QAAQ,kBAAkB;AACnD,SAAS,uBAAuB,QAAQ,4BAA4B;AACpE,SAAS,gBAAgB,QAAQ,cAAc;AAC/C,SAAS,4BAA4B,QAAQ,wBAAwB;AACrE,SAAiC,gBAAgB,QAAQ,iBAAiB;AAC1E,SAAS,WAAW,QAAQ,YAAY","ignoreList":[]}
|