@nativescript/compiler-angular 0.0.0-stage → 9.2.0-alpha.9
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/dist/angular-libraries.js +173 -0
- package/dist/angular.js +2895 -0
- package/dist/component-bases.js +746 -0
- package/dist/core-api.js +8 -0
- package/dist/entry.js +118 -0
- package/dist/index.js +157 -0
- package/dist/kotlin.js +280 -0
- package/dist/modules.js +698 -0
- package/dist/ng-modules.js +66 -0
- package/dist/package.js +15 -0
- package/dist/refusals.js +5 -0
- package/dist/semantics.js +213 -0
- package/dist/swift.js +340 -0
- package/kit-android/fromcore/AngularAPI.kt +172 -0
- package/kit-android/fromcore/AngularRouter.kt +587 -0
- package/kit-android/handport/Router.kt +151 -0
- package/kit-android/main/AngularChangeDetection.kt +250 -0
- package/kit-android/main/AngularCore.kt +685 -0
- package/kit-android/main/AngularHttp.kt +431 -0
- package/kit-android/main/AngularRouterValues.kt +154 -0
- package/kit-android/main/AngularRx.kt +224 -0
- package/kit-apple/AngularAPI.swift +224 -0
- package/kit-apple/AngularChangeDetection.swift +248 -0
- package/kit-apple/AngularCore.swift +764 -0
- package/kit-apple/AngularHttp.swift +467 -0
- package/kit-apple/AngularRouter.swift +626 -0
- package/kit-apple/AngularRouterValues.swift +285 -0
- package/kit-apple/AngularRx.swift +246 -0
- package/kit-apple/kit-index.json +739 -0
- package/package.json +53 -4
- package/runtime/angular-forms.ts +3099 -0
- package/runtime/angular-rx.ts +550 -0
- package/runtime/angular.ts +826 -0
- package/README.md +0 -3
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { componentOf, declarablesIn } from "./angular.js";
|
|
4
|
+
import { core, ts } from "./core-api.js";
|
|
5
|
+
/** The TypeScript of each `<package>/angular` entry the app imports, from the plugin's source beside its main module. */
|
|
6
|
+
export function angularLibraries(sources, modulesDir, plugins, replaced) {
|
|
7
|
+
const out = [];
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
for (const f of sources) {
|
|
10
|
+
for (const m of readFileSync(f, 'utf8').matchAll(/import\s*\{([^}]*)\}\s*from\s*['"]((?:@[\w.-]+\/)?[\w.-]+)\/angular['"]/g)) {
|
|
11
|
+
const wanted = m[1].split(',').map((x) => x.trim().split(/\s+as\s+/)[0]).filter(Boolean);
|
|
12
|
+
// A plugin the kit implements renders its elements itself, and one the app replaces is the app's module: neither
|
|
13
|
+
// has an Angular wrapper of its own compiled.
|
|
14
|
+
if (seen.has(m[2]) || core.kitPlugins.includes(m[2]) || core.stubbedPlugins.has(m[2]) || replaced.has(m[2]))
|
|
15
|
+
continue;
|
|
16
|
+
seen.add(m[2]);
|
|
17
|
+
const dir = join(modulesDir, m[2]);
|
|
18
|
+
const main = ['index.ios.js', 'index.js'].map((x) => join(dir, x)).find(existsSync);
|
|
19
|
+
if (!main)
|
|
20
|
+
continue;
|
|
21
|
+
plugins.get(dir);
|
|
22
|
+
const mainSource = plugins.sourceOf(main);
|
|
23
|
+
const angular = mainSource && join(dirname(mainSource), 'angular');
|
|
24
|
+
// A wrapper written against Angular's view internals (ElementRef, ViewContainerRef) has no components of its own the build reads.
|
|
25
|
+
if (!angular || !existsSync(angular))
|
|
26
|
+
continue;
|
|
27
|
+
const components = new Map();
|
|
28
|
+
/** The names an NgModule's `declarations`, `imports` and `exports` list: an app importing the module imports those. */
|
|
29
|
+
const modules = new Map();
|
|
30
|
+
const moduleFiles = new Map();
|
|
31
|
+
// A wrapper written against Angular's view internals (ElementRef, ViewContainerRef) is not compiled: a compiled template replaces it.
|
|
32
|
+
const viewInternals = (text) => /\b(ViewContainerRef|DetachedContainer)\b/.test(text);
|
|
33
|
+
const walk = (d) => {
|
|
34
|
+
for (const x of readdirSync(d)) {
|
|
35
|
+
const p = join(d, x);
|
|
36
|
+
if (statSync(p).isDirectory())
|
|
37
|
+
walk(p);
|
|
38
|
+
else if (x.endsWith('.ts') && !x.endsWith('.d.ts') && !x.endsWith('.spec.ts')) {
|
|
39
|
+
const text = readFileSync(p, 'utf8');
|
|
40
|
+
const name = viewInternals(text) ? undefined : componentOf(p, text)?.name;
|
|
41
|
+
if (name)
|
|
42
|
+
components.set(name, p);
|
|
43
|
+
const found = declarablesIn(p, text);
|
|
44
|
+
for (const d of found.classes)
|
|
45
|
+
components.set(d, p);
|
|
46
|
+
for (const [m, names] of found.modules) {
|
|
47
|
+
modules.set(m, names);
|
|
48
|
+
if (!viewInternals(text))
|
|
49
|
+
moduleFiles.set(m, p);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
walk(angular);
|
|
55
|
+
const listed = (names) => names.flatMap((n) => (modules.has(n) ? listed(modules.get(n).filter((x) => x !== n)) : [n]));
|
|
56
|
+
// The components and pipes the app imports, directly or through an NgModule, and those their `imports` name,
|
|
57
|
+
// transitively, with the modules of their own they import.
|
|
58
|
+
const queue = listed(wanted).filter((w) => components.has(w));
|
|
59
|
+
const taken = new Set();
|
|
60
|
+
const files = [...components.values()];
|
|
61
|
+
const take = (file) => {
|
|
62
|
+
out.push(file);
|
|
63
|
+
const text = readFileSync(file, 'utf8');
|
|
64
|
+
const imports = /imports:\s*\[([^\]]*)\]/.exec(text)?.[1] ?? '';
|
|
65
|
+
for (const i of imports.split(',').map((x) => x.trim()))
|
|
66
|
+
if (components.has(i))
|
|
67
|
+
queue.push(i);
|
|
68
|
+
for (const m of text.matchAll(/from\s*['"](\.[^'"]+)['"]/g)) {
|
|
69
|
+
const support = [resolve(dirname(file), m[1]) + '.ts', join(resolve(dirname(file), m[1]), 'index.ts')].find(existsSync);
|
|
70
|
+
if (support && !files.includes(support) && !out.includes(support) && !viewInternals(readFileSync(support, 'utf8')))
|
|
71
|
+
out.push(support);
|
|
72
|
+
// A component the code itself uses (a dialog it opens).
|
|
73
|
+
for (const [other, f] of components)
|
|
74
|
+
if (f === support)
|
|
75
|
+
queue.push(other);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const drain = () => {
|
|
79
|
+
while (queue.length) {
|
|
80
|
+
const name = queue.pop();
|
|
81
|
+
if (taken.has(name))
|
|
82
|
+
continue;
|
|
83
|
+
taken.add(name);
|
|
84
|
+
take(components.get(name));
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
drain();
|
|
88
|
+
// An entry with components compiled here resolves to its typings unless it is compiled too: the NgModules the app
|
|
89
|
+
// imports from it are, in their own files. Without components the whole entry is compiled as the plugin's source.
|
|
90
|
+
if (!taken.size)
|
|
91
|
+
continue;
|
|
92
|
+
const imported = new Set();
|
|
93
|
+
const moduleNames = (names) => names.forEach((n) => { if (modules.has(n) && !imported.has(n)) {
|
|
94
|
+
imported.add(n);
|
|
95
|
+
moduleNames(modules.get(n));
|
|
96
|
+
} });
|
|
97
|
+
moduleNames(wanted);
|
|
98
|
+
for (const name of imported) {
|
|
99
|
+
const file = moduleFiles.get(name);
|
|
100
|
+
if (file && !out.includes(file))
|
|
101
|
+
take(file);
|
|
102
|
+
}
|
|
103
|
+
drain();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Tags registered for plugin views: `registerElement('Tag', () => Class)` or `registerElement('Tag', () => Class, meta)`
|
|
110
|
+
* in the app, and in the Angular entry (`<package>/angular`) of a plugin the app imports, with the module each class is from.
|
|
111
|
+
*/
|
|
112
|
+
export function registeredElements(sources, modulesDir) {
|
|
113
|
+
const found = new Map();
|
|
114
|
+
const scan = (text, file) => {
|
|
115
|
+
if (!text.includes('registerElement'))
|
|
116
|
+
return;
|
|
117
|
+
const imports = new Map();
|
|
118
|
+
for (const m of text.matchAll(/import\s*\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
119
|
+
for (const part of m[1].split(',')) {
|
|
120
|
+
const [orig, alias] = part.trim().split(/\s+as\s+/);
|
|
121
|
+
if (orig)
|
|
122
|
+
imports.set((alias ?? orig).trim(), JSON.stringify([orig.trim(), m[2]]));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const sf = ts.createSourceFile(file ?? 'entry.mjs', text, ts.ScriptTarget.Latest, true, file?.endsWith('.ts') ? ts.ScriptKind.TS : ts.ScriptKind.JS);
|
|
126
|
+
const objectOf = (e) => {
|
|
127
|
+
if (ts.isObjectLiteralExpression(e))
|
|
128
|
+
return e;
|
|
129
|
+
if (!ts.isIdentifier(e))
|
|
130
|
+
return null;
|
|
131
|
+
for (const st of sf.statements) {
|
|
132
|
+
if (!ts.isVariableStatement(st) || !(st.declarationList.flags & ts.NodeFlags.Const))
|
|
133
|
+
continue;
|
|
134
|
+
for (const d of st.declarationList.declarations)
|
|
135
|
+
if (ts.isIdentifier(d.name) && d.name.text === e.text && d.initializer)
|
|
136
|
+
return objectOf(d.initializer);
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
};
|
|
140
|
+
const visit = (n) => {
|
|
141
|
+
ts.forEachChild(n, visit);
|
|
142
|
+
if (!ts.isCallExpression(n) || !ts.isIdentifier(n.expression) || n.expression.text !== 'registerElement')
|
|
143
|
+
return;
|
|
144
|
+
const [tag, resolver, meta] = n.arguments;
|
|
145
|
+
if (!tag || !ts.isStringLiteralLike(tag) || !resolver || !ts.isArrowFunction(resolver) || resolver.parameters.length || !ts.isIdentifier(resolver.body))
|
|
146
|
+
return;
|
|
147
|
+
const imported = imports.get(resolver.body.text);
|
|
148
|
+
if (!imported)
|
|
149
|
+
return;
|
|
150
|
+
const [name, from] = JSON.parse(imported);
|
|
151
|
+
// Core's own views are elements already.
|
|
152
|
+
if (from === '@nativescript/core' || core.stubbedPlugins.has(core.packageOf(from)))
|
|
153
|
+
return;
|
|
154
|
+
const object = meta ? objectOf(meta) : null;
|
|
155
|
+
const keys = object && object.properties.every((p) => p.name && !ts.isComputedPropertyName(p.name)) ? object.properties.map((p) => p.name.getText().replace(/^['"]|['"]$/g, '')) : null;
|
|
156
|
+
found.set(tag.text, { name, from: from.startsWith('.') && file ? resolve(dirname(file), from) : from, ...(meta ? { meta: keys } : {}) });
|
|
157
|
+
};
|
|
158
|
+
visit(sf);
|
|
159
|
+
};
|
|
160
|
+
for (const f of sources) {
|
|
161
|
+
const text = readFileSync(f, 'utf8');
|
|
162
|
+
scan(text, f);
|
|
163
|
+
for (const m of text.matchAll(/from\s*['"]((?:@[\w.-]+\/)?[\w.-]+)\/angular['"]/g)) {
|
|
164
|
+
if (core.stubbedPlugins.has(m[1]))
|
|
165
|
+
continue;
|
|
166
|
+
const dir = join(modulesDir, m[1], 'angular');
|
|
167
|
+
const entry = existsSync(dir) ? readdirSync(dir).flatMap((d) => (/^fesm/.test(d) ? readdirSync(join(dir, d)).filter((x) => x.endsWith('.mjs')).map((x) => join(dir, d, x)) : [])).sort().reverse()[0] : undefined;
|
|
168
|
+
if (entry)
|
|
169
|
+
scan(readFileSync(entry, 'utf8'), null);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return found;
|
|
173
|
+
}
|