revojs 0.2.31 → 0.2.33
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/module/index.d.ts +9 -1
- package/dist/module/index.js +49 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/module/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type InferVariables<T extends Record<string, Variable>> = {
|
|
|
27
27
|
export type UnionToIntersection<TUnion> = (TUnion extends unknown ? (arg: TUnion) => void : never) extends (arg: infer TIntersection) => void ? TIntersection : never;
|
|
28
28
|
export type InferModuleConfig<TModule> = TModule extends Module<infer TName extends string, infer TConfig, infer TDependencies extends ReadonlyArray<Module>> ? Record<TName, TConfig> & InferModuleConfigs<TDependencies> : never;
|
|
29
29
|
export type InferModuleConfigs<TModules extends ReadonlyArray<Module>> = Partial<UnionToIntersection<InferModuleConfig<TModules[number]>>>;
|
|
30
|
-
export type ModuleInput<TModules extends ReadonlyArray<Module>> = Mergeable<Config> & InferModuleConfigs<TModules
|
|
30
|
+
export type ModuleInput<TModules extends ReadonlyArray<Module>> = Mergeable<Config> & Mergeable<InferModuleConfigs<TModules>> & {
|
|
31
31
|
modules?: TModules;
|
|
32
32
|
};
|
|
33
33
|
export type ModuleSetupResult<TName extends string, TConfig, TDependencies extends ReadonlyArray<Module> = []> = void | (Mergeable<Config> & Mergeable<Record<TName, TConfig>> & Mergeable<InferModuleConfigs<TDependencies>>);
|
|
@@ -73,6 +73,13 @@ export interface EnumVariable {
|
|
|
73
73
|
default?: string;
|
|
74
74
|
optional?: boolean;
|
|
75
75
|
}
|
|
76
|
+
export interface PackageManifest {
|
|
77
|
+
name?: string;
|
|
78
|
+
dependencies?: Record<string, string>;
|
|
79
|
+
devDependencies?: Record<string, string>;
|
|
80
|
+
peerDependencies?: Record<string, string>;
|
|
81
|
+
optionalDependencies?: Record<string, string>;
|
|
82
|
+
}
|
|
76
83
|
export interface Config {
|
|
77
84
|
copy: Array<string>;
|
|
78
85
|
modules: Array<Module>;
|
|
@@ -103,6 +110,7 @@ export declare function posixPath(path: string): string;
|
|
|
103
110
|
export declare function resolvePattern(pattern: string, cwd?: string): string[];
|
|
104
111
|
export declare function resolvePaths(patterns: string | ArrayLike<string>, cwd?: string): string[];
|
|
105
112
|
export declare function matchesConsumer(path: string, consumer: Consumer): boolean;
|
|
113
|
+
export declare function resolveFrameworkPackages(root: string): string[];
|
|
106
114
|
export declare function resolveSource(source: Source): Map<string, Map<string, string>>;
|
|
107
115
|
export declare function useModule(source: string | URL): {
|
|
108
116
|
fromModule: (...paths: Array<string>) => string;
|
package/dist/module/index.js
CHANGED
|
@@ -58,6 +58,42 @@ function matchesConsumer(path, consumer) {
|
|
|
58
58
|
const marker = /\.(client|server)\.[^./]+$/.exec(path)?.[1];
|
|
59
59
|
return marker === void 0 || marker === consumer;
|
|
60
60
|
}
|
|
61
|
+
function resolveFrameworkPackages(root) {
|
|
62
|
+
const packages = /* @__PURE__ */ new Set();
|
|
63
|
+
const checked = /* @__PURE__ */ new Set();
|
|
64
|
+
const manifests = [resolve(root, "package.json")];
|
|
65
|
+
for (const [index, path] of manifests.entries()) {
|
|
66
|
+
let manifest;
|
|
67
|
+
try {
|
|
68
|
+
manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
69
|
+
} catch {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const groups = [
|
|
73
|
+
manifest.dependencies,
|
|
74
|
+
manifest.peerDependencies,
|
|
75
|
+
manifest.optionalDependencies
|
|
76
|
+
];
|
|
77
|
+
if (index === 0) groups.push(manifest.devDependencies);
|
|
78
|
+
for (const dependencies of groups) for (const name in dependencies) {
|
|
79
|
+
if (checked.has(name)) continue;
|
|
80
|
+
checked.add(name);
|
|
81
|
+
let dependencyPath;
|
|
82
|
+
try {
|
|
83
|
+
dependencyPath = findPackageJSON(name, pathToFileURL(path).href);
|
|
84
|
+
} catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (dependencyPath === void 0) continue;
|
|
88
|
+
const dependency = JSON.parse(readFileSync(dependencyPath, "utf8"));
|
|
89
|
+
if (name === package_default.name || dependency.dependencies?.[package_default.name] !== void 0 || dependency.peerDependencies?.[package_default.name] !== void 0) {
|
|
90
|
+
packages.add(name);
|
|
91
|
+
manifests.push(dependencyPath);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...packages];
|
|
96
|
+
}
|
|
61
97
|
function resolveSource(source) {
|
|
62
98
|
const scopes = /* @__PURE__ */ new Map();
|
|
63
99
|
for (const directory of source.from) {
|
|
@@ -303,11 +339,13 @@ async function module(inputConfig) {
|
|
|
303
339
|
}
|
|
304
340
|
async function revojs(inputConfig) {
|
|
305
341
|
const config = await createConfig(inputConfig);
|
|
342
|
+
const frameworkPackages = resolveFrameworkPackages(".");
|
|
306
343
|
return [await core(config), {
|
|
307
344
|
name: package_default.name,
|
|
308
345
|
config() {
|
|
309
346
|
return mergeObjects({
|
|
310
347
|
appType: config.modules.length === 0 ? "spa" : "custom",
|
|
348
|
+
resolve: { dedupe: frameworkPackages },
|
|
311
349
|
builder: {
|
|
312
350
|
sharedConfigBuild: true,
|
|
313
351
|
async buildApp(builder) {
|
|
@@ -317,6 +355,16 @@ async function revojs(inputConfig) {
|
|
|
317
355
|
}
|
|
318
356
|
}, config.vite);
|
|
319
357
|
},
|
|
358
|
+
configEnvironment(name, options) {
|
|
359
|
+
if ((options.consumer ?? (name === "client" ? "client" : "server")) === "server") return {
|
|
360
|
+
resolve: { noExternal: frameworkPackages },
|
|
361
|
+
optimizeDeps: { exclude: frameworkPackages }
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
transform(_code, id) {
|
|
365
|
+
const path = id.split("?", 1)[0];
|
|
366
|
+
if (this.environment.config.consumer === "client" && !path.includes("/node_modules/") && !matchesConsumer(path, "client")) throw new Error(`Server-only module "${path}" must not be imported by client code.`);
|
|
367
|
+
},
|
|
320
368
|
configResolved(viteConfig) {
|
|
321
369
|
addVirtual(config, "assets", () => {
|
|
322
370
|
const assets = new Array();
|
|
@@ -342,4 +390,4 @@ async function revojs(inputConfig) {
|
|
|
342
390
|
}
|
|
343
391
|
var PACKAGE_CACHE = /* @__PURE__ */ new Map();
|
|
344
392
|
//#endregion
|
|
345
|
-
export { addTemplate, addTypes, addVirtual, core, createConfig, defineCommand, defineModule, matchesConsumer, module, posixPath, resolvePaths, resolvePattern, resolveSource, revojs, useModule };
|
|
393
|
+
export { addTemplate, addTypes, addVirtual, core, createConfig, defineCommand, defineModule, matchesConsumer, module, posixPath, resolveFrameworkPackages, resolvePaths, resolvePattern, resolveSource, revojs, useModule };
|
package/dist/package.js
CHANGED