@open-pioneer/vite-plugin-pioneer 0.7.0 → 0.8.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/CHANGELOG.md +15 -0
- package/dist/index.js +311 -287
- package/dist/index.js.map +4 -4
- package/package.json +7 -4
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,7 +1026,7 @@ export {
|
|
|
1002
1026
|
}
|
|
1003
1027
|
|
|
1004
1028
|
// src/codegenPlugin.ts
|
|
1005
|
-
var
|
|
1029
|
+
var import_promises4 = require("node:fs/promises");
|
|
1006
1030
|
|
|
1007
1031
|
// src/codegen/generateReactHooks.ts
|
|
1008
1032
|
function generateReactHooks(packageName, runtimeModuleId) {
|
|
@@ -1078,7 +1102,7 @@ async function generateI18nMessages(options) {
|
|
|
1078
1102
|
const { messages, overrides } = await loadI18n(filePath);
|
|
1079
1103
|
if (pkg.name === appName) {
|
|
1080
1104
|
packageOverrides = overrides;
|
|
1081
|
-
} else if (overrides
|
|
1105
|
+
} else if (overrides) {
|
|
1082
1106
|
throw new ReportableError(
|
|
1083
1107
|
`Unexpected 'overrides' block in '${filePath}'. Overrides are only supported in the app.`
|
|
1084
1108
|
);
|
|
@@ -1116,8 +1140,8 @@ async function generateI18nMessages(options) {
|
|
|
1116
1140
|
}
|
|
1117
1141
|
|
|
1118
1142
|
// src/codegenPlugin.ts
|
|
1119
|
-
var
|
|
1120
|
-
var
|
|
1143
|
+
var isDebug3 = !!process.env.DEBUG;
|
|
1144
|
+
var debug4 = createDebugger("open-pioneer:codegen");
|
|
1121
1145
|
function codegenPlugin() {
|
|
1122
1146
|
const manualDeps = /* @__PURE__ */ new Map();
|
|
1123
1147
|
let config;
|
|
@@ -1147,16 +1171,16 @@ function codegenPlugin() {
|
|
|
1147
1171
|
configureServer(server) {
|
|
1148
1172
|
devServer = server;
|
|
1149
1173
|
server.watcher.on("all", (_, path) => {
|
|
1150
|
-
const moduleIds = manualDeps.get((0,
|
|
1174
|
+
const moduleIds = manualDeps.get((0, import_vite4.normalizePath)(path));
|
|
1151
1175
|
if (!moduleIds) {
|
|
1152
1176
|
return;
|
|
1153
1177
|
}
|
|
1154
|
-
|
|
1178
|
+
isDebug3 && debug4(`File changed: ${path}`);
|
|
1155
1179
|
repository.onFileChanged(path);
|
|
1156
1180
|
for (const moduleId of moduleIds) {
|
|
1157
1181
|
const mod = server.moduleGraph.getModuleById(moduleId);
|
|
1158
1182
|
if (mod) {
|
|
1159
|
-
|
|
1183
|
+
isDebug3 && debug4(`Triggering hmr of ${moduleId}`);
|
|
1160
1184
|
server.reloadModule(mod).catch((err) => {
|
|
1161
1185
|
config.logger.error(`Failed to trigger hmr`, { error: err });
|
|
1162
1186
|
});
|
|
@@ -1180,7 +1204,7 @@ function codegenPlugin() {
|
|
|
1180
1204
|
);
|
|
1181
1205
|
}
|
|
1182
1206
|
const packageDir = (0, import_node_path3.dirname)(packageJsonPath);
|
|
1183
|
-
return (0,
|
|
1207
|
+
return (0, import_vite4.normalizePath)(packageDir);
|
|
1184
1208
|
};
|
|
1185
1209
|
if (moduleId === "open-pioneer:app") {
|
|
1186
1210
|
return serializeModuleId({
|
|
@@ -1205,7 +1229,7 @@ function codegenPlugin() {
|
|
|
1205
1229
|
if (!mod) {
|
|
1206
1230
|
return void 0;
|
|
1207
1231
|
}
|
|
1208
|
-
|
|
1232
|
+
isDebug3 && debug4("Loading virtual module %O", mod);
|
|
1209
1233
|
const packageJsonPath = (_a = await this.resolve(mod.packageDirectory + "/package.json")) == null ? void 0 : _a.id;
|
|
1210
1234
|
if (!packageJsonPath) {
|
|
1211
1235
|
throw new ReportableError(
|
|
@@ -1220,7 +1244,7 @@ function codegenPlugin() {
|
|
|
1220
1244
|
}
|
|
1221
1245
|
const packageName = await getPackageName(this, packageJsonPath2);
|
|
1222
1246
|
const generatedSourceCode = generateReactHooks(packageName, reactIntegrationId);
|
|
1223
|
-
|
|
1247
|
+
isDebug3 && debug4("Generated hooks code: %O", generatedSourceCode);
|
|
1224
1248
|
return generatedSourceCode;
|
|
1225
1249
|
}
|
|
1226
1250
|
if (mod.type === "app-meta") {
|
|
@@ -1237,12 +1261,12 @@ function codegenPlugin() {
|
|
|
1237
1261
|
appName: appMetadata.name,
|
|
1238
1262
|
packages: appMetadata.packages
|
|
1239
1263
|
});
|
|
1240
|
-
|
|
1264
|
+
isDebug3 && debug4("Generated app metadata: %O", generatedSourceCode);
|
|
1241
1265
|
return generatedSourceCode;
|
|
1242
1266
|
}
|
|
1243
1267
|
case "app-css": {
|
|
1244
1268
|
const generatedSourceCode = generateCombinedCss(appMetadata.packages);
|
|
1245
|
-
|
|
1269
|
+
isDebug3 && debug4("Generated app css: %O", generatedSourceCode);
|
|
1246
1270
|
return generatedSourceCode;
|
|
1247
1271
|
}
|
|
1248
1272
|
case "app-i18n-index": {
|
|
@@ -1250,7 +1274,7 @@ function codegenPlugin() {
|
|
|
1250
1274
|
mod.packageDirectory,
|
|
1251
1275
|
appMetadata.locales
|
|
1252
1276
|
);
|
|
1253
|
-
|
|
1277
|
+
isDebug3 && debug4("Generated i18n lookup: %O", generatedSourceCode);
|
|
1254
1278
|
return generatedSourceCode;
|
|
1255
1279
|
}
|
|
1256
1280
|
case "app-i18n": {
|
|
@@ -1262,7 +1286,7 @@ function codegenPlugin() {
|
|
|
1262
1286
|
return repository.getI18nFile(context, path);
|
|
1263
1287
|
}
|
|
1264
1288
|
});
|
|
1265
|
-
|
|
1289
|
+
isDebug3 && debug4("Generated i18n messages: %O", generatedSourceCode);
|
|
1266
1290
|
return generatedSourceCode;
|
|
1267
1291
|
}
|
|
1268
1292
|
}
|
|
@@ -1278,7 +1302,7 @@ function buildMetadataContext(ctx, moduleId, devServer, manualDeps) {
|
|
|
1278
1302
|
resolve: ctx.resolve,
|
|
1279
1303
|
addWatchFile: (id) => {
|
|
1280
1304
|
if (devServer) {
|
|
1281
|
-
|
|
1305
|
+
isDebug3 && debug4(`Adding manual watch for ${id}`);
|
|
1282
1306
|
devServer.watcher.add(id);
|
|
1283
1307
|
addManualDep(manualDeps, id, moduleId);
|
|
1284
1308
|
}
|
|
@@ -1297,7 +1321,7 @@ function reportError(ctx, error) {
|
|
|
1297
1321
|
});
|
|
1298
1322
|
}
|
|
1299
1323
|
function addManualDep(manualDeps, file, moduleId) {
|
|
1300
|
-
const normalizedPath = (0,
|
|
1324
|
+
const normalizedPath = (0, import_vite4.normalizePath)(file);
|
|
1301
1325
|
let moduleIds = manualDeps.get(normalizedPath);
|
|
1302
1326
|
if (!moduleIds) {
|
|
1303
1327
|
moduleIds = /* @__PURE__ */ new Set();
|
|
@@ -1309,10 +1333,10 @@ function findPackageJson(startDir, rootDir) {
|
|
|
1309
1333
|
let dir = startDir;
|
|
1310
1334
|
while (dir) {
|
|
1311
1335
|
const candidate = (0, import_node_path3.join)(dir, "package.json");
|
|
1312
|
-
if ((0,
|
|
1336
|
+
if ((0, import_node_fs2.existsSync)(candidate)) {
|
|
1313
1337
|
return candidate;
|
|
1314
1338
|
}
|
|
1315
|
-
if ((0,
|
|
1339
|
+
if ((0, import_vite4.normalizePath)(dir) == (0, import_vite4.normalizePath)(rootDir)) {
|
|
1316
1340
|
return void 0;
|
|
1317
1341
|
}
|
|
1318
1342
|
const parent = (0, import_node_path3.dirname)(dir);
|
|
@@ -1323,7 +1347,7 @@ function findPackageJson(startDir, rootDir) {
|
|
|
1323
1347
|
async function getPackageName(ctx, packageJsonPath) {
|
|
1324
1348
|
let name;
|
|
1325
1349
|
try {
|
|
1326
|
-
const content = await (0,
|
|
1350
|
+
const content = await (0, import_promises4.readFile)(packageJsonPath, "utf-8");
|
|
1327
1351
|
name = JSON.parse(content).name;
|
|
1328
1352
|
} catch (e) {
|
|
1329
1353
|
throw new ReportableError(`Failed to read package.json file`, { cause: e });
|
|
@@ -1335,7 +1359,7 @@ async function getPackageName(ctx, packageJsonPath) {
|
|
|
1335
1359
|
}
|
|
1336
1360
|
|
|
1337
1361
|
// src/mpaPlugin.ts
|
|
1338
|
-
var
|
|
1362
|
+
var import_node_fs3 = require("node:fs");
|
|
1339
1363
|
var import_node_path4 = require("node:path");
|
|
1340
1364
|
var import_node_path5 = require("node:path");
|
|
1341
1365
|
var import_node_process = require("node:process");
|
|
@@ -1393,7 +1417,7 @@ function gatherEntryPoints(options) {
|
|
|
1393
1417
|
} else {
|
|
1394
1418
|
apps = Object.entries(options.apps).map(([name, appPath]) => {
|
|
1395
1419
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, appPath);
|
|
1396
|
-
if (!(0,
|
|
1420
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1397
1421
|
throw new Error(
|
|
1398
1422
|
`Failed to find app '${name}' at ${path}. Ensure that the path is spelled correctly.`
|
|
1399
1423
|
);
|
|
@@ -1403,7 +1427,7 @@ function gatherEntryPoints(options) {
|
|
|
1403
1427
|
}
|
|
1404
1428
|
const sites = options.sites.map((sitePath) => {
|
|
1405
1429
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, sitePath, "index.html");
|
|
1406
|
-
if (!(0,
|
|
1430
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1407
1431
|
throw new Error(
|
|
1408
1432
|
`Failed to find site at ${path}. Ensure that the site name in your vite configuration is spelled correctly.`
|
|
1409
1433
|
);
|
|
@@ -1415,7 +1439,7 @@ function gatherEntryPoints(options) {
|
|
|
1415
1439
|
});
|
|
1416
1440
|
if (options.rootSite) {
|
|
1417
1441
|
const path = (0, import_node_path4.resolve)(options.sourceRoot, "index.html");
|
|
1418
|
-
if (!(0,
|
|
1442
|
+
if (!(0, import_node_fs3.existsSync)(path)) {
|
|
1419
1443
|
throw new Error(
|
|
1420
1444
|
`Failed to find root site at ${path}. Create the missing file or set 'rootSite' to false.`
|
|
1421
1445
|
);
|
|
@@ -1452,7 +1476,7 @@ var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
|
|
|
1452
1476
|
function findMatchingEntryPointFile(appName, prefix) {
|
|
1453
1477
|
for (const ext of EXTENSIONS) {
|
|
1454
1478
|
const candidate = prefix + ext;
|
|
1455
|
-
if ((0,
|
|
1479
|
+
if ((0, import_node_fs3.existsSync)(candidate)) {
|
|
1456
1480
|
return candidate;
|
|
1457
1481
|
}
|
|
1458
1482
|
}
|