@jointhedots/gear 1.1.18 → 1.2.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.
- package/esm/builder/build-app-bundle.js +4 -6
- package/esm/builder/build-application.js +2 -3
- package/esm/builder/build-target.js +3 -3
- package/esm/commands/install.js +2 -2
- package/esm/commands/make.js +3 -2
- package/esm/workspace/helpers/create-manifests.js +1 -1
- package/esm/workspace/helpers/discover-workspace.js +130 -133
- package/esm/workspace/packagers/packager-standard.js +48 -23
- package/esm/workspace/storage.js +15 -10
- package/esm/workspace/workspace.js +23 -14
- package/package.json +1 -1
|
@@ -17,8 +17,7 @@ export var PathStatus;
|
|
|
17
17
|
PathStatus[PathStatus["ExternalBundle"] = 4] = "ExternalBundle";
|
|
18
18
|
})(PathStatus || (PathStatus = {}));
|
|
19
19
|
export function create_bundle_target(opts) {
|
|
20
|
-
const { bundle, library, storage } = opts;
|
|
21
|
-
const lib = library;
|
|
20
|
+
const { bundle, library: lib, storage } = opts;
|
|
22
21
|
const target = new BuildTarget(bundle.id, storage, lib.workspace, opts.devmode == true, opts.watch == true, opts.clean == true);
|
|
23
22
|
// Prepare esm setup
|
|
24
23
|
target.esmodules.set_root(lib.path);
|
|
@@ -84,7 +83,7 @@ export function create_bundle_target(opts) {
|
|
|
84
83
|
paths_qualifier.set(dep, PathStatus.ExternalBundle);
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
|
-
for (const xbun of lib.
|
|
86
|
+
for (const xbun of lib.shelve) {
|
|
88
87
|
if (xbun !== bundle) {
|
|
89
88
|
paths_qualifier.set(xbun.id, xbun);
|
|
90
89
|
paths_qualifier.set(xbun.alias, xbun);
|
|
@@ -169,9 +168,8 @@ export function create_bundle_target(opts) {
|
|
|
169
168
|
}
|
|
170
169
|
});
|
|
171
170
|
// Register esbuild plugin for dependency deduplication (graph-based + singleton)
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const libGraph = collectLibraryGraph(library);
|
|
171
|
+
const rootNodeModules = lib.search_directories[0] || Path.join(lib.path, 'node_modules');
|
|
172
|
+
const libGraph = collectLibraryGraph(lib);
|
|
175
173
|
target.esmodules.plugins.push(DependencyDeduplicationPlugin(libGraph, rootNodeModules, target.log));
|
|
176
174
|
return target;
|
|
177
175
|
}
|
|
@@ -33,8 +33,7 @@ export function create_application_monolith_target(opts) {
|
|
|
33
33
|
const { app, version } = opts;
|
|
34
34
|
const { type, name, webviews, modules, assets, components } = app.descriptor;
|
|
35
35
|
const lib = app.library;
|
|
36
|
-
const
|
|
37
|
-
const target = new BuildTarget(name, opts.storage, ws, opts.devmode == true, opts.watch == true, opts.clean == true);
|
|
36
|
+
const target = new BuildTarget(name, opts.storage, lib.workspace, opts.devmode == true, opts.watch == true, opts.clean == true);
|
|
38
37
|
const libs = collect_app_libraries(app);
|
|
39
38
|
target.log.info(`+ 🧭 app-library-graph: ${libs.map(lib => `${lib.name}@${lib.descriptor.version}`).join(", ")}`);
|
|
40
39
|
// Prepare esm setup
|
|
@@ -152,7 +151,7 @@ export function create_application_monolith_target(opts) {
|
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
153
|
// Register esbuild plugin for dependency deduplication (graph-based + singleton)
|
|
155
|
-
const rootNodeModules =
|
|
154
|
+
const rootNodeModules = lib.search_directories[0] || Path.join(lib.path, 'node_modules');
|
|
156
155
|
target.esmodules.plugins.push(DependencyDeduplicationPlugin(libs, rootNodeModules, target.log));
|
|
157
156
|
return target;
|
|
158
157
|
}
|
|
@@ -39,7 +39,7 @@ export class BuildTarget {
|
|
|
39
39
|
add_component(descriptor, baseDir, library) {
|
|
40
40
|
const id = descriptor.$id;
|
|
41
41
|
if (this.components.has(id)) {
|
|
42
|
-
throw new Error(createComponentDuplicateMessage(id,
|
|
42
|
+
throw new Error(createComponentDuplicateMessage(id, library));
|
|
43
43
|
}
|
|
44
44
|
const manifest = {
|
|
45
45
|
...descriptor,
|
|
@@ -94,10 +94,10 @@ export class BuildTarget {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
function createComponentDuplicateMessage(id,
|
|
97
|
+
function createComponentDuplicateMessage(id, library) {
|
|
98
98
|
const duplicates = [];
|
|
99
99
|
const libs = [];
|
|
100
|
-
for (const bun of
|
|
100
|
+
for (const bun of library.shelve) {
|
|
101
101
|
for (const [cpath, cmanifest] of bun.components.entries()) {
|
|
102
102
|
if (cmanifest.$id === id) {
|
|
103
103
|
duplicates.push(`\n - ${cpath}`);
|
package/esm/commands/install.js
CHANGED
|
@@ -28,8 +28,8 @@ export function command_install() {
|
|
|
28
28
|
});
|
|
29
29
|
// Select all workspace bundles
|
|
30
30
|
const selector = new BundleSelector(ws);
|
|
31
|
-
for (const
|
|
32
|
-
selector.add(bundle);
|
|
31
|
+
for (const lib of ws.libraries) {
|
|
32
|
+
selector.add(lib.bundle);
|
|
33
33
|
}
|
|
34
34
|
if (selector.missing.length > 0) {
|
|
35
35
|
ws.log.warn(`Missing bundle dependencies: ${selector.missing.join(", ")}`);
|
package/esm/commands/make.js
CHANGED
|
@@ -88,8 +88,9 @@ export function command_make() {
|
|
|
88
88
|
}
|
|
89
89
|
const bundles = [];
|
|
90
90
|
if (argv.bundles === "*") {
|
|
91
|
-
for (const
|
|
92
|
-
|
|
91
|
+
for (const lib of ws.libraries) {
|
|
92
|
+
if (lib.bundle)
|
|
93
|
+
bundles.push(lib.bundle);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
else if (argv.bundles) {
|
|
@@ -84,7 +84,7 @@ export function create_package_manifest(lib, bun, build_version) {
|
|
|
84
84
|
optionalDependencies: undefined,
|
|
85
85
|
};
|
|
86
86
|
if (pkg_manif.dependencies) {
|
|
87
|
-
const resolved = lib.
|
|
87
|
+
const resolved = lib.resolved_versions;
|
|
88
88
|
for (const dep in pkg_manif.dependencies) {
|
|
89
89
|
if (pkg_manif.dependencies[dep] === "*") {
|
|
90
90
|
const dep_resolved = resolved[dep];
|
|
@@ -9,7 +9,7 @@ import { file, make_canonical_path, make_normalized_dirname, make_normalized_pat
|
|
|
9
9
|
import { findConfigFile, is_config_filename, readConfigFile, readSingletonConfigFile } from "./config-loader.js";
|
|
10
10
|
import { read_lockfile } from "./lockfile.js";
|
|
11
11
|
import { LoadLibraryPackager } from "../packager.js";
|
|
12
|
-
import {
|
|
12
|
+
import { DefaultLibraryPackager } from "../packagers/packager-standard.js";
|
|
13
13
|
const exclude_dirs = ["node_modules", ".git"];
|
|
14
14
|
function is_ignored_dir(ws, path) {
|
|
15
15
|
const normalized_path = make_normalized_path(path);
|
|
@@ -20,26 +20,8 @@ function is_ignored_dir(ws, path) {
|
|
|
20
20
|
}
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
|
-
export function setup_library_bundle(lib) {
|
|
24
|
-
const ws = lib.workspace;
|
|
25
|
-
const manif = make_library_bundle_manifest(lib);
|
|
26
|
-
let bun = ws.get_bundle(manif.$id);
|
|
27
|
-
if (!bun) {
|
|
28
|
-
bun = new Bundle(manif, lib.path, ws, lib);
|
|
29
|
-
lib.bundle = bun;
|
|
30
|
-
ws.bundles.push(bun);
|
|
31
|
-
lib.log.info(`+ 📦 bundle: ${bun.id}`);
|
|
32
|
-
return bun;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
throw new Error(`Library '${lib.get_id()}' is associate to a bundle '${bun.id}' that is already associated`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
23
|
export async function discover_component(lib, fpath) {
|
|
39
|
-
|
|
40
|
-
if (!bundle) {
|
|
41
|
-
bundle = setup_library_bundle(lib);
|
|
42
|
-
}
|
|
24
|
+
const { bundle } = lib;
|
|
43
25
|
if (bundle.components.has(fpath)) {
|
|
44
26
|
return true;
|
|
45
27
|
}
|
|
@@ -92,7 +74,7 @@ async function discover_application(lib, fpath) {
|
|
|
92
74
|
lib.log.error(`invalid application at ${fpath}: ${e?.message}`);
|
|
93
75
|
}
|
|
94
76
|
}
|
|
95
|
-
export async function
|
|
77
|
+
export async function discover_library_definitions(lib, path, subdir = false) {
|
|
96
78
|
// List names from directory
|
|
97
79
|
const fnames = await Fsp.readdir(path);
|
|
98
80
|
if (subdir && fnames.includes("package.json")) {
|
|
@@ -104,8 +86,8 @@ export async function discover_library_components(lib, path, subdir = false) {
|
|
|
104
86
|
const fstat = await Fsp.stat(fpath);
|
|
105
87
|
if (fstat.isDirectory()) {
|
|
106
88
|
if (!exclude_dirs.includes(fname)) {
|
|
107
|
-
if (await
|
|
108
|
-
await
|
|
89
|
+
if (await discover_bundle(lib, fpath) === Discovered.None) {
|
|
90
|
+
await discover_library_definitions(lib, fpath, true);
|
|
109
91
|
}
|
|
110
92
|
}
|
|
111
93
|
}
|
|
@@ -125,133 +107,57 @@ export async function discover_library_components(lib, path, subdir = false) {
|
|
|
125
107
|
}
|
|
126
108
|
}
|
|
127
109
|
}
|
|
128
|
-
export function collect_declarations_field(lib, key, value) {
|
|
129
|
-
for (const decl of lib.declarations.values()) {
|
|
130
|
-
if (typeof decl[key] === typeof value) {
|
|
131
|
-
if (Array.isArray(value))
|
|
132
|
-
value.push(...decl[key]);
|
|
133
|
-
else if (typeof value === "object")
|
|
134
|
-
Object.assign(value, decl[key]);
|
|
135
|
-
else
|
|
136
|
-
value = decl[key];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return value;
|
|
140
|
-
}
|
|
141
|
-
function make_library_bundle_manifest(lib) {
|
|
142
|
-
return {
|
|
143
|
-
$id: makeNormalizedName(collect_declarations_field(lib, "$id", lib.name), NameStyle.OBJECT),
|
|
144
|
-
type: "bundle",
|
|
145
|
-
name: lib.name,
|
|
146
|
-
icon: collect_declarations_field(lib, "icon", ""),
|
|
147
|
-
title: collect_declarations_field(lib, "title", lib.name),
|
|
148
|
-
tags: collect_declarations_field(lib, "tags", lib.descriptor?.tags),
|
|
149
|
-
keywords: collect_declarations_field(lib, "keywords", lib.descriptor?.keywords),
|
|
150
|
-
description: collect_declarations_field(lib, "description", lib.descriptor?.description),
|
|
151
|
-
selectors: collect_declarations_field(lib, "selectors", undefined),
|
|
152
|
-
data: {
|
|
153
|
-
package: lib.get_id(),
|
|
154
|
-
alias: collect_declarations_field(lib, "alias", lib.name),
|
|
155
|
-
namespaces: collect_declarations_field(lib, "namespaces", []),
|
|
156
|
-
dependencies: collect_declarations_field(lib, "dependencies", []),
|
|
157
|
-
distribueds: collect_declarations_field(lib, "distribueds", {}),
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
110
|
var Discovered;
|
|
162
111
|
(function (Discovered) {
|
|
163
112
|
Discovered[Discovered["None"] = 0] = "None";
|
|
164
113
|
Discovered[Discovered["Ignored"] = 1] = "Ignored";
|
|
165
114
|
Discovered[Discovered["Registered"] = 2] = "Registered";
|
|
166
115
|
})(Discovered || (Discovered = {}));
|
|
167
|
-
async function discover_library(ws, location
|
|
116
|
+
async function discover_library(ws, location) {
|
|
168
117
|
const lib_path = make_canonical_path(ws.path, location);
|
|
169
118
|
if (is_ignored_dir(ws, lib_path))
|
|
170
119
|
return Discovered.Ignored;
|
|
120
|
+
const has_bundle_manifest = file.exists(findConfigFile(lib_path, "bundle.manifest"));
|
|
121
|
+
if (has_bundle_manifest) {
|
|
122
|
+
// discover_bundle
|
|
123
|
+
return Discovered.Ignored;
|
|
124
|
+
}
|
|
171
125
|
const package_path = lib_path + "/package.json";
|
|
172
126
|
const has_package_manifest = file.exists(package_path);
|
|
173
|
-
|
|
174
|
-
if (!has_package_manifest && !has_bundle_manifest)
|
|
127
|
+
if (!has_package_manifest)
|
|
175
128
|
return Discovered.None;
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
178
|
-
return Discovered.Ignored;
|
|
179
|
-
const lib_desc = await readJsonFile(package_path);
|
|
180
|
-
if (!lib_desc?.name)
|
|
129
|
+
const lib_manifest = await readJsonFile(package_path);
|
|
130
|
+
if (!lib_manifest?.name)
|
|
181
131
|
return Discovered.Ignored;
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
else {
|
|
190
|
-
throw new Error(`library '${lib_desc.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const lib = new Library(lib_desc.name, lib_path, lib_desc, ws, installed);
|
|
194
|
-
ws.libraries.push(lib);
|
|
195
|
-
ws.log.info(`+ 📚 library: ${installed ? "⏬" : "🐣"} ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
|
|
196
|
-
// Setup node search directory
|
|
197
|
-
const lib_search_path = lib_path + "/node_modules";
|
|
198
|
-
if (Fs.existsSync(lib_search_path)) {
|
|
199
|
-
lib.search_directories.push(lib_search_path);
|
|
200
|
-
}
|
|
201
|
-
// Load library packager
|
|
202
|
-
let packager = null;
|
|
203
|
-
if (has_bundle_manifest) {
|
|
204
|
-
packager = new BundledLibraryPackager();
|
|
132
|
+
if (!lib_manifest?.dots)
|
|
133
|
+
return Discovered.None;
|
|
134
|
+
const other = ws.get_library(lib_manifest.name);
|
|
135
|
+
if (other) {
|
|
136
|
+
if (lib_path.includes(other.path)) {
|
|
137
|
+
ws.log.info(`ignore library build at ${lib_path}`);
|
|
138
|
+
return Discovered.Ignored;
|
|
205
139
|
}
|
|
206
140
|
else {
|
|
207
|
-
|
|
208
|
-
const packager_ref = declaration_config && declaration_config.data?.packager;
|
|
209
|
-
if (packager_ref) {
|
|
210
|
-
packager = await LoadLibraryPackager(packager_ref);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
packager = new DefaultLibraryPackager();
|
|
214
|
-
}
|
|
141
|
+
throw new Error(`library '${lib_manifest.name}' declared multiple times\n - ${other.path}\n - ${lib_path}`);
|
|
215
142
|
}
|
|
216
|
-
// Discover library with packager
|
|
217
|
-
await packager.discover_library(lib);
|
|
218
|
-
return Discovered.Registered;
|
|
219
143
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (await discover_library(ws, dir, false) === Discovered.None) {
|
|
225
|
-
for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
|
|
226
|
-
if (entry.name === "node_modules")
|
|
227
|
-
continue;
|
|
228
|
-
const fullPath = dir + "/" + entry.name;
|
|
229
|
-
if (entry.isDirectory()) {
|
|
230
|
-
await walk(fullPath);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
await walk(ws.path);
|
|
236
|
-
}
|
|
237
|
-
function show_constants(ws) {
|
|
238
|
-
for (const name in ws.constants) {
|
|
239
|
-
ws.log.info(`+ 🔖 ${name} = ${ws.constants[name]}`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
export async function discover_workspace(ws) {
|
|
144
|
+
const lib = new Library(lib_manifest.name, lib_path, lib_manifest, ws);
|
|
145
|
+
ws.libraries.push(lib);
|
|
146
|
+
ws.log.info(`+ 📚 library: ${lib.get_id()} (${make_relative_path(ws.path, location)})`);
|
|
147
|
+
// Discover library-level search_directories, lockfile, and constants (walk up to workspace root)
|
|
243
148
|
let lockfile = null;
|
|
244
|
-
|
|
149
|
+
lib.constants = { ...ws.constants };
|
|
150
|
+
for (let path = lib.path;;) {
|
|
245
151
|
const package_json = await readJsonFile(path + "/package.json");
|
|
246
152
|
if (package_json) {
|
|
247
153
|
const search_path = path + "/node_modules";
|
|
248
154
|
if (Fs.existsSync(search_path)) {
|
|
249
|
-
|
|
155
|
+
lib.search_directories.push(search_path);
|
|
250
156
|
}
|
|
251
157
|
if (package_json.constants) {
|
|
252
|
-
|
|
158
|
+
lib.constants = {
|
|
253
159
|
...package_json.constants,
|
|
254
|
-
...
|
|
160
|
+
...lib.constants,
|
|
255
161
|
};
|
|
256
162
|
}
|
|
257
163
|
}
|
|
@@ -263,19 +169,110 @@ export async function discover_workspace(ws) {
|
|
|
263
169
|
break;
|
|
264
170
|
path = next_path;
|
|
265
171
|
}
|
|
266
|
-
|
|
172
|
+
// Analyze lock file
|
|
173
|
+
if (lockfile) {
|
|
174
|
+
lib.resolved_versions = lockfile.resolved_versions;
|
|
175
|
+
for (const dep_id in lockfile.resolved_versions) {
|
|
176
|
+
const dep_path = lib.resolved_versions[dep_id];
|
|
177
|
+
await discover_bundle(lib, dep_path);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
267
181
|
throw new Error(`Lock file not found for '${ws.name}'`);
|
|
268
182
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
183
|
+
// Load library packager
|
|
184
|
+
let packager = null;
|
|
185
|
+
const declaration_config = await readSingletonConfigFile(lib_path, "declaration");
|
|
186
|
+
const packager_ref = declaration_config && declaration_config.data?.packager;
|
|
187
|
+
if (packager_ref) {
|
|
188
|
+
packager = await LoadLibraryPackager(packager_ref);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
packager = new DefaultLibraryPackager();
|
|
192
|
+
}
|
|
193
|
+
// Discover library with packager
|
|
194
|
+
await packager.discover_library(lib);
|
|
195
|
+
return Discovered.Registered;
|
|
196
|
+
}
|
|
197
|
+
async function discover_bundle(lib, location) {
|
|
198
|
+
const bun_path = make_canonical_path(lib.path, location);
|
|
199
|
+
if (is_ignored_dir(lib.workspace, bun_path))
|
|
200
|
+
return Discovered.Ignored;
|
|
201
|
+
const bun_manif_path = findConfigFile(bun_path, "bundle.manifest");
|
|
202
|
+
if (!bun_manif_path)
|
|
203
|
+
return Discovered.None;
|
|
204
|
+
const bun_manif = await readConfigFile(bun_manif_path);
|
|
205
|
+
if (!bun_manif) {
|
|
206
|
+
lib.log.error(`bundle manifest invalid at: ${bun_manif_path}`);
|
|
207
|
+
return Discovered.Ignored;
|
|
208
|
+
}
|
|
209
|
+
const other = lib.get_bundle(bun_manif.$id);
|
|
210
|
+
if (other) {
|
|
211
|
+
if (bun_path.includes(other.path)) {
|
|
212
|
+
lib.log.info(`ignore bundle at ${bun_path}`);
|
|
213
|
+
return Discovered.Ignored;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
lib.log.error(`bundle '${bun_manif.$id}' declared multiple times\n - ${other.path}\n - ${bun_path}`);
|
|
217
|
+
return Discovered.Ignored;
|
|
218
|
+
}
|
|
273
219
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
220
|
+
const bun = new Bundle(bun_manif, lib.path, lib.workspace);
|
|
221
|
+
lib.bundle = bun;
|
|
222
|
+
lib.shelve.push(bun);
|
|
223
|
+
lib.log.info(`+ 📦 bundle: ${bun.id} ⏬`);
|
|
224
|
+
// Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
|
|
225
|
+
if (bun_manif?.data?.components) {
|
|
226
|
+
for (const pub of bun_manif.data.components) {
|
|
227
|
+
const fpath = lib.path + "/" + (pub.ref ?? pub.id);
|
|
228
|
+
await discover_component(lib, fpath);
|
|
277
229
|
}
|
|
278
230
|
}
|
|
231
|
+
return Discovered.Registered;
|
|
232
|
+
}
|
|
233
|
+
function show_constants(ws) {
|
|
234
|
+
// Collect all constant keys across libraries
|
|
235
|
+
const all_keys = new Set();
|
|
236
|
+
for (const lib of ws.libraries) {
|
|
237
|
+
for (const key in lib.constants)
|
|
238
|
+
all_keys.add(key);
|
|
239
|
+
}
|
|
240
|
+
for (const name of all_keys) {
|
|
241
|
+
const lib_values = new Map();
|
|
242
|
+
for (const lib of ws.libraries) {
|
|
243
|
+
if (name in lib.constants) {
|
|
244
|
+
const val = lib.constants[name];
|
|
245
|
+
const key = String(val);
|
|
246
|
+
if (!lib_values.has(val))
|
|
247
|
+
lib_values.set(val, []);
|
|
248
|
+
lib_values.get(val).push(lib.name);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (lib_values.size === 1) {
|
|
252
|
+
const [value] = lib_values.keys();
|
|
253
|
+
ws.log.info(`+ 🔖 ${name} = ${value}`);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
for (const [value, libs] of lib_values) {
|
|
257
|
+
ws.log.info(`+ 🔖 ${name} = ${value} (${libs.join(", ")})`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
export async function discover_workspace(ws) {
|
|
263
|
+
async function walk(dir) {
|
|
264
|
+
if (await discover_library(ws, dir) === Discovered.None) {
|
|
265
|
+
for (const entry of Fs.readdirSync(dir, { withFileTypes: true })) {
|
|
266
|
+
if (entry.name === "node_modules")
|
|
267
|
+
continue;
|
|
268
|
+
const fullPath = dir + "/" + entry.name;
|
|
269
|
+
if (entry.isDirectory()) {
|
|
270
|
+
await walk(fullPath);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
await walk(ws.path);
|
|
279
276
|
show_constants(ws);
|
|
280
277
|
return ws;
|
|
281
278
|
}
|
|
@@ -2,38 +2,63 @@ import {} from "../component.js";
|
|
|
2
2
|
import { Bundle, Library } from "../workspace.js";
|
|
3
3
|
import { readSingletonConfigFile } from "../helpers/config-loader.js";
|
|
4
4
|
import {} from "../packager.js";
|
|
5
|
-
import { discover_component,
|
|
5
|
+
import { discover_component, discover_library_definitions } from "../helpers/discover-workspace.js";
|
|
6
|
+
import { makeNormalizedName, NameStyle } from "../../utils/normalized-name.js";
|
|
6
7
|
export class DefaultLibraryPackager {
|
|
7
8
|
async discover_library(lib) {
|
|
8
9
|
// Setup library infos from bundle manifest
|
|
9
10
|
setup_library_bundle(lib);
|
|
10
11
|
// Collect library declaration
|
|
11
|
-
await
|
|
12
|
+
await discover_library_definitions(lib, lib.path);
|
|
12
13
|
return lib.bundle;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
lib.log.info(`+ 📦 bundle: ${bun.id}`);
|
|
25
|
-
}
|
|
26
|
-
else if (bun.source != lib) {
|
|
27
|
-
lib.log.warn(`Conflict between two prebuild library bundle`);
|
|
28
|
-
}
|
|
29
|
-
// Analyze library deployment manifest (supports json/yaml/yml/toml, singleton)
|
|
30
|
-
if (manif?.data?.components) {
|
|
31
|
-
for (const pub of manif.data.components) {
|
|
32
|
-
const fpath = lib.path + "/" + (pub.ref ?? pub.id);
|
|
33
|
-
await discover_component(lib, fpath);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
16
|
+
export function setup_library_bundle(lib) {
|
|
17
|
+
const ws = lib.workspace;
|
|
18
|
+
const manif = make_library_bundle_manifest(lib);
|
|
19
|
+
let bun = lib.get_bundle(manif.$id);
|
|
20
|
+
if (!bun) {
|
|
21
|
+
bun = new Bundle(manif, lib.path, ws, lib);
|
|
22
|
+
lib.bundle = bun;
|
|
23
|
+
lib.shelve.push(bun);
|
|
24
|
+
lib.log.info(`+ 📦 bundle: ${bun.id} 🐣`);
|
|
36
25
|
return bun;
|
|
37
26
|
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`Library '${lib.get_id()}' is associate to a bundle '${bun.id}' that is already associated`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function collect_declarations_field(lib, key, value) {
|
|
32
|
+
for (const decl of lib.declarations.values()) {
|
|
33
|
+
if (typeof decl[key] === typeof value) {
|
|
34
|
+
if (Array.isArray(value))
|
|
35
|
+
value.push(...decl[key]);
|
|
36
|
+
else if (typeof value === "object")
|
|
37
|
+
Object.assign(value, decl[key]);
|
|
38
|
+
else
|
|
39
|
+
value = decl[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function make_library_bundle_manifest(lib) {
|
|
45
|
+
return {
|
|
46
|
+
$id: makeNormalizedName(collect_declarations_field(lib, "$id", lib.name), NameStyle.OBJECT),
|
|
47
|
+
type: "bundle",
|
|
48
|
+
name: lib.name,
|
|
49
|
+
icon: collect_declarations_field(lib, "icon", ""),
|
|
50
|
+
title: collect_declarations_field(lib, "title", lib.name),
|
|
51
|
+
tags: collect_declarations_field(lib, "tags", lib.descriptor?.tags),
|
|
52
|
+
keywords: collect_declarations_field(lib, "keywords", lib.descriptor?.keywords),
|
|
53
|
+
description: collect_declarations_field(lib, "description", lib.descriptor?.description),
|
|
54
|
+
selectors: collect_declarations_field(lib, "selectors", undefined),
|
|
55
|
+
data: {
|
|
56
|
+
package: lib.get_id(),
|
|
57
|
+
alias: collect_declarations_field(lib, "alias", lib.name),
|
|
58
|
+
namespaces: collect_declarations_field(lib, "namespaces", []),
|
|
59
|
+
dependencies: collect_declarations_field(lib, "dependencies", []),
|
|
60
|
+
distribueds: collect_declarations_field(lib, "distribueds", {}),
|
|
61
|
+
}
|
|
62
|
+
};
|
|
38
63
|
}
|
|
39
64
|
//# sourceMappingURL=packager-standard.js.map
|
package/esm/workspace/storage.js
CHANGED
|
@@ -54,17 +54,22 @@ export class StorageTransaction {
|
|
|
54
54
|
const { root, scratch, baseDir } = this;
|
|
55
55
|
await Fsp.mkdir(baseDir, { recursive: true });
|
|
56
56
|
const changes = { added: [], updated: [], changed: false };
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
const pending_writes = [...this.pending].filter(([fpath, { hash }]) => root.cache.get(fpath) !== hash);
|
|
58
|
+
const write_channel = async () => {
|
|
59
|
+
const item = pending_writes.pop();
|
|
60
|
+
if (!item)
|
|
61
|
+
return;
|
|
62
|
+
const [fpath, { data, hash }] = item;
|
|
63
|
+
const changelist = root.cache.has(fpath) ? changes.updated : changes.added;
|
|
64
|
+
changelist.push(Path.basename(fpath));
|
|
65
65
|
root.cache.set(fpath, hash);
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
await Fsp.mkdir(Path.dirname(fpath), { recursive: true });
|
|
67
|
+
await Fsp.writeFile(fpath, data);
|
|
68
|
+
if (pending_writes.length > 0) {
|
|
69
|
+
return write_channel();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
await Promise.all(Array.from({ length: Math.min(100, pending_writes.length) }, () => write_channel()));
|
|
68
73
|
this.pending.clear();
|
|
69
74
|
if (changes.updated.length > 0 || changes.added.length > 0) {
|
|
70
75
|
root.on_changes.sendEventsToAll("change", changes);
|
|
@@ -23,26 +23,37 @@ export class Library extends WorkspaceItem {
|
|
|
23
23
|
path;
|
|
24
24
|
descriptor;
|
|
25
25
|
workspace;
|
|
26
|
-
installed;
|
|
27
26
|
bundle = null;
|
|
28
27
|
declarations = new Map();
|
|
29
28
|
applications = new Map();
|
|
30
29
|
externals = {};
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
resolved_versions = {};
|
|
31
|
+
search_directories = [];
|
|
32
|
+
constants = {};
|
|
33
|
+
shelve = [];
|
|
34
|
+
constructor(name, path, descriptor, workspace) {
|
|
33
35
|
super(workspace, `lib:${name}`);
|
|
34
36
|
this.name = name;
|
|
35
37
|
this.path = path;
|
|
36
38
|
this.descriptor = descriptor;
|
|
37
39
|
this.workspace = workspace;
|
|
38
|
-
this.installed = installed;
|
|
39
|
-
this.search_directories = workspace.search_directories.slice();
|
|
40
40
|
Object.assign(this.externals, descriptor.peerDependencies, descriptor.dependencies);
|
|
41
41
|
}
|
|
42
42
|
get_id() {
|
|
43
43
|
const { name, version } = this.descriptor;
|
|
44
44
|
return `${name}-${version}`;
|
|
45
45
|
}
|
|
46
|
+
get_bundle(id) {
|
|
47
|
+
for (const bundle of this.shelve) {
|
|
48
|
+
if (bundle.id === id)
|
|
49
|
+
return bundle;
|
|
50
|
+
}
|
|
51
|
+
for (const bundle of this.shelve) {
|
|
52
|
+
if (bundle.alias === id)
|
|
53
|
+
return bundle;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
46
57
|
make_file_id(prefix, id) {
|
|
47
58
|
const devmode = true;
|
|
48
59
|
const base = devmode ? makeNormalizedName(id, NameStyle.OBJECT) : computeNameHashID(id);
|
|
@@ -104,11 +115,8 @@ export class Workspace {
|
|
|
104
115
|
version;
|
|
105
116
|
path;
|
|
106
117
|
devmode;
|
|
107
|
-
bundles = [];
|
|
108
118
|
libraries = [];
|
|
109
119
|
constants = {};
|
|
110
|
-
resolved_versions = {};
|
|
111
|
-
search_directories = [];
|
|
112
120
|
ignored_directories = new Set();
|
|
113
121
|
logger = new Logger();
|
|
114
122
|
log;
|
|
@@ -120,13 +128,14 @@ export class Workspace {
|
|
|
120
128
|
this.log = this.logger.get(`workspace:${name}`);
|
|
121
129
|
}
|
|
122
130
|
get_bundle(id) {
|
|
123
|
-
for (const
|
|
124
|
-
if (bundle.id === id)
|
|
125
|
-
return bundle;
|
|
131
|
+
for (const lib of this.libraries) {
|
|
132
|
+
if (lib.bundle.id === id)
|
|
133
|
+
return lib.bundle;
|
|
126
134
|
}
|
|
127
|
-
for (const
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
for (const lib of this.libraries) {
|
|
136
|
+
const bun = lib.get_bundle(id);
|
|
137
|
+
if (bun)
|
|
138
|
+
return bun;
|
|
130
139
|
}
|
|
131
140
|
return null;
|
|
132
141
|
}
|