@use-worker/query-loader 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +14 -0
- package/THIRD_PARTY_NOTICES.md +63 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/loader.cjs +26 -0
- package/dist/loader.d.cts +16 -0
- package/dist/transform.d.ts +13 -0
- package/dist/transform.js +31 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrew Ingram
|
|
4
|
+
|
|
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
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
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
|
+
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/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @use-worker/query-loader
|
|
2
|
+
|
|
3
|
+
Shared loader for `@use-worker/webpack` and `@use-worker/turbopack`. Applications
|
|
4
|
+
install their selected integration and let its configuration helper select this
|
|
5
|
+
loader. There is no umbrella `use-worker` package.
|
|
6
|
+
|
|
7
|
+
The root exports the absolute `loader` path. `/loader` exports the CommonJS
|
|
8
|
+
loader. It selects application, Worker-entry and whole-module implementation
|
|
9
|
+
views by resource query, using core and standalone Oxc. It does not depend on
|
|
10
|
+
Webpack, Next.js, Vite, SWC, or either host configuration package.
|
|
11
|
+
|
|
12
|
+
Hosts own module resolution, Worker bundling and update propagation. The loader
|
|
13
|
+
passes ordinary source through unchanged and emits static browser Worker URL
|
|
14
|
+
expressions for marked source. Composed source maps remain unfinished.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Parts of the scope analysis and function-hoisting approach in
|
|
4
|
+
`src/compiler/closure-scope.ts` and `src/compiler/hoist.ts` are adapted from the official Vite
|
|
5
|
+
React Server Components transform:
|
|
6
|
+
|
|
7
|
+
https://github.com/vitejs/vite-plugin-react/tree/11ad0af/packages/plugin-rsc/src/transforms
|
|
8
|
+
|
|
9
|
+
Vite is distributed under the following license:
|
|
10
|
+
|
|
11
|
+
> MIT License
|
|
12
|
+
>
|
|
13
|
+
> Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
14
|
+
>
|
|
15
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
> in the Software without restriction, including without limitation the rights
|
|
18
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
> furnished to do so, subject to the following conditions:
|
|
21
|
+
>
|
|
22
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
> copies or substantial portions of the Software.
|
|
24
|
+
>
|
|
25
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
> SOFTWARE.
|
|
32
|
+
|
|
33
|
+
The directive typo-detection algorithm in `src/compiler/transform.ts` and capture-path
|
|
34
|
+
coalescing in `src/compiler/hoist.ts` are adapted from the Next.js Server Actions
|
|
35
|
+
transform:
|
|
36
|
+
|
|
37
|
+
https://github.com/vercel/next.js/blob/090f1b72753b2d0094235d27d46ffa0da5fc7d35/crates/next-custom-transforms/src/transforms/server_actions.rs#L3231-L3285
|
|
38
|
+
|
|
39
|
+
https://github.com/vercel/next.js/blob/090f1b72753b2d0094235d27d46ffa0da5fc7d35/crates/next-custom-transforms/src/transforms/server_actions.rs#L2920-L2966
|
|
40
|
+
|
|
41
|
+
Next.js is distributed under the following license:
|
|
42
|
+
|
|
43
|
+
> The MIT License (MIT)
|
|
44
|
+
>
|
|
45
|
+
> Copyright (c) 2025 Vercel, Inc.
|
|
46
|
+
>
|
|
47
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
48
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
49
|
+
> in the Software without restriction, including without limitation the rights
|
|
50
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
51
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
52
|
+
> furnished to do so, subject to the following conditions:
|
|
53
|
+
>
|
|
54
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
55
|
+
> copies or substantial portions of the Software.
|
|
56
|
+
>
|
|
57
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
58
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
59
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
60
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
61
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
62
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
63
|
+
> SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loader: string;
|
package/dist/index.js
ADDED
package/dist/loader.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = function workerLoader(source, inputMap) {
|
|
3
|
+
const done = this.async();
|
|
4
|
+
const query = new URLSearchParams(this.resourceQuery);
|
|
5
|
+
const options = this.getOptions();
|
|
6
|
+
const poolSize = options.poolSize ?? 1;
|
|
7
|
+
const target = options.target ?? "browser";
|
|
8
|
+
if (target !== "browser" && target !== "node") {
|
|
9
|
+
done(new TypeError("target must be browser or node"));
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const hmr = options.hmr ?? "webpack";
|
|
13
|
+
if (hmr !== "webpack" && hmr !== "turbopack") {
|
|
14
|
+
done(new TypeError("hmr must be webpack or turbopack"));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!Number.isInteger(poolSize) || poolSize < 1) {
|
|
18
|
+
done(new TypeError("poolSize must be a positive integer"));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
import("./transform.js").then(({ transform }) => {
|
|
22
|
+
const result = transform({ code: source, sourceId: this.resourcePath, query, poolSize, hmr, target, otel: options.otel, instrumentation: options.instrumentation, workerSetup: options.workerSetup, rootContext: this.rootContext,
|
|
23
|
+
inputMap: typeof inputMap === "string" ? inputMap : inputMap ? JSON.stringify(inputMap) : undefined });
|
|
24
|
+
done(null, result.code, result.map ? JSON.parse(result.map) : undefined);
|
|
25
|
+
}).catch(error => done(error instanceof Error ? error : new Error(String(error))));
|
|
26
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface LoaderContext {
|
|
2
|
+
rootContext: string;
|
|
3
|
+
resourcePath: string;
|
|
4
|
+
resourceQuery: string;
|
|
5
|
+
getOptions(): {
|
|
6
|
+
otel?: boolean | "forward";
|
|
7
|
+
instrumentation?: string;
|
|
8
|
+
workerSetup?: string;
|
|
9
|
+
poolSize?: number;
|
|
10
|
+
target?: "browser" | "node";
|
|
11
|
+
hmr?: "webpack" | "turbopack";
|
|
12
|
+
};
|
|
13
|
+
async(): (error: Error | null, code?: string, map?: unknown) => void;
|
|
14
|
+
}
|
|
15
|
+
export = workerLoader;
|
|
16
|
+
declare function workerLoader(this: LoaderContext, source: string, inputMap?: string | object): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function transform({ code, sourceId, query, poolSize, hmr, target, inputMap, otel, workerSetup, instrumentation, rootContext }: {
|
|
2
|
+
otel?: boolean | "forward";
|
|
3
|
+
instrumentation?: string;
|
|
4
|
+
workerSetup?: string;
|
|
5
|
+
rootContext?: string;
|
|
6
|
+
code: string;
|
|
7
|
+
inputMap?: string;
|
|
8
|
+
sourceId: string;
|
|
9
|
+
query: URLSearchParams;
|
|
10
|
+
poolSize: number;
|
|
11
|
+
target: "browser" | "node";
|
|
12
|
+
hmr: "webpack" | "turbopack";
|
|
13
|
+
}): import("@use-worker/compiler-estree").GeneratedModule;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { basename, dirname, relative, resolve } from "node:path";
|
|
2
|
+
import { compileSource, createModuleWorkerEntry, mayContainWorkerDirective } from "@use-worker/oxc";
|
|
3
|
+
export function transform({ code, sourceId, query, poolSize, hmr, target, inputMap, otel, workerSetup, instrumentation, rootContext }) {
|
|
4
|
+
if (!mayContainWorkerDirective(code) && !query.has("use-worker-entry") && !query.has("use-worker-implementation"))
|
|
5
|
+
return { code, map: inputMap ?? null };
|
|
6
|
+
const ownPath = `./${basename(sourceId)}`;
|
|
7
|
+
const linkage = {
|
|
8
|
+
instrumentation: instrumentation ? "./" + relative(dirname(sourceId), resolve(rootContext ?? process.cwd(), instrumentation)).replaceAll("\\", "/") : undefined,
|
|
9
|
+
otel, workerSetup: workerSetup ? "./" + relative(dirname(sourceId), resolve(rootContext ?? process.cwd(), workerSetup)).replaceAll("\\", "/") : undefined,
|
|
10
|
+
client: "@use-worker/core/internal/client-runtime",
|
|
11
|
+
worker: target === "node" ? "@use-worker/core/internal/node-worker" : "@use-worker/core/internal/worker-runtime",
|
|
12
|
+
hmr,
|
|
13
|
+
};
|
|
14
|
+
const result = compileSource({
|
|
15
|
+
code, sourceId, linkage, poolSize, inputMap, transformInline: true,
|
|
16
|
+
moduleImplementation: query.has("use-worker-implementation"),
|
|
17
|
+
});
|
|
18
|
+
const compilation = result.compilation;
|
|
19
|
+
if (!compilation)
|
|
20
|
+
return { code: result.code, map: result.map };
|
|
21
|
+
if (compilation.kind === "implementation")
|
|
22
|
+
return compilation.main;
|
|
23
|
+
if (query.has("use-worker-entry")) {
|
|
24
|
+
return compilation.kind === "inline" ? { code: compilation.workerCode, map: compilation.workerMap } :
|
|
25
|
+
{ code: createModuleWorkerEntry(`${ownPath}?use-worker-implementation`, linkage.worker, linkage), map: null };
|
|
26
|
+
}
|
|
27
|
+
const specifier = `${ownPath}?use-worker-entry`;
|
|
28
|
+
return compilation.renderMain(target === "node"
|
|
29
|
+
? { kind: "node", specifier, adapter: "@use-worker/core/internal/node-client" }
|
|
30
|
+
: { kind: "browser", specifier });
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@use-worker/query-loader",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"THIRD_PARTY_NOTICES.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./loader": "./dist/loader.cjs"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@use-worker/oxc": "0.1.0-beta.0",
|
|
20
|
+
"@use-worker/core": "0.1.0-beta.0"
|
|
21
|
+
},
|
|
22
|
+
"description": "Shared query-aware source loader for use-worker bundler integrations.",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
|
+
}
|
|
30
|
+
}
|