@lakutata/builder 3.0.0-beta.5 → 3.0.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/dist/esm/lib/Native.js +32 -2
- package/dist/types/lib/Native.d.ts +7 -0
- package/package.json +1 -1
package/dist/esm/lib/Native.js
CHANGED
|
@@ -11,6 +11,16 @@ import { gzipSync } from 'node:zlib';
|
|
|
11
11
|
function contentOf(file) {
|
|
12
12
|
return file.content ?? readFileSync(file.source);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Whether a package is the framework, or built on it (it depends on it)
|
|
16
|
+
* @param manifest
|
|
17
|
+
*/
|
|
18
|
+
function sharesFramework(manifest) {
|
|
19
|
+
const name = String(manifest.name ?? '');
|
|
20
|
+
if (name === 'lakutata' || name.startsWith('@lakutata/'))
|
|
21
|
+
return true;
|
|
22
|
+
return ['dependencies', 'peerDependencies', 'optionalDependencies'].some((field) => !!manifest[field] && ('lakutata' in manifest[field] || '@lakutata/core' in manifest[field]));
|
|
23
|
+
}
|
|
14
24
|
/**
|
|
15
25
|
* The shared libraries: the addons, and the libraries they are linked with (sharp and libvips)
|
|
16
26
|
*/
|
|
@@ -221,7 +231,13 @@ export class NativeCollector {
|
|
|
221
231
|
const info = this.package(root);
|
|
222
232
|
if (!info)
|
|
223
233
|
return false;
|
|
224
|
-
|
|
234
|
+
if (info.addons)
|
|
235
|
+
return true;
|
|
236
|
+
//A package of the framework, or built on it, shares it with the application: bundled with it (one copy of its
|
|
237
|
+
//classes, its container), its native dependencies loaded by their names, which the bundler follows
|
|
238
|
+
if (sharesFramework(info.manifest))
|
|
239
|
+
return false;
|
|
240
|
+
return this.dependencies(root).some(({ root: dependency }) => !!this.package(dependency)?.addons);
|
|
225
241
|
}
|
|
226
242
|
/**
|
|
227
243
|
* Resolve an import as esbuild does
|
|
@@ -232,6 +248,18 @@ export class NativeCollector {
|
|
|
232
248
|
const result = await build.resolve(args.path, { kind: args.kind, resolveDir: args.resolveDir, importer: args.importer, pluginData: { [RESOLVING]: true } });
|
|
233
249
|
return result.errors.length || result.external || !result.path ? undefined : realpathSync(result.path);
|
|
234
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Whether a package is an optional dependency of the package of a module: an optional peer dependency
|
|
253
|
+
* (peerDependenciesMeta) or an optional dependency
|
|
254
|
+
* @param specifier
|
|
255
|
+
* @param importer
|
|
256
|
+
*/
|
|
257
|
+
isOptionalOf(specifier, importer) {
|
|
258
|
+
const name = specifierPackage(specifier);
|
|
259
|
+
const root = name && importer ? this.packageRoot(existsSync(importer) ? realpathSync(importer) : importer) : undefined;
|
|
260
|
+
const manifest = root ? this.package(root)?.manifest : undefined;
|
|
261
|
+
return !!name && !!manifest && (!!manifest.peerDependenciesMeta?.[name]?.optional || !!manifest.optionalDependencies?.[name]);
|
|
262
|
+
}
|
|
235
263
|
/**
|
|
236
264
|
* The plugin of the bundle: the native packages are external, the addons of the application are loaded from the tree
|
|
237
265
|
* @param transforms the transformations of the sources of the modules (the paths of the workers), giving their new
|
|
@@ -245,8 +273,10 @@ export class NativeCollector {
|
|
|
245
273
|
if (args.pluginData?.[RESOLVING] || isBuiltin(args.path) || args.kind === 'entry-point')
|
|
246
274
|
return undefined;
|
|
247
275
|
const file = await this.resolve(build, args);
|
|
276
|
+
//An optional dependency of the package importing it, not installed: left out, it throws when it is
|
|
277
|
+
//loaded at run time, as without the bundle (the drivers of the stores the application does not use)
|
|
248
278
|
if (!file)
|
|
249
|
-
return undefined;
|
|
279
|
+
return this.isOptionalOf(args.path, args.importer) ? { path: args.path, external: true } : undefined;
|
|
250
280
|
const root = this.packageRoot(file);
|
|
251
281
|
if (this.isNative(root)) {
|
|
252
282
|
const name = specifierPackage(args.path);
|
|
@@ -136,6 +136,13 @@ export declare class NativeCollector {
|
|
|
136
136
|
resolveDir: string;
|
|
137
137
|
importer: string;
|
|
138
138
|
}): Promise<string | undefined>;
|
|
139
|
+
/**
|
|
140
|
+
* Whether a package is an optional dependency of the package of a module: an optional peer dependency
|
|
141
|
+
* (peerDependenciesMeta) or an optional dependency
|
|
142
|
+
* @param specifier
|
|
143
|
+
* @param importer
|
|
144
|
+
*/
|
|
145
|
+
protected isOptionalOf(specifier: string, importer: string): boolean;
|
|
139
146
|
/**
|
|
140
147
|
* The plugin of the bundle: the native packages are external, the addons of the application are loaded from the tree
|
|
141
148
|
* @param transforms the transformations of the sources of the modules (the paths of the workers), giving their new
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/builder",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The builder of the applications of the lakutata framework: their bundles, their executables (Node.js, Bun) with their native addons and their resources.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|