@open-pioneer/vite-plugin-pioneer 0.7.0 → 0.8.1
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/CHANGELOG.md +23 -0
- package/dist/index.js +336 -313
- package/dist/index.js.map +4 -4
- package/package.json +10 -7
package/dist/index.js
CHANGED
|
@@ -35,9 +35,9 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/codegenPlugin.ts
|
|
38
|
-
var
|
|
38
|
+
var import_node_fs2 = require("node:fs");
|
|
39
39
|
var import_node_path3 = require("node:path");
|
|
40
|
-
var
|
|
40
|
+
var import_vite4 = require("vite");
|
|
41
41
|
|
|
42
42
|
// src/utils/debug.ts
|
|
43
43
|
var import_debug = require("debug");
|
|
@@ -132,7 +132,7 @@ function generatePackagesMetadata({ appName, packages }) {
|
|
|
132
132
|
for (const pkg of packages) {
|
|
133
133
|
if (pkg.name === appName) {
|
|
134
134
|
overrides = pkg.config.overrides;
|
|
135
|
-
} else if (pkg.config.overrides
|
|
135
|
+
} else if (pkg.config.overrides) {
|
|
136
136
|
throw new ReportableError(
|
|
137
137
|
`Unexpected 'overrides' in package '${pkg.name}'. Overrides are only supported in the app.`
|
|
138
138
|
);
|
|
@@ -264,21 +264,9 @@ function undefinedNode() {
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
// src/metadata/MetadataRepository.ts
|
|
267
|
-
var
|
|
267
|
+
var import_promises3 = require("fs/promises");
|
|
268
268
|
var import_path = require("path");
|
|
269
|
-
var
|
|
270
|
-
|
|
271
|
-
// src/utils/fileUtils.ts
|
|
272
|
-
var fs = __toESM(require("node:fs"));
|
|
273
|
-
var import_node_path = require("node:path");
|
|
274
|
-
function fileExists(file) {
|
|
275
|
-
return fs.promises.access(file, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
276
|
-
}
|
|
277
|
-
function isInDirectory(candidate, directory) {
|
|
278
|
-
const rel = (0, import_node_path.relative)(directory, candidate);
|
|
279
|
-
const isChild = rel && !rel.startsWith("..") && !(0, import_node_path.isAbsolute)(rel);
|
|
280
|
-
return !!isChild;
|
|
281
|
-
}
|
|
269
|
+
var import_vite2 = require("vite");
|
|
282
270
|
|
|
283
271
|
// src/utils/Cache.ts
|
|
284
272
|
var Cache = class {
|
|
@@ -345,17 +333,6 @@ var Cache = class {
|
|
|
345
333
|
}
|
|
346
334
|
};
|
|
347
335
|
|
|
348
|
-
// src/metadata/parseBuildConfig.ts
|
|
349
|
-
var import_build_common = require("@open-pioneer/build-common");
|
|
350
|
-
var import_node_path2 = require("node:path");
|
|
351
|
-
async function loadBuildConfig(path) {
|
|
352
|
-
const rawConfig = await (0, import_build_common.loadBuildConfig)(path);
|
|
353
|
-
return (0, import_build_common.createPackageConfigFromBuildConfig)(rawConfig);
|
|
354
|
-
}
|
|
355
|
-
function isBuildConfig(file) {
|
|
356
|
-
return (0, import_node_path2.basename)(file) === import_build_common.BUILD_CONFIG_NAME;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
336
|
// src/metadata/parseI18nYaml.ts
|
|
360
337
|
var import_promises = require("fs/promises");
|
|
361
338
|
var import_js_yaml = require("js-yaml");
|
|
@@ -391,10 +368,12 @@ function parseI18nFile(data) {
|
|
|
391
368
|
throw (0, import_zod_validation_error.fromZodError)(result.error);
|
|
392
369
|
}
|
|
393
370
|
const rawI18n = result.data;
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
371
|
+
const messages = gatherMessages((rawI18n == null ? void 0 : rawI18n.messages) ?? void 0);
|
|
372
|
+
let overrides;
|
|
373
|
+
if (typeof (rawI18n == null ? void 0 : rawI18n.overrides) === "object") {
|
|
374
|
+
overrides = gatherOverrides((rawI18n == null ? void 0 : rawI18n.overrides) ?? void 0);
|
|
375
|
+
}
|
|
376
|
+
return { messages, overrides };
|
|
398
377
|
}
|
|
399
378
|
function gatherMessages(data) {
|
|
400
379
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -433,16 +412,263 @@ function gatherOverrides(data) {
|
|
|
433
412
|
return overrides;
|
|
434
413
|
}
|
|
435
414
|
|
|
436
|
-
// src/metadata/
|
|
437
|
-
var
|
|
415
|
+
// src/metadata/loadPackageMetadata.ts
|
|
416
|
+
var import_promises2 = require("node:fs/promises");
|
|
417
|
+
|
|
418
|
+
// src/utils/fileUtils.ts
|
|
419
|
+
var fs = __toESM(require("node:fs"));
|
|
420
|
+
var import_node_path = require("node:path");
|
|
421
|
+
function fileExists(file) {
|
|
422
|
+
return fs.promises.access(file, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
423
|
+
}
|
|
424
|
+
function isInDirectory(candidate, directory) {
|
|
425
|
+
const rel = (0, import_node_path.relative)(directory, candidate);
|
|
426
|
+
const isChild = rel && !rel.startsWith("..") && !(0, import_node_path.isAbsolute)(rel);
|
|
427
|
+
return !!isChild;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/metadata/loadPackageMetadata.ts
|
|
431
|
+
var import_build_common = require("@open-pioneer/build-common");
|
|
432
|
+
var import_vite = require("vite");
|
|
433
|
+
var import_node_path2 = require("node:path");
|
|
438
434
|
|
|
439
435
|
// src/utils/package.ts
|
|
440
436
|
var PACKAGE_NAME = "@open-pioneer/vite-plugin-pioneer";
|
|
441
437
|
|
|
442
|
-
// src/metadata/
|
|
443
|
-
var
|
|
438
|
+
// src/metadata/loadPackageMetadata.ts
|
|
439
|
+
var import_node_fs = require("node:fs");
|
|
444
440
|
var isDebug = !!process.env.DEBUG;
|
|
445
441
|
var debug2 = createDebugger("open-pioneer:metadata");
|
|
442
|
+
async function loadPackageMetadata(ctx, packageDir, sourceRoot) {
|
|
443
|
+
return await new PackageMetadataReader(ctx, packageDir, sourceRoot).readPackageMetadata();
|
|
444
|
+
}
|
|
445
|
+
var PackageMetadataReader = class {
|
|
446
|
+
ctx;
|
|
447
|
+
packageDir;
|
|
448
|
+
sourceRoot;
|
|
449
|
+
packageJsonPath;
|
|
450
|
+
constructor(ctx, packageDir, sourceRoot) {
|
|
451
|
+
this.ctx = ctx;
|
|
452
|
+
this.packageDir = packageDir;
|
|
453
|
+
this.sourceRoot = sourceRoot;
|
|
454
|
+
this.packageJsonPath = (0, import_node_path2.join)(packageDir, "package.json");
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Reads package metadata for the configured package.
|
|
458
|
+
*/
|
|
459
|
+
async readPackageMetadata() {
|
|
460
|
+
const { ctx, packageDir, packageJsonPath, sourceRoot } = this;
|
|
461
|
+
const mode = isLocalPackage(packageDir, sourceRoot) ? "local" : "external";
|
|
462
|
+
isDebug && debug2(`Visiting package directory ${packageDir} in mode ${mode}.`);
|
|
463
|
+
ctx.addWatchFile(packageJsonPath);
|
|
464
|
+
const {
|
|
465
|
+
name: packageName,
|
|
466
|
+
dependencies,
|
|
467
|
+
frameworkMetadata
|
|
468
|
+
} = await parsePackageJson(packageJsonPath);
|
|
469
|
+
const configResult = await this.readConfig(mode, packageName, frameworkMetadata);
|
|
470
|
+
if (!configResult) {
|
|
471
|
+
return {
|
|
472
|
+
type: "plain",
|
|
473
|
+
name: packageName,
|
|
474
|
+
directory: packageDir
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const { config, configPath } = configResult;
|
|
478
|
+
let servicesModule;
|
|
479
|
+
if (config.services.size) {
|
|
480
|
+
try {
|
|
481
|
+
servicesModule = await resolveLocalFile(
|
|
482
|
+
ctx,
|
|
483
|
+
packageDir,
|
|
484
|
+
config.servicesModule ?? "./services"
|
|
485
|
+
);
|
|
486
|
+
} catch (e) {
|
|
487
|
+
ctx.warn({
|
|
488
|
+
message: `Failed to resolve services entry point for package ${packageDir}`,
|
|
489
|
+
cause: e
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
let cssFile;
|
|
494
|
+
if (config.styles) {
|
|
495
|
+
try {
|
|
496
|
+
cssFile = await resolveLocalFile(ctx, packageDir, config.styles);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
throw new ReportableError(`Failed to resolve css file for package ${packageDir}`, {
|
|
499
|
+
cause: e
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (!cssFile) {
|
|
503
|
+
throw new ReportableError(
|
|
504
|
+
`Failed to find css file '${config.styles}' in ${packageDir}`
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const i18nPaths = /* @__PURE__ */ new Map();
|
|
509
|
+
for (const locale of config.languages) {
|
|
510
|
+
if (i18nPaths.has(locale)) {
|
|
511
|
+
throw new ReportableError(`Locale '${locale}' was defined twice in ${configPath}`);
|
|
512
|
+
}
|
|
513
|
+
const path = (0, import_node_path2.join)(packageDir, "i18n", `${locale}.yaml`);
|
|
514
|
+
ctx.addWatchFile(path);
|
|
515
|
+
if (!await fileExists(path)) {
|
|
516
|
+
throw new ReportableError(`i18n file '${path}' does not exist.`);
|
|
517
|
+
}
|
|
518
|
+
i18nPaths.set(locale, (0, import_vite.normalizePath)(path));
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
type: "pioneer-package",
|
|
522
|
+
name: packageName,
|
|
523
|
+
directory: packageDir,
|
|
524
|
+
packageJsonPath,
|
|
525
|
+
servicesModulePath: servicesModule,
|
|
526
|
+
cssFilePath: cssFile,
|
|
527
|
+
i18nPaths,
|
|
528
|
+
dependencies,
|
|
529
|
+
config
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Attempts to read the package's metadata/configuration, depending on mode.
|
|
534
|
+
*/
|
|
535
|
+
async readConfig(mode, packageName, frameworkMetadata) {
|
|
536
|
+
const { ctx, packageDir } = this;
|
|
537
|
+
switch (mode) {
|
|
538
|
+
case "external": {
|
|
539
|
+
if (!frameworkMetadata) {
|
|
540
|
+
return void 0;
|
|
541
|
+
}
|
|
542
|
+
return this.parsePackageConfigFromMetadata(packageName, frameworkMetadata);
|
|
543
|
+
}
|
|
544
|
+
case "local": {
|
|
545
|
+
const buildConfigPath = (0, import_node_path2.join)(packageDir, import_build_common.BUILD_CONFIG_NAME);
|
|
546
|
+
const buildConfigExists = (0, import_node_fs.existsSync)(buildConfigPath);
|
|
547
|
+
if (buildConfigExists && frameworkMetadata) {
|
|
548
|
+
throw new Error(
|
|
549
|
+
`Package '${packageName}' at ${packageDir} contains both framework metadata in its package.json and a ${import_build_common.BUILD_CONFIG_NAME}. Mixing both formats is not supported. Metadata in package.json files is only intended for distributed packages.`
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
if (frameworkMetadata) {
|
|
553
|
+
ctx.warn(
|
|
554
|
+
`Using framework metadata from package.json instead of ${import_build_common.BUILD_CONFIG_NAME} in ${packageDir}, make sure that this intended.`
|
|
555
|
+
);
|
|
556
|
+
return this.parsePackageConfigFromMetadata(packageName, frameworkMetadata);
|
|
557
|
+
}
|
|
558
|
+
return this.parsePackageConfigFromBuildConfig(buildConfigPath);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Attempts to read the package configuration from the package.json's metadata value.
|
|
564
|
+
* Note that the value may not be present at this point if the package does not use open pioneer metadata.
|
|
565
|
+
*/
|
|
566
|
+
async parsePackageConfigFromMetadata(packageName, frameworkMetadata) {
|
|
567
|
+
const { packageDir, packageJsonPath } = this;
|
|
568
|
+
const metadataResult = import_build_common.PackageMetadataV1.parsePackageMetadata(frameworkMetadata);
|
|
569
|
+
if (metadataResult.type === "error") {
|
|
570
|
+
if (metadataResult.code === "unsupported-version") {
|
|
571
|
+
throw new ReportableError(
|
|
572
|
+
`Package '${packageName}' in ${packageDir} uses an unsupported package metadata version. Try updating ${PACKAGE_NAME}.
|
|
573
|
+
|
|
574
|
+
` + metadataResult.message,
|
|
575
|
+
{ cause: metadataResult.cause }
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
throw new ReportableError(
|
|
579
|
+
`Failed to parse metadata of package '${packageName}' in ${packageDir}: ${metadataResult.message}`,
|
|
580
|
+
{ cause: metadataResult.cause }
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
configPath: packageJsonPath,
|
|
585
|
+
config: (0, import_build_common.createPackageConfigFromPackageMetadata)(metadataResult.value)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
async parsePackageConfigFromBuildConfig(buildConfigPath) {
|
|
589
|
+
const { ctx, packageDir } = this;
|
|
590
|
+
let buildConfig;
|
|
591
|
+
ctx.addWatchFile((0, import_vite.normalizePath)(buildConfigPath));
|
|
592
|
+
if (await fileExists(buildConfigPath)) {
|
|
593
|
+
try {
|
|
594
|
+
buildConfig = await (0, import_build_common.loadBuildConfig)(buildConfigPath);
|
|
595
|
+
} catch (e) {
|
|
596
|
+
throw new ReportableError(`Failed to load build config ${buildConfigPath}`, {
|
|
597
|
+
cause: e
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
} else {
|
|
601
|
+
throw new ReportableError(`Expected a ${import_build_common.BUILD_CONFIG_NAME} in ${packageDir}`);
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
configPath: buildConfigPath,
|
|
605
|
+
config: (0, import_build_common.createPackageConfigFromBuildConfig)(buildConfig)
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
async function parsePackageJson(packageJsonPath) {
|
|
610
|
+
if (!await fileExists(packageJsonPath)) {
|
|
611
|
+
throw new ReportableError(`Expected a 'package.json' file at ${packageJsonPath}`);
|
|
612
|
+
}
|
|
613
|
+
let packageJsonContent;
|
|
614
|
+
try {
|
|
615
|
+
packageJsonContent = JSON.parse(await (0, import_promises2.readFile)(packageJsonPath, "utf-8"));
|
|
616
|
+
} catch (e) {
|
|
617
|
+
throw new ReportableError(`Failed to read ${packageJsonPath}`, { cause: e });
|
|
618
|
+
}
|
|
619
|
+
const packageName = packageJsonContent.name;
|
|
620
|
+
if (typeof packageName !== "string") {
|
|
621
|
+
throw new ReportableError(`Expected 'name' to be a string in ${packageJsonPath}`);
|
|
622
|
+
}
|
|
623
|
+
const dependencies = packageJsonContent.dependencies ?? {};
|
|
624
|
+
if (typeof dependencies !== "object") {
|
|
625
|
+
throw new ReportableError(`Expected a valid 'dependencies' object in ${packageJsonPath}`);
|
|
626
|
+
}
|
|
627
|
+
const peerDependencies = packageJsonContent.peerDependencies ?? {};
|
|
628
|
+
if (typeof peerDependencies !== "object") {
|
|
629
|
+
throw new ReportableError(
|
|
630
|
+
`Expected a valid 'peerDependencies' object in ${packageJsonPath}`
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
const optionalDependencies = packageJsonContent.optionalDependencies ?? {};
|
|
634
|
+
if (typeof optionalDependencies !== "object") {
|
|
635
|
+
throw new ReportableError(
|
|
636
|
+
`Expected a valid 'optionalDependencies' object in ${packageJsonPath}`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const allDependencies = [
|
|
640
|
+
...Object.keys(dependencies).map((packageName2) => ({ packageName: packageName2, optional: false })),
|
|
641
|
+
...Object.keys(peerDependencies).map((packageName2) => {
|
|
642
|
+
var _a, _b;
|
|
643
|
+
return {
|
|
644
|
+
packageName: packageName2,
|
|
645
|
+
optional: ((_b = (_a = packageJsonContent == null ? void 0 : packageJsonContent.peerDependenciesMeta) == null ? void 0 : _a[packageName2]) == null ? void 0 : _b.optional) ?? false
|
|
646
|
+
};
|
|
647
|
+
}),
|
|
648
|
+
...Object.keys(optionalDependencies).map((packageName2) => ({ packageName: packageName2, optional: true }))
|
|
649
|
+
];
|
|
650
|
+
const frameworkMetadata = packageJsonContent[import_build_common.PackageMetadataV1.PACKAGE_JSON_KEY] ?? void 0;
|
|
651
|
+
return {
|
|
652
|
+
name: packageName,
|
|
653
|
+
dependencies: allDependencies,
|
|
654
|
+
frameworkMetadata
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
async function resolveLocalFile(ctx, packageDir, localModuleId) {
|
|
658
|
+
const result = await ctx.resolve(`./${localModuleId}`, `${packageDir}/package.json`, {
|
|
659
|
+
skipSelf: true
|
|
660
|
+
});
|
|
661
|
+
return result == null ? void 0 : result.id;
|
|
662
|
+
}
|
|
663
|
+
var NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
664
|
+
function isLocalPackage(file, sourceDir) {
|
|
665
|
+
return isInDirectory(file, sourceDir) && !NODE_MODULES_RE.test(file);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/metadata/MetadataRepository.ts
|
|
669
|
+
var import_build_common2 = require("@open-pioneer/build-common");
|
|
670
|
+
var isDebug2 = !!process.env.DEBUG;
|
|
671
|
+
var debug3 = createDebugger("open-pioneer:metadata");
|
|
446
672
|
var MetadataRepository = class {
|
|
447
673
|
sourceRoot;
|
|
448
674
|
// Key: package directory on disk, value: existing metadata
|
|
@@ -483,7 +709,7 @@ var MetadataRepository = class {
|
|
|
483
709
|
* will be returned here.
|
|
484
710
|
*/
|
|
485
711
|
async getAppMetadata(ctx, appDirectory) {
|
|
486
|
-
|
|
712
|
+
isDebug2 && debug3(`Request for app metadata of ${appDirectory}`);
|
|
487
713
|
const appPackageMetadata = await this.getPackageMetadata(ctx, {
|
|
488
714
|
type: "absolute",
|
|
489
715
|
directory: appDirectory
|
|
@@ -532,18 +758,15 @@ var MetadataRepository = class {
|
|
|
532
758
|
* Returns package metadata associated with the given package.
|
|
533
759
|
*/
|
|
534
760
|
async getPackageMetadata(ctx, loc) {
|
|
535
|
-
|
|
761
|
+
isDebug2 && debug3(`Request for package metadata of ${formatPackageLocation(loc)}`);
|
|
536
762
|
const packageDir = await this.resolvePackageLocation(loc);
|
|
537
763
|
if (!packageDir) {
|
|
538
764
|
return void 0;
|
|
539
765
|
}
|
|
540
766
|
const entry = await this.packageMetadataCache.get(packageDir, ctx);
|
|
541
767
|
propagateWatchFiles(entry.watchFiles, ctx);
|
|
542
|
-
for (const warning of entry.warnings) {
|
|
543
|
-
ctx.warn(warning);
|
|
544
|
-
}
|
|
545
768
|
if (entry.metadata.type === "plain") {
|
|
546
|
-
|
|
769
|
+
isDebug2 && debug3(`Skipping package '${packageDir}'.`);
|
|
547
770
|
return void 0;
|
|
548
771
|
}
|
|
549
772
|
return entry.metadata;
|
|
@@ -558,7 +781,7 @@ var MetadataRepository = class {
|
|
|
558
781
|
}
|
|
559
782
|
async resolvePackageLocation(loc) {
|
|
560
783
|
if (loc.type === "absolute") {
|
|
561
|
-
return await (0,
|
|
784
|
+
return await (0, import_promises3.realpath)(loc.directory);
|
|
562
785
|
}
|
|
563
786
|
const { packageName, optional } = loc.dependency;
|
|
564
787
|
const { resolvePackageData } = await import("vite");
|
|
@@ -570,24 +793,24 @@ var MetadataRepository = class {
|
|
|
570
793
|
);
|
|
571
794
|
if (!packageData) {
|
|
572
795
|
if (optional) {
|
|
573
|
-
|
|
796
|
+
isDebug2 && debug3(`Optional package '${packageName}' was not found.`);
|
|
574
797
|
return void 0;
|
|
575
798
|
}
|
|
576
799
|
throw new ReportableError(
|
|
577
800
|
`Failed to find package '${packageName}' (from '${loc.importedFrom}'), is the dependency installed correctly?`
|
|
578
801
|
);
|
|
579
802
|
}
|
|
580
|
-
const packageDir = await (0,
|
|
581
|
-
|
|
803
|
+
const packageDir = await (0, import_promises3.realpath)(packageData.dir);
|
|
804
|
+
isDebug2 && debug3(`Found package '${packageName}' at ${packageDir}`);
|
|
582
805
|
return packageDir;
|
|
583
806
|
}
|
|
584
807
|
createI18nCache() {
|
|
585
808
|
return new Cache({
|
|
586
809
|
getId(path) {
|
|
587
|
-
return (0,
|
|
810
|
+
return (0, import_vite2.normalizePath)(path);
|
|
588
811
|
},
|
|
589
812
|
async getValue(path, ctx) {
|
|
590
|
-
|
|
813
|
+
isDebug2 && debug3(`Loading i18n file ${path}`);
|
|
591
814
|
ctx.addWatchFile(path);
|
|
592
815
|
const entry = {
|
|
593
816
|
i18n: await loadI18nFile(path),
|
|
@@ -596,10 +819,10 @@ var MetadataRepository = class {
|
|
|
596
819
|
return entry;
|
|
597
820
|
},
|
|
598
821
|
onInvalidate(path) {
|
|
599
|
-
|
|
822
|
+
isDebug2 && debug3(`Removed cache entry for i18n file ${path}`);
|
|
600
823
|
},
|
|
601
824
|
onCachedReturn(path) {
|
|
602
|
-
|
|
825
|
+
isDebug2 && debug3(`Returning cached entry for i18n file ${path}`);
|
|
603
826
|
}
|
|
604
827
|
});
|
|
605
828
|
}
|
|
@@ -608,27 +831,24 @@ var MetadataRepository = class {
|
|
|
608
831
|
const provider = {
|
|
609
832
|
_byName: /* @__PURE__ */ new Map(),
|
|
610
833
|
getId(directory) {
|
|
611
|
-
return (0,
|
|
834
|
+
return (0, import_vite2.normalizePath)(directory);
|
|
612
835
|
},
|
|
613
836
|
async getValue(directory, ctx) {
|
|
614
|
-
|
|
837
|
+
isDebug2 && debug3(`Loading metadata for package at ${directory}`);
|
|
615
838
|
const watchFiles = /* @__PURE__ */ new Set();
|
|
616
|
-
const warnings = [];
|
|
617
839
|
const trackingCtx = {
|
|
618
840
|
resolve: ctx.resolve,
|
|
619
841
|
addWatchFile(id) {
|
|
620
842
|
ctx.addWatchFile(id);
|
|
621
843
|
watchFiles.add(id);
|
|
622
844
|
},
|
|
623
|
-
warn
|
|
624
|
-
warnings.push(typeof msg === "string" ? { message: msg } : msg);
|
|
625
|
-
}
|
|
845
|
+
warn: ctx.warn
|
|
626
846
|
};
|
|
627
|
-
const metadata = await
|
|
628
|
-
|
|
847
|
+
const metadata = await loadPackageMetadata(trackingCtx, directory, sourceRoot);
|
|
848
|
+
isDebug2 && debug3(`Metadata for '${metadata.name}': %O`, metadata);
|
|
629
849
|
if (metadata.type === "pioneer-package") {
|
|
630
850
|
const existingMetadata = this._byName.get(metadata.name);
|
|
631
|
-
if (existingMetadata && (0,
|
|
851
|
+
if (existingMetadata && (0, import_vite2.normalizePath)(existingMetadata.directory) !== (0, import_vite2.normalizePath)(metadata.directory)) {
|
|
632
852
|
throw new ReportableError(
|
|
633
853
|
`Found package '${metadata.name}' at two different locations ${existingMetadata.directory} and ${metadata.directory}`
|
|
634
854
|
);
|
|
@@ -637,16 +857,15 @@ var MetadataRepository = class {
|
|
|
637
857
|
}
|
|
638
858
|
return {
|
|
639
859
|
metadata,
|
|
640
|
-
watchFiles
|
|
641
|
-
warnings
|
|
860
|
+
watchFiles
|
|
642
861
|
};
|
|
643
862
|
},
|
|
644
863
|
onInvalidate(directory, entry) {
|
|
645
|
-
|
|
864
|
+
isDebug2 && debug3(`Removed cache entry for '${entry.metadata.name}'`);
|
|
646
865
|
this._byName.delete(entry.metadata.name);
|
|
647
866
|
},
|
|
648
867
|
onCachedReturn(directory, entry) {
|
|
649
|
-
|
|
868
|
+
isDebug2 && debug3(`Returning cached metadata for '${entry.metadata.name}'`);
|
|
650
869
|
}
|
|
651
870
|
};
|
|
652
871
|
return new Cache(provider);
|
|
@@ -657,200 +876,6 @@ function propagateWatchFiles(watchFiles, ctx) {
|
|
|
657
876
|
ctx.addWatchFile(file);
|
|
658
877
|
}
|
|
659
878
|
}
|
|
660
|
-
async function parsePackageMetadata(ctx, packageDir, sourceRoot) {
|
|
661
|
-
const mode = isLocalPackage(packageDir, sourceRoot) ? "local" : "external";
|
|
662
|
-
isDebug && debug2(`Visiting package directory ${packageDir} in mode ${mode}.`);
|
|
663
|
-
const packageJsonPath = (0, import_path.join)(packageDir, "package.json");
|
|
664
|
-
ctx.addWatchFile(packageJsonPath);
|
|
665
|
-
const {
|
|
666
|
-
name: packageName,
|
|
667
|
-
dependencies,
|
|
668
|
-
frameworkMetadata
|
|
669
|
-
} = await parsePackageJson(ctx, packageJsonPath);
|
|
670
|
-
const configResult = await readConfig(
|
|
671
|
-
ctx,
|
|
672
|
-
packageDir,
|
|
673
|
-
mode,
|
|
674
|
-
frameworkMetadata,
|
|
675
|
-
packageName,
|
|
676
|
-
packageJsonPath
|
|
677
|
-
);
|
|
678
|
-
if (!configResult) {
|
|
679
|
-
return {
|
|
680
|
-
type: "plain",
|
|
681
|
-
name: packageName,
|
|
682
|
-
directory: packageDir
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
const { config, configPath } = configResult;
|
|
686
|
-
let servicesModule;
|
|
687
|
-
if (config.services.size) {
|
|
688
|
-
try {
|
|
689
|
-
servicesModule = await resolveLocalFile(
|
|
690
|
-
ctx,
|
|
691
|
-
packageDir,
|
|
692
|
-
config.servicesModule ?? "./services"
|
|
693
|
-
);
|
|
694
|
-
} catch (e) {
|
|
695
|
-
ctx.warn({
|
|
696
|
-
message: `Failed to resolve entry point for package ${packageDir}`,
|
|
697
|
-
cause: e
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
let cssFile;
|
|
702
|
-
if (config.styles) {
|
|
703
|
-
try {
|
|
704
|
-
cssFile = await resolveLocalFile(ctx, packageDir, config.styles);
|
|
705
|
-
} catch (e) {
|
|
706
|
-
throw new ReportableError(`Failed to resolve css file for package ${packageDir}`, {
|
|
707
|
-
cause: e
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
if (!cssFile) {
|
|
711
|
-
throw new ReportableError(
|
|
712
|
-
`Failed to find css file '${config.styles}' in ${packageDir}`
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
const i18nPaths = /* @__PURE__ */ new Map();
|
|
717
|
-
for (const locale of config.languages) {
|
|
718
|
-
if (i18nPaths.has(locale)) {
|
|
719
|
-
throw new ReportableError(`Locale '${locale}' was defined twice in ${configPath}`);
|
|
720
|
-
}
|
|
721
|
-
const path = (0, import_path.join)(packageDir, "i18n", `${locale}.yaml`);
|
|
722
|
-
ctx.addWatchFile(path);
|
|
723
|
-
if (!await fileExists(path)) {
|
|
724
|
-
throw new ReportableError(`i18n file '${path}' does not exist.`);
|
|
725
|
-
}
|
|
726
|
-
i18nPaths.set(locale, (0, import_vite.normalizePath)(path));
|
|
727
|
-
}
|
|
728
|
-
return {
|
|
729
|
-
type: "pioneer-package",
|
|
730
|
-
name: packageName,
|
|
731
|
-
directory: packageDir,
|
|
732
|
-
packageJsonPath,
|
|
733
|
-
servicesModulePath: servicesModule,
|
|
734
|
-
cssFilePath: cssFile,
|
|
735
|
-
i18nPaths,
|
|
736
|
-
dependencies,
|
|
737
|
-
config
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
async function readConfig(ctx, packageDir, mode, frameworkMetadata, packageName, packageJsonPath) {
|
|
741
|
-
const parsePackageConfigFromMetadata = () => {
|
|
742
|
-
const metadataResult = import_build_common2.PackageMetadataV1.parsePackageMetadata(frameworkMetadata);
|
|
743
|
-
if (metadataResult.type === "error") {
|
|
744
|
-
if (metadataResult.code === "unsupported-version") {
|
|
745
|
-
throw new ReportableError(
|
|
746
|
-
`Package '${packageName}' in ${packageDir} uses an unsupported package metadata version. Try updating ${PACKAGE_NAME}.
|
|
747
|
-
|
|
748
|
-
` + metadataResult.message,
|
|
749
|
-
{ cause: metadataResult.cause }
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
throw new ReportableError(
|
|
753
|
-
`Failed to parse metadata of package '${packageName}' in ${packageDir}: ${metadataResult.message}`,
|
|
754
|
-
{ cause: metadataResult.cause }
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
return {
|
|
758
|
-
configPath: packageJsonPath,
|
|
759
|
-
config: (0, import_build_common2.createPackageConfigFromPackageMetadata)(metadataResult.value)
|
|
760
|
-
};
|
|
761
|
-
};
|
|
762
|
-
switch (mode) {
|
|
763
|
-
case "external": {
|
|
764
|
-
if (!frameworkMetadata) {
|
|
765
|
-
return void 0;
|
|
766
|
-
}
|
|
767
|
-
return parsePackageConfigFromMetadata();
|
|
768
|
-
}
|
|
769
|
-
case "local": {
|
|
770
|
-
const buildConfigPath = (0, import_path.join)(packageDir, import_build_common2.BUILD_CONFIG_NAME);
|
|
771
|
-
const buildConfigExists = (0, import_fs.existsSync)(buildConfigPath);
|
|
772
|
-
if (buildConfigExists && frameworkMetadata) {
|
|
773
|
-
throw new Error(
|
|
774
|
-
`Package '${packageName}' at ${packageDir} contains both framework metadata in its package.json and a ${import_build_common2.BUILD_CONFIG_NAME}. Mixing both formats is not supported. Metadata in package.json files is only intended for distributed packages.`
|
|
775
|
-
);
|
|
776
|
-
}
|
|
777
|
-
if (frameworkMetadata) {
|
|
778
|
-
ctx.warn(
|
|
779
|
-
`Using framework metadata from package.json instead of ${import_build_common2.BUILD_CONFIG_NAME} in ${packageDir}, make sure that this intended.`
|
|
780
|
-
);
|
|
781
|
-
return parsePackageConfigFromMetadata();
|
|
782
|
-
}
|
|
783
|
-
let buildConfig;
|
|
784
|
-
ctx.addWatchFile((0, import_vite.normalizePath)(buildConfigPath));
|
|
785
|
-
if (await fileExists(buildConfigPath)) {
|
|
786
|
-
try {
|
|
787
|
-
buildConfig = await loadBuildConfig(buildConfigPath);
|
|
788
|
-
} catch (e) {
|
|
789
|
-
throw new ReportableError(`Failed to load build config ${buildConfigPath}`, {
|
|
790
|
-
cause: e
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
} else {
|
|
794
|
-
throw new ReportableError(`Expected a ${import_build_common2.BUILD_CONFIG_NAME} in ${packageDir}`);
|
|
795
|
-
}
|
|
796
|
-
return { configPath: buildConfigPath, config: buildConfig };
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
async function parsePackageJson(ctx, packageJsonPath) {
|
|
801
|
-
if (!await fileExists(packageJsonPath)) {
|
|
802
|
-
throw new ReportableError(`Expected a 'package.json' file at ${packageJsonPath}`);
|
|
803
|
-
}
|
|
804
|
-
let packageJsonContent;
|
|
805
|
-
try {
|
|
806
|
-
packageJsonContent = JSON.parse(await (0, import_promises2.readFile)(packageJsonPath, "utf-8"));
|
|
807
|
-
} catch (e) {
|
|
808
|
-
throw new ReportableError(`Failed to read ${packageJsonPath}`, { cause: e });
|
|
809
|
-
}
|
|
810
|
-
const packageName = packageJsonContent.name;
|
|
811
|
-
if (typeof packageName !== "string") {
|
|
812
|
-
throw new ReportableError(`Expected 'name' to be a string in ${packageJsonPath}`);
|
|
813
|
-
}
|
|
814
|
-
const dependencies = packageJsonContent.dependencies ?? {};
|
|
815
|
-
if (typeof dependencies !== "object") {
|
|
816
|
-
throw new ReportableError(`Expected a valid 'dependencies' object in ${packageJsonPath}`);
|
|
817
|
-
}
|
|
818
|
-
const peerDependencies = packageJsonContent.peerDependencies ?? {};
|
|
819
|
-
if (typeof peerDependencies !== "object") {
|
|
820
|
-
throw new ReportableError(
|
|
821
|
-
`Expected a valid 'peerDependencies' object in ${packageJsonPath}`
|
|
822
|
-
);
|
|
823
|
-
}
|
|
824
|
-
const optionalDependencies = packageJsonContent.optionalDependencies ?? {};
|
|
825
|
-
if (typeof optionalDependencies !== "object") {
|
|
826
|
-
throw new ReportableError(
|
|
827
|
-
`Expected a valid 'optionalDependencies' object in ${packageJsonPath}`
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
const allDependencies = [
|
|
831
|
-
...Object.keys(dependencies).map((packageName2) => ({ packageName: packageName2, optional: false })),
|
|
832
|
-
...Object.keys(peerDependencies).map((packageName2) => {
|
|
833
|
-
var _a, _b;
|
|
834
|
-
return {
|
|
835
|
-
packageName: packageName2,
|
|
836
|
-
optional: ((_b = (_a = packageJsonContent == null ? void 0 : packageJsonContent.peerDependenciesMeta) == null ? void 0 : _a[packageName2]) == null ? void 0 : _b.optional) ?? false
|
|
837
|
-
};
|
|
838
|
-
}),
|
|
839
|
-
...Object.keys(optionalDependencies).map((packageName2) => ({ packageName: packageName2, optional: true }))
|
|
840
|
-
];
|
|
841
|
-
const frameworkMetadata = packageJsonContent[import_build_common2.PackageMetadataV1.PACKAGE_JSON_KEY] ?? void 0;
|
|
842
|
-
return {
|
|
843
|
-
name: packageName,
|
|
844
|
-
dependencies: allDependencies,
|
|
845
|
-
frameworkMetadata
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
async function resolveLocalFile(ctx, packageDir, localModuleId) {
|
|
849
|
-
const result = await ctx.resolve(`./${localModuleId}`, `${packageDir}/package.json`, {
|
|
850
|
-
skipSelf: true
|
|
851
|
-
});
|
|
852
|
-
return result == null ? void 0 : result.id;
|
|
853
|
-
}
|
|
854
879
|
function formatPackageLocation(loc) {
|
|
855
880
|
switch (loc.type) {
|
|
856
881
|
case "absolute":
|
|
@@ -864,14 +889,13 @@ function formatPackageLocation(loc) {
|
|
|
864
889
|
}
|
|
865
890
|
}
|
|
866
891
|
}
|
|
867
|
-
var NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
868
|
-
function isLocalPackage(file, sourceDir) {
|
|
869
|
-
return isInDirectory(file, sourceDir) && !NODE_MODULES_RE.test(file);
|
|
870
|
-
}
|
|
871
892
|
var PACKAGE_JSON_RE = /[\\/]package\.json($|\?)/;
|
|
872
893
|
function isPackageJson(file) {
|
|
873
894
|
return PACKAGE_JSON_RE.test(file);
|
|
874
895
|
}
|
|
896
|
+
function isBuildConfig(file) {
|
|
897
|
+
return (0, import_path.basename)(file) === import_build_common2.BUILD_CONFIG_NAME;
|
|
898
|
+
}
|
|
875
899
|
|
|
876
900
|
// src/codegen/generateCombinedCss.ts
|
|
877
901
|
function generateCombinedCss(packages) {
|
|
@@ -881,7 +905,7 @@ function generateCombinedCss(packages) {
|
|
|
881
905
|
|
|
882
906
|
// src/codegen/shared.ts
|
|
883
907
|
var import_posix = require("node:path/posix");
|
|
884
|
-
var
|
|
908
|
+
var import_vite3 = require("vite");
|
|
885
909
|
var APP_MODULE = "@@open-pioneer-app";
|
|
886
910
|
var APP_META_QUERY = "open-pioneer-app";
|
|
887
911
|
var APP_META_RE = /[?&]open-pioneer-app(?:$|&)/;
|
|
@@ -897,7 +921,7 @@ var APP_I18N_LOCALE_RE = /[?&]locale=(?<locale>.*?)(?:$|&)/;
|
|
|
897
921
|
var PACKAGE_HOOKS_MODULE = "@@open-pioneer-react-hooks";
|
|
898
922
|
var SOURCE_FILE_RE = /^(.*?)(?:\?|$)/;
|
|
899
923
|
function parseVirtualModuleId(inputModuleId) {
|
|
900
|
-
const moduleId = (0,
|
|
924
|
+
const moduleId = (0, import_vite3.normalizePath)(inputModuleId);
|
|
901
925
|
if (!moduleId || moduleId.includes("\\0")) {
|
|
902
926
|
return void 0;
|
|
903
927
|
}
|
|
@@ -1002,22 +1026,7 @@ export {
|
|
|
1002
1026
|
}
|
|
1003
1027
|
|
|
1004
1028
|
// src/codegenPlugin.ts
|
|
1005
|
-
var
|
|
1006
|
-
|
|
1007
|
-
// src/codegen/generateReactHooks.ts
|
|
1008
|
-
function generateReactHooks(packageName, runtimeModuleId) {
|
|
1009
|
-
return `
|
|
1010
|
-
import { useServiceInternal, useServicesInternal, usePropertiesInternal, useIntlInternal } from ${JSON.stringify(
|
|
1011
|
-
runtimeModuleId
|
|
1012
|
-
)};
|
|
1013
|
-
|
|
1014
|
-
const PACKAGE_NAME = ${JSON.stringify(packageName)};
|
|
1015
|
-
export const useService = /*@__PURE__*/ useServiceInternal.bind(undefined, PACKAGE_NAME);
|
|
1016
|
-
export const useServices = /*@__PURE__*/ useServicesInternal.bind(undefined, PACKAGE_NAME);
|
|
1017
|
-
export const useProperties = /*@__PURE__*/ usePropertiesInternal.bind(undefined, PACKAGE_NAME);
|
|
1018
|
-
export const useIntl = /*@__PURE__*/ useIntlInternal.bind(undefined, PACKAGE_NAME);
|
|
1019
|
-
`.trim();
|
|
1020
|
-
}
|
|
1029
|
+
var import_promises4 = require("node:fs/promises");
|
|
1021
1030
|
|
|
1022
1031
|
// src/codegen/generateI18n.ts
|
|
1023
1032
|
var nodes2 = __toESM(require("@babel/types"));
|
|
@@ -1078,7 +1087,7 @@ async function generateI18nMessages(options) {
|
|
|
1078
1087
|
const { messages, overrides } = await loadI18n(filePath);
|
|
1079
1088
|
if (pkg.name === appName) {
|
|
1080
1089
|
packageOverrides = overrides;
|
|
1081
|
-
} else if (overrides
|
|
1090
|
+
} else if (overrides) {
|
|
1082
1091
|
throw new ReportableError(
|
|
1083
1092
|
`Unexpected 'overrides' block in '${filePath}'. Overrides are only supported in the app.`
|
|
1084
1093
|
);
|
|
@@ -1116,8 +1125,9 @@ async function generateI18nMessages(options) {
|
|
|
1116
1125
|
}
|
|
1117
1126
|
|
|
1118
1127
|
// src/codegenPlugin.ts
|
|
1119
|
-
var
|
|
1120
|
-
var
|
|
1128
|
+
var import_build_common3 = require("@open-pioneer/build-common");
|
|
1129
|
+
var isDebug3 = !!process.env.DEBUG;
|
|
1130
|
+
var debug4 = createDebugger("open-pioneer:codegen");
|
|
1121
1131
|
function codegenPlugin() {
|
|
1122
1132
|
const manualDeps = /* @__PURE__ */ new Map();
|
|
1123
1133
|
let config;
|
|
@@ -1137,7 +1147,7 @@ function codegenPlugin() {
|
|
|
1137
1147
|
}
|
|
1138
1148
|
return resolvedResult.id;
|
|
1139
1149
|
};
|
|
1140
|
-
reactIntegrationId = await resolve2(
|
|
1150
|
+
reactIntegrationId = await resolve2(import_build_common3.RuntimeSupport.REACT_INTEGRATION_MODULE_ID);
|
|
1141
1151
|
metadataId = await resolve2("@open-pioneer/runtime/metadata");
|
|
1142
1152
|
},
|
|
1143
1153
|
configResolved(resolvedConfig) {
|
|
@@ -1147,16 +1157,16 @@ function codegenPlugin() {
|
|
|
1147
1157
|
configureServer(server) {
|
|
1148
1158
|
devServer = server;
|
|
1149
1159
|
server.watcher.on("all", (_, path) => {
|
|
1150
|
-
const moduleIds = manualDeps.get((0,
|
|
1160
|
+
const moduleIds = manualDeps.get((0, import_vite4.normalizePath)(path));
|
|
1151
1161
|
if (!moduleIds) {
|
|
1152
1162
|
return;
|
|
1153
1163
|
}
|
|
1154
|
-
|
|
1164
|
+
isDebug3 && debug4(`File changed: ${path}`);
|
|
1155
1165
|
repository.onFileChanged(path);
|
|
1156
1166
|
for (const moduleId of moduleIds) {
|
|
1157
1167
|
const mod = server.moduleGraph.getModuleById(moduleId);
|
|
1158
1168
|
if (mod) {
|
|
1159
|
-
|
|
1169
|
+
isDebug3 && debug4(`Triggering hmr of ${moduleId}`);
|
|
1160
1170
|
server.reloadModule(mod).catch((err) => {
|
|
1161
1171
|
config.logger.error(`Failed to trigger hmr`, { error: err });
|
|
1162
1172
|
});
|
|
@@ -1180,19 +1190,29 @@ function codegenPlugin() {
|
|
|
1180
1190
|
);
|
|
1181
1191
|
}
|
|
1182
1192
|
const packageDir = (0, import_node_path3.dirname)(packageJsonPath);
|
|
1183
|
-
return (0,
|
|
1193
|
+
return (0, import_vite4.normalizePath)(packageDir);
|
|
1184
1194
|
};
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1195
|
+
let virtualModule;
|
|
1196
|
+
try {
|
|
1197
|
+
virtualModule = import_build_common3.RuntimeSupport.parseVirtualModule(moduleId);
|
|
1198
|
+
} catch (e) {
|
|
1199
|
+
this.error({
|
|
1200
|
+
id: moduleId,
|
|
1201
|
+
message: "Invalid virtual module id",
|
|
1202
|
+
cause: e
|
|
1189
1203
|
});
|
|
1190
1204
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1205
|
+
switch (virtualModule) {
|
|
1206
|
+
case "app":
|
|
1207
|
+
return serializeModuleId({
|
|
1208
|
+
type: "app-meta",
|
|
1209
|
+
packageDirectory: getPackageDirectory()
|
|
1210
|
+
});
|
|
1211
|
+
case "react-hooks":
|
|
1212
|
+
return serializeModuleId({
|
|
1213
|
+
type: "package-hooks",
|
|
1214
|
+
packageDirectory: getPackageDirectory()
|
|
1215
|
+
});
|
|
1196
1216
|
}
|
|
1197
1217
|
} catch (e) {
|
|
1198
1218
|
reportError(this, e);
|
|
@@ -1205,7 +1225,7 @@ function codegenPlugin() {
|
|
|
1205
1225
|
if (!mod) {
|
|
1206
1226
|
return void 0;
|
|
1207
1227
|
}
|
|
1208
|
-
|
|
1228
|
+
isDebug3 && debug4("Loading virtual module %O", mod);
|
|
1209
1229
|
const packageJsonPath = (_a = await this.resolve(mod.packageDirectory + "/package.json")) == null ? void 0 : _a.id;
|
|
1210
1230
|
if (!packageJsonPath) {
|
|
1211
1231
|
throw new ReportableError(
|
|
@@ -1219,8 +1239,11 @@ function codegenPlugin() {
|
|
|
1219
1239
|
throw new ReportableError(`Failed to resolve package.json in ${directory}`);
|
|
1220
1240
|
}
|
|
1221
1241
|
const packageName = await getPackageName(this, packageJsonPath2);
|
|
1222
|
-
const generatedSourceCode = generateReactHooks(
|
|
1223
|
-
|
|
1242
|
+
const generatedSourceCode = import_build_common3.RuntimeSupport.generateReactHooks(
|
|
1243
|
+
packageName,
|
|
1244
|
+
reactIntegrationId
|
|
1245
|
+
);
|
|
1246
|
+
isDebug3 && debug4("Generated hooks code: %O", generatedSourceCode);
|
|
1224
1247
|
return generatedSourceCode;
|
|
1225
1248
|
}
|
|
1226
1249
|
if (mod.type === "app-meta") {
|
|
@@ -1237,12 +1260,12 @@ function codegenPlugin() {
|
|
|
1237
1260
|
appName: appMetadata.name,
|
|
1238
1261
|
packages: appMetadata.packages
|
|
1239
1262
|
});
|
|
1240
|
-
|
|
1263
|
+
isDebug3 && debug4("Generated app metadata: %O", generatedSourceCode);
|
|
1241
1264
|
return generatedSourceCode;
|
|
1242
1265
|
}
|
|
1243
1266
|
case "app-css": {
|
|
1244
1267
|
const generatedSourceCode = generateCombinedCss(appMetadata.packages);
|
|
1245
|
-
|
|
1268
|
+
isDebug3 && debug4("Generated app css: %O", generatedSourceCode);
|
|
1246
1269
|
return generatedSourceCode;
|
|
1247
1270
|
}
|
|
1248
1271
|
case "app-i18n-index": {
|
|
@@ -1250,7 +1273,7 @@ function codegenPlugin() {
|
|
|
1250
1273
|
mod.packageDirectory,
|
|
1251
1274
|
appMetadata.locales
|
|
1252
1275
|
);
|
|
1253
|
-
|
|
1276
|
+
isDebug3 && debug4("Generated i18n lookup: %O", generatedSourceCode);
|
|
1254
1277
|
return generatedSourceCode;
|
|
1255
1278
|
}
|
|
1256
1279
|
case "app-i18n": {
|
|
@@ -1262,7 +1285,7 @@ function codegenPlugin() {
|
|
|
1262
1285
|
return repository.getI18nFile(context, path);
|
|
1263
1286
|
}
|
|
1264
1287
|
});
|
|
1265
|
-
|
|
1288
|
+
isDebug3 && debug4("Generated i18n messages: %O", generatedSourceCode);
|
|
1266
1289
|
return generatedSourceCode;
|
|
1267
1290
|
}
|
|
1268
1291
|
}
|
|
@@ -1278,7 +1301,7 @@ function buildMetadataContext(ctx, moduleId, devServer, manualDeps) {
|
|
|
1278
1301
|
resolve: ctx.resolve,
|
|
1279
1302
|
addWatchFile: (id) => {
|
|
1280
1303
|
if (devServer) {
|
|
1281
|
-
|
|
1304
|
+
isDebug3 && debug4(`Adding manual watch for ${id}`);
|
|
1282
1305
|
devServer.watcher.add(id);
|
|
1283
1306
|
addManualDep(manualDeps, id, moduleId);
|
|
1284
1307
|
}
|
|
@@ -1297,7 +1320,7 @@ function reportError(ctx, error) {
|
|
|
1297
1320
|
});
|
|
1298
1321
|
}
|
|
1299
1322
|
function addManualDep(manualDeps, file, moduleId) {
|
|
1300
|
-
const normalizedPath = (0,
|
|
1323
|
+
const normalizedPath = (0, import_vite4.normalizePath)(file);
|
|
1301
1324
|
let moduleIds = manualDeps.get(normalizedPath);
|
|
1302
1325
|
if (!moduleIds) {
|
|
1303
1326
|
moduleIds = /* @__PURE__ */ new Set();
|
|
@@ -1309,10 +1332,10 @@ function findPackageJson(startDir, rootDir) {
|
|
|
1309
1332
|
let dir = startDir;
|
|
1310
1333
|
while (dir) {
|
|
1311
1334
|
const candidate = (0, import_node_path3.join)(dir, "package.json");
|
|
1312
|
-
if ((0,
|
|
1335
|
+
if ((0, import_node_fs2.existsSync)(candidate)) {
|
|
1313
1336
|
return candidate;
|
|
1314
1337
|
}
|
|
1315
|
-
if ((0,
|
|
1338
|
+
if ((0, import_vite4.normalizePath)(dir) == (0, import_vite4.normalizePath)(rootDir)) {
|
|
1316
1339
|
return void 0;
|
|
1317
1340
|
}
|
|
1318
1341
|
const parent = (0, import_node_path3.dirname)(dir);
|
|
@@ -1323,7 +1346,7 @@ function findPackageJson(startDir, rootDir) {
|
|
|
1323
1346
|
async function getPackageName(ctx, packageJsonPath) {
|
|
1324
1347
|
let name;
|
|
1325
1348
|
try {
|
|
1326
|
-
const content = await (0,
|
|
1349
|
+
const content = await (0, import_promises4.readFile)(packageJsonPath, "utf-8");
|
|
1327
1350
|
name = JSON.parse(content).name;
|
|
1328
1351
|
} catch (e) {
|
|
1329
1352
|
throw new ReportableError(`Failed to read package.json file`, { cause: e });
|
|
@@ -1335,7 +1358,7 @@ async function getPackageName(ctx, packageJsonPath) {
|
|
|
1335
1358
|
}
|
|
1336
1359
|
|
|
1337
1360
|
// src/mpaPlugin.ts
|
|
1338
|
-
var
|
|
1361
|
+
var import_node_fs3 = require("node:fs");
|
|
1339
1362
|
var import_node_path4 = require("node:path");
|
|
1340
1363
|
var import_node_path5 = require("node:path");
|
|
1341
1364
|
var import_node_process = require("node:process");
|
|
@@ -1393,7 +1416,7 @@ function gatherEntryPoints(options) {
|
|
|
1393
1416
|
} else {
|
|
1394
1417
|
apps = Object.entries(options.apps).map(([name, appPath]) => {
|
|
1395
1418
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, appPath);
|
|
1396
|
-
if (!(0,
|
|
1419
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1397
1420
|
throw new Error(
|
|
1398
1421
|
`Failed to find app '${name}' at ${path}. Ensure that the path is spelled correctly.`
|
|
1399
1422
|
);
|
|
@@ -1403,7 +1426,7 @@ function gatherEntryPoints(options) {
|
|
|
1403
1426
|
}
|
|
1404
1427
|
const sites = options.sites.map((sitePath) => {
|
|
1405
1428
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, sitePath, "index.html");
|
|
1406
|
-
if (!(0,
|
|
1429
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1407
1430
|
throw new Error(
|
|
1408
1431
|
`Failed to find site at ${path}. Ensure that the site name in your vite configuration is spelled correctly.`
|
|
1409
1432
|
);
|
|
@@ -1415,7 +1438,7 @@ function gatherEntryPoints(options) {
|
|
|
1415
1438
|
});
|
|
1416
1439
|
if (options.rootSite) {
|
|
1417
1440
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, "index.html");
|
|
1418
|
-
if (!(0,
|
|
1441
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1419
1442
|
throw new Error(
|
|
1420
1443
|
`Failed to find root site at ${path}. Create the missing file or set 'rootSite' to false.`
|
|
1421
1444
|
);
|
|
@@ -1452,7 +1475,7 @@ var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
|
|
|
1452
1475
|
function findMatchingEntryPointFile(appName, prefix) {
|
|
1453
1476
|
for (const ext of EXTENSIONS) {
|
|
1454
1477
|
const candidate = prefix + ext;
|
|
1455
|
-
if ((0,
|
|
1478
|
+
if ((0, import_node_fs3.existsSync)(candidate)) {
|
|
1456
1479
|
return candidate;
|
|
1457
1480
|
}
|
|
1458
1481
|
}
|