@workflow/builders 4.0.1-beta.4
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.md +201 -0
- package/README.md +43 -0
- package/dist/apply-swc-transform.d.ts +24 -0
- package/dist/apply-swc-transform.d.ts.map +1 -0
- package/dist/apply-swc-transform.js +38 -0
- package/dist/apply-swc-transform.js.map +1 -0
- package/dist/base-builder.d.ts +131 -0
- package/dist/base-builder.d.ts.map +1 -0
- package/dist/base-builder.js +558 -0
- package/dist/base-builder.js.map +1 -0
- package/dist/config-helpers.d.ts +12 -0
- package/dist/config-helpers.d.ts.map +1 -0
- package/dist/config-helpers.js +16 -0
- package/dist/config-helpers.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +25 -0
- package/dist/constants.js.map +1 -0
- package/dist/discover-entries-esbuild-plugin.d.ts +11 -0
- package/dist/discover-entries-esbuild-plugin.d.ts.map +1 -0
- package/dist/discover-entries-esbuild-plugin.js +84 -0
- package/dist/discover-entries-esbuild-plugin.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/node-module-esbuild-plugin.d.ts +3 -0
- package/dist/node-module-esbuild-plugin.d.ts.map +1 -0
- package/dist/node-module-esbuild-plugin.js +24 -0
- package/dist/node-module-esbuild-plugin.js.map +1 -0
- package/dist/node-module-esbuild-plugin.test.d.ts +2 -0
- package/dist/node-module-esbuild-plugin.test.d.ts.map +1 -0
- package/dist/node-module-esbuild-plugin.test.js +128 -0
- package/dist/node-module-esbuild-plugin.test.js.map +1 -0
- package/dist/standalone.d.ts +8 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +47 -0
- package/dist/standalone.js.map +1 -0
- package/dist/swc-esbuild-plugin.d.ts +12 -0
- package/dist/swc-esbuild-plugin.d.ts.map +1 -0
- package/dist/swc-esbuild-plugin.js +134 -0
- package/dist/swc-esbuild-plugin.js.map +1 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/vercel-build-output-api.d.ts +9 -0
- package/dist/vercel-build-output-api.d.ts.map +1 -0
- package/dist/vercel-build-output-api.js +92 -0
- package/dist/vercel-build-output-api.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queue trigger configuration for workflow step execution.
|
|
3
|
+
* Steps are queued to the __wkf_step_* topic.
|
|
4
|
+
*/
|
|
5
|
+
export const STEP_QUEUE_TRIGGER = {
|
|
6
|
+
type: 'queue/v1beta',
|
|
7
|
+
topic: '__wkf_step_*',
|
|
8
|
+
consumer: 'default',
|
|
9
|
+
maxDeliveries: 64, // Maximum number of delivery attempts (default: 3)
|
|
10
|
+
retryAfterSeconds: 5, // Delay between retries (default: 60)
|
|
11
|
+
initialDelaySeconds: 0, // Initial delay before first delivery (default: 0)
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Queue trigger configuration for workflow orchestration.
|
|
15
|
+
* Workflows are queued to the __wkf_workflow_* topic.
|
|
16
|
+
*/
|
|
17
|
+
export const WORKFLOW_QUEUE_TRIGGER = {
|
|
18
|
+
type: 'queue/v1beta',
|
|
19
|
+
topic: '__wkf_workflow_*',
|
|
20
|
+
consumer: 'default',
|
|
21
|
+
maxDeliveries: 64, // Maximum number of delivery attempts (default: 3)
|
|
22
|
+
retryAfterSeconds: 5, // Delay between retries (default: 60)
|
|
23
|
+
initialDelaySeconds: 0, // Initial delay before first delivery (default: 0)
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,cAAuB;IAC7B,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,SAAS;IACnB,aAAa,EAAE,EAAE,EAAE,mDAAmD;IACtE,iBAAiB,EAAE,CAAC,EAAE,sCAAsC;IAC5D,mBAAmB,EAAE,CAAC,EAAE,mDAAmD;CAC5E,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,cAAuB;IAC7B,KAAK,EAAE,kBAAkB;IACzB,QAAQ,EAAE,SAAS;IACnB,aAAa,EAAE,EAAE,EAAE,mDAAmD;IACtE,iBAAiB,EAAE,CAAC,EAAE,sCAAsC;IAC5D,mBAAmB,EAAE,CAAC,EAAE,mDAAmD;CAC5E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
export declare const jsTsRegex: RegExp;
|
|
3
|
+
export declare const useWorkflowPattern: RegExp;
|
|
4
|
+
export declare const useStepPattern: RegExp;
|
|
5
|
+
export declare const importParents: Map<string, string>;
|
|
6
|
+
export declare function parentHasChild(parent: string, childToFind: string): boolean;
|
|
7
|
+
export declare function createDiscoverEntriesPlugin(state: {
|
|
8
|
+
discoveredSteps: string[];
|
|
9
|
+
discoveredWorkflows: string[];
|
|
10
|
+
}): Plugin;
|
|
11
|
+
//# sourceMappingURL=discover-entries-esbuild-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-entries-esbuild-plugin.d.ts","sourceRoot":"","sources":["../src/discover-entries-esbuild-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKtC,eAAO,MAAM,SAAS,QAA+B,CAAC;AAGtD,eAAO,MAAM,kBAAkB,QAAoC,CAAC;AACpE,eAAO,MAAM,cAAc,QAAgC,CAAC;AAG5D,eAAO,MAAM,aAAa,qBAA4B,CAAC;AAKvD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAsBjE;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,GAAG,MAAM,CAyDT"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import enhancedResolveOriginal from 'enhanced-resolve';
|
|
4
|
+
import { applySwcTransform } from './apply-swc-transform.js';
|
|
5
|
+
const enhancedResolve = promisify(enhancedResolveOriginal);
|
|
6
|
+
export const jsTsRegex = /\.(ts|tsx|js|jsx|mjs|cjs)$/;
|
|
7
|
+
// Matches: 'use workflow'; "use workflow"; 'use step'; "use step"; at line start with optional whitespace
|
|
8
|
+
export const useWorkflowPattern = /^\s*(['"])use workflow\1;?\s*$/m;
|
|
9
|
+
export const useStepPattern = /^\s*(['"])use step\1;?\s*$/m;
|
|
10
|
+
// parent -> child relationship
|
|
11
|
+
export const importParents = new Map();
|
|
12
|
+
// check if a parent has a child in it's import chain
|
|
13
|
+
// e.g. if a dependency needs to be bundled because it has
|
|
14
|
+
// a 'use workflow/'use step' directive in it
|
|
15
|
+
export function parentHasChild(parent, childToFind) {
|
|
16
|
+
let child;
|
|
17
|
+
let currentParent = parent;
|
|
18
|
+
const visited = new Set();
|
|
19
|
+
do {
|
|
20
|
+
if (currentParent) {
|
|
21
|
+
// Detect circular imports to prevent infinite loop
|
|
22
|
+
if (visited.has(currentParent)) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
visited.add(currentParent);
|
|
26
|
+
child = importParents.get(currentParent);
|
|
27
|
+
}
|
|
28
|
+
if (child === childToFind) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
currentParent = child;
|
|
32
|
+
} while (child && currentParent);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
export function createDiscoverEntriesPlugin(state) {
|
|
36
|
+
return {
|
|
37
|
+
name: 'discover-entries-esbuild-plugin',
|
|
38
|
+
setup(build) {
|
|
39
|
+
build.onResolve({ filter: jsTsRegex }, async (args) => {
|
|
40
|
+
try {
|
|
41
|
+
const resolved = await enhancedResolve(args.resolveDir, args.path);
|
|
42
|
+
if (resolved) {
|
|
43
|
+
importParents.set(args.importer, resolved);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (_) { }
|
|
47
|
+
return null;
|
|
48
|
+
});
|
|
49
|
+
// Handle TypeScript and JavaScript files
|
|
50
|
+
build.onLoad({ filter: jsTsRegex }, async (args) => {
|
|
51
|
+
try {
|
|
52
|
+
// Determine the loader based on the output
|
|
53
|
+
let loader = 'js';
|
|
54
|
+
const isTypeScript = args.path.endsWith('.ts') || args.path.endsWith('.tsx');
|
|
55
|
+
if (!isTypeScript && args.path.endsWith('.jsx')) {
|
|
56
|
+
loader = 'jsx';
|
|
57
|
+
}
|
|
58
|
+
const source = await readFile(args.path, 'utf8');
|
|
59
|
+
const hasUseWorkflow = useWorkflowPattern.test(source);
|
|
60
|
+
const hasUseStep = useStepPattern.test(source);
|
|
61
|
+
if (hasUseWorkflow) {
|
|
62
|
+
state.discoveredWorkflows.push(args.path);
|
|
63
|
+
}
|
|
64
|
+
if (hasUseStep) {
|
|
65
|
+
state.discoveredSteps.push(args.path);
|
|
66
|
+
}
|
|
67
|
+
const { code: transformedCode } = await applySwcTransform(args.path, source, false);
|
|
68
|
+
return {
|
|
69
|
+
contents: transformedCode,
|
|
70
|
+
loader,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (_) {
|
|
74
|
+
// ignore trace errors during discover phase
|
|
75
|
+
return {
|
|
76
|
+
contents: '',
|
|
77
|
+
loader: 'js',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=discover-entries-esbuild-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-entries-esbuild-plugin.js","sourceRoot":"","sources":["../src/discover-entries-esbuild-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,uBAAuB,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,eAAe,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,SAAS,GAAG,4BAA4B,CAAC;AAEtD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,kBAAkB,GAAG,iCAAiC,CAAC;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAE5D,+BAA+B;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEvD,qDAAqD;AACrD,0DAA0D;AAC1D,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,IAAI,KAAyB,CAAC;IAC9B,IAAI,aAAa,GAAuB,MAAM,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,GAAG,CAAC;QACF,IAAI,aAAa,EAAE,CAAC;YAClB,mDAAmD;YACnD,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC/B,MAAM;YACR,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC3B,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;YAC1B,OAAO,IAAI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BAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBACvD,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAE/C,IAAI,cAAc,EAAE,CAAC;wBACnB,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC5C,CAAC;oBAED,IAAI,UAAU,EAAE,CAAC;wBACf,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACxC,CAAC;oBAED,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,GAAG,MAAM,iBAAiB,CACvD,IAAI,CAAC,IAAI,EACT,MAAM,EACN,KAAK,CACN,CAAC;oBAEF,OAAO;wBACL,QAAQ,EAAE,eAAe;wBACzB,MAAM;qBACP,CAAC;gBACJ,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,4CAA4C;oBAC5C,OAAO;wBACL,QAAQ,EAAE,EAAE;wBACZ,MAAM,EAAE,IAAI;qBACb,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type { WorkflowManifest } from './apply-swc-transform.js';
|
|
2
|
+
export { applySwcTransform } from './apply-swc-transform.js';
|
|
3
|
+
export { BaseBuilder } from './base-builder.js';
|
|
4
|
+
export { createBaseBuilderConfig } from './config-helpers.js';
|
|
5
|
+
export { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from './constants.js';
|
|
6
|
+
export { createDiscoverEntriesPlugin } from './discover-entries-esbuild-plugin.js';
|
|
7
|
+
export { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
|
|
8
|
+
export { StandaloneBuilder } from './standalone.js';
|
|
9
|
+
export { createSwcPlugin } from './swc-esbuild-plugin.js';
|
|
10
|
+
export type { BuildTarget, NextConfig, StandaloneConfig, SvelteKitConfig, VercelBuildOutputConfig, WorkflowConfig, } from './types.js';
|
|
11
|
+
export { isValidBuildTarget, validBuildTargets, } from './types.js';
|
|
12
|
+
export { VercelBuildOutputAPIBuilder } from './vercel-build-output-api.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { applySwcTransform } from './apply-swc-transform.js';
|
|
2
|
+
export { BaseBuilder } from './base-builder.js';
|
|
3
|
+
export { createBaseBuilderConfig } from './config-helpers.js';
|
|
4
|
+
export { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from './constants.js';
|
|
5
|
+
export { createDiscoverEntriesPlugin } from './discover-entries-esbuild-plugin.js';
|
|
6
|
+
export { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
|
|
7
|
+
export { StandaloneBuilder } from './standalone.js';
|
|
8
|
+
export { createSwcPlugin } from './swc-esbuild-plugin.js';
|
|
9
|
+
export { isValidBuildTarget, validBuildTargets, } from './types.js';
|
|
10
|
+
export { VercelBuildOutputAPIBuilder } from './vercel-build-output-api.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAS1D,OAAO,EACL,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-module-esbuild-plugin.d.ts","sourceRoot":"","sources":["../src/node-module-esbuild-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAIxC,wBAAgB,2BAA2B,IAAI,OAAO,CAAC,MAAM,CAmB5D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ERROR_SLUGS } from '@workflow/errors';
|
|
2
|
+
import builtinModules from 'builtin-modules';
|
|
3
|
+
const nodeModulesRegex = new RegExp(`^(${builtinModules.join('|')})`);
|
|
4
|
+
export function createNodeModuleErrorPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'workflow-node-module-error',
|
|
7
|
+
setup(build) {
|
|
8
|
+
build.onResolve({ filter: nodeModulesRegex }, (args) => {
|
|
9
|
+
// Ignore if the import is coming from a node_modules folder
|
|
10
|
+
if (args.importer.includes('node_modules'))
|
|
11
|
+
return null;
|
|
12
|
+
return {
|
|
13
|
+
path: args.path,
|
|
14
|
+
errors: [
|
|
15
|
+
{
|
|
16
|
+
text: `Cannot use Node.js module "${args.path}" in workflow functions. Move this module to a step function.\n\nLearn more: https://useworkflow.dev/err/${ERROR_SLUGS.NODE_JS_MODULE_IN_WORKFLOW}`,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=node-module-esbuild-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-module-esbuild-plugin.js","sourceRoot":"","sources":["../src/node-module-esbuild-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAG7C,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,KAAK,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtE,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;gBACrD,4DAA4D;gBAC5D,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAExD,OAAO;oBACL,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE;wBACN;4BACE,IAAI,EAAE,8BAA8B,IAAI,CAAC,IAAI,4GAA4G,WAAW,CAAC,0BAA0B,EAAE;yBAClM;qBACF;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-module-esbuild-plugin.test.d.ts","sourceRoot":"","sources":["../src/node-module-esbuild-plugin.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
|
|
4
|
+
describe('workflow-node-module-error plugin', () => {
|
|
5
|
+
it('should error on fs import', async () => {
|
|
6
|
+
const testCode = `
|
|
7
|
+
import { readFile } from "fs";
|
|
8
|
+
export function workflow() {
|
|
9
|
+
return readFile("test.txt");
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
await expect(esbuild.build({
|
|
13
|
+
stdin: {
|
|
14
|
+
contents: testCode,
|
|
15
|
+
resolveDir: process.cwd(),
|
|
16
|
+
sourcefile: 'test-workflow.ts',
|
|
17
|
+
loader: 'ts',
|
|
18
|
+
},
|
|
19
|
+
bundle: true,
|
|
20
|
+
write: false,
|
|
21
|
+
platform: 'neutral',
|
|
22
|
+
plugins: [createNodeModuleErrorPlugin()],
|
|
23
|
+
logLevel: 'silent',
|
|
24
|
+
})).rejects.toThrow(/Cannot use Node\.js module "fs"/);
|
|
25
|
+
});
|
|
26
|
+
it('should error on path import', async () => {
|
|
27
|
+
const testCode = `
|
|
28
|
+
import { join } from "path";
|
|
29
|
+
export function workflow() {
|
|
30
|
+
return join("a", "b");
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
await expect(esbuild.build({
|
|
34
|
+
stdin: {
|
|
35
|
+
contents: testCode,
|
|
36
|
+
resolveDir: process.cwd(),
|
|
37
|
+
sourcefile: 'test-workflow.ts',
|
|
38
|
+
loader: 'ts',
|
|
39
|
+
},
|
|
40
|
+
format: 'cjs',
|
|
41
|
+
bundle: true,
|
|
42
|
+
write: false,
|
|
43
|
+
platform: 'neutral',
|
|
44
|
+
plugins: [createNodeModuleErrorPlugin()],
|
|
45
|
+
logLevel: 'silent',
|
|
46
|
+
})).rejects.toThrow(/Cannot use Node\.js module "path"/);
|
|
47
|
+
});
|
|
48
|
+
it('should error on node: prefixed imports', async () => {
|
|
49
|
+
const testCode = `
|
|
50
|
+
import { readFile } from "node:fs";
|
|
51
|
+
export function workflow() {
|
|
52
|
+
return readFile;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
await expect(esbuild.build({
|
|
56
|
+
stdin: {
|
|
57
|
+
contents: testCode,
|
|
58
|
+
resolveDir: process.cwd(),
|
|
59
|
+
sourcefile: 'test-workflow.ts',
|
|
60
|
+
loader: 'ts',
|
|
61
|
+
},
|
|
62
|
+
bundle: true,
|
|
63
|
+
write: false,
|
|
64
|
+
platform: 'neutral',
|
|
65
|
+
format: 'cjs',
|
|
66
|
+
plugins: [createNodeModuleErrorPlugin()],
|
|
67
|
+
logLevel: 'silent',
|
|
68
|
+
})).rejects.toThrow(/Cannot use Node\.js module/);
|
|
69
|
+
});
|
|
70
|
+
it('should error on multiple Node.js imports', async () => {
|
|
71
|
+
const testCode = `
|
|
72
|
+
import { readFile } from "fs";
|
|
73
|
+
import { join } from "path";
|
|
74
|
+
export function workflow() {
|
|
75
|
+
return readFile(join("a", "b"));
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
const result = esbuild.build({
|
|
79
|
+
stdin: {
|
|
80
|
+
contents: testCode,
|
|
81
|
+
resolveDir: process.cwd(),
|
|
82
|
+
sourcefile: 'test-workflow.ts',
|
|
83
|
+
loader: 'ts',
|
|
84
|
+
},
|
|
85
|
+
format: 'cjs',
|
|
86
|
+
bundle: true,
|
|
87
|
+
write: false,
|
|
88
|
+
platform: 'neutral',
|
|
89
|
+
plugins: [createNodeModuleErrorPlugin()],
|
|
90
|
+
logLevel: 'silent',
|
|
91
|
+
});
|
|
92
|
+
await expect(result).rejects.toThrow();
|
|
93
|
+
// Verify we get errors for both imports
|
|
94
|
+
try {
|
|
95
|
+
await result;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
expect(error.message).toMatch(/fs/);
|
|
99
|
+
expect(error.message).toMatch(/path/);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
it('should allow non-Node.js npm package imports', async () => {
|
|
103
|
+
const testCode = `
|
|
104
|
+
// This should NOT error - it's not a built-in Node.js module
|
|
105
|
+
import { someFunction } from "some-random-package";
|
|
106
|
+
export function workflow() {
|
|
107
|
+
return "ok";
|
|
108
|
+
}
|
|
109
|
+
`;
|
|
110
|
+
// This will fail because the package doesn't exist, but it shouldn't
|
|
111
|
+
// fail with our plugin's error message
|
|
112
|
+
await expect(esbuild.build({
|
|
113
|
+
stdin: {
|
|
114
|
+
contents: testCode,
|
|
115
|
+
resolveDir: process.cwd(),
|
|
116
|
+
sourcefile: 'test-workflow.ts',
|
|
117
|
+
loader: 'ts',
|
|
118
|
+
},
|
|
119
|
+
bundle: true,
|
|
120
|
+
write: false,
|
|
121
|
+
platform: 'neutral',
|
|
122
|
+
plugins: [createNodeModuleErrorPlugin()],
|
|
123
|
+
logLevel: 'silent',
|
|
124
|
+
external: ['some-random-package'], // Mark as external so it doesn't fail resolution
|
|
125
|
+
})).resolves.toBeDefined();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=node-module-esbuild-plugin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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,wCAAwC;QACxC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,QAAQ,GAAG;;;;;;KAMhB,CAAC;QAEF,qEAAqE;QACrE,uCAAuC;QACvC,MAAM,MAAM,CACV,OAAO,CAAC,KAAK,CAAC;YACZ,KAAK,EAAE;gBACL,QAAQ,EAAE,QAAQ;gBAClB,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE;gBACzB,UAAU,EAAE,kBAAkB;gBAC9B,MAAM,EAAE,IAAI;aACb;YACD,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,SAAS;YACnB,OAAO,EAAE,CAAC,2BAA2B,EAAE,CAAC;YACxC,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,CAAC,qBAAqB,CAAC,EAAE,iDAAiD;SACrF,CAAC,CACH,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseBuilder } from './base-builder.js';
|
|
2
|
+
export declare class StandaloneBuilder extends BaseBuilder {
|
|
3
|
+
build(): Promise<void>;
|
|
4
|
+
private buildStepsBundle;
|
|
5
|
+
private buildWorkflowsBundle;
|
|
6
|
+
private buildWebhookFunction;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=standalone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,WAAW;IAC1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAgBd,gBAAgB;YAsBhB,oBAAoB;YA2BpB,oBAAoB;CAUnC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BaseBuilder } from './base-builder.js';
|
|
2
|
+
export class StandaloneBuilder extends BaseBuilder {
|
|
3
|
+
async build() {
|
|
4
|
+
const inputFiles = await this.getInputFiles();
|
|
5
|
+
const tsConfig = await this.getTsConfigOptions();
|
|
6
|
+
const options = {
|
|
7
|
+
inputFiles,
|
|
8
|
+
tsBaseUrl: tsConfig.baseUrl,
|
|
9
|
+
tsPaths: tsConfig.paths,
|
|
10
|
+
};
|
|
11
|
+
await this.buildStepsBundle(options);
|
|
12
|
+
await this.buildWorkflowsBundle(options);
|
|
13
|
+
await this.buildWebhookFunction();
|
|
14
|
+
await this.createClientLibrary();
|
|
15
|
+
}
|
|
16
|
+
async buildStepsBundle({ inputFiles, tsPaths, tsBaseUrl, }) {
|
|
17
|
+
console.log('Creating steps bundle at', this.config.stepsBundlePath);
|
|
18
|
+
const stepsBundlePath = this.resolvePath(this.config.stepsBundlePath);
|
|
19
|
+
await this.ensureDirectory(stepsBundlePath);
|
|
20
|
+
await this.createStepsBundle({
|
|
21
|
+
outfile: stepsBundlePath,
|
|
22
|
+
inputFiles,
|
|
23
|
+
tsBaseUrl,
|
|
24
|
+
tsPaths,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async buildWorkflowsBundle({ inputFiles, tsPaths, tsBaseUrl, }) {
|
|
28
|
+
console.log('Creating workflows bundle at', this.config.workflowsBundlePath);
|
|
29
|
+
const workflowBundlePath = this.resolvePath(this.config.workflowsBundlePath);
|
|
30
|
+
await this.ensureDirectory(workflowBundlePath);
|
|
31
|
+
await this.createWorkflowsBundle({
|
|
32
|
+
outfile: workflowBundlePath,
|
|
33
|
+
inputFiles,
|
|
34
|
+
tsBaseUrl,
|
|
35
|
+
tsPaths,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async buildWebhookFunction() {
|
|
39
|
+
console.log('Creating webhook bundle at', this.config.webhookBundlePath);
|
|
40
|
+
const webhookBundlePath = this.resolvePath(this.config.webhookBundlePath);
|
|
41
|
+
await this.ensureDirectory(webhookBundlePath);
|
|
42
|
+
await this.createWebhookBundle({
|
|
43
|
+
outfile: webhookBundlePath,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=standalone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone.js","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAChD,KAAK,CAAC,KAAK;QACT,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAEjD,MAAM,OAAO,GAAG;YACd,UAAU;YACV,SAAS,EAAE,QAAQ,CAAC,OAAO;YAC3B,OAAO,EAAE,QAAQ,CAAC,KAAK;SACxB,CAAC;QACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACzC,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAElC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;IACnC,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,EAC7B,UAAU,EACV,OAAO,EACP,SAAS,GAKV;QACC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAErE,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACtE,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QAE5C,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,OAAO,EAAE,eAAe;YACxB,UAAU;YACV,SAAS;YACT,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,EACjC,UAAU,EACV,OAAO,EACP,SAAS,GAKV;QACC,OAAO,CAAC,GAAG,CACT,8BAA8B,EAC9B,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAChC,CAAC;QAEF,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,CACzC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAChC,CAAC;QACF,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAE/C,MAAM,IAAI,CAAC,qBAAqB,CAAC;YAC/B,OAAO,EAAE,kBAAkB;YAC3B,UAAU;YACV,SAAS;YACT,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,oBAAoB;QAChC,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAEzE,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC1E,MAAM,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;QAE9C,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC7B,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
import { type WorkflowManifest } from './apply-swc-transform.js';
|
|
3
|
+
export interface SwcPluginOptions {
|
|
4
|
+
mode: 'step' | 'workflow' | 'client';
|
|
5
|
+
entriesToBundle?: string[];
|
|
6
|
+
outdir?: string;
|
|
7
|
+
tsPaths?: Record<string, string[]>;
|
|
8
|
+
tsBaseUrl?: string;
|
|
9
|
+
workflowManifest?: WorkflowManifest;
|
|
10
|
+
}
|
|
11
|
+
export declare function createSwcPlugin(options: SwcPluginOptions): Plugin;
|
|
12
|
+
//# sourceMappingURL=swc-esbuild-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc-esbuild-plugin.d.ts","sourceRoot":"","sources":["../src/swc-esbuild-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAMlC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AA2BD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAsIjE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import enhancedResolveOrig from 'enhanced-resolve';
|
|
3
|
+
import { relative } from 'path';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import { applySwcTransform, } from './apply-swc-transform.js';
|
|
6
|
+
import { jsTsRegex, parentHasChild, } from './discover-entries-esbuild-plugin.js';
|
|
7
|
+
const NODE_RESOLVE_OPTIONS = {
|
|
8
|
+
dependencyType: 'commonjs',
|
|
9
|
+
modules: ['node_modules'],
|
|
10
|
+
exportsFields: ['exports'],
|
|
11
|
+
importsFields: ['imports'],
|
|
12
|
+
conditionNames: ['node', 'require'],
|
|
13
|
+
descriptionFiles: ['package.json'],
|
|
14
|
+
extensions: ['.ts', '.mts', '.cjs', '.js', '.json', '.node'],
|
|
15
|
+
enforceExtensions: false,
|
|
16
|
+
symlinks: true,
|
|
17
|
+
mainFields: ['main'],
|
|
18
|
+
mainFiles: ['index'],
|
|
19
|
+
roots: [],
|
|
20
|
+
fullySpecified: false,
|
|
21
|
+
preferRelative: false,
|
|
22
|
+
preferAbsolute: false,
|
|
23
|
+
restrictions: [],
|
|
24
|
+
};
|
|
25
|
+
const NODE_ESM_RESOLVE_OPTIONS = {
|
|
26
|
+
...NODE_RESOLVE_OPTIONS,
|
|
27
|
+
dependencyType: 'esm',
|
|
28
|
+
conditionNames: ['node', 'import'],
|
|
29
|
+
};
|
|
30
|
+
export function createSwcPlugin(options) {
|
|
31
|
+
return {
|
|
32
|
+
name: 'swc-workflow-plugin',
|
|
33
|
+
setup(build) {
|
|
34
|
+
// everything is external unless explicitly configured
|
|
35
|
+
// to be bundled
|
|
36
|
+
const cjsResolver = promisify(enhancedResolveOrig.create(NODE_RESOLVE_OPTIONS));
|
|
37
|
+
const esmResolver = promisify(enhancedResolveOrig.create(NODE_ESM_RESOLVE_OPTIONS));
|
|
38
|
+
const enhancedResolve = async (context, path) => {
|
|
39
|
+
try {
|
|
40
|
+
return await esmResolver(context, path);
|
|
41
|
+
}
|
|
42
|
+
catch (_) {
|
|
43
|
+
return cjsResolver(context, path);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
47
|
+
if (!options.entriesToBundle) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
let resolvedPath = args.path;
|
|
52
|
+
// handle local imports e.g. ./hello or ../another
|
|
53
|
+
if (args.path.startsWith('.')) {
|
|
54
|
+
resolvedPath = await enhancedResolve(args.resolveDir, args.path);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resolvedPath = await enhancedResolve(
|
|
58
|
+
// `args.resolveDir` is not used here to ensure we only
|
|
59
|
+
// externalize packages that can be resolved in the
|
|
60
|
+
// project's working directory e.g. a nested dep can't
|
|
61
|
+
// be externalized as we won't be able to resolve it once
|
|
62
|
+
// it's parent has been bundled
|
|
63
|
+
build.initialOptions.absWorkingDir || process.cwd(), args.path);
|
|
64
|
+
}
|
|
65
|
+
if (!resolvedPath)
|
|
66
|
+
return null;
|
|
67
|
+
for (const entryToBundle of options.entriesToBundle) {
|
|
68
|
+
if (resolvedPath === entryToBundle) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// if the current entry imports a child that needs
|
|
72
|
+
// to be bundled then it needs to also be bundled so
|
|
73
|
+
// that the child can have our transform applied
|
|
74
|
+
if (parentHasChild(resolvedPath, entryToBundle)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const isFilePath = args.path.startsWith('.') || args.path.startsWith('/');
|
|
79
|
+
return {
|
|
80
|
+
external: true,
|
|
81
|
+
path: isFilePath
|
|
82
|
+
? relative(options.outdir || '', resolvedPath)
|
|
83
|
+
: args.path,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (_) { }
|
|
87
|
+
return null;
|
|
88
|
+
});
|
|
89
|
+
// Handle TypeScript and JavaScript files
|
|
90
|
+
build.onLoad({ filter: jsTsRegex }, async (args) => {
|
|
91
|
+
// Determine if this is a TypeScript file
|
|
92
|
+
const isTypeScript = args.path.endsWith('.ts') || args.path.endsWith('.tsx');
|
|
93
|
+
try {
|
|
94
|
+
// Determine the loader based on the output
|
|
95
|
+
let loader = 'js';
|
|
96
|
+
if (!isTypeScript && args.path.endsWith('.jsx')) {
|
|
97
|
+
loader = 'jsx';
|
|
98
|
+
}
|
|
99
|
+
const source = await readFile(args.path, 'utf8');
|
|
100
|
+
const { code: transformedCode, workflowManifest } = await applySwcTransform(args.path, source, options.mode,
|
|
101
|
+
// we need to provide the tsconfig/jsconfig
|
|
102
|
+
// alias via swc so that we can resolve them
|
|
103
|
+
// with our custom resolve logic
|
|
104
|
+
{
|
|
105
|
+
paths: options.tsPaths,
|
|
106
|
+
baseUrl: options.tsBaseUrl,
|
|
107
|
+
});
|
|
108
|
+
if (!options.workflowManifest) {
|
|
109
|
+
options.workflowManifest = {};
|
|
110
|
+
}
|
|
111
|
+
options.workflowManifest.workflows = Object.assign(options.workflowManifest.workflows || {}, workflowManifest.workflows);
|
|
112
|
+
options.workflowManifest.steps = Object.assign(options.workflowManifest.steps || {}, workflowManifest.steps);
|
|
113
|
+
return {
|
|
114
|
+
contents: transformedCode,
|
|
115
|
+
loader,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
120
|
+
console.error(`❌ SWC transform error in ${args.path}:`, errorMessage);
|
|
121
|
+
return {
|
|
122
|
+
errors: [
|
|
123
|
+
{
|
|
124
|
+
text: `SWC transform failed: ${errorMessage}`,
|
|
125
|
+
location: { file: args.path, line: 0, column: 0 },
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=swc-esbuild-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc-esbuild-plugin.js","sourceRoot":"","sources":["../src/swc-esbuild-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,mBAAmB,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,SAAS,E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AAC,OAAO;wBACtB,OAAO,EAAE,OAAO,CAAC,SAAS;qBAC3B,CACF,CAAC;oBAEJ,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;wBAC9B,OAAO,CAAC,gBAAgB,GAAG,EAAE,CAAC;oBAChC,CAAC;oBACD,OAAO,CAAC,gBAAgB,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAChD,OAAO,CAAC,gBAAgB,CAAC,SAAS,IAAI,EAAE,EACxC,gBAAgB,CAAC,SAAS,CAC3B,CAAC;oBACF,OAAO,CAAC,gBAAgB,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAC5C,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE,EACpC,gBAAgB,CAAC,KAAK,CACvB,CAAC;oBAEF,OAAO;wBACL,QAAQ,EAAE,eAAe;wBACzB,MAAM;qBACP,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACzD,OAAO,CAAC,KAAK,CACX,4BAA4B,IAAI,CAAC,IAAI,GAAG,EACxC,YAAY,CACb,CAAC;oBACF,OAAO;wBACL,MAAM,EAAE;4BACN;gCACE,IAAI,EAAE,yBAAyB,YAAY,EAAE;gCAC7C,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;6BAClD;yBACF;qBACF,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const validBuildTargets: readonly ["standalone", "vercel-build-output-api", "next", "sveltekit"];
|
|
2
|
+
export type BuildTarget = (typeof validBuildTargets)[number];
|
|
3
|
+
/**
|
|
4
|
+
* Common configuration options shared across all builder types.
|
|
5
|
+
*/
|
|
6
|
+
interface BaseWorkflowConfig {
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
dirs: string[];
|
|
9
|
+
workingDir: string;
|
|
10
|
+
clientBundlePath?: string;
|
|
11
|
+
externalPackages?: string[];
|
|
12
|
+
workflowManifestPath?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for standalone (CLI-based) builds.
|
|
16
|
+
*/
|
|
17
|
+
export interface StandaloneConfig extends BaseWorkflowConfig {
|
|
18
|
+
buildTarget: 'standalone';
|
|
19
|
+
stepsBundlePath: string;
|
|
20
|
+
workflowsBundlePath: string;
|
|
21
|
+
webhookBundlePath: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for Vercel Build Output API builds.
|
|
25
|
+
*/
|
|
26
|
+
export interface VercelBuildOutputConfig extends BaseWorkflowConfig {
|
|
27
|
+
buildTarget: 'vercel-build-output-api';
|
|
28
|
+
stepsBundlePath: string;
|
|
29
|
+
workflowsBundlePath: string;
|
|
30
|
+
webhookBundlePath: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for Next.js builds.
|
|
34
|
+
*/
|
|
35
|
+
export interface NextConfig extends BaseWorkflowConfig {
|
|
36
|
+
buildTarget: 'next';
|
|
37
|
+
stepsBundlePath: string;
|
|
38
|
+
workflowsBundlePath: string;
|
|
39
|
+
webhookBundlePath: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for SvelteKit builds.
|
|
43
|
+
*/
|
|
44
|
+
export interface SvelteKitConfig extends BaseWorkflowConfig {
|
|
45
|
+
buildTarget: 'sveltekit';
|
|
46
|
+
stepsBundlePath: string;
|
|
47
|
+
workflowsBundlePath: string;
|
|
48
|
+
webhookBundlePath: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Discriminated union of all builder configuration types.
|
|
52
|
+
*/
|
|
53
|
+
export type WorkflowConfig = StandaloneConfig | VercelBuildOutputConfig | NextConfig | SvelteKitConfig;
|
|
54
|
+
export declare function isValidBuildTarget(target: string | undefined): target is BuildTarget;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|