@workflow/next 4.0.1-beta.5 → 4.0.1-beta.50
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 -21
- package/dist/builder.d.ts +2 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +390 -0
- package/dist/builder.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -11
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +125 -8
- package/dist/loader.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/swc-cache.d.ts +8 -0
- package/dist/swc-cache.d.ts.map +1 -0
- package/dist/swc-cache.js +53 -0
- package/dist/swc-cache.js.map +1 -0
- package/docs/api-reference/index.mdx +14 -0
- package/docs/api-reference/with-workflow.mdx +52 -0
- package/docs/next.mdx +279 -0
- package/package.json +16 -10
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMvC,wBAAgB,YAAY,CAC1B,cAAc,EACV,UAAU,GACV,CAAC,CACC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,KAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,EAC7B,EACE,SAAS,GACV,GAAE;IACD,SAAS,CAAC,EAAE;QACV,KAAK,CAAC,EAAE;YACN,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;CACE,IAkBJ,OAAO,MAAM,EACb,KAAK;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,yBAyHrC"}
|
package/dist/index.js
CHANGED
|
@@ -4,15 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.withWorkflow = withWorkflow;
|
|
7
|
-
const
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const semver_1 = __importDefault(require("semver"));
|
|
9
|
+
const builder_js_1 = require("./builder.js");
|
|
10
|
+
const swc_cache_js_1 = require("./swc-cache.js");
|
|
9
11
|
function withWorkflow(nextConfigOrFn, { workflows, } = {}) {
|
|
10
12
|
if (!process.env.VERCEL_DEPLOYMENT_ID) {
|
|
11
13
|
if (!process.env.WORKFLOW_TARGET_WORLD) {
|
|
12
|
-
process.env.WORKFLOW_TARGET_WORLD = '
|
|
13
|
-
process.env.
|
|
14
|
+
process.env.WORKFLOW_TARGET_WORLD = 'local';
|
|
15
|
+
process.env.WORKFLOW_LOCAL_DATA_DIR = '.next/workflow-data';
|
|
14
16
|
}
|
|
15
|
-
const maybePort = workflows?.
|
|
17
|
+
const maybePort = workflows?.local?.port;
|
|
16
18
|
if (maybePort) {
|
|
17
19
|
process.env.PORT = maybePort.toString();
|
|
18
20
|
}
|
|
@@ -43,16 +45,30 @@ function withWorkflow(nextConfigOrFn, { workflows, } = {}) {
|
|
|
43
45
|
const existingRules = nextConfig.turbopack.rules;
|
|
44
46
|
const nextVersion = require('next/package.json').version;
|
|
45
47
|
const supportsTurboCondition = semver_1.default.gte(nextVersion, 'v16.0.0');
|
|
46
|
-
for (const key of [
|
|
48
|
+
for (const key of [
|
|
49
|
+
'*.tsx',
|
|
50
|
+
'*.ts',
|
|
51
|
+
'*.jsx',
|
|
52
|
+
'*.js',
|
|
53
|
+
'*.mjs',
|
|
54
|
+
'*.mts',
|
|
55
|
+
'*.cjs',
|
|
56
|
+
'*.cts',
|
|
57
|
+
]) {
|
|
47
58
|
nextConfig.turbopack.rules[key] = {
|
|
48
59
|
...(supportsTurboCondition
|
|
49
60
|
? {
|
|
50
61
|
condition: {
|
|
51
|
-
|
|
52
|
-
any
|
|
53
|
-
|
|
62
|
+
// Use 'all' to combine: must match content AND must NOT be in generated path
|
|
63
|
+
// Merge with any existing 'all' conditions from user config
|
|
64
|
+
all: [
|
|
65
|
+
...(existingRules[key]?.condition?.all || []),
|
|
66
|
+
// Exclude generated workflow route files from transformation
|
|
67
|
+
{ not: { path: /[/\\]\.well-known[/\\]workflow[/\\]/ } },
|
|
68
|
+
// Match files with workflow directives or custom serialization patterns
|
|
69
|
+
// Uses backreferences (\2, \3) to ensure matching quote types
|
|
54
70
|
{
|
|
55
|
-
content: /(use workflow|use step)/,
|
|
71
|
+
content: /(use workflow|use step|from\s+(['"])@workflow\/serde\2|Symbol\.for\s*\(\s*(['"])workflow-(?:serialize|deserialize)\3\s*\))/,
|
|
56
72
|
},
|
|
57
73
|
],
|
|
58
74
|
},
|
|
@@ -85,8 +101,12 @@ function withWorkflow(nextConfigOrFn, { workflows, } = {}) {
|
|
|
85
101
|
// as Next.js uses child processes for different builds
|
|
86
102
|
if (!process.env.WORKFLOW_NEXT_PRIVATE_BUILT &&
|
|
87
103
|
phase !== 'phase-production-server') {
|
|
104
|
+
// Check swc-plugin build hash and invalidate cache if changed
|
|
105
|
+
const distDir = path_1.default.resolve(process.cwd(), nextConfig.distDir || '.next');
|
|
106
|
+
(0, swc_cache_js_1.maybeInvalidateCacheOnSwcChange)(distDir);
|
|
88
107
|
const shouldWatch = process.env.NODE_ENV === 'development';
|
|
89
|
-
const
|
|
108
|
+
const NextBuilder = await (0, builder_js_1.getNextBuilder)();
|
|
109
|
+
const workflowBuilder = new NextBuilder({
|
|
90
110
|
watch: shouldWatch,
|
|
91
111
|
// discover workflows from pages/app entries
|
|
92
112
|
dirs: ['pages', 'app', 'src/pages', 'src/app'],
|
|
@@ -96,7 +116,12 @@ function withWorkflow(nextConfigOrFn, { workflows, } = {}) {
|
|
|
96
116
|
stepsBundlePath: '', // not used in base
|
|
97
117
|
webhookBundlePath: '', // node used in base
|
|
98
118
|
externalPackages: [
|
|
99
|
-
|
|
119
|
+
// server-only and client-only are pseudo-packages handled by Next.js
|
|
120
|
+
// during its build process. We mark them as external to prevent esbuild
|
|
121
|
+
// from failing when bundling code that imports them.
|
|
122
|
+
// See: https://nextjs.org/docs/app/getting-started/server-and-client-components
|
|
123
|
+
'server-only',
|
|
124
|
+
'client-only',
|
|
100
125
|
...(nextConfig.serverExternalPackages || []),
|
|
101
126
|
],
|
|
102
127
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAMA,oCA4JC;AAjKD,gDAAwB;AACxB,oDAA4B;AAC5B,6CAA8C;AAC9C,iDAAiE;AAEjE,SAAgB,YAAY,CAC1B,cAK6B,EAC7B,EACE,SAAS,MAQP,EAAE;IAEN,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,qBAAqB,GAAG,OAAO,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,qBAAqB,CAAC;QAC9D,CAAC;QACD,MAAM,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC;QACzC,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC1C,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,OAA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GAAG,CAAC,2BAA2B;YACxC,KAAK,KAAK,yBAAyB,EACnC,CAAC;YACD,8DAA8D;YAC9D,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAC1B,OAAO,CAAC,GAAG,EAAE,EACb,UAAU,CAAC,OAAO,IAAI,OAAO,CAC9B,CAAC;YACF,IAAA,8CAA+B,EAAC,OAAO,CAAC,CAAC;YAEzC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;YAC3D,MAAM,WAAW,GAAG,MAAM,IAAA,2BAAc,GAAE,CAAC;YAC3C,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC;gBACtC,KAAK,EAAE,WAAW;gBAClB,4CAA4C;gBAC5C,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC;gBAC9C,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE;gBACzB,WAAW,EAAE,MAAM;gBACnB,mBAAmB,EAAE,EAAE,EAAE,mBAAmB;gBAC5C,eAAe,EAAE,EAAE,EAAE,mBAAmB;gBACxC,iBAAiB,EAAE,EAAE,EAAE,oBAAoB;gBAC3C,gBAAgB,EAAE;oBAChB,qEAAqE;oBACrE,wEAAwE;oBACxE,qDAAqD;oBACrD,gFAAgF;oBAChF,aAAa;oBACb,aAAa;oBACb,GAAG,CAAC,UAAU,CAAC,sBAAsB,IAAI,EAAE,CAAC;iBAC7C;aACF,CAAC,CAAC;YAEH,MAAM,eAAe,CAAC,KAAK,EAAE,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,GAAG,CAAC;QAChD,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AA4EA,wBAA8B,cAAc,CAC1C,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAC;CACtB,EACD,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,EAAE,GAAG,GACb,OAAO,CAAC,MAAM,CAAC,CAoHjB"}
|
package/dist/loader.js
CHANGED
|
@@ -1,32 +1,149 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = workflowLoader;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
4
5
|
const core_1 = require("@swc/core");
|
|
6
|
+
// Cache decorator options per working directory to avoid reading tsconfig for every file
|
|
7
|
+
const decoratorOptionsCache = new Map();
|
|
8
|
+
// Cache for shared utilities from @workflow/builders (ESM module loaded dynamically in CommonJS context)
|
|
9
|
+
let cachedBuildersModule = null;
|
|
10
|
+
async function getBuildersModule() {
|
|
11
|
+
if (cachedBuildersModule) {
|
|
12
|
+
return cachedBuildersModule;
|
|
13
|
+
}
|
|
14
|
+
// Dynamic import to handle ESM module from CommonJS context
|
|
15
|
+
// biome-ignore lint/security/noGlobalEval: Need to use eval here to avoid TypeScript from transpiling the import statement into `require()`
|
|
16
|
+
cachedBuildersModule = (await eval('import("@workflow/builders")'));
|
|
17
|
+
return cachedBuildersModule;
|
|
18
|
+
}
|
|
19
|
+
async function getDecoratorOptions(workingDir) {
|
|
20
|
+
const cached = decoratorOptionsCache.get(workingDir);
|
|
21
|
+
if (cached) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
const promise = (async () => {
|
|
25
|
+
const { getDecoratorOptionsForDirectory } = await getBuildersModule();
|
|
26
|
+
return getDecoratorOptionsForDirectory(workingDir);
|
|
27
|
+
})();
|
|
28
|
+
decoratorOptionsCache.set(workingDir, promise);
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
async function detectPatterns(source) {
|
|
32
|
+
const { detectWorkflowPatterns } = await getBuildersModule();
|
|
33
|
+
return detectWorkflowPatterns(source);
|
|
34
|
+
}
|
|
35
|
+
async function checkGeneratedFile(filePath) {
|
|
36
|
+
const { isGeneratedWorkflowFile } = await getBuildersModule();
|
|
37
|
+
return isGeneratedWorkflowFile(filePath);
|
|
38
|
+
}
|
|
39
|
+
async function checkSdkFile(filePath) {
|
|
40
|
+
const { isWorkflowSdkFile } = await getBuildersModule();
|
|
41
|
+
return isWorkflowSdkFile(filePath);
|
|
42
|
+
}
|
|
43
|
+
async function checkShouldTransform(filePath, patterns) {
|
|
44
|
+
const { shouldTransformFile } = await getBuildersModule();
|
|
45
|
+
return shouldTransformFile(filePath, patterns);
|
|
46
|
+
}
|
|
47
|
+
async function getModuleSpecifier(filePath, projectRoot) {
|
|
48
|
+
const { resolveModuleSpecifier } = await getBuildersModule();
|
|
49
|
+
return resolveModuleSpecifier(filePath, projectRoot).moduleSpecifier;
|
|
50
|
+
}
|
|
5
51
|
// This loader applies the "use workflow"/"use step"
|
|
6
52
|
// client transformation
|
|
7
53
|
async function workflowLoader(source, sourceMap) {
|
|
8
54
|
const filename = this.resourcePath;
|
|
9
55
|
const normalizedSource = source.toString();
|
|
10
|
-
//
|
|
11
|
-
if (
|
|
56
|
+
// Skip generated workflow route files to avoid re-processing them
|
|
57
|
+
if (await checkGeneratedFile(filename)) {
|
|
12
58
|
return normalizedSource;
|
|
13
59
|
}
|
|
14
|
-
|
|
15
|
-
const
|
|
60
|
+
// Detect workflow patterns in the source code
|
|
61
|
+
const patterns = await detectPatterns(normalizedSource);
|
|
62
|
+
// For @workflow SDK packages, only transform files with actual directives,
|
|
63
|
+
// not files that just match serde patterns (which are internal SDK implementation files)
|
|
64
|
+
const isSdkFile = await checkSdkFile(filename);
|
|
65
|
+
if (isSdkFile && !patterns.hasDirective) {
|
|
66
|
+
return normalizedSource;
|
|
67
|
+
}
|
|
68
|
+
// Check if file needs transformation based on patterns and path
|
|
69
|
+
if (!(await checkShouldTransform(filename, patterns))) {
|
|
70
|
+
return normalizedSource;
|
|
71
|
+
}
|
|
72
|
+
const isTypeScript = filename.endsWith('.ts') ||
|
|
73
|
+
filename.endsWith('.tsx') ||
|
|
74
|
+
filename.endsWith('.mts') ||
|
|
75
|
+
filename.endsWith('.cts');
|
|
76
|
+
// Calculate relative filename for SWC plugin
|
|
77
|
+
// The SWC plugin uses filename to generate workflowId, so it must be relative
|
|
78
|
+
const workingDir = process.cwd();
|
|
79
|
+
const normalizedWorkingDir = workingDir
|
|
80
|
+
.replace(/\\/g, '/')
|
|
81
|
+
.replace(/\/$/, '');
|
|
82
|
+
const normalizedFilepath = filename.replace(/\\/g, '/');
|
|
83
|
+
// Windows fix: Use case-insensitive comparison to work around drive letter casing issues
|
|
84
|
+
const lowerWd = normalizedWorkingDir.toLowerCase();
|
|
85
|
+
const lowerPath = normalizedFilepath.toLowerCase();
|
|
86
|
+
let relativeFilename;
|
|
87
|
+
if (lowerPath.startsWith(lowerWd + '/')) {
|
|
88
|
+
// File is under working directory - manually calculate relative path
|
|
89
|
+
relativeFilename = normalizedFilepath.substring(normalizedWorkingDir.length + 1);
|
|
90
|
+
}
|
|
91
|
+
else if (lowerPath === lowerWd) {
|
|
92
|
+
// File IS the working directory (shouldn't happen)
|
|
93
|
+
relativeFilename = '.';
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Use relative() for files outside working directory
|
|
97
|
+
relativeFilename = (0, node_path_1.relative)(workingDir, filename).replace(/\\/g, '/');
|
|
98
|
+
if (relativeFilename.startsWith('../')) {
|
|
99
|
+
relativeFilename = relativeFilename
|
|
100
|
+
.split('/')
|
|
101
|
+
.filter((part) => part !== '..')
|
|
102
|
+
.join('/');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Final safety check - ensure we never pass an absolute path to SWC
|
|
106
|
+
if (relativeFilename.includes(':') || relativeFilename.startsWith('/')) {
|
|
107
|
+
// This should rarely happen, but use filename split as last resort
|
|
108
|
+
relativeFilename = normalizedFilepath.split('/').pop() || 'unknown.ts';
|
|
109
|
+
}
|
|
110
|
+
// Get decorator options from tsconfig (cached per working directory)
|
|
111
|
+
const decoratorOptions = await getDecoratorOptions(workingDir);
|
|
112
|
+
// Resolve module specifier for packages (node_modules or workspace packages)
|
|
113
|
+
const moduleSpecifier = await getModuleSpecifier(filename, workingDir);
|
|
16
114
|
// Transform with SWC
|
|
17
115
|
const result = await (0, core_1.transform)(normalizedSource, {
|
|
18
|
-
filename,
|
|
116
|
+
filename: relativeFilename,
|
|
19
117
|
jsc: {
|
|
20
118
|
parser: {
|
|
21
|
-
|
|
22
|
-
|
|
119
|
+
...(isTypeScript
|
|
120
|
+
? {
|
|
121
|
+
syntax: 'typescript',
|
|
122
|
+
tsx: filename.endsWith('.tsx'),
|
|
123
|
+
decorators: decoratorOptions.decorators,
|
|
124
|
+
}
|
|
125
|
+
: {
|
|
126
|
+
syntax: 'ecmascript',
|
|
127
|
+
jsx: filename.endsWith('.jsx'),
|
|
128
|
+
decorators: decoratorOptions.decorators,
|
|
129
|
+
}),
|
|
23
130
|
},
|
|
24
131
|
target: 'es2022',
|
|
25
132
|
experimental: {
|
|
26
133
|
plugins: [
|
|
27
|
-
[
|
|
134
|
+
[
|
|
135
|
+
require.resolve('@workflow/swc-plugin'),
|
|
136
|
+
{ mode: 'client', moduleSpecifier },
|
|
137
|
+
],
|
|
28
138
|
],
|
|
29
139
|
},
|
|
140
|
+
transform: {
|
|
141
|
+
react: {
|
|
142
|
+
runtime: 'preserve',
|
|
143
|
+
},
|
|
144
|
+
legacyDecorator: decoratorOptions.legacyDecorator,
|
|
145
|
+
decoratorMetadata: decoratorOptions.decoratorMetadata,
|
|
146
|
+
},
|
|
30
147
|
},
|
|
31
148
|
minify: false,
|
|
32
149
|
inputSourceMap: sourceMap,
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"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e,EAAE;qBACpC;iBACF;aACF;YACD,SAAS,EAAE;gBACT,KAAK,EAAE;oBACL,OAAO,EAAE,UAAU;iBACpB;gBACD,eAAe,EAAE,gBAAgB,CAAC,eAAe;gBACjD,iBAAiB,EAAE,gBAAgB,CAAC,iBAAiB;aACtD;SACF;QACD,MAAM,EAAE,KAAK;QACb,cAAc,EAAE,SAAS;QACzB,UAAU,EAAE,IAAI;QAChB,oBAAoB,EAAE,IAAI;KAC3B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '@workflow/
|
|
1
|
+
export * from '@workflow/core/dist/runtime';
|
|
2
2
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,cAAc,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAC"}
|
package/dist/runtime.js
CHANGED
|
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// re-export runtime as stub for resolving to not
|
|
18
18
|
// require @workflow/core be a dependency as well as
|
|
19
19
|
// @workflow/next
|
|
20
|
-
__exportStar(require("@workflow/
|
|
20
|
+
__exportStar(require("@workflow/core/dist/runtime"), exports);
|
|
21
21
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAAiD;AACjD,oDAAoD;AACpD,iBAAiB;AACjB,
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAAiD;AACjD,oDAAoD;AACpD,iBAAiB;AACjB,8DAA4C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the SWC plugin build has changed and invalidates the Next.js cache if needed.
|
|
3
|
+
* Also registers an exit handler to write the current build hash for future comparisons.
|
|
4
|
+
*
|
|
5
|
+
* @param distDir - The Next.js dist directory (e.g., '.next')
|
|
6
|
+
*/
|
|
7
|
+
export declare function maybeInvalidateCacheOnSwcChange(distDir: string): void;
|
|
8
|
+
//# sourceMappingURL=swc-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc-cache.d.ts","sourceRoot":"","sources":["../src/swc-cache.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAyCrE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.maybeInvalidateCacheOnSwcChange = maybeInvalidateCacheOnSwcChange;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the SWC plugin build has changed and invalidates the Next.js cache if needed.
|
|
11
|
+
* Also registers an exit handler to write the current build hash for future comparisons.
|
|
12
|
+
*
|
|
13
|
+
* @param distDir - The Next.js dist directory (e.g., '.next')
|
|
14
|
+
*/
|
|
15
|
+
function maybeInvalidateCacheOnSwcChange(distDir) {
|
|
16
|
+
const cacheDir = path_1.default.join(distDir, 'cache');
|
|
17
|
+
const devCacheDir = path_1.default.join(distDir, 'dev', 'cache');
|
|
18
|
+
const workflowJsonPath = path_1.default.join(cacheDir, 'workflow.json');
|
|
19
|
+
const swcPluginBuildHash = require('@workflow/swc-plugin/build-hash.json')
|
|
20
|
+
.buildHash;
|
|
21
|
+
let shouldInvalidateCache = false;
|
|
22
|
+
try {
|
|
23
|
+
const existing = JSON.parse(fs_1.default.readFileSync(workflowJsonPath, 'utf-8'));
|
|
24
|
+
if (existing.swcPluginBuildHash !== swcPluginBuildHash) {
|
|
25
|
+
shouldInvalidateCache = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// File doesn't exist or is invalid
|
|
30
|
+
shouldInvalidateCache = true;
|
|
31
|
+
}
|
|
32
|
+
if (shouldInvalidateCache) {
|
|
33
|
+
console.log('workflow transform upgraded, invalidating Next.js cache');
|
|
34
|
+
// Delete cache directories
|
|
35
|
+
const cacheDirs = [cacheDir, devCacheDir];
|
|
36
|
+
for (const dir of cacheDirs) {
|
|
37
|
+
if (fs_1.default.existsSync(dir)) {
|
|
38
|
+
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Write workflow.json lazily on process exit
|
|
43
|
+
process.on('exit', () => {
|
|
44
|
+
try {
|
|
45
|
+
fs_1.default.mkdirSync(cacheDir, { recursive: true });
|
|
46
|
+
fs_1.default.writeFileSync(workflowJsonPath, JSON.stringify({ swcPluginBuildHash }, null, 2));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Ignore errors on exit
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=swc-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swc-cache.js","sourceRoot":"","sources":["../src/swc-cache.ts"],"names":[],"mappings":";;;;;AASA,0EAyCC;AAlDD,4CAAoB;AACpB,gDAAwB;AAExB;;;;;GAKG;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,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5C,YAAE,CAAC,aAAa,CACd,gBAAgB,EAChB,IAAI,CAAC,SAAS,CAAC,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAChD,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,wBAAwB;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "workflow/next"
|
|
3
|
+
description: Next.js integration for automatic bundling and runtime configuration.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Next.js integration for Workflow DevKit that automatically configures bundling and runtime support.
|
|
7
|
+
|
|
8
|
+
## Functions
|
|
9
|
+
|
|
10
|
+
<Cards>
|
|
11
|
+
<Card title="withWorkflow" href="/docs/api-reference/workflow-next/with-workflow">
|
|
12
|
+
Configures webpack/turbopack loaders to transform workflow code (`"use step"`/`"use workflow"` directives)
|
|
13
|
+
</Card>
|
|
14
|
+
</Cards>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: withWorkflow
|
|
3
|
+
description: Configure webpack/turbopack to transform workflow directives in Next.js.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Configures webpack/turbopack loaders to transform workflow code (`"use step"`/`"use workflow"` directives)
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
To enable `"use step"` and `"use workflow"` directives while developing locally or deploying to production, wrap your `nextConfig` with `withWorkflow`.
|
|
11
|
+
|
|
12
|
+
```typescript title="next.config.ts" lineNumbers
|
|
13
|
+
import { withWorkflow } from "workflow/next"; // [!code highlight]
|
|
14
|
+
import type { NextConfig } from "next";
|
|
15
|
+
|
|
16
|
+
const nextConfig: NextConfig = {
|
|
17
|
+
// … rest of your Next.js config
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// not required but allows configuring workflow options
|
|
21
|
+
const workflowConfig = {}
|
|
22
|
+
|
|
23
|
+
export default withWorkflow(nextConfig, workflowConfig); // [!code highlight]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you are exporting a function in your `next.config` you will need to ensure you call the function returned from `withWorkflow`.
|
|
27
|
+
|
|
28
|
+
```typescript title="next.config.ts" lineNumbers
|
|
29
|
+
import { NextConfig } from "next";
|
|
30
|
+
import { withWorkflow } from "workflow/next";
|
|
31
|
+
import createNextIntlPlugin from "next-intl/plugin";
|
|
32
|
+
|
|
33
|
+
const withNextIntl = createNextIntlPlugin();
|
|
34
|
+
|
|
35
|
+
export default async function config(
|
|
36
|
+
phase: string,
|
|
37
|
+
ctx: {
|
|
38
|
+
defaultConfig: NextConfig
|
|
39
|
+
}
|
|
40
|
+
): Promise<NextConfig> {
|
|
41
|
+
let nextConfig: NextConfig | typeof config = {};
|
|
42
|
+
|
|
43
|
+
for (const configModifier of [withNextIntl, withWorkflow]) {
|
|
44
|
+
nextConfig = configModifier(nextConfig);
|
|
45
|
+
|
|
46
|
+
if (typeof nextConfig === "function") {
|
|
47
|
+
nextConfig = await nextConfig(phase, ctx);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return nextConfig;
|
|
51
|
+
}
|
|
52
|
+
```
|