@workflow/nest 0.0.0-beta.6 → 0.0.0-beta.8
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/README.md +11 -0
- package/dist/builder.d.ts +16 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +49 -2
- package/dist/builder.js.map +1 -1
- package/dist/cjs-rewrite.d.ts +35 -0
- package/dist/cjs-rewrite.d.ts.map +1 -0
- package/dist/cjs-rewrite.js +63 -0
- package/dist/cjs-rewrite.js.map +1 -0
- package/dist/cjs-rewrite.test.d.ts +2 -0
- package/dist/cjs-rewrite.test.d.ts.map +1 -0
- package/dist/cjs-rewrite.test.js +92 -0
- package/dist/cjs-rewrite.test.js.map +1 -0
- package/dist/cli.js +20 -4
- package/dist/cli.js.map +1 -1
- package/dist/parse-module-type.d.ts +6 -0
- package/dist/parse-module-type.d.ts.map +1 -0
- package/dist/parse-module-type.js +16 -0
- package/dist/parse-module-type.js.map +1 -0
- package/dist/parse-module-type.test.d.ts +2 -0
- package/dist/parse-module-type.test.d.ts.map +1 -0
- package/dist/parse-module-type.test.js +22 -0
- package/dist/parse-module-type.test.js.map +1 -0
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -113,6 +113,15 @@ WorkflowModule.forRoot({
|
|
|
113
113
|
|
|
114
114
|
// Skip building in production when bundles are pre-built
|
|
115
115
|
skipBuild: false,
|
|
116
|
+
|
|
117
|
+
// SWC module type: 'es6' (default) or 'commonjs'
|
|
118
|
+
// Set to 'commonjs' if your NestJS project compiles to CJS via SWC
|
|
119
|
+
moduleType: 'es6',
|
|
120
|
+
|
|
121
|
+
// Directory where NestJS compiles .ts to .js (default: 'dist')
|
|
122
|
+
// Only used when moduleType is 'commonjs'
|
|
123
|
+
// Should match the outDir in your tsconfig.json
|
|
124
|
+
distDir: 'dist',
|
|
116
125
|
});
|
|
117
126
|
```
|
|
118
127
|
|
|
@@ -164,6 +173,8 @@ WorkflowModule.forRoot({
|
|
|
164
173
|
dirs: ['src/workflows'],
|
|
165
174
|
outDir: '.nestjs/workflow',
|
|
166
175
|
skipBuild: process.env.NODE_ENV === 'production',
|
|
176
|
+
moduleType: 'commonjs', // if using SWC CommonJS compilation
|
|
177
|
+
distDir: 'dist', // where compiled .js files live
|
|
167
178
|
})
|
|
168
179
|
```
|
|
169
180
|
|
package/dist/builder.d.ts
CHANGED
|
@@ -20,6 +20,22 @@ export interface NestBuilderOptions {
|
|
|
20
20
|
* @default false
|
|
21
21
|
*/
|
|
22
22
|
watch?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* SWC module compilation type.
|
|
25
|
+
* Set to 'commonjs' if your NestJS project compiles to CJS via SWC.
|
|
26
|
+
* When 'commonjs', the builder rewrites externalized imports in the
|
|
27
|
+
* steps bundle to use require() via createRequire, avoiding ESM/CJS
|
|
28
|
+
* named-export interop issues with SWC's _export() wrapper pattern.
|
|
29
|
+
* @default 'es6'
|
|
30
|
+
*/
|
|
31
|
+
moduleType?: 'es6' | 'commonjs';
|
|
32
|
+
/**
|
|
33
|
+
* Directory where NestJS compiles .ts source files to .js (relative to workingDir).
|
|
34
|
+
* Used when moduleType is 'commonjs' to resolve compiled file paths.
|
|
35
|
+
* This should match the `outDir` in your tsconfig.json.
|
|
36
|
+
* @default 'dist'
|
|
37
|
+
*/
|
|
38
|
+
distDir?: string;
|
|
23
39
|
}
|
|
24
40
|
export declare class NestLocalBuilder extends BaseBuilder {
|
|
25
41
|
#private;
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAC;AAI1E,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,WAAW;;gBAOnC,OAAO,GAAE,kBAAuB;IAuB5C,IAAI,MAAM,IAAI,MAAM,CAEnB;IAEc,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA0FtC"}
|
package/dist/builder.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
2
2
|
import { BaseBuilder, createBaseBuilderConfig } from '@workflow/builders';
|
|
3
3
|
import { join } from 'pathe';
|
|
4
|
+
import { rewriteTsImportsInContent } from './cjs-rewrite.js';
|
|
4
5
|
export class NestLocalBuilder extends BaseBuilder {
|
|
5
6
|
#outDir;
|
|
7
|
+
#moduleType;
|
|
8
|
+
#distDir;
|
|
9
|
+
#dirs;
|
|
10
|
+
#workingDir;
|
|
6
11
|
constructor(options = {}) {
|
|
7
12
|
const workingDir = options.workingDir ?? process.cwd();
|
|
8
13
|
const outDir = options.outDir ?? join(workingDir, '.nestjs/workflow');
|
|
14
|
+
const dirs = options.dirs ?? ['src'];
|
|
9
15
|
super({
|
|
10
16
|
...createBaseBuilderConfig({
|
|
11
17
|
workingDir,
|
|
12
18
|
watch: options.watch ?? false,
|
|
13
|
-
dirs
|
|
19
|
+
dirs,
|
|
14
20
|
}),
|
|
15
21
|
// Use 'standalone' as base target - we handle the specific bundling ourselves
|
|
16
22
|
buildTarget: 'standalone',
|
|
@@ -19,6 +25,10 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
19
25
|
webhookBundlePath: join(outDir, 'webhook.mjs'),
|
|
20
26
|
});
|
|
21
27
|
this.#outDir = outDir;
|
|
28
|
+
this.#moduleType = options.moduleType ?? 'es6';
|
|
29
|
+
this.#distDir = options.distDir ?? 'dist';
|
|
30
|
+
this.#dirs = dirs;
|
|
31
|
+
this.#workingDir = workingDir;
|
|
22
32
|
}
|
|
23
33
|
get outDir() {
|
|
24
34
|
return this.#outDir;
|
|
@@ -38,6 +48,13 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
38
48
|
format: 'esm',
|
|
39
49
|
inputFiles,
|
|
40
50
|
});
|
|
51
|
+
// When the NestJS project compiles to CJS via SWC, the ESM steps bundle
|
|
52
|
+
// can't import named exports from CJS files because cjs-module-lexer
|
|
53
|
+
// doesn't recognize SWC's _export() wrapper pattern.
|
|
54
|
+
// Rewrite externalized .ts imports to use require() via createRequire.
|
|
55
|
+
if (this.#moduleType === 'commonjs') {
|
|
56
|
+
await this.#rewriteStepsBundleForCjs();
|
|
57
|
+
}
|
|
41
58
|
await this.createWebhookBundle({
|
|
42
59
|
outfile: join(this.#outDir, 'webhook.mjs'),
|
|
43
60
|
bundle: false,
|
|
@@ -59,5 +76,35 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
59
76
|
await writeFile(join(this.#outDir, '.gitignore'), '*\n');
|
|
60
77
|
}
|
|
61
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Rewrite externalized .ts/.tsx imports in the steps bundle to use require()
|
|
81
|
+
* for CommonJS compatibility.
|
|
82
|
+
*
|
|
83
|
+
* When NestJS compiles to CJS via SWC, the ESM steps bundle can't import
|
|
84
|
+
* named exports from CJS files because cjs-module-lexer doesn't recognize
|
|
85
|
+
* SWC's _export() wrapper pattern. This rewrites the imports to use
|
|
86
|
+
* createRequire() and points them to the compiled .js files in distDir.
|
|
87
|
+
*/
|
|
88
|
+
async #rewriteStepsBundleForCjs() {
|
|
89
|
+
const stepsPath = join(this.#outDir, 'steps.mjs');
|
|
90
|
+
const stepsContent = await readFile(stepsPath, 'utf-8');
|
|
91
|
+
const { content: rewritten, matchCount } = rewriteTsImportsInContent(stepsContent, {
|
|
92
|
+
outDir: this.#outDir,
|
|
93
|
+
workingDir: this.#workingDir,
|
|
94
|
+
distDir: this.#distDir,
|
|
95
|
+
dirs: this.#dirs,
|
|
96
|
+
});
|
|
97
|
+
if (matchCount === 0) {
|
|
98
|
+
console.warn('[@workflow/nest] No .ts/.tsx imports found to rewrite for CommonJS. ' +
|
|
99
|
+
"If you expected externalized imports, esbuild's output format may have changed.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const requireShim = [
|
|
103
|
+
`import { createRequire as __bundled_createRequire } from 'node:module';`,
|
|
104
|
+
`const require = __bundled_createRequire(import.meta.url);`,
|
|
105
|
+
``,
|
|
106
|
+
].join('\n');
|
|
107
|
+
await writeFile(stepsPath, requireShim + rewritten);
|
|
108
|
+
}
|
|
62
109
|
}
|
|
63
110
|
//# sourceMappingURL=builder.js.map
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAyC7D,MAAM,OAAO,gBAAiB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W,EAAE,IAAI,CAAC,OAAO;YACzB,QAAQ;SACT,CAAC,CAAC;QAEH,+CAA+C;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;YACtC,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,yBAAyB;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAExD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,yBAAyB,CAClE,YAAY,EACZ;YACE,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,IAAI,EAAE,IAAI,CAAC,KAAK;SACjB,CACF,CAAC;QAEF,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CACV,sEAAsE;gBACpE,iFAAiF,CACpF,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GAAG;YAClB,yEAAyE;YACzE,2DAA2D;YAC3D,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,SAAS,CAAC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regex to match named imports from relative .ts/.tsx files (externalized by esbuild).
|
|
3
|
+
* esbuild's externalized output emits named imports (`import { ... } from "..."`).
|
|
4
|
+
* Namespace imports (import * as) and default imports are not emitted for externalized
|
|
5
|
+
* source files in this context.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TS_IMPORT_REGEX: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* Rewrite externalized .ts/.tsx imports in steps bundle content to use require()
|
|
10
|
+
* for CommonJS compatibility.
|
|
11
|
+
*
|
|
12
|
+
* @returns Object with rewritten content and the number of imports rewritten.
|
|
13
|
+
* matchCount is 0 when no .ts/.tsx imports were found (valid when no externalized
|
|
14
|
+
* imports exist, or could indicate esbuild output format change).
|
|
15
|
+
*/
|
|
16
|
+
export declare function rewriteTsImportsInContent(stepsContent: string, options: {
|
|
17
|
+
outDir: string;
|
|
18
|
+
workingDir: string;
|
|
19
|
+
distDir: string;
|
|
20
|
+
dirs: string[];
|
|
21
|
+
}): {
|
|
22
|
+
content: string;
|
|
23
|
+
matchCount: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Map a source file path (relative to workingDir) to the compiled path in distDir.
|
|
27
|
+
*
|
|
28
|
+
* For dirs=['src'], distDir='dist': "src/services/foo.ts" → "dist/services/foo.js"
|
|
29
|
+
*
|
|
30
|
+
* When dirs includes ".", prefix is empty so no dir matches in the loop; we fall
|
|
31
|
+
* through to the default which prepends distDir to the entire path.
|
|
32
|
+
* e.g. dirs: [".", "src"] — "src/foo.ts" matches "src", files outside match "."
|
|
33
|
+
*/
|
|
34
|
+
export declare function mapSourceToDistPath(relToWorkingDir: string, dirs: string[], distDir: string): string;
|
|
35
|
+
//# sourceMappingURL=cjs-rewrite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cjs-rewrite.d.ts","sourceRoot":"","sources":["../src/cjs-rewrite.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAC8C,CAAC;AAE3E;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,GACA;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAmCzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,GACd,MAAM,CAYR"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { join, resolve, relative } from 'pathe';
|
|
2
|
+
/**
|
|
3
|
+
* Regex to match named imports from relative .ts/.tsx files (externalized by esbuild).
|
|
4
|
+
* esbuild's externalized output emits named imports (`import { ... } from "..."`).
|
|
5
|
+
* Namespace imports (import * as) and default imports are not emitted for externalized
|
|
6
|
+
* source files in this context.
|
|
7
|
+
*/
|
|
8
|
+
export const TS_IMPORT_REGEX = /import\s*\{([^}]+)\}\s*from\s*["']((?:\.\.?\/)+[^"']+\.tsx?)["']\s*;?/g;
|
|
9
|
+
/**
|
|
10
|
+
* Rewrite externalized .ts/.tsx imports in steps bundle content to use require()
|
|
11
|
+
* for CommonJS compatibility.
|
|
12
|
+
*
|
|
13
|
+
* @returns Object with rewritten content and the number of imports rewritten.
|
|
14
|
+
* matchCount is 0 when no .ts/.tsx imports were found (valid when no externalized
|
|
15
|
+
* imports exist, or could indicate esbuild output format change).
|
|
16
|
+
*/
|
|
17
|
+
export function rewriteTsImportsInContent(stepsContent, options) {
|
|
18
|
+
const { outDir, workingDir, distDir, dirs } = options;
|
|
19
|
+
const countRegex = new RegExp(TS_IMPORT_REGEX.source, TS_IMPORT_REGEX.flags);
|
|
20
|
+
const matches = [];
|
|
21
|
+
let m;
|
|
22
|
+
while ((m = countRegex.exec(stepsContent)) !== null) {
|
|
23
|
+
matches.push({ fullMatch: m[0], imports: m[1], path: m[2] });
|
|
24
|
+
}
|
|
25
|
+
if (matches.length === 0) {
|
|
26
|
+
return { content: stepsContent, matchCount: 0 };
|
|
27
|
+
}
|
|
28
|
+
const replaceRegex = new RegExp(TS_IMPORT_REGEX.source, TS_IMPORT_REGEX.flags);
|
|
29
|
+
const rewritten = stepsContent.replace(replaceRegex, (_match, imports, tsRelativePath) => {
|
|
30
|
+
const absSourcePath = resolve(outDir, tsRelativePath);
|
|
31
|
+
const relToWorkingDir = relative(workingDir, absSourcePath);
|
|
32
|
+
const distRelPath = mapSourceToDistPath(relToWorkingDir, dirs, distDir);
|
|
33
|
+
const distAbsPath = join(workingDir, distRelPath);
|
|
34
|
+
let newRelPath = relative(outDir, distAbsPath).replace(/\\/g, '/');
|
|
35
|
+
if (!newRelPath.startsWith('.')) {
|
|
36
|
+
newRelPath = `./${newRelPath}`;
|
|
37
|
+
}
|
|
38
|
+
const cjsImports = imports.replace(/\s+as\s+/g, ': ');
|
|
39
|
+
return `const {${cjsImports}} = require("${newRelPath}");`;
|
|
40
|
+
});
|
|
41
|
+
return { content: rewritten, matchCount: matches.length };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Map a source file path (relative to workingDir) to the compiled path in distDir.
|
|
45
|
+
*
|
|
46
|
+
* For dirs=['src'], distDir='dist': "src/services/foo.ts" → "dist/services/foo.js"
|
|
47
|
+
*
|
|
48
|
+
* When dirs includes ".", prefix is empty so no dir matches in the loop; we fall
|
|
49
|
+
* through to the default which prepends distDir to the entire path.
|
|
50
|
+
* e.g. dirs: [".", "src"] — "src/foo.ts" matches "src", files outside match "."
|
|
51
|
+
*/
|
|
52
|
+
export function mapSourceToDistPath(relToWorkingDir, dirs, distDir) {
|
|
53
|
+
const normalized = relToWorkingDir.replace(/\\/g, '/');
|
|
54
|
+
for (const dir of dirs) {
|
|
55
|
+
const prefix = dir === '.' ? '' : `${dir}/`;
|
|
56
|
+
if (prefix && normalized.startsWith(prefix)) {
|
|
57
|
+
const withinDir = normalized.slice(prefix.length);
|
|
58
|
+
return join(distDir, withinDir).replace(/\.tsx?$/, '.js');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return join(distDir, normalized).replace(/\.tsx?$/, '.js');
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=cjs-rewrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cjs-rewrite.js","sourceRoot":"","sources":["../src/cjs-rewrite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,wEAAwE,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAoB,EACpB,OAKC;IAED,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IAC7E,MAAM,OAAO,GACX,EAAE,CAAC;IACL,IAAI,CAAC,CAAC;IACN,OAAO,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IAClD,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,eAAe,CAAC,MAAM,EACtB,eAAe,CAAC,KAAK,CACtB,CAAC;IACF,MAAM,SAAS,GAAG,YAAY,C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5C,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAClD,OAAO,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cjs-rewrite.test.d.ts","sourceRoot":"","sources":["../src/cjs-rewrite.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { mapSourceToDistPath, rewriteTsImportsInContent, TS_IMPORT_REGEX, } from './cjs-rewrite.js';
|
|
3
|
+
describe('TS_IMPORT_REGEX', () => {
|
|
4
|
+
const testRegex = () => new RegExp(TS_IMPORT_REGEX.source, TS_IMPORT_REGEX.flags);
|
|
5
|
+
it('matches named imports from .ts files', () => {
|
|
6
|
+
const s = 'import { foo, bar } from "../src/services/helper.ts";';
|
|
7
|
+
expect(testRegex().test(s)).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it('matches named imports from .tsx files', () => {
|
|
10
|
+
const s = 'import { foo } from "./components/Widget.tsx";';
|
|
11
|
+
expect(testRegex().test(s)).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
it('matches imports with "as" alias', () => {
|
|
14
|
+
const s = 'import { hasValue as hv } from "../utils.ts";';
|
|
15
|
+
expect(testRegex().test(s)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it('does not match imports from node_modules', () => {
|
|
18
|
+
expect(testRegex().test('import { x } from "@workflow/core";')).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('rewriteTsImportsInContent', () => {
|
|
22
|
+
const opts = {
|
|
23
|
+
outDir: '/proj/.nestjs/workflow',
|
|
24
|
+
workingDir: '/proj',
|
|
25
|
+
distDir: 'dist',
|
|
26
|
+
dirs: ['src'],
|
|
27
|
+
};
|
|
28
|
+
it('rewrites named imports from .ts to require()', () => {
|
|
29
|
+
const content = [
|
|
30
|
+
'import { foo, bar } from "../../src/services/helper.ts";',
|
|
31
|
+
'const x = 1;',
|
|
32
|
+
].join('\n');
|
|
33
|
+
const { content: result, matchCount } = rewriteTsImportsInContent(content, opts);
|
|
34
|
+
expect(matchCount).toBe(1);
|
|
35
|
+
expect(result).toContain('require("../../dist/services/helper.js")');
|
|
36
|
+
expect(result).toMatch(/\bfoo\b.*\bbar\b/);
|
|
37
|
+
});
|
|
38
|
+
it('rewrites imports with "as" alias', () => {
|
|
39
|
+
const content = 'import { hasValue as hv } from "../../src/utils.ts";';
|
|
40
|
+
const { content: result, matchCount } = rewriteTsImportsInContent(content, opts);
|
|
41
|
+
expect(matchCount).toBe(1);
|
|
42
|
+
expect(result).toContain('hasValue: hv');
|
|
43
|
+
expect(result).toContain('require("../../dist/utils.js")');
|
|
44
|
+
});
|
|
45
|
+
it('handles .tsx files', () => {
|
|
46
|
+
const content = 'import { Widget } from "../../src/components/Widget.tsx";';
|
|
47
|
+
const { content: result, matchCount } = rewriteTsImportsInContent(content, opts);
|
|
48
|
+
expect(matchCount).toBe(1);
|
|
49
|
+
expect(result).toContain('dist/components/Widget.js');
|
|
50
|
+
});
|
|
51
|
+
it('returns matchCount 0 when no .ts/.tsx imports', () => {
|
|
52
|
+
const content = 'import { x } from "@workflow/core";\nconst y = 1;';
|
|
53
|
+
const { content: result, matchCount } = rewriteTsImportsInContent(content, opts);
|
|
54
|
+
expect(matchCount).toBe(0);
|
|
55
|
+
expect(result).toBe(content);
|
|
56
|
+
});
|
|
57
|
+
it('rewrites multiple imports', () => {
|
|
58
|
+
const content = [
|
|
59
|
+
'import { a } from "../../src/a.ts";',
|
|
60
|
+
'import { b } from "../../src/b.ts";',
|
|
61
|
+
].join('\n');
|
|
62
|
+
const { content: result, matchCount } = rewriteTsImportsInContent(content, opts);
|
|
63
|
+
expect(matchCount).toBe(2);
|
|
64
|
+
expect(result).toContain('require("../../dist/a.js")');
|
|
65
|
+
expect(result).toContain('require("../../dist/b.js")');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('mapSourceToDistPath', () => {
|
|
69
|
+
it('maps src/ path with dirs=["src"]', () => {
|
|
70
|
+
expect(mapSourceToDistPath('src/services/foo.ts', ['src'], 'dist')).toBe('dist/services/foo.js');
|
|
71
|
+
});
|
|
72
|
+
it('maps src/ path with dirs=["src"] for .tsx', () => {
|
|
73
|
+
expect(mapSourceToDistPath('src/components/foo.tsx', ['src'], 'dist')).toBe('dist/components/foo.js');
|
|
74
|
+
});
|
|
75
|
+
it('handles dirs with multiple entries', () => {
|
|
76
|
+
expect(mapSourceToDistPath('src/foo.ts', ['src', 'lib'], 'dist')).toBe('dist/foo.js');
|
|
77
|
+
expect(mapSourceToDistPath('lib/bar.ts', ['src', 'lib'], 'dist')).toBe('dist/bar.js');
|
|
78
|
+
});
|
|
79
|
+
it('handles dirs: ["."] - fallthrough to dist prepend', () => {
|
|
80
|
+
expect(mapSourceToDistPath('services/foo.ts', ['.'], 'dist')).toBe('dist/services/foo.js');
|
|
81
|
+
});
|
|
82
|
+
it('handles dirs: [".", "src"] - src matches first for src/ files', () => {
|
|
83
|
+
expect(mapSourceToDistPath('src/foo.ts', ['.', 'src'], 'dist')).toBe('dist/foo.js');
|
|
84
|
+
});
|
|
85
|
+
it('handles dirs: [".", "src"] - fallthrough for files outside src/', () => {
|
|
86
|
+
expect(mapSourceToDistPath('services/foo.ts', ['.', 'src'], 'dist')).toBe('dist/services/foo.js');
|
|
87
|
+
});
|
|
88
|
+
it('handles path outside all dirs', () => {
|
|
89
|
+
expect(mapSourceToDistPath('other/foo.ts', ['src'], 'dist')).toBe('dist/other/foo.js');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
//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C,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAC/D,mBAAmB,CACpB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ function resolveSwcPluginPath() {
|
|
|
17
17
|
/**
|
|
18
18
|
* Generate .swcrc configuration for NestJS with the workflow plugin.
|
|
19
19
|
*/
|
|
20
|
-
function generateSwcrc(pluginPath) {
|
|
20
|
+
function generateSwcrc(pluginPath, moduleType = 'es6') {
|
|
21
21
|
return {
|
|
22
22
|
$schema: 'https://swc.rs/schema.json',
|
|
23
23
|
jsc: {
|
|
@@ -34,7 +34,7 @@ function generateSwcrc(pluginPath) {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
module: {
|
|
37
|
-
type:
|
|
37
|
+
type: moduleType,
|
|
38
38
|
},
|
|
39
39
|
sourceMaps: true,
|
|
40
40
|
};
|
|
@@ -48,7 +48,11 @@ Commands:
|
|
|
48
48
|
help Show this help message
|
|
49
49
|
|
|
50
50
|
Usage:
|
|
51
|
-
npx @workflow/nest init
|
|
51
|
+
npx @workflow/nest init [options]
|
|
52
|
+
|
|
53
|
+
Options:
|
|
54
|
+
--module <type> SWC module type: 'es6' (default) or 'commonjs'
|
|
55
|
+
--force Overwrite existing .swcrc file
|
|
52
56
|
|
|
53
57
|
This command generates a .swcrc file configured with the Workflow SWC plugin
|
|
54
58
|
for client-mode transformations. The plugin path is resolved from the
|
|
@@ -68,9 +72,21 @@ function hasWorkflowPlugin(swcrcContent) {
|
|
|
68
72
|
return false;
|
|
69
73
|
}
|
|
70
74
|
}
|
|
75
|
+
import { parseModuleType as parseModuleTypeRaw } from './parse-module-type.js';
|
|
76
|
+
function parseModuleType(args) {
|
|
77
|
+
const result = parseModuleTypeRaw(args);
|
|
78
|
+
if (result === null) {
|
|
79
|
+
const idx = args.indexOf('--module');
|
|
80
|
+
const value = idx >= 0 && idx + 1 < args.length ? args[idx + 1] : '';
|
|
81
|
+
console.error(`Invalid module type: ${value}. Must be 'es6' or 'commonjs'.`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
71
86
|
function handleInit(args) {
|
|
72
87
|
const swcrcPath = resolve(process.cwd(), '.swcrc');
|
|
73
88
|
const forceMode = args.includes('--force');
|
|
89
|
+
const moduleType = parseModuleType(args);
|
|
74
90
|
if (existsSync(swcrcPath)) {
|
|
75
91
|
const existing = readFileSync(swcrcPath, 'utf-8');
|
|
76
92
|
if (hasWorkflowPlugin(existing)) {
|
|
@@ -86,7 +102,7 @@ function handleInit(args) {
|
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
const pluginPath = resolveSwcPluginPath();
|
|
89
|
-
const swcrc = generateSwcrc(pluginPath);
|
|
105
|
+
const swcrc = generateSwcrc(pluginPath, moduleType);
|
|
90
106
|
writeFileSync(swcrcPath, `${JSON.stringify(swcrc, null, 2)}\n`);
|
|
91
107
|
console.log('✓ Created .swcrc with workflow plugin configuration');
|
|
92
108
|
console.log(` Plugin path: ${pluginPath}`);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG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,kBAAkB,UAAU,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,CACT,sEAAsE,CACvE,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,IAAI;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAExB,IACE,CAAC,OAAO;QACR,OAAO,KAAK,MAAM;QAClB,OAAO,KAAK,QAAQ;QACpB,OAAO,KAAK,IAAI,EAChB,CAAC;QACD,QAAQ,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-module-type.d.ts","sourceRoot":"","sources":["../src/parse-module-type.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,UAAU,GAAG,IAAI,CAOzE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse --module flag from CLI args.
|
|
3
|
+
* Returns null when the value is invalid.
|
|
4
|
+
*/
|
|
5
|
+
export function parseModuleType(args) {
|
|
6
|
+
const idx = args.indexOf('--module');
|
|
7
|
+
if (idx === -1 || idx + 1 >= args.length)
|
|
8
|
+
return 'es6';
|
|
9
|
+
const value = args[idx + 1];
|
|
10
|
+
if (value === 'commonjs')
|
|
11
|
+
return 'commonjs';
|
|
12
|
+
if (value === 'es6')
|
|
13
|
+
return 'es6';
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=parse-module-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-module-type.js","sourceRoot":"","sources":["../src/parse-module-type.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAc;IAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAC5B,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC;IAC5C,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-module-type.test.d.ts","sourceRoot":"","sources":["../src/parse-module-type.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseModuleType } from './parse-module-type.js';
|
|
3
|
+
describe('parseModuleType', () => {
|
|
4
|
+
it('returns es6 when --module is absent', () => {
|
|
5
|
+
expect(parseModuleType(['init'])).toBe('es6');
|
|
6
|
+
expect(parseModuleType([])).toBe('es6');
|
|
7
|
+
});
|
|
8
|
+
it('returns es6 when --module es6', () => {
|
|
9
|
+
expect(parseModuleType(['init', '--module', 'es6'])).toBe('es6');
|
|
10
|
+
});
|
|
11
|
+
it('returns commonjs when --module commonjs', () => {
|
|
12
|
+
expect(parseModuleType(['init', '--module', 'commonjs'])).toBe('commonjs');
|
|
13
|
+
});
|
|
14
|
+
it('returns null when --module has invalid value', () => {
|
|
15
|
+
expect(parseModuleType(['init', '--module', 'umd'])).toBe(null);
|
|
16
|
+
expect(parseModuleType(['--module', 'invalid'])).toBe(null);
|
|
17
|
+
});
|
|
18
|
+
it('returns es6 when --module is last arg (no value)', () => {
|
|
19
|
+
expect(parseModuleType(['init', '--module'])).toBe('es6');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=parse-module-type.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-module-type.test.js","sourceRoot":"","sources":["../src/parse-module-type.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChE,MAAM,CAAC,eAAe,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,eAAe,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/nest",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.8",
|
|
4
4
|
"description": "NestJS integration for Workflow DevKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
14
15
|
},
|
|
15
16
|
"./builder": {
|
|
16
17
|
"types": "./dist/builder.d.ts",
|
|
17
|
-
"import": "./dist/builder.js"
|
|
18
|
+
"import": "./dist/builder.js",
|
|
19
|
+
"default": "./dist/builder.js"
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"@swc/core": "1.15.3",
|
|
28
30
|
"pathe": "2.0.3",
|
|
29
|
-
"@workflow/builders": "4.0.1-beta.
|
|
31
|
+
"@workflow/builders": "4.0.1-beta.50",
|
|
30
32
|
"@workflow/swc-plugin": "4.1.0-beta.18"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
@@ -54,6 +56,7 @@
|
|
|
54
56
|
"@nestjs/core": "^11.0.1",
|
|
55
57
|
"@types/node": "22.19.0",
|
|
56
58
|
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^3.2.4",
|
|
57
60
|
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
58
61
|
},
|
|
59
62
|
"license": "Apache-2.0",
|
|
@@ -65,6 +68,7 @@
|
|
|
65
68
|
"scripts": {
|
|
66
69
|
"build": "tsc",
|
|
67
70
|
"dev": "tsc --watch",
|
|
68
|
-
"clean": "tsc --build --clean && rm -rf dist"
|
|
71
|
+
"clean": "tsc --build --clean && rm -rf dist",
|
|
72
|
+
"test": "vitest run src"
|
|
69
73
|
}
|
|
70
74
|
}
|