@n8n-as-code/sync 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * WorkspaceSetupService
3
+ *
4
+ * Ensures a workflow directory has the files needed for a smooth TypeScript
5
+ * editing experience — no npm install required in the user's workspace:
6
+ *
7
+ * 1. `n8n-workflows.d.ts` — ambient declarations for @n8n-as-code/transformer.
8
+ * Eliminates red-squiggle "Cannot find module" errors in .workflow.ts files.
9
+ *
10
+ * 2. `tsconfig.json` (only if absent) — minimal config that enables decorators
11
+ * and includes the generated declaration file.
12
+ *
13
+ * Both files are written to the workflow sync directory.
14
+ * The .d.ts is always overwritten so it stays up-to-date with new extension/CLI releases.
15
+ * The tsconfig.json is only written once and never overwritten (respects user edits).
16
+ *
17
+ * Responsibility: @n8n-as-code/sync — called by both the VS Code extension
18
+ * and the CLI so the experience is identical regardless of how the workspace
19
+ * was initialised.
20
+ */
21
+ import fs from 'fs';
22
+ import path from 'path';
23
+ import { fileURLToPath } from 'url';
24
+ // ─── Resolve bundled assets path ─────────────────────────────────────────────
25
+ // Works in both ESM (import.meta.url) and CJS (__dirname)
26
+ const _filename = typeof __filename !== 'undefined'
27
+ ? __filename
28
+ : fileURLToPath(import.meta.url);
29
+ const _dirname = path.dirname(_filename);
30
+ // In the built package the assets live next to this file (dist/services/../assets/)
31
+ // At source level they live in src/assets/
32
+ function resolveAssetPath(filename) {
33
+ // Try sibling assets/ dir (built layout: dist/services/workspace-setup-service.js)
34
+ const candidates = [
35
+ path.join(_dirname, '..', 'assets', filename), // packages/sync/dist/assets/
36
+ path.join(_dirname, 'assets', filename), // packages/sync/dist/services/assets/ (fallback)
37
+ ];
38
+ for (const candidate of candidates) {
39
+ if (fs.existsSync(candidate))
40
+ return candidate;
41
+ }
42
+ throw new Error(`[n8n-as-code] Could not find bundled asset "${filename}". Tried:\n` +
43
+ candidates.map(c => ` ${c}`).join('\n'));
44
+ }
45
+ // ─── Minimal tsconfig.json ────────────────────────────────────────────────────
46
+ const TSCONFIG_CONTENT = JSON.stringify({
47
+ compilerOptions: {
48
+ target: 'ES2022',
49
+ module: 'ESNext',
50
+ moduleResolution: 'node',
51
+ baseUrl: '.',
52
+ paths: {
53
+ '@n8n-as-code/transformer': ['./n8n-workflows.d.ts'],
54
+ },
55
+ experimentalDecorators: true,
56
+ emitDecoratorMetadata: false,
57
+ strict: false,
58
+ noEmit: true,
59
+ skipLibCheck: true,
60
+ },
61
+ include: ['**/*.workflow.ts', '**/*.d.ts'],
62
+ exclude: ['node_modules'],
63
+ }, null, 4);
64
+ // ─── Service ──────────────────────────────────────────────────────────────────
65
+ export class WorkspaceSetupService {
66
+ /**
67
+ * Ensure TypeScript support files are present in the given workflow directory.
68
+ * Safe to call multiple times — only writes when content has actually changed.
69
+ *
70
+ * @param workflowDir Absolute path to the directory that contains .workflow.ts files
71
+ */
72
+ static ensureWorkspaceFiles(workflowDir) {
73
+ fs.mkdirSync(workflowDir, { recursive: true });
74
+ WorkspaceSetupService.writeDeclarationFile(workflowDir);
75
+ WorkspaceSetupService.writeTsConfig(workflowDir);
76
+ }
77
+ // ── Private helpers ───────────────────────────────────────────────────────
78
+ /** Copy / overwrite the bundled .d.ts stub so it stays current */
79
+ static writeDeclarationFile(dir) {
80
+ let stubContent;
81
+ try {
82
+ const src = resolveAssetPath('n8n-workflows.d.ts');
83
+ stubContent = fs.readFileSync(src, 'utf-8');
84
+ }
85
+ catch (err) {
86
+ console.warn('[n8n-as-code] WorkspaceSetupService:', err.message);
87
+ return;
88
+ }
89
+ const dest = path.join(dir, 'n8n-workflows.d.ts');
90
+ WorkspaceSetupService.writeIfChanged(dest, stubContent);
91
+ }
92
+ /** Write tsconfig.json, overwriting if content has changed (keeps existing workspaces up to date) */
93
+ static writeTsConfig(dir) {
94
+ const dest = path.join(dir, 'tsconfig.json');
95
+ WorkspaceSetupService.writeIfChanged(dest, TSCONFIG_CONTENT);
96
+ }
97
+ /** Write only when content differs (avoids unnecessary git dirty state) */
98
+ static writeIfChanged(filePath, content) {
99
+ const existing = fs.existsSync(filePath)
100
+ ? fs.readFileSync(filePath, 'utf-8')
101
+ : null;
102
+ if (existing !== content) {
103
+ fs.writeFileSync(filePath, content, 'utf-8');
104
+ }
105
+ }
106
+ }
107
+ //# sourceMappingURL=workspace-setup-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-setup-service.js","sourceRoot":"","sources":["../../src/services/workspace-setup-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,gFAAgF;AAEhF,0DAA0D;AAC1D,MAAM,SAAS,GACX,OAAO,UAAU,KAAK,WAAW;IAC7B,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAEzC,oFAAoF;AACpF,2CAA2C;AAC3C,SAAS,gBAAgB,CAAC,QAAgB;IACtC,mFAAmF;IACnF,MAAM,UAAU,GAAG;QACf,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAI,6BAA6B;QAC9E,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAW,iDAAiD;KACtG,CAAC;IACF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IACnD,CAAC;IACD,MAAM,IAAI,KAAK,CACX,+CAA+C,QAAQ,aAAa;QACpE,UAAU,C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AI,CAAC,sCAAsC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YAClE,OAAO;QACX,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAClD,qBAAqB,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED,qGAAqG;IAC7F,MAAM,CAAC,aAAa,CAAC,GAAW;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QAC7C,qBAAqB,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACjE,CAAC;IAED,2EAA2E;IACnE,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,OAAe;QAC3D,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;YACpC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;YACpC,CAAC,CAAC,IAAI,CAAC;QACX,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YACvB,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@n8n-as-code/sync",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Sync library for n8n-as-code ecosystem",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "prebuild": "node ../../scripts/compare-extraction.mjs || echo 'Warning: Report generation skipped/failed'",
10
- "build": "tsc -b",
10
+ "copy-assets": "mkdir -p dist/assets && cp src/assets/n8n-workflows.d.ts dist/assets/",
11
+ "build": "tsc -b && npm run copy-assets",
11
12
  "watch": "tsc -b -w",
12
13
  "clean": "rm -rf dist tsconfig.tsbuildinfo",
13
14
  "test": "npm run test:unit && npm run test:integration",
@@ -16,6 +17,7 @@
16
17
  "validate-schema": "node ../../scripts/validate-schema.js --schema ./src/assets/n8n-nodes-index.json"
17
18
  },
18
19
  "dependencies": {
20
+ "@n8n-as-code/transformer": "0.2.0",
19
21
  "chokidar": "^3.5.3",
20
22
  "@types/json-stable-stringify": "^1.1.0",
21
23
  "axios": "^1.6.0",