-
Notifications
You must be signed in to change notification settings - Fork 438
Expand file tree
/
Copy pathenv.js
More file actions
73 lines (64 loc) · 2.38 KB
/
env.js
File metadata and controls
73 lines (64 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2023, Salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
/**
* This Karma plugin injects environment variable to configure the application and the test properly. As temporary
* script is generated based the config, and served as the first file Karma should run.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const { LWC_VERSION } = require('@lwc/shared');
const {
FORCE_NATIVE_SHADOW_MODE_FOR_TEST,
SYNTHETIC_SHADOW_ENABLED,
ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL,
ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION,
NODE_ENV_FOR_TEST,
API_VERSION,
ENABLE_EXPERIMENTAL_SIGNALS,
FORCE_LWC_V5_COMPILER_FOR_TEST,
} = require('../shared/options');
const DIST_DIR = path.resolve(__dirname, '../../dist');
const ENV_FILENAME = path.resolve(DIST_DIR, 'env.js');
function createEnvFile() {
if (!fs.existsSync(DIST_DIR)) {
fs.mkdirSync(DIST_DIR);
}
fs.writeFileSync(
ENV_FILENAME,
`
window.lwcRuntimeFlags = {
ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: ${FORCE_NATIVE_SHADOW_MODE_FOR_TEST},
};
window.process = {
env: {
NODE_ENV: ${JSON.stringify(NODE_ENV_FOR_TEST || 'development')},
MIXED_SHADOW: ${FORCE_NATIVE_SHADOW_MODE_FOR_TEST},
NATIVE_SHADOW: ${!SYNTHETIC_SHADOW_ENABLED || FORCE_NATIVE_SHADOW_MODE_FOR_TEST},
NATIVE_SHADOW_ROOT_DEFINED: typeof ShadowRoot !== 'undefined',
SYNTHETIC_SHADOW_ENABLED: ${SYNTHETIC_SHADOW_ENABLED},
ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL: ${ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL},
ENABLE_EXPERIMENTAL_SIGNALS: ${ENABLE_EXPERIMENTAL_SIGNALS},
ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION: ${ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION},
LWC_VERSION: ${JSON.stringify(LWC_VERSION)},
API_VERSION: ${JSON.stringify(API_VERSION)},
FORCE_LWC_V5_COMPILER_FOR_TEST: ${JSON.stringify(FORCE_LWC_V5_COMPILER_FOR_TEST)}
}
};
`
);
}
function initEnv(files) {
createEnvFile();
files.unshift({
pattern: ENV_FILENAME,
});
}
initEnv.$inject = ['config.files'];
module.exports = {
'framework:env': ['factory', initEnv],
};