@openzeppelin/adapters-vite 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +226 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +191 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +89 -0
- package/src/__tests__/config.test.ts +180 -0
- package/src/config.ts +128 -0
- package/src/index.ts +21 -0
- package/src/registry.ts +108 -0
- package/src/resolver.ts +111 -0
- package/src/types.ts +46 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_fs = require("node:fs");
|
|
29
|
+
node_fs = __toESM(node_fs);
|
|
30
|
+
let node_module = require("node:module");
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path);
|
|
33
|
+
|
|
34
|
+
//#region src/registry.ts
|
|
35
|
+
const ADAPTER_REGISTRY = {
|
|
36
|
+
evm: {
|
|
37
|
+
packageName: "@openzeppelin/adapter-evm",
|
|
38
|
+
extraOptimizeDepsExclude: ["@openzeppelin/adapter-evm-core"],
|
|
39
|
+
async loadConfig() {
|
|
40
|
+
const { getEvmViteConfig } = await import("@openzeppelin/adapter-evm/vite-config");
|
|
41
|
+
return getEvmViteConfig();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
midnight: {
|
|
45
|
+
packageName: "@openzeppelin/adapter-midnight",
|
|
46
|
+
async loadConfig(options) {
|
|
47
|
+
const midnightPlugins = options.pluginFactories?.midnight;
|
|
48
|
+
if (!midnightPlugins) throw new Error("Midnight adapter Vite configuration requires `pluginFactories.midnight` with `wasm` and `topLevelAwait`.");
|
|
49
|
+
const { getMidnightViteConfig } = await import("@openzeppelin/adapter-midnight/vite-config");
|
|
50
|
+
return getMidnightViteConfig(midnightPlugins);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
polkadot: {
|
|
54
|
+
packageName: "@openzeppelin/adapter-polkadot",
|
|
55
|
+
async loadConfig() {
|
|
56
|
+
const { getPolkadotViteConfig } = await import("@openzeppelin/adapter-polkadot/vite-config");
|
|
57
|
+
return getPolkadotViteConfig();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
solana: {
|
|
61
|
+
packageName: "@openzeppelin/adapter-solana",
|
|
62
|
+
async loadConfig() {
|
|
63
|
+
const { getSolanaViteConfig } = await import("@openzeppelin/adapter-solana/vite-config");
|
|
64
|
+
return getSolanaViteConfig();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
stellar: {
|
|
68
|
+
packageName: "@openzeppelin/adapter-stellar",
|
|
69
|
+
async loadConfig() {
|
|
70
|
+
const { getStellarViteConfig } = await import("@openzeppelin/adapter-stellar/vite-config");
|
|
71
|
+
return getStellarViteConfig();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function normalizeEcosystems(ecosystems) {
|
|
76
|
+
return [...new Set(ecosystems)];
|
|
77
|
+
}
|
|
78
|
+
function getAdapterRegistryEntry(ecosystem) {
|
|
79
|
+
return ADAPTER_REGISTRY[ecosystem];
|
|
80
|
+
}
|
|
81
|
+
function getOpenZeppelinAdapterPackageNames(ecosystems) {
|
|
82
|
+
return normalizeEcosystems(ecosystems).map((ecosystem) => ADAPTER_REGISTRY[ecosystem].packageName);
|
|
83
|
+
}
|
|
84
|
+
function getOpenZeppelinAdapterImportSpecifier(packageName, exportPath) {
|
|
85
|
+
if (exportPath === ".") return packageName;
|
|
86
|
+
return `${packageName}/${exportPath.slice(2)}`;
|
|
87
|
+
}
|
|
88
|
+
function getOpenZeppelinAdapterImportSpecifiers(ecosystems, exportPaths) {
|
|
89
|
+
const specifiers = /* @__PURE__ */ new Set();
|
|
90
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(ecosystems)) for (const exportPath of exportPaths) specifiers.add(getOpenZeppelinAdapterImportSpecifier(packageName, exportPath));
|
|
91
|
+
return [...specifiers];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/config.ts
|
|
96
|
+
function appendPlugins(target, plugins) {
|
|
97
|
+
if (!plugins) return;
|
|
98
|
+
target.push(...Array.isArray(plugins) ? plugins : [plugins]);
|
|
99
|
+
}
|
|
100
|
+
function appendStringValues(target, value) {
|
|
101
|
+
if (!value) return;
|
|
102
|
+
const values = Array.isArray(value) ? value : [value];
|
|
103
|
+
for (const entry of values) if (entry) target.add(entry);
|
|
104
|
+
}
|
|
105
|
+
function appendNoExternalValues(target, seenStrings, value) {
|
|
106
|
+
if (!value) return false;
|
|
107
|
+
if (value === true) return true;
|
|
108
|
+
const values = Array.isArray(value) ? value : [value];
|
|
109
|
+
for (const entry of values) {
|
|
110
|
+
if (typeof entry === "string") {
|
|
111
|
+
if (!seenStrings.has(entry)) {
|
|
112
|
+
seenStrings.add(entry);
|
|
113
|
+
target.push(entry);
|
|
114
|
+
}
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (entry instanceof RegExp) target.push(entry);
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
async function loadOpenZeppelinAdapterViteConfig(options) {
|
|
122
|
+
const ecosystems = normalizeEcosystems(options.ecosystems);
|
|
123
|
+
const plugins = [];
|
|
124
|
+
const dedupe = /* @__PURE__ */ new Set();
|
|
125
|
+
const optimizeDepsInclude = /* @__PURE__ */ new Set();
|
|
126
|
+
const optimizeDepsExclude = /* @__PURE__ */ new Set();
|
|
127
|
+
const ssrNoExternal = [];
|
|
128
|
+
const seenSsrNoExternalStrings = /* @__PURE__ */ new Set();
|
|
129
|
+
let ssrNoExternalAll = false;
|
|
130
|
+
const packageNames = getOpenZeppelinAdapterPackageNames(ecosystems);
|
|
131
|
+
for (const packageName of packageNames) {
|
|
132
|
+
optimizeDepsExclude.add(packageName);
|
|
133
|
+
ssrNoExternalAll = appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, packageName) || ssrNoExternalAll;
|
|
134
|
+
}
|
|
135
|
+
for (const ecosystem of ecosystems) {
|
|
136
|
+
const entry = getAdapterRegistryEntry(ecosystem);
|
|
137
|
+
let fragment;
|
|
138
|
+
try {
|
|
139
|
+
fragment = await entry.loadConfig(options);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new Error(`Failed to load ${entry.packageName} Vite configuration. Original error: ${error instanceof Error ? error.message : String(error)}`);
|
|
142
|
+
}
|
|
143
|
+
appendPlugins(plugins, fragment.plugins);
|
|
144
|
+
appendStringValues(dedupe, fragment.resolve?.dedupe);
|
|
145
|
+
appendStringValues(optimizeDepsInclude, fragment.optimizeDeps?.include);
|
|
146
|
+
appendStringValues(optimizeDepsExclude, fragment.optimizeDeps?.exclude);
|
|
147
|
+
appendStringValues(optimizeDepsExclude, entry.extraOptimizeDepsExclude);
|
|
148
|
+
ssrNoExternalAll = appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, fragment.ssr?.noExternal) || ssrNoExternalAll;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
plugins,
|
|
152
|
+
resolve: { dedupe: [...dedupe] },
|
|
153
|
+
optimizeDeps: {
|
|
154
|
+
include: [...optimizeDepsInclude],
|
|
155
|
+
exclude: [...optimizeDepsExclude]
|
|
156
|
+
},
|
|
157
|
+
ssr: { noExternal: ssrNoExternalAll ? true : ssrNoExternal },
|
|
158
|
+
packageNames
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/resolver.ts
|
|
164
|
+
function readPackageJson(packageDirectory) {
|
|
165
|
+
return JSON.parse(node_fs.default.readFileSync(node_path.default.join(packageDirectory, "package.json"), "utf8"));
|
|
166
|
+
}
|
|
167
|
+
function getImportTarget(entry) {
|
|
168
|
+
if (!entry) return null;
|
|
169
|
+
if (typeof entry === "string") return entry;
|
|
170
|
+
if (typeof entry.import === "string") return entry.import;
|
|
171
|
+
if (entry.import && typeof entry.import === "object" && typeof entry.import.default === "string") return entry.import.default;
|
|
172
|
+
if (typeof entry.default === "string") return entry.default;
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
function resolveInstalledPackageDirectory(packageName, importMetaUrl) {
|
|
176
|
+
const installedEntryPath = (0, node_module.createRequire)(importMetaUrl).resolve(packageName);
|
|
177
|
+
return node_path.default.resolve(node_path.default.dirname(installedEntryPath), "..");
|
|
178
|
+
}
|
|
179
|
+
function resolveInstalledExportEntry(packageName, packageDirectory, exportPath) {
|
|
180
|
+
const target = getImportTarget(readPackageJson(packageDirectory).exports?.[exportPath]);
|
|
181
|
+
if (!target) throw new Error(`Missing export "${exportPath}" in ${packageName}/package.json (required "import" condition)`);
|
|
182
|
+
return node_path.default.resolve(packageDirectory, target);
|
|
183
|
+
}
|
|
184
|
+
function resolveInstalledOpenZeppelinAdapterEntries(options) {
|
|
185
|
+
const exportPaths = options.exportPaths ?? [
|
|
186
|
+
".",
|
|
187
|
+
"./metadata",
|
|
188
|
+
"./networks"
|
|
189
|
+
];
|
|
190
|
+
const entries = {};
|
|
191
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(options.ecosystems)) {
|
|
192
|
+
const packageDirectory = resolveInstalledPackageDirectory(packageName, options.importMetaUrl);
|
|
193
|
+
for (const exportPath of exportPaths) entries[getOpenZeppelinAdapterImportSpecifier(packageName, exportPath)] = resolveInstalledExportEntry(packageName, packageDirectory, exportPath);
|
|
194
|
+
}
|
|
195
|
+
return entries;
|
|
196
|
+
}
|
|
197
|
+
function createOpenZeppelinAdapterResolverPlugin(options) {
|
|
198
|
+
const entries = resolveInstalledOpenZeppelinAdapterEntries(options);
|
|
199
|
+
return {
|
|
200
|
+
name: "openzeppelin-adapter-package-resolver",
|
|
201
|
+
enforce: "pre",
|
|
202
|
+
resolveId(id) {
|
|
203
|
+
return entries[id] ?? null;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/types.ts
|
|
210
|
+
const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = [
|
|
211
|
+
"evm",
|
|
212
|
+
"midnight",
|
|
213
|
+
"polkadot",
|
|
214
|
+
"solana",
|
|
215
|
+
"stellar"
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
exports.SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS;
|
|
220
|
+
exports.createOpenZeppelinAdapterResolverPlugin = createOpenZeppelinAdapterResolverPlugin;
|
|
221
|
+
exports.getOpenZeppelinAdapterImportSpecifier = getOpenZeppelinAdapterImportSpecifier;
|
|
222
|
+
exports.getOpenZeppelinAdapterImportSpecifiers = getOpenZeppelinAdapterImportSpecifiers;
|
|
223
|
+
exports.getOpenZeppelinAdapterPackageNames = getOpenZeppelinAdapterPackageNames;
|
|
224
|
+
exports.loadOpenZeppelinAdapterViteConfig = loadOpenZeppelinAdapterViteConfig;
|
|
225
|
+
exports.resolveInstalledOpenZeppelinAdapterEntries = resolveInstalledOpenZeppelinAdapterEntries;
|
|
226
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fs","path"],"sources":["../src/registry.ts","../src/config.ts","../src/resolver.ts","../src/types.ts"],"sourcesContent":["import type { UserConfig } from 'vite';\n\nimport type {\n AdapterViteConfigFragment,\n LoadOpenZeppelinAdapterViteConfigOptions,\n OpenZeppelinAdapterEcosystem,\n OpenZeppelinAdapterExportPath,\n} from './types';\n\ninterface AdapterRegistryEntry {\n packageName: string;\n extraOptimizeDepsExclude?: string[];\n loadConfig: (\n options: LoadOpenZeppelinAdapterViteConfigOptions\n ) => Promise<AdapterViteConfigFragment>;\n}\n\nconst ADAPTER_REGISTRY: Record<OpenZeppelinAdapterEcosystem, AdapterRegistryEntry> = {\n evm: {\n packageName: '@openzeppelin/adapter-evm',\n extraOptimizeDepsExclude: ['@openzeppelin/adapter-evm-core'],\n async loadConfig() {\n const { getEvmViteConfig } = await import('@openzeppelin/adapter-evm/vite-config');\n return getEvmViteConfig() as Partial<UserConfig>;\n },\n },\n midnight: {\n packageName: '@openzeppelin/adapter-midnight',\n async loadConfig(options) {\n const midnightPlugins = options.pluginFactories?.midnight;\n if (!midnightPlugins) {\n throw new Error(\n 'Midnight adapter Vite configuration requires `pluginFactories.midnight` with `wasm` and `topLevelAwait`.'\n );\n }\n\n const { getMidnightViteConfig } = await import('@openzeppelin/adapter-midnight/vite-config');\n return getMidnightViteConfig(midnightPlugins) as Partial<UserConfig>;\n },\n },\n polkadot: {\n packageName: '@openzeppelin/adapter-polkadot',\n async loadConfig() {\n const { getPolkadotViteConfig } = await import('@openzeppelin/adapter-polkadot/vite-config');\n return getPolkadotViteConfig() as Partial<UserConfig>;\n },\n },\n solana: {\n packageName: '@openzeppelin/adapter-solana',\n async loadConfig() {\n const { getSolanaViteConfig } = await import('@openzeppelin/adapter-solana/vite-config');\n return getSolanaViteConfig() as Partial<UserConfig>;\n },\n },\n stellar: {\n packageName: '@openzeppelin/adapter-stellar',\n async loadConfig() {\n const { getStellarViteConfig } = await import('@openzeppelin/adapter-stellar/vite-config');\n return getStellarViteConfig() as Partial<UserConfig>;\n },\n },\n};\n\nexport function normalizeEcosystems(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[]\n): OpenZeppelinAdapterEcosystem[] {\n return [...new Set(ecosystems)];\n}\n\nexport function getAdapterRegistryEntry(\n ecosystem: OpenZeppelinAdapterEcosystem\n): AdapterRegistryEntry {\n return ADAPTER_REGISTRY[ecosystem];\n}\n\nexport function getOpenZeppelinAdapterPackageNames(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[]\n): string[] {\n return normalizeEcosystems(ecosystems).map(\n (ecosystem) => ADAPTER_REGISTRY[ecosystem].packageName\n );\n}\n\nexport function getOpenZeppelinAdapterImportSpecifier(\n packageName: string,\n exportPath: OpenZeppelinAdapterExportPath\n): string {\n if (exportPath === '.') {\n return packageName;\n }\n\n return `${packageName}/${exportPath.slice(2)}`;\n}\n\nexport function getOpenZeppelinAdapterImportSpecifiers(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[],\n exportPaths: readonly OpenZeppelinAdapterExportPath[]\n): string[] {\n const specifiers = new Set<string>();\n\n for (const packageName of getOpenZeppelinAdapterPackageNames(ecosystems)) {\n for (const exportPath of exportPaths) {\n specifiers.add(getOpenZeppelinAdapterImportSpecifier(packageName, exportPath));\n }\n }\n\n return [...specifiers];\n}\n","import type { PluginOption, UserConfig } from 'vite';\n\nimport {\n getAdapterRegistryEntry,\n getOpenZeppelinAdapterPackageNames,\n normalizeEcosystems,\n} from './registry';\nimport type {\n AdapterViteConfigFragment,\n LoadOpenZeppelinAdapterViteConfigOptions,\n OpenZeppelinAdapterViteConfig,\n} from './types';\n\ntype SsrNoExternalValue = NonNullable<NonNullable<UserConfig['ssr']>['noExternal']>;\n\nfunction appendPlugins(target: PluginOption[], plugins: AdapterViteConfigFragment['plugins']) {\n if (!plugins) {\n return;\n }\n\n target.push(...(Array.isArray(plugins) ? plugins : [plugins]));\n}\n\nfunction appendStringValues(target: Set<string>, value: string | string[] | undefined) {\n if (!value) {\n return;\n }\n\n const values = Array.isArray(value) ? value : [value];\n\n for (const entry of values) {\n if (entry) {\n target.add(entry);\n }\n }\n}\n\nfunction appendNoExternalValues(\n target: Array<string | RegExp>,\n seenStrings: Set<string>,\n value: SsrNoExternalValue | undefined\n): boolean {\n if (!value) {\n return false;\n }\n\n if (value === true) {\n return true;\n }\n\n const values = Array.isArray(value) ? value : [value];\n\n for (const entry of values) {\n if (typeof entry === 'string') {\n if (!seenStrings.has(entry)) {\n seenStrings.add(entry);\n target.push(entry);\n }\n continue;\n }\n\n if (entry instanceof RegExp) {\n target.push(entry);\n }\n }\n\n return false;\n}\n\nexport async function loadOpenZeppelinAdapterViteConfig(\n options: LoadOpenZeppelinAdapterViteConfigOptions\n): Promise<OpenZeppelinAdapterViteConfig> {\n const ecosystems = normalizeEcosystems(options.ecosystems);\n const plugins: PluginOption[] = [];\n const dedupe = new Set<string>();\n const optimizeDepsInclude = new Set<string>();\n const optimizeDepsExclude = new Set<string>();\n const ssrNoExternal: Array<string | RegExp> = [];\n const seenSsrNoExternalStrings = new Set<string>();\n let ssrNoExternalAll = false;\n const packageNames = getOpenZeppelinAdapterPackageNames(ecosystems);\n\n for (const packageName of packageNames) {\n optimizeDepsExclude.add(packageName);\n ssrNoExternalAll =\n appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, packageName) ||\n ssrNoExternalAll;\n }\n\n for (const ecosystem of ecosystems) {\n const entry = getAdapterRegistryEntry(ecosystem);\n\n let fragment: AdapterViteConfigFragment;\n try {\n fragment = await entry.loadConfig(options);\n } catch (error) {\n throw new Error(\n `Failed to load ${entry.packageName} Vite configuration. ` +\n `Original error: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n\n appendPlugins(plugins, fragment.plugins);\n appendStringValues(dedupe, fragment.resolve?.dedupe);\n appendStringValues(optimizeDepsInclude, fragment.optimizeDeps?.include);\n appendStringValues(optimizeDepsExclude, fragment.optimizeDeps?.exclude);\n appendStringValues(optimizeDepsExclude, entry.extraOptimizeDepsExclude);\n\n ssrNoExternalAll =\n appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, fragment.ssr?.noExternal) ||\n ssrNoExternalAll;\n }\n\n return {\n plugins,\n resolve: {\n dedupe: [...dedupe],\n },\n optimizeDeps: {\n include: [...optimizeDepsInclude],\n exclude: [...optimizeDepsExclude],\n },\n ssr: {\n noExternal: ssrNoExternalAll ? true : ssrNoExternal,\n },\n packageNames,\n };\n}\n","import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport type { Plugin } from 'vite';\n\nimport {\n getOpenZeppelinAdapterImportSpecifier,\n getOpenZeppelinAdapterPackageNames,\n} from './registry';\nimport type {\n OpenZeppelinAdapterExportPath,\n ResolveInstalledOpenZeppelinAdapterEntriesOptions,\n} from './types';\n\ntype PackageExportEntry =\n | string\n | {\n import?: string | { default?: string };\n default?: string;\n };\n\nfunction readPackageJson(packageDirectory: string): {\n exports?: Record<string, PackageExportEntry>;\n} {\n return JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'), 'utf8')) as {\n exports?: Record<string, PackageExportEntry>;\n };\n}\n\nfunction getImportTarget(entry: PackageExportEntry | undefined): string | null {\n if (!entry) {\n return null;\n }\n\n if (typeof entry === 'string') {\n return entry;\n }\n\n if (typeof entry.import === 'string') {\n return entry.import;\n }\n\n if (\n entry.import &&\n typeof entry.import === 'object' &&\n typeof entry.import.default === 'string'\n ) {\n return entry.import.default;\n }\n\n if (typeof entry.default === 'string') {\n return entry.default;\n }\n\n return null;\n}\n\nfunction resolveInstalledPackageDirectory(packageName: string, importMetaUrl: string): string {\n const require = createRequire(importMetaUrl);\n const installedEntryPath = require.resolve(packageName);\n return path.resolve(path.dirname(installedEntryPath), '..');\n}\n\nfunction resolveInstalledExportEntry(\n packageName: string,\n packageDirectory: string,\n exportPath: OpenZeppelinAdapterExportPath\n): string {\n const packageJson = readPackageJson(packageDirectory);\n const target = getImportTarget(packageJson.exports?.[exportPath]);\n\n if (!target) {\n throw new Error(\n `Missing export \"${exportPath}\" in ${packageName}/package.json (required \"import\" condition)`\n );\n }\n\n return path.resolve(packageDirectory, target);\n}\n\nexport function resolveInstalledOpenZeppelinAdapterEntries(\n options: ResolveInstalledOpenZeppelinAdapterEntriesOptions\n): Record<string, string> {\n const exportPaths = options.exportPaths ?? ['.', './metadata', './networks'];\n const entries: Record<string, string> = {};\n\n for (const packageName of getOpenZeppelinAdapterPackageNames(options.ecosystems)) {\n const packageDirectory = resolveInstalledPackageDirectory(packageName, options.importMetaUrl);\n\n for (const exportPath of exportPaths) {\n entries[getOpenZeppelinAdapterImportSpecifier(packageName, exportPath)] =\n resolveInstalledExportEntry(packageName, packageDirectory, exportPath);\n }\n }\n\n return entries;\n}\n\nexport function createOpenZeppelinAdapterResolverPlugin(\n options: ResolveInstalledOpenZeppelinAdapterEntriesOptions\n): Plugin {\n const entries = resolveInstalledOpenZeppelinAdapterEntries(options);\n\n return {\n name: 'openzeppelin-adapter-package-resolver',\n enforce: 'pre',\n resolveId(id) {\n return entries[id] ?? null;\n },\n };\n}\n","import type { Plugin, PluginOption, UserConfig } from 'vite';\n\nexport const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = [\n 'evm',\n 'midnight',\n 'polkadot',\n 'solana',\n 'stellar',\n] as const;\n\nexport type OpenZeppelinAdapterEcosystem =\n (typeof SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS)[number];\n\nexport type OpenZeppelinAdapterExportPath = '.' | './metadata' | './networks';\n\nexport interface MidnightAdapterPluginFactories {\n wasm: () => Plugin;\n topLevelAwait: () => Plugin;\n}\n\nexport interface OpenZeppelinAdapterPluginFactories {\n midnight?: MidnightAdapterPluginFactories;\n}\n\nexport interface LoadOpenZeppelinAdapterViteConfigOptions {\n ecosystems: readonly OpenZeppelinAdapterEcosystem[];\n pluginFactories?: OpenZeppelinAdapterPluginFactories;\n}\n\nexport interface ResolveInstalledOpenZeppelinAdapterEntriesOptions {\n ecosystems: readonly OpenZeppelinAdapterEcosystem[];\n importMetaUrl: string;\n exportPaths?: readonly OpenZeppelinAdapterExportPath[];\n}\n\nexport interface OpenZeppelinAdapterViteConfig {\n plugins: PluginOption[];\n resolve: NonNullable<UserConfig['resolve']>;\n optimizeDeps: NonNullable<UserConfig['optimizeDeps']>;\n ssr: NonNullable<UserConfig['ssr']>;\n packageNames: string[];\n}\n\nexport type AdapterViteConfigFragment = Partial<\n Pick<UserConfig, 'plugins' | 'resolve' | 'optimizeDeps' | 'ssr'>\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,mBAA+E;CACnF,KAAK;EACH,aAAa;EACb,0BAA0B,CAAC,iCAAiC;EAC5D,MAAM,aAAa;GACjB,MAAM,EAAE,qBAAqB,MAAM,OAAO;AAC1C,UAAO,kBAAkB;;EAE5B;CACD,UAAU;EACR,aAAa;EACb,MAAM,WAAW,SAAS;GACxB,MAAM,kBAAkB,QAAQ,iBAAiB;AACjD,OAAI,CAAC,gBACH,OAAM,IAAI,MACR,2GACD;GAGH,MAAM,EAAE,0BAA0B,MAAM,OAAO;AAC/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vB,SAAQ,sCAAsC,aAAa,WAAW,IACpE,4BAA4B,aAAa,kBAAkB,WAAW;;AAI5E,QAAO;;AAGT,SAAgB,wCACd,SACQ;CACR,MAAM,UAAU,2CAA2C,QAAQ;AAEnE,QAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,IAAI;AACZ,UAAO,QAAQ,OAAO;;EAEzB;;;;;AC3GH,MAAa,4CAA4C;CACvD;CACA;CACA;CACA;CACA;CACD"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Plugin, PluginOption, UserConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS: readonly ["evm", "midnight", "polkadot", "solana", "stellar"];
|
|
5
|
+
type OpenZeppelinAdapterEcosystem = (typeof SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS)[number];
|
|
6
|
+
type OpenZeppelinAdapterExportPath = '.' | './metadata' | './networks';
|
|
7
|
+
interface MidnightAdapterPluginFactories {
|
|
8
|
+
wasm: () => Plugin;
|
|
9
|
+
topLevelAwait: () => Plugin;
|
|
10
|
+
}
|
|
11
|
+
interface OpenZeppelinAdapterPluginFactories {
|
|
12
|
+
midnight?: MidnightAdapterPluginFactories;
|
|
13
|
+
}
|
|
14
|
+
interface LoadOpenZeppelinAdapterViteConfigOptions {
|
|
15
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
16
|
+
pluginFactories?: OpenZeppelinAdapterPluginFactories;
|
|
17
|
+
}
|
|
18
|
+
interface ResolveInstalledOpenZeppelinAdapterEntriesOptions {
|
|
19
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
20
|
+
importMetaUrl: string;
|
|
21
|
+
exportPaths?: readonly OpenZeppelinAdapterExportPath[];
|
|
22
|
+
}
|
|
23
|
+
interface OpenZeppelinAdapterViteConfig {
|
|
24
|
+
plugins: PluginOption[];
|
|
25
|
+
resolve: NonNullable<UserConfig['resolve']>;
|
|
26
|
+
optimizeDeps: NonNullable<UserConfig['optimizeDeps']>;
|
|
27
|
+
ssr: NonNullable<UserConfig['ssr']>;
|
|
28
|
+
packageNames: string[];
|
|
29
|
+
}
|
|
30
|
+
type AdapterViteConfigFragment = Partial<Pick<UserConfig, 'plugins' | 'resolve' | 'optimizeDeps' | 'ssr'>>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/config.d.ts
|
|
33
|
+
declare function loadOpenZeppelinAdapterViteConfig(options: LoadOpenZeppelinAdapterViteConfigOptions): Promise<OpenZeppelinAdapterViteConfig>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/registry.d.ts
|
|
36
|
+
declare function getOpenZeppelinAdapterPackageNames(ecosystems: readonly OpenZeppelinAdapterEcosystem[]): string[];
|
|
37
|
+
declare function getOpenZeppelinAdapterImportSpecifier(packageName: string, exportPath: OpenZeppelinAdapterExportPath): string;
|
|
38
|
+
declare function getOpenZeppelinAdapterImportSpecifiers(ecosystems: readonly OpenZeppelinAdapterEcosystem[], exportPaths: readonly OpenZeppelinAdapterExportPath[]): string[];
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/resolver.d.ts
|
|
41
|
+
declare function resolveInstalledOpenZeppelinAdapterEntries(options: ResolveInstalledOpenZeppelinAdapterEntriesOptions): Record<string, string>;
|
|
42
|
+
declare function createOpenZeppelinAdapterResolverPlugin(options: ResolveInstalledOpenZeppelinAdapterEntriesOptions): Plugin;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type AdapterViteConfigFragment, type LoadOpenZeppelinAdapterViteConfigOptions, type MidnightAdapterPluginFactories, type OpenZeppelinAdapterEcosystem, type OpenZeppelinAdapterExportPath, type OpenZeppelinAdapterPluginFactories, type OpenZeppelinAdapterViteConfig, type ResolveInstalledOpenZeppelinAdapterEntriesOptions, SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS, createOpenZeppelinAdapterResolverPlugin, getOpenZeppelinAdapterImportSpecifier, getOpenZeppelinAdapterImportSpecifiers, getOpenZeppelinAdapterPackageNames, loadOpenZeppelinAdapterViteConfig, resolveInstalledOpenZeppelinAdapterEntries };
|
|
45
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/config.ts","../src/registry.ts","../src/resolver.ts"],"sourcesContent":[],"mappings":";;;cAEa;KAQD,4BAAA,WACF;AATG,KAWD,6BAAA,GAXC,GAAA,GAMH,YAAA,GAAA,YAAA;AAEE,UAKK,8BAAA,CAJP;EAEE,IAAA,EAAA,GAAA,GAGE,MAHF;EAEK,aAAA,EAAA,GAAA,GAEM,MAFN;AAKjB;AAIiB,UAJA,kCAAA,CAIwC;EAKxC,QAAA,CAAA,EARJ,8BAQI;AAMjB;AACW,UAZM,wCAAA,CAYN;EACY,UAAA,EAAA,SAZA,4BAYA,EAAA;EAAZ,eAAA,CAAA,EAXS,kCAWT;;AACK,UATC,iDAAA,CASD;EACG,UAAA,EAAA,SATI,4BASJ,EAAA;EAAZ,aAAA,EAAA,MAAA;EAAW,WAAA,CAAA,EAAA,SAPO,6BAOP,EAAA;AAIlB;AACO,UATU,6BAAA,CASV;EAAL,OAAA,EARS,YAQT,EAAA;EADsC,OAAA,EAN7B,WAM6B,CANjB,UAMiB,CAAA,SAAA,CAAA,CAAA;EAAO,YAAA,EAL/B,WAK+B,CALnB,UAKmB,CAAA,cAAA,CAAA,CAAA;OAJxC,YAAY;;;AC8BG,KD1BV,yBAAA,GAA4B,OC0Be,CDzBrD,ICyBqD,CDzBhD,UCyBgD,EAAA,SAAA,GAAA,SAAA,GAAA,cAAA,GAAA,KAAA,CAAA,CAAA;;;iBAAjC,iCAAA,UACX,2CACR,QAAQ;;;AD/CM,iBEmDD,kCAAA,CFlDO,UAAA,EAAA,SEmDA,4BFlDH,EAAA,CAAA,EAAA,MAAA,EAAA;AAGH,iBEsDD,qCAAA,CFtDkD,WAC3C,EAAA,MAAA,EAAA,UAAA,EEuDT,6BFrDW,CAAA,EAA6B,MAAA;AAGrC,iBE2DD,sCAAA,CF3D8B,UAAA,EAAA,SE4DvB,4BF5DuB,EAAA,EAAA,WAAA,EAAA,SE6DtB,6BF7DsB,EAAA,CAAA,EAAA,MAAA,EAAA;;;iBG6C9B,0CAAA,UACL,oDACR;AHhFU,iBGgGG,uCAAA,CH1FN,OAAA,EG2FC,iDH3FD,CAAA,EG4FP,MH5FO"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Plugin, PluginOption, UserConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS: readonly ["evm", "midnight", "polkadot", "solana", "stellar"];
|
|
5
|
+
type OpenZeppelinAdapterEcosystem = (typeof SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS)[number];
|
|
6
|
+
type OpenZeppelinAdapterExportPath = '.' | './metadata' | './networks';
|
|
7
|
+
interface MidnightAdapterPluginFactories {
|
|
8
|
+
wasm: () => Plugin;
|
|
9
|
+
topLevelAwait: () => Plugin;
|
|
10
|
+
}
|
|
11
|
+
interface OpenZeppelinAdapterPluginFactories {
|
|
12
|
+
midnight?: MidnightAdapterPluginFactories;
|
|
13
|
+
}
|
|
14
|
+
interface LoadOpenZeppelinAdapterViteConfigOptions {
|
|
15
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
16
|
+
pluginFactories?: OpenZeppelinAdapterPluginFactories;
|
|
17
|
+
}
|
|
18
|
+
interface ResolveInstalledOpenZeppelinAdapterEntriesOptions {
|
|
19
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
20
|
+
importMetaUrl: string;
|
|
21
|
+
exportPaths?: readonly OpenZeppelinAdapterExportPath[];
|
|
22
|
+
}
|
|
23
|
+
interface OpenZeppelinAdapterViteConfig {
|
|
24
|
+
plugins: PluginOption[];
|
|
25
|
+
resolve: NonNullable<UserConfig['resolve']>;
|
|
26
|
+
optimizeDeps: NonNullable<UserConfig['optimizeDeps']>;
|
|
27
|
+
ssr: NonNullable<UserConfig['ssr']>;
|
|
28
|
+
packageNames: string[];
|
|
29
|
+
}
|
|
30
|
+
type AdapterViteConfigFragment = Partial<Pick<UserConfig, 'plugins' | 'resolve' | 'optimizeDeps' | 'ssr'>>;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/config.d.ts
|
|
33
|
+
declare function loadOpenZeppelinAdapterViteConfig(options: LoadOpenZeppelinAdapterViteConfigOptions): Promise<OpenZeppelinAdapterViteConfig>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/registry.d.ts
|
|
36
|
+
declare function getOpenZeppelinAdapterPackageNames(ecosystems: readonly OpenZeppelinAdapterEcosystem[]): string[];
|
|
37
|
+
declare function getOpenZeppelinAdapterImportSpecifier(packageName: string, exportPath: OpenZeppelinAdapterExportPath): string;
|
|
38
|
+
declare function getOpenZeppelinAdapterImportSpecifiers(ecosystems: readonly OpenZeppelinAdapterEcosystem[], exportPaths: readonly OpenZeppelinAdapterExportPath[]): string[];
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/resolver.d.ts
|
|
41
|
+
declare function resolveInstalledOpenZeppelinAdapterEntries(options: ResolveInstalledOpenZeppelinAdapterEntriesOptions): Record<string, string>;
|
|
42
|
+
declare function createOpenZeppelinAdapterResolverPlugin(options: ResolveInstalledOpenZeppelinAdapterEntriesOptions): Plugin;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type AdapterViteConfigFragment, type LoadOpenZeppelinAdapterViteConfigOptions, type MidnightAdapterPluginFactories, type OpenZeppelinAdapterEcosystem, type OpenZeppelinAdapterExportPath, type OpenZeppelinAdapterPluginFactories, type OpenZeppelinAdapterViteConfig, type ResolveInstalledOpenZeppelinAdapterEntriesOptions, SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS, createOpenZeppelinAdapterResolverPlugin, getOpenZeppelinAdapterImportSpecifier, getOpenZeppelinAdapterImportSpecifiers, getOpenZeppelinAdapterPackageNames, loadOpenZeppelinAdapterViteConfig, resolveInstalledOpenZeppelinAdapterEntries };
|
|
45
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/config.ts","../src/registry.ts","../src/resolver.ts"],"sourcesContent":[],"mappings":";;;cAEa;KAQD,4BAAA,WACF;AATG,KAWD,6BAAA,GAXC,GAAA,GAMH,YAAA,GAAA,YAAA;AAEE,UAKK,8BAAA,CAJP;EAEE,IAAA,EAAA,GAAA,GAGE,MAHF;EAEK,aAAA,EAAA,GAAA,GAEM,MAFN;AAKjB;AAIiB,UAJA,kCAAA,CAIwC;EAKxC,QAAA,CAAA,EARJ,8BAQI;AAMjB;AACW,UAZM,wCAAA,CAYN;EACY,UAAA,EAAA,SAZA,4BAYA,EAAA;EAAZ,eAAA,CAAA,EAXS,kCAWT;;AACK,UATC,iDAAA,CASD;EACG,UAAA,EAAA,SATI,4BASJ,EAAA;EAAZ,aAAA,EAAA,MAAA;EAAW,WAAA,CAAA,EAAA,SAPO,6BAOP,EAAA;AAIlB;AACO,UATU,6BAAA,CASV;EAAL,OAAA,EARS,YAQT,EAAA;EADsC,OAAA,EAN7B,WAM6B,CANjB,UAMiB,CAAA,SAAA,CAAA,CAAA;EAAO,YAAA,EAL/B,WAK+B,CALnB,UAKmB,CAAA,cAAA,CAAA,CAAA;OAJxC,YAAY;;;AC8BG,KD1BV,yBAAA,GAA4B,OC0Be,CDzBrD,ICyBqD,CDzBhD,UCyBgD,EAAA,SAAA,GAAA,SAAA,GAAA,cAAA,GAAA,KAAA,CAAA,CAAA;;;iBAAjC,iCAAA,UACX,2CACR,QAAQ;;;AD/CM,iBEmDD,kCAAA,CFlDO,UAAA,EAAA,SEmDA,4BFlDH,EAAA,CAAA,EAAA,MAAA,EAAA;AAGH,iBEsDD,qCAAA,CFtDkD,WAC3C,EAAA,MAAA,EAAA,UAAA,EEuDT,6BFrDW,CAAA,EAA6B,MAAA;AAGrC,iBE2DD,sCAAA,CF3D8B,UAAA,EAAA,SE4DvB,4BF5DuB,EAAA,EAAA,WAAA,EAAA,SE6DtB,6BF7DsB,EAAA,CAAA,EAAA,MAAA,EAAA;;;iBG6C9B,0CAAA,UACL,oDACR;AHhFU,iBGgGG,uCAAA,CH1FN,OAAA,EG2FC,iDH3FD,CAAA,EG4FP,MH5FO"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/registry.ts
|
|
6
|
+
const ADAPTER_REGISTRY = {
|
|
7
|
+
evm: {
|
|
8
|
+
packageName: "@openzeppelin/adapter-evm",
|
|
9
|
+
extraOptimizeDepsExclude: ["@openzeppelin/adapter-evm-core"],
|
|
10
|
+
async loadConfig() {
|
|
11
|
+
const { getEvmViteConfig } = await import("@openzeppelin/adapter-evm/vite-config");
|
|
12
|
+
return getEvmViteConfig();
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
midnight: {
|
|
16
|
+
packageName: "@openzeppelin/adapter-midnight",
|
|
17
|
+
async loadConfig(options) {
|
|
18
|
+
const midnightPlugins = options.pluginFactories?.midnight;
|
|
19
|
+
if (!midnightPlugins) throw new Error("Midnight adapter Vite configuration requires `pluginFactories.midnight` with `wasm` and `topLevelAwait`.");
|
|
20
|
+
const { getMidnightViteConfig } = await import("@openzeppelin/adapter-midnight/vite-config");
|
|
21
|
+
return getMidnightViteConfig(midnightPlugins);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
polkadot: {
|
|
25
|
+
packageName: "@openzeppelin/adapter-polkadot",
|
|
26
|
+
async loadConfig() {
|
|
27
|
+
const { getPolkadotViteConfig } = await import("@openzeppelin/adapter-polkadot/vite-config");
|
|
28
|
+
return getPolkadotViteConfig();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
solana: {
|
|
32
|
+
packageName: "@openzeppelin/adapter-solana",
|
|
33
|
+
async loadConfig() {
|
|
34
|
+
const { getSolanaViteConfig } = await import("@openzeppelin/adapter-solana/vite-config");
|
|
35
|
+
return getSolanaViteConfig();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
stellar: {
|
|
39
|
+
packageName: "@openzeppelin/adapter-stellar",
|
|
40
|
+
async loadConfig() {
|
|
41
|
+
const { getStellarViteConfig } = await import("@openzeppelin/adapter-stellar/vite-config");
|
|
42
|
+
return getStellarViteConfig();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function normalizeEcosystems(ecosystems) {
|
|
47
|
+
return [...new Set(ecosystems)];
|
|
48
|
+
}
|
|
49
|
+
function getAdapterRegistryEntry(ecosystem) {
|
|
50
|
+
return ADAPTER_REGISTRY[ecosystem];
|
|
51
|
+
}
|
|
52
|
+
function getOpenZeppelinAdapterPackageNames(ecosystems) {
|
|
53
|
+
return normalizeEcosystems(ecosystems).map((ecosystem) => ADAPTER_REGISTRY[ecosystem].packageName);
|
|
54
|
+
}
|
|
55
|
+
function getOpenZeppelinAdapterImportSpecifier(packageName, exportPath) {
|
|
56
|
+
if (exportPath === ".") return packageName;
|
|
57
|
+
return `${packageName}/${exportPath.slice(2)}`;
|
|
58
|
+
}
|
|
59
|
+
function getOpenZeppelinAdapterImportSpecifiers(ecosystems, exportPaths) {
|
|
60
|
+
const specifiers = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(ecosystems)) for (const exportPath of exportPaths) specifiers.add(getOpenZeppelinAdapterImportSpecifier(packageName, exportPath));
|
|
62
|
+
return [...specifiers];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/config.ts
|
|
67
|
+
function appendPlugins(target, plugins) {
|
|
68
|
+
if (!plugins) return;
|
|
69
|
+
target.push(...Array.isArray(plugins) ? plugins : [plugins]);
|
|
70
|
+
}
|
|
71
|
+
function appendStringValues(target, value) {
|
|
72
|
+
if (!value) return;
|
|
73
|
+
const values = Array.isArray(value) ? value : [value];
|
|
74
|
+
for (const entry of values) if (entry) target.add(entry);
|
|
75
|
+
}
|
|
76
|
+
function appendNoExternalValues(target, seenStrings, value) {
|
|
77
|
+
if (!value) return false;
|
|
78
|
+
if (value === true) return true;
|
|
79
|
+
const values = Array.isArray(value) ? value : [value];
|
|
80
|
+
for (const entry of values) {
|
|
81
|
+
if (typeof entry === "string") {
|
|
82
|
+
if (!seenStrings.has(entry)) {
|
|
83
|
+
seenStrings.add(entry);
|
|
84
|
+
target.push(entry);
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (entry instanceof RegExp) target.push(entry);
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
async function loadOpenZeppelinAdapterViteConfig(options) {
|
|
93
|
+
const ecosystems = normalizeEcosystems(options.ecosystems);
|
|
94
|
+
const plugins = [];
|
|
95
|
+
const dedupe = /* @__PURE__ */ new Set();
|
|
96
|
+
const optimizeDepsInclude = /* @__PURE__ */ new Set();
|
|
97
|
+
const optimizeDepsExclude = /* @__PURE__ */ new Set();
|
|
98
|
+
const ssrNoExternal = [];
|
|
99
|
+
const seenSsrNoExternalStrings = /* @__PURE__ */ new Set();
|
|
100
|
+
let ssrNoExternalAll = false;
|
|
101
|
+
const packageNames = getOpenZeppelinAdapterPackageNames(ecosystems);
|
|
102
|
+
for (const packageName of packageNames) {
|
|
103
|
+
optimizeDepsExclude.add(packageName);
|
|
104
|
+
ssrNoExternalAll = appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, packageName) || ssrNoExternalAll;
|
|
105
|
+
}
|
|
106
|
+
for (const ecosystem of ecosystems) {
|
|
107
|
+
const entry = getAdapterRegistryEntry(ecosystem);
|
|
108
|
+
let fragment;
|
|
109
|
+
try {
|
|
110
|
+
fragment = await entry.loadConfig(options);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new Error(`Failed to load ${entry.packageName} Vite configuration. Original error: ${error instanceof Error ? error.message : String(error)}`);
|
|
113
|
+
}
|
|
114
|
+
appendPlugins(plugins, fragment.plugins);
|
|
115
|
+
appendStringValues(dedupe, fragment.resolve?.dedupe);
|
|
116
|
+
appendStringValues(optimizeDepsInclude, fragment.optimizeDeps?.include);
|
|
117
|
+
appendStringValues(optimizeDepsExclude, fragment.optimizeDeps?.exclude);
|
|
118
|
+
appendStringValues(optimizeDepsExclude, entry.extraOptimizeDepsExclude);
|
|
119
|
+
ssrNoExternalAll = appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, fragment.ssr?.noExternal) || ssrNoExternalAll;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
plugins,
|
|
123
|
+
resolve: { dedupe: [...dedupe] },
|
|
124
|
+
optimizeDeps: {
|
|
125
|
+
include: [...optimizeDepsInclude],
|
|
126
|
+
exclude: [...optimizeDepsExclude]
|
|
127
|
+
},
|
|
128
|
+
ssr: { noExternal: ssrNoExternalAll ? true : ssrNoExternal },
|
|
129
|
+
packageNames
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/resolver.ts
|
|
135
|
+
function readPackageJson(packageDirectory) {
|
|
136
|
+
return JSON.parse(fs.readFileSync(path.join(packageDirectory, "package.json"), "utf8"));
|
|
137
|
+
}
|
|
138
|
+
function getImportTarget(entry) {
|
|
139
|
+
if (!entry) return null;
|
|
140
|
+
if (typeof entry === "string") return entry;
|
|
141
|
+
if (typeof entry.import === "string") return entry.import;
|
|
142
|
+
if (entry.import && typeof entry.import === "object" && typeof entry.import.default === "string") return entry.import.default;
|
|
143
|
+
if (typeof entry.default === "string") return entry.default;
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
function resolveInstalledPackageDirectory(packageName, importMetaUrl) {
|
|
147
|
+
const installedEntryPath = createRequire(importMetaUrl).resolve(packageName);
|
|
148
|
+
return path.resolve(path.dirname(installedEntryPath), "..");
|
|
149
|
+
}
|
|
150
|
+
function resolveInstalledExportEntry(packageName, packageDirectory, exportPath) {
|
|
151
|
+
const target = getImportTarget(readPackageJson(packageDirectory).exports?.[exportPath]);
|
|
152
|
+
if (!target) throw new Error(`Missing export "${exportPath}" in ${packageName}/package.json (required "import" condition)`);
|
|
153
|
+
return path.resolve(packageDirectory, target);
|
|
154
|
+
}
|
|
155
|
+
function resolveInstalledOpenZeppelinAdapterEntries(options) {
|
|
156
|
+
const exportPaths = options.exportPaths ?? [
|
|
157
|
+
".",
|
|
158
|
+
"./metadata",
|
|
159
|
+
"./networks"
|
|
160
|
+
];
|
|
161
|
+
const entries = {};
|
|
162
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(options.ecosystems)) {
|
|
163
|
+
const packageDirectory = resolveInstalledPackageDirectory(packageName, options.importMetaUrl);
|
|
164
|
+
for (const exportPath of exportPaths) entries[getOpenZeppelinAdapterImportSpecifier(packageName, exportPath)] = resolveInstalledExportEntry(packageName, packageDirectory, exportPath);
|
|
165
|
+
}
|
|
166
|
+
return entries;
|
|
167
|
+
}
|
|
168
|
+
function createOpenZeppelinAdapterResolverPlugin(options) {
|
|
169
|
+
const entries = resolveInstalledOpenZeppelinAdapterEntries(options);
|
|
170
|
+
return {
|
|
171
|
+
name: "openzeppelin-adapter-package-resolver",
|
|
172
|
+
enforce: "pre",
|
|
173
|
+
resolveId(id) {
|
|
174
|
+
return entries[id] ?? null;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/types.ts
|
|
181
|
+
const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = [
|
|
182
|
+
"evm",
|
|
183
|
+
"midnight",
|
|
184
|
+
"polkadot",
|
|
185
|
+
"solana",
|
|
186
|
+
"stellar"
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
export { SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS, createOpenZeppelinAdapterResolverPlugin, getOpenZeppelinAdapterImportSpecifier, getOpenZeppelinAdapterImportSpecifiers, getOpenZeppelinAdapterPackageNames, loadOpenZeppelinAdapterViteConfig, resolveInstalledOpenZeppelinAdapterEntries };
|
|
191
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/registry.ts","../src/config.ts","../src/resolver.ts","../src/types.ts"],"sourcesContent":["import type { UserConfig } from 'vite';\n\nimport type {\n AdapterViteConfigFragment,\n LoadOpenZeppelinAdapterViteConfigOptions,\n OpenZeppelinAdapterEcosystem,\n OpenZeppelinAdapterExportPath,\n} from './types';\n\ninterface AdapterRegistryEntry {\n packageName: string;\n extraOptimizeDepsExclude?: string[];\n loadConfig: (\n options: LoadOpenZeppelinAdapterViteConfigOptions\n ) => Promise<AdapterViteConfigFragment>;\n}\n\nconst ADAPTER_REGISTRY: Record<OpenZeppelinAdapterEcosystem, AdapterRegistryEntry> = {\n evm: {\n packageName: '@openzeppelin/adapter-evm',\n extraOptimizeDepsExclude: ['@openzeppelin/adapter-evm-core'],\n async loadConfig() {\n const { getEvmViteConfig } = await import('@openzeppelin/adapter-evm/vite-config');\n return getEvmViteConfig() as Partial<UserConfig>;\n },\n },\n midnight: {\n packageName: '@openzeppelin/adapter-midnight',\n async loadConfig(options) {\n const midnightPlugins = options.pluginFactories?.midnight;\n if (!midnightPlugins) {\n throw new Error(\n 'Midnight adapter Vite configuration requires `pluginFactories.midnight` with `wasm` and `topLevelAwait`.'\n );\n }\n\n const { getMidnightViteConfig } = await import('@openzeppelin/adapter-midnight/vite-config');\n return getMidnightViteConfig(midnightPlugins) as Partial<UserConfig>;\n },\n },\n polkadot: {\n packageName: '@openzeppelin/adapter-polkadot',\n async loadConfig() {\n const { getPolkadotViteConfig } = await import('@openzeppelin/adapter-polkadot/vite-config');\n return getPolkadotViteConfig() as Partial<UserConfig>;\n },\n },\n solana: {\n packageName: '@openzeppelin/adapter-solana',\n async loadConfig() {\n const { getSolanaViteConfig } = await import('@openzeppelin/adapter-solana/vite-config');\n return getSolanaViteConfig() as Partial<UserConfig>;\n },\n },\n stellar: {\n packageName: '@openzeppelin/adapter-stellar',\n async loadConfig() {\n const { getStellarViteConfig } = await import('@openzeppelin/adapter-stellar/vite-config');\n return getStellarViteConfig() as Partial<UserConfig>;\n },\n },\n};\n\nexport function normalizeEcosystems(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[]\n): OpenZeppelinAdapterEcosystem[] {\n return [...new Set(ecosystems)];\n}\n\nexport function getAdapterRegistryEntry(\n ecosystem: OpenZeppelinAdapterEcosystem\n): AdapterRegistryEntry {\n return ADAPTER_REGISTRY[ecosystem];\n}\n\nexport function getOpenZeppelinAdapterPackageNames(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[]\n): string[] {\n return normalizeEcosystems(ecosystems).map(\n (ecosystem) => ADAPTER_REGISTRY[ecosystem].packageName\n );\n}\n\nexport function getOpenZeppelinAdapterImportSpecifier(\n packageName: string,\n exportPath: OpenZeppelinAdapterExportPath\n): string {\n if (exportPath === '.') {\n return packageName;\n }\n\n return `${packageName}/${exportPath.slice(2)}`;\n}\n\nexport function getOpenZeppelinAdapterImportSpecifiers(\n ecosystems: readonly OpenZeppelinAdapterEcosystem[],\n exportPaths: readonly OpenZeppelinAdapterExportPath[]\n): string[] {\n const specifiers = new Set<string>();\n\n for (const packageName of getOpenZeppelinAdapterPackageNames(ecosystems)) {\n for (const exportPath of exportPaths) {\n specifiers.add(getOpenZeppelinAdapterImportSpecifier(packageName, exportPath));\n }\n }\n\n return [...specifiers];\n}\n","import type { PluginOption, UserConfig } from 'vite';\n\nimport {\n getAdapterRegistryEntry,\n getOpenZeppelinAdapterPackageNames,\n normalizeEcosystems,\n} from './registry';\nimport type {\n AdapterViteConfigFragment,\n LoadOpenZeppelinAdapterViteConfigOptions,\n OpenZeppelinAdapterViteConfig,\n} from './types';\n\ntype SsrNoExternalValue = NonNullable<NonNullable<UserConfig['ssr']>['noExternal']>;\n\nfunction appendPlugins(target: PluginOption[], plugins: AdapterViteConfigFragment['plugins']) {\n if (!plugins) {\n return;\n }\n\n target.push(...(Array.isArray(plugins) ? plugins : [plugins]));\n}\n\nfunction appendStringValues(target: Set<string>, value: string | string[] | undefined) {\n if (!value) {\n return;\n }\n\n const values = Array.isArray(value) ? value : [value];\n\n for (const entry of values) {\n if (entry) {\n target.add(entry);\n }\n }\n}\n\nfunction appendNoExternalValues(\n target: Array<string | RegExp>,\n seenStrings: Set<string>,\n value: SsrNoExternalValue | undefined\n): boolean {\n if (!value) {\n return false;\n }\n\n if (value === true) {\n return true;\n }\n\n const values = Array.isArray(value) ? value : [value];\n\n for (const entry of values) {\n if (typeof entry === 'string') {\n if (!seenStrings.has(entry)) {\n seenStrings.add(entry);\n target.push(entry);\n }\n continue;\n }\n\n if (entry instanceof RegExp) {\n target.push(entry);\n }\n }\n\n return false;\n}\n\nexport async function loadOpenZeppelinAdapterViteConfig(\n options: LoadOpenZeppelinAdapterViteConfigOptions\n): Promise<OpenZeppelinAdapterViteConfig> {\n const ecosystems = normalizeEcosystems(options.ecosystems);\n const plugins: PluginOption[] = [];\n const dedupe = new Set<string>();\n const optimizeDepsInclude = new Set<string>();\n const optimizeDepsExclude = new Set<string>();\n const ssrNoExternal: Array<string | RegExp> = [];\n const seenSsrNoExternalStrings = new Set<string>();\n let ssrNoExternalAll = false;\n const packageNames = getOpenZeppelinAdapterPackageNames(ecosystems);\n\n for (const packageName of packageNames) {\n optimizeDepsExclude.add(packageName);\n ssrNoExternalAll =\n appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, packageName) ||\n ssrNoExternalAll;\n }\n\n for (const ecosystem of ecosystems) {\n const entry = getAdapterRegistryEntry(ecosystem);\n\n let fragment: AdapterViteConfigFragment;\n try {\n fragment = await entry.loadConfig(options);\n } catch (error) {\n throw new Error(\n `Failed to load ${entry.packageName} Vite configuration. ` +\n `Original error: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n\n appendPlugins(plugins, fragment.plugins);\n appendStringValues(dedupe, fragment.resolve?.dedupe);\n appendStringValues(optimizeDepsInclude, fragment.optimizeDeps?.include);\n appendStringValues(optimizeDepsExclude, fragment.optimizeDeps?.exclude);\n appendStringValues(optimizeDepsExclude, entry.extraOptimizeDepsExclude);\n\n ssrNoExternalAll =\n appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, fragment.ssr?.noExternal) ||\n ssrNoExternalAll;\n }\n\n return {\n plugins,\n resolve: {\n dedupe: [...dedupe],\n },\n optimizeDeps: {\n include: [...optimizeDepsInclude],\n exclude: [...optimizeDepsExclude],\n },\n ssr: {\n noExternal: ssrNoExternalAll ? true : ssrNoExternal,\n },\n packageNames,\n };\n}\n","import fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport type { Plugin } from 'vite';\n\nimport {\n getOpenZeppelinAdapterImportSpecifier,\n getOpenZeppelinAdapterPackageNames,\n} from './registry';\nimport type {\n OpenZeppelinAdapterExportPath,\n ResolveInstalledOpenZeppelinAdapterEntriesOptions,\n} from './types';\n\ntype PackageExportEntry =\n | string\n | {\n import?: string | { default?: string };\n default?: string;\n };\n\nfunction readPackageJson(packageDirectory: string): {\n exports?: Record<string, PackageExportEntry>;\n} {\n return JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'), 'utf8')) as {\n exports?: Record<string, PackageExportEntry>;\n };\n}\n\nfunction getImportTarget(entry: PackageExportEntry | undefined): string | null {\n if (!entry) {\n return null;\n }\n\n if (typeof entry === 'string') {\n return entry;\n }\n\n if (typeof entry.import === 'string') {\n return entry.import;\n }\n\n if (\n entry.import &&\n typeof entry.import === 'object' &&\n typeof entry.import.default === 'string'\n ) {\n return entry.import.default;\n }\n\n if (typeof entry.default === 'string') {\n return entry.default;\n }\n\n return null;\n}\n\nfunction resolveInstalledPackageDirectory(packageName: string, importMetaUrl: string): string {\n const require = createRequire(importMetaUrl);\n const installedEntryPath = require.resolve(packageName);\n return path.resolve(path.dirname(installedEntryPath), '..');\n}\n\nfunction resolveInstalledExportEntry(\n packageName: string,\n packageDirectory: string,\n exportPath: OpenZeppelinAdapterExportPath\n): string {\n const packageJson = readPackageJson(packageDirectory);\n const target = getImportTarget(packageJson.exports?.[exportPath]);\n\n if (!target) {\n throw new Error(\n `Missing export \"${exportPath}\" in ${packageName}/package.json (required \"import\" condition)`\n );\n }\n\n return path.resolve(packageDirectory, target);\n}\n\nexport function resolveInstalledOpenZeppelinAdapterEntries(\n options: ResolveInstalledOpenZeppelinAdapterEntriesOptions\n): Record<string, string> {\n const exportPaths = options.exportPaths ?? ['.', './metadata', './networks'];\n const entries: Record<string, string> = {};\n\n for (const packageName of getOpenZeppelinAdapterPackageNames(options.ecosystems)) {\n const packageDirectory = resolveInstalledPackageDirectory(packageName, options.importMetaUrl);\n\n for (const exportPath of exportPaths) {\n entries[getOpenZeppelinAdapterImportSpecifier(packageName, exportPath)] =\n resolveInstalledExportEntry(packageName, packageDirectory, exportPath);\n }\n }\n\n return entries;\n}\n\nexport function createOpenZeppelinAdapterResolverPlugin(\n options: ResolveInstalledOpenZeppelinAdapterEntriesOptions\n): Plugin {\n const entries = resolveInstalledOpenZeppelinAdapterEntries(options);\n\n return {\n name: 'openzeppelin-adapter-package-resolver',\n enforce: 'pre',\n resolveId(id) {\n return entries[id] ?? null;\n },\n };\n}\n","import type { Plugin, PluginOption, UserConfig } from 'vite';\n\nexport const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = [\n 'evm',\n 'midnight',\n 'polkadot',\n 'solana',\n 'stellar',\n] as const;\n\nexport type OpenZeppelinAdapterEcosystem =\n (typeof SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS)[number];\n\nexport type OpenZeppelinAdapterExportPath = '.' | './metadata' | './networks';\n\nexport interface MidnightAdapterPluginFactories {\n wasm: () => Plugin;\n topLevelAwait: () => Plugin;\n}\n\nexport interface OpenZeppelinAdapterPluginFactories {\n midnight?: MidnightAdapterPluginFactories;\n}\n\nexport interface LoadOpenZeppelinAdapterViteConfigOptions {\n ecosystems: readonly OpenZeppelinAdapterEcosystem[];\n pluginFactories?: OpenZeppelinAdapterPluginFactories;\n}\n\nexport interface ResolveInstalledOpenZeppelinAdapterEntriesOptions {\n ecosystems: readonly OpenZeppelinAdapterEcosystem[];\n importMetaUrl: string;\n exportPaths?: readonly OpenZeppelinAdapterExportPath[];\n}\n\nexport interface OpenZeppelinAdapterViteConfig {\n plugins: PluginOption[];\n resolve: NonNullable<UserConfig['resolve']>;\n optimizeDeps: NonNullable<UserConfig['optimizeDeps']>;\n ssr: NonNullable<UserConfig['ssr']>;\n packageNames: string[];\n}\n\nexport type AdapterViteConfigFragment = Partial<\n Pick<UserConfig, 'plugins' | 'resolve' | 'optimizeDeps' | 'ssr'>\n>;\n"],"mappings":";;;;;AAiBA,MAAM,mBAA+E;CACnF,KAAK;EACH,aAAa;EACb,0BAA0B,CAAC,iCAAiC;EAC5D,MAAM,aAAa;GACjB,MAAM,EAAE,qBAAqB,MAAM,OAAO;AAC1C,UAAO,kBAAkB;;EAE5B;CACD,UAAU;EACR,aAAa;EACb,MAAM,WAAW,SAAS;GACxB,MAAM,kBAAkB,QAAQ,iBAAiB;AACjD,OAAI,CAAC,gBACH,OAAM,IAAI,MACR,2GACD;GAGH,MAAM,EAAE,0BAA0B,MAAM,OAAO;AAC/C,UAAO,sBAAsB,gBAAgB;;EAEhD;CACD,UAAU;EACR,aAAa;EACb,MAAM,aAAa;GACjB,MAAM,EAAE,0BAA0B,MAAM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R,MAAM,UAAU,2CAA2C,QAAQ;AAEnE,QAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,IAAI;AACZ,UAAO,QAAQ,OAAO;;EAEzB;;;;;AC3GH,MAAa,4CAA4C;CACvD;CACA;CACA;CACA;CACA;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openzeppelin/adapters-vite",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Shared Vite and Vitest integration helpers for OpenZeppelin adapter packages",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"openzeppelin",
|
|
8
|
+
"vite",
|
|
9
|
+
"vitest",
|
|
10
|
+
"adapter",
|
|
11
|
+
"tooling"
|
|
12
|
+
],
|
|
13
|
+
"author": "Aleksandr Pasevin <aleksandr.pasevin@openzeppelin.com>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.cjs",
|
|
17
|
+
"module": "dist/index.mjs",
|
|
18
|
+
"types": "dist/index.d.mts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/OpenZeppelin/openzeppelin-adapters.git",
|
|
29
|
+
"directory": "packages/adapters-vite"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/OpenZeppelin/openzeppelin-adapters/issues"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@openzeppelin/adapter-evm": "^1.1.0",
|
|
36
|
+
"@openzeppelin/adapter-midnight": "^1.1.0",
|
|
37
|
+
"@openzeppelin/adapter-polkadot": "^1.1.0",
|
|
38
|
+
"@openzeppelin/adapter-solana": "^1.1.0",
|
|
39
|
+
"@openzeppelin/adapter-stellar": "^1.1.0",
|
|
40
|
+
"vite": "^7.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@openzeppelin/adapter-evm": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@openzeppelin/adapter-midnight": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@openzeppelin/adapter-polkadot": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@openzeppelin/adapter-solana": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@openzeppelin/adapter-stellar": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"eslint": "^9.32.0",
|
|
61
|
+
"typescript": "^5.9.2",
|
|
62
|
+
"vite": "^7.2.2",
|
|
63
|
+
"vitest": "^3.2.4",
|
|
64
|
+
"@openzeppelin/adapter-evm": "1.1.0",
|
|
65
|
+
"@openzeppelin/adapter-polkadot": "1.1.0",
|
|
66
|
+
"@openzeppelin/adapter-midnight": "1.1.0",
|
|
67
|
+
"@openzeppelin/adapter-stellar": "1.1.0",
|
|
68
|
+
"@openzeppelin/adapter-solana": "1.1.0"
|
|
69
|
+
},
|
|
70
|
+
"exports": {
|
|
71
|
+
".": {
|
|
72
|
+
"types": {
|
|
73
|
+
"import": "./dist/index.d.mts",
|
|
74
|
+
"require": "./dist/index.d.cts"
|
|
75
|
+
},
|
|
76
|
+
"import": "./dist/index.mjs",
|
|
77
|
+
"require": "./dist/index.cjs"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"build": "tsdown",
|
|
82
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
83
|
+
"lint": "eslint .",
|
|
84
|
+
"lint:fix": "eslint . --fix",
|
|
85
|
+
"typecheck": "tsc --noEmit",
|
|
86
|
+
"test": "vitest run",
|
|
87
|
+
"test:watch": "vitest"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getOpenZeppelinAdapterImportSpecifiers,
|
|
5
|
+
getOpenZeppelinAdapterPackageNames,
|
|
6
|
+
loadOpenZeppelinAdapterViteConfig,
|
|
7
|
+
} from '../index';
|
|
8
|
+
import type { AdapterViteConfigFragment } from '../types';
|
|
9
|
+
|
|
10
|
+
const mockGetEvmViteConfig = vi.fn<() => AdapterViteConfigFragment>(() => ({
|
|
11
|
+
plugins: [{ name: 'evm-plugin' }],
|
|
12
|
+
resolve: {
|
|
13
|
+
dedupe: ['viem', 'wagmi'],
|
|
14
|
+
},
|
|
15
|
+
optimizeDeps: {
|
|
16
|
+
include: ['viem', '@tanstack/react-query'],
|
|
17
|
+
exclude: ['wagmi'],
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const mockGetStellarViteConfig = vi.fn<() => AdapterViteConfigFragment>(() => ({
|
|
22
|
+
resolve: {
|
|
23
|
+
dedupe: ['@stellar/stellar-sdk'],
|
|
24
|
+
},
|
|
25
|
+
optimizeDeps: {
|
|
26
|
+
include: ['@stellar/stellar-sdk'],
|
|
27
|
+
exclude: [],
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const mockGetPolkadotViteConfig = vi.fn<() => AdapterViteConfigFragment>(() => ({
|
|
32
|
+
optimizeDeps: {
|
|
33
|
+
include: ['viem'],
|
|
34
|
+
},
|
|
35
|
+
ssr: {
|
|
36
|
+
noExternal: ['viem'],
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const mockGetMidnightViteConfig = vi.fn(
|
|
41
|
+
(plugins: { wasm: () => { name: string }; topLevelAwait: () => { name: string } }) => ({
|
|
42
|
+
plugins: [plugins.wasm(), plugins.topLevelAwait()],
|
|
43
|
+
resolve: {
|
|
44
|
+
dedupe: ['@midnight-ntwrk/midnight-js-network-id'],
|
|
45
|
+
},
|
|
46
|
+
optimizeDeps: {
|
|
47
|
+
include: ['buffer'],
|
|
48
|
+
exclude: ['@midnight-ntwrk/onchain-runtime'],
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const mockGetSolanaViteConfig = vi.fn<() => AdapterViteConfigFragment>(() => ({
|
|
54
|
+
ssr: {
|
|
55
|
+
noExternal: [/^@solana\//],
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
vi.mock('@openzeppelin/adapter-evm/vite-config', () => ({
|
|
60
|
+
getEvmViteConfig: mockGetEvmViteConfig,
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
vi.mock('@openzeppelin/adapter-stellar/vite-config', () => ({
|
|
64
|
+
getStellarViteConfig: mockGetStellarViteConfig,
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
vi.mock('@openzeppelin/adapter-polkadot/vite-config', () => ({
|
|
68
|
+
getPolkadotViteConfig: mockGetPolkadotViteConfig,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
vi.mock('@openzeppelin/adapter-midnight/vite-config', () => ({
|
|
72
|
+
getMidnightViteConfig: mockGetMidnightViteConfig,
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
vi.mock('@openzeppelin/adapter-solana/vite-config', () => ({
|
|
76
|
+
getSolanaViteConfig: mockGetSolanaViteConfig,
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
describe('@openzeppelin/adapters-vite', () => {
|
|
80
|
+
it('merges adapter config fragments and adds package-level exclusions', async () => {
|
|
81
|
+
const config = await loadOpenZeppelinAdapterViteConfig({
|
|
82
|
+
ecosystems: ['evm', 'stellar', 'polkadot'],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(config.plugins).toHaveLength(1);
|
|
86
|
+
expect(config.resolve.dedupe).toEqual(['viem', 'wagmi', '@stellar/stellar-sdk']);
|
|
87
|
+
expect(config.optimizeDeps.include).toEqual([
|
|
88
|
+
'viem',
|
|
89
|
+
'@tanstack/react-query',
|
|
90
|
+
'@stellar/stellar-sdk',
|
|
91
|
+
]);
|
|
92
|
+
expect(config.optimizeDeps.exclude).toEqual([
|
|
93
|
+
'@openzeppelin/adapter-evm',
|
|
94
|
+
'@openzeppelin/adapter-stellar',
|
|
95
|
+
'@openzeppelin/adapter-polkadot',
|
|
96
|
+
'wagmi',
|
|
97
|
+
'@openzeppelin/adapter-evm-core',
|
|
98
|
+
]);
|
|
99
|
+
expect(config.ssr.noExternal).toEqual([
|
|
100
|
+
'@openzeppelin/adapter-evm',
|
|
101
|
+
'@openzeppelin/adapter-stellar',
|
|
102
|
+
'@openzeppelin/adapter-polkadot',
|
|
103
|
+
'viem',
|
|
104
|
+
]);
|
|
105
|
+
expect(config.packageNames).toEqual([
|
|
106
|
+
'@openzeppelin/adapter-evm',
|
|
107
|
+
'@openzeppelin/adapter-stellar',
|
|
108
|
+
'@openzeppelin/adapter-polkadot',
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('requires midnight plugin factories when midnight support is requested', async () => {
|
|
113
|
+
await expect(
|
|
114
|
+
loadOpenZeppelinAdapterViteConfig({
|
|
115
|
+
ecosystems: ['midnight'],
|
|
116
|
+
})
|
|
117
|
+
).rejects.toThrow(/pluginFactories\.midnight/);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('supports midnight config when plugin factories are provided', async () => {
|
|
121
|
+
const config = await loadOpenZeppelinAdapterViteConfig({
|
|
122
|
+
ecosystems: ['midnight'],
|
|
123
|
+
pluginFactories: {
|
|
124
|
+
midnight: {
|
|
125
|
+
wasm: () => ({ name: 'wasm-plugin' }),
|
|
126
|
+
topLevelAwait: () => ({ name: 'tla-plugin' }),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(config.plugins).toHaveLength(2);
|
|
132
|
+
expect(config.resolve.dedupe).toEqual(['@midnight-ntwrk/midnight-js-network-id']);
|
|
133
|
+
expect(config.optimizeDeps.include).toEqual(['buffer']);
|
|
134
|
+
expect(config.optimizeDeps.exclude).toEqual([
|
|
135
|
+
'@openzeppelin/adapter-midnight',
|
|
136
|
+
'@midnight-ntwrk/onchain-runtime',
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('preserves regexp ssr.noExternal entries from adapter fragments', async () => {
|
|
141
|
+
const config = await loadOpenZeppelinAdapterViteConfig({
|
|
142
|
+
ecosystems: ['solana'],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(config.ssr.noExternal).toHaveLength(2);
|
|
146
|
+
expect(config.ssr.noExternal).toEqual(['@openzeppelin/adapter-solana', /^@solana\//]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('returns ssr.noExternal true when any adapter requires full bundling', async () => {
|
|
150
|
+
mockGetStellarViteConfig.mockReturnValueOnce({
|
|
151
|
+
ssr: {
|
|
152
|
+
noExternal: true,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const config = await loadOpenZeppelinAdapterViteConfig({
|
|
157
|
+
ecosystems: ['stellar'],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
expect(config.ssr.noExternal).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('returns deduplicated package names and import specifiers', () => {
|
|
164
|
+
expect(getOpenZeppelinAdapterPackageNames(['evm', 'stellar', 'evm'])).toEqual([
|
|
165
|
+
'@openzeppelin/adapter-evm',
|
|
166
|
+
'@openzeppelin/adapter-stellar',
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
expect(
|
|
170
|
+
getOpenZeppelinAdapterImportSpecifiers(
|
|
171
|
+
['evm'],
|
|
172
|
+
['.', './metadata', './networks', './metadata']
|
|
173
|
+
)
|
|
174
|
+
).toEqual([
|
|
175
|
+
'@openzeppelin/adapter-evm',
|
|
176
|
+
'@openzeppelin/adapter-evm/metadata',
|
|
177
|
+
'@openzeppelin/adapter-evm/networks',
|
|
178
|
+
]);
|
|
179
|
+
});
|
|
180
|
+
});
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { PluginOption, UserConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAdapterRegistryEntry,
|
|
5
|
+
getOpenZeppelinAdapterPackageNames,
|
|
6
|
+
normalizeEcosystems,
|
|
7
|
+
} from './registry';
|
|
8
|
+
import type {
|
|
9
|
+
AdapterViteConfigFragment,
|
|
10
|
+
LoadOpenZeppelinAdapterViteConfigOptions,
|
|
11
|
+
OpenZeppelinAdapterViteConfig,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
type SsrNoExternalValue = NonNullable<NonNullable<UserConfig['ssr']>['noExternal']>;
|
|
15
|
+
|
|
16
|
+
function appendPlugins(target: PluginOption[], plugins: AdapterViteConfigFragment['plugins']) {
|
|
17
|
+
if (!plugins) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
target.push(...(Array.isArray(plugins) ? plugins : [plugins]));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function appendStringValues(target: Set<string>, value: string | string[] | undefined) {
|
|
25
|
+
if (!value) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const values = Array.isArray(value) ? value : [value];
|
|
30
|
+
|
|
31
|
+
for (const entry of values) {
|
|
32
|
+
if (entry) {
|
|
33
|
+
target.add(entry);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function appendNoExternalValues(
|
|
39
|
+
target: Array<string | RegExp>,
|
|
40
|
+
seenStrings: Set<string>,
|
|
41
|
+
value: SsrNoExternalValue | undefined
|
|
42
|
+
): boolean {
|
|
43
|
+
if (!value) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (value === true) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const values = Array.isArray(value) ? value : [value];
|
|
52
|
+
|
|
53
|
+
for (const entry of values) {
|
|
54
|
+
if (typeof entry === 'string') {
|
|
55
|
+
if (!seenStrings.has(entry)) {
|
|
56
|
+
seenStrings.add(entry);
|
|
57
|
+
target.push(entry);
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (entry instanceof RegExp) {
|
|
63
|
+
target.push(entry);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function loadOpenZeppelinAdapterViteConfig(
|
|
71
|
+
options: LoadOpenZeppelinAdapterViteConfigOptions
|
|
72
|
+
): Promise<OpenZeppelinAdapterViteConfig> {
|
|
73
|
+
const ecosystems = normalizeEcosystems(options.ecosystems);
|
|
74
|
+
const plugins: PluginOption[] = [];
|
|
75
|
+
const dedupe = new Set<string>();
|
|
76
|
+
const optimizeDepsInclude = new Set<string>();
|
|
77
|
+
const optimizeDepsExclude = new Set<string>();
|
|
78
|
+
const ssrNoExternal: Array<string | RegExp> = [];
|
|
79
|
+
const seenSsrNoExternalStrings = new Set<string>();
|
|
80
|
+
let ssrNoExternalAll = false;
|
|
81
|
+
const packageNames = getOpenZeppelinAdapterPackageNames(ecosystems);
|
|
82
|
+
|
|
83
|
+
for (const packageName of packageNames) {
|
|
84
|
+
optimizeDepsExclude.add(packageName);
|
|
85
|
+
ssrNoExternalAll =
|
|
86
|
+
appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, packageName) ||
|
|
87
|
+
ssrNoExternalAll;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const ecosystem of ecosystems) {
|
|
91
|
+
const entry = getAdapterRegistryEntry(ecosystem);
|
|
92
|
+
|
|
93
|
+
let fragment: AdapterViteConfigFragment;
|
|
94
|
+
try {
|
|
95
|
+
fragment = await entry.loadConfig(options);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Failed to load ${entry.packageName} Vite configuration. ` +
|
|
99
|
+
`Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
appendPlugins(plugins, fragment.plugins);
|
|
104
|
+
appendStringValues(dedupe, fragment.resolve?.dedupe);
|
|
105
|
+
appendStringValues(optimizeDepsInclude, fragment.optimizeDeps?.include);
|
|
106
|
+
appendStringValues(optimizeDepsExclude, fragment.optimizeDeps?.exclude);
|
|
107
|
+
appendStringValues(optimizeDepsExclude, entry.extraOptimizeDepsExclude);
|
|
108
|
+
|
|
109
|
+
ssrNoExternalAll =
|
|
110
|
+
appendNoExternalValues(ssrNoExternal, seenSsrNoExternalStrings, fragment.ssr?.noExternal) ||
|
|
111
|
+
ssrNoExternalAll;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
plugins,
|
|
116
|
+
resolve: {
|
|
117
|
+
dedupe: [...dedupe],
|
|
118
|
+
},
|
|
119
|
+
optimizeDeps: {
|
|
120
|
+
include: [...optimizeDepsInclude],
|
|
121
|
+
exclude: [...optimizeDepsExclude],
|
|
122
|
+
},
|
|
123
|
+
ssr: {
|
|
124
|
+
noExternal: ssrNoExternalAll ? true : ssrNoExternal,
|
|
125
|
+
},
|
|
126
|
+
packageNames,
|
|
127
|
+
};
|
|
128
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { loadOpenZeppelinAdapterViteConfig } from './config';
|
|
2
|
+
export {
|
|
3
|
+
getOpenZeppelinAdapterImportSpecifier,
|
|
4
|
+
getOpenZeppelinAdapterImportSpecifiers,
|
|
5
|
+
getOpenZeppelinAdapterPackageNames,
|
|
6
|
+
} from './registry';
|
|
7
|
+
export {
|
|
8
|
+
createOpenZeppelinAdapterResolverPlugin,
|
|
9
|
+
resolveInstalledOpenZeppelinAdapterEntries,
|
|
10
|
+
} from './resolver';
|
|
11
|
+
export {
|
|
12
|
+
SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS,
|
|
13
|
+
type AdapterViteConfigFragment,
|
|
14
|
+
type LoadOpenZeppelinAdapterViteConfigOptions,
|
|
15
|
+
type MidnightAdapterPluginFactories,
|
|
16
|
+
type OpenZeppelinAdapterEcosystem,
|
|
17
|
+
type OpenZeppelinAdapterExportPath,
|
|
18
|
+
type OpenZeppelinAdapterPluginFactories,
|
|
19
|
+
type OpenZeppelinAdapterViteConfig,
|
|
20
|
+
type ResolveInstalledOpenZeppelinAdapterEntriesOptions,
|
|
21
|
+
} from './types';
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AdapterViteConfigFragment,
|
|
5
|
+
LoadOpenZeppelinAdapterViteConfigOptions,
|
|
6
|
+
OpenZeppelinAdapterEcosystem,
|
|
7
|
+
OpenZeppelinAdapterExportPath,
|
|
8
|
+
} from './types';
|
|
9
|
+
|
|
10
|
+
interface AdapterRegistryEntry {
|
|
11
|
+
packageName: string;
|
|
12
|
+
extraOptimizeDepsExclude?: string[];
|
|
13
|
+
loadConfig: (
|
|
14
|
+
options: LoadOpenZeppelinAdapterViteConfigOptions
|
|
15
|
+
) => Promise<AdapterViteConfigFragment>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ADAPTER_REGISTRY: Record<OpenZeppelinAdapterEcosystem, AdapterRegistryEntry> = {
|
|
19
|
+
evm: {
|
|
20
|
+
packageName: '@openzeppelin/adapter-evm',
|
|
21
|
+
extraOptimizeDepsExclude: ['@openzeppelin/adapter-evm-core'],
|
|
22
|
+
async loadConfig() {
|
|
23
|
+
const { getEvmViteConfig } = await import('@openzeppelin/adapter-evm/vite-config');
|
|
24
|
+
return getEvmViteConfig() as Partial<UserConfig>;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
midnight: {
|
|
28
|
+
packageName: '@openzeppelin/adapter-midnight',
|
|
29
|
+
async loadConfig(options) {
|
|
30
|
+
const midnightPlugins = options.pluginFactories?.midnight;
|
|
31
|
+
if (!midnightPlugins) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Midnight adapter Vite configuration requires `pluginFactories.midnight` with `wasm` and `topLevelAwait`.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { getMidnightViteConfig } = await import('@openzeppelin/adapter-midnight/vite-config');
|
|
38
|
+
return getMidnightViteConfig(midnightPlugins) as Partial<UserConfig>;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
polkadot: {
|
|
42
|
+
packageName: '@openzeppelin/adapter-polkadot',
|
|
43
|
+
async loadConfig() {
|
|
44
|
+
const { getPolkadotViteConfig } = await import('@openzeppelin/adapter-polkadot/vite-config');
|
|
45
|
+
return getPolkadotViteConfig() as Partial<UserConfig>;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
solana: {
|
|
49
|
+
packageName: '@openzeppelin/adapter-solana',
|
|
50
|
+
async loadConfig() {
|
|
51
|
+
const { getSolanaViteConfig } = await import('@openzeppelin/adapter-solana/vite-config');
|
|
52
|
+
return getSolanaViteConfig() as Partial<UserConfig>;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
stellar: {
|
|
56
|
+
packageName: '@openzeppelin/adapter-stellar',
|
|
57
|
+
async loadConfig() {
|
|
58
|
+
const { getStellarViteConfig } = await import('@openzeppelin/adapter-stellar/vite-config');
|
|
59
|
+
return getStellarViteConfig() as Partial<UserConfig>;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function normalizeEcosystems(
|
|
65
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[]
|
|
66
|
+
): OpenZeppelinAdapterEcosystem[] {
|
|
67
|
+
return [...new Set(ecosystems)];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getAdapterRegistryEntry(
|
|
71
|
+
ecosystem: OpenZeppelinAdapterEcosystem
|
|
72
|
+
): AdapterRegistryEntry {
|
|
73
|
+
return ADAPTER_REGISTRY[ecosystem];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getOpenZeppelinAdapterPackageNames(
|
|
77
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[]
|
|
78
|
+
): string[] {
|
|
79
|
+
return normalizeEcosystems(ecosystems).map(
|
|
80
|
+
(ecosystem) => ADAPTER_REGISTRY[ecosystem].packageName
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getOpenZeppelinAdapterImportSpecifier(
|
|
85
|
+
packageName: string,
|
|
86
|
+
exportPath: OpenZeppelinAdapterExportPath
|
|
87
|
+
): string {
|
|
88
|
+
if (exportPath === '.') {
|
|
89
|
+
return packageName;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return `${packageName}/${exportPath.slice(2)}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getOpenZeppelinAdapterImportSpecifiers(
|
|
96
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[],
|
|
97
|
+
exportPaths: readonly OpenZeppelinAdapterExportPath[]
|
|
98
|
+
): string[] {
|
|
99
|
+
const specifiers = new Set<string>();
|
|
100
|
+
|
|
101
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(ecosystems)) {
|
|
102
|
+
for (const exportPath of exportPaths) {
|
|
103
|
+
specifiers.add(getOpenZeppelinAdapterImportSpecifier(packageName, exportPath));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return [...specifiers];
|
|
108
|
+
}
|
package/src/resolver.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import type { Plugin } from 'vite';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
getOpenZeppelinAdapterImportSpecifier,
|
|
8
|
+
getOpenZeppelinAdapterPackageNames,
|
|
9
|
+
} from './registry';
|
|
10
|
+
import type {
|
|
11
|
+
OpenZeppelinAdapterExportPath,
|
|
12
|
+
ResolveInstalledOpenZeppelinAdapterEntriesOptions,
|
|
13
|
+
} from './types';
|
|
14
|
+
|
|
15
|
+
type PackageExportEntry =
|
|
16
|
+
| string
|
|
17
|
+
| {
|
|
18
|
+
import?: string | { default?: string };
|
|
19
|
+
default?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function readPackageJson(packageDirectory: string): {
|
|
23
|
+
exports?: Record<string, PackageExportEntry>;
|
|
24
|
+
} {
|
|
25
|
+
return JSON.parse(fs.readFileSync(path.join(packageDirectory, 'package.json'), 'utf8')) as {
|
|
26
|
+
exports?: Record<string, PackageExportEntry>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getImportTarget(entry: PackageExportEntry | undefined): string | null {
|
|
31
|
+
if (!entry) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof entry === 'string') {
|
|
36
|
+
return entry;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof entry.import === 'string') {
|
|
40
|
+
return entry.import;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
entry.import &&
|
|
45
|
+
typeof entry.import === 'object' &&
|
|
46
|
+
typeof entry.import.default === 'string'
|
|
47
|
+
) {
|
|
48
|
+
return entry.import.default;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof entry.default === 'string') {
|
|
52
|
+
return entry.default;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveInstalledPackageDirectory(packageName: string, importMetaUrl: string): string {
|
|
59
|
+
const require = createRequire(importMetaUrl);
|
|
60
|
+
const installedEntryPath = require.resolve(packageName);
|
|
61
|
+
return path.resolve(path.dirname(installedEntryPath), '..');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveInstalledExportEntry(
|
|
65
|
+
packageName: string,
|
|
66
|
+
packageDirectory: string,
|
|
67
|
+
exportPath: OpenZeppelinAdapterExportPath
|
|
68
|
+
): string {
|
|
69
|
+
const packageJson = readPackageJson(packageDirectory);
|
|
70
|
+
const target = getImportTarget(packageJson.exports?.[exportPath]);
|
|
71
|
+
|
|
72
|
+
if (!target) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Missing export "${exportPath}" in ${packageName}/package.json (required "import" condition)`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return path.resolve(packageDirectory, target);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function resolveInstalledOpenZeppelinAdapterEntries(
|
|
82
|
+
options: ResolveInstalledOpenZeppelinAdapterEntriesOptions
|
|
83
|
+
): Record<string, string> {
|
|
84
|
+
const exportPaths = options.exportPaths ?? ['.', './metadata', './networks'];
|
|
85
|
+
const entries: Record<string, string> = {};
|
|
86
|
+
|
|
87
|
+
for (const packageName of getOpenZeppelinAdapterPackageNames(options.ecosystems)) {
|
|
88
|
+
const packageDirectory = resolveInstalledPackageDirectory(packageName, options.importMetaUrl);
|
|
89
|
+
|
|
90
|
+
for (const exportPath of exportPaths) {
|
|
91
|
+
entries[getOpenZeppelinAdapterImportSpecifier(packageName, exportPath)] =
|
|
92
|
+
resolveInstalledExportEntry(packageName, packageDirectory, exportPath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return entries;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function createOpenZeppelinAdapterResolverPlugin(
|
|
100
|
+
options: ResolveInstalledOpenZeppelinAdapterEntriesOptions
|
|
101
|
+
): Plugin {
|
|
102
|
+
const entries = resolveInstalledOpenZeppelinAdapterEntries(options);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
name: 'openzeppelin-adapter-package-resolver',
|
|
106
|
+
enforce: 'pre',
|
|
107
|
+
resolveId(id) {
|
|
108
|
+
return entries[id] ?? null;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Plugin, PluginOption, UserConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
export const SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS = [
|
|
4
|
+
'evm',
|
|
5
|
+
'midnight',
|
|
6
|
+
'polkadot',
|
|
7
|
+
'solana',
|
|
8
|
+
'stellar',
|
|
9
|
+
] as const;
|
|
10
|
+
|
|
11
|
+
export type OpenZeppelinAdapterEcosystem =
|
|
12
|
+
(typeof SUPPORTED_OPENZEPPELIN_ADAPTER_ECOSYSTEMS)[number];
|
|
13
|
+
|
|
14
|
+
export type OpenZeppelinAdapterExportPath = '.' | './metadata' | './networks';
|
|
15
|
+
|
|
16
|
+
export interface MidnightAdapterPluginFactories {
|
|
17
|
+
wasm: () => Plugin;
|
|
18
|
+
topLevelAwait: () => Plugin;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface OpenZeppelinAdapterPluginFactories {
|
|
22
|
+
midnight?: MidnightAdapterPluginFactories;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LoadOpenZeppelinAdapterViteConfigOptions {
|
|
26
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
27
|
+
pluginFactories?: OpenZeppelinAdapterPluginFactories;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ResolveInstalledOpenZeppelinAdapterEntriesOptions {
|
|
31
|
+
ecosystems: readonly OpenZeppelinAdapterEcosystem[];
|
|
32
|
+
importMetaUrl: string;
|
|
33
|
+
exportPaths?: readonly OpenZeppelinAdapterExportPath[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface OpenZeppelinAdapterViteConfig {
|
|
37
|
+
plugins: PluginOption[];
|
|
38
|
+
resolve: NonNullable<UserConfig['resolve']>;
|
|
39
|
+
optimizeDeps: NonNullable<UserConfig['optimizeDeps']>;
|
|
40
|
+
ssr: NonNullable<UserConfig['ssr']>;
|
|
41
|
+
packageNames: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type AdapterViteConfigFragment = Partial<
|
|
45
|
+
Pick<UserConfig, 'plugins' | 'resolve' | 'optimizeDeps' | 'ssr'>
|
|
46
|
+
>;
|