@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.
- package/LICENSE +166 -0
- package/README.md +125 -0
- package/lib/compiler.d.ts +88 -0
- package/lib/compiler.d.ts.map +1 -0
- package/lib/compiler.js +230 -0
- package/lib/compiler.js.map +1 -0
- package/lib/configuration.d.ts +35 -0
- package/lib/configuration.d.ts.map +1 -0
- package/lib/configuration.js +170 -0
- package/lib/configuration.js.map +1 -0
- package/lib/definition.d.ts +787 -0
- package/lib/definition.d.ts.map +1 -0
- package/lib/definition.js +189 -0
- package/lib/definition.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/module.d.ts +36 -0
- package/lib/module.d.ts.map +1 -0
- package/lib/module.js +119 -0
- package/lib/module.js.map +1 -0
- package/lib/morpher/capabilities.d.ts +35 -0
- package/lib/morpher/capabilities.d.ts.map +1 -0
- package/lib/morpher/capabilities.js +66 -0
- package/lib/morpher/capabilities.js.map +1 -0
- package/lib/morpher/imports.d.ts +10 -0
- package/lib/morpher/imports.d.ts.map +1 -0
- package/lib/morpher/imports.js +97 -0
- package/lib/morpher/imports.js.map +1 -0
- package/lib/morpher/morpher.d.ts +34 -0
- package/lib/morpher/morpher.d.ts.map +1 -0
- package/lib/morpher/morpher.js +87 -0
- package/lib/morpher/morpher.js.map +1 -0
- package/lib/operations.d.ts +29 -0
- package/lib/operations.d.ts.map +1 -0
- package/lib/operations.js +197 -0
- package/lib/operations.js.map +1 -0
- package/lib/schema-backend.d.ts +55 -0
- package/lib/schema-backend.d.ts.map +1 -0
- package/lib/schema-backend.js +86 -0
- package/lib/schema-backend.js.map +1 -0
- package/lib/session-types.d.ts +14 -0
- package/lib/session-types.d.ts.map +1 -0
- package/lib/session-types.js +79 -0
- package/lib/session-types.js.map +1 -0
- package/lib/shell-build-dispatch.d.ts +54 -0
- package/lib/shell-build-dispatch.d.ts.map +1 -0
- package/lib/shell-build-dispatch.js +77 -0
- package/lib/shell-build-dispatch.js.map +1 -0
- package/lib/shell.d.ts +3 -0
- package/lib/shell.d.ts.map +1 -0
- package/lib/shell.js +297 -0
- package/lib/shell.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAwC/C,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,aAAa,GAAG,oBAAoB,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACrC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,KAAK,EAAE,MAAM,CA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;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,sBAAsB,CAAC;IAC9B;;OAEG;IACH,GAAG,EAAE,cAAc,CAAC;IACpB;;OAEG;IACH,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,iGAAiG;AACjG,qBAAa,YAAY;IAQrB,SAAS,CAAC,MAAM,EAAE,MAAM;IACxB,SAAS,CAAC,MAAM,EAAE,YAAY;IARhC,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,iBAAiB,CAAC;IACtC;;;OAGG;IACH,YACY,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,YAAiC,EAYpD;IAED;;;OAGG;IACH,aAAa,IAAI,OAAO,CAOvB;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;;OAGG;IACH,SAAS,IAAI,MAAM,CAuBlB;IAED;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,QAI5B;IAED;;;;OAIG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,QAEnD;IAED;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,QAEjC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,UAKvB;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,QAExC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAK7B;CACF"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { FileUtils } from "@webda/utils";
|
|
2
|
+
import { WorkerOutput } from "@webda/workout";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
import { existsSync, globSync, readFileSync } from "fs";
|
|
5
|
+
import { dirname, join } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the running @webda/compiler installation root and its lib/ dir.
|
|
9
|
+
*
|
|
10
|
+
* Anchored on the compiler's package.json — not on `import.meta.url` —
|
|
11
|
+
* because under vitest the TS source is served directly, so the running
|
|
12
|
+
* file lives in `src/` rather than `lib/`. Hashing `src/` at test time
|
|
13
|
+
* but `lib/` at build time would otherwise produce different digests
|
|
14
|
+
* for the same logical compiler version.
|
|
15
|
+
*
|
|
16
|
+
* @returns the resolved package root and lib directory, or undefined
|
|
17
|
+
* if the compiler isn't installed in a standard layout
|
|
18
|
+
*/
|
|
19
|
+
function resolveCompilerLayout() {
|
|
20
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
/* c8 ignore next 14 -- defensive walk for non-standard installs */
|
|
22
|
+
while (true) {
|
|
23
|
+
const pkgPath = join(dir, "package.json");
|
|
24
|
+
if (existsSync(pkgPath)) {
|
|
25
|
+
try {
|
|
26
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
27
|
+
if (pkg.name === "@webda/compiler") {
|
|
28
|
+
const main = typeof pkg.main === "string" ? pkg.main : "lib/index.js";
|
|
29
|
+
return { root: dir, lib: dirname(join(dir, main)) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
/* malformed package.json — keep walking */
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const parent = dirname(dir);
|
|
37
|
+
if (parent === dir)
|
|
38
|
+
return undefined;
|
|
39
|
+
dir = parent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const COMPILER_LAYOUT = resolveCompilerLayout();
|
|
43
|
+
/** Represents a Webda project on disk, providing access to package metadata and project paths */
|
|
44
|
+
export class WebdaProject {
|
|
45
|
+
folder;
|
|
46
|
+
output;
|
|
47
|
+
namespace;
|
|
48
|
+
packageDescription;
|
|
49
|
+
/** Create a new WebdaProject.
|
|
50
|
+
* @param folder - path to the project root
|
|
51
|
+
* @param output - worker output for logging
|
|
52
|
+
*/
|
|
53
|
+
constructor(folder, output = new WorkerOutput()) {
|
|
54
|
+
this.folder = folder;
|
|
55
|
+
this.output = output;
|
|
56
|
+
if (!existsSync(folder) || !existsSync(join(folder, "package.json"))) {
|
|
57
|
+
throw new Error(`Invalid folder ${folder}`);
|
|
58
|
+
}
|
|
59
|
+
this.packageDescription = JSON.parse(readFileSync(join(folder, "package.json")).toString());
|
|
60
|
+
this.namespace = this.packageDescription.webda?.namespace;
|
|
61
|
+
if (!this.namespace && this.packageDescription.name.startsWith("@")) {
|
|
62
|
+
this.namespace = this.packageDescription.name.split("/")[0].substring(1);
|
|
63
|
+
this.namespace = this.namespace.charAt(0).toUpperCase() + this.namespace.slice(1);
|
|
64
|
+
}
|
|
65
|
+
this.namespace ??= "Webda";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if the project is a webda application
|
|
69
|
+
* @returns true if a webda.config file exists
|
|
70
|
+
*/
|
|
71
|
+
isApplication() {
|
|
72
|
+
try {
|
|
73
|
+
FileUtils.getConfigurationFile(join(this.folder, "webda.config"));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Mix the running @webda/compiler's package.json + lib/ contents into the
|
|
82
|
+
* digest. Catches both published version bumps (via package.json) and
|
|
83
|
+
* local rebuilds of a linked workspace dep (via lib/ files), since neither
|
|
84
|
+
* project source nor tsconfig change when a framework dep updates.
|
|
85
|
+
*
|
|
86
|
+
* @param hash - the digest accumulator to update
|
|
87
|
+
*/
|
|
88
|
+
hashCompilerPackage(hash) {
|
|
89
|
+
if (!COMPILER_LAYOUT)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
hash.update(readFileSync(join(COMPILER_LAYOUT.root, "package.json")));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
/* package.json vanished mid-flight — skip */
|
|
96
|
+
}
|
|
97
|
+
if (!existsSync(COMPILER_LAYOUT.lib))
|
|
98
|
+
return;
|
|
99
|
+
globSync("**/*", { cwd: COMPILER_LAYOUT.lib, withFileTypes: true })
|
|
100
|
+
.filter(f => f.isFile())
|
|
101
|
+
.map(f => join(f.parentPath, f.name))
|
|
102
|
+
.sort()
|
|
103
|
+
.forEach(f => hash.update(readFileSync(f)));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Compute digest of the source files
|
|
107
|
+
* @returns the MD5 hex digest of the source
|
|
108
|
+
*/
|
|
109
|
+
getDigest() {
|
|
110
|
+
const current = createHash("md5");
|
|
111
|
+
const tsCfg = readFileSync(this.getAppPath("tsconfig.json"));
|
|
112
|
+
current.update(tsCfg);
|
|
113
|
+
// Only `include` / `exclude` are read. FileUtils.load parses the JSONC a
|
|
114
|
+
// tsconfig is written in, and agrees with TypeScript's own parser on
|
|
115
|
+
// every tsconfig in the repository, so the digest is unchanged.
|
|
116
|
+
const tsParsed = FileUtils.load(this.getAppPath("tsconfig.json"));
|
|
117
|
+
// Maybe just use the mtime of tsconfig + all files?
|
|
118
|
+
globSync(tsParsed.include || ["**/*"], {
|
|
119
|
+
cwd: this.getAppPath(""),
|
|
120
|
+
exclude: tsParsed.exclude,
|
|
121
|
+
withFileTypes: true
|
|
122
|
+
})
|
|
123
|
+
.filter(f => f.isFile())
|
|
124
|
+
.map(f => join(f.parentPath, f.name))
|
|
125
|
+
.sort()
|
|
126
|
+
.forEach(f => {
|
|
127
|
+
current.update(readFileSync(f));
|
|
128
|
+
});
|
|
129
|
+
this.hashCompilerPackage(current);
|
|
130
|
+
// We might want to consider doing the same with the output files?
|
|
131
|
+
return current.digest("hex");
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Ensure a dependency is declared
|
|
135
|
+
* @param name - the package name to check
|
|
136
|
+
*/
|
|
137
|
+
ensureDependency(name) {
|
|
138
|
+
if (!this.packageDescription.dependencies || !this.packageDescription.dependencies[name]) {
|
|
139
|
+
throw new Error(`Package ${name} is not declared as a dependency in package.json`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Subscribe to output events
|
|
144
|
+
* @param event - event name
|
|
145
|
+
* @param listener - callback function
|
|
146
|
+
*/
|
|
147
|
+
on(event, listener) {
|
|
148
|
+
this.output.on(event, listener);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Emit an output event
|
|
152
|
+
* @param event - event name
|
|
153
|
+
* @param args - event arguments
|
|
154
|
+
*/
|
|
155
|
+
emit(event, ...args) {
|
|
156
|
+
this.output.emit(event, ...args);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get an absolute path within the project folder, or the project root if no path given
|
|
160
|
+
* @param path - relative path within the project
|
|
161
|
+
* @returns the absolute path
|
|
162
|
+
*/
|
|
163
|
+
getAppPath(path) {
|
|
164
|
+
if (!path) {
|
|
165
|
+
return this.folder;
|
|
166
|
+
}
|
|
167
|
+
return join(this.folder, path);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Log a message at the specified level through the worker output
|
|
171
|
+
* @param level - log level
|
|
172
|
+
* @param args - log arguments
|
|
173
|
+
*/
|
|
174
|
+
log(level, ...args) {
|
|
175
|
+
this.output.log(level, ...args);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Prefix a name with the project namespace if it does not already contain one
|
|
179
|
+
* @param name - the name to prefix
|
|
180
|
+
* @returns the namespaced name
|
|
181
|
+
*/
|
|
182
|
+
completeNamespace(name) {
|
|
183
|
+
if (!name.includes("/")) {
|
|
184
|
+
return `${this.namespace}/${name}`;
|
|
185
|
+
}
|
|
186
|
+
return name;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=definition.js.map
|
|
@@ -0,0 +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AC,KAAa,EAAE,GAAG,IAAW;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAAa;QACtB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAqB,EAAE,GAAG,IAAW;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,IAAY;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;QACrC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
package/lib/module.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Compiler } from "./compiler.js";
|
|
2
|
+
import type { WebdaModule } from "./definition.js";
|
|
3
|
+
import type { GeneratedModule, NamingViolation } from "./schema-backend.js";
|
|
4
|
+
export type { NamingViolation };
|
|
5
|
+
/**
|
|
6
|
+
* Report Webda classes declared in files the content mapper cannot claim.
|
|
7
|
+
*
|
|
8
|
+
* Under TypeScript 7 the accessor and behaviour generation runs as a content
|
|
9
|
+
* mapper, and a mapper can only claim files by extension — never plain `.ts`
|
|
10
|
+
* (TS100021). A model in `user.ts` instead of `user.model.ts` is therefore
|
|
11
|
+
* never transformed, compiles cleanly, and breaks only at runtime. Strict by
|
|
12
|
+
* default; `WEBDA_STRICT_FILE_NAMING=0` downgrades it to a warning while an
|
|
13
|
+
* application migrates. See `docs/contribute/TypeScript 7 Content Mappers.md` §8.
|
|
14
|
+
* @param compiler - the compiler whose project is being built
|
|
15
|
+
* @param violations - classes in unclaimable files
|
|
16
|
+
* @throws when strict and any violation exists
|
|
17
|
+
*/
|
|
18
|
+
export declare function reportNamingViolations(compiler: Compiler, violations: NamingViolation[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Write the generated module and its derived files.
|
|
21
|
+
*
|
|
22
|
+
* Refuses to write when generation reported errors — the cases the
|
|
23
|
+
* TypeScript 6 generator threw on, such as an unresolved relation target —
|
|
24
|
+
* so a partial module never replaces a complete one.
|
|
25
|
+
* @param compiler - the compiler whose project is being built
|
|
26
|
+
* @param generated - the generator's answer
|
|
27
|
+
* @returns the module written, or undefined when generation failed
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeModule(compiler: Compiler, generated: GeneratedModule): WebdaModule | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Generate TypeScript library for the module
|
|
32
|
+
* @param compiler - the compiler whose project is being built
|
|
33
|
+
* @param mod - the Webda module metadata
|
|
34
|
+
*/
|
|
35
|
+
export declare function generateTypescriptLibrary(compiler: Compiler, mod: WebdaModule): void;
|
|
36
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG5E,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,IAAI,CAe9F;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,GAAG,WAAW,GAAG,SAAS,CAiBnG;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,WAAW,QA8C7E"}
|
package/lib/module.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write `webda.module.json` from what `@webda/content-mapper` generated.
|
|
3
|
+
*
|
|
4
|
+
* Module generation used to live here: 1,300 lines walking a TypeScript 6
|
|
5
|
+
* program, plus seven metadata plugins. It now runs on TypeScript 7.1 in the
|
|
6
|
+
* content mapper's worker, which produces every section byte for byte as
|
|
7
|
+
* this code did (`packages/content-mapper/tools/module-diff.mjs`). What is
|
|
8
|
+
* left is the part that needs no checker: the source digest, the file-naming
|
|
9
|
+
* guard, writing the file, and the application's `.webda/module.d.ts`.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { dirname, relative } from "node:path";
|
|
13
|
+
import { FileUtils } from "@webda/utils";
|
|
14
|
+
import { useLog } from "@webda/workout";
|
|
15
|
+
import { generateSessionTypes } from "./session-types.js";
|
|
16
|
+
/**
|
|
17
|
+
* Report Webda classes declared in files the content mapper cannot claim.
|
|
18
|
+
*
|
|
19
|
+
* Under TypeScript 7 the accessor and behaviour generation runs as a content
|
|
20
|
+
* mapper, and a mapper can only claim files by extension — never plain `.ts`
|
|
21
|
+
* (TS100021). A model in `user.ts` instead of `user.model.ts` is therefore
|
|
22
|
+
* never transformed, compiles cleanly, and breaks only at runtime. Strict by
|
|
23
|
+
* default; `WEBDA_STRICT_FILE_NAMING=0` downgrades it to a warning while an
|
|
24
|
+
* application migrates. See `docs/contribute/TypeScript 7 Content Mappers.md` §8.
|
|
25
|
+
* @param compiler - the compiler whose project is being built
|
|
26
|
+
* @param violations - classes in unclaimable files
|
|
27
|
+
* @throws when strict and any violation exists
|
|
28
|
+
*/
|
|
29
|
+
export function reportNamingViolations(compiler, violations) {
|
|
30
|
+
if (!violations.length)
|
|
31
|
+
return;
|
|
32
|
+
const strict = process.env.WEBDA_STRICT_FILE_NAMING !== "0";
|
|
33
|
+
const lines = violations.map(v => ` - ${relative(compiler.project.getAppPath(), v.fileName)} declares ${v.section.replace(/s$/, "")} '${v.className}' but is not a mapped file; rename it to '${v.expectedSuffix}'`);
|
|
34
|
+
const message = `${violations.length} Webda class(es) are in files the content mapper cannot claim:\n` +
|
|
35
|
+
`${lines.join("\n")}\n` +
|
|
36
|
+
`A content mapper cannot register the built-in '.ts' extension, so these files are never transformed.`;
|
|
37
|
+
if (strict)
|
|
38
|
+
throw new Error(message);
|
|
39
|
+
useLog("WARN", message);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Write the generated module and its derived files.
|
|
43
|
+
*
|
|
44
|
+
* Refuses to write when generation reported errors — the cases the
|
|
45
|
+
* TypeScript 6 generator threw on, such as an unresolved relation target —
|
|
46
|
+
* so a partial module never replaces a complete one.
|
|
47
|
+
* @param compiler - the compiler whose project is being built
|
|
48
|
+
* @param generated - the generator's answer
|
|
49
|
+
* @returns the module written, or undefined when generation failed
|
|
50
|
+
*/
|
|
51
|
+
export function writeModule(compiler, generated) {
|
|
52
|
+
try {
|
|
53
|
+
reportNamingViolations(compiler, generated.namingViolations);
|
|
54
|
+
if (generated.errors.length) {
|
|
55
|
+
throw new Error(generated.errors.join("\n"));
|
|
56
|
+
}
|
|
57
|
+
const mod = generated.module;
|
|
58
|
+
FileUtils.save(mod, compiler.project.getAppPath("webda.module.json"));
|
|
59
|
+
if (compiler.project.isApplication()) {
|
|
60
|
+
generateTypescriptLibrary(compiler, mod);
|
|
61
|
+
}
|
|
62
|
+
return mod;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
useLog("ERROR", "Cannot generate module", err.message);
|
|
66
|
+
useLog("TRACE", err.stack);
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate TypeScript library for the module
|
|
72
|
+
* @param compiler - the compiler whose project is being built
|
|
73
|
+
* @param mod - the Webda module metadata
|
|
74
|
+
*/
|
|
75
|
+
export function generateTypescriptLibrary(compiler, mod) {
|
|
76
|
+
// Should generate typescript library file: .webda/webda.module.ts
|
|
77
|
+
// Read the webda.module.json and generate a type for ServiceName
|
|
78
|
+
// And for ModelName
|
|
79
|
+
// So we can have type safe access to services and models
|
|
80
|
+
const config = FileUtils.loadConfigurationFile(compiler.project.getAppPath("webda.config"));
|
|
81
|
+
let content = `import "@webda/core";\ndeclare module "@webda/core" {\n`;
|
|
82
|
+
// Services Map
|
|
83
|
+
content += ` interface ServicesMap {\n`;
|
|
84
|
+
Object.keys(config.services || {})
|
|
85
|
+
.sort()
|
|
86
|
+
.forEach(name => {
|
|
87
|
+
content += ` ${name}: never;\n`;
|
|
88
|
+
return;
|
|
89
|
+
// Resolve service type
|
|
90
|
+
content += ` ${name}: import("${mod.moddas[name].Import.split(":")[0]}").${mod.moddas[name].Import.split(":")[1]};\n`;
|
|
91
|
+
});
|
|
92
|
+
Object.keys(mod.beans || {})
|
|
93
|
+
.sort()
|
|
94
|
+
.forEach(name => {
|
|
95
|
+
const [file, importName] = mod.beans[name].Import.split(":");
|
|
96
|
+
// Add import at the top
|
|
97
|
+
content = `import { ${importName} } from "${file}";\n` + content;
|
|
98
|
+
// Add to services map
|
|
99
|
+
content += ` ${name.split("/").pop()}: ${importName};\n`;
|
|
100
|
+
});
|
|
101
|
+
content += ` }\n\n`;
|
|
102
|
+
// Models Map
|
|
103
|
+
content += `}`;
|
|
104
|
+
content = `// This file is autogenerated by Webda, do not edit\n\n` + content;
|
|
105
|
+
const outPath = compiler.project.getAppPath(".webda/module.d.ts");
|
|
106
|
+
if (!existsSync(dirname(outPath))) {
|
|
107
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
writeFileSync(outPath, content);
|
|
110
|
+
useLog("INFO", `Generated TypeScript library at .webda/module.d.ts`);
|
|
111
|
+
try {
|
|
112
|
+
generateSessionTypes(compiler.project.getAppPath());
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
useLog("ERROR", "Failed to generate session types:", err.message);
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAI1D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAkB,EAAE,UAA6B;IACtF,IAAI,CAAC,UAAU,CAAC,MA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C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7D,wBAAwB;QACxB,OAAO,GAAG,YAAY,UAAU,YAAY,IAAI,MAAM,GAAG,OAAO,CAAC;QACjE,sBAAsB;QACtB,OAAO,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,UAAU,KAAK,CAAC;IAC9D,CAAC,CAAC,CAAC;IACL,OAAO,IAAI,SAAS,CAAC;IACrB,aAAa;IACb,OAAO,IAAI,GAAG,CAAC;IAEf,OAAO,GAAG,yDAAyD,GAAG,OAAO,CAAC;IAC9E,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAClE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAClC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,CAAC,MAAM,EAAE,oDAAoD,CAAC,CAAC;IAErE,IAAI,CAAC;QACH,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,OAAO,EAAE,mCAAmC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SourceFile } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* Morpher module that removes manual `registerRequestFilter(this)` and
|
|
4
|
+
* `registerCORSFilter(this)` calls from service source files.
|
|
5
|
+
*
|
|
6
|
+
* These manual registrations are replaced by the capabilities auto-discovery
|
|
7
|
+
* system. The morpher only removes calls where the argument is `this`
|
|
8
|
+
* (service self-registration). Calls with other arguments (e.g., anonymous
|
|
9
|
+
* objects in test files) are preserved.
|
|
10
|
+
*
|
|
11
|
+
* Also removes commented-out versions of these calls (e.g.,
|
|
12
|
+
* `//this._webda.registerCORSFilter(this);`).
|
|
13
|
+
*
|
|
14
|
+
* @param sourceFile - The ts-morph SourceFile to transform (modified in place)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Before morpher:
|
|
19
|
+
* class HawkService extends Service {
|
|
20
|
+
* resolve() {
|
|
21
|
+
* this.getWebda().registerRequestFilter(this); // removed
|
|
22
|
+
* this.getWebda().registerCORSFilter(this); // removed
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // After morpher:
|
|
27
|
+
* class HawkService extends Service {
|
|
28
|
+
* resolve() {
|
|
29
|
+
* // calls removed — capability auto-discovery handles registration
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function removeFilterRegistrations(sourceFile: SourceFile): void;
|
|
35
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/morpher/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAAc,MAAM,UAAU,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAmCtE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SyntaxKind } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* Morpher module that removes manual `registerRequestFilter(this)` and
|
|
4
|
+
* `registerCORSFilter(this)` calls from service source files.
|
|
5
|
+
*
|
|
6
|
+
* These manual registrations are replaced by the capabilities auto-discovery
|
|
7
|
+
* system. The morpher only removes calls where the argument is `this`
|
|
8
|
+
* (service self-registration). Calls with other arguments (e.g., anonymous
|
|
9
|
+
* objects in test files) are preserved.
|
|
10
|
+
*
|
|
11
|
+
* Also removes commented-out versions of these calls (e.g.,
|
|
12
|
+
* `//this._webda.registerCORSFilter(this);`).
|
|
13
|
+
*
|
|
14
|
+
* @param sourceFile - The ts-morph SourceFile to transform (modified in place)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Before morpher:
|
|
19
|
+
* class HawkService extends Service {
|
|
20
|
+
* resolve() {
|
|
21
|
+
* this.getWebda().registerRequestFilter(this); // removed
|
|
22
|
+
* this.getWebda().registerCORSFilter(this); // removed
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // After morpher:
|
|
27
|
+
* class HawkService extends Service {
|
|
28
|
+
* resolve() {
|
|
29
|
+
* // calls removed — capability auto-discovery handles registration
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function removeFilterRegistrations(sourceFile) {
|
|
35
|
+
// --- Remove live call statements ---
|
|
36
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
37
|
+
const statementsToRemove = [];
|
|
38
|
+
for (const call of callExpressions) {
|
|
39
|
+
const callText = call.getText();
|
|
40
|
+
const isFilterCall = callText.includes("registerRequestFilter") || callText.includes("registerCORSFilter");
|
|
41
|
+
if (!isFilterCall)
|
|
42
|
+
continue;
|
|
43
|
+
const args = call.getArguments();
|
|
44
|
+
if (args.length === 1 && args[0].getText() === "this") {
|
|
45
|
+
const parent = call.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);
|
|
46
|
+
if (parent) {
|
|
47
|
+
statementsToRemove.push(parent);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Remove in reverse order to preserve node positions
|
|
52
|
+
for (const stmt of statementsToRemove.reverse()) {
|
|
53
|
+
stmt.remove();
|
|
54
|
+
}
|
|
55
|
+
// --- Remove commented-out versions ---
|
|
56
|
+
// Matches lines like:
|
|
57
|
+
// // this._webda.registerCORSFilter(this);
|
|
58
|
+
// // this.getWebda().registerRequestFilter(this);
|
|
59
|
+
const fullText = sourceFile.getFullText();
|
|
60
|
+
const commentPattern = /^\s*\/\/\s*this[\._].*register(?:Request|CORS)Filter\(this\);[^\S\n]*\n?/gm;
|
|
61
|
+
const cleaned = fullText.replace(commentPattern, "");
|
|
62
|
+
if (cleaned !== fullText) {
|
|
63
|
+
sourceFile.replaceWithText(cleaned);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/morpher/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAsB;IAC9D,sCAAsC;IACtC,MAAM,eAAe,GAAG,UAAU,CAAC,oBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IACnF,MAAM,kBAAkB,GAA0B,EAAE,CAAC;IAErD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,uBAAuB,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QAE3G,IAAI,CAAC,YAAY;YAAE,SAAS;QAE5B,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;YAC3E,IAAI,MAAM,EAAE,CAAC;gBACX,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,qDAAqD;IACrD,KAAK,MAAM,IAAI,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,wCAAwC;IACxC,sBAAsB;IACtB,6CAA6C;IAC7C,oDAAoD;IACpD,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,cAAc,GAAG,4EAA4E,CAAC;IACpG,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QACzB,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SourceFile } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* Replace all packages according to the constant replacePackages
|
|
4
|
+
* @param sourceFile - the source file to update
|
|
5
|
+
* @param replacePackages - map of package import replacements
|
|
6
|
+
*/
|
|
7
|
+
export declare function updateImports(sourceFile: SourceFile, replacePackages: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
}): void;
|
|
10
|
+
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/morpher/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAM,MAAM,UAAU,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,QAyF/F"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ts } from "ts-morph";
|
|
2
|
+
/**
|
|
3
|
+
* Replace all packages according to the constant replacePackages
|
|
4
|
+
* @param sourceFile - the source file to update
|
|
5
|
+
* @param replacePackages - map of package import replacements
|
|
6
|
+
*/
|
|
7
|
+
export function updateImports(sourceFile, replacePackages) {
|
|
8
|
+
const moveImports = {};
|
|
9
|
+
// Flat the replacePackage into moveImports
|
|
10
|
+
for (const i in replacePackages) {
|
|
11
|
+
const [pkg, replace = "*"] = i.split(":");
|
|
12
|
+
moveImports[pkg] ??= {};
|
|
13
|
+
if (replace.includes(",")) {
|
|
14
|
+
replace.split(",").forEach(r => {
|
|
15
|
+
moveImports[pkg][r] = replacePackages[i] + ":" + r;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
moveImports[pkg][replace] = replacePackages[i];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Check for each moved import now
|
|
23
|
+
for (const pkg in moveImports) {
|
|
24
|
+
const importDeclarations = sourceFile
|
|
25
|
+
.getImportDeclarations()
|
|
26
|
+
.filter(declaration => declaration.getModuleSpecifierValue() === pkg);
|
|
27
|
+
const replacements = moveImports[pkg];
|
|
28
|
+
// Update each import declaration
|
|
29
|
+
importDeclarations.forEach(importDeclaration => {
|
|
30
|
+
let moved = false;
|
|
31
|
+
for (const i in replacements) {
|
|
32
|
+
if (i === "*") {
|
|
33
|
+
// The whole module has been renamed
|
|
34
|
+
importDeclaration.setModuleSpecifier(replacements[i]);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// If import is not there yet
|
|
38
|
+
const original = importDeclaration.getNamedImports().find(n => n.getName() === i);
|
|
39
|
+
if (!original) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Rename within the module
|
|
43
|
+
const [newPkg, namedImport] = replacements[i].split(":");
|
|
44
|
+
//original.remove();
|
|
45
|
+
if (newPkg == pkg) {
|
|
46
|
+
// Check if the identifier exists already
|
|
47
|
+
const existingGlobalIdentifier = sourceFile
|
|
48
|
+
.getDescendantsOfKind(ts.SyntaxKind.Identifier)
|
|
49
|
+
.find(identifier => {
|
|
50
|
+
// Check if the identifier is a named import with the same name
|
|
51
|
+
const importSpecifier = identifier.getParentIfKind(ts.SyntaxKind.ImportSpecifier);
|
|
52
|
+
return importSpecifier !== undefined && importSpecifier.getName() === namedImport;
|
|
53
|
+
});
|
|
54
|
+
if (existingGlobalIdentifier) {
|
|
55
|
+
original.setName(namedImport).setAlias(i);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// Use the renameAlias so it update all references
|
|
59
|
+
original.renameAlias(namedImport);
|
|
60
|
+
// Set the name to the alias
|
|
61
|
+
original.setName(namedImport);
|
|
62
|
+
// Remove the alias
|
|
63
|
+
original.removeAlias();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
original.remove();
|
|
68
|
+
moved = true;
|
|
69
|
+
// Move to another module
|
|
70
|
+
const newDeclaration = sourceFile.getImportDeclaration(newPkg) ||
|
|
71
|
+
sourceFile.addImportDeclaration({
|
|
72
|
+
moduleSpecifier: newPkg,
|
|
73
|
+
namedImports: namedImport.startsWith("*") ? undefined : namedImport,
|
|
74
|
+
namespaceImport: namedImport.startsWith("*") ? namedImport.substring(1) : undefined
|
|
75
|
+
});
|
|
76
|
+
if (namedImport.startsWith("*")) {
|
|
77
|
+
if (newDeclaration.getNamespaceImport() === undefined) {
|
|
78
|
+
newDeclaration.setNamespaceImport(namedImport.substring(1));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (!newDeclaration.getNamedImports().find(n => n.getName() === namedImport)) {
|
|
82
|
+
newDeclaration.addNamedImport(namedImport);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Remove the import once everything it named has moved; a side-effect
|
|
87
|
+
// or default import never named anything and stays
|
|
88
|
+
if (moved &&
|
|
89
|
+
!importDeclaration.getDefaultImport() &&
|
|
90
|
+
!importDeclaration.getNamespaceImport() &&
|
|
91
|
+
importDeclaration.getNamedImports().length === 0) {
|
|
92
|
+
importDeclaration.remove();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.js","sourceRoot":"","sources":["../../src/morpher/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,EAAE,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAsB,EAAE,eAA0C;IAC9F,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,2CAA2C;IAC3C,KAAK,MAAM,CAAC,IAAI,eAAe,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBAC7B,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,kCAAkC;IAClC,KAAK,MAAM,GA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