@webda/compiler 4.0.0-beta.3

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.
Files changed (55) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +125 -0
  3. package/lib/compiler.d.ts +88 -0
  4. package/lib/compiler.d.ts.map +1 -0
  5. package/lib/compiler.js +230 -0
  6. package/lib/compiler.js.map +1 -0
  7. package/lib/configuration.d.ts +35 -0
  8. package/lib/configuration.d.ts.map +1 -0
  9. package/lib/configuration.js +170 -0
  10. package/lib/configuration.js.map +1 -0
  11. package/lib/definition.d.ts +787 -0
  12. package/lib/definition.d.ts.map +1 -0
  13. package/lib/definition.js +189 -0
  14. package/lib/definition.js.map +1 -0
  15. package/lib/index.d.ts +5 -0
  16. package/lib/index.d.ts.map +1 -0
  17. package/lib/index.js +5 -0
  18. package/lib/index.js.map +1 -0
  19. package/lib/module.d.ts +36 -0
  20. package/lib/module.d.ts.map +1 -0
  21. package/lib/module.js +119 -0
  22. package/lib/module.js.map +1 -0
  23. package/lib/morpher/capabilities.d.ts +35 -0
  24. package/lib/morpher/capabilities.d.ts.map +1 -0
  25. package/lib/morpher/capabilities.js +66 -0
  26. package/lib/morpher/capabilities.js.map +1 -0
  27. package/lib/morpher/imports.d.ts +10 -0
  28. package/lib/morpher/imports.d.ts.map +1 -0
  29. package/lib/morpher/imports.js +97 -0
  30. package/lib/morpher/imports.js.map +1 -0
  31. package/lib/morpher/morpher.d.ts +34 -0
  32. package/lib/morpher/morpher.d.ts.map +1 -0
  33. package/lib/morpher/morpher.js +87 -0
  34. package/lib/morpher/morpher.js.map +1 -0
  35. package/lib/operations.d.ts +29 -0
  36. package/lib/operations.d.ts.map +1 -0
  37. package/lib/operations.js +197 -0
  38. package/lib/operations.js.map +1 -0
  39. package/lib/schema-backend.d.ts +55 -0
  40. package/lib/schema-backend.d.ts.map +1 -0
  41. package/lib/schema-backend.js +86 -0
  42. package/lib/schema-backend.js.map +1 -0
  43. package/lib/session-types.d.ts +14 -0
  44. package/lib/session-types.d.ts.map +1 -0
  45. package/lib/session-types.js +79 -0
  46. package/lib/session-types.js.map +1 -0
  47. package/lib/shell-build-dispatch.d.ts +54 -0
  48. package/lib/shell-build-dispatch.d.ts.map +1 -0
  49. package/lib/shell-build-dispatch.js +77 -0
  50. package/lib/shell-build-dispatch.js.map +1 -0
  51. package/lib/shell.d.ts +3 -0
  52. package/lib/shell.d.ts.map +1 -0
  53. package/lib/shell.js +297 -0
  54. package/lib/shell.js.map +1 -0
  55. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,166 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
166
+
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # @webda/compiler module
2
+
3
+ This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
4
+
5
+ <img src="https://webda.io/images/webda.svg" width="128" />
6
+
7
+ ![CI](https://github.com/loopingz/webda.io/workflows/CI/badge.svg)
8
+
9
+ [![Join the chat at https://gitter.im/loopingz/webda](https://badges.gitter.im/loopingz/webda.svg)](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
+ [![codecov](https://codecov.io/gh/loopingz/webda.io/branch/main/graph/badge.svg?token=8N9DNM3K3O)](https://codecov.io/gh/loopingz/webda.io)
11
+ [![SonarCloud.io](https://sonarcloud.io/api/project_badges/measure?project=loopingz_webda.io&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
12
+ ![CodeQL](https://github.com/loopingz/webda.io/workflows/CodeQL/badge.svg)
13
+
14
+ <!-- README_HEADER -->
15
+
16
+ ## @webda/compiler
17
+
18
+ The build toolchain for Webda applications. It compiles on TypeScript 7.1 through `@webda/content-mapper`, generates the module manifest (`webda.module.json`) and JSON Schemas for all models and service parameters, and can migrate sources written for older Webda versions.
19
+
20
+ ### When to use it
21
+
22
+ - Run `webdac build` once after making changes to build and generate the module manifest.
23
+ - Use `webdac build --watch` during development to rebuild on every change.
24
+ - Use `webdac code` once when migrating an application from an older Webda version (moved imports, obsolete filter registrations).
25
+
26
+ ### Install
27
+
28
+ ```bash
29
+ npm install --save-dev @webda/compiler
30
+ ```
31
+
32
+ The `webdac` binary is included.
33
+
34
+ ### Commands
35
+
36
+ #### `webdac build`
37
+
38
+ Compiles the application TypeScript and regenerates `webda.module.json` and all schemas.
39
+
40
+ ```bash
41
+ webdac build # one-shot build
42
+ webdac build --watch # watch mode: rebuild on every change under src/
43
+ webdac build --appPath /path/to/app
44
+ ```
45
+
46
+ What it does:
47
+ 1. Compiles with TypeScript 7.1 through `@webda/content-mapper`, which generates accessors,
48
+ `toJSON` and behaviours, type-checks the result and emits ES modules to `lib/`
49
+ 2. Discovers models, services, deployers, and beans with the same type checker
50
+ 3. Generates per-model JSON Schemas (input, output, stored)
51
+ 4. Writes `webda.module.json` at the project root
52
+ 5. Merges dependency modules from `node_modules`
53
+ 6. Writes `.webda-config-schema.json` and `.webda-deployment-schema.json`
54
+
55
+ #### `webdac code`
56
+
57
+ Migrates application sources written for an older Webda version, in place:
58
+
59
+ ```bash
60
+ webdac code # run every migration module
61
+ webdac code --module updateImports # run a specific module
62
+ ```
63
+
64
+ Migration modules available:
65
+
66
+ | Module | Description |
67
+ |--------|-------------|
68
+ | `updateImports` | Moves imports to the packages that now own them |
69
+ | `capabilities` | Removes filter registrations the framework now does automatically |
70
+
71
+ It no longer generates code: `webdac build` does, without touching your sources.
72
+
73
+ ### `webda.module.json` format
74
+
75
+ ```json
76
+ {
77
+ "$schema": "https://webda.io/schemas/webda.module.v4.json",
78
+ "beans": {
79
+ "MyApp/MyBean": {
80
+ "Import": "lib/services/mybean:MyBean",
81
+ "Schema": { ... }
82
+ }
83
+ },
84
+ "moddas": {
85
+ "MyApp/MyService": {
86
+ "Import": "lib/services/myservice:MyService",
87
+ "Schema": { ... }
88
+ }
89
+ },
90
+ "models": {
91
+ "MyApp/Post": {
92
+ "Import": "lib/models/post:Post",
93
+ "Schema": { ... }
94
+ }
95
+ },
96
+ "deployers": {},
97
+ "schemas": {}
98
+ }
99
+ ```
100
+
101
+ ### See also
102
+
103
+ - [Build reference](../../docs/pages/Modules/compiler/Build.md)
104
+ - [Code generation](../../docs/pages/Modules/compiler/CodeGen.md)
105
+ - [Module manifest](../../docs/pages/Modules/compiler/ModuleManifest.md)
106
+ - [Extending the compiler](../../docs/pages/Modules/compiler/Plugins.md)
107
+
108
+ <!-- README_FOOTER -->
109
+ ## Sponsors
110
+
111
+ <!--
112
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](mailto:sponsor@webda.io)
113
+ -->
114
+
115
+ Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
116
+
117
+ [<img src="https://arize.com/hubfs/arize/brand/arize-logomark-1.png" width="200">](https://arize.com)
118
+
119
+ Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
120
+
121
+ [<img src="https://loopingz.com/images/logo.png" width="200">](https://loopingz.com)
122
+
123
+ Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
124
+
125
+ [<img src="https://tellae.fr/" width="200">](https://tellae.fr)
@@ -0,0 +1,88 @@
1
+ import type { WebdaProject } from "./definition.js";
2
+ /**
3
+ * Compiler
4
+ *
5
+ * Builds an application on TypeScript 7.1 through `@webda/content-mapper`:
6
+ * the two-pass build emits the JavaScript — generated accessors, behaviours
7
+ * and WebdaQL rewrites included, type-checked as written — and the same
8
+ * process generates `webda.module.json`. See `schema-backend.ts` for why it
9
+ * runs out of process, and `docs/contribute/TypeScript 7 Content Mappers.md`
10
+ * for the migration.
11
+ */
12
+ export declare class Compiler {
13
+ project: WebdaProject;
14
+ /**
15
+ * If true the compiler has compiled already
16
+ */
17
+ compiled: boolean;
18
+ /** File watcher when in watch mode. */
19
+ private watcher?;
20
+ /** Pending rebuild in watch mode, debounced. */
21
+ private rebuild?;
22
+ /**
23
+ * True while rebuilding because `.webda/module.d.ts` changed
24
+ */
25
+ private secondPass;
26
+ /**
27
+ * Read the generated TypeScript library, if any
28
+ * @param file - path to `.webda/module.d.ts`
29
+ * @returns its content, or undefined when it does not exist
30
+ */
31
+ private readLibrary;
32
+ /**
33
+ * Create a new compiler for the given project
34
+ * @param project - the Webda project to compile
35
+ */
36
+ constructor(project: WebdaProject);
37
+ /**
38
+ * MD5 hex digest of a file's contents.
39
+ * @param path - absolute path to the file
40
+ * @returns the digest, or undefined if the file is missing
41
+ */
42
+ private fileDigest;
43
+ /**
44
+ * Add a system to recompile if needed
45
+ * @returns true if compilation is needed
46
+ */
47
+ requireCompilation(): boolean;
48
+ /**
49
+ * Whether an emitted file the module points at is missing.
50
+ *
51
+ * Every `Import` in `webda.module.json` names an emitted file
52
+ * (`lib/services/audit.model:AuditService`), so checking them follows the
53
+ * configured `outDir` and catches a partially deleted output. A module that
54
+ * declares nothing falls back to `lib/` existing.
55
+ * @param mod - the parsed `webda.module.json`
56
+ * @returns true if at least one output is missing
57
+ */
58
+ private missingOutputs;
59
+ /**
60
+ * This is our main entry point
61
+ * @param force - skip cache and force recompilation
62
+ * @returns true if compilation succeeded
63
+ */
64
+ compile(force?: boolean): boolean;
65
+ /**
66
+ * Persist the build cache: source digest plus the generated module file's
67
+ * content hash, so {@link requireCompilation} can detect both source-file
68
+ * changes and external mutations of webda.module.json.
69
+ */
70
+ private updateCache;
71
+ /**
72
+ * Launch compiler in watch mode
73
+ *
74
+ * Rebuilds on any change under `src/`, debounced. The TypeScript 6 version
75
+ * drove a `createWatchProgram`; there is no incremental emit with generated
76
+ * code in 7.1's API, and a full two-pass build is fast enough — well under
77
+ * a second for `@webda/core` — that a resident incremental program is not
78
+ * worth its complexity yet.
79
+ * @param callback - called with `MODULE_GENERATION` / `MODULE_GENERATED`
80
+ * around each rebuild, and with `COMPILATION_ERROR` when one fails
81
+ */
82
+ watch(callback?: (event: string) => void): void;
83
+ /**
84
+ * Stop watching for changes
85
+ */
86
+ stopWatch(): void;
87
+ }
88
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIpD;;;;;;;;;GASG;AACH,qBAAa,QAAQ;IA2BA,OAAO,EAAE,YAAY;IA1BxC;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,OAAO,CAAC,OAAO,CAAC,CAAY;IAC5B,gDAAgD;IAChD,OAAO,CAAC,OAAO,CAAC,CAAiB;IACjC;;OAEG;IACH,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAInB;;;OAGG;IACH,YAAmB,OAAO,EAAE,YAAY,EAAI;IAE5C;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAOlB;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAsC5B;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAetB;;;;OAIG;IACH,OAAO,CAAC,KAAK,GAAE,OAAe,GAAG,OAAO,CA0DvC;IAED;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,QAAQ,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe,QAWjD;IAED;;OAEG;IACH,SAAS,SAKR;CACF"}
@@ -0,0 +1,230 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, mkdirSync, readFileSync, watch as watchFiles } from "node:fs";
3
+ import { FileUtils } from "@webda/utils";
4
+ import { useLog } from "@webda/workout";
5
+ import { writeModule } from "./module.js";
6
+ import { build } from "./schema-backend.js";
7
+ /**
8
+ * Compiler
9
+ *
10
+ * Builds an application on TypeScript 7.1 through `@webda/content-mapper`:
11
+ * the two-pass build emits the JavaScript — generated accessors, behaviours
12
+ * and WebdaQL rewrites included, type-checked as written — and the same
13
+ * process generates `webda.module.json`. See `schema-backend.ts` for why it
14
+ * runs out of process, and `docs/contribute/TypeScript 7 Content Mappers.md`
15
+ * for the migration.
16
+ */
17
+ export class Compiler {
18
+ project;
19
+ /**
20
+ * If true the compiler has compiled already
21
+ */
22
+ compiled;
23
+ /** File watcher when in watch mode. */
24
+ watcher;
25
+ /** Pending rebuild in watch mode, debounced. */
26
+ rebuild;
27
+ /**
28
+ * True while rebuilding because `.webda/module.d.ts` changed
29
+ */
30
+ secondPass = false;
31
+ /**
32
+ * Read the generated TypeScript library, if any
33
+ * @param file - path to `.webda/module.d.ts`
34
+ * @returns its content, or undefined when it does not exist
35
+ */
36
+ readLibrary(file) {
37
+ return existsSync(file) ? readFileSync(file, "utf8") : undefined;
38
+ }
39
+ /**
40
+ * Create a new compiler for the given project
41
+ * @param project - the Webda project to compile
42
+ */
43
+ constructor(project) {
44
+ this.project = project;
45
+ }
46
+ /**
47
+ * MD5 hex digest of a file's contents.
48
+ * @param path - absolute path to the file
49
+ * @returns the digest, or undefined if the file is missing
50
+ */
51
+ fileDigest(path) {
52
+ if (!existsSync(path)) {
53
+ return undefined;
54
+ }
55
+ return createHash("md5").update(readFileSync(path)).digest("hex");
56
+ }
57
+ /**
58
+ * Add a system to recompile if needed
59
+ * @returns true if compilation is needed
60
+ */
61
+ requireCompilation() {
62
+ const f = this.project.getAppPath(".webda/cache");
63
+ if (!existsSync(this.project.getAppPath(".webda"))) {
64
+ mkdirSync(this.project.getAppPath(".webda"));
65
+ }
66
+ if (!existsSync(f)) {
67
+ return true;
68
+ }
69
+ const webdaCache = FileUtils.load(f, "json");
70
+ const currentDigest = this.project.getDigest();
71
+ if (webdaCache.sourceDigest !== currentDigest) {
72
+ return true;
73
+ }
74
+ // Cross-check the on-disk webda.module.json: sources may be unchanged but
75
+ // the generated module file can drift from the cache (git checkout, manual
76
+ // edit, framework upgrade that regenerates it).
77
+ const modulePath = this.project.getAppPath("webda.module.json");
78
+ const moduleDigest = this.fileDigest(modulePath);
79
+ if (!moduleDigest || moduleDigest !== webdaCache.moduleDigest) {
80
+ return true;
81
+ }
82
+ let moduleContent;
83
+ try {
84
+ moduleContent = FileUtils.load(modulePath, "json");
85
+ }
86
+ catch {
87
+ return true;
88
+ }
89
+ // The output has to exist too. The digests only describe the inputs, so
90
+ // without this a deleted `lib/` — or a single deleted file in it — was
91
+ // reported as up to date.
92
+ if (this.missingOutputs(moduleContent)) {
93
+ return true;
94
+ }
95
+ useLog("DEBUG", "Skipping compilation as nothing changed");
96
+ return false;
97
+ }
98
+ /**
99
+ * Whether an emitted file the module points at is missing.
100
+ *
101
+ * Every `Import` in `webda.module.json` names an emitted file
102
+ * (`lib/services/audit.model:AuditService`), so checking them follows the
103
+ * configured `outDir` and catches a partially deleted output. A module that
104
+ * declares nothing falls back to `lib/` existing.
105
+ * @param mod - the parsed `webda.module.json`
106
+ * @returns true if at least one output is missing
107
+ */
108
+ missingOutputs(mod) {
109
+ const files = new Set();
110
+ for (const section of ["beans", "deployers", "moddas", "models", "behaviors"]) {
111
+ for (const entry of Object.values(mod[section] ?? {})) {
112
+ if (typeof entry?.Import === "string") {
113
+ files.add(entry.Import.split(":")[0]);
114
+ }
115
+ }
116
+ }
117
+ if (files.size === 0) {
118
+ return !existsSync(this.project.getAppPath("lib"));
119
+ }
120
+ return [...files].some(file => !existsSync(this.project.getAppPath(`${file}.js`)));
121
+ }
122
+ /**
123
+ * This is our main entry point
124
+ * @param force - skip cache and force recompilation
125
+ * @returns true if compilation succeeded
126
+ */
127
+ compile(force = false) {
128
+ if ((this.compiled || !this.requireCompilation()) && !force) {
129
+ return true;
130
+ }
131
+ this.project.emit("compiling");
132
+ const started = Date.now();
133
+ const library = this.project.getAppPath(".webda/module.d.ts");
134
+ const libraryBefore = this.readLibrary(library);
135
+ let result;
136
+ try {
137
+ result = build(this.project.getAppPath(), {
138
+ namespace: this.project.namespace,
139
+ capabilities: this.project.packageDescription.webda?.capabilities
140
+ });
141
+ }
142
+ catch (err) {
143
+ useLog("ERROR", err.message);
144
+ this.project.emit("compilationError");
145
+ return false;
146
+ }
147
+ if (result.emit.diagnosticCount) {
148
+ result.emit.diagnostics
149
+ .split("\n")
150
+ .filter(line => line.trim() !== "")
151
+ .forEach(line => this.project.log("WARN", line));
152
+ this.project.emit("compilationError");
153
+ return false;
154
+ }
155
+ const compilation = Date.now() - started;
156
+ const moduleStart = Date.now();
157
+ this.project.emit("analyzing");
158
+ // A module that cannot be written fails the build. Under TypeScript 6 the
159
+ // error was logged and the build still reported success, so a strict
160
+ // file-naming violation never actually stopped anything.
161
+ if (!result.module || !writeModule(this, result.module)) {
162
+ this.project.emit("compilationError");
163
+ return false;
164
+ }
165
+ useLog("INFO", `Took: Compilation - ${compilation}ms | Module generation - ${Date.now() - moduleStart}ms`);
166
+ // writeModule regenerates .webda/module.d.ts, which declares the configured
167
+ // services and beans in ServicesMap. The schemas just written were derived
168
+ // from the previous version, so when it changed (a clean checkout, a new
169
+ // service) build once more against the new one.
170
+ if (!this.secondPass && this.readLibrary(library) !== libraryBefore) {
171
+ useLog("INFO", "Service map changed; rebuilding the module against it");
172
+ this.secondPass = true;
173
+ try {
174
+ return this.compile(true);
175
+ }
176
+ finally {
177
+ this.secondPass = false;
178
+ }
179
+ }
180
+ this.compiled = true;
181
+ this.updateCache();
182
+ this.project.emit("done");
183
+ return true;
184
+ }
185
+ /**
186
+ * Persist the build cache: source digest plus the generated module file's
187
+ * content hash, so {@link requireCompilation} can detect both source-file
188
+ * changes and external mutations of webda.module.json.
189
+ */
190
+ updateCache() {
191
+ const f = this.project.getAppPath(".webda/cache");
192
+ const webdaCache = existsSync(f) ? FileUtils.load(f, "json") : {};
193
+ webdaCache.sourceDigest = this.project.getDigest();
194
+ webdaCache.moduleDigest = this.fileDigest(this.project.getAppPath("webda.module.json"));
195
+ FileUtils.save(webdaCache, f, "json");
196
+ }
197
+ /**
198
+ * Launch compiler in watch mode
199
+ *
200
+ * Rebuilds on any change under `src/`, debounced. The TypeScript 6 version
201
+ * drove a `createWatchProgram`; there is no incremental emit with generated
202
+ * code in 7.1's API, and a full two-pass build is fast enough — well under
203
+ * a second for `@webda/core` — that a resident incremental program is not
204
+ * worth its complexity yet.
205
+ * @param callback - called with `MODULE_GENERATION` / `MODULE_GENERATED`
206
+ * around each rebuild, and with `COMPILATION_ERROR` when one fails
207
+ */
208
+ watch(callback = () => { }) {
209
+ const run = () => {
210
+ callback("MODULE_GENERATION");
211
+ const ok = this.compile(true);
212
+ callback(ok ? "MODULE_GENERATED" : "COMPILATION_ERROR");
213
+ };
214
+ this.watcher = watchFiles(this.project.getAppPath("src"), { recursive: true }, () => {
215
+ clearTimeout(this.rebuild);
216
+ this.rebuild = setTimeout(run, 150);
217
+ });
218
+ run();
219
+ }
220
+ /**
221
+ * Stop watching for changes
222
+ */
223
+ stopWatch() {
224
+ clearTimeout(this.rebuild);
225
+ this.watcher?.close();
226
+ this.watcher = undefined;
227
+ this.compiled = false;
228
+ }
229
+ }
230
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,IAAI,UAAU,EAAkB,MAAM,SAAS,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAQ;IA2BA,OAAO;IA1B1B;;OAEG;IACH,QAAQ,CAAU;IAClB,uCAAuC;IAC/B,OAAO,CAAa;IAC5B,gDAAgD;IACxC,OAAO,CAAkB;IACjC;;OAEG;IACK,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;OAIG;IACK,WAAW,CAAC,IAAY;QAC9B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CA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G,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QACH,GAAG,EAAE,CAAC;IACR,CAAC;IAED;;OAEG;IACH,SAAS;QACP,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ /**
3
+ * Interface for the application methods needed by configuration schema generation
4
+ */
5
+ export interface ConfigSchemaApplication {
6
+ getModdas(): {
7
+ [key: string]: any;
8
+ };
9
+ getSchema(type: string): JSONSchema7;
10
+ getDeployers(): {
11
+ [key: string]: any;
12
+ };
13
+ getConfiguration(): {
14
+ services: {
15
+ [key: string]: any;
16
+ };
17
+ };
18
+ getModules(): {
19
+ beans?: {
20
+ [key: string]: any;
21
+ };
22
+ };
23
+ completeNamespace(name: string): string;
24
+ }
25
+ /**
26
+ * Generate the configuration and deployment schemas
27
+ *
28
+ * @param app to use for application metadata
29
+ * @param filename to save config schema to
30
+ * @param deploymentFilename to save deployment schema to
31
+ * @param full to keep all required
32
+ * @param configFile - optional config file path to update $schema reference
33
+ */
34
+ export declare function generateConfigurationSchemas(app: ConfigSchemaApplication, filename?: string, deploymentFilename?: string, full?: boolean, configFile?: string): void;
35
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,SAAS,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IACpC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IACrC,YAAY,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IACvC,gBAAgB,IAAI;QAAE,QAAQ,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAA;KAAE,CAAC;IACzD,UAAU,IAAI;QAAE,KAAK,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAA;KAAE,CAAC;IACjD,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACzC;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,uBAAuB,EAC5B,QAAQ,GAAE,MAAoC,EAC9C,kBAAkB,GAAE,MAAwC,EAC5D,IAAI,GAAE,OAAe,EACrB,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI,CAmJN"}