@pikku/cli 0.12.54 → 0.12.56
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/cli.schema.json +1 -1
- package/console-app/assets/{index-DYnbceYg.js → index-xN8LW0II.js} +155 -155
- package/console-app/index.html +1 -1
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +3 -3
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.d.ts +6 -6
- package/dist/.pikku/cli/pikku-cli-channel.js +11 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.json +14 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +29 -0
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +8 -31
- package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.json +1420 -1384
- package/dist/.pikku/function/pikku-functions.gen.js +3 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
- package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
- package/dist/.pikku/pikku-meta-service.gen.js +1 -1
- package/dist/.pikku/pikku-services.gen.d.ts +4 -2
- package/dist/.pikku/pikku-services.gen.js +2 -0
- package/dist/.pikku/pikku-types.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.json +0 -248
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +69 -67
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +191 -185
- package/dist/.pikku/schemas/schemas/FabricAddonVerifyInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricAddonVerifyOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuAuthInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
- package/dist/.pikku/workflow/meta/allWorkflow.gen.json +9 -3
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
- package/dist/bin/pikku-bin.mjs +2 -2
- package/dist/src/cli.wiring.js +15 -1
- package/dist/src/deploy/analyzer/analyzer.d.ts +6 -0
- package/dist/src/deploy/analyzer/analyzer.js +5 -4
- package/dist/src/deploy/build-pipeline.d.ts +5 -1
- package/dist/src/deploy/build-pipeline.js +5 -5
- package/dist/src/deploy/bundler/bun-bundler.d.ts +14 -0
- package/dist/src/deploy/bundler/bun-bundler.js +121 -0
- package/dist/src/deploy/bundler/bundler.d.ts +25 -30
- package/dist/src/deploy/bundler/bundler.interface.d.ts +54 -0
- package/dist/src/deploy/bundler/bundler.interface.js +11 -0
- package/dist/src/deploy/bundler/bundler.js +120 -190
- package/dist/src/deploy/bundler/dep-extractor.d.ts +11 -3
- package/dist/src/deploy/bundler/dep-extractor.js +12 -6
- package/dist/src/deploy/bundler/index.d.ts +5 -2
- package/dist/src/deploy/bundler/index.js +4 -2
- package/dist/src/deploy/bundler/node-bundler.d.ts +13 -0
- package/dist/src/deploy/bundler/node-bundler.js +80 -0
- package/dist/src/deploy/provider-adapter.d.ts +11 -0
- package/dist/src/deploy/server-entry.js +3 -1
- package/dist/src/fabric/fabric-commands.d.ts +109 -72
- package/dist/src/fabric/fabric-commands.js +8 -0
- package/dist/src/fabric/functions/add.function.d.ts +3 -3
- package/dist/src/fabric/functions/addon-verify.function.d.ts +54 -0
- package/dist/src/fabric/functions/addon-verify.function.js +153 -0
- package/dist/src/fabric/functions/db-schema.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy-units.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy.function.d.ts +6 -6
- package/dist/src/fabric/functions/domains-add.function.d.ts +3 -3
- package/dist/src/fabric/functions/domains-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/domains-remove.function.d.ts +3 -3
- package/dist/src/fabric/functions/errors.function.d.ts +3 -3
- package/dist/src/fabric/functions/init.function.d.ts +3 -3
- package/dist/src/fabric/functions/link.function.d.ts +3 -3
- package/dist/src/fabric/functions/llm-key.function.d.ts +3 -3
- package/dist/src/fabric/functions/llm-key.function.js +1 -1
- package/dist/src/fabric/functions/login.function.d.ts +3 -3
- package/dist/src/fabric/functions/logs.function.d.ts +3 -3
- package/dist/src/fabric/functions/metrics.function.d.ts +3 -3
- package/dist/src/fabric/functions/publish.function.d.ts +3 -3
- package/dist/src/fabric/functions/publish.function.js +8 -3
- package/dist/src/fabric/functions/rollback.function.d.ts +3 -3
- package/dist/src/fabric/functions/secrets-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/secrets-set.function.d.ts +3 -3
- package/dist/src/fabric/functions/smoke.function.d.ts +3 -3
- package/dist/src/fabric/functions/status.function.d.ts +3 -3
- package/dist/src/fabric/functions/trace.function.d.ts +3 -3
- package/dist/src/fabric/functions/validate.function.d.ts +3 -3
- package/dist/src/functions/commands/all.d.ts +1 -1
- package/dist/src/functions/commands/all.js +19 -2
- package/dist/src/functions/commands/binary.d.ts +3 -3
- package/dist/src/functions/commands/bootstrap.d.ts +1 -1
- package/dist/src/functions/commands/bootstrap.js +3 -0
- package/dist/src/functions/commands/console.d.ts +3 -3
- package/dist/src/functions/commands/db-audit.d.ts +1 -1
- package/dist/src/functions/commands/db-generate.d.ts +1 -1
- package/dist/src/functions/commands/db-migrate.d.ts +1 -1
- package/dist/src/functions/commands/db-reset.d.ts +1 -1
- package/dist/src/functions/commands/db-seed.d.ts +1 -1
- package/dist/src/functions/commands/deploy-apply.d.ts +3 -3
- package/dist/src/functions/commands/deploy-apply.js +32 -1
- package/dist/src/functions/commands/deploy-info.d.ts +1 -1
- package/dist/src/functions/commands/deploy-plan.d.ts +3 -3
- package/dist/src/functions/commands/deploy-plan.js +3 -1
- package/dist/src/functions/commands/dev.d.ts +3 -3
- package/dist/src/functions/commands/dev.js +17 -45
- package/dist/src/functions/commands/emails-init.d.ts +1 -1
- package/dist/src/functions/commands/enable.d.ts +6 -5
- package/dist/src/functions/commands/enable.js +4 -0
- package/dist/src/functions/commands/info.d.ts +4 -4
- package/dist/src/functions/commands/login.d.ts +7 -7
- package/dist/src/functions/commands/meta.d.ts +31 -31
- package/dist/src/functions/commands/new-addon.d.ts +3 -3
- package/dist/src/functions/commands/new-function.d.ts +3 -3
- package/dist/src/functions/commands/new-middleware.d.ts +3 -3
- package/dist/src/functions/commands/new-permission.d.ts +3 -3
- package/dist/src/functions/commands/new-wiring.d.ts +3 -3
- package/dist/src/functions/commands/pikku-command-bootstrap.d.ts +1 -1
- package/dist/src/functions/commands/pikku-command-summary.d.ts +1 -1
- package/dist/src/functions/commands/pikku-command-summary.js +6 -1
- package/dist/src/functions/commands/skills.d.ts +6 -6
- package/dist/src/functions/commands/tests-coverage.d.ts +3 -3
- package/dist/src/functions/commands/tests-init.d.ts +3 -3
- package/dist/src/functions/commands/versions-check.d.ts +1 -1
- package/dist/src/functions/commands/versions-init.d.ts +3 -3
- package/dist/src/functions/commands/versions-update.d.ts +1 -1
- package/dist/src/functions/commands/watch.d.ts +3 -3
- package/dist/src/functions/commands/workspace-validate.d.ts +3 -3
- package/dist/src/functions/db/db-codegen.js +14 -0
- package/dist/src/functions/db/sqlite/sqlite-runtime-bun.js +10 -0
- package/dist/src/functions/runtimes/fetch/index.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.d.ts +1 -1
- package/dist/src/functions/runtimes/tanstack-start/pikku-command-tanstack-start.d.ts +1 -1
- package/dist/src/functions/runtimes/websocket/pikku-command-websocket-typed.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent-types.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-public-agent.d.ts +1 -1
- package/dist/src/functions/wirings/auth/pikku-command-auth.d.ts +7 -1
- package/dist/src/functions/wirings/auth/pikku-command-auth.js +14 -2
- package/dist/src/functions/wirings/auth/serialize-auth-types.d.ts +10 -0
- package/dist/src/functions/wirings/auth/serialize-auth-types.js +15 -0
- package/dist/src/functions/wirings/channels/pikku-channels.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channel-types.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channels-map.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channels.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-console-functions.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-node-types.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-nodes-meta.d.ts +1 -1
- package/dist/src/functions/wirings/credentials/pikku-command-credentials.d.ts +1 -1
- package/dist/src/functions/wirings/emails/pikku-command-emails.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-addon-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.d.ts +3 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types.d.ts +3 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +10 -3
- package/dist/src/functions/wirings/functions/pikku-command-functions.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +6 -29
- package/dist/src/functions/wirings/gateway/pikku-command-gateway.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-map.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-routes.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-types.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-openapi.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-http-routes.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.d.ts +1 -1
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.d.ts +1 -1
- package/dist/src/functions/wirings/package/pikku-command-package-types.d.ts +2 -2
- package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -1
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-map.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-service.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-types.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-queue-map.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-queue.d.ts +1 -1
- package/dist/src/functions/wirings/realtime/pikku-command-events-scaffold.d.ts +1 -1
- package/dist/src/functions/wirings/realtime/pikku-command-realtime.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-public-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-react-query.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-remote-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.d.ts +2 -2
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.d.ts +1 -1
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.d.ts +1 -1
- package/dist/src/functions/wirings/secrets/pikku-command-secrets.d.ts +1 -1
- package/dist/src/functions/wirings/triggers/pikku-command-trigger-types.d.ts +3 -3
- package/dist/src/functions/wirings/triggers/pikku-command-trigger.d.ts +1 -1
- package/dist/src/functions/wirings/variables/pikku-command-variables.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-routes.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow.d.ts +1 -1
- package/dist/src/functions/workflows/all.workflow.js +6 -1
- package/dist/src/scaffold/rpc-remote.gen.d.ts +3 -3
- package/dist/src/scaffold/rpc-remote.gen.js +1 -1
- package/dist/src/server/bun-server-runner.d.ts +17 -0
- package/dist/src/server/bun-server-runner.js +25 -0
- package/dist/src/server/dev-server-runner.interface.d.ts +31 -0
- package/dist/src/server/dev-server-runner.interface.js +11 -0
- package/dist/src/server/node-server-runner.d.ts +12 -0
- package/dist/src/server/node-server-runner.js +30 -0
- package/dist/src/services/cli-logger.service.js +7 -1
- package/dist/src/services.js +18 -0
- package/dist/src/utils/detect-better-auth.d.ts +7 -0
- package/dist/src/utils/detect-better-auth.js +29 -0
- package/dist/src/utils/parse-cli-filters.d.ts +1 -0
- package/dist/src/utils/parse-cli-filters.js +1 -0
- package/dist/src/utils/pikku-cli-config.js +1 -1
- package/dist/src/utils/serialize-schemas.js +5 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/skills/pikku-addon/SKILL.md +25 -117
- package/skills/pikku-addon/references/addon-package-manifest.md +63 -0
- package/skills/pikku-cli/SKILL.md +7 -93
- package/skills/pikku-cli/references/complete-example.md +82 -0
- package/skills/pikku-concepts/SKILL.md +17 -69
- package/skills/pikku-concepts/references/concept-mapping.md +37 -13
- package/skills/pikku-concepts/references/packages.md +29 -0
- package/skills/pikku-http/SKILL.md +14 -105
- package/skills/pikku-http/references/http-options.md +57 -0
- package/skills/pikku-middleware/SKILL.md +11 -68
- package/skills/pikku-middleware/references/middleware-patterns.md +61 -0
- package/skills/pikku-realtime/SKILL.md +56 -105
- package/skills/pikku-realtime/references/other-routes.md +23 -0
- package/skills/pikku-services/SKILL.md +25 -108
- package/skills/pikku-services/references/audit-wire-service.md +34 -0
- package/skills/pikku-testing/SKILL.md +51 -359
- package/skills/pikku-testing/references/cucumber-bdd-testing.md +176 -0
- package/skills/pikku-workflow/SKILL.md +93 -259
- package/skills/pikku-workflow/references/workflow-reference.md +63 -0
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared bundling orchestration for Pikku deploys.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* `BaseBundler` performs everything that is runtime-independent for each
|
|
5
|
+
* deployment unit:
|
|
6
|
+
* 1. Take a pre-generated entry point (provided by the deploy provider)
|
|
7
|
+
* 2. Stub gen files / npm modules not needed by this unit
|
|
8
|
+
* 3. Delegate the actual compile to a runtime backend (`compile`)
|
|
9
|
+
* 4. Resolve external dependency versions into a minimal package.json
|
|
10
|
+
* 5. Write all artifacts to `<outputDir>/<unit-name>/` and hash them
|
|
11
|
+
*
|
|
12
|
+
* The runtime-specific compile step lives in `NodeBundler` (esbuild) and
|
|
13
|
+
* `BunBundler` (Bun.build); the right one is injected from `services.ts`.
|
|
11
14
|
*/
|
|
12
|
-
import type { DeploymentManifest,
|
|
15
|
+
import type { DeploymentManifest, BundleOutput } from './types.js';
|
|
16
|
+
import type { Bundler, BundleUnitsOptions, CompileInput, CompileResult } from './bundler.interface.js';
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Entry points must be pre-generated by the provider-specific package
|
|
17
|
-
* (e.g. @pikku/deploy-cloudflare) and passed in as entryFiles.
|
|
18
|
-
*
|
|
19
|
-
* @param projectDir - Root directory of the Pikku project
|
|
20
|
-
* @param manifest - The deployment manifest describing all units
|
|
21
|
-
* @param entryFiles - Map of unit name -> entry file path (generated by the deploy provider)
|
|
22
|
-
* @param outputDir - Base output directory (defaults to `<projectDir>/.deploy/build`)
|
|
18
|
+
* Runtime-independent bundling orchestration. Subclasses implement only
|
|
19
|
+
* `compile` — the actual esbuild / Bun.build invocation.
|
|
23
20
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
resolveOutputDir?: (unit: DeploymentUnit, baseOutputDir: string) => string;
|
|
35
|
-
}): Promise<BundleOutput>;
|
|
21
|
+
export declare abstract class BaseBundler implements Bundler {
|
|
22
|
+
/**
|
|
23
|
+
* Runtime-specific compile step: write `input.bundlePath` (and its `.map`
|
|
24
|
+
* when `input.sourcemap`) and return the external packages + optional
|
|
25
|
+
* metafile JSON.
|
|
26
|
+
*/
|
|
27
|
+
protected abstract compile(input: CompileInput): Promise<CompileResult>;
|
|
28
|
+
bundleUnits(projectDir: string, manifest: DeploymentManifest, entryFiles: Map<string, string>, outputDir?: string, options?: BundleUnitsOptions): Promise<BundleOutput>;
|
|
29
|
+
private bundleUnit;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler abstraction.
|
|
3
|
+
*
|
|
4
|
+
* A `Bundler` turns a deployment manifest's units into self-contained bundles.
|
|
5
|
+
* The shared orchestration (dead-module stubbing, dependency extraction,
|
|
6
|
+
* package.json + hashing) lives in `BaseBundler`; each runtime supplies only the
|
|
7
|
+
* compile step via a `Bundler` implementation (esbuild for node, Bun.build for
|
|
8
|
+
* bun). The runtime is resolved once in `services.ts` and injected — no
|
|
9
|
+
* `typeof Bun` checks in the pipeline.
|
|
10
|
+
*/
|
|
11
|
+
import type { DeploymentManifest, DeploymentUnit, BundleOutput } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Inputs the shared orchestration hands to a backend's runtime-specific compile
|
|
14
|
+
* step. The backend writes `bundlePath` (and `${bundlePath}.map` when
|
|
15
|
+
* `sourcemap`) itself and returns the external packages + optional metafile.
|
|
16
|
+
*/
|
|
17
|
+
export interface CompileInput {
|
|
18
|
+
unitName: string;
|
|
19
|
+
entryPath: string;
|
|
20
|
+
bundlePath: string;
|
|
21
|
+
projectDir: string;
|
|
22
|
+
platform: 'node' | 'neutral' | 'browser';
|
|
23
|
+
format: 'esm' | 'cjs';
|
|
24
|
+
externals: string[];
|
|
25
|
+
aliases?: Record<string, string>;
|
|
26
|
+
define?: Record<string, string>;
|
|
27
|
+
/** ESM require/__filename/__dirname shim, or undefined when not needed. */
|
|
28
|
+
bannerJs?: string;
|
|
29
|
+
sourcemap: boolean;
|
|
30
|
+
emitMetafile: boolean;
|
|
31
|
+
/** Regexes for modules to replace with an empty `export {}` module. */
|
|
32
|
+
deadPatterns: RegExp[];
|
|
33
|
+
}
|
|
34
|
+
export interface CompileResult {
|
|
35
|
+
/** Real npm package names kept external — drive the unit's package.json. */
|
|
36
|
+
externalPackages: Set<string>;
|
|
37
|
+
/** Stringified metafile when `emitMetafile` was set; otherwise undefined. */
|
|
38
|
+
metafileJson?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface BundleUnitsOptions {
|
|
41
|
+
externals?: string[];
|
|
42
|
+
aliases?: Record<string, string>;
|
|
43
|
+
define?: Record<string, string>;
|
|
44
|
+
platform?: 'node' | 'neutral' | 'browser';
|
|
45
|
+
format?: 'esm' | 'cjs';
|
|
46
|
+
noRequireShim?: boolean;
|
|
47
|
+
sourcemap?: boolean;
|
|
48
|
+
emitMetafile?: boolean;
|
|
49
|
+
stubModules?: string[];
|
|
50
|
+
resolveOutputDir?: (unit: DeploymentUnit, baseOutputDir: string) => string;
|
|
51
|
+
}
|
|
52
|
+
export interface Bundler {
|
|
53
|
+
bundleUnits(projectDir: string, manifest: DeploymentManifest, entryFiles: Map<string, string>, outputDir?: string, options?: BundleUnitsOptions): Promise<BundleOutput>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler abstraction.
|
|
3
|
+
*
|
|
4
|
+
* A `Bundler` turns a deployment manifest's units into self-contained bundles.
|
|
5
|
+
* The shared orchestration (dead-module stubbing, dependency extraction,
|
|
6
|
+
* package.json + hashing) lives in `BaseBundler`; each runtime supplies only the
|
|
7
|
+
* compile step via a `Bundler` implementation (esbuild for node, Bun.build for
|
|
8
|
+
* bun). The runtime is resolved once in `services.ts` and injected — no
|
|
9
|
+
* `typeof Bun` checks in the pipeline.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared bundling orchestration for Pikku deploys.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* `BaseBundler` performs everything that is runtime-independent for each
|
|
5
|
+
* deployment unit:
|
|
6
|
+
* 1. Take a pre-generated entry point (provided by the deploy provider)
|
|
7
|
+
* 2. Stub gen files / npm modules not needed by this unit
|
|
8
|
+
* 3. Delegate the actual compile to a runtime backend (`compile`)
|
|
9
|
+
* 4. Resolve external dependency versions into a minimal package.json
|
|
10
|
+
* 5. Write all artifacts to `<outputDir>/<unit-name>/` and hash them
|
|
11
|
+
*
|
|
12
|
+
* The runtime-specific compile step lives in `NodeBundler` (esbuild) and
|
|
13
|
+
* `BunBundler` (Bun.build); the right one is injected from `services.ts`.
|
|
11
14
|
*/
|
|
12
|
-
import { build } from 'esbuild';
|
|
13
15
|
import { writeFile, mkdir, stat, readFile } from 'node:fs/promises';
|
|
14
16
|
import { join } from 'node:path';
|
|
15
17
|
import { createHash } from 'node:crypto';
|
|
16
|
-
import {
|
|
18
|
+
import { resolveExternalVersions, generateMinimalPackageJson, } from './dep-extractor.js';
|
|
17
19
|
/**
|
|
18
20
|
* Mapping of service name -> gen file pattern that should be stubbed
|
|
19
21
|
* when the service is not required by a deployment unit.
|
|
@@ -66,196 +68,124 @@ async function getDeadGenFilePatterns(unitOutputDir) {
|
|
|
66
68
|
}
|
|
67
69
|
return patterns;
|
|
68
70
|
}
|
|
69
|
-
/**
|
|
70
|
-
* esbuild plugin that stubs gen files for services not needed by this unit.
|
|
71
|
-
* This prevents Node.js-only modules (e.g. LocalMetaService which uses fs)
|
|
72
|
-
* from being pulled into serverless worker bundles via dynamic imports.
|
|
73
|
-
*/
|
|
74
|
-
function createDeadModuleStubPlugin(patterns) {
|
|
75
|
-
return {
|
|
76
|
-
name: 'pikku-dead-module-stub',
|
|
77
|
-
setup(build) {
|
|
78
|
-
if (patterns.length === 0)
|
|
79
|
-
return;
|
|
80
|
-
const combined = new RegExp(patterns.map((p) => p.source).join('|'));
|
|
81
|
-
build.onResolve({ filter: combined }, (args) => ({
|
|
82
|
-
path: args.path,
|
|
83
|
-
namespace: 'pikku-stub',
|
|
84
|
-
}));
|
|
85
|
-
build.onLoad({ filter: /.*/, namespace: 'pikku-stub' }, () => ({
|
|
86
|
-
contents: 'export {}',
|
|
87
|
-
loader: 'js',
|
|
88
|
-
}));
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
71
|
const BUNDLE_FILENAME = 'bundle.js';
|
|
93
72
|
const METAFILE_FILENAME = 'metafile.json';
|
|
94
73
|
const PACKAGE_JSON_FILENAME = 'package.json';
|
|
95
74
|
const EXACT_DEPENDENCIES_FILENAME = 'exact-dependencies.json';
|
|
96
75
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* Produces three files in the unit output directory:
|
|
100
|
-
* - bundle.js: The bundled code (user code only, external deps as bare imports)
|
|
101
|
-
* - metafile.json: esbuild's metafile for analysis
|
|
102
|
-
* - package.json: Minimal manifest with only the external deps this unit needs
|
|
76
|
+
* Runtime-independent bundling orchestration. Subclasses implement only
|
|
77
|
+
* `compile` — the actual esbuild / Bun.build invocation.
|
|
103
78
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
dir = parent;
|
|
133
|
-
}
|
|
134
|
-
// For ESM + node platform, CJS deps may use require() / __filename / __dirname
|
|
135
|
-
// for builtins or to locate native addons (the `bindings` package, used
|
|
136
|
-
// transitively by `pg` and many others, calls `__filename` directly). esbuild
|
|
137
|
-
// wraps require() as __require() which fails at runtime in ESM, and leaves
|
|
138
|
-
// `__filename` / `__dirname` as undefined references. The banner shims all
|
|
139
|
-
// three via createRequire / fileURLToPath so CJS builtins resolve and native-
|
|
140
|
-
// addon loaders find their .node files.
|
|
141
|
-
// Skipped when the provider opts out via `noRequireShim` (e.g. CF Workers
|
|
142
|
-
// — `import.meta.url` is undefined there, so the shim crashes at boot).
|
|
143
|
-
const resolvedFormat = format ?? 'esm';
|
|
144
|
-
const banner = resolvedFormat === 'esm' &&
|
|
145
|
-
(platform ?? 'node') === 'node' &&
|
|
146
|
-
!options.noRequireShim
|
|
147
|
-
? {
|
|
148
|
-
js: `import { createRequire as __pikkuCreateRequire } from 'node:module'; import { fileURLToPath as __pikkuFileURLToPath } from 'node:url'; import { dirname as __pikkuDirname } from 'node:path'; const require = __pikkuCreateRequire(import.meta.url); const __filename = __pikkuFileURLToPath(import.meta.url); const __dirname = __pikkuDirname(__filename);`,
|
|
79
|
+
export class BaseBundler {
|
|
80
|
+
async bundleUnits(projectDir, manifest, entryFiles, outputDir, options) {
|
|
81
|
+
const buildDir = outputDir ?? join(projectDir, '.deploy', 'build');
|
|
82
|
+
const results = [];
|
|
83
|
+
const errors = [];
|
|
84
|
+
if (manifest.units.length === 0) {
|
|
85
|
+
return { results, errors };
|
|
86
|
+
}
|
|
87
|
+
for (const unit of manifest.units) {
|
|
88
|
+
const entryPath = entryFiles.get(unit.name);
|
|
89
|
+
if (!entryPath) {
|
|
90
|
+
errors.push({
|
|
91
|
+
unitName: unit.name,
|
|
92
|
+
error: `No entry point provided for unit "${unit.name}"`,
|
|
93
|
+
});
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const unitOutputDir = options?.resolveOutputDir
|
|
97
|
+
? options.resolveOutputDir(unit, buildDir)
|
|
98
|
+
: join(buildDir, unit.name);
|
|
99
|
+
try {
|
|
100
|
+
const result = await this.bundleUnit(unit, entryPath, unitOutputDir, projectDir, options ?? {});
|
|
101
|
+
results.push(result);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
105
|
+
errors.push({ unitName: unit.name, error: message });
|
|
106
|
+
}
|
|
149
107
|
}
|
|
150
|
-
: undefined;
|
|
151
|
-
const result = await build({
|
|
152
|
-
entryPoints: [entryPath],
|
|
153
|
-
bundle: true,
|
|
154
|
-
absWorkingDir: projectDir,
|
|
155
|
-
nodePaths,
|
|
156
|
-
platform: platform ?? 'node',
|
|
157
|
-
format: resolvedFormat,
|
|
158
|
-
banner,
|
|
159
|
-
metafile: true,
|
|
160
|
-
target: 'es2022',
|
|
161
|
-
outfile: bundlePath,
|
|
162
|
-
// Minify every deploy bundle — esbuild output ships straight to the runtime
|
|
163
|
-
// (CF Workers / container), tsc is never the bundler. keepNames preserves
|
|
164
|
-
// Function.name / constructor.name so name-based reflection still works.
|
|
165
|
-
minify: true,
|
|
166
|
-
keepNames: true,
|
|
167
|
-
sourcemap: sourcemap ?? false,
|
|
168
|
-
logLevel: 'warning',
|
|
169
|
-
loader: { '.ts': 'ts' },
|
|
170
|
-
external: externals ?? ['node:*'],
|
|
171
|
-
alias: aliases,
|
|
172
|
-
define,
|
|
173
|
-
plugins: [createDeadModuleStubPlugin(deadPatterns)],
|
|
174
|
-
});
|
|
175
|
-
// Always produced in-memory (drives dependency extraction); only persisted
|
|
176
|
-
// when requested — it's large (~1.6MB/unit) and never needed at runtime.
|
|
177
|
-
if (emitMetafile) {
|
|
178
|
-
const metafileJson = JSON.stringify(result.metafile, null, 2);
|
|
179
|
-
await writeFile(metafilePath, metafileJson, 'utf-8');
|
|
180
|
-
}
|
|
181
|
-
// Extract dependencies and generate minimal package.json
|
|
182
|
-
const { exactDependencies, exactOptionalDependencies } = await extractDependencies(result.metafile, projectDir);
|
|
183
|
-
const packageJson = generateMinimalPackageJson(unit.name, exactDependencies, exactOptionalDependencies);
|
|
184
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
185
|
-
await writeFile(exactDependenciesPath, JSON.stringify({
|
|
186
|
-
dependencies: Object.fromEntries(Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b))),
|
|
187
|
-
optionalDependencies: Object.fromEntries(Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b))),
|
|
188
|
-
}, null, 2), 'utf-8');
|
|
189
|
-
// Get bundle size
|
|
190
|
-
const bundleStat = await stat(bundlePath);
|
|
191
|
-
const bundleContents = await readFile(bundlePath);
|
|
192
|
-
const bundleHash = createHash('sha256').update(bundleContents).digest('hex');
|
|
193
|
-
const exactDependenciesHash = createHash('sha256')
|
|
194
|
-
.update(JSON.stringify({
|
|
195
|
-
dependencies: Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b)),
|
|
196
|
-
optionalDependencies: Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b)),
|
|
197
|
-
}))
|
|
198
|
-
.digest('hex');
|
|
199
|
-
return {
|
|
200
|
-
unitName: unit.name,
|
|
201
|
-
bundlePath,
|
|
202
|
-
packageJsonPath,
|
|
203
|
-
exactDependenciesPath,
|
|
204
|
-
metafilePath,
|
|
205
|
-
bundleSizeBytes: bundleStat.size,
|
|
206
|
-
bundleHash,
|
|
207
|
-
exactDependenciesHash,
|
|
208
|
-
exactDependencies,
|
|
209
|
-
exactOptionalDependencies,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Bundles all deployment units defined in a DeploymentManifest.
|
|
214
|
-
*
|
|
215
|
-
* Entry points must be pre-generated by the provider-specific package
|
|
216
|
-
* (e.g. @pikku/deploy-cloudflare) and passed in as entryFiles.
|
|
217
|
-
*
|
|
218
|
-
* @param projectDir - Root directory of the Pikku project
|
|
219
|
-
* @param manifest - The deployment manifest describing all units
|
|
220
|
-
* @param entryFiles - Map of unit name -> entry file path (generated by the deploy provider)
|
|
221
|
-
* @param outputDir - Base output directory (defaults to `<projectDir>/.deploy/build`)
|
|
222
|
-
*/
|
|
223
|
-
export async function bundleUnits(projectDir, manifest, entryFiles, outputDir, options) {
|
|
224
|
-
const buildDir = outputDir ?? join(projectDir, '.deploy', 'build');
|
|
225
|
-
const results = [];
|
|
226
|
-
const errors = [];
|
|
227
|
-
if (manifest.units.length === 0) {
|
|
228
108
|
return { results, errors };
|
|
229
109
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const result = await bundleUnit({
|
|
244
|
-
unit,
|
|
245
|
-
entryPath,
|
|
246
|
-
unitOutputDir,
|
|
247
|
-
projectDir,
|
|
248
|
-
...options,
|
|
249
|
-
});
|
|
250
|
-
results.push(result);
|
|
110
|
+
async bundleUnit(unit, entryPath, unitOutputDir, projectDir, options) {
|
|
111
|
+
await mkdir(unitOutputDir, { recursive: true });
|
|
112
|
+
const bundlePath = join(unitOutputDir, BUNDLE_FILENAME);
|
|
113
|
+
const metafilePath = join(unitOutputDir, METAFILE_FILENAME);
|
|
114
|
+
const packageJsonPath = join(unitOutputDir, PACKAGE_JSON_FILENAME);
|
|
115
|
+
const exactDependenciesPath = join(unitOutputDir, EXACT_DEPENDENCIES_FILENAME);
|
|
116
|
+
// Determine which gen files to stub based on per-unit service requirements,
|
|
117
|
+
// plus any provider-supplied module stubs (modules the provider's runtime
|
|
118
|
+
// never executes — e.g. the `postgres` driver on CF Workers, which use a
|
|
119
|
+
// libsql/Turso dialect; the postgres branch is URL-gated and never taken).
|
|
120
|
+
const deadPatterns = await getDeadGenFilePatterns(unitOutputDir);
|
|
121
|
+
for (const source of options.stubModules ?? []) {
|
|
122
|
+
deadPatterns.push(new RegExp(source));
|
|
251
123
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
124
|
+
const platform = options.platform ?? 'node';
|
|
125
|
+
const format = options.format ?? 'esm';
|
|
126
|
+
const externals = options.externals ?? ['node:*'];
|
|
127
|
+
const sourcemap = options.sourcemap ?? false;
|
|
128
|
+
const emitMetafile = options.emitMetafile ?? false;
|
|
129
|
+
// For ESM + node platform, CJS deps may use require() / __filename /
|
|
130
|
+
// __dirname for builtins or to locate native addons (the `bindings`
|
|
131
|
+
// package, used transitively by `pg`, calls `__filename` directly). esbuild
|
|
132
|
+
// wraps require() as __require() which fails at runtime in ESM, and leaves
|
|
133
|
+
// `__filename` / `__dirname` as undefined references. The banner shims all
|
|
134
|
+
// three so CJS builtins resolve and native-addon loaders find their .node
|
|
135
|
+
// files. Skipped when the provider opts out via `noRequireShim` (e.g. CF
|
|
136
|
+
// Workers — `import.meta.url` is undefined there, so the shim crashes).
|
|
137
|
+
const bannerJs = format === 'esm' && platform === 'node' && !options.noRequireShim
|
|
138
|
+
? `import { createRequire as __pikkuCreateRequire } from 'node:module'; import { fileURLToPath as __pikkuFileURLToPath } from 'node:url'; import { dirname as __pikkuDirname } from 'node:path'; const require = __pikkuCreateRequire(import.meta.url); const __filename = __pikkuFileURLToPath(import.meta.url); const __dirname = __pikkuDirname(__filename);`
|
|
139
|
+
: undefined;
|
|
140
|
+
const { externalPackages, metafileJson } = await this.compile({
|
|
141
|
+
unitName: unit.name,
|
|
142
|
+
entryPath,
|
|
143
|
+
bundlePath,
|
|
144
|
+
projectDir,
|
|
145
|
+
platform,
|
|
146
|
+
format,
|
|
147
|
+
externals,
|
|
148
|
+
aliases: options.aliases,
|
|
149
|
+
define: options.define,
|
|
150
|
+
bannerJs,
|
|
151
|
+
sourcemap,
|
|
152
|
+
emitMetafile,
|
|
153
|
+
deadPatterns,
|
|
154
|
+
});
|
|
155
|
+
// Metafile is large (~1.6MB/unit) and never needed at runtime — only
|
|
156
|
+
// persisted for debugging.
|
|
157
|
+
if (emitMetafile && metafileJson) {
|
|
158
|
+
await writeFile(metafilePath, metafileJson, 'utf-8');
|
|
258
159
|
}
|
|
160
|
+
// Extract dependencies and generate minimal package.json
|
|
161
|
+
const { exactDependencies, exactOptionalDependencies } = await resolveExternalVersions(externalPackages, projectDir);
|
|
162
|
+
const packageJson = generateMinimalPackageJson(unit.name, exactDependencies, exactOptionalDependencies);
|
|
163
|
+
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
164
|
+
await writeFile(exactDependenciesPath, JSON.stringify({
|
|
165
|
+
dependencies: Object.fromEntries(Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b))),
|
|
166
|
+
optionalDependencies: Object.fromEntries(Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b))),
|
|
167
|
+
}, null, 2), 'utf-8');
|
|
168
|
+
// Get bundle size + hashes
|
|
169
|
+
const bundleStat = await stat(bundlePath);
|
|
170
|
+
const bundleContents = await readFile(bundlePath);
|
|
171
|
+
const bundleHash = createHash('sha256').update(bundleContents).digest('hex');
|
|
172
|
+
const exactDependenciesHash = createHash('sha256')
|
|
173
|
+
.update(JSON.stringify({
|
|
174
|
+
dependencies: Object.entries(exactDependencies).sort(([a], [b]) => a.localeCompare(b)),
|
|
175
|
+
optionalDependencies: Object.entries(exactOptionalDependencies).sort(([a], [b]) => a.localeCompare(b)),
|
|
176
|
+
}))
|
|
177
|
+
.digest('hex');
|
|
178
|
+
return {
|
|
179
|
+
unitName: unit.name,
|
|
180
|
+
bundlePath,
|
|
181
|
+
packageJsonPath,
|
|
182
|
+
exactDependenciesPath,
|
|
183
|
+
metafilePath,
|
|
184
|
+
bundleSizeBytes: bundleStat.size,
|
|
185
|
+
bundleHash,
|
|
186
|
+
exactDependenciesHash,
|
|
187
|
+
exactDependencies,
|
|
188
|
+
exactOptionalDependencies,
|
|
189
|
+
};
|
|
259
190
|
}
|
|
260
|
-
return { results, errors };
|
|
261
191
|
}
|
|
@@ -21,12 +21,20 @@ export declare function extractExternalPackages(metafile: Metafile): Set<string>
|
|
|
21
21
|
* Returns null for relative imports or other non-package specifiers.
|
|
22
22
|
*/
|
|
23
23
|
export declare function parsePackageName(specifier: string): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves exact versions for a set of external package names.
|
|
26
|
+
*
|
|
27
|
+
* Shared by both bundler backends: esbuild derives the set from its metafile
|
|
28
|
+
* (`extractExternalPackages`), while the Bun.build backend captures it via a
|
|
29
|
+
* resolve plugin (Bun's metafile does not record external imports).
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveExternalVersions(externalPackages: Set<string>, projectDir: string): Promise<{
|
|
32
|
+
exactDependencies: Record<string, string>;
|
|
33
|
+
exactOptionalDependencies: Record<string, string>;
|
|
34
|
+
}>;
|
|
24
35
|
/**
|
|
25
36
|
* Given an esbuild metafile, extracts all external packages and resolves
|
|
26
37
|
* their versions from the project's dependency files.
|
|
27
|
-
*
|
|
28
|
-
* Returns a record of package name to exact version, suitable for
|
|
29
|
-
* writing into a minimal package.json.
|
|
30
38
|
*/
|
|
31
39
|
export declare function extractDependencies(metafile: Metafile, projectDir: string): Promise<{
|
|
32
40
|
exactDependencies: Record<string, string>;
|
|
@@ -244,14 +244,13 @@ async function resolveVersion(packageName, projectDeps, yarnLockVersions, projec
|
|
|
244
244
|
return null;
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
248
|
-
* their versions from the project's dependency files.
|
|
247
|
+
* Resolves exact versions for a set of external package names.
|
|
249
248
|
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
249
|
+
* Shared by both bundler backends: esbuild derives the set from its metafile
|
|
250
|
+
* (`extractExternalPackages`), while the Bun.build backend captures it via a
|
|
251
|
+
* resolve plugin (Bun's metafile does not record external imports).
|
|
252
252
|
*/
|
|
253
|
-
export async function
|
|
254
|
-
const externalPackages = extractExternalPackages(metafile);
|
|
253
|
+
export async function resolveExternalVersions(externalPackages, projectDir) {
|
|
255
254
|
if (externalPackages.size === 0) {
|
|
256
255
|
return { exactDependencies: {}, exactOptionalDependencies: {} };
|
|
257
256
|
}
|
|
@@ -278,6 +277,13 @@ export async function extractDependencies(metafile, projectDir) {
|
|
|
278
277
|
}
|
|
279
278
|
return { exactDependencies, exactOptionalDependencies };
|
|
280
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Given an esbuild metafile, extracts all external packages and resolves
|
|
282
|
+
* their versions from the project's dependency files.
|
|
283
|
+
*/
|
|
284
|
+
export async function extractDependencies(metafile, projectDir) {
|
|
285
|
+
return resolveExternalVersions(extractExternalPackages(metafile), projectDir);
|
|
286
|
+
}
|
|
281
287
|
/**
|
|
282
288
|
* Generates a minimal package.json content object for a unit bundle.
|
|
283
289
|
*/
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { BaseBundler } from './bundler.js';
|
|
2
|
+
export { NodeBundler } from './node-bundler.js';
|
|
3
|
+
export { BunBundler } from './bun-bundler.js';
|
|
4
|
+
export type { Bundler, BundleUnitsOptions } from './bundler.interface.js';
|
|
5
|
+
export { extractDependencies, extractExternalPackages, resolveExternalVersions, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
|
|
3
6
|
export type { BundleResult, BundleError, BundleOutput, DeploymentUnit, DeploymentUnitRole, } from './types.js';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { BaseBundler } from './bundler.js';
|
|
2
|
+
export { NodeBundler } from './node-bundler.js';
|
|
3
|
+
export { BunBundler } from './bun-bundler.js';
|
|
4
|
+
export { extractDependencies, extractExternalPackages, resolveExternalVersions, parsePackageName, generateMinimalPackageJson, } from './dep-extractor.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node (esbuild) bundler backend.
|
|
3
|
+
*
|
|
4
|
+
* Used when the CLI runs under Node (yarn/npm projects). esbuild resolves deps
|
|
5
|
+
* via `nodePaths` walking up the directory tree, which assumes a flat, hoisted
|
|
6
|
+
* `node_modules` — exactly what yarn/npm produce. For bun's per-workspace
|
|
7
|
+
* symlink layout use `BunBundler` instead (selected in `services.ts`).
|
|
8
|
+
*/
|
|
9
|
+
import { BaseBundler } from './bundler.js';
|
|
10
|
+
import type { CompileInput, CompileResult } from './bundler.interface.js';
|
|
11
|
+
export declare class NodeBundler extends BaseBundler {
|
|
12
|
+
protected compile(input: CompileInput): Promise<CompileResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node (esbuild) bundler backend.
|
|
3
|
+
*
|
|
4
|
+
* Used when the CLI runs under Node (yarn/npm projects). esbuild resolves deps
|
|
5
|
+
* via `nodePaths` walking up the directory tree, which assumes a flat, hoisted
|
|
6
|
+
* `node_modules` — exactly what yarn/npm produce. For bun's per-workspace
|
|
7
|
+
* symlink layout use `BunBundler` instead (selected in `services.ts`).
|
|
8
|
+
*/
|
|
9
|
+
import { build } from 'esbuild';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { extractExternalPackages } from './dep-extractor.js';
|
|
12
|
+
import { BaseBundler } from './bundler.js';
|
|
13
|
+
/**
|
|
14
|
+
* esbuild plugin that stubs gen files / modules not needed by this unit,
|
|
15
|
+
* preventing Node-only modules (e.g. LocalMetaService using fs) from being
|
|
16
|
+
* pulled into serverless worker bundles via dynamic imports.
|
|
17
|
+
*/
|
|
18
|
+
function createDeadModuleStubPlugin(patterns) {
|
|
19
|
+
return {
|
|
20
|
+
name: 'pikku-dead-module-stub',
|
|
21
|
+
setup(build) {
|
|
22
|
+
if (patterns.length === 0)
|
|
23
|
+
return;
|
|
24
|
+
const combined = new RegExp(patterns.map((p) => p.source).join('|'));
|
|
25
|
+
build.onResolve({ filter: combined }, (args) => ({
|
|
26
|
+
path: args.path,
|
|
27
|
+
namespace: 'pikku-stub',
|
|
28
|
+
}));
|
|
29
|
+
build.onLoad({ filter: /.*/, namespace: 'pikku-stub' }, () => ({
|
|
30
|
+
contents: 'export {}',
|
|
31
|
+
loader: 'js',
|
|
32
|
+
}));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export class NodeBundler extends BaseBundler {
|
|
37
|
+
async compile(input) {
|
|
38
|
+
// Resolve node_modules paths up the directory tree for workspace packages.
|
|
39
|
+
const nodePaths = [];
|
|
40
|
+
let dir = input.projectDir;
|
|
41
|
+
while (true) {
|
|
42
|
+
nodePaths.push(join(dir, 'node_modules'));
|
|
43
|
+
const parent = join(dir, '..');
|
|
44
|
+
if (parent === dir)
|
|
45
|
+
break;
|
|
46
|
+
dir = parent;
|
|
47
|
+
}
|
|
48
|
+
const result = await build({
|
|
49
|
+
entryPoints: [input.entryPath],
|
|
50
|
+
bundle: true,
|
|
51
|
+
absWorkingDir: input.projectDir,
|
|
52
|
+
nodePaths,
|
|
53
|
+
platform: input.platform,
|
|
54
|
+
format: input.format,
|
|
55
|
+
banner: input.bannerJs ? { js: input.bannerJs } : undefined,
|
|
56
|
+
metafile: true,
|
|
57
|
+
target: 'es2022',
|
|
58
|
+
outfile: input.bundlePath,
|
|
59
|
+
// Minify every deploy bundle — esbuild output ships straight to the
|
|
60
|
+
// runtime (CF Workers / container), tsc is never the bundler. keepNames
|
|
61
|
+
// preserves Function.name / constructor.name so name-based reflection
|
|
62
|
+
// still works.
|
|
63
|
+
minify: true,
|
|
64
|
+
keepNames: true,
|
|
65
|
+
sourcemap: input.sourcemap,
|
|
66
|
+
logLevel: 'warning',
|
|
67
|
+
loader: { '.ts': 'ts' },
|
|
68
|
+
external: input.externals,
|
|
69
|
+
alias: input.aliases,
|
|
70
|
+
define: input.define,
|
|
71
|
+
plugins: [createDeadModuleStubPlugin(input.deadPatterns)],
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
externalPackages: extractExternalPackages(result.metafile),
|
|
75
|
+
metafileJson: input.emitMetafile
|
|
76
|
+
? JSON.stringify(result.metafile, null, 2)
|
|
77
|
+
: undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|