(compilation)
| 80 | * @returns {{ stringify: string, env: Record<string, string> }} env object as JSON string |
| 81 | */ |
| 82 | const collectImportMetaEnvDefinitions = (compilation) => { |
| 83 | const cached = compilationMetaEnvMap.get(compilation); |
| 84 | if (cached) { |
| 85 | return cached; |
| 86 | } |
| 87 | |
| 88 | const definePluginHooks = DefinePlugin.getCompilationHooks(compilation); |
| 89 | const definitions = definePluginHooks.definitions.call({}); |
| 90 | /** @type {Record<string, string>} */ |
| 91 | const env = {}; |
| 92 | /** @type {string[]} */ |
| 93 | const pairs = []; |
| 94 | for (const key of Object.keys(definitions)) { |
| 95 | if (key.startsWith("import.meta.env.")) { |
| 96 | const envKey = key.slice("import.meta.env.".length); |
| 97 | const value = definitions[key]; |
| 98 | pairs.push(`${JSON.stringify(envKey)}:${value}`); |
| 99 | env[envKey] = /** @type {string} */ (value); |
| 100 | } |
| 101 | } |
| 102 | const result = { stringify: `{${pairs.join(",")}}`, env }; |
| 103 | compilationMetaEnvMap.set(compilation, result); |
| 104 | return result; |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * Defines the import meta plugin hooks type used by this module. |
no test coverage detected